47121a38d1685cbfa9f01f4aa0b66a2ae0a9c925
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / UpdateVnfInfra.groovy
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * OPENECOMP - MSO\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.beans.MetaData.java_lang_Class_PersistenceDelegate\r
29 import java.io.Serializable;\r
30 import java.util.UUID;\r
31 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil\r
32 import org.camunda.bpm.engine.delegate.BpmnError\r
33 import org.camunda.bpm.engine.impl.cmd.AbstractSetVariableCmd\r
34 import org.camunda.bpm.engine.runtime.Execution\r
35 import org.openecomp.mso.rest.APIResponse\r
36 import org.openecomp.mso.rest.RESTClient\r
37 import org.openecomp.mso.rest.RESTConfig\r
38 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor;\r
39 import org.openecomp.mso.bpmn.common.scripts.VidUtils;\r
40 import org.openecomp.mso.bpmn.core.RollbackData\r
41 import org.openecomp.mso.bpmn.core.WorkflowException\r
42 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil\r
43 import org.openecomp.mso.bpmn.core.json.JsonUtils\r
44 import org.openecomp.mso.bpmn.core.domain.ModelInfo\r
45 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition\r
46 import org.openecomp.mso.bpmn.core.domain.VnfResource\r
47 import org.openecomp.mso.client.aai.*\r
48 \r
49 import org.openecomp.mso.client.appc.ApplicationControllerClient;\r
50 import org.openecomp.mso.client.appc.ApplicationControllerSupport;\r
51 import org.openecomp.appc.client.lcm.model.Action;\r
52 import org.openecomp.appc.client.lcm.model.ActionIdentifiers;\r
53 import org.openecomp.appc.client.lcm.model.LockInput\r
54 import org.openecomp.appc.client.lcm.model.UnlockInput\r
55 import org.openecomp.appc.client.lcm.model.HealthCheckInput\r
56 import org.openecomp.appc.client.lcm.model.StartInput\r
57 import org.openecomp.appc.client.lcm.model.StopInput\r
58 import org.openecomp.appc.client.lcm.model.Flags\r
59 import org.openecomp.appc.client.lcm.model.Status\r
60 \r
61 \r
62 \r
63 public class UpdateVnfInfra extends AbstractServiceTaskProcessor {\r
64 \r
65         ExceptionUtil exceptionUtil = new ExceptionUtil()\r
66         JsonUtils jsonUtils = new JsonUtils()\r
67         ApplicationControllerClient appcClient = new ApplicationControllerClient()\r
68         def prefix = "UPDVnfI_"\r
69 \r
70         /**\r
71          * Initialize the flow's variables.\r
72          *\r
73          * @param execution The flow's execution instance.\r
74          */\r
75         public void initProcessVariables(Execution execution) {\r
76                 execution.setVariable('prefix', 'UPDVnfI_')\r
77                 execution.setVariable('UPDVnfI_Request', null)\r
78                 execution.setVariable('UPDVnfI_requestInfo', null)\r
79                 execution.setVariable('UPDVnfI_requestId', null)\r
80                 execution.setVariable('UPDVnfI_source', null)\r
81                 execution.setVariable('UPDVnfI_vnfInputs', null)\r
82                 execution.setVariable('UPDVnfI_vnfId', null)            \r
83                 execution.setVariable('UPDVnfI_tenantId', null)         \r
84                 execution.setVariable('UPDVnfI_vnfParams', null)                \r
85                 execution.setVariable('UpdateVnfSuccessIndicator', false)\r
86                 execution.setVariable('UPDVnfI_serviceType', null)\r
87                 execution.setVariable('UPDVnfI_nfRole', null)\r
88                 execution.setVariable('UPDVnfI_currentActivity', 'UPDVnfI')\r
89                 execution.setVariable('UPDVnfI_workStep', null)\r
90                 execution.setVariable('UPDVnfI_failedActivity', null)\r
91                 execution.setVariable('UPDVnfI_errorCode', "0")\r
92                 execution.setVariable('UPDVnfI_errorText', null)\r
93                 execution.setVariable('UPDVnfI_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                         execution.setVariable('msoRequestId', requestId)\r
173                         \r
174                         \r
175                         def vnfName = reqMap.requestDetails?.requestInfo?.instanceName ?: null\r
176                         execution.setVariable(prefix + 'vnfName', vnfName)\r
177                         \r
178                         def requestorId = reqMap.requestDetails?.requestInfo?.requestorId ?: null\r
179                         execution.setVariable(prefix + 'requestorId', requestorId)\r
180                         \r
181                         def usePreload = reqMap.requestDetails?.requestParameters?.usePreload\r
182                         execution.setVariable(prefix + 'usePreload', usePreload)\r
183                         \r
184                         def cloudConfiguration = reqMap.requestDetails?.cloudConfiguration\r
185                         def lcpCloudRegionId    = cloudConfiguration.lcpCloudRegionId\r
186                         execution.setVariable(prefix + 'lcpCloudRegionId', lcpCloudRegionId)\r
187                         def tenantId = 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("UpdateVnfInfraSuccessIndicator", 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>UPDATE</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('UPDVnfI_requestInfo')\r
244                         def requestId = execution.getVariable('UPDVnfI_requestId')\r
245                         def source = execution.getVariable('UPDVnfI_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(prefix + "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(prefix + "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(prefix + "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         /**\r
528          * Builds a "CompletionHandler" request and stores it in the specified execution variable.\r
529          *\r
530          * @param execution the execution\r
531          * @param resultVar the execution variable in which the result will be stored\r
532          */\r
533         public void completionHandlerPrep(Execution execution, String resultVar) {\r
534                 def method = getClass().getSimpleName() + '.completionHandlerPrep(' +\r
535                         'execution=' + execution.getId() +\r
536                         ', resultVar=' + resultVar +\r
537                         ')'\r
538                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
539                 logDebug('Entered ' + method, isDebugLogEnabled)                \r
540                 \r
541 \r
542                 try {\r
543                         appcClient.shutdownclient()\r
544                         def requestInfo = getVariable(execution, 'UPDVnfI_requestInfo')\r
545 \r
546                         String content = """\r
547                                 <sdncadapterworkflow:MsoCompletionRequest xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"\r
548                                                 xmlns:reqtype="http://org.openecomp/mso/request/types/v1">\r
549                                         ${requestInfo}\r
550                                         <sdncadapterworkflow:mso-bpel-name>MSO_ACTIVATE_BPEL</sdncadapterworkflow:mso-bpel-name>\r
551                                 </sdncadapterworkflow:MsoCompletionRequest>\r
552                         """\r
553 \r
554                         content = utils.formatXml(content)\r
555                         logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)\r
556                         execution.setVariable(resultVar, content)\r
557 \r
558                         logDebug('Exited ' + method, isDebugLogEnabled)\r
559                 } catch (BpmnError e) {\r
560                         throw e;\r
561                 } catch (Exception e) {\r
562                         logError('Caught exception in ' + method, e)\r
563                         exceptionUtil.buildAndThrowWorkflowException(execution, 2000, 'Internal Error')\r
564                 }\r
565         }\r
566         \r
567         /**\r
568         * Prepare DoUpdateVnfAndModules call.\r
569         *\r
570         *\r
571         * @param execution The flow's execution instance.\r
572         */\r
573    public void prepDoUpdateVnfAndModules(Execution execution) {\r
574            def method = getClass().getSimpleName() + '.prepDoUpdateVnfAndModules(' +\r
575                    'execution=' + execution.getId() +\r
576                    ')'\r
577            def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
578            execution.setVariable(prefix + 'errorCode', "0")\r
579            logDebug('Entered ' + method, isDebugLogEnabled)\r
580            execution.setVariable(prefix + "workStep", "doUpdateVnfAndModules")\r
581            execution.setVariable(prefix + "failedActivity", "MSO Update VNF")\r
582            logDebug('Exited ' + method, isDebugLogEnabled)\r
583            \r
584    }\r
585         \r
586         /**\r
587          * Builds a "FalloutHandler" request and stores it in the specified execution variable.\r
588          *\r
589          * @param execution the execution\r
590          * @param resultVar the execution variable in which the result will be stored\r
591          */\r
592         public void falloutHandlerPrep(Execution execution, String resultVar) {\r
593                 def method = getClass().getSimpleName() + '.falloutHandlerPrep(' +\r
594                         'execution=' + execution.getId() +\r
595                         ', resultVar=' + resultVar +\r
596                         ')'\r
597                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
598                 logDebug('Entered ' + method, isDebugLogEnabled)\r
599 \r
600                 try {\r
601                         def prefix = execution.getVariable('prefix')\r
602                         def request = getVariable(execution, prefix+'Request')\r
603                         def requestInformation = execution.getVariable(prefix + "requestInfo")          \r
604                         \r
605                         appcClient.shutdownclient()\r
606 \r
607                         def WorkflowException workflowException = execution.getVariable("WorkflowException")\r
608                         def errorResponseCode = workflowException.getErrorCode()\r
609                         def errorResponseMsg = workflowException.getErrorMessage()\r
610                         def encErrorResponseMsg = ""\r
611                         if (errorResponseMsg != null) {\r
612                                 encErrorResponseMsg = errorResponseMsg.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")\r
613                         }\r
614 \r
615                         String content = """\r
616                                 <sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"\r
617                                                 xmlns:reqtype="http://org.openecomp/mso/request/types/v1"\r
618                                                 xmlns:msoservtypes="http://org.openecomp/mso/request/types/v1"\r
619                                                 xmlns:structuredtypes="http://org.openecomp/mso/structured/types/v1">\r
620                                         ${requestInformation}\r
621                                         <sdncadapterworkflow:WorkflowException>\r
622                                                 <sdncadapterworkflow:ErrorMessage>${encErrorResponseMsg}</sdncadapterworkflow:ErrorMessage>\r
623                                                 <sdncadapterworkflow:ErrorCode>${errorResponseCode}</sdncadapterworkflow:ErrorCode>\r
624                                         </sdncadapterworkflow:WorkflowException>\r
625                                 </sdncadapterworkflow:FalloutHandlerRequest>\r
626                         """\r
627                         content = utils.formatXml(content)\r
628                         logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)\r
629                         execution.setVariable(resultVar, content)\r
630 \r
631                         logDebug('Exited ' + method, isDebugLogEnabled)\r
632                 } catch (BpmnError e) {\r
633                         throw e;\r
634                 } catch (Exception e) {\r
635                         logError('Caught exception in ' + method, e)\r
636                         exceptionUtil.buildWorkflowException(execution, 2000, 'Internal Error')\r
637                 }\r
638         }\r
639         \r
640         /**\r
641          * Handle Abort disposition from RainyDayHandler\r
642          *\r
643          * @param execution The flow's execution instance.       \r
644          */\r
645         public void abortProcessing(Execution execution) {\r
646                 def method = getClass().getSimpleName() + '.abortProcessing(' +\r
647                         'execution=' + execution.getId() +\r
648                         ')'\r
649                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
650                 logDebug('Entered ' + method, isDebugLogEnabled)\r
651                 \r
652                 def errorText = execution.getVariable(prefix + "errorText")\r
653                 def errorCode = execution.getVariable(prefix + "errorCode")\r
654                 \r
655                 exceptionUtil.buildAndThrowWorkflowException(execution, errorCode as Integer, errorText)\r
656         }\r
657         \r
658         /**\r
659          * Handle Manual disposition from RainyDayHandler\r
660          *\r
661          * @param execution The flow's execution instance. \r
662          */\r
663         public void manualProcessing(Execution execution) {\r
664                 def method = getClass().getSimpleName() + '.manualProcessing(' +\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 taskId = execution.getVariable("UPDVnfI_taskId")            \r
671                 \r
672                 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Processing halted - manual task created: " + taskId)\r
673         }\r
674 \r
675         \r
676 }\r