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