2 * ============LICENSE_START=======================================================
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
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=========================================================
20 package org.openecomp.mso.bpmn.infrastructure.scripts
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
28 import org.json.JSONArray
29 import org.json.JSONObject
31 import java.io.Serializable;
33 import java.util.UUID;
34 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil
35 import org.camunda.bpm.engine.delegate.BpmnError
36 import org.camunda.bpm.engine.impl.cmd.AbstractSetVariableCmd
37 import org.camunda.bpm.engine.delegate.DelegateExecution
38 import org.openecomp.mso.rest.APIResponse
39 import org.openecomp.mso.rest.RESTClient
40 import org.openecomp.mso.rest.RESTConfig
41 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor;
42 import org.openecomp.mso.bpmn.common.scripts.VidUtils;
43 import org.openecomp.mso.bpmn.core.RollbackData
44 import org.openecomp.mso.bpmn.core.WorkflowException
45 import org.openecomp.mso.bpmn.core.json.JsonUtils
46 import org.openecomp.mso.bpmn.core.domain.ModelInfo
47 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition
48 import org.openecomp.mso.bpmn.core.domain.VnfResource
49 import org.openecomp.mso.client.aai.*
51 import org.openecomp.mso.client.appc.ApplicationControllerClient;
52 import org.openecomp.mso.client.appc.ApplicationControllerSupport;
53 import org.openecomp.mso.client.aai.entities.AAIResultWrapper
54 import org.openecomp.mso.client.aai.entities.Relationships
55 import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri
56 import org.openecomp.mso.client.aai.entities.uri.AAIUri
57 import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory
58 import org.onap.appc.client.lcm.model.Action;
59 import org.onap.appc.client.lcm.model.ActionIdentifiers;
60 import org.onap.appc.client.lcm.model.LockInput
61 import org.onap.appc.client.lcm.model.UnlockInput
62 import org.onap.appc.client.lcm.model.HealthCheckInput
63 import org.onap.appc.client.lcm.model.StartInput
64 import org.onap.appc.client.lcm.model.StopInput
65 import org.onap.appc.client.lcm.model.Flags
66 import org.onap.appc.client.lcm.model.Status
70 public abstract class VnfCmBase extends AbstractServiceTaskProcessor {
72 ExceptionUtil exceptionUtil = new ExceptionUtil()
73 JsonUtils jsonUtils = new JsonUtils()
74 def prefix = "VnfIPU_"
77 * Initialize the flow's variables.
79 * @param execution The flow's execution instance.
83 * Prepare and send the sychronous response for this flow.
85 * @param execution The flow's execution instance.
87 public void sendSynchResponse(DelegateExecution execution) {
88 def method = getClass().getSimpleName() + '.sendSynchResponse(' +
89 'execution=' + execution.getId() +
91 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
92 logDebug('Entered ' + method, isDebugLogEnabled)
96 def requestInfo = execution.getVariable('requestInfo')
97 def requestId = execution.getVariable('requestId')
98 def source = execution.getVariable('source')
99 def progress = getNodeTextForce(requestInfo, 'progress')
100 if (progress.isEmpty()) {
103 def startTime = getNodeTextForce(requestInfo, 'start-time')
104 if (startTime.isEmpty()) {
105 startTime = System.currentTimeMillis()
108 // RESTResponse (for API Handler (APIH) Reply Task)
109 def vnfId = execution.getVariable("vnfId")
110 String synchResponse = """{"requestReferences":{"instanceId":"${vnfId}","requestId":"${requestId}"}}""".trim()
112 sendWorkflowResponse(execution, 200, synchResponse)
114 logDebug('Exited ' + method, isDebugLogEnabled)
115 } catch (BpmnError e) {
117 } catch (Exception e) {
118 logError('Caught exception in ' + method, e)
119 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())
126 * Get VnfResource decomposition object for this VNF.
129 * @param execution The flow's execution instance.
131 public void getVnfResourceDecomposition(DelegateExecution execution) {
132 def method = getClass().getSimpleName() + '.getVnfResourceDecomposition(' +
133 'execution=' + execution.getId() +
135 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
136 logDebug('Entered ' + method, isDebugLogEnabled)
139 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
140 String vnfModelInvariantUuid = execution.getVariable('vnfModelInvariantUuid')
141 logDebug("vnfModelInvariantUuid: " + vnfModelInvariantUuid, isDebugLogEnabled)
142 List<VnfResource> vnfResources = serviceDecomposition.getServiceVnfs()
144 for (i in 0..vnfResources.size()-1) {
145 ModelInfo modelInfo = vnfResources[i].getModelInfo()
146 String modelInvariantUuidFromDecomposition = modelInfo.getModelInvariantUuid()
147 logDebug("modelInvariantUuidFromDecomposition: " + modelInvariantUuidFromDecomposition, isDebugLogEnabled)
149 if (vnfModelInvariantUuid.equals(modelInvariantUuidFromDecomposition)) {
150 VnfResource vnfResourceDecomposition = vnfResources[i]
151 execution.setVariable('vnfResourceDecomposition', vnfResourceDecomposition)
152 def nfRole = vnfResourceDecomposition.getNfRole()
153 execution.setVariable('nfRole', nfRole)
154 logDebug("vnfResourceDecomposition: " + vnfResourceDecomposition.toJsonString(), isDebugLogEnabled)
163 logDebug('Exited ' + method, isDebugLogEnabled)
164 } catch (BpmnError e) {
166 } catch (Exception e) {
167 logError('Caught exception in ' + method, e)
168 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in getVnfResourceDecomposition(): ' + e.getMessage())
173 * Check if this VNF is already in maintenance in A&AI.
176 * @param execution The flow's execution instance.
178 public void checkIfVnfInMaintInAAI(DelegateExecution execution) {
179 def method = getClass().getSimpleName() + '.checkIfVnfInMaintInAAI(' +
180 'execution=' + execution.getId() +
182 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
183 execution.setVariable('errorCode', "0")
184 execution.setVariable("workStep", "checkIfVnfInMaintInAAI")
185 execution.setVariable("failedActivity", "AAI")
186 logDebug('Entered ' + method, isDebugLogEnabled)
189 def transactionLoggingUuid = UUID.randomUUID().toString()
190 AAIRestClientImpl client = new AAIRestClientImpl()
191 AAIValidatorImpl aaiValidator = new AAIValidatorImpl()
192 aaiValidator.setClient(client)
193 def vnfId = execution.getVariable("vnfId")
194 boolean isInMaint = aaiValidator.isVNFLocked(vnfId, transactionLoggingUuid)
195 logDebug("isInMaint result: " + isInMaint, isDebugLogEnabled)
196 execution.setVariable('isVnfInMaintenance', isInMaint)
199 execution.setVariable("errorCode", "1003")
200 execution.setVariable("errorText", "VNF is in maintenance in A&AI")
204 logDebug('Exited ' + method, isDebugLogEnabled)
205 } catch (BpmnError e) {
207 } catch (Exception e) {
208 logError('Caught exception in ' + method, e)
209 execution.setVariable("errorCode", "1002")
210 execution.setVariable("errorText", e.getMessage())
211 //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in checkIfVnfInMaintInAAI(): ' + e.getMessage())
216 * Get VNF info from A&AI.
219 * @param execution The flow's execution instance.
221 public void queryAAIForVnf(DelegateExecution execution) {
222 def method = getClass().getSimpleName() + '.queryAAIForVnf(' +
223 'execution=' + execution.getId() +
225 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
226 logDebug('Entered ' + method, isDebugLogEnabled)
229 def transactionLoggingUuid = UUID.randomUUID().toString()
230 def vnfId = execution.getVariable("vnfId")
231 logDebug("vnfId is: " + vnfId, isDebugLogEnabled)
232 def cloudRegionId = execution.getVariable("lcpCloudRegionId")
233 logDebug("cloudRegionId is: " + cloudRegionId, isDebugLogEnabled)
235 AAIResourcesClient client = new AAIResourcesClient()
237 AAIUri genericVnfUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
238 // Check if this VNF exists
239 if (!client.exists(genericVnfUri)) {
240 logDebug("VNF with vnfId " + vnfId + " does not exist in A&AI", isDebugLogEnabled)
241 exceptionUtil.buildAndThrowWorkflowException(execution, 404, "VNF with vnfId " + vnfId + " does not exist in A&AI")
244 AAIResultWrapper aaiRW = client.get(genericVnfUri)
246 Map<String, Object> result = aaiRW.asMap()
248 String vnfName = result.get("vnf-name")
249 logDebug("vnfName from A&AI is: " + vnfName, isDebugLogEnabled)
250 execution.setVariable("vnfName", vnfName)
251 String nfRole = result.get("nf-role")
252 logDebug("nfRole from A&AI is: " + nfRole, isDebugLogEnabled)
253 execution.setVariable("nfRole", nfRole)
254 String vnfHostIpAddress = result.get("ipv4-oam-address")
255 logDebug("vnfHostIpAddress from A&AI is: " + vnfHostIpAddress, isDebugLogEnabled)
256 execution.setVariable("vnfHostIpAddress", vnfHostIpAddress)
257 execution.setVariable("vmIdList", null)
258 if (aaiRW.getRelationships() != null) {
259 Relationships relationships = aaiRW.getRelationships().get()
260 if (relationships != null) {
262 List<AAIResourceUri> vserverUris = relationships.getRelatedAAIUris(AAIObjectType.VSERVER)
263 JSONArray vserverIds = new JSONArray()
265 for (AAIResourceUri j in vserverUris) {
267 String vserverId = j.getURIKeys().get('vserver-id')
268 vserverIds.put(vserverId)
271 JSONObject vmidsArray = new JSONObject()
272 vmidsArray.put("vmIds", vserverIds.toString())
274 logDebug("vmidsArray is: " + vmidsArray.toString(), isDebugLogEnabled)
276 execution.setVariable("vmIdList", vmidsArray.toString())
280 if (cloudRegionId != null) {
281 String cloudOwnerId = "att-aic";
283 cloudOwnerId = execution.getVariable("URN_mso_default_cloud_owner_id");
284 if (cloudOwnerId == null) cloudOwnerId = "att-aic";
285 } catch (RuntimeException e) {
286 cloudOwnerId = "att-aic";
289 AAIUri cloudRegionUri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, cloudOwnerId, cloudRegionId)
290 // Check if this client region exists
291 if (!client.exists(cloudRegionUri)) {
292 logDebug("Cloud Region with cloudOwner ID " + cloudOwnerId + " and cloudRegionId " + cloudRegionId + " does not exist in A&AI", isDebugLogEnabled)
293 exceptionUtil.buildAndThrowWorkflowException(execution, 404, "Cloud Region with cloudRegionId " + cloudRegionId + " does not exist in A&AI")
296 AAIResultWrapper aaiRWCloud = client.get(cloudRegionUri)
298 Map<String, Object> resultCloud = aaiRWCloud.asMap()
300 String aicIdentity = resultCloud.get("identity-url")
301 logDebug("aicIdentity from A&AI is: " + aicIdentity, isDebugLogEnabled)
302 execution.setVariable("aicIdentity", aicIdentity)
305 logDebug('Exited ' + method, isDebugLogEnabled)
306 } catch (BpmnError e) {
308 } catch (Exception e) {
309 logError('Caught exception in ' + method, e)
310 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIForVnf(): ' + e.getMessage())
317 * Check if this VNF's pservers are locked in A&AI.
320 * @param execution The flow's execution instance.
322 public void checkIfPserversInMaintInAAI(DelegateExecution execution) {
323 def method = getClass().getSimpleName() + '.checkIfPserversInMaintInAAI(' +
324 'execution=' + execution.getId() +
326 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
327 execution.setVariable('errorCode', "0")
328 logDebug('Entered ' + method, isDebugLogEnabled)
329 execution.setVariable("workStep", "checkIfPserversInMaintInAAI")
330 execution.setVariable("failedActivity", "AAI")
333 def transactionLoggingUuid = UUID.randomUUID().toString()
334 AAIRestClientImpl client = new AAIRestClientImpl()
335 AAIValidatorImpl aaiValidator = new AAIValidatorImpl()
336 aaiValidator.setClient(client)
337 def vnfId = execution.getVariable("vnfId")
338 boolean areLocked = aaiValidator.isPhysicalServerLocked(vnfId, transactionLoggingUuid)
339 logDebug("areLocked result: " + areLocked, isDebugLogEnabled)
340 execution.setVariable('arePserversLocked', areLocked)
343 execution.setVariable("errorCode", "1003")
344 execution.setVariable("errorText", "pServers are locked in A&AI")
347 logDebug('Exited ' + method, isDebugLogEnabled)
348 } catch (BpmnError e) {
350 } catch (Exception e) {
351 logError('Caught exception in ' + method, e)
352 execution.setVariable("errorCode", "1002")
353 execution.setVariable("errorText", e.getMessage())
354 //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in checkIfPserversInMaintInAAI(): ' + e.getMessage())
359 * Set inMaint flag for this VNF to the specified value in A&AI.
362 * @param execution The flow's execution instance.
363 * @param inMaint The boolean value of the flag to set
365 public void setVnfInMaintFlagInAAI(DelegateExecution execution, boolean inMaint) {
366 def method = getClass().getSimpleName() + '.setVnfInMaintFlagInAAI(' +
367 'execution=' + execution.getId() +
369 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
370 execution.setVariable('errorCode', "0")
371 logDebug('Entered ' + method, isDebugLogEnabled)
373 execution.setVariable("workStep", "setVnfInMaintFlagInAAI")
376 execution.setVariable("workStep", "unsetVnfInMaintFlagInAAI")
378 execution.setVariable("failedActivity", "AAI")
381 def transactionLoggingUuid = UUID.randomUUID().toString()
382 AAIRestClientImpl client = new AAIRestClientImpl()
383 AAIUpdatorImpl aaiUpdator = new AAIUpdatorImpl()
384 aaiUpdator.setClient(client)
385 def vnfId = execution.getVariable("vnfId")
387 aaiUpdator.updateVnfToLocked(vnfId, transactionLoggingUuid)
388 execution.setVariable("rollbackSetVnfInMaintenanceFlag", true)
391 aaiUpdator.updateVnfToUnLocked(vnfId, transactionLoggingUuid)
392 execution.setVariable("rollbackSetVnfInMaintenanceFlag", false)
395 logDebug('Exited ' + method, isDebugLogEnabled)
396 } catch (BpmnError e) {
398 } catch (Exception e) {
399 logError('Caught exception in ' + method, e)
400 execution.setVariable("errorCode", "1002")
401 execution.setVariable("errorText", e.getMessage())
402 //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in setVnfInMaintFlagInAAI(): ' + e.getMessage())
407 * Check if VF Closed Loop Disabled in A&AI.
410 * @param execution The flow's execution instance.
412 public void checkIfClosedLoopDisabledInAAI(DelegateExecution execution) {
413 def method = getClass().getSimpleName() + '.checkIfClosedLoopDisabledInAAI(' +
414 'execution=' + execution.getId() +
416 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
417 execution.setVariable('errorCode', "0")
418 execution.setVariable("workStep", "checkClosedLoopDisabledFlagInAAI")
419 execution.setVariable("failedActivity", "AAI")
420 logDebug('Entered ' + method, isDebugLogEnabled)
423 def transactionLoggingUuid = UUID.randomUUID().toString()
424 def vnfId = execution.getVariable("vnfId")
425 logDebug("vnfId is: " + vnfId, isDebugLogEnabled)
426 AAIResourcesClient client = new AAIResourcesClient()
427 AAIUri genericVnfUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
428 AAIResultWrapper aaiRW = client.get(genericVnfUri)
429 Map<String, Object> result = aaiRW.asMap()
430 boolean isClosedLoopDisabled = result.getOrDefault("is-closed-loop-disabled", false)
432 logDebug("isClosedLoopDisabled result: " + isClosedLoopDisabled, isDebugLogEnabled)
433 execution.setVariable('isClosedLoopDisabled', isClosedLoopDisabled)
435 if (isClosedLoopDisabled) {
436 execution.setVariable("errorCode", "1004")
437 execution.setVariable("errorText", "closedLoop is disabled in A&AI")
440 logDebug('Exited ' + method, isDebugLogEnabled)
441 } catch (BpmnError e) {
443 } catch (Exception e) {
444 logError('Caught exception in ' + method, e)
445 execution.setVariable("errorCode", "1002")
446 execution.setVariable("errorText", e.getMessage())
451 * Set VF Closed Loop Disabled Flag in A&AI.
454 * @param execution The flow's execution instance.
456 public void setClosedLoopDisabledInAAI(DelegateExecution execution, boolean setDisabled) {
457 def method = getClass().getSimpleName() + '.setClosedLoopDisabledInAAI(' +
458 'execution=' + execution.getId() +
460 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
461 execution.setVariable('errorCode', "0")
463 execution.setVariable("workStep", "setClosedLoopDisabledFlagInAAI")
464 execution.setVariable("rollbackSetClosedLoopDisabledFlag", true)
467 execution.setVariable("workStep", "unsetClosedLoopDisabledFlagInAAI")
468 execution.setVariable("rollbackSetClosedLoopDisabledFlag", false)
471 execution.setVariable("failedActivity", "AAI")
472 logDebug('Entered ' + method, isDebugLogEnabled)
475 def transactionLoggingUuid = UUID.randomUUID().toString()
476 def vnfId = execution.getVariable("vnfId")
477 AAIResourcesClient client = new AAIResourcesClient()
478 AAIUri genericVnfUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
480 Map<String, Boolean> request = new HashMap<>()
481 request.put("is-closed-loop-disabled", setDisabled)
482 client.update(genericVnfUri, request)
483 logDebug("set isClosedLoop to: " + setDisabled, isDebugLogEnabled)
485 logDebug('Exited ' + method, isDebugLogEnabled)
486 } catch (BpmnError e) {
488 } catch (Exception e) {
489 logError('Caught exception in ' + method, e)
490 execution.setVariable("errorCode", "1002")
491 execution.setVariable("errorText", e.getMessage())
499 * Call APP-C client to execute specified APP-C command for this VNF.
502 * @param execution The flow's execution instance.
503 * @param action The action to take in APP-C.
505 public void runAppcCommand(DelegateExecution execution, Action action) {
506 def method = getClass().getSimpleName() + '.runAppcCommand(' +
507 'execution=' + execution.getId() +
509 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
510 execution.setVariable('errorCode', "0")
511 logDebug('Entered ' + method, isDebugLogEnabled)
513 ApplicationControllerClient appcClient = null
516 logDebug("Running APP-C action: " + action.toString(), isDebugLogEnabled)
517 String vnfId = execution.getVariable('vnfId')
518 String msoRequestId = execution.getVariable('requestId')
519 execution.setVariable('msoRequestId', msoRequestId)
520 execution.setVariable("failedActivity", "APP-C")
522 appcClient = new ApplicationControllerClient()
523 ApplicationControllerSupport support = new ApplicationControllerSupport()
524 appcClient.appCSupport=support
525 org.springframework.test.util.ReflectionTestUtils.setField(support, "lcmModelPackage", "org.onap.appc.client.lcm.model");
526 Flags flags = new Flags();
527 ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
528 actionIdentifiers.setVnfId(vnfId);
532 execution.setVariable('workStep', "LockVNF")
533 appcStatus = appcClient.runCommand(Action.Lock,actionIdentifiers,null,msoRequestId)
536 execution.setVariable('workStep', "UnlockVNF")
537 appcStatus = appcClient.runCommand(Action.Unlock,actionIdentifiers,null,msoRequestId)
539 case Action.HealthCheck:
540 def healthCheckIndex = execution.getVariable('healthCheckIndex')
541 execution.setVariable('workStep', "HealthCheckVNF" + healthCheckIndex)
542 execution.setVariable('healthCheckIndex', healthCheckIndex + 1)
543 appcStatus = appcClient.runCommand(Action.HealthCheck,actionIdentifiers,null,msoRequestId)
546 execution.setVariable('workStep', "StartVNF")
547 appcStatus = appcClient.runCommand(Action.Start,actionIdentifiers,null,msoRequestId)
550 execution.setVariable('workStep', "StopVNF")
551 appcStatus = appcClient.runCommand(Action.Stop,actionIdentifiers,null,msoRequestId)
556 logDebug("Completed AppC request", isDebugLogEnabled)
557 int appcCode = appcStatus.getCode()
558 logDebug("AppC status code is: " + appcCode, isDebugLogEnabled)
559 logDebug("AppC status message is: " + appcStatus.getMessage(), isDebugLogEnabled)
560 if (support.getCategoryOf(appcStatus) == ApplicationControllerSupport.StatusCategory.ERROR) {
561 execution.setVariable("errorCode", Integer.toString(appcCode))
562 execution.setVariable("errorText", appcStatus.getMessage())
565 logDebug('Exited ' + method, isDebugLogEnabled)
566 } catch (BpmnError e) {
567 logError('Caught exception in ' + method, e)
568 execution.setVariable("errorCode", "1002")
569 execution.setVariable("errorText", e.getMessage())
571 } catch (java.lang.NoSuchMethodError e) {
572 logError('Caught exception in ' + method, e)
573 execution.setVariable("errorCode", "1002")
574 execution.setVariable("errorText", e.getMessage())
576 } catch (Exception e) {
577 logError('Caught exception in ' + method, e)
578 execution.setVariable("errorCode", "1002")
579 execution.setVariable("errorText", e.getMessage())
585 * Placeholder for a call to APP-C client to execute specified APP-C command for this VNF.
588 * @param execution The flow's execution instance.
589 * @param action The action to take in APP-C.
591 public void runAppcCommandPlaceholder(DelegateExecution execution, String action) {
592 def method = getClass().getSimpleName() + '.runAppcCommandPlaceholder(' +
593 'execution=' + execution.getId() +
595 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
596 execution.setVariable('errorCode', "0")
597 logDebug('Entered ' + method, isDebugLogEnabled)
598 execution.setVariable("failedActivity", "APP-C")
599 execution.setVariable("workStep", action)
609 * Builds a "CompletionHandler" request and stores it in the specified execution variable.
611 * @param execution the execution
612 * @param resultVar the execution variable in which the result will be stored
614 public void completionHandlerPrep(DelegateExecution execution, String resultVar) {
615 def method = getClass().getSimpleName() + '.completionHandlerPrep(' +
616 'execution=' + execution.getId() +
617 ', resultVar=' + resultVar +
619 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
620 logDebug('Entered ' + method, isDebugLogEnabled)
624 def requestInfo = execution.getVariable('requestInfo')
627 <sdncadapterworkflow:MsoCompletionRequest xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
628 xmlns:reqtype="http://org.openecomp/mso/request/types/v1">
630 <sdncadapterworkflow:status-message>Vnf has been updated successfully.</sdncadapterworkflow:status-message>
631 <sdncadapterworkflow:mso-bpel-name>MSO_ACTIVATE_BPEL</sdncadapterworkflow:mso-bpel-name>
632 </sdncadapterworkflow:MsoCompletionRequest>
635 content = utils.formatXml(content)
636 logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
637 execution.setVariable(resultVar, content)
639 logDebug('Exited ' + method, isDebugLogEnabled)
640 } catch (BpmnError e) {
642 } catch (Exception e) {
643 logError('Caught exception in ' + method, e)
644 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, 'Internal Error')
649 * Prepare DoUpdateVnfAndModules call.
652 * @param execution The flow's execution instance.
654 public void prepDoUpdateVnfAndModules(DelegateExecution execution) {
655 def method = getClass().getSimpleName() + '.prepDoUpdateVnfAndModules(' +
656 'execution=' + execution.getId() +
658 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
659 execution.setVariable('errorCode', "0")
660 logDebug('Entered ' + method, isDebugLogEnabled)
661 execution.setVariable("workStep", "doUpdateVnfAndModules")
662 execution.setVariable("failedActivity", "MSO Update VNF")
663 logDebug('Exited ' + method, isDebugLogEnabled)
668 * Builds a "FalloutHandler" request and stores it in the specified execution variable.
670 * @param execution the execution
671 * @param resultVar the execution variable in which the result will be stored
673 public void falloutHandlerPrep(DelegateExecution execution, String resultVar) {
674 def method = getClass().getSimpleName() + '.falloutHandlerPrep(' +
675 'execution=' + execution.getId() +
676 ', resultVar=' + resultVar +
678 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
679 logDebug('Entered ' + method, isDebugLogEnabled)
682 def prefix = execution.getVariable('prefix')
683 def requestInformation = execution.getVariable("requestInfo")
685 def WorkflowException workflowException = execution.getVariable("WorkflowException")
686 def errorResponseCode = workflowException.getErrorCode()
687 def errorResponseMsg = workflowException.getErrorMessage()
688 def encErrorResponseMsg = ""
689 if (errorResponseMsg != null) {
690 encErrorResponseMsg = errorResponseMsg.replace("&", "&").replace("<", "<").replace(">", ">")
694 <sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
695 xmlns:reqtype="http://org.openecomp/mso/request/types/v1"
696 xmlns:msoservtypes="http://org.openecomp/mso/request/types/v1"
697 xmlns:structuredtypes="http://org.openecomp/mso/structured/types/v1">
698 ${requestInformation}
699 <sdncadapterworkflow:WorkflowException>
700 <sdncadapterworkflow:ErrorMessage>${encErrorResponseMsg}</sdncadapterworkflow:ErrorMessage>
701 <sdncadapterworkflow:ErrorCode>${errorResponseCode}</sdncadapterworkflow:ErrorCode>
702 </sdncadapterworkflow:WorkflowException>
703 </sdncadapterworkflow:FalloutHandlerRequest>
705 content = utils.formatXml(content)
706 logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
707 execution.setVariable(resultVar, content)
709 logDebug('Exited ' + method, isDebugLogEnabled)
710 } catch (BpmnError e) {
712 } catch (Exception e) {
713 logError('Caught exception in ' + method, e)
714 exceptionUtil.buildWorkflowException(execution, 2000, 'Internal Error')
719 * Handle Abort disposition from RainyDayHandler
721 * @param execution The flow's execution instance.
723 public void abortProcessing(DelegateExecution execution) {
724 def method = getClass().getSimpleName() + '.abortProcessing(' +
725 'execution=' + execution.getId() +
727 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
728 logDebug('Entered ' + method, isDebugLogEnabled)
730 def errorText = execution.getVariable("errorText")
731 def errorCode = execution.getVariable("errorCode")
733 exceptionUtil.buildAndThrowWorkflowException(execution, errorCode as Integer, errorText)
737 * Increment Retry Count for Current Work Step
739 * @param execution The flow's execution instance.
741 public void incrementRetryCount(DelegateExecution execution) {
742 def method = getClass().getSimpleName() + '.incrementRetryCount(' +
743 'execution=' + execution.getId() +
745 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
746 logDebug('Entered ' + method, isDebugLogEnabled)
748 String retryCountVariableName = execution.getVariable("workStep") + "RetryCount"
749 execution.setVariable("retryCountVariableName", retryCountVariableName)
751 def retryCountVariable = execution.getVariable(retryCountVariableName)
754 if (retryCountVariable != null) {
755 retryCount = (int) retryCountVariable
760 execution.setVariable(retryCountVariableName, retryCount)
762 logDebug("value of " + retryCountVariableName + " is " + retryCount, isDebugLogEnabled)
763 logDebug('Exited ' + method, isDebugLogEnabled)
768 public void preProcessRollback (DelegateExecution execution) {
769 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
770 utils.log("DEBUG"," ***** preProcessRollback ***** ", isDebugEnabled)
773 Object workflowException = execution.getVariable("WorkflowException");
775 if (workflowException instanceof WorkflowException) {
776 utils.log("DEBUG", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
777 execution.setVariable("prevWorkflowException", workflowException);
778 //execution.setVariable("WorkflowException", null);
780 } catch (BpmnError e) {
781 utils.log("DEBUG", "BPMN Error during preProcessRollback", isDebugEnabled)
782 } catch(Exception ex) {
783 String msg = "Exception in preProcessRollback. " + ex.getMessage()
784 utils.log("DEBUG", msg, isDebugEnabled)
786 utils.log("DEBUG"," *** Exit preProcessRollback *** ", isDebugEnabled)
789 public void postProcessRollback (DelegateExecution execution) {
790 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
791 utils.log("DEBUG"," ***** postProcessRollback ***** ", isDebugEnabled)
794 Object workflowException = execution.getVariable("prevWorkflowException");
795 if (workflowException instanceof WorkflowException) {
796 utils.log("DEBUG", "Setting prevException to WorkflowException: ", isDebugEnabled)
797 execution.setVariable("WorkflowException", workflowException);
800 } catch (BpmnError b) {
801 utils.log("DEBUG", "BPMN Error during postProcessRollback", isDebugEnabled)
803 } catch(Exception ex) {
804 msg = "Exception in postProcessRollback. " + ex.getMessage()
805 utils.log("DEBUG", msg, isDebugEnabled)
807 utils.log("DEBUG"," *** Exit postProcessRollback *** ", isDebugEnabled)