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