Groovy scripts header correction
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / ReplaceVnfInfra.groovy
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP - SO\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *      http://www.apache.org/licenses/LICENSE-2.0\r
11  * \r
12  * Unless required by applicable law or agreed to in writing, software\r
13  * distributed under the License is distributed on an "AS IS" BASIS,\r
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
15  * See the License for the specific language governing permissions and\r
16  * limitations under the License.\r
17  * ============LICENSE_END=========================================================\r
18  */\r
19 \r
20 package org.openecomp.mso.bpmn.infrastructure.scripts\r
21 \r
22 import groovy.json.JsonOutput\r
23 import groovy.json.JsonSlurper\r
24 import groovy.util.Node\r
25 import groovy.util.XmlParser;\r
26 import groovy.xml.QName\r
27 \r
28 import java.io.Serializable;\r
29 import java.util.UUID;\r
30 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil\r
31 import org.camunda.bpm.engine.delegate.BpmnError\r
32 import org.camunda.bpm.engine.impl.cmd.AbstractSetVariableCmd\r
33 import org.camunda.bpm.engine.runtime.Execution\r
34 import org.openecomp.mso.rest.APIResponse\r
35 import org.openecomp.mso.rest.RESTClient\r
36 import org.openecomp.mso.rest.RESTConfig\r
37 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor;\r
38 import org.openecomp.mso.bpmn.common.scripts.VidUtils;\r
39 import org.openecomp.mso.bpmn.core.RollbackData\r
40 import org.openecomp.mso.bpmn.core.WorkflowException\r
41 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil\r
42 import org.openecomp.mso.bpmn.core.json.JsonUtils\r
43 import org.openecomp.mso.bpmn.core.domain.ModelInfo\r
44 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition\r
45 import org.openecomp.mso.bpmn.core.domain.VnfResource\r
46 import org.openecomp.mso.client.aai.*\r
47 \r
48 import org.openecomp.mso.client.appc.ApplicationControllerClient;\r
49 import org.openecomp.mso.client.appc.ApplicationControllerSupport;\r
50 import org.openecomp.appc.client.lcm.model.Action;\r
51 import org.openecomp.appc.client.lcm.model.ActionIdentifiers;\r
52 import org.openecomp.appc.client.lcm.model.LockInput\r
53 import org.openecomp.appc.client.lcm.model.UnlockInput\r
54 import org.openecomp.appc.client.lcm.model.HealthCheckInput\r
55 import org.openecomp.appc.client.lcm.model.StartInput\r
56 import org.openecomp.appc.client.lcm.model.StopInput\r
57 import org.openecomp.appc.client.lcm.model.Flags\r
58 import org.openecomp.appc.client.lcm.model.Status\r
59 \r
60 \r
61 \r
62 public class ReplaceVnfInfra extends AbstractServiceTaskProcessor {\r
63 \r
64         ExceptionUtil exceptionUtil = new ExceptionUtil()\r
65         JsonUtils jsonUtils = new JsonUtils()\r
66         ApplicationControllerClient appcClient = new ApplicationControllerClient()      \r
67         def prefix = "RPLVnfI_"\r
68 \r
69         /**\r
70          * Initialize the flow's variables.\r
71          *\r
72          * @param execution The flow's execution instance.\r
73          */\r
74         public void initProcessVariables(Execution execution) {\r
75                 execution.setVariable('prefix', 'RPLVnfI_')\r
76                 execution.setVariable('RPLVnfI_Request', null)\r
77                 execution.setVariable('RPLVnfI_requestInfo', null)\r
78                 execution.setVariable('RPLVnfI_requestId', null)\r
79                 execution.setVariable('RPLVnfI_source', null)\r
80                 execution.setVariable('RPLVnfI_vnfInputs', null)\r
81                 execution.setVariable('RPLVnfI_vnfId', null)            \r
82                 execution.setVariable('RPLVnfI_tenantId', null)         \r
83                 execution.setVariable('RPLVnfI_vnfParams', null)\r
84                 execution.setVariable('RPLVnfI_cloudConfiguration', null)               \r
85                 execution.setVariable('ReplaceVnfSuccessIndicator', false)\r
86                 execution.setVariable('RPLVnfI_serviceType', null)\r
87                 execution.setVariable('RPLVnfI_nfRole', null)\r
88                 execution.setVariable('RPLVnfI_currentActivity', 'RPLVnfI')\r
89                 execution.setVariable('RPLVnfI_workStep', null)\r
90                 execution.setVariable('RPLVnfI_failedActivity', null)\r
91                 execution.setVariable('RPLVnfI_errorCode', "0")\r
92                 execution.setVariable('RPLVnfI_errorText', null)\r
93                 execution.setVariable('RPLVnfI_healthCheckIndex', 1)\r
94         }\r
95 \r
96         /**\r
97          * Check for missing elements in the received request.\r
98          *\r
99          * @param execution The flow's execution instance.\r
100          */\r
101         public void preProcessRequest(Execution execution) {\r
102                 def method = getClass().getSimpleName() + '.preProcessRequest(' +\r
103                 'execution=' + execution.getId() +\r
104                 ')'\r
105                 initProcessVariables(execution)\r
106                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
107                 logDebug('Entered ' + method, isDebugLogEnabled)\r
108 \r
109                 initProcessVariables(execution)         \r
110 \r
111                 def incomingRequest = execution.getVariable('bpmnRequest')\r
112 \r
113                 utils.log("DEBUG", "Incoming Infra Request: " + incomingRequest, isDebugLogEnabled)\r
114                 try {\r
115                         def jsonSlurper = new JsonSlurper()\r
116                         def jsonOutput = new JsonOutput()\r
117                         Map reqMap = jsonSlurper.parseText(incomingRequest)\r
118                         utils.log("DEBUG", " Request is in JSON format.", isDebugLogEnabled)\r
119 \r
120                         def serviceInstanceId = execution.getVariable('serviceInstanceId')\r
121                         def vnfId = execution.getVariable('vnfId')\r
122                         \r
123                         execution.setVariable(prefix + 'serviceInstanceId', serviceInstanceId)\r
124                         execution.setVariable(prefix + 'vnfId', vnfId)\r
125                         execution.setVariable("isVidRequest", "true")                   \r
126                         \r
127                         def asdcServiceModelVersion = ''\r
128                         def serviceModelInfo = null\r
129                         \r
130                         def relatedInstanceList = reqMap.requestDetails?.relatedInstanceList\r
131                                                 \r
132                         if (relatedInstanceList != null) {\r
133                                 relatedInstanceList.each {\r
134                                         if (it.relatedInstance.modelInfo?.modelType == 'service') {\r
135                                                 utils.log("DEBUG", "PROCESSING SERVICE INFO", isDebugLogEnabled)\r
136                                                 asdcServiceModelVersion = it.relatedInstance.modelInfo?.modelVersion\r
137                                                 serviceModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)\r
138                                                 utils.log("DEBUG", "ServiceModelInfo: " + serviceModelInfo, isDebugLogEnabled)\r
139                                                 def modelInvariant = jsonUtils.getJsonValue(serviceModelInfo, "modelInvariantUuid")\r
140                                                 utils.log("DEBUG", "modelInvariant: " + modelInvariant, isDebugLogEnabled)\r
141                                         }\r
142                                         \r
143                                 }\r
144                         }               \r
145                         \r
146                         execution.setVariable(prefix + 'asdcServiceModelVersion', asdcServiceModelVersion)\r
147                         execution.setVariable(prefix + 'serviceModelInfo', serviceModelInfo)\r
148                         def vnfModelInfo = jsonOutput.toJson(reqMap.requestDetails?.modelInfo)\r
149                         execution.setVariable(prefix + 'vnfModelInfo', vnfModelInfo)\r
150                         def vnfModelInvariantUuid = jsonUtils.getJsonValue(vnfModelInfo, "modelInvariantUuid")\r
151                         execution.setVariable(prefix + 'vnfModelInvariantUuid', vnfModelInvariantUuid)  \r
152                         logDebug("vnfModelInvariantUuid: " + vnfModelInvariantUuid, isDebugLogEnabled)  \r
153                         \r
154                         def vnfType = execution.getVariable('vnfType')\r
155                         execution.setVariable(prefix + 'vnfType', vnfType)      \r
156                         \r
157                         def userParams = reqMap.requestDetails?.requestParameters?.userParams                                   \r
158                         \r
159                         Map<String, String> userParamsMap = [:]\r
160                         if (userParams != null) {\r
161                                 userParams.each { userParam ->\r
162                                         userParamsMap.put(userParam.name, userParam.value)\r
163                                 }                                                       \r
164                         }               \r
165                                                 \r
166                         utils.log("DEBUG", 'Processed user params: ' + userParamsMap, isDebugLogEnabled)                \r
167                         \r
168                         execution.setVariable(prefix + 'vfModuleInputParams', userParamsMap)                    \r
169                                                 \r
170                         def requestId = execution.getVariable("mso-request-id")\r
171                         execution.setVariable(prefix + 'requestId', requestId)\r
172                         \r
173                         \r
174                         def vnfName = reqMap.requestDetails?.requestInfo?.instanceName ?: null\r
175                         execution.setVariable(prefix + 'vnfName', vnfName)\r
176                         \r
177                         def requestorId = reqMap.requestDetails?.requestInfo?.requestorId ?: null\r
178                         execution.setVariable(prefix + 'requestorId', requestorId)\r
179                         \r
180                         def usePreload = reqMap.requestDetails?.requestParameters?.usePreload\r
181                         execution.setVariable(prefix + 'usePreload', usePreload)\r
182                         \r
183                         def cloudConfiguration = jsonOutput.toJson(reqMap.requestDetails?.cloudConfiguration)           \r
184                         execution.setVariable(prefix + 'cloudConfiguration', cloudConfiguration)\r
185                         def lcpCloudRegionId    = jsonUtils.getJsonValue(cloudConfiguration, "lcpCloudRegionId")\r
186                         execution.setVariable(prefix + 'lcpCloudRegionId', lcpCloudRegionId)\r
187                         def tenantId = jsonUtils.getJsonValue(cloudConfiguration, "tenantId")\r
188                         execution.setVariable(prefix + 'tenantId', tenantId)\r
189                         \r
190                         def globalSubscriberId = reqMap.requestDetails?.subscriberInfo?.globalSubscriberId ?: ''\r
191                         execution.setVariable(prefix + 'globalSubscriberId', globalSubscriberId)\r
192                         \r
193                         execution.setVariable(prefix + 'sdncVersion', '1702')\r
194 \r
195                         execution.setVariable("ReplaceVnfInfraSuccessIndicator", false)\r
196                                                 \r
197                         execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)                   \r
198                         \r
199                         def source = reqMap.requestDetails?.requestInfo?.source\r
200                         execution.setVariable(prefix + "source", source)\r
201                         \r
202                         //For Completion Handler & Fallout Handler\r
203                         String requestInfo =\r
204                         """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
205                                         <request-id>${requestId}</request-id>\r
206                                         <action>REPLACE</action>\r
207                                         <source>${source}</source>\r
208                                    </request-info>"""\r
209                         \r
210                         execution.setVariable(prefix + "requestInfo", requestInfo)                      \r
211                         \r
212                         logDebug('RequestInfo: ' + execution.getVariable(prefix + "requestInfo"), isDebugLogEnabled)            \r
213                         \r
214                         logDebug('Exited ' + method, isDebugLogEnabled)\r
215 \r
216                 }\r
217                 catch(groovy.json.JsonException je) {\r
218                         utils.log("DEBUG", " Request is not in JSON format.", isDebugLogEnabled)\r
219                         exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Invalid request format")\r
220 \r
221                 }\r
222                 catch(Exception e) {\r
223                         String restFaultMessage = e.getMessage()\r
224                         utils.log("ERROR", " Exception Encountered - " + "\n" + restFaultMessage, isDebugLogEnabled)\r
225                         exceptionUtil.buildAndThrowWorkflowException(execution, 5000, restFaultMessage)\r
226                 }       \r
227         }\r
228 \r
229         /**\r
230          * Prepare and send the sychronous response for this flow.\r
231          *\r
232          * @param execution The flow's execution instance.\r
233          */\r
234         public void sendSynchResponse(Execution execution) {\r
235                 def method = getClass().getSimpleName() + '.sendSynchResponse(' +\r
236                         'execution=' + execution.getId() +\r
237                         ')'\r
238                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
239                 logDebug('Entered ' + method, isDebugLogEnabled)\r
240 \r
241 \r
242                 try {\r
243                         def requestInfo = execution.getVariable('RPLVnfI_requestInfo')\r
244                         def requestId = execution.getVariable('RPLVnfI_requestId')\r
245                         def source = execution.getVariable('RPLVnfI_source')\r
246                         def progress = getNodeTextForce(requestInfo, 'progress')\r
247                         if (progress.isEmpty()) {\r
248                                 progress = '0'\r
249                         }\r
250                         def startTime = getNodeTextForce(requestInfo, 'start-time')\r
251                         if (startTime.isEmpty()) {\r
252                                 startTime = System.currentTimeMillis()\r
253                         }\r
254 \r
255                         // RESTResponse (for API Handler (APIH) Reply Task)\r
256                         def vnfId = execution.getVariable("vnfId")\r
257                         String synchResponse = """{"requestReferences":{"instanceId":"${vnfId}","requestId":"${requestId}"}}""".trim()\r
258 \r
259                         sendWorkflowResponse(execution, 200, synchResponse)\r
260 \r
261                         logDebug('Exited ' + method, isDebugLogEnabled)\r
262                 } catch (BpmnError e) {\r
263                         throw e;\r
264                 } catch (Exception e) {\r
265                         logError('Caught exception in ' + method, e)\r
266                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())\r
267                 }\r
268         }\r
269         \r
270         \r
271 \r
272         /**\r
273          * Get VnfResource decomposition object for this VNF.\r
274          *      \r
275          *\r
276          * @param execution The flow's execution instance.\r
277          */\r
278         public void getVnfResourceDecomposition(Execution execution) {\r
279                 def method = getClass().getSimpleName() + '.getVnfResourceDecomposition(' +\r
280                         'execution=' + execution.getId() +\r
281                         ')'\r
282                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
283                 logDebug('Entered ' + method, isDebugLogEnabled)\r
284 \r
285                 try {\r
286                         ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")\r
287                         String vnfModelInvariantUuid = execution.getVariable(prefix + 'vnfModelInvariantUuid')\r
288                         logDebug("vnfModelInvariantUuid: " + vnfModelInvariantUuid, isDebugLogEnabled)\r
289                         List<VnfResource> vnfResources = serviceDecomposition.getServiceVnfs()\r
290                         \r
291                         for (i in 0..vnfResources.size()-1) {\r
292                                 ModelInfo modelInfo = vnfResources[i].getModelInfo()\r
293                                 String modelInvariantUuidFromDecomposition = modelInfo.getModelInvariantUuid()\r
294                                 logDebug("modelInvariantUuidFromDecomposition: " + modelInvariantUuidFromDecomposition, isDebugLogEnabled)\r
295                                 \r
296                                 if (vnfModelInvariantUuid.equals(modelInvariantUuidFromDecomposition)) {\r
297                                         VnfResource vnfResourceDecomposition = vnfResources[i]\r
298                                         execution.setVariable(prefix + 'vnfResourceDecomposition', vnfResourceDecomposition)\r
299                                         def nfRole = vnfResourceDecomposition.getNfRole()                                       \r
300                                         execution.setVariable(prefix + 'nfRole', nfRole)\r
301                                         logDebug("vnfResourceDecomposition: " + vnfResourceDecomposition.toJsonString(), isDebugLogEnabled)                                     \r
302                                         break\r
303                                 }\r
304                                 else {\r
305                                         //exception!\r
306                                 }\r
307                                 \r
308                         }\r
309 \r
310                         logDebug('Exited ' + method, isDebugLogEnabled)\r
311                 } catch (BpmnError e) {\r
312                         throw e;\r
313                 } catch (Exception e) {\r
314                         logError('Caught exception in ' + method, e)\r
315                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in getVnfResourceDecomposition(): ' + e.getMessage())\r
316                 }\r
317         }\r
318         \r
319         /**\r
320          * Check if this VNF is already in maintenance in A&AI.\r
321          *\r
322          *\r
323          * @param execution The flow's execution instance.\r
324          */\r
325         public void checkIfVnfInMaintInAAI(Execution execution) {\r
326                 def method = getClass().getSimpleName() + '.checkIfVnfInMaintInAAI(' +\r
327                         'execution=' + execution.getId() +\r
328                         ')'\r
329                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
330                 execution.setVariable(prefix + 'errorCode', "0")\r
331                 execution.setVariable(prefix + "workStep", "checkIfVnfInMaintInAAI")\r
332                 execution.setVariable("failedActivity", "AAI")\r
333                 logDebug('Entered ' + method, isDebugLogEnabled)\r
334 \r
335                 try {\r
336                         def transactionLoggingUuid = UUID.randomUUID().toString()\r
337                         AAIRestClientImpl client = new AAIRestClientImpl()\r
338                         AAIValidatorImpl aaiValidator = new AAIValidatorImpl()\r
339                         aaiValidator.setClient(client)\r
340                         def vnfId = execution.getVariable("vnfId")\r
341                         boolean isInMaint = aaiValidator.isVNFLocked(vnfId, transactionLoggingUuid)\r
342                         logDebug("isInMaint result: " + isInMaint, isDebugLogEnabled)\r
343                         execution.setVariable(prefix + 'isVnfInMaintenance', isInMaint)\r
344 \r
345                         logDebug('Exited ' + method, isDebugLogEnabled)\r
346                 } catch (BpmnError e) {\r
347                         throw e;\r
348                 } catch (Exception e) {\r
349                         logError('Caught exception in ' + method, e)\r
350                         execution.setVariable(prefix + "errorCode", "1002")\r
351                         execution.setVariable(prefix + "errorText", e.getMessage())\r
352                         //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in checkIfVnfInMaintInAAI(): ' + e.getMessage())\r
353                 }\r
354         }\r
355         \r
356         \r
357         /**\r
358          * Check if this VNF's pservers are locked in A&AI.\r
359          *\r
360          *\r
361          * @param execution The flow's execution instance.\r
362          */\r
363         public void checkIfPserversInMaintInAAI(Execution execution) {\r
364                 def method = getClass().getSimpleName() + '.checkIfPserversInMaintInAAI(' +\r
365                         'execution=' + execution.getId() +\r
366                         ')'\r
367                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
368                 execution.setVariable(prefix + 'errorCode', "0")\r
369                 logDebug('Entered ' + method, isDebugLogEnabled)\r
370                 execution.setVariable(prefix + "workStep", "checkIfPserversInMaintInAAI")\r
371                 execution.setVariable("failedActivity", "AAI")\r
372 \r
373                 try {\r
374                         def transactionLoggingUuid = UUID.randomUUID().toString()\r
375                         AAIRestClientImpl client = new AAIRestClientImpl()\r
376                         AAIValidatorImpl aaiValidator = new AAIValidatorImpl()\r
377                         aaiValidator.setClient(client)\r
378                         def vnfId = execution.getVariable("vnfId")                      \r
379                         boolean areLocked = aaiValidator.isPhysicalServerLocked(vnfId, transactionLoggingUuid)\r
380                         logDebug("areLocked result: " + areLocked, isDebugLogEnabled)\r
381                         execution.setVariable(prefix + 'arePserversLocked', areLocked)\r
382 \r
383                         logDebug('Exited ' + method, isDebugLogEnabled)\r
384                 } catch (BpmnError e) {\r
385                         throw e;\r
386                 } catch (Exception e) {\r
387                         logError('Caught exception in ' + method, e)\r
388                         execution.setVariable(prefix + "errorCode", "1002")\r
389                         execution.setVariable(prefix + "errorText", e.getMessage())\r
390                         //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in checkIfPserversInMaintInAAI(): ' + e.getMessage())\r
391                 }\r
392         }\r
393         \r
394         /**\r
395          * Set inMaint flag for this VNF to the specified value in A&AI.\r
396          *\r
397          *\r
398          * @param execution The flow's execution instance.\r
399          * @param inMaint The boolean value of the flag to set\r
400          */\r
401         public void setVnfInMaintFlagInAAI(Execution execution, boolean inMaint) {\r
402                 def method = getClass().getSimpleName() + '.setVnfInMaintFlagInAAI(' +\r
403                         'execution=' + execution.getId() +\r
404                         ')'\r
405                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
406                 execution.setVariable(prefix + 'errorCode', "0")\r
407                 logDebug('Entered ' + method, isDebugLogEnabled)\r
408                 if (inMaint) {\r
409                         execution.setVariable(prefix + "workStep", "setVnfInMaintFlagInAAI")\r
410                 }\r
411                 else {\r
412                         execution.setVariable(prefix + "workStep", "unsetVnfInMaintFlagInAAI")\r
413                 }\r
414                 execution.setVariable("failedActivity", "AAI")\r
415 \r
416                 try {\r
417                         def transactionLoggingUuid = UUID.randomUUID().toString()\r
418                         AAIRestClientImpl client = new AAIRestClientImpl()\r
419                         AAIUpdatorImpl aaiUpdator = new AAIUpdatorImpl()\r
420                         aaiUpdator.setClient(client)\r
421                         def vnfId = execution.getVariable("vnfId")\r
422                         if (inMaint) {\r
423                                 aaiUpdator.updateVnfToLocked(vnfId, transactionLoggingUuid)\r
424                         }\r
425                         else {\r
426                                 aaiUpdator.updateVnfToUnLocked(vnfId, transactionLoggingUuid)\r
427                         }\r
428                                                         \r
429                         logDebug('Exited ' + method, isDebugLogEnabled)\r
430                 } catch (BpmnError e) {\r
431                         throw e;\r
432                 } catch (Exception e) {\r
433                         logError('Caught exception in ' + method, e)\r
434                         execution.setVariable(prefix + "errorCode", "1002")\r
435                         execution.setVariable(prefix + "errorText", e.getMessage())\r
436                         //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in setVnfInMaintFlagInAAI(): ' + e.getMessage())\r
437                 }\r
438         }\r
439         \r
440         /**\r
441          * Call APP-C client to execute specified APP-C command for this VNF.\r
442          *\r
443          *\r
444          * @param execution The flow's execution instance.\r
445          * @param action The action to take in APP-C.\r
446          */\r
447         public void runAppcCommand(Execution execution, Action action) {\r
448                 def method = getClass().getSimpleName() + '.runAppcCommand(' +\r
449                         'execution=' + execution.getId() +\r
450                         ')'\r
451                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
452                 execution.setVariable(prefix + 'errorCode', "0")\r
453                 logDebug('Entered ' + method, isDebugLogEnabled)\r
454                 \r
455                 try {\r
456                         logDebug("Running APP-C action: " + action.toString(), isDebugLogEnabled)\r
457                         String vnfId = execution.getVariable('vnfId')\r
458                         String msoRequestId = execution.getVariable(prefix + 'requestId')\r
459                         execution.setVariable('msoRequestId', msoRequestId)\r
460                         execution.setVariable(prefix + "failedActivity", "APP-C")\r
461                                 \r
462                         ApplicationControllerSupport support = new ApplicationControllerSupport()\r
463                         appcClient.appCSupport=support\r
464                         org.springframework.test.util.ReflectionTestUtils.setField(support, "lcmModelPackage", "org.openecomp.appc.client.lcm.model");\r
465                         Flags flags = new Flags();\r
466                         ActionIdentifiers actionIdentifiers = new ActionIdentifiers();\r
467                         actionIdentifiers.setVnfId(vnfId);\r
468                         Status appcStatus\r
469                         switch(action) {\r
470                                 case Action.Lock:\r
471                                         execution.setVariable(prefix + 'workStep', "LockVNF")\r
472                                         appcStatus = appcClient.runCommand(Action.Lock,actionIdentifiers,flags,null,msoRequestId)\r
473                                         break\r
474                                 case Action.Unlock:\r
475                                         execution.setVariable(prefix + 'workStep', "UnlockVNF")\r
476                                         appcStatus = appcClient.runCommand(Action.Unlock,actionIdentifiers,flags,null,msoRequestId)\r
477                                         break\r
478                                 case Action.HealthCheck:\r
479                                         def healthCheckIndex = execution.getVariable(prefix + 'healthCheckIndex')\r
480                                         execution.setVariable(prefix + 'workStep', "HealthCheckVNF" + healthCheckIndex)\r
481                                         execution.setVariable(prefix + 'healthCheckIndex', healthCheckIndex + 1)\r
482                                         appcStatus = appcClient.runCommand(Action.HealthCheck,actionIdentifiers,flags,null,msoRequestId)\r
483                                         break\r
484                                 case Action.Start:\r
485                                         execution.setVariable(prefix + 'workStep', "StartVNF")\r
486                                         appcStatus = appcClient.runCommand(Action.Start,actionIdentifiers,flags,null,msoRequestId)\r
487                                         break\r
488                                 case Action.Stop:\r
489                                         execution.setVariable(prefix + 'workStep', "StopVNF")\r
490                                         appcStatus = appcClient.runCommand(Action.Stop,actionIdentifiers,flags,null,msoRequestId)\r
491                                         break\r
492                                 default:\r
493                                         break\r
494                         }\r
495                         logDebug("Completed AppC request", isDebugLogEnabled)\r
496                         int appcCode = appcStatus.getCode()\r
497                         logDebug("AppC status code is: " + appcCode, isDebugLogEnabled)\r
498                         logDebug("AppC status message is: " + appcStatus.getMessage(), isDebugLogEnabled)\r
499                         if (support.getCategoryOf(appcStatus) == ApplicationControllerSupport.StatusCategory.ERROR) {\r
500                                 execution.setVariable(prefix + "errorCode", Integer.toString(appcCode))\r
501                                 execution.setVariable(prefix + "errorText", appcStatus.getMessage())\r
502                         }\r
503                         logDebug('Exited ' + method, isDebugLogEnabled)\r
504                 } catch (BpmnError e) {\r
505                         logError('Caught exception in ' + method, e)\r
506                         execution.setVariable(prefix + "errorCode", "1002")\r
507                         execution.setVariable(prefix + "errorText", e.getMessage())\r
508                         //throw e;\r
509                 } catch (java.lang.NoSuchMethodError e) {\r
510                         logError('Caught exception in ' + method, e)\r
511                         execution.setVariable(prefix + "errorCode", "1002")\r
512                         execution.setVariable(prefix + "errorText", e.getMessage())\r
513                         //throw e;\r
514                 } catch (Exception e) {\r
515                         logError('Caught exception in ' + method, e)\r
516                         execution.setVariable(prefix + "errorCode", "1002")\r
517                         execution.setVariable(prefix + "errorText", e.getMessage())\r
518                         \r
519                         //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in ' + method + ': ' + e.getMessage())\r
520                 }\r
521         }\r
522 \r
523 \r
524         \r
525 \r
526         /**\r
527          * Builds a "CompletionHandler" request and stores it in the specified execution variable.\r
528          *\r
529          * @param execution the execution\r
530          * @param resultVar the execution variable in which the result will be stored\r
531          */\r
532         public void completionHandlerPrep(Execution execution, String resultVar) {\r
533                 def method = getClass().getSimpleName() + '.completionHandlerPrep(' +\r
534                         'execution=' + execution.getId() +\r
535                         ', resultVar=' + resultVar +\r
536                         ')'\r
537                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
538                 logDebug('Entered ' + method, isDebugLogEnabled)\r
539 \r
540                 try {\r
541                         def requestInfo = getVariable(execution, 'RPLVnfI_requestInfo')\r
542                         \r
543                         appcClient.shutdownclient()\r
544 \r
545                         String content = """\r
546                                 <sdncadapterworkflow:MsoCompletionRequest xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"\r
547                                                 xmlns:reqtype="http://org.openecomp/mso/request/types/v1">\r
548                                         ${requestInfo}\r
549                                         <sdncadapterworkflow:mso-bpel-name>MSO_ACTIVATE_BPEL</sdncadapterworkflow:mso-bpel-name>\r
550                                 </sdncadapterworkflow:MsoCompletionRequest>\r
551                         """\r
552 \r
553                         content = utils.formatXml(content)\r
554                         logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)\r
555                         execution.setVariable(resultVar, content)\r
556 \r
557                         logDebug('Exited ' + method, isDebugLogEnabled)\r
558                 } catch (BpmnError e) {\r
559                         throw e;\r
560                 } catch (Exception e) {\r
561                         logError('Caught exception in ' + method, e)\r
562                         exceptionUtil.buildAndThrowWorkflowException(execution, 2000, 'Internal Error')\r
563                 }\r
564         }\r
565         \r
566         /**\r
567         * Prepare DoDeleteVnfAndModules call.\r
568         *\r
569         *\r
570         * @param execution The flow's execution instance.\r
571         */\r
572    public void prepDoDeleteVnfAndModules(Execution execution) {\r
573            def method = getClass().getSimpleName() + '.prepDoDeleteVnfAndModules(' +\r
574                    'execution=' + execution.getId() +\r
575                    ')'\r
576            def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled') \r
577            execution.setVariable(prefix + 'errorCode', "0")\r
578            logDebug('Entered ' + method, isDebugLogEnabled)\r
579            execution.setVariable(prefix + "workStep", "doDeleteVnfAndModules")\r
580            execution.setVariable("failedActivity", "MSO Delete VNF")\r
581            logDebug('Exited ' + method, isDebugLogEnabled)\r
582            \r
583    }\r
584    \r
585    /**\r
586         * Prepare DoCreateVnfAndModules call.\r
587         *\r
588         *\r
589         * @param execution The flow's execution instance.\r
590         */\r
591    public void prepDoCreateVnfAndModules(Execution execution) {\r
592            def method = getClass().getSimpleName() + '.prepDoReplaceVnfAndModules(' +\r
593                    'execution=' + execution.getId() +\r
594                    ')'\r
595            def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
596            execution.setVariable(prefix + 'errorCode', "0")\r
597            logDebug('Entered ' + method, isDebugLogEnabled)\r
598            execution.setVariable(prefix + "workStep", "doReplaceVnfAndModules")\r
599            execution.setVariable("failedActivity", "MSO Replace VNF")\r
600            logDebug('Exited ' + method, isDebugLogEnabled)\r
601            \r
602    }\r
603         \r
604         /**\r
605          * Builds a "FalloutHandler" request and stores it in the specified execution variable.\r
606          *\r
607          * @param execution the execution\r
608          * @param resultVar the execution variable in which the result will be stored\r
609          */\r
610         public void falloutHandlerPrep(Execution execution, String resultVar) {\r
611                 def method = getClass().getSimpleName() + '.falloutHandlerPrep(' +\r
612                         'execution=' + execution.getId() +\r
613                         ', resultVar=' + resultVar +\r
614                         ')'\r
615                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
616                 logDebug('Entered ' + method, isDebugLogEnabled)\r
617 \r
618                 try {\r
619                         def prefix = execution.getVariable('prefix')\r
620                         def request = getVariable(execution, prefix+'Request')\r
621                         def requestInformation = execution.getVariable(prefix + "requestInfo")                  \r
622                         \r
623                         appcClient.shutdownclient()\r
624 \r
625                         def WorkflowException workflowException = execution.getVariable("WorkflowException")\r
626                         def errorResponseCode = workflowException.getErrorCode()\r
627                         def errorResponseMsg = workflowException.getErrorMessage()\r
628                         def encErrorResponseMsg = ""\r
629                         if (errorResponseMsg != null) {\r
630                                 encErrorResponseMsg = errorResponseMsg.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")\r
631                         }\r
632 \r
633                         String content = """\r
634                                 <sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"\r
635                                                 xmlns:reqtype="http://org.openecomp/mso/request/types/v1"\r
636                                                 xmlns:msoservtypes="http://org.openecomp/mso/request/types/v1"\r
637                                                 xmlns:structuredtypes="http://org.openecomp/mso/structured/types/v1">\r
638                                         ${requestInformation}\r
639                                         <sdncadapterworkflow:WorkflowException>\r
640                                                 <sdncadapterworkflow:ErrorMessage>${encErrorResponseMsg}</sdncadapterworkflow:ErrorMessage>\r
641                                                 <sdncadapterworkflow:ErrorCode>${errorResponseCode}</sdncadapterworkflow:ErrorCode>\r
642                                         </sdncadapterworkflow:WorkflowException>\r
643                                 </sdncadapterworkflow:FalloutHandlerRequest>\r
644                         """\r
645                         content = utils.formatXml(content)\r
646                         logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)\r
647                         execution.setVariable(resultVar, content)\r
648 \r
649                         logDebug('Exited ' + method, isDebugLogEnabled)\r
650                 } catch (BpmnError e) {\r
651                         throw e;\r
652                 } catch (Exception e) {\r
653                         logError('Caught exception in ' + method, e)\r
654                         exceptionUtil.buildWorkflowException(execution, 2000, 'Internal Error')\r
655                 }\r
656         }\r
657         \r
658         /**\r
659          * Handle Abort disposition from RainyDayHandler\r
660          *       \r
661          * @param execution The flow's execution instance.      \r
662          */\r
663         public void abortProcessing(Execution execution) {\r
664                 def method = getClass().getSimpleName() + '.abortProcessing(' +\r
665                         'execution=' + execution.getId() +\r
666                         ')'\r
667                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
668                 logDebug('Entered ' + method, isDebugLogEnabled)\r
669                 \r
670                 def errorText = execution.getVariable(prefix + "errorText")\r
671                 def errorCode = execution.getVariable(prefix + "errorCode")\r
672                 \r
673                 exceptionUtil.buildAndThrowWorkflowException(execution, errorCode as Integer, errorText)\r
674         }\r
675         \r
676         /**\r
677          * Handle Manual disposition from RainyDayHandler\r
678          *\r
679          * @param execution The flow's execution instance.\r
680          */\r
681         public void manualProcessing(Execution execution) {\r
682                 def method = getClass().getSimpleName() + '.manualProcessing(' +\r
683                         'execution=' + execution.getId() +\r
684                         ')'\r
685                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
686                 logDebug('Entered ' + method, isDebugLogEnabled)\r
687                 \r
688                 def taskId = execution.getVariable("RPLVnfI_taskId")\r
689                 \r
690                 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Processing halted - manual task created: " + taskId)\r
691         }\r
692 \r
693         \r
694 }\r