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