2c1b66ded5e58d424b4462cab5298cd728dcaac3
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  * 
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  * ============LICENSE_END=========================================================
18  */
19
20 package org.onap.so.bpmn.infrastructure.scripts
21
22 import org.camunda.bpm.engine.delegate.BpmnError
23 import org.camunda.bpm.engine.delegate.DelegateExecution
24 import org.onap.appc.client.lcm.model.Action
25 import org.onap.appc.client.lcm.model.ActionIdentifiers
26 import org.onap.appc.client.lcm.model.Flags
27 import org.onap.appc.client.lcm.model.Status
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil
29 import org.onap.so.bpmn.common.scripts.MsoUtils
30 import org.onap.so.bpmn.core.json.JsonUtils
31 import org.onap.so.client.aai.*
32 import org.onap.so.client.aai.entities.AAIResultWrapper
33 import org.onap.so.client.aai.entities.uri.AAIUri
34 import org.onap.so.client.aai.entities.uri.AAIUriFactory
35 import org.onap.so.client.appc.ApplicationControllerClient;
36 import org.onap.so.client.appc.ApplicationControllerSupport;
37 import org.onap.so.logger.MessageEnum
38 import org.onap.so.logger.MsoLogger
39
40 import groovy.json.JsonOutput
41 import groovy.json.JsonSlurper
42
43 public class VnfInPlaceUpdate extends VnfCmBase {
44         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, VnfInPlaceUpdate.class);
45
46         ExceptionUtil exceptionUtil = new ExceptionUtil()
47         JsonUtils jsonUtils = new JsonUtils()
48         def prefix = "VnfIPU_"
49
50         /**
51          * Initialize the flow's variables.
52          *
53          * @param execution The flow's execution instance.
54          */
55         public void initProcessVariables(DelegateExecution execution) {
56                 execution.setVariable('prefix', 'VnfIPU_')
57                 execution.setVariable('Request', null)
58                 execution.setVariable('requestInfo', null)
59                 execution.setVariable('source', null)
60                 execution.setVariable('vnfInputs', null)
61                 execution.setVariable('tenantId', null)
62                 execution.setVariable('vnfParams', null)
63                 execution.setVariable('controllerType', null)           
64                 execution.setVariable('UpdateVnfSuccessIndicator', false)
65                 execution.setVariable('serviceType', null)
66                 execution.setVariable('nfRole', null)
67                 execution.setVariable('currentActivity', 'VnfIPU')
68                 execution.setVariable('workStep', null)
69                 execution.setVariable('failedActivity', null)
70                 execution.setVariable('errorCode', "0")
71                 execution.setVariable('errorText', null)
72                 execution.setVariable('healthCheckIndex0', 0)
73                 execution.setVariable('healthCheckIndex1', 1)
74                 execution.setVariable('maxRetryCount', 3)
75                 execution.setVariable("rollbackSetClosedLoopDisabledFlag", false)
76                 execution.setVariable("rollbackVnfStop", false)
77                 execution.setVariable("rollbackVnfLock", false)
78                 execution.setVariable("rollbackQuiesceTraffic", false)
79                 execution.setVariable("rollbackSetVnfInMaintenanceFlag", false)
80         }
81
82         /**
83          * Check for missing elements in the received request.
84          *
85          * @param execution The flow's execution instance.
86          */
87         public void preProcessRequest(DelegateExecution execution) {
88                 def method = getClass().getSimpleName() + '.preProcessRequest(' +
89                                 'execution=' + execution.getId() +
90                                 ')'
91                 initProcessVariables(execution)
92
93                 msoLogger.trace('Entered ' + method)
94
95                 initProcessVariables(execution)
96
97                 def incomingRequest = execution.getVariable('bpmnRequest')
98
99                 msoLogger.debug("Incoming Infra Request: " + incomingRequest)
100                 try {
101                         def jsonSlurper = new JsonSlurper()
102                         def jsonOutput = new JsonOutput()
103                         Map reqMap = jsonSlurper.parseText(incomingRequest)
104                         msoLogger.debug(" Request is in JSON format.")
105
106                         def serviceInstanceId = execution.getVariable('serviceInstanceId')
107                         def vnfId = execution.getVariable('vnfId')
108
109                         execution.setVariable('serviceInstanceId', serviceInstanceId)
110                         execution.setVariable('vnfId', vnfId)
111                         execution.setVariable("isVidRequest", "true")
112                         execution.setVariable('serviceType', 'Mobility')
113                         execution.setVariable('payload', "")
114                         execution.setVariable('actionSnapshot', Action.Snapshot)
115                         execution.setVariable('actionLock', Action.Lock)
116                         execution.setVariable('actionUnlock', Action.Unlock)
117                         execution.setVariable('actionUpgradePreCheck', Action.UpgradePreCheck)
118                         execution.setVariable('actionUpgradePostCheck', Action.UpgradePostCheck)
119                         execution.setVariable('actionQuiesceTraffic', Action.QuiesceTraffic)
120                         execution.setVariable('actionUpgradeBackup', Action.UpgradeBackup)
121                         execution.setVariable('actionUpgradeSoftware', Action.UpgradeSoftware)
122                         execution.setVariable('actionResumeTraffic', Action.ResumeTraffic)
123
124
125                         def controllerType = reqMap.requestDetails?.requestParameters?.controllerType
126                         execution.setVariable('controllerType', controllerType)
127                         
128                         msoLogger.debug('Controller Type: ' + controllerType)
129                 
130                         def payload = reqMap.requestDetails?.requestParameters?.payload
131                         execution.setVariable('payload', payload)
132
133                         msoLogger.debug('Processed payload: ' + payload)
134
135
136                         def requestId = execution.getVariable("mso-request-id")
137                         execution.setVariable('requestId', requestId)
138                         execution.setVariable('msoRequestId', requestId)
139
140                         def requestorId = reqMap.requestDetails?.requestInfo?.requestorId ?: null
141                         execution.setVariable('requestorId', requestorId)
142
143                         def cloudConfiguration = reqMap.requestDetails?.cloudConfiguration
144                         def lcpCloudRegionId    = cloudConfiguration.lcpCloudRegionId
145                         execution.setVariable('lcpCloudRegionId', lcpCloudRegionId)
146                         def cloudOwner  = cloudConfiguration.cloudOwner
147                         execution.setVariable('cloudOwner', cloudOwner)
148                         def tenantId = cloudConfiguration.tenantId
149                         execution.setVariable('tenantId', tenantId)
150
151                         execution.setVariable("UpdateVnfInfraSuccessIndicator", false)
152
153
154
155                         def source = reqMap.requestDetails?.requestInfo?.source
156                         execution.setVariable("source", source)
157
158                         //For Completion Handler & Fallout Handler
159                         String requestInfo =
160                                         """<request-info xmlns="http://org.onap/so/infra/vnf-request/v1">
161                                         <request-id>${MsoUtils.xmlEscape(requestId)}</request-id>
162                                         <action>UPDATE</action>
163                                         <source>${MsoUtils.xmlEscape(source)}</source>
164                                    </request-info>"""
165
166                         execution.setVariable("requestInfo", requestInfo)
167
168                         msoLogger.debug('RequestInfo: ' + execution.getVariable("requestInfo"))
169
170                         msoLogger.trace('Exited ' + method)
171
172                 }
173                 catch(groovy.json.JsonException je) {
174                         msoLogger.debug(" Request is not in JSON format.")
175                         exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Invalid request format")
176                 }
177                 catch(Exception e) {
178                         String restFaultMessage = e.getMessage()
179                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, " Exception Encountered - " + "\n" + restFaultMessage, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
180                         exceptionUtil.buildAndThrowWorkflowException(execution, 5000, restFaultMessage)
181                 }
182         }
183
184         /**
185          * Prepare and send the sychronous response for this flow.
186          *
187          * @param execution The flow's execution instance.
188          */
189         public void sendSynchResponse(DelegateExecution execution) {
190                 def method = getClass().getSimpleName() + '.sendSynchResponse(' +
191                                 'execution=' + execution.getId() +
192                                 ')'
193
194                 msoLogger.trace('Entered ' + method)
195
196
197                 try {
198                         def requestInfo = execution.getVariable('requestInfo')
199                         def requestId = execution.getVariable('requestId')
200                         def source = execution.getVariable('source')
201                         def progress = getNodeTextForce(requestInfo, 'progress')
202                         if (progress.isEmpty()) {
203                                 progress = '0'
204                         }
205                         def startTime = getNodeTextForce(requestInfo, 'start-time')
206                         if (startTime.isEmpty()) {
207                                 startTime = System.currentTimeMillis()
208                         }
209
210                         // RESTResponse (for API Handler (APIH) Reply Task)
211                         def vnfId = execution.getVariable("vnfId")
212                         String synchResponse = """{"requestReferences":{"instanceId":"${vnfId}","requestId":"${requestId}"}}""".trim()
213
214                         sendWorkflowResponse(execution, 200, synchResponse)
215
216                         msoLogger.trace('Exited ' + method)
217                 } catch (BpmnError e) {
218                         throw e;
219                 } catch (Exception e) {
220                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
221                         exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())
222                 }
223         }
224
225
226         /**
227          * Check if this VNF is already in maintenance in A&AI.
228          *
229          *
230          * @param execution The flow's execution instance.
231          */
232         public void checkIfVnfInMaintInAAI(DelegateExecution execution) {
233                 def method = getClass().getSimpleName() + '.checkIfVnfInMaintInAAI(' +
234                                 'execution=' + execution.getId() +
235                                 ')'
236
237                 execution.setVariable('errorCode', "0")
238                 execution.setVariable("workStep", "checkIfVnfInMaintInAAI")
239                 execution.setVariable("failedActivity", "AAI")
240                 msoLogger.trace('Entered ' + method)
241
242                 try {
243                         def transactionLoggingUuid = UUID.randomUUID().toString()
244                         AAIRestClientImpl client = new AAIRestClientImpl()
245                         AAIValidatorImpl aaiValidator = new AAIValidatorImpl()
246                         aaiValidator.setClient(client)
247                         def vnfId = execution.getVariable("vnfId")
248                         boolean isInMaint = aaiValidator.isVNFLocked(vnfId, transactionLoggingUuid)
249                         msoLogger.debug("isInMaint result: " + isInMaint)
250                         execution.setVariable('isVnfInMaintenance', isInMaint)
251
252                         if (isInMaint) {
253                                 execution.setVariable("errorCode", "1003")
254                                 execution.setVariable("errorText", "VNF is in maintenance in A&AI")
255                         }
256
257
258                         msoLogger.trace('Exited ' + method)
259                 } catch (BpmnError e) {
260                         throw e;
261                 } catch (Exception e) {
262                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
263                         execution.setVariable("errorCode", "1002")
264                         execution.setVariable("errorText", e.getMessage())
265                         //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in checkIfVnfInMaintInAAI(): ' + e.getMessage())
266                 }
267         }
268
269
270         /**
271          * Check if this VNF's pservers are locked in A&AI.
272          *
273          *
274          * @param execution The flow's execution instance.
275          */
276         public void checkIfPserversInMaintInAAI(DelegateExecution execution) {
277                 def method = getClass().getSimpleName() + '.checkIfPserversInMaintInAAI(' +
278                                 'execution=' + execution.getId() +
279                                 ')'
280
281                 execution.setVariable('errorCode', "0")
282                 msoLogger.trace('Entered ' + method)
283                 execution.setVariable("workStep", "checkIfPserversInMaintInAAI")
284                 execution.setVariable("failedActivity", "AAI")
285
286                 try {
287                         def transactionLoggingUuid = UUID.randomUUID().toString()
288                         AAIRestClientImpl client = new AAIRestClientImpl()
289                         AAIValidatorImpl aaiValidator = new AAIValidatorImpl()
290                         aaiValidator.setClient(client)
291                         def vnfId = execution.getVariable("vnfId")
292                         boolean areLocked = aaiValidator.isPhysicalServerLocked(vnfId, transactionLoggingUuid)
293                         msoLogger.debug("areLocked result: " + areLocked)
294                         execution.setVariable('arePserversLocked', areLocked)
295
296                         if (areLocked) {
297                                 execution.setVariable("errorCode", "1003")
298                                 execution.setVariable("errorText", "pServers are locked in A&AI")
299                         }
300
301                         msoLogger.trace('Exited ' + method)
302                 } catch (BpmnError e) {
303                         throw e;
304                 } catch (Exception e) {
305                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
306                         execution.setVariable("errorCode", "1002")
307                         execution.setVariable("errorText", e.getMessage())
308                         //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in checkIfPserversInMaintInAAI(): ' + e.getMessage())
309                 }
310         }
311
312         /**
313          * Set inMaint flag for this VNF to the specified value in A&AI.
314          *
315          *
316          * @param execution The flow's execution instance.
317          * @param inMaint The boolean value of the flag to set
318          */
319         public void setVnfInMaintFlagInAAI(DelegateExecution execution, boolean inMaint) {
320                 def method = getClass().getSimpleName() + '.setVnfInMaintFlagInAAI(' +
321                                 'execution=' + execution.getId() +
322                                 ')'
323
324                 execution.setVariable('errorCode', "0")
325                 msoLogger.trace('Entered ' + method)
326                 if (inMaint) {
327                         execution.setVariable("workStep", "setVnfInMaintFlagInAAI")
328                 }
329                 else {
330                         execution.setVariable("workStep", "unsetVnfInMaintFlagInAAI")
331                 }
332                 execution.setVariable("failedActivity", "AAI")
333
334                 try {
335                         def transactionLoggingUuid = UUID.randomUUID().toString()
336                         AAIRestClientImpl client = new AAIRestClientImpl()
337                         AAIUpdatorImpl aaiUpdator = new AAIUpdatorImpl()
338                         aaiUpdator.setClient(client)
339                         def vnfId = execution.getVariable("vnfId")
340                         if (inMaint) {
341                                 aaiUpdator.updateVnfToLocked(vnfId, transactionLoggingUuid)
342                                 execution.setVariable("rollbackSetVnfInMaintenanceFlag", true)
343                         }
344                         else {
345                                 aaiUpdator.updateVnfToUnLocked(vnfId, transactionLoggingUuid)
346                         }
347
348                         msoLogger.trace('Exited ' + method)
349                 } catch (BpmnError e) {
350                         throw e;
351                 } catch (Exception e) {
352                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
353                         execution.setVariable("errorCode", "1002")
354                         execution.setVariable("errorText", e.getMessage())
355                         //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in setVnfInMaintFlagInAAI(): ' + e.getMessage())
356                 }
357         }
358
359         /**
360          * Check if VF Closed Loop Disabled in A&AI.
361          *
362          *
363          * @param execution The flow's execution instance.
364          */
365         public void checkIfClosedLoopDisabledInAAI(DelegateExecution execution) {
366                 def method = getClass().getSimpleName() + '.checkIfClosedLoopDisabledInAAI(' +
367                                 'execution=' + execution.getId() +
368                                 ')'
369
370                 execution.setVariable('errorCode', "0")
371                 execution.setVariable("workStep", "checkClosedLoopDisabledFlagInAAI")
372                 execution.setVariable("failedActivity", "AAI")
373                 msoLogger.trace('Entered ' + method)
374
375                 try {
376                         def transactionLoggingUuid = UUID.randomUUID().toString()
377                         def vnfId = execution.getVariable("vnfId")
378                         msoLogger.debug("vnfId is: " + vnfId)
379                         AAIResourcesClient client = new AAIResourcesClient()
380                         AAIUri genericVnfUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
381                         AAIResultWrapper aaiRW = client.get(genericVnfUri)
382                         Map<String, Object> result = aaiRW.asMap()
383                         boolean isClosedLoopDisabled = result.getOrDefault("is-closed-loop-disabled", false)
384
385                         msoLogger.debug("isClosedLoopDisabled result: " + isClosedLoopDisabled)
386                         execution.setVariable('isClosedLoopDisabled', isClosedLoopDisabled)
387
388                         if (isClosedLoopDisabled) {
389                                 execution.setVariable("errorCode", "1004")
390                                 execution.setVariable("errorText", "closedLoop is disabled in A&AI")
391                         }
392
393                         msoLogger.trace('Exited ' + method)
394                 } catch (BpmnError e) {
395                         throw e;
396                 } catch (Exception e) {
397                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
398                         execution.setVariable("errorCode", "1002")
399                         execution.setVariable("errorText", e.getMessage())
400                 }
401         }
402
403         /**
404          * Set VF Closed Loop Disabled Flag in A&AI.
405          *
406          *
407          * @param execution The flow's execution instance.
408          */
409         public void setClosedLoopDisabledInAAI(DelegateExecution execution, boolean setDisabled) {
410                 def method = getClass().getSimpleName() + '.setClosedLoopDisabledInAAI(' +
411                                 'execution=' + execution.getId() +
412                                 ')'
413
414                 execution.setVariable('errorCode', "0")
415                 if (setDisabled) {
416                         execution.setVariable("workStep", "setClosedLoopDisabledFlagInAAI")
417                         execution.setVariable("rollbackSetClosedLoopDisabledFlag", true)
418                 }
419                 else {
420                         execution.setVariable("workStep", "unsetClosedLoopDisabledFlagInAAI")
421                 }
422
423                 execution.setVariable("failedActivity", "AAI")
424                 msoLogger.trace('Entered ' + method)
425
426                 try {
427                         def transactionLoggingUuid = UUID.randomUUID().toString()
428                         def vnfId = execution.getVariable("vnfId")
429                         AAIResourcesClient client = new AAIResourcesClient()
430                         AAIUri genericVnfUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
431
432                         Map<String, Boolean> request = new HashMap<>()
433                         request.put("is-closed-loop-disabled", setDisabled)
434                         client.update(genericVnfUri, request)
435                         msoLogger.debug("set isClosedLoop to: " + setDisabled)
436
437                         msoLogger.trace('Exited ' + method)
438                 } catch (BpmnError e) {
439                         throw e;
440                 } catch (Exception e) {
441                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
442                         execution.setVariable("errorCode", "1002")
443                         execution.setVariable("errorText", e.getMessage())
444                 }
445         }
446
447
448
449
450         /**
451          * Call APP-C client to execute specified APP-C command for this VNF.
452          *
453          *
454          * @param execution The flow's execution instance.
455          * @param action The action to take in APP-C.
456          */
457         public void runAppcCommand(DelegateExecution execution, Action action) {
458                 def method = getClass().getSimpleName() + '.runAppcCommand(' +
459                                 'execution=' + execution.getId() +
460                                 ')'
461
462                 execution.setVariable('errorCode', "0")
463                 msoLogger.trace('Entered ' + method)
464
465                 ApplicationControllerClient appcClient = null
466
467                 try {
468                         msoLogger.debug("Running APP-C action: " + action.toString())
469                         String vnfId = execution.getVariable('vnfId')
470                         String msoRequestId = execution.getVariable('requestId')
471                         execution.setVariable('msoRequestId', msoRequestId)
472                         execution.setVariable("failedActivity", "APP-C")
473
474                         appcClient = new ApplicationControllerClient()
475                         ApplicationControllerSupport support = new ApplicationControllerSupport()
476                         appcClient.appCSupport=support
477                         org.springframework.test.util.ReflectionTestUtils.setField(support, "lcmModelPackage", "org.onap.appc.client.lcm.model");
478                         Flags flags = new Flags();
479                         ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
480                         actionIdentifiers.setVnfId(vnfId);
481                         Status appcStatus
482                         switch(action) {
483                                 case Action.Lock:
484                                         execution.setVariable('workStep', "LockVNF")
485                                         appcStatus = appcClient.runCommand(Action.Lock,actionIdentifiers,null,msoRequestId)
486                                         break
487                                 case Action.Unlock:
488                                         execution.setVariable('workStep', "UnlockVNF")
489                                         appcStatus = appcClient.runCommand(Action.Unlock,actionIdentifiers,null,msoRequestId)
490                                         break
491                                 case Action.HealthCheck:
492                                         def healthCheckIndex = execution.getVariable('healthCheckIndex')
493                                         execution.setVariable('workStep', "HealthCheckVNF" + healthCheckIndex)
494                                         execution.setVariable('healthCheckIndex', healthCheckIndex + 1)
495                                         appcStatus = appcClient.runCommand(Action.HealthCheck,actionIdentifiers,null,msoRequestId)
496                                         break
497                                 case Action.Start:
498                                         execution.setVariable('workStep', "StartVNF")
499                                         appcStatus = appcClient.runCommand(Action.Start,actionIdentifiers,null,msoRequestId)
500                                         break
501                                 case Action.Stop:
502                                         execution.setVariable('workStep', "StopVNF")
503                                         appcStatus = appcClient.runCommand(Action.Stop,actionIdentifiers,null,msoRequestId)
504                                         break
505                                 default:
506                                         break
507                         }
508                         msoLogger.debug("Completed AppC request")
509                         int appcCode = appcStatus.getCode()
510                         msoLogger.debug("AppC status code is: " + appcCode)
511                         msoLogger.debug("AppC status message is: " + appcStatus.getMessage())
512                         if (support.getCategoryOf(appcStatus) == ApplicationControllerSupport.StatusCategory.ERROR) {
513                                 execution.setVariable("errorCode", Integer.toString(appcCode))
514                                 execution.setVariable("errorText", appcStatus.getMessage())
515                         }
516
517                         msoLogger.trace('Exited ' + method)
518                 } catch (BpmnError e) {
519                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
520                         execution.setVariable("errorCode", "1002")
521                         execution.setVariable("errorText", e.getMessage())
522                 } catch (java.lang.NoSuchMethodError e) {
523                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
524                         execution.setVariable("errorCode", "1002")
525                         execution.setVariable("errorText", e.getMessage())
526                 } catch (Exception e) {
527                         msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
528                         execution.setVariable("errorCode", "1002")
529                         execution.setVariable("errorText", e.getMessage())
530                 }
531         }
532
533         /**
534          * Placeholder for a call to APP-C client to execute specified APP-C command for this VNF.
535          *
536          *
537          * @param execution The flow's execution instance.
538          * @param action The action to take in APP-C.
539          */
540         public void runAppcCommandPlaceholder(DelegateExecution execution, String action) {
541                 def method = getClass().getSimpleName() + '.runAppcCommandPlaceholder(' +
542                                 'execution=' + execution.getId() +
543                                 ')'
544
545                 execution.setVariable('errorCode', "0")
546                 msoLogger.trace('Entered ' + method)
547                 execution.setVariable("failedActivity", "APP-C")
548                 execution.setVariable("workStep", action)
549         }
550
551
552
553         /**
554          * Handle Abort disposition from RainyDayHandler
555          *
556          * @param execution The flow's execution instance.       
557          */
558         public void abortProcessing(DelegateExecution execution) {
559                 def method = getClass().getSimpleName() + '.abortProcessing(' +
560                                 'execution=' + execution.getId() +
561                                 ')'
562
563                 msoLogger.trace('Entered ' + method)
564
565                 def errorText = execution.getVariable("errorText")
566                 def errorCode = execution.getVariable("errorCode")
567
568                 exceptionUtil.buildAndThrowWorkflowException(execution, errorCode as Integer, errorText)
569         }
570
571         /**
572          * Increment Retry Count for Current Work Step
573          *
574          * @param execution The flow's execution instance.
575          */
576         public void incrementRetryCount(DelegateExecution execution) {
577                 def method = getClass().getSimpleName() + '.incrementRetryCount(' +
578                                 'execution=' + execution.getId() +
579                                 ')'
580
581                 msoLogger.trace('Entered ' + method)
582
583                 String retryCountVariableName = execution.getVariable("workStep") + "RetryCount"
584                 execution.setVariable("retryCountVariableName", retryCountVariableName)
585
586                 def retryCountVariable = execution.getVariable(retryCountVariableName)
587                 int retryCount = 0
588
589                 if (retryCountVariable != null) {
590                         retryCount = (int) retryCountVariable
591                 }
592
593                 retryCount += 1
594
595                 execution.setVariable(retryCountVariableName, retryCount)
596
597                 msoLogger.debug("value of " + retryCountVariableName + " is " + retryCount)
598                 msoLogger.trace('Exited ' + method)
599         }
600
601 }