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 AAIUri cloudRegionUri = AAIUriFactory.createResourceUri(AAIObjectType.DEFAULT_CLOUD_REGION, cloudRegionId)
282 // Check if this client region exists
283 if (!client.exists(cloudRegionUri)) {
284 logDebug("Cloud Region with cloudRegionId " + cloudRegionId + " does not exist in A&AI", isDebugLogEnabled)
285 exceptionUtil.buildAndThrowWorkflowException(execution, 404, "Cloud Region with cloudRegionId " + cloudRegionId + " does not exist in A&AI")
288 AAIResultWrapper aaiRWCloud = client.get(cloudRegionUri)
290 Map<String, Object> resultCloud = aaiRWCloud.asMap()
292 String aicIdentity = resultCloud.get("identity-url")
293 logDebug("aicIdentity from A&AI is: " + aicIdentity, isDebugLogEnabled)
294 execution.setVariable("aicIdentity", aicIdentity)
297 logDebug('Exited ' + method, isDebugLogEnabled)
298 } catch (BpmnError e) {
300 } catch (Exception e) {
301 logError('Caught exception in ' + method, e)
302 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIForVnf(): ' + e.getMessage())
309 * Check if this VNF's pservers are locked in A&AI.
312 * @param execution The flow's execution instance.
314 public void checkIfPserversInMaintInAAI(DelegateExecution execution) {
315 def method = getClass().getSimpleName() + '.checkIfPserversInMaintInAAI(' +
316 'execution=' + execution.getId() +
318 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
319 execution.setVariable('errorCode', "0")
320 logDebug('Entered ' + method, isDebugLogEnabled)
321 execution.setVariable("workStep", "checkIfPserversInMaintInAAI")
322 execution.setVariable("failedActivity", "AAI")
325 def transactionLoggingUuid = UUID.randomUUID().toString()
326 AAIRestClientImpl client = new AAIRestClientImpl()
327 AAIValidatorImpl aaiValidator = new AAIValidatorImpl()
328 aaiValidator.setClient(client)
329 def vnfId = execution.getVariable("vnfId")
330 boolean areLocked = aaiValidator.isPhysicalServerLocked(vnfId, transactionLoggingUuid)
331 logDebug("areLocked result: " + areLocked, isDebugLogEnabled)
332 execution.setVariable('arePserversLocked', areLocked)
335 execution.setVariable("errorCode", "1003")
336 execution.setVariable("errorText", "pServers are locked in A&AI")
339 logDebug('Exited ' + method, isDebugLogEnabled)
340 } catch (BpmnError e) {
342 } catch (Exception e) {
343 logError('Caught exception in ' + method, e)
344 execution.setVariable("errorCode", "1002")
345 execution.setVariable("errorText", e.getMessage())
346 //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in checkIfPserversInMaintInAAI(): ' + e.getMessage())
351 * Set inMaint flag for this VNF to the specified value in A&AI.
354 * @param execution The flow's execution instance.
355 * @param inMaint The boolean value of the flag to set
357 public void setVnfInMaintFlagInAAI(DelegateExecution execution, boolean inMaint) {
358 def method = getClass().getSimpleName() + '.setVnfInMaintFlagInAAI(' +
359 'execution=' + execution.getId() +
361 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
362 execution.setVariable('errorCode', "0")
363 logDebug('Entered ' + method, isDebugLogEnabled)
365 execution.setVariable("workStep", "setVnfInMaintFlagInAAI")
368 execution.setVariable("workStep", "unsetVnfInMaintFlagInAAI")
370 execution.setVariable("failedActivity", "AAI")
373 def transactionLoggingUuid = UUID.randomUUID().toString()
374 AAIRestClientImpl client = new AAIRestClientImpl()
375 AAIUpdatorImpl aaiUpdator = new AAIUpdatorImpl()
376 aaiUpdator.setClient(client)
377 def vnfId = execution.getVariable("vnfId")
379 aaiUpdator.updateVnfToLocked(vnfId, transactionLoggingUuid)
380 execution.setVariable("rollbackSetVnfInMaintenanceFlag", true)
383 aaiUpdator.updateVnfToUnLocked(vnfId, transactionLoggingUuid)
384 execution.setVariable("rollbackSetVnfInMaintenanceFlag", false)
387 logDebug('Exited ' + method, isDebugLogEnabled)
388 } catch (BpmnError e) {
390 } catch (Exception e) {
391 logError('Caught exception in ' + method, e)
392 execution.setVariable("errorCode", "1002")
393 execution.setVariable("errorText", e.getMessage())
394 //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in setVnfInMaintFlagInAAI(): ' + e.getMessage())
399 * Check if VF Closed Loop Disabled in A&AI.
402 * @param execution The flow's execution instance.
404 public void checkIfClosedLoopDisabledInAAI(DelegateExecution execution) {
405 def method = getClass().getSimpleName() + '.checkIfClosedLoopDisabledInAAI(' +
406 'execution=' + execution.getId() +
408 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
409 execution.setVariable('errorCode', "0")
410 execution.setVariable("workStep", "checkClosedLoopDisabledFlagInAAI")
411 execution.setVariable("failedActivity", "AAI")
412 logDebug('Entered ' + method, isDebugLogEnabled)
415 def transactionLoggingUuid = UUID.randomUUID().toString()
416 def vnfId = execution.getVariable("vnfId")
417 logDebug("vnfId is: " + vnfId, isDebugLogEnabled)
418 AAIResourcesClient client = new AAIResourcesClient()
419 AAIUri genericVnfUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
420 AAIResultWrapper aaiRW = client.get(genericVnfUri)
421 Map<String, Object> result = aaiRW.asMap()
422 boolean isClosedLoopDisabled = result.getOrDefault("is-closed-loop-disabled", false)
424 logDebug("isClosedLoopDisabled result: " + isClosedLoopDisabled, isDebugLogEnabled)
425 execution.setVariable('isClosedLoopDisabled', isClosedLoopDisabled)
427 if (isClosedLoopDisabled) {
428 execution.setVariable("errorCode", "1004")
429 execution.setVariable("errorText", "closedLoop is disabled in A&AI")
432 logDebug('Exited ' + method, isDebugLogEnabled)
433 } catch (BpmnError e) {
435 } catch (Exception e) {
436 logError('Caught exception in ' + method, e)
437 execution.setVariable("errorCode", "1002")
438 execution.setVariable("errorText", e.getMessage())
443 * Set VF Closed Loop Disabled Flag in A&AI.
446 * @param execution The flow's execution instance.
448 public void setClosedLoopDisabledInAAI(DelegateExecution execution, boolean setDisabled) {
449 def method = getClass().getSimpleName() + '.setClosedLoopDisabledInAAI(' +
450 'execution=' + execution.getId() +
452 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
453 execution.setVariable('errorCode', "0")
455 execution.setVariable("workStep", "setClosedLoopDisabledFlagInAAI")
456 execution.setVariable("rollbackSetClosedLoopDisabledFlag", true)
459 execution.setVariable("workStep", "unsetClosedLoopDisabledFlagInAAI")
460 execution.setVariable("rollbackSetClosedLoopDisabledFlag", false)
463 execution.setVariable("failedActivity", "AAI")
464 logDebug('Entered ' + method, isDebugLogEnabled)
467 def transactionLoggingUuid = UUID.randomUUID().toString()
468 def vnfId = execution.getVariable("vnfId")
469 AAIResourcesClient client = new AAIResourcesClient()
470 AAIUri genericVnfUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
472 Map<String, Boolean> request = new HashMap<>()
473 request.put("is-closed-loop-disabled", setDisabled)
474 client.update(genericVnfUri, request)
475 logDebug("set isClosedLoop to: " + setDisabled, isDebugLogEnabled)
477 logDebug('Exited ' + method, isDebugLogEnabled)
478 } catch (BpmnError e) {
480 } catch (Exception e) {
481 logError('Caught exception in ' + method, e)
482 execution.setVariable("errorCode", "1002")
483 execution.setVariable("errorText", e.getMessage())
491 * Call APP-C client to execute specified APP-C command for this VNF.
494 * @param execution The flow's execution instance.
495 * @param action The action to take in APP-C.
497 public void runAppcCommand(DelegateExecution execution, Action action) {
498 def method = getClass().getSimpleName() + '.runAppcCommand(' +
499 'execution=' + execution.getId() +
501 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
502 execution.setVariable('errorCode', "0")
503 logDebug('Entered ' + method, isDebugLogEnabled)
505 ApplicationControllerClient appcClient = null
508 logDebug("Running APP-C action: " + action.toString(), isDebugLogEnabled)
509 String vnfId = execution.getVariable('vnfId')
510 String msoRequestId = execution.getVariable('requestId')
511 execution.setVariable('msoRequestId', msoRequestId)
512 execution.setVariable("failedActivity", "APP-C")
514 appcClient = new ApplicationControllerClient()
515 ApplicationControllerSupport support = new ApplicationControllerSupport()
516 appcClient.appCSupport=support
517 org.springframework.test.util.ReflectionTestUtils.setField(support, "lcmModelPackage", "org.onap.appc.client.lcm.model");
518 Flags flags = new Flags();
519 ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
520 actionIdentifiers.setVnfId(vnfId);
524 execution.setVariable('workStep', "LockVNF")
525 appcStatus = appcClient.runCommand(Action.Lock,actionIdentifiers,null,msoRequestId)
528 execution.setVariable('workStep', "UnlockVNF")
529 appcStatus = appcClient.runCommand(Action.Unlock,actionIdentifiers,null,msoRequestId)
531 case Action.HealthCheck:
532 def healthCheckIndex = execution.getVariable('healthCheckIndex')
533 execution.setVariable('workStep', "HealthCheckVNF" + healthCheckIndex)
534 execution.setVariable('healthCheckIndex', healthCheckIndex + 1)
535 appcStatus = appcClient.runCommand(Action.HealthCheck,actionIdentifiers,null,msoRequestId)
538 execution.setVariable('workStep', "StartVNF")
539 appcStatus = appcClient.runCommand(Action.Start,actionIdentifiers,null,msoRequestId)
542 execution.setVariable('workStep', "StopVNF")
543 appcStatus = appcClient.runCommand(Action.Stop,actionIdentifiers,null,msoRequestId)
548 logDebug("Completed AppC request", isDebugLogEnabled)
549 int appcCode = appcStatus.getCode()
550 logDebug("AppC status code is: " + appcCode, isDebugLogEnabled)
551 logDebug("AppC status message is: " + appcStatus.getMessage(), isDebugLogEnabled)
552 if (support.getCategoryOf(appcStatus) == ApplicationControllerSupport.StatusCategory.ERROR) {
553 execution.setVariable("errorCode", Integer.toString(appcCode))
554 execution.setVariable("errorText", appcStatus.getMessage())
557 logDebug('Exited ' + method, isDebugLogEnabled)
558 } catch (BpmnError e) {
559 logError('Caught exception in ' + method, e)
560 execution.setVariable("errorCode", "1002")
561 execution.setVariable("errorText", e.getMessage())
563 } catch (java.lang.NoSuchMethodError e) {
564 logError('Caught exception in ' + method, e)
565 execution.setVariable("errorCode", "1002")
566 execution.setVariable("errorText", e.getMessage())
568 } catch (Exception e) {
569 logError('Caught exception in ' + method, e)
570 execution.setVariable("errorCode", "1002")
571 execution.setVariable("errorText", e.getMessage())
577 * Placeholder for a call to APP-C client to execute specified APP-C command for this VNF.
580 * @param execution The flow's execution instance.
581 * @param action The action to take in APP-C.
583 public void runAppcCommandPlaceholder(DelegateExecution execution, String action) {
584 def method = getClass().getSimpleName() + '.runAppcCommandPlaceholder(' +
585 'execution=' + execution.getId() +
587 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
588 execution.setVariable('errorCode', "0")
589 logDebug('Entered ' + method, isDebugLogEnabled)
590 execution.setVariable("failedActivity", "APP-C")
591 execution.setVariable("workStep", action)
601 * Builds a "CompletionHandler" request and stores it in the specified execution variable.
603 * @param execution the execution
604 * @param resultVar the execution variable in which the result will be stored
606 public void completionHandlerPrep(DelegateExecution execution, String resultVar) {
607 def method = getClass().getSimpleName() + '.completionHandlerPrep(' +
608 'execution=' + execution.getId() +
609 ', resultVar=' + resultVar +
611 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
612 logDebug('Entered ' + method, isDebugLogEnabled)
616 def requestInfo = execution.getVariable('requestInfo')
619 <sdncadapterworkflow:MsoCompletionRequest xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
620 xmlns:reqtype="http://org.openecomp/mso/request/types/v1">
622 <sdncadapterworkflow:status-message>Vnf has been updated successfully.</sdncadapterworkflow:status-message>
623 <sdncadapterworkflow:mso-bpel-name>MSO_ACTIVATE_BPEL</sdncadapterworkflow:mso-bpel-name>
624 </sdncadapterworkflow:MsoCompletionRequest>
627 content = utils.formatXml(content)
628 logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
629 execution.setVariable(resultVar, content)
631 logDebug('Exited ' + method, isDebugLogEnabled)
632 } catch (BpmnError e) {
634 } catch (Exception e) {
635 logError('Caught exception in ' + method, e)
636 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, 'Internal Error')
641 * Prepare DoUpdateVnfAndModules call.
644 * @param execution The flow's execution instance.
646 public void prepDoUpdateVnfAndModules(DelegateExecution execution) {
647 def method = getClass().getSimpleName() + '.prepDoUpdateVnfAndModules(' +
648 'execution=' + execution.getId() +
650 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
651 execution.setVariable('errorCode', "0")
652 logDebug('Entered ' + method, isDebugLogEnabled)
653 execution.setVariable("workStep", "doUpdateVnfAndModules")
654 execution.setVariable("failedActivity", "MSO Update VNF")
655 logDebug('Exited ' + method, isDebugLogEnabled)
660 * Builds a "FalloutHandler" request and stores it in the specified execution variable.
662 * @param execution the execution
663 * @param resultVar the execution variable in which the result will be stored
665 public void falloutHandlerPrep(DelegateExecution execution, String resultVar) {
666 def method = getClass().getSimpleName() + '.falloutHandlerPrep(' +
667 'execution=' + execution.getId() +
668 ', resultVar=' + resultVar +
670 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
671 logDebug('Entered ' + method, isDebugLogEnabled)
674 def prefix = execution.getVariable('prefix')
675 def requestInformation = execution.getVariable("requestInfo")
677 def WorkflowException workflowException = execution.getVariable("WorkflowException")
678 def errorResponseCode = workflowException.getErrorCode()
679 def errorResponseMsg = workflowException.getErrorMessage()
680 def encErrorResponseMsg = ""
681 if (errorResponseMsg != null) {
682 encErrorResponseMsg = errorResponseMsg.replace("&", "&").replace("<", "<").replace(">", ">")
686 <sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow="http://org.openecomp/mso/workflow/schema/v1"
687 xmlns:reqtype="http://org.openecomp/mso/request/types/v1"
688 xmlns:msoservtypes="http://org.openecomp/mso/request/types/v1"
689 xmlns:structuredtypes="http://org.openecomp/mso/structured/types/v1">
690 ${requestInformation}
691 <sdncadapterworkflow:WorkflowException>
692 <sdncadapterworkflow:ErrorMessage>${encErrorResponseMsg}</sdncadapterworkflow:ErrorMessage>
693 <sdncadapterworkflow:ErrorCode>${errorResponseCode}</sdncadapterworkflow:ErrorCode>
694 </sdncadapterworkflow:WorkflowException>
695 </sdncadapterworkflow:FalloutHandlerRequest>
697 content = utils.formatXml(content)
698 logDebug(resultVar + ' = ' + System.lineSeparator() + content, isDebugLogEnabled)
699 execution.setVariable(resultVar, content)
701 logDebug('Exited ' + method, isDebugLogEnabled)
702 } catch (BpmnError e) {
704 } catch (Exception e) {
705 logError('Caught exception in ' + method, e)
706 exceptionUtil.buildWorkflowException(execution, 2000, 'Internal Error')
711 * Handle Abort disposition from RainyDayHandler
713 * @param execution The flow's execution instance.
715 public void abortProcessing(DelegateExecution execution) {
716 def method = getClass().getSimpleName() + '.abortProcessing(' +
717 'execution=' + execution.getId() +
719 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
720 logDebug('Entered ' + method, isDebugLogEnabled)
722 def errorText = execution.getVariable("errorText")
723 def errorCode = execution.getVariable("errorCode")
725 exceptionUtil.buildAndThrowWorkflowException(execution, errorCode as Integer, errorText)
729 * Increment Retry Count for Current Work Step
731 * @param execution The flow's execution instance.
733 public void incrementRetryCount(DelegateExecution execution) {
734 def method = getClass().getSimpleName() + '.incrementRetryCount(' +
735 'execution=' + execution.getId() +
737 def isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
738 logDebug('Entered ' + method, isDebugLogEnabled)
740 String retryCountVariableName = execution.getVariable("workStep") + "RetryCount"
741 execution.setVariable("retryCountVariableName", retryCountVariableName)
743 def retryCountVariable = execution.getVariable(retryCountVariableName)
746 if (retryCountVariable != null) {
747 retryCount = (int) retryCountVariable
752 execution.setVariable(retryCountVariableName, retryCount)
754 logDebug("value of " + retryCountVariableName + " is " + retryCount, isDebugLogEnabled)
755 logDebug('Exited ' + method, isDebugLogEnabled)
760 public void preProcessRollback (DelegateExecution execution) {
761 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
762 utils.log("DEBUG"," ***** preProcessRollback ***** ", isDebugEnabled)
765 Object workflowException = execution.getVariable("WorkflowException");
767 if (workflowException instanceof WorkflowException) {
768 utils.log("DEBUG", "Prev workflowException: " + workflowException.getErrorMessage(), isDebugEnabled)
769 execution.setVariable("prevWorkflowException", workflowException);
770 //execution.setVariable("WorkflowException", null);
772 } catch (BpmnError e) {
773 utils.log("DEBUG", "BPMN Error during preProcessRollback", isDebugEnabled)
774 } catch(Exception ex) {
775 String msg = "Exception in preProcessRollback. " + ex.getMessage()
776 utils.log("DEBUG", msg, isDebugEnabled)
778 utils.log("DEBUG"," *** Exit preProcessRollback *** ", isDebugEnabled)
781 public void postProcessRollback (DelegateExecution execution) {
782 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
783 utils.log("DEBUG"," ***** postProcessRollback ***** ", isDebugEnabled)
786 Object workflowException = execution.getVariable("prevWorkflowException");
787 if (workflowException instanceof WorkflowException) {
788 utils.log("DEBUG", "Setting prevException to WorkflowException: ", isDebugEnabled)
789 execution.setVariable("WorkflowException", workflowException);
792 } catch (BpmnError b) {
793 utils.log("DEBUG", "BPMN Error during postProcessRollback", isDebugEnabled)
795 } catch(Exception ex) {
796 msg = "Exception in postProcessRollback. " + ex.getMessage()
797 utils.log("DEBUG", msg, isDebugEnabled)
799 utils.log("DEBUG"," *** Exit postProcessRollback *** ", isDebugEnabled)