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.onap.so.bpmn.infrastructure.scripts
22 import org.camunda.bpm.engine.delegate.BpmnError
23 import org.camunda.bpm.engine.delegate.DelegateExecution
24 import org.json.JSONArray
25 import org.json.JSONObject
26 import org.onap.appc.client.lcm.model.Action;
27 import org.onap.appc.client.lcm.model.ActionIdentifiers
28 import org.onap.appc.client.lcm.model.Flags
29 import org.onap.appc.client.lcm.model.Status
30 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor;
31 import org.onap.so.bpmn.common.scripts.ExceptionUtil
32 import org.onap.so.bpmn.common.scripts.MsoUtils
33 import org.onap.so.bpmn.core.WorkflowException
34 import org.onap.so.bpmn.core.domain.ModelInfo
35 import org.onap.so.bpmn.core.domain.ServiceDecomposition
36 import org.onap.so.bpmn.core.domain.VnfResource
37 import org.onap.so.bpmn.core.json.JsonUtils
38 import org.onap.so.client.aai.*
39 import org.onap.so.client.aai.entities.AAIResultWrapper
40 import org.onap.so.client.aai.entities.Relationships
41 import org.onap.so.client.aai.entities.uri.AAIResourceUri
42 import org.onap.so.client.aai.entities.uri.AAIUri
43 import org.onap.so.client.aai.entities.uri.AAIUriFactory
44 import org.onap.so.client.appc.ApplicationControllerClient;
45 import org.onap.so.client.appc.ApplicationControllerSupport;
46 import org.onap.so.logger.MessageEnum
47 import org.onap.so.logger.MsoLogger
49 import groovy.json.JsonSlurper
51 public abstract class VnfCmBase extends AbstractServiceTaskProcessor {
52 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, VnfCmBase.class);
54 ExceptionUtil exceptionUtil = new ExceptionUtil()
55 JsonUtils jsonUtils = new JsonUtils()
56 def prefix = "VnfIPU_"
59 * Initialize the flow's variables.
61 * @param execution The flow's execution instance.
65 * Prepare and send the sychronous response for this flow.
67 * @param execution The flow's execution instance.
69 public void sendSynchResponse(DelegateExecution execution) {
70 def method = getClass().getSimpleName() + '.sendSynchResponse(' +
71 'execution=' + execution.getId() +
74 msoLogger.trace('Entered ' + method)
78 def requestInfo = execution.getVariable('requestInfo')
79 def requestId = execution.getVariable('requestId')
80 def source = execution.getVariable('source')
81 def progress = getNodeTextForce(requestInfo, 'progress')
82 if (progress.isEmpty()) {
85 def startTime = getNodeTextForce(requestInfo, 'start-time')
86 if (startTime.isEmpty()) {
87 startTime = System.currentTimeMillis()
90 // RESTResponse (for API Handler (APIH) Reply Task)
91 def vnfId = execution.getVariable("vnfId")
92 String synchResponse = """{"requestReferences":{"instanceId":"${vnfId}","requestId":"${requestId}"}}""".trim()
94 sendWorkflowResponse(execution, 200, synchResponse)
96 msoLogger.trace('Exited ' + method)
97 } catch (BpmnError e) {
99 } catch (Exception e) {
100 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
101 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in sendResponse(): ' + e.getMessage())
108 * Get VnfResource decomposition object for this VNF.
111 * @param execution The flow's execution instance.
113 public void getVnfResourceDecomposition(DelegateExecution execution) {
114 def method = getClass().getSimpleName() + '.getVnfResourceDecomposition(' +
115 'execution=' + execution.getId() +
117 msoLogger.trace('Entered ' + method)
120 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
121 String vnfModelInvariantUuid = execution.getVariable('vnfModelInvariantUuid')
122 msoLogger.debug("vnfModelInvariantUuid: " + vnfModelInvariantUuid)
123 List<VnfResource> vnfResources = serviceDecomposition.getVnfResources()
125 for (i in 0..vnfResources.size()-1) {
126 ModelInfo modelInfo = vnfResources[i].getModelInfo()
127 String modelInvariantUuidFromDecomposition = modelInfo.getModelInvariantUuid()
128 msoLogger.debug("modelInvariantUuidFromDecomposition: " + modelInvariantUuidFromDecomposition)
130 if (vnfModelInvariantUuid.equals(modelInvariantUuidFromDecomposition)) {
131 VnfResource vnfResourceDecomposition = vnfResources[i]
132 execution.setVariable('vnfResourceDecomposition', vnfResourceDecomposition)
133 def nfRole = vnfResourceDecomposition.getNfRole()
134 execution.setVariable('nfRole', nfRole)
135 msoLogger.debug("vnfResourceDecomposition: " + vnfResourceDecomposition.toJsonString())
144 msoLogger.trace('Exited ' + method)
145 } catch (BpmnError e) {
147 } catch (Exception e) {
148 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
149 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in getVnfResourceDecomposition(): ' + e.getMessage())
154 * Check if this VNF is already in maintenance in A&AI.
157 * @param execution The flow's execution instance.
159 public void checkIfVnfInMaintInAAI(DelegateExecution execution) {
160 def method = getClass().getSimpleName() + '.checkIfVnfInMaintInAAI(' +
161 'execution=' + execution.getId() +
164 execution.setVariable('errorCode', "0")
165 execution.setVariable("workStep", "checkIfVnfInMaintInAAI")
166 execution.setVariable("failedActivity", "AAI")
167 msoLogger.trace('Entered ' + method)
170 AAIRestClientImpl client = new AAIRestClientImpl()
171 AAIValidatorImpl aaiValidator = new AAIValidatorImpl()
172 aaiValidator.setClient(client)
173 def vnfId = execution.getVariable("vnfId")
174 boolean isInMaint = aaiValidator.isVNFLocked(vnfId)
175 msoLogger.debug("isInMaint result: " + isInMaint)
176 execution.setVariable('isVnfInMaintenance', isInMaint)
179 execution.setVariable("errorCode", "1003")
180 execution.setVariable("errorText", "VNF is in maintenance in A&AI")
184 msoLogger.trace('Exited ' + method)
185 } catch (BpmnError e) {
187 } catch (Exception e) {
188 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
189 execution.setVariable("errorCode", "1002")
190 execution.setVariable("errorText", e.getMessage())
191 //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in checkIfVnfInMaintInAAI(): ' + e.getMessage())
196 * Get VNF info from A&AI.
199 * @param execution The flow's execution instance.
201 public void queryAAIForVnf(DelegateExecution execution) {
202 def method = getClass().getSimpleName() + '.queryAAIForVnf(' +
203 'execution=' + execution.getId() +
206 msoLogger.trace('Entered ' + method)
209 def transactionLoggingUuid = UUID.randomUUID().toString()
210 def vnfId = execution.getVariable("vnfId")
211 msoLogger.debug("vnfId is: " + vnfId)
212 def cloudRegionId = execution.getVariable("lcpCloudRegionId")
213 msoLogger.debug("cloudRegionId is: " + cloudRegionId)
215 AAIResourcesClient client = new AAIResourcesClient()
216 AAIUri genericVnfUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
217 // Check if this VNF exists
218 if (!client.exists(genericVnfUri)) {
219 msoLogger.debug("VNF with vnfId " + vnfId + " does not exist in A&AI")
220 exceptionUtil.buildAndThrowWorkflowException(execution, 404, "VNF with vnfId " + vnfId + " does not exist in A&AI")
223 AAIResultWrapper aaiRW = client.get(genericVnfUri)
225 Map<String, Object> result = aaiRW.asMap()
227 String vnfName = result.get("vnf-name")
228 msoLogger.debug("vnfName from A&AI is: " + vnfName)
229 execution.setVariable("vnfName", vnfName)
230 String nfRole = result.get("nf-role")
231 msoLogger.debug("nfRole from A&AI is: " + nfRole)
232 execution.setVariable("nfRole", nfRole)
233 String vnfHostIpAddress = result.get("ipv4-oam-address")
234 msoLogger.debug("vnfHostIpAddress from A&AI is: " + vnfHostIpAddress)
235 execution.setVariable("vnfHostIpAddress", vnfHostIpAddress)
236 execution.setVariable("vmIdList", null)
237 if (aaiRW.getRelationships() != null) {
238 Relationships relationships = aaiRW.getRelationships().get()
239 if (relationships != null) {
241 List<AAIResourceUri> vserverUris = relationships.getRelatedAAIUris(AAIObjectType.VSERVER)
242 JSONArray vserverIds = new JSONArray()
243 JSONArray vserverSelfLinks = new JSONArray()
245 for (AAIResourceUri j in vserverUris) {
247 String vserverId = j.getURIKeys().get('vserver-id')
248 String vserverJson = client.get(j).getJson()
249 msoLogger.debug("Retrieved vserverJson from AAI: " + vserverJson)
250 String vserverSelfLink = jsonUtils.getJsonValue(vserverJson, "vserver-selflink")
252 vserverIds.put(vserverId)
253 vserverSelfLinks.put(vserverSelfLink)
256 JSONObject vmidsArray = new JSONObject()
257 JSONObject vserveridsArray = new JSONObject()
258 vmidsArray.put("vmIds", vserverSelfLinks.toString())
259 vserveridsArray.put("vserverIds", vserverIds.toString())
261 msoLogger.debug("vmidsArray is: " + vmidsArray.toString())
262 msoLogger.debug("vserveridsArray is: " + vserveridsArray.toString())
264 execution.setVariable("vmIdList", vmidsArray.toString())
265 execution.setVariable("vserverIdList", vserveridsArray.toString())
269 if (cloudRegionId != null) {
270 AAIUri cloudRegionUri = AAIUriFactory.createResourceUri(AAIObjectType.DEFAULT_CLOUD_REGION, cloudRegionId)
271 // Check if this client region exists
272 if (!client.exists(cloudRegionUri)) {
273 msoLogger.debug("Cloud Region with cloudRegionId " + cloudRegionId + " does not exist in A&AI")
274 exceptionUtil.buildAndThrowWorkflowException(execution, 404, "Cloud Region with cloudRegionId " + cloudRegionId + " does not exist in A&AI")
277 AAIResultWrapper aaiRWCloud = client.get(cloudRegionUri)
279 Map<String, Object> resultCloud = aaiRWCloud.asMap()
281 String aicIdentity = resultCloud.get("identity-url")
282 msoLogger.debug("aicIdentity from A&AI is: " + aicIdentity)
283 execution.setVariable("aicIdentity", aicIdentity)
285 // preserve relationships if exist
286 Optional<Relationships> relationships = aaiRW.getRelationships()
288 if(relationships.isPresent()) {
289 msoLogger.debug("relationships are present")
290 String rs = relationships.get().getJson()
291 def jsonSlurper = new JsonSlurper()
292 def map = jsonSlurper.parseText(rs)
293 if (map instanceof Map) {
294 List<Map<String, Object>> relationshipsList = (List<Map<String, Object>>)map.get("relationship");
295 for (Map<String, Object> relationship : relationshipsList) {
296 final String relatedTo = (String)relationship.get("related-to");
297 if (relatedTo.equals("platform")) {
298 List<Map<String, Object>> relationshipDataList = (List<Map<String, Object>>)relationship.get("relationship-data")
299 msoLogger.debug("Found platform entry")
300 for (Map<String, Object> relationshipData : relationshipDataList) {
301 String relationshipKey = (String)relationshipData.get("relationship-key");
302 if (relationshipKey.equals("platform.platform-name")) {
303 String platformName = (String) relationshipData.get("relationship-value")
304 msoLogger.debug("platform from A&AI is: " + platformName)
305 execution.setVariable("platform", platformName)
310 if (relatedTo.equals("line-of-business")) {
311 List<Map<String, Object>> relationshipDataList = (List<Map<String, Object>>)relationship.get("relationship-data")
312 msoLogger.debug("Found line-of-business entry")
313 for (Map<String, Object> relationshipData : relationshipDataList) {
314 String relationshipKey = (String)relationshipData.get("relationship-key");
315 if (relationshipKey.equals("line-of-business.line-of-business-name")) {
316 String lineOfBusinessName = (String) relationshipData.get("relationship-value")
317 msoLogger.debug("lineOfBusiness from A&AI is: " + lineOfBusinessName)
318 execution.setVariable("lineOfBusiness", lineOfBusinessName)
329 msoLogger.trace('Exited ' + method)
330 } catch (BpmnError e) {
332 } catch (Exception e) {
333 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
334 exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in queryAAIForVnf(): ' + e.getMessage())
341 * Check if this VNF's pservers are locked in A&AI.
344 * @param execution The flow's execution instance.
346 public void checkIfPserversInMaintInAAI(DelegateExecution execution) {
347 def method = getClass().getSimpleName() + '.checkIfPserversInMaintInAAI(' +
348 'execution=' + execution.getId() +
351 execution.setVariable('errorCode', "0")
352 msoLogger.trace('Entered ' + method)
353 execution.setVariable("workStep", "checkIfPserversInMaintInAAI")
354 execution.setVariable("failedActivity", "AAI")
357 AAIRestClientImpl client = new AAIRestClientImpl()
358 AAIValidatorImpl aaiValidator = new AAIValidatorImpl()
359 aaiValidator.setClient(client)
360 def vnfId = execution.getVariable("vnfId")
361 boolean areLocked = aaiValidator.isPhysicalServerLocked(vnfId)
362 msoLogger.debug("areLocked result: " + areLocked)
363 execution.setVariable('arePserversLocked', areLocked)
366 execution.setVariable("errorCode", "1003")
367 execution.setVariable("errorText", "pServers are locked in A&AI")
370 msoLogger.trace('Exited ' + method)
371 } catch (BpmnError e) {
373 } catch (Exception e) {
374 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
375 execution.setVariable("errorCode", "1002")
376 execution.setVariable("errorText", e.getMessage())
377 //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in checkIfPserversInMaintInAAI(): ' + e.getMessage())
382 * Set inMaint flag for this VNF to the specified value in A&AI.
385 * @param execution The flow's execution instance.
386 * @param inMaint The boolean value of the flag to set
388 public void setVnfInMaintFlagInAAI(DelegateExecution execution, boolean inMaint) {
389 def method = getClass().getSimpleName() + '.setVnfInMaintFlagInAAI(' +
390 'execution=' + execution.getId() +
393 execution.setVariable('errorCode', "0")
394 msoLogger.trace('Entered ' + method)
396 execution.setVariable("workStep", "setVnfInMaintFlagInAAI")
399 execution.setVariable("workStep", "unsetVnfInMaintFlagInAAI")
401 execution.setVariable("failedActivity", "AAI")
404 def transactionLoggingUuid = UUID.randomUUID().toString()
405 AAIRestClientImpl client = new AAIRestClientImpl()
406 AAIUpdatorImpl aaiUpdator = new AAIUpdatorImpl()
407 aaiUpdator.setClient(client)
408 def vnfId = execution.getVariable("vnfId")
410 aaiUpdator.updateVnfToLocked(vnfId, transactionLoggingUuid)
411 execution.setVariable("rollbackSetVnfInMaintenanceFlag", true)
414 aaiUpdator.updateVnfToUnLocked(vnfId, transactionLoggingUuid)
417 msoLogger.trace('Exited ' + method)
418 } catch (BpmnError e) {
420 } catch (Exception e) {
421 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
422 execution.setVariable("errorCode", "1002")
423 execution.setVariable("errorText", e.getMessage())
424 //exceptionUtil.buildAndThrowWorkflowException(execution, 1002, 'Error in setVnfInMaintFlagInAAI(): ' + e.getMessage())
429 * Check if VF Closed Loop Disabled in A&AI.
432 * @param execution The flow's execution instance.
434 public void checkIfClosedLoopDisabledInAAI(DelegateExecution execution) {
435 def method = getClass().getSimpleName() + '.checkIfClosedLoopDisabledInAAI(' +
436 'execution=' + execution.getId() +
439 execution.setVariable('errorCode', "0")
440 execution.setVariable("workStep", "checkClosedLoopDisabledFlagInAAI")
441 execution.setVariable("failedActivity", "AAI")
442 msoLogger.trace('Entered ' + method)
445 def transactionLoggingUuid = UUID.randomUUID().toString()
446 def vnfId = execution.getVariable("vnfId")
447 msoLogger.debug("vnfId is: " + vnfId)
448 AAIResourcesClient client = new AAIResourcesClient()
449 AAIUri genericVnfUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
450 AAIResultWrapper aaiRW = client.get(genericVnfUri)
451 Map<String, Object> result = aaiRW.asMap()
452 boolean isClosedLoopDisabled = result.getOrDefault("is-closed-loop-disabled", false)
454 msoLogger.debug("isClosedLoopDisabled result: " + isClosedLoopDisabled)
455 execution.setVariable('isClosedLoopDisabled', isClosedLoopDisabled)
457 if (isClosedLoopDisabled) {
458 execution.setVariable("errorCode", "1004")
459 execution.setVariable("errorText", "closedLoop is disabled in A&AI")
462 msoLogger.trace('Exited ' + method)
463 } catch (BpmnError e) {
465 } catch (Exception e) {
466 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
467 execution.setVariable("errorCode", "1002")
468 execution.setVariable("errorText", e.getMessage())
473 * Set VF Closed Loop Disabled Flag in A&AI.
476 * @param execution The flow's execution instance.
478 public void setClosedLoopDisabledInAAI(DelegateExecution execution, boolean setDisabled) {
479 def method = getClass().getSimpleName() + '.setClosedLoopDisabledInAAI(' +
480 'execution=' + execution.getId() +
483 execution.setVariable('errorCode', "0")
485 execution.setVariable("workStep", "setClosedLoopDisabledFlagInAAI")
486 execution.setVariable("rollbackSetClosedLoopDisabledFlag", true)
489 execution.setVariable("workStep", "unsetClosedLoopDisabledFlagInAAI")
490 execution.setVariable("rollbackSetClosedLoopDisabledFlag", false)
493 execution.setVariable("failedActivity", "AAI")
494 msoLogger.trace('Entered ' + method)
497 def transactionLoggingUuid = UUID.randomUUID().toString()
498 def vnfId = execution.getVariable("vnfId")
499 AAIResourcesClient client = new AAIResourcesClient()
500 AAIUri genericVnfUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
502 Map<String, Boolean> request = new HashMap<>()
503 request.put("is-closed-loop-disabled", setDisabled)
504 client.update(genericVnfUri, request)
505 msoLogger.debug("set isClosedLoop to: " + setDisabled)
507 msoLogger.trace('Exited ' + method)
508 } catch (BpmnError e) {
510 } catch (Exception e) {
511 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
512 execution.setVariable("errorCode", "1002")
513 execution.setVariable("errorText", e.getMessage())
521 * Call APP-C client to execute specified APP-C command for this VNF.
524 * @param execution The flow's execution instance.
525 * @param action The action to take in APP-C.
527 public void runAppcCommand(DelegateExecution execution, Action action) {
528 def method = getClass().getSimpleName() + '.runAppcCommand(' +
529 'execution=' + execution.getId() +
532 execution.setVariable('errorCode', "0")
533 msoLogger.trace('Entered ' + method)
535 ApplicationControllerClient appcClient = null
538 msoLogger.debug("Running APP-C action: " + action.toString())
539 String vnfId = execution.getVariable('vnfId')
540 String msoRequestId = execution.getVariable('requestId')
541 execution.setVariable('msoRequestId', msoRequestId)
542 execution.setVariable("failedActivity", "APP-C")
544 appcClient = new ApplicationControllerClient()
545 ApplicationControllerSupport support = new ApplicationControllerSupport()
546 appcClient.appCSupport=support
547 org.springframework.test.util.ReflectionTestUtils.setField(support, "lcmModelPackage", "org.onap.appc.client.lcm.model");
548 Flags flags = new Flags();
549 ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
550 actionIdentifiers.setVnfId(vnfId);
554 execution.setVariable('workStep', "LockVNF")
555 appcStatus = appcClient.runCommand(Action.Lock,actionIdentifiers,null,msoRequestId)
558 execution.setVariable('workStep', "UnlockVNF")
559 appcStatus = appcClient.runCommand(Action.Unlock,actionIdentifiers,null,msoRequestId)
561 case Action.HealthCheck:
562 def healthCheckIndex = execution.getVariable('healthCheckIndex')
563 execution.setVariable('workStep', "HealthCheckVNF" + healthCheckIndex)
564 execution.setVariable('healthCheckIndex', healthCheckIndex + 1)
565 appcStatus = appcClient.runCommand(Action.HealthCheck,actionIdentifiers,null,msoRequestId)
568 execution.setVariable('workStep', "StartVNF")
569 appcStatus = appcClient.runCommand(Action.Start,actionIdentifiers,null,msoRequestId)
572 execution.setVariable('workStep', "StopVNF")
573 appcStatus = appcClient.runCommand(Action.Stop,actionIdentifiers,null,msoRequestId)
578 msoLogger.debug("Completed AppC request")
579 int appcCode = appcStatus.getCode()
580 msoLogger.debug("AppC status code is: " + appcCode)
581 msoLogger.debug("AppC status message is: " + appcStatus.getMessage())
582 if (support.getCategoryOf(appcStatus) == ApplicationControllerSupport.StatusCategory.ERROR) {
583 execution.setVariable("errorCode", Integer.toString(appcCode))
584 execution.setVariable("errorText", appcStatus.getMessage())
587 msoLogger.trace('Exited ' + method)
588 } catch (BpmnError e) {
589 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
590 execution.setVariable("errorCode", "1002")
591 execution.setVariable("errorText", e.getMessage())
593 } catch (java.lang.NoSuchMethodError e) {
594 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
595 execution.setVariable("errorCode", "1002")
596 execution.setVariable("errorText", e.getMessage())
598 } catch (Exception e) {
599 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
600 execution.setVariable("errorCode", "1002")
601 execution.setVariable("errorText", e.getMessage())
607 * Placeholder for a call to APP-C client to execute specified APP-C command for this VNF.
610 * @param execution The flow's execution instance.
611 * @param action The action to take in APP-C.
613 public void runAppcCommandPlaceholder(DelegateExecution execution, String action) {
614 def method = getClass().getSimpleName() + '.runAppcCommandPlaceholder(' +
615 'execution=' + execution.getId() +
618 execution.setVariable('errorCode', "0")
619 msoLogger.trace('Entered ' + method)
620 execution.setVariable("failedActivity", "APP-C")
621 execution.setVariable("workStep", action)
631 * Builds a "CompletionHandler" request and stores it in the specified execution variable.
633 * @param execution the execution
634 * @param resultVar the execution variable in which the result will be stored
636 public void completionHandlerPrep(DelegateExecution execution, String resultVar) {
637 def method = getClass().getSimpleName() + '.completionHandlerPrep(' +
638 'execution=' + execution.getId() +
639 ', resultVar=' + resultVar +
642 msoLogger.trace('Entered ' + method)
646 def requestInfo = execution.getVariable('requestInfo')
649 <sdncadapterworkflow:MsoCompletionRequest xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
650 xmlns:reqtype="http://org.onap/so/request/types/v1">
652 <sdncadapterworkflow:status-message>Vnf has been updated successfully.</sdncadapterworkflow:status-message>
653 <sdncadapterworkflow:mso-bpel-name>MSO_ACTIVATE_BPEL</sdncadapterworkflow:mso-bpel-name>
654 </sdncadapterworkflow:MsoCompletionRequest>
657 content = utils.formatXml(content)
658 msoLogger.debug(resultVar + ' = ' + System.lineSeparator() + content)
659 execution.setVariable(resultVar, content)
661 msoLogger.trace('Exited ' + method)
662 } catch (BpmnError e) {
664 } catch (Exception e) {
665 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
666 exceptionUtil.buildAndThrowWorkflowException(execution, 2000, 'Internal Error')
671 * Prepare DoUpdateVnfAndModules call.
674 * @param execution The flow's execution instance.
676 public void prepDoUpdateVnfAndModules(DelegateExecution execution) {
677 def method = getClass().getSimpleName() + '.prepDoUpdateVnfAndModules(' +
678 'execution=' + execution.getId() +
681 execution.setVariable('errorCode', "0")
682 msoLogger.trace('Entered ' + method)
683 execution.setVariable("workStep", "doUpdateVnfAndModules")
684 execution.setVariable("failedActivity", "MSO Update VNF")
685 msoLogger.trace('Exited ' + method)
690 * Builds a "FalloutHandler" request and stores it in the specified execution variable.
692 * @param execution the execution
693 * @param resultVar the execution variable in which the result will be stored
695 public void falloutHandlerPrep(DelegateExecution execution, String resultVar) {
696 def method = getClass().getSimpleName() + '.falloutHandlerPrep(' +
697 'execution=' + execution.getId() +
698 ', resultVar=' + resultVar +
701 msoLogger.trace('Entered ' + method)
704 def prefix = execution.getVariable('prefix')
705 def requestInformation = execution.getVariable("requestInfo")
707 def WorkflowException workflowException = execution.getVariable("WorkflowException")
708 def errorResponseCode = workflowException.getErrorCode()
709 def errorResponseMsg = workflowException.getErrorMessage()
710 def encErrorResponseMsg = ""
711 if (errorResponseMsg != null) {
712 encErrorResponseMsg = errorResponseMsg
716 <sdncadapterworkflow:FalloutHandlerRequest xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"
717 xmlns:reqtype="http://org.onap/so/request/types/v1"
718 xmlns:msoservtypes="http://org.onap/so/request/types/v1"
719 xmlns:structuredtypes="http://org.onap/so/structured/types/v1">
720 ${requestInformation}
721 <sdncadapterworkflow:WorkflowException>
722 <sdncadapterworkflow:ErrorMessage>${MsoUtils.xmlEscape(encErrorResponseMsg)}</sdncadapterworkflow:ErrorMessage>
723 <sdncadapterworkflow:ErrorCode>${MsoUtils.xmlEscape(errorResponseCode)}</sdncadapterworkflow:ErrorCode>
724 </sdncadapterworkflow:WorkflowException>
725 </sdncadapterworkflow:FalloutHandlerRequest>
727 content = utils.formatXml(content)
728 msoLogger.debug(resultVar + ' = ' + System.lineSeparator() + content)
729 execution.setVariable(resultVar, content)
731 msoLogger.trace('Exited ' + method)
732 } catch (BpmnError e) {
734 } catch (Exception e) {
735 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
736 exceptionUtil.buildWorkflowException(execution, 2000, 'Internal Error')
741 * Handle Abort disposition from RainyDayHandler
743 * @param execution The flow's execution instance.
745 public void abortProcessing(DelegateExecution execution) {
746 def method = getClass().getSimpleName() + '.abortProcessing(' +
747 'execution=' + execution.getId() +
750 msoLogger.trace('Entered ' + method)
752 def errorText = execution.getVariable("errorText")
753 def errorCode = execution.getVariable("errorCode")
755 exceptionUtil.buildAndThrowWorkflowException(execution, errorCode as Integer, errorText)
759 * Increment Retry Count for Current Work Step
761 * @param execution The flow's execution instance.
763 public void incrementRetryCount(DelegateExecution execution) {
764 def method = getClass().getSimpleName() + '.incrementRetryCount(' +
765 'execution=' + execution.getId() +
768 msoLogger.trace('Entered ' + method)
770 String retryCountVariableName = execution.getVariable("workStep") + "RetryCount"
771 execution.setVariable("retryCountVariableName", retryCountVariableName)
773 def retryCountVariable = execution.getVariable(retryCountVariableName)
776 if (retryCountVariable != null) {
777 retryCount = (int) retryCountVariable
782 execution.setVariable(retryCountVariableName, retryCount)
784 msoLogger.debug("value of " + retryCountVariableName + " is " + retryCount)
785 msoLogger.trace('Exited ' + method)
791 public void preProcessRollback (DelegateExecution execution) {
792 msoLogger.trace("preProcessRollback ")
795 Object workflowException = execution.getVariable("WorkflowException");
797 if (workflowException instanceof WorkflowException) {
798 msoLogger.debug("Prev workflowException: " + workflowException.getErrorMessage())
799 execution.setVariable("prevWorkflowException", workflowException);
800 //execution.setVariable("WorkflowException", null);
802 } catch (BpmnError e) {
803 msoLogger.debug("BPMN Error during preProcessRollback")
804 } catch(Exception ex) {
805 String msg = "Exception in preProcessRollback. " + ex.getMessage()
808 msoLogger.trace("Exit preProcessRollback ")
811 public void postProcessRollback (DelegateExecution execution) {
812 msoLogger.trace("postProcessRollback ")
815 Object workflowException = execution.getVariable("prevWorkflowException");
816 if (workflowException instanceof WorkflowException) {
817 msoLogger.debug("Setting prevException to WorkflowException: ")
818 execution.setVariable("WorkflowException", workflowException);
821 } catch (BpmnError b) {
822 msoLogger.debug("BPMN Error during postProcessRollback")
824 } catch(Exception ex) {
825 msg = "Exception in postProcessRollback. " + ex.getMessage()
828 msoLogger.trace("Exit postProcessRollback ")