1 | /** |
2 | * |
3 | */ |
4 | package de.fzi.se.accuracy.transformation; |
5 | |
6 | import org.apache.log4j.Logger; |
7 | |
8 | import de.fzi.se.quality.qualityannotation.NoPrecision; |
9 | import de.fzi.se.quality.qualityannotation.REPrecision; |
10 | import de.fzi.se.quality.util.EcoreCopierCreatingNewIds; |
11 | import de.uka.ipd.sdq.pcm.core.PCMRandomVariable; |
12 | import de.uka.ipd.sdq.pcm.parameter.ParameterFactory; |
13 | import de.uka.ipd.sdq.pcm.parameter.VariableCharacterisation; |
14 | import de.uka.ipd.sdq.pcm.parameter.VariableUsage; |
15 | import de.uka.ipd.sdq.pcm.reliability.FailureType; |
16 | import de.uka.ipd.sdq.pcm.seff.AbstractAction; |
17 | import de.uka.ipd.sdq.pcm.seff.CallAction; |
18 | import de.uka.ipd.sdq.pcm.seff.CallReturnAction; |
19 | import de.uka.ipd.sdq.pcm.seff.ExternalCallAction; |
20 | import de.uka.ipd.sdq.pcm.seff.InternalCallAction; |
21 | import de.uka.ipd.sdq.pcm.seff.SeffFactory; |
22 | import de.uka.ipd.sdq.pcm.seff.ServiceEffectSpecification; |
23 | import de.uka.ipd.sdq.pcm.seff.seff_performance.InfrastructureCall; |
24 | import de.uka.ipd.sdq.pcm.seff.seff_performance.ParametricResourceDemand; |
25 | import de.uka.ipd.sdq.pcm.seff.seff_performance.ResourceCall; |
26 | import de.uka.ipd.sdq.pcm.seff.seff_reliability.FailureHandlingEntity; |
27 | import de.uka.ipd.sdq.stoex.AbstractNamedReference; |
28 | import de.uka.ipd.sdq.workflow.pcm.blackboard.PCMResourceSetPartition; |
29 | import de.uka.ipd.sdq.workflow.pcm.runconfig.AccuracyInfluenceAnalysisState; |
30 | |
31 | /** |
32 | * Implementing the transformation of given SEFFs for the state |
33 | * {@link AccuracyInfluenceAnalysisState#MAXIMUM}. Start the transformation by |
34 | * invoking {@link #doSwitch(org.eclipse.emf.ecore.EObject)} with a parameter of |
35 | * type {@link ServiceEffectSpecification}. |
36 | * |
37 | * @author groenda |
38 | * |
39 | */ |
40 | public class AccuracyInfluenceSEFFTransformationStrategyMaximum extends |
41 | AbstractAccuracyInfluenceSEFFTransformationStrategy { |
42 | /** Logger for this class. */ |
43 | private static final Logger logger = Logger.getLogger(AccuracyInfluenceSEFFTransformationStrategyMaximum.class); |
44 | |
45 | /** Copier for EMF elements. */ |
46 | private EcoreCopierCreatingNewIds copier = new EcoreCopierCreatingNewIds(); |
47 | |
48 | /** Transformation of the specification of {@link PCMRandomVariable} for the maximum of a precision. */ |
49 | private final PCMRandomVariableSpecificationAccuracyMaximumTrafo randomVariableMaximumTrafo = new PCMRandomVariableSpecificationAccuracyMaximumTrafo(); |
50 | /** Returns the minimum value for a validation precision and provided absolute value. */ |
51 | private final ValidationPrecisionToMaximumLongValue precisionMaximalValue = new ValidationPrecisionToMaximumLongValue(); |
52 | |
53 | /**Create a new instance using the given quality annotations. |
54 | * @param pcmPartition Partition containing the quality annotations. |
55 | */ |
56 | public AccuracyInfluenceSEFFTransformationStrategyMaximum(PCMResourceSetPartition pcmPartition) { |
57 | super(pcmPartition); |
58 | } |
59 | |
60 | /* (non-Javadoc) |
61 | * @see de.uka.ipd.sdq.codegen.simucontroller.workflow.jobs.AbstractAccuracyInfluenceSEFFTransformationStrategy#modifyComponentExternalCall(de.uka.ipd.sdq.pcm.seff.ExternalCallAction, de.fzi.se.quality.qualityannotation.REPrecision) |
62 | */ |
63 | @Override |
64 | protected void modifyComponentExternalCall(ExternalCallAction call, |
65 | REPrecision precision) { |
66 | // Call Parameters for an CallAction |
67 | handleInputParametersOfCallAction(call, precision); |
68 | // Number of Calls for an AbstractAction |
69 | precisionMaximalValue.setAbsoluteValue(1l); |
70 | long max = precisionMaximalValue.doSwitch(precision.getDefaultPrecisionNumberOfCalls()); |
71 | if (max > 1) { |
72 | ExternalCallAction eca = null; |
73 | AbstractAction predecessor = call; |
74 | AbstractAction finalSuccessor = call.getSuccessor_AbstractAction(); |
75 | //replicate action |
76 | for (int i = 1; i < max; i++) { |
77 | eca = SeffFactory.eINSTANCE.createExternalCallAction(); |
78 | if (i == 1) { // special case for the first replica for correct control flow |
79 | call.setSuccessor_AbstractAction(eca); |
80 | } |
81 | eca.setCalledService_ExternalService(call.getCalledService_ExternalService()); |
82 | eca.setEntityName(call.getEntityName() + " Accuracy Influence Replica " + i); |
83 | eca.setRetryCount(eca.getRetryCount()); |
84 | copyInputVariableUsages(eca, call); |
85 | copyReturnVariableUsage(eca, call); |
86 | copyFailureTypes(eca, call); |
87 | eca.setRole_ExternalService(call.getRole_ExternalService()); |
88 | eca.setPredecessor_AbstractAction(predecessor); |
89 | predecessor = eca; |
90 | } |
91 | if (eca != null) { |
92 | eca.setSuccessor_AbstractAction(finalSuccessor); |
93 | } else { |
94 | String msg = "Impossible control flow in implemenation. Correct implemenatation."; |
95 | logger.fatal(msg); |
96 | throw new IllegalArgumentException(msg); |
97 | } |
98 | } |
99 | } |
100 | |
101 | /* (non-Javadoc) |
102 | * @see de.uka.ipd.sdq.codegen.simucontroller.workflow.jobs.AbstractAccuracyInfluenceSEFFTransformationStrategy#modifyComponentInternalCall(de.uka.ipd.sdq.pcm.seff.InternalCallAction, de.fzi.se.quality.qualityannotation.REPrecision) |
103 | */ |
104 | @Override |
105 | protected void modifyComponentInternalCall(InternalCallAction call, |
106 | REPrecision precision) { |
107 | // Call Parameters for an CallAction |
108 | handleInputParametersOfCallAction(call, precision); |
109 | // Number of Calls for an AbstractAction |
110 | precisionMaximalValue.setAbsoluteValue(1l); |
111 | long max = precisionMaximalValue.doSwitch(precision.getDefaultPrecisionNumberOfCalls()); |
112 | if (max > 1) { |
113 | InternalCallAction ica = null; |
114 | AbstractAction predecessor = call; |
115 | AbstractAction finalSuccessor = call.getSuccessor_AbstractAction(); |
116 | //replicate action |
117 | for (int i = 1; i < max; i++) { |
118 | ica = SeffFactory.eINSTANCE.createInternalCallAction(); |
119 | if (i == 1) { // special case for the first replica for correct control flow |
120 | call.setSuccessor_AbstractAction(ica); |
121 | } |
122 | ica.setCalledResourceDemandingInternalBehaviour(call.getCalledResourceDemandingInternalBehaviour()); |
123 | ica.setEntityName(call.getEntityName() + " Accuracy Influence Replica " + i); |
124 | copyInputVariableUsages(ica, call); |
125 | // not implemented although it should be copyReturnVariableUsage(ica, call); |
126 | ica.setPredecessor_AbstractAction(predecessor); |
127 | predecessor = ica; |
128 | } |
129 | if (ica != null) { |
130 | ica.setSuccessor_AbstractAction(finalSuccessor); |
131 | } else { |
132 | String msg = "Impossible control flow in implemenation. Correct implemenatation."; |
133 | logger.fatal(msg); |
134 | throw new IllegalArgumentException(msg); |
135 | } |
136 | } |
137 | } |
138 | |
139 | /* (non-Javadoc) |
140 | * @see de.uka.ipd.sdq.codegen.simucontroller.workflow.jobs.AbstractAccuracyInfluenceSEFFTransformationStrategy#modifyInfrastructureCall(de.uka.ipd.sdq.pcm.seff.seff_performance.InfrastructureCall, de.fzi.se.quality.qualityannotation.REPrecision) |
141 | */ |
142 | @Override |
143 | protected void modifyInfrastructureCall(InfrastructureCall call, |
144 | REPrecision precision) { |
145 | // Number of Calls |
146 | randomVariableMaximumTrafo.setModifiedVariable(call.getNumberOfCalls__InfrastructureCall()); |
147 | randomVariableMaximumTrafo.doSwitch(precision.getDefaultPrecisionNumberOfCalls()); |
148 | // Call parameters |
149 | handleInputParametersOfCallAction(call, precision); |
150 | } |
151 | |
152 | /* (non-Javadoc) |
153 | * @see de.uka.ipd.sdq.codegen.simucontroller.workflow.jobs.AbstractAccuracyInfluenceSEFFTransformationStrategy#modifyResourceCall(de.uka.ipd.sdq.pcm.seff.seff_performance.ResourceCall, de.fzi.se.quality.qualityannotation.REPrecision) |
154 | */ |
155 | @Override |
156 | protected void modifyResourceCall(ResourceCall call, REPrecision precision) { |
157 | // Number of Calls |
158 | randomVariableMaximumTrafo.setModifiedVariable(call.getNumberOfCalls__ResourceCall()); |
159 | randomVariableMaximumTrafo.doSwitch(precision.getDefaultPrecisionNumberOfCalls()); |
160 | // Call parameters |
161 | for (VariableUsage variableUsage : call.getInputVariableUsages__CallAction()) { |
162 | for (VariableCharacterisation varChar : variableUsage.getVariableCharacterisation_VariableUsage()) { |
163 | randomVariableMaximumTrafo.setModifiedVariable(varChar.getSpecification_VariableCharacterisation()); |
164 | randomVariableMaximumTrafo.doSwitch(precision.getDefaultPrecisionCallParameter()); |
165 | } |
166 | } |
167 | } |
168 | |
169 | /* (non-Javadoc) |
170 | * @see de.uka.ipd.sdq.codegen.simucontroller.workflow.jobs.AbstractAccuracyInfluenceSEFFTransformationStrategy#modifyResourceDemand(de.uka.ipd.sdq.pcm.seff.seff_performance.ParametricResourceDemand, de.fzi.se.quality.qualityannotation.REPrecision) |
171 | */ |
172 | @Override |
173 | protected void modifyResourceDemand(ParametricResourceDemand demand, |
174 | REPrecision precision) { |
175 | // Number of Calls |
176 | randomVariableMaximumTrafo.setModifiedVariable(demand.getSpecification_ParametericResourceDemand()); |
177 | randomVariableMaximumTrafo.doSwitch(precision.getDefaultPrecisionNumberOfCalls()); |
178 | // Call Parameters |
179 | if (!(precision.getDefaultPrecisionCallParameter() instanceof NoPrecision)) { |
180 | String msg = "A ResourceDemand has no parameters. The default precision for call parameters must be set to NoPrecision."; |
181 | logger.error(msg); |
182 | throw new IllegalArgumentException(msg); |
183 | } |
184 | } |
185 | |
186 | /**Handles the transformation for input parameters of call actions. |
187 | * @param call Call action to transform. |
188 | * @param precision Precision. |
189 | */ |
190 | private void handleInputParametersOfCallAction(CallAction call, |
191 | REPrecision precision) { |
192 | for (VariableUsage variableUsage : call.getInputVariableUsages__CallAction()) { |
193 | for (VariableCharacterisation varChar : variableUsage.getVariableCharacterisation_VariableUsage()) { |
194 | randomVariableMaximumTrafo.setModifiedVariable(varChar.getSpecification_VariableCharacterisation()); |
195 | randomVariableMaximumTrafo.doSwitch(precision.getDefaultPrecisionCallParameter()); |
196 | } |
197 | } |
198 | } |
199 | |
200 | /**Copy input variable usages from source to target. |
201 | * @param target Target. |
202 | * @param source Source. |
203 | */ |
204 | private void copyInputVariableUsages(CallAction target, |
205 | CallAction source) { |
206 | VariableUsage newVU; |
207 | VariableCharacterisation newVC; |
208 | for (VariableUsage variableUsage : source.getInputVariableUsages__CallAction()) { |
209 | newVU = ParameterFactory.eINSTANCE.createVariableUsage(); |
210 | newVU.setNamedReference__VariableUsage((AbstractNamedReference) copier.copy(variableUsage.getNamedReference__VariableUsage())); |
211 | for (VariableCharacterisation varChar : variableUsage.getVariableCharacterisation_VariableUsage()) { |
212 | newVC = ParameterFactory.eINSTANCE.createVariableCharacterisation(); |
213 | newVC.setSpecification_VariableCharacterisation(varChar.getSpecification_VariableCharacterisation()); |
214 | newVU.getVariableCharacterisation_VariableUsage().add(newVC); |
215 | } |
216 | target.getInputVariableUsages__CallAction().add(newVU); |
217 | } |
218 | } |
219 | |
220 | /**Copy return variable usages from source to target. |
221 | * @param target Target. |
222 | * @param source Source. |
223 | */ |
224 | private void copyReturnVariableUsage(CallReturnAction target, |
225 | CallReturnAction source) { |
226 | VariableUsage newVU; |
227 | VariableCharacterisation newVC; |
228 | for (VariableUsage variableUsage : source.getReturnVariableUsage__CallReturnAction()) { |
229 | newVU = ParameterFactory.eINSTANCE.createVariableUsage(); |
230 | newVU.setNamedReference__VariableUsage((AbstractNamedReference) copier.copy(variableUsage.getNamedReference__VariableUsage())); |
231 | for (VariableCharacterisation varChar : variableUsage.getVariableCharacterisation_VariableUsage()) { |
232 | newVC = ParameterFactory.eINSTANCE.createVariableCharacterisation(); |
233 | newVC.setSpecification_VariableCharacterisation(varChar.getSpecification_VariableCharacterisation()); |
234 | newVU.getVariableCharacterisation_VariableUsage().add(newVC); |
235 | } |
236 | target.getReturnVariableUsage__CallReturnAction().add(newVU); |
237 | } |
238 | } |
239 | |
240 | /**Copy failure types from source to target. |
241 | * @param target Target. |
242 | * @param source Source. |
243 | */ |
244 | private void copyFailureTypes(FailureHandlingEntity target, |
245 | FailureHandlingEntity source) { |
246 | for (FailureType failureType : source.getFailureTypes_FailureHandlingEntity()) { |
247 | target.getFailureTypes_FailureHandlingEntity().add(failureType); |
248 | } |
249 | } |
250 | |
251 | |
252 | } |