Merge "Reorder modifiers"
[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  * @param - vnfName
31  * @param - controllerType
32  *
33  * Outputs:
34  * @param - errorcode
35  * @param - errorText
36  * @param - responsePayload
37  * @param - healthCheckIndex
38  * @param - workstep
39  * @param - rollbackVnfStop
40  * @param - rollbackVnfLock
41  * @param - rollbackQuiesceTraffic
42  */
43
44 public class AppCClient extends AbstractServiceTaskProcessor{
45         
46         ExceptionUtil exceptionUtil = new ExceptionUtil()
47         JsonUtils jsonUtils = new JsonUtils()
48         def prefix = "UPDVnfI_"
49         
50         public void preProcessRequest(DelegateExecution execution){
51
52         }
53         
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() +
59                 ')'
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 = ""
67                 Action action = null
68                 try {
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)
95                         }
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)
100                         }
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()
108                 }
109                 catch (BpmnError e) {
110                         logError('Caught exception in ' + method, e)
111                         appcMessage = e.getMessage()
112                 }
113                 execution.setVariable("errorCode", appcCode)
114                 if (appcCode == '0' && action != null) {
115                         if (action.equals(Action.Lock)) {
116                                 execution.setVariable("rollbackVnfLock", true)
117                         }
118                         if (action.equals(Action.Unlock)) {
119                                 execution.setVariable("rollbackVnfLock", false)
120                         }
121                         if (action.equals(Action.Start)) {
122                                 execution.setVariable("rollbackVnfStop", true)
123                         }
124                         if (action.equals(Action.Stop)) {
125                                 execution.setVariable("rollbackVnfStop", false)
126                         }
127                         if (action.equals(Action.QuiesceTraffic)) {
128                                 execution.setVariable("rollbackQuiesceTraffic", true)
129                         }
130                         if (action.equals(Action.ResumeTraffic)) {
131                                 execution.setVariable("rollbackQuiesceTraffic", false)
132                         }
133                 }
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)
139         }
140 }