1 package org.openecomp.mso.bpmn.common.scripts
3 import java.util.HashMap;
4 import org.camunda.bpm.engine.delegate.BpmnError
5 import org.camunda.bpm.engine.delegate.DelegateExecution
6 import org.hibernate.event.internal.AbstractLockUpgradeEventListener
7 import org.openecomp.mso.bpmn.core.HealthCheckHandler
8 import org.openecomp.mso.bpmn.core.json.JsonUtils
9 import org.openecomp.mso.client.appc.ApplicationControllerOrchestrator
10 import org.openecomp.mso.client.appc.ApplicationControllerOrchestratorException
11 import org.onap.appc.client.lcm.model.Action
12 import org.onap.appc.client.lcm.model.Status
13 import org.openecomp.mso.bpmn.appc.payload.PayloadClient
14 import org.openecomp.mso.bpmn.common.adapter.vnf.CreateVnfNotification.Outputs
15 import org.openecomp.mso.client.appc.ApplicationControllerAction;
16 import groovy.transform.TypeChecked;
17 import java.util.UUID;
20 * This groovy class supports the <class>AppCClient.bpmn</class> process.
23 * @param - msoRequestId
24 * @param - mso-request-Id
25 * @param - isDebugLogEnabled
31 * @param - controllerType
36 * @param - responsePayload
37 * @param - healthCheckIndex
39 * @param - rollbackVnfStop
40 * @param - rollbackVnfLock
41 * @param - rollbackQuiesceTraffic
44 public class AppCClient extends AbstractServiceTaskProcessor{
46 ExceptionUtil exceptionUtil = new ExceptionUtil()
47 JsonUtils jsonUtils = new JsonUtils()
48 def prefix = "UPDVnfI_"
50 public void preProcessRequest(DelegateExecution execution){
54 public void runAppcCommand(DelegateExecution execution) {
55 String isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
56 utils.log("DEBUG", "***** Start runCommand *****", isDebugLogEnabled)
57 def method = getClass().getSimpleName() + '.runAppcCommand(' +
58 'execution=' + execution.getId() +
60 logDebug('Entered ' + method, isDebugLogEnabled)
61 execution.setVariable("rollbackVnfStop", false)
62 execution.setVariable("rollbackVnfLock", false)
63 execution.setVariable("rollbackQuiesceTraffic", false)
64 String appcCode = "1002"
65 String responsePayload = ""
66 String appcMessage = ""
69 action = (Action) execution.getVariable("action")
70 String vnfId = execution.getVariable('vnfId')
71 String msoRequestId = execution.getVariable('msoRequestId')
72 String vnfName = execution.getVariable('vnfName')
73 String aicIdentity = execution.getVariable('aicIdentity')
74 String vnfHostIpAddress = execution.getVariable('vnfHostIpAddress')
75 String vmIdList = execution.getVariable("vmIdList")
76 String identityUrl = execution.getVariable("identityUrl")
77 String controllerType = execution.getVariable("controllerType")
78 String vfModuleId = execution.getVariable("vfModuleId")
79 HashMap<String, String> payloadInfo = new HashMap<String, String>();
80 payloadInfo.put("vnfName", vnfName)
81 payloadInfo.put("aicIdentity", aicIdentity)
82 payloadInfo.put("vnfHostIpAddress", vnfHostIpAddress)
83 payloadInfo.put("vmIdList", vmIdList)
84 payloadInfo.put("identityUrl", identityUrl)
85 payloadInfo.put("vfModuleId",vfModuleId)
86 Optional<String> payload
87 logDebug("Running APP-C action: " + action.toString(), isDebugLogEnabled)
88 utils.log("DEBUG", "VNFID: " + vnfId, isDebugLogEnabled)
89 execution.setVariable('msoRequestId', msoRequestId)
90 execution.setVariable("failedActivity", "APP-C")
91 execution.setVariable('workStep', action.toString())
92 if(execution.getVariable("payload") != null){
93 String pay = execution.getVariable("payload")
94 payload = Optional.of(pay)
96 if(action.equals(Action.HealthCheck)){
97 String healthCheckIndex = execution.getVariable('healthCheckIndex')
98 execution.setVariable('workStep', action.toString() + healthCheckIndex)
99 execution.setVariable('healthCheckIndex', healthCheckIndex + 1)
101 ApplicationControllerAction client = new ApplicationControllerAction()
102 utils.log("DEBUG", "Created Application Controller Action Object", isDebugLogEnabled)
103 //PayloadInfo contains extra information that adds on to payload before making request to appc
104 client.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType)
105 utils.log("DEBUG", "ran through the main method for Application Contoller", isDebugLogEnabled)
106 appcCode = client.getErrorCode()
107 appcMessage = client.getErrorMessage()
109 catch (BpmnError e) {
110 logError('Caught exception in ' + method, e)
111 appcMessage = e.getMessage()
113 execution.setVariable("errorCode", appcCode)
114 if (appcCode == '0' && action != null) {
115 if (action.equals(Action.Lock)) {
116 execution.setVariable("rollbackVnfLock", true)
118 if (action.equals(Action.Unlock)) {
119 execution.setVariable("rollbackVnfLock", false)
121 if (action.equals(Action.Start)) {
122 execution.setVariable("rollbackVnfStop", true)
124 if (action.equals(Action.Stop)) {
125 execution.setVariable("rollbackVnfStop", false)
127 if (action.equals(Action.QuiesceTraffic)) {
128 execution.setVariable("rollbackQuiesceTraffic", true)
130 if (action.equals(Action.ResumeTraffic)) {
131 execution.setVariable("rollbackQuiesceTraffic", false)
134 execution.setVariable("errorText", appcMessage)
135 execution.setVariable("responsePayload", responsePayload)
136 utils.log("DEBUG", "Error Message: " + appcMessage, isDebugLogEnabled)
137 utils.log("DEBUG","ERROR CODE: " + execution.getVariable("errorCode"), isDebugLogEnabled)
138 utils.log("DEBUG", "***** End of runCommand *****", isDebugLogEnabled)