AT&T 1712 and 1802 release code
[so.git] / bpmn / MSOCommonBPMN / src / main / groovy / org / openecomp / mso / bpmn / common / scripts / AppCClient.groovy
1 package org.openecomp.mso.bpmn.common.scripts
2
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;
18
19 /**
20  * This groovy class supports the <class>AppCClient.bpmn</class> process.
21  *
22  * Inputs:
23  * @param - msoRequestId
24  * @param - mso-request-Id
25  * @param - isDebugLogEnabled
26  * @param - requestId
27  * @param - vnfId
28  * @param - action
29  * @param - payload
30  *
31  * Outputs:
32  * @param - errorcode
33  * @param - errorText
34  * @param - responsePayload
35  * @param - healthCheckIndex
36  * @param - workstep
37  * @param - rollbackVnfStop
38  * @param - rollbackVnfLock
39  * @param - rollbackQuiesceTraffic
40  */
41
42 public class AppCClient extends AbstractServiceTaskProcessor{
43         
44         ExceptionUtil exceptionUtil = new ExceptionUtil()
45         JsonUtils jsonUtils = new JsonUtils()
46         def prefix = "UPDVnfI_"
47         
48         public void preProcessRequest(DelegateExecution execution){
49
50         }
51         
52         public void runAppcCommand(DelegateExecution execution) {
53                 String isDebugLogEnabled = execution.getVariable('isDebugLogEnabled')
54                 utils.log("DEBUG", "***** Start runCommand *****", isDebugLogEnabled)
55                 def method = getClass().getSimpleName() + '.runAppcCommand(' +
56                 'execution=' + execution.getId() +
57                 ')'
58                 logDebug('Entered ' + method, isDebugLogEnabled)
59                 execution.setVariable("rollbackVnfStop", false)
60                 execution.setVariable("rollbackVnfLock", false)
61                 execution.setVariable("rollbackQuiesceTraffic", false)
62                 String appcCode = "1002"
63                 String responsePayload = ""
64                 String appcMessage = ""
65                 Action action = null
66                 try {
67                         action = (Action) execution.getVariable("action")
68                         String vnfId = execution.getVariable('vnfId')
69                         String msoRequestId = execution.getVariable('msoRequestId')
70                         String vnfName = execution.getVariable('vnfName')
71                         String aicIdentity = execution.getVariable('aicIdentity')
72                         String vnfHostIpAddress = execution.getVariable('vnfHostIpAddress')
73                         String vmIdList = execution.getVariable("vmIdList")
74                         String identityUrl = execution.getVariable("identityUrl")
75                         HashMap<String, String> payloadInfo = new HashMap<String, String>();
76                         payloadInfo.put("vnfName", vnfName)
77                         payloadInfo.put("aicIdentity", aicIdentity)
78                         payloadInfo.put("vnfHostIpAddress", vnfHostIpAddress)
79                         payloadInfo.put("vmIdList", vmIdList)
80                         payloadInfo.put("identityUrl", identityUrl)
81                         Optional<String> payload
82                         logDebug("Running APP-C action: " + action.toString(), isDebugLogEnabled)
83                         utils.log("DEBUG", "VNFID: " + vnfId, isDebugLogEnabled)
84                         execution.setVariable('msoRequestId', msoRequestId)
85                         execution.setVariable("failedActivity", "APP-C")
86                         execution.setVariable('workStep', action.toString())
87                         if(execution.getVariable("payload") != null){
88                                 String pay = execution.getVariable("payload")
89                                 payload =  Optional.of(pay)
90                         }
91                         if(action.equals(Action.HealthCheck)){
92                                 String healthCheckIndex = execution.getVariable('healthCheckIndex')
93                                 execution.setVariable('workStep', action.toString() + healthCheckIndex)
94                                 execution.setVariable('healthCheckIndex', healthCheckIndex + 1)
95                         }
96                         ApplicationControllerAction client = new ApplicationControllerAction()
97                         utils.log("DEBUG", "Created Application Controller Action Object", isDebugLogEnabled)
98                         //PayloadInfo contains extra information that adds on to payload before making request to appc
99                         client.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo)
100                         utils.log("DEBUG", "ran through the main method for Application Contoller", isDebugLogEnabled)
101                         appcCode = client.getErrorCode()
102                         appcMessage = client.getErrorMessage()
103                 }
104                 catch (BpmnError e) {
105                         logError('Caught exception in ' + method, e)
106                         appcMessage = e.getMessage()
107                 }
108                 execution.setVariable("errorCode", appcCode)
109                 if (appcCode == '0' && action != null) {
110                         if (action.equals(Action.Lock)) {
111                                 execution.setVariable("rollbackVnfLock", true)
112                         }
113                         if (action.equals(Action.Unlock)) {
114                                 execution.setVariable("rollbackVnfLock", false)
115                         }
116                         if (action.equals(Action.Start)) {
117                                 execution.setVariable("rollbackVnfStop", true)
118                         }
119                         if (action.equals(Action.Stop)) {
120                                 execution.setVariable("rollbackVnfStop", false)
121                         }
122                         if (action.equals(Action.QuiesceTraffic)) {
123                                 execution.setVariable("rollbackQuiesceTraffic", true)
124                         }
125                         if (action.equals(Action.ResumeTraffic)) {
126                                 execution.setVariable("rollbackQuiesceTraffic", false)
127                         }
128                 }
129                 execution.setVariable("errorText", appcMessage)
130                 execution.setVariable("responsePayload", responsePayload)
131                 utils.log("DEBUG", "Error Message: " + appcMessage, isDebugLogEnabled)
132                 utils.log("DEBUG","ERROR CODE: " + execution.getVariable("errorCode"), isDebugLogEnabled)
133                 utils.log("DEBUG", "***** End of runCommand *****", isDebugLogEnabled)
134         }
135 }