summaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/AppCClient.groovy
blob: 5cbbe0ab469f81243bda4e995d0149cc14b9921c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*-
 * ============LICENSE_START=======================================================
 * ONAP - SO
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.so.bpmn.common.scripts

import org.camunda.bpm.engine.delegate.BpmnError
import org.camunda.bpm.engine.delegate.DelegateExecution
import org.onap.so.bpmn.core.json.JsonUtils
import org.onap.appc.client.lcm.model.Action
import org.onap.so.client.appc.ApplicationControllerAction;
import org.onap.so.logger.MessageEnum
import org.onap.so.logger.MsoLogger

/**
 * This groovy class supports the <class>AppCClient.bpmn</class> process.
 *
 * Inputs:
 * @param - msoRequestId
 * @param - mso-request-Id
 * @param - isDebugLogEnabled
 * @param - requestId
 * @param - vnfId
 * @param - action
 * @param - payload
 * 
 * Outputs:
 * @param - errorcode
 * @param - errorText
 * @param - responsePayload
 * @param - healthCheckIndex
 * @param - workstep
 */

public class AppCClient extends AbstractServiceTaskProcessor{
	private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, AppCClient.class);

	ExceptionUtil exceptionUtil = new ExceptionUtil()
	JsonUtils jsonUtils = new JsonUtils()
	def prefix = "UPDVnfI_"
	
    public void preProcessRequest(DelegateExecution execution){

	}
	
	public void runAppcCommand(DelegateExecution execution) {
		msoLogger.trace("Start runCommand ")
		def method = getClass().getSimpleName() + '.runAppcCommand(' +
		'execution=' + execution.getId() +
		')'
		msoLogger.trace('Entered ' + method)
		execution.setVariable("rollbackVnfStop", false)
		execution.setVariable("rollbackVnfLock", false)
		execution.setVariable("rollbackQuiesceTraffic", false)
		String appcCode = "1002"
		String responsePayload = ""
		String appcMessage = ""
		Action action = null
		try {
			action = (Action) execution.getVariable("action")
			String vnfId = execution.getVariable('vnfId')
			String msoRequestId = execution.getVariable('msoRequestId')
			String vnfName = execution.getVariable('vnfName')
			String aicIdentity = execution.getVariable('aicIdentity')
			String vnfHostIpAddress = execution.getVariable('vnfHostIpAddress')
			String vmIdList = execution.getVariable("vmIdList")
			String vserverIdList = execution.getVariable("vserverIdList")
			String identityUrl = execution.getVariable("identityUrl")
			String controllerType = execution.getVariable("controllerType")			
			String vfModuleId = execution.getVariable("vfModuleId")		
			HashMap<String, String> payloadInfo = new HashMap<String, String>();
			payloadInfo.put("vnfName", vnfName)
			payloadInfo.put("aicIdentity", aicIdentity)
			payloadInfo.put("vnfHostIpAddress", vnfHostIpAddress)
			payloadInfo.put("vmIdList", vmIdList)
			payloadInfo.put("vserverIdList", vserverIdList)
			payloadInfo.put("identityUrl", identityUrl)
			payloadInfo.put("vfModuleId",vfModuleId)
			Optional<String> payload
			msoLogger.debug("Running APP-C action: " + action.toString())
			msoLogger.debug("VNFID: " + vnfId)
			execution.setVariable('msoRequestId', msoRequestId)
			execution.setVariable("failedActivity", "APP-C")
			execution.setVariable('workStep', action.toString())
			if(execution.getVariable("payload") != null){
				String pay = execution.getVariable("payload")
				payload =  Optional.of(pay)
			}
			if(action.equals(Action.HealthCheck)){
				Integer healthCheckIndex = (Integer) execution.getVariable('healthCheckIndex')
				execution.setVariable('workStep', action.toString() + healthCheckIndex)
				execution.setVariable('healthCheckIndex', healthCheckIndex + 1)
			}
			ApplicationControllerAction client = new ApplicationControllerAction()
			msoLogger.debug("Created Application Controller Action Object")
			//PayloadInfo contains extra information that adds on to payload before making request to appc
			client.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType)
			msoLogger.debug("ran through the main method for Application Contoller")
			appcCode = client.getErrorCode()
			appcMessage = client.getErrorMessage()
		}
		catch (BpmnError e) {
			msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
			appcMessage = e.getMessage()
		} 
		execution.setVariable("errorCode", appcCode)
		if (appcCode == '0' && action != null) {
			if (action.equals(Action.Lock)) {
				execution.setVariable("rollbackVnfLock", true)
			}
			if (action.equals(Action.Unlock)) {
				execution.setVariable("rollbackVnfLock", false)
			}
			if (action.equals(Action.Start)) {
				execution.setVariable("rollbackVnfStop", true)
			}
			if (action.equals(Action.Stop)) {
				execution.setVariable("rollbackVnfStop", false)
			}
			if (action.equals(Action.QuiesceTraffic)) {
				execution.setVariable("rollbackQuiesceTraffic", true)
			}
			if (action.equals(Action.ResumeTraffic)) {
				execution.setVariable("rollbackQuiesceTraffic", false)
			}
		}
		execution.setVariable("errorText", appcMessage)
		execution.setVariable("responsePayload", responsePayload)
		msoLogger.debug("Error Message: " + appcMessage)
		msoLogger.debug("ERROR CODE: " + execution.getVariable("errorCode"))
		msoLogger.trace("End of runCommand ")
	}    
}