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