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