Merge "Reorder modifiers"
[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.delegate.DelegateExecution\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.ApplicationControllerOrchestrator\r
49 import org.onap.appc.client.lcm.model.Action;\r
50 import org.onap.appc.client.lcm.model.ActionIdentifiers;\r
51 import org.onap.appc.client.lcm.model.LockInput\r
52 import org.onap.appc.client.lcm.model.UnlockInput\r
53 import org.onap.appc.client.lcm.model.HealthCheckInput\r
54 import org.onap.appc.client.lcm.model.StartInput\r
55 import org.onap.appc.client.lcm.model.Flags\r
56 import org.onap.appc.client.lcm.model.Status\r
57 \r
58 \r
59 \r
60 public class ReplaceVnfInfra extends VnfCmBase {\r
61 \r
62         ExceptionUtil exceptionUtil = new ExceptionUtil()\r
63         JsonUtils jsonUtils = new JsonUtils()           \r
64         def prefix = "RPLVnfI_"\r
65 \r
66         /**\r
67          * Initialize the flow's variables.\r
68          *\r
69          * @param execution The flow's execution instance.\r
70          */\r
71         public void initProcessVariables(DelegateExecution execution) {\r
72                 execution.setVariable('prefix', 'RPLVnfI_')\r
73                 execution.setVariable('Request', null)\r
74                 execution.setVariable('requestInfo', null)              \r
75                 execution.setVariable('source', null)\r
76                 execution.setVariable('vnfInputs', null)                \r
77                 execution.setVariable('tenantId', null)         \r
78                 execution.setVariable('vnfParams', null)\r
79                 execution.setVariable('controllerType', null)\r
80                 execution.setVariable('cloudConfiguration', null)               \r
81                 execution.setVariable('ReplaceVnfSuccessIndicator', false)\r
82                 execution.setVariable('serviceType', null)\r
83                 execution.setVariable('nfRole', null)\r
84                 execution.setVariable('currentActivity', 'RPLVnfI')\r
85                 execution.setVariable('workStep', null)\r
86                 execution.setVariable('failedActivity', null)\r
87                 execution.setVariable('errorCode', "0")\r
88                 execution.setVariable('errorText', null)\r
89                 execution.setVariable('healthCheckIndex', 1)\r
90                 execution.setVariable('retainResources', true)\r
91                 execution.setVariable('productFamilyId', null)\r
92                 execution.setVariable('healthCheckIndex0', 0)\r
93                 execution.setVariable('healthCheckIndex1', 1)\r
94                 execution.setVariable("rollbackSetClosedLoopDisabledFlag", false)\r
95                 execution.setVariable("rollbackVnfStop", false)\r
96                 execution.setVariable("rollbackVnfLock", false)\r
97                 execution.setVariable("rollbackQuiesceTraffic", false)\r
98                 execution.setVariable("rollbackSetVnfInMaintenanceFlag", false)\r
99         }\r
100 \r
101         /**\r
102          * Check for missing elements in the received request.\r
103          *\r
104          * @param execution The flow's execution instance.\r
105          */\r
106         public void preProcessRequest(DelegateExecution execution) {\r
107                 def method = getClass().getSimpleName() + '.preProcessRequest(' +\r
108                 'execution=' + execution.getId() +\r
109                 ')'\r
110                 initProcessVariables(execution)\r
111                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
112                 logDebug('Entered ' + method, isDebugLogEnabled)\r
113 \r
114                 initProcessVariables(execution)         \r
115 \r
116                 def incomingRequest = execution.getVariable('bpmnRequest')\r
117 \r
118                 utils.log("DEBUG", "Incoming Infra Request: " + incomingRequest, isDebugLogEnabled)\r
119                 try {\r
120                         def jsonSlurper = new JsonSlurper()\r
121                         def jsonOutput = new JsonOutput()\r
122                         Map reqMap = jsonSlurper.parseText(incomingRequest)\r
123                         utils.log("DEBUG", " Request is in JSON format.", isDebugLogEnabled)\r
124 \r
125                         def serviceInstanceId = execution.getVariable('serviceInstanceId')\r
126                         def vnfId = execution.getVariable('vnfId')\r
127                         \r
128                         execution.setVariable('serviceInstanceId', serviceInstanceId)                   \r
129                         execution.setVariable("isVidRequest", "true")\r
130                         execution.setVariable('serviceType', 'Mobility')\r
131                         execution.setVariable('retainResources', true)\r
132                         execution.setVariable('disableRollback', true)\r
133                         execution.setVariable('payload', "")\r
134                         execution.setVariable('actionLock', Action.Lock)\r
135                         execution.setVariable('actionUnlock', Action.Unlock)\r
136                         execution.setVariable('actionHealthCheck', Action.HealthCheck)\r
137                         execution.setVariable('actionStart', Action.Start)\r
138                         execution.setVariable('actionStop', Action.Stop)\r
139                         \r
140                         def asdcServiceModelVersion = ''\r
141                         def serviceModelInfo = null\r
142                         \r
143                         def relatedInstanceList = reqMap.requestDetails?.relatedInstanceList\r
144                                                 \r
145                         if (relatedInstanceList != null) {\r
146                                 relatedInstanceList.each {\r
147                                         if (it.relatedInstance.modelInfo?.modelType == 'service') {\r
148                                                 utils.log("DEBUG", "PROCESSING SERVICE INFO", isDebugLogEnabled)\r
149                                                 asdcServiceModelVersion = it.relatedInstance.modelInfo?.modelVersion\r
150                                                 serviceModelInfo = jsonOutput.toJson(it.relatedInstance.modelInfo)\r
151                                                 utils.log("DEBUG", "ServiceModelInfo: " + serviceModelInfo, isDebugLogEnabled)\r
152                                                 def modelInvariant = jsonUtils.getJsonValue(serviceModelInfo, "modelInvariantUuid")\r
153                                                 utils.log("DEBUG", "modelInvariant: " + modelInvariant, isDebugLogEnabled)\r
154                                         }\r
155                                         \r
156                                 }\r
157                         }               \r
158                         \r
159                         execution.setVariable('asdcServiceModelVersion', asdcServiceModelVersion)\r
160                         execution.setVariable('serviceModelInfo', serviceModelInfo)                     \r
161                         def vnfModelInfo = jsonOutput.toJson(reqMap.requestDetails?.modelInfo)\r
162                         execution.setVariable('vnfModelInfo', vnfModelInfo)\r
163                         def vnfModelInvariantUuid = jsonUtils.getJsonValue(vnfModelInfo, "modelInvariantUuid")\r
164                         execution.setVariable('vnfModelInvariantUuid', vnfModelInvariantUuid)   \r
165                         logDebug("vnfModelInvariantUuid: " + vnfModelInvariantUuid, isDebugLogEnabled)  \r
166                         \r
167                         def vnfType = execution.getVariable('vnfType')\r
168                         execution.setVariable('vnfType', vnfType)\r
169                         \r
170                         def controllerType = reqMap.requestDetails?.requestParameters?.controllerType\r
171                         execution.setVariable('controllerType', controllerType)\r
172                         \r
173                         utils.log("DEBUG", 'Controller Type: ' + controllerType, isDebugLogEnabled)     \r
174                         \r
175                         def userParams = reqMap.requestDetails?.requestParameters?.userParams                                   \r
176                         \r
177                         Map<String, String> userParamsMap = [:]\r
178                         if (userParams != null) {\r
179                                 userParams.each { userParam ->\r
180                                         userParamsMap.put(userParam.name, userParam.value.toString())\r
181                                 }                                                       \r
182                         }               \r
183                                                 \r
184                         utils.log("DEBUG", 'Processed user params: ' + userParamsMap, isDebugLogEnabled)                \r
185                         \r
186                         execution.setVariable('vfModuleInputParams', userParamsMap)                     \r
187                                                 \r
188                         def requestId = execution.getVariable("requestId")              \r
189                         execution.setVariable('msoRequestId', requestId)\r
190                         utils.log("DEBUG", "requestId is: " + requestId, isDebugLogEnabled)\r
191                         \r
192                         def vnfName = reqMap.requestDetails?.requestInfo?.instanceName ?: null\r
193                         execution.setVariable('vnfName', vnfName)\r
194                         \r
195                         def requestorId = reqMap.requestDetails?.requestInfo?.requestorId ?: null\r
196                         execution.setVariable('requestorId', requestorId)\r
197                         \r
198                         def usePreload = reqMap.requestDetails?.requestParameters?.usePreload\r
199                         execution.setVariable('usePreload', usePreload)\r
200                         \r
201                         def productFamilyId = reqMap.requestDetails?.requestInfo?.productFamilyId ?: null\r
202                         execution.setVariable('productFamilyId', productFamilyId)\r
203                         \r
204                         def cloudConfiguration = jsonOutput.toJson(reqMap.requestDetails?.cloudConfiguration)           \r
205                         execution.setVariable('cloudConfiguration', cloudConfiguration)\r
206                         def lcpCloudRegionId    = jsonUtils.getJsonValue(cloudConfiguration, "lcpCloudRegionId")\r
207                         execution.setVariable('lcpCloudRegionId', lcpCloudRegionId)\r
208                         def tenantId = jsonUtils.getJsonValue(cloudConfiguration, "tenantId")\r
209                         execution.setVariable('tenantId', tenantId)\r
210                         \r
211                         def globalSubscriberId = reqMap.requestDetails?.subscriberInfo?.globalSubscriberId ?: ''\r
212                         execution.setVariable('globalSubscriberId', globalSubscriberId)\r
213                         \r
214                         execution.setVariable('sdncVersion', '1702')\r
215 \r
216                         execution.setVariable("ReplaceVnfInfraSuccessIndicator", false)\r
217                                                 \r
218                         execution.setVariable("isDebugLogEnabled", isDebugLogEnabled)                   \r
219                         \r
220                         def source = reqMap.requestDetails?.requestInfo?.source\r
221                         execution.setVariable("source", source)\r
222                         \r
223                         //For Completion Handler & Fallout Handler\r
224                         String requestInfo =\r
225                         """<request-info xmlns="http://org.openecomp/mso/infra/vnf-request/v1">\r
226                                         <request-id>${requestId}</request-id>\r
227                                         <action>REPLACE</action>\r
228                                         <source>${source}</source>\r
229                                    </request-info>"""\r
230                         \r
231                         execution.setVariable("requestInfo", requestInfo)                       \r
232                         \r
233                         logDebug('RequestInfo: ' + execution.getVariable("requestInfo"), isDebugLogEnabled)             \r
234                         \r
235                         logDebug('Exited ' + method, isDebugLogEnabled)\r
236 \r
237                 }\r
238                 catch(groovy.json.JsonException je) {\r
239                         utils.log("DEBUG", " Request is not in JSON format.", isDebugLogEnabled)\r
240                         exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Invalid request format")\r
241 \r
242                 }\r
243                 catch(Exception e) {\r
244                         String restFaultMessage = e.getMessage()\r
245                         utils.log("ERROR", " Exception Encountered - " + "\n" + restFaultMessage, isDebugLogEnabled)\r
246                         exceptionUtil.buildAndThrowWorkflowException(execution, 5000, restFaultMessage)\r
247                 }       \r
248         }\r
249 \r
250         /**\r
251          * Prepare and send the sychronous response for this flow.\r
252          *\r
253          * @param execution The flow's execution instance.\r
254          */\r
255         public void sendSynchResponse(DelegateExecution execution) {\r
256                 def method = getClass().getSimpleName() + '.sendSynchResponse(' +\r
257                         'execution=' + execution.getId() +\r
258                         ')'\r
259                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
260                 logDebug('Entered ' + method, isDebugLogEnabled)\r
261 \r
262 \r
263                 try {\r
264                         def requestInfo = execution.getVariable('requestInfo')\r
265                         def requestId = execution.getVariable('requestId')\r
266                         def source = execution.getVariable('source')\r
267                         def progress = getNodeTextForce(requestInfo, 'progress')\r
268                         if (progress.isEmpty()) {\r
269                                 progress = '0'\r
270                         }\r
271                         def startTime = getNodeTextForce(requestInfo, 'start-time')\r
272                         if (startTime.isEmpty()) {\r
273                                 startTime = System.currentTimeMillis()\r
274                         }\r
275 \r
276                         // RESTResponse (for API Handler (APIH) Reply Task)\r
277                         def vnfId = execution.getVariable("vnfId")\r
278                         String synchResponse = """{"requestReferences":{"instanceId":"${vnfId}","requestId":"${requestId}"}}""".trim()\r
279 \r
280                         sendWorkflowResponse(execution, 200, synchResponse)\r
281 \r
282                         logDebug('Exited ' + method, isDebugLogEnabled)\r
283                 } catch (BpmnError e) {\r
284                         throw e;\r
285                 } catch (Exception e) {\r
286                         logError('Caught exception in ' + method, e)\r
287                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())\r
288                 }\r
289         }\r
290         \r
291         \r
292 \r
293         /**\r
294          * Get VnfResource decomposition object for this VNF.\r
295          *      \r
296          *\r
297          * @param execution The flow's execution instance.\r
298          */\r
299         public void getVnfResourceDecomposition(DelegateExecution execution) {\r
300                 def method = getClass().getSimpleName() + '.getVnfResourceDecomposition(' +\r
301                         'execution=' + execution.getId() +\r
302                         ')'\r
303                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
304                 logDebug('Entered ' + method, isDebugLogEnabled)\r
305 \r
306                 try {\r
307                         ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")\r
308                         String vnfModelInvariantUuid = execution.getVariable('vnfModelInvariantUuid')\r
309                         logDebug("vnfModelInvariantUuid: " + vnfModelInvariantUuid, isDebugLogEnabled)\r
310                         List<VnfResource> vnfResources = serviceDecomposition.getServiceVnfs()\r
311                         \r
312                         for (i in 0..vnfResources.size()-1) {\r
313                                 ModelInfo modelInfo = vnfResources[i].getModelInfo()\r
314                                 String modelInvariantUuidFromDecomposition = modelInfo.getModelInvariantUuid()\r
315                                 logDebug("modelInvariantUuidFromDecomposition: " + modelInvariantUuidFromDecomposition, isDebugLogEnabled)\r
316                                 \r
317                                 if (vnfModelInvariantUuid.equals(modelInvariantUuidFromDecomposition)) {\r
318                                         VnfResource vnfResourceDecomposition = vnfResources[i]\r
319                                         execution.setVariable('vnfResourceDecomposition', vnfResourceDecomposition)\r
320                                         def nfRole = vnfResourceDecomposition.getNfRole()                                       \r
321                                         execution.setVariable('nfRole', nfRole)\r
322                                         logDebug("vnfResourceDecomposition: " + vnfResourceDecomposition.toJsonString(), isDebugLogEnabled)                                     \r
323                                         break\r
324                                 }\r
325                                 else {\r
326                                         //exception!\r
327                                 }\r
328                                 \r
329                         }\r
330 \r
331                         logDebug('Exited ' + method, isDebugLogEnabled)\r
332                 } catch (BpmnError e) {\r
333                         throw e;\r
334                 } catch (Exception e) {\r
335                         logError('Caught exception in ' + method, e)\r
336                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in getVnfResourceDecomposition(): ' + e.getMessage())\r
337                 }\r
338         }\r
339         \r
340         /**\r
341          * Check if this VNF is already in maintenance in A&AI.\r
342          *\r
343          *\r
344          * @param execution The flow's execution instance.\r
345          */\r
346         public void checkIfVnfInMaintInAAI(DelegateExecution execution) {\r
347                 def method = getClass().getSimpleName() + '.checkIfVnfInMaintInAAI(' +\r
348                         'execution=' + execution.getId() +\r
349                         ')'\r
350                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
351                 execution.setVariable('errorCode', "0")\r
352                 execution.setVariable("workStep", "checkIfVnfInMaintInAAI")\r
353                 execution.setVariable("failedActivity", "AAI")\r
354                 logDebug('Entered ' + method, isDebugLogEnabled)\r
355 \r
356                 try {\r
357                         def transactionLoggingUuid = UUID.randomUUID().toString()\r
358                         AAIRestClientImpl client = new AAIRestClientImpl()\r
359                         AAIValidatorImpl aaiValidator = new AAIValidatorImpl()\r
360                         aaiValidator.setClient(client)\r
361                         def vnfId = execution.getVariable("vnfId")\r
362                         boolean isInMaint = aaiValidator.isVNFLocked(vnfId, transactionLoggingUuid)\r
363                         logDebug("isInMaint result: " + isInMaint, isDebugLogEnabled)\r
364                         execution.setVariable('isVnfInMaintenance', isInMaint)\r
365                         \r
366                         if (isInMaint) {\r
367                                 execution.setVariable("errorCode", "1003")\r
368                                 execution.setVariable("errorText", "VNF is in maintenance in A&AI")\r
369                         }\r
370 \r
371 \r
372                         logDebug('Exited ' + method, isDebugLogEnabled)\r
373                 } catch (BpmnError e) {\r
374                         throw e;\r
375                 } catch (Exception e) {\r
376                         logError('Caught exception in ' + method, e)\r
377                         execution.setVariable("errorCode", "1002")\r
378                         execution.setVariable("errorText", e.getMessage())\r
379                         //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in checkIfVnfInMaintInAAI(): ' + e.getMessage())\r
380                 }\r
381         }\r
382         \r
383         \r
384         /**\r
385          * Check if this VNF's pservers are locked in A&AI.\r
386          *\r
387          *\r
388          * @param execution The flow's execution instance.\r
389          */\r
390         public void checkIfPserversInMaintInAAI(DelegateExecution execution) {\r
391                 def method = getClass().getSimpleName() + '.checkIfPserversInMaintInAAI(' +\r
392                         'execution=' + execution.getId() +\r
393                         ')'\r
394                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
395                 execution.setVariable('errorCode', "0")\r
396                 logDebug('Entered ' + method, isDebugLogEnabled)\r
397                 execution.setVariable("workStep", "checkIfPserversInMaintInAAI")\r
398                 execution.setVariable("failedActivity", "AAI")\r
399 \r
400                 try {\r
401                         def transactionLoggingUuid = UUID.randomUUID().toString()\r
402                         AAIRestClientImpl client = new AAIRestClientImpl()\r
403                         AAIValidatorImpl aaiValidator = new AAIValidatorImpl()\r
404                         aaiValidator.setClient(client)\r
405                         def vnfId = execution.getVariable("vnfId")                      \r
406                         boolean areLocked = aaiValidator.isPhysicalServerLocked(vnfId, transactionLoggingUuid)\r
407                         logDebug("areLocked result: " + areLocked, isDebugLogEnabled)\r
408                         execution.setVariable('arePserversLocked', areLocked)\r
409                         \r
410                         if (areLocked) {\r
411                                 execution.setVariable("errorCode", "1003")\r
412                                 execution.setVariable("errorText", "pServers are locked in A&AI")\r
413                         }\r
414 \r
415                         logDebug('Exited ' + method, isDebugLogEnabled)\r
416                 } catch (BpmnError e) {\r
417                         throw e;\r
418                 } catch (Exception e) {\r
419                         logError('Caught exception in ' + method, e)\r
420                         execution.setVariable("errorCode", "1002")\r
421                         execution.setVariable("errorText", e.getMessage())\r
422                         //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in checkIfPserversInMaintInAAI(): ' + e.getMessage())\r
423                 }\r
424         }\r
425         \r
426         /**\r
427          * Set inMaint flag for this VNF to the specified value in A&AI.\r
428          *\r
429          *\r
430          * @param execution The flow's execution instance.\r
431          * @param inMaint The boolean value of the flag to set\r
432          */\r
433         public void setVnfInMaintFlagInAAI(DelegateExecution execution, boolean inMaint) {\r
434                 def method = getClass().getSimpleName() + '.setVnfInMaintFlagInAAI(' +\r
435                         'execution=' + execution.getId() +\r
436                         ')'\r
437                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
438                 execution.setVariable('errorCode', "0")\r
439                 logDebug('Entered ' + method, isDebugLogEnabled)\r
440                 if (inMaint) {\r
441                         execution.setVariable("workStep", "setVnfInMaintFlagInAAI")\r
442                 }\r
443                 else {\r
444                         execution.setVariable("workStep", "unsetVnfInMaintFlagInAAI")\r
445                 }\r
446                 execution.setVariable("failedActivity", "AAI")\r
447 \r
448                 try {\r
449                         def transactionLoggingUuid = UUID.randomUUID().toString()\r
450                         AAIRestClientImpl client = new AAIRestClientImpl()\r
451                         AAIUpdatorImpl aaiUpdator = new AAIUpdatorImpl()\r
452                         aaiUpdator.setClient(client)\r
453                         def vnfId = execution.getVariable("vnfId")\r
454                         if (inMaint) {\r
455                                 aaiUpdator.updateVnfToLocked(vnfId, transactionLoggingUuid)\r
456                                 execution.setVariable("rollbackSetVnfInMaintenanceFlag", true)\r
457                         }\r
458                         else {\r
459                                 aaiUpdator.updateVnfToUnLocked(vnfId, transactionLoggingUuid)\r
460                         }\r
461                                                         \r
462                         logDebug('Exited ' + method, isDebugLogEnabled)\r
463                 } catch (BpmnError e) {\r
464                         throw e;\r
465                 } catch (Exception e) {\r
466                         logError('Caught exception in ' + method, e)\r
467                         execution.setVariable("errorCode", "1002")\r
468                         execution.setVariable("errorText", e.getMessage())\r
469                         //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in setVnfInMaintFlagInAAI(): ' + e.getMessage())\r
470                 }\r
471         }\r
472         \r
473         /**\r
474          * Call APP-C client to execute specified APP-C command for this VNF.\r
475          *\r
476          *\r
477          * @param execution The flow's execution instance.\r
478          * @param action The action to take in APP-C.\r
479          */\r
480         public void runAppcCommand(DelegateExecution execution, Action action) {\r
481                 def method = getClass().getSimpleName() + '.runAppcCommand(' +\r
482                         'execution=' + execution.getId() +\r
483                         ')'\r
484                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
485                 execution.setVariable('errorCode', "0")\r
486                 logDebug('Entered ' + method, isDebugLogEnabled)                \r
487                 \r
488                 try {\r
489                         logDebug("Running APP-C action: " + action.toString(), isDebugLogEnabled)\r
490                         String vnfId = execution.getVariable('vnfId')\r
491                         String msoRequestId = execution.getVariable('requestId')\r
492                         execution.setVariable('msoRequestId', msoRequestId)\r
493                         execution.setVariable("failedActivity", "APP-C")\r
494                         execution.setVariable("workStep", action.toString() + "VNF")\r
495                         \r
496                         ApplicationControllerOrchestrator appcClient = new ApplicationControllerOrchestrator()                  \r
497                         Status appcStatus = null\r
498                         switch(action) {\r
499                                 case Action.Lock:\r
500                                         execution.setVariable('workStep', "LockVNF")\r
501                                         appcStatus = appcClient.runCommand(Action.Lock,msoRequestId,vnfId,null)\r
502                                         break\r
503                                 case Action.Unlock:\r
504                                         execution.setVariable('workStep', "UnlockVNF")\r
505                                         appcStatus = appcClient.runCommand(Action.Unlock,msoRequestId,vnfId,null)\r
506                                         break\r
507                                 case Action.HealthCheck:\r
508                                         def healthCheckIndex = execution.getVariable('healthCheckIndex')\r
509                                         execution.setVariable('workStep', "HealthCheckVNF" + healthCheckIndex)\r
510                                         execution.setVariable('healthCheckIndex', healthCheckIndex + 1)\r
511                                         appcStatus = appcClient.runCommand(Action.HealthCheck,msoRequestId,vnfId,null)\r
512                                         break\r
513                                 case Action.Start:\r
514                                         execution.setVariable('workStep', "StartVNF")\r
515                                         appcStatus = appcClient.runCommand(Action.Start,msoRequestId,vnfId,null)\r
516                                         break\r
517                                 case Action.Stop:\r
518                                         execution.setVariable('workStep', "StopVNF")\r
519                                         appcStatus = appcClient.runCommand(Action.Stop,msoRequestId,vnfId,null)\r
520                                         break\r
521                                 default:\r
522                                         break\r
523                         }\r
524                         logDebug("Completed AppC request", isDebugLogEnabled)\r
525                         int appcCode = appcStatus.getCode()\r
526                         logDebug("AppC status code is: " + appcCode, isDebugLogEnabled)\r
527                         logDebug("AppC status message is: " + appcStatus.getMessage(), isDebugLogEnabled)\r
528                         if (support.getCategoryOf(appcStatus) == ApplicationControllerSupport.StatusCategory.ERROR) {\r
529                                 execution.setVariable("errorCode", Integer.toString(appcCode))\r
530                                 execution.setVariable("errorText", appcStatus.getMessage())\r
531                         }\r
532                         \r
533                         logDebug('Exited ' + method, isDebugLogEnabled)\r
534                 } catch (BpmnError e) {\r
535                         logError('Caught exception in ' + method, e)\r
536                         execution.setVariable("errorCode", "1002")\r
537                         execution.setVariable("errorText", e.getMessage())                      \r
538                 } catch (java.lang.NoSuchMethodError e) {\r
539                         logError('Caught exception in ' + method, e)\r
540                         execution.setVariable("errorCode", "1002")\r
541                         execution.setVariable("errorText", e.getMessage())                              \r
542                 } catch (Exception e) {\r
543                         logError('Caught exception in ' + method, e)\r
544                         execution.setVariable("errorCode", "1002")\r
545                         execution.setVariable("errorText", e.getMessage())                      \r
546                 }\r
547         }\r
548 \r
549 \r
550         \r
551         /**\r
552         * Prepare DoDeleteVnfAndModules call.\r
553         *\r
554         *\r
555         * @param execution The flow's execution instance.\r
556         */\r
557    public void prepDoDeleteVnfAndModules(DelegateExecution execution) {\r
558            def method = getClass().getSimpleName() + '.prepDoDeleteVnfAndModules(' +\r
559                    'execution=' + execution.getId() +\r
560                    ')'\r
561            def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled') \r
562            execution.setVariable('errorCode', "0")\r
563            logDebug('Entered ' + method, isDebugLogEnabled)\r
564            execution.setVariable("workStep", "doDeleteVnfAndModules")\r
565            execution.setVariable("failedActivity", "MSO Delete VNF")\r
566            logDebug('Exited ' + method, isDebugLogEnabled)\r
567            \r
568    }\r
569    \r
570    /**\r
571         * Prepare DoCreateVnfAndModules call.\r
572         *\r
573         *\r
574         * @param execution The flow's execution instance.\r
575         */\r
576    public void prepDoCreateVnfAndModules(DelegateExecution execution) {\r
577            def method = getClass().getSimpleName() + '.prepDoReplaceVnfAndModules(' +\r
578                    'execution=' + execution.getId() +\r
579                    ')'\r
580            def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
581            execution.setVariable('errorCode', "0")\r
582            logDebug('Entered ' + method, isDebugLogEnabled)\r
583            execution.setVariable("workStep", "doCreateVnfAndModules")\r
584            execution.setVariable("failedActivity", "MSO Create VNF")\r
585            logDebug('Exited ' + method, isDebugLogEnabled)\r
586            \r
587    }\r
588         \r
589         \r
590         /**\r
591          * Handle Abort disposition from RainyDayHandler\r
592          *       \r
593          * @param execution The flow's execution instance.      \r
594          */\r
595         public void abortProcessing(DelegateExecution execution) {\r
596                 def method = getClass().getSimpleName() + '.abortProcessing(' +\r
597                         'execution=' + execution.getId() +\r
598                         ')'\r
599                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
600                 logDebug('Entered ' + method, isDebugLogEnabled)\r
601                 \r
602                 def errorText = execution.getVariable("errorText")\r
603                 def errorCode = execution.getVariable("errorCode")\r
604                 \r
605                 exceptionUtil.buildAndThrowWorkflowException(execution, errorCode as Integer, errorText)\r
606         }\r
607         \r
608         /**\r
609          * Handle Manual disposition from RainyDayHandler\r
610          *\r
611          * @param execution The flow's execution instance.\r
612          */\r
613         public void manualProcessing(DelegateExecution execution) {\r
614                 def method = getClass().getSimpleName() + '.manualProcessing(' +\r
615                         'execution=' + execution.getId() +\r
616                         ')'\r
617                 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')\r
618                 logDebug('Entered ' + method, isDebugLogEnabled)\r
619                 \r
620                 def taskId = execution.getVariable("taskId")\r
621                 \r
622                 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, "Processing halted - manual task created: " + taskId)\r
623         }\r
624 \r
625         \r
626 }\r