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
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.common.scripts
23 import org.onap.so.bpmn.core.UrnPropertiesReader
25 import java.util.HashMap;
26 import org.camunda.bpm.engine.delegate.BpmnError
27 import org.camunda.bpm.engine.delegate.DelegateExecution
28 import org.hibernate.event.internal.AbstractLockUpgradeEventListener
29 import org.onap.so.bpmn.core.json.JsonUtils
30 import org.onap.so.client.appc.ApplicationControllerOrchestrator
31 import org.onap.so.client.appc.ApplicationControllerOrchestratorException
32 import org.onap.appc.client.lcm.model.Action
33 import org.onap.appc.client.lcm.model.Status
34 import org.onap.so.bpmn.appc.payload.PayloadClient
35 import org.onap.so.client.appc.ApplicationControllerAction;
36 import groovy.transform.TypeChecked;
37 import java.util.UUID;
38 import org.onap.so.logger.MessageEnum
39 import org.onap.so.logger.MsoLogger
42 * This groovy class supports the <class>AppCClient.bpmn</class> process.
45 * @param - msoRequestId
46 * @param - mso-request-Id
47 * @param - isDebugLogEnabled
56 * @param - responsePayload
57 * @param - healthCheckIndex
61 public class AppCClient extends AbstractServiceTaskProcessor{
62 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, AppCClient.class);
64 ExceptionUtil exceptionUtil = new ExceptionUtil()
65 JsonUtils jsonUtils = new JsonUtils()
66 def prefix = "UPDVnfI_"
68 public void preProcessRequest(DelegateExecution execution){
72 public void runAppcCommand(DelegateExecution execution) {
73 msoLogger.trace("Start runCommand ")
74 def method = getClass().getSimpleName() + '.runAppcCommand(' +
75 'execution=' + execution.getId() +
77 msoLogger.trace('Entered ' + method)
78 execution.setVariable("rollbackVnfStop", false)
79 execution.setVariable("rollbackVnfLock", false)
80 execution.setVariable("rollbackQuiesceTraffic", false)
81 String appcCode = "1002"
82 String responsePayload = ""
83 String appcMessage = ""
86 action = (Action) execution.getVariable("action")
87 String vnfId = execution.getVariable('vnfId')
88 String msoRequestId = execution.getVariable('msoRequestId')
89 String vnfName = execution.getVariable('vnfName')
90 String aicIdentity = execution.getVariable('aicIdentity')
91 String vnfHostIpAddress = execution.getVariable('vnfHostIpAddress')
92 String vmIdList = execution.getVariable("vmIdList")
93 String vserverIdList = execution.getVariable("vserverIdList")
94 String identityUrl = execution.getVariable("identityUrl")
95 String controllerType = execution.getVariable("controllerType")
96 String vfModuleId = execution.getVariable("vfModuleId")
97 HashMap<String, String> payloadInfo = new HashMap<String, String>();
98 payloadInfo.put("vnfName", vnfName)
99 payloadInfo.put("aicIdentity", aicIdentity)
100 payloadInfo.put("vnfHostIpAddress", vnfHostIpAddress)
101 payloadInfo.put("vmIdList", vmIdList)
102 payloadInfo.put("vserverIdList", vserverIdList)
103 payloadInfo.put("identityUrl", identityUrl)
104 payloadInfo.put("vfModuleId",vfModuleId)
105 Optional<String> payload
106 msoLogger.debug("Running APP-C action: " + action.toString())
107 msoLogger.debug("VNFID: " + vnfId)
108 execution.setVariable('msoRequestId', msoRequestId)
109 execution.setVariable("failedActivity", "APP-C")
110 execution.setVariable('workStep', action.toString())
111 if(execution.getVariable("payload") != null){
112 String pay = execution.getVariable("payload")
113 payload = Optional.of(pay)
115 if(action.equals(Action.HealthCheck)){
116 String healthCheckIndex = execution.getVariable('healthCheckIndex')
117 execution.setVariable('workStep', action.toString() + healthCheckIndex)
118 execution.setVariable('healthCheckIndex', healthCheckIndex + 1)
120 ApplicationControllerAction client = new ApplicationControllerAction()
121 msoLogger.debug("Created Application Controller Action Object")
122 //PayloadInfo contains extra information that adds on to payload before making request to appc
123 client.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType)
124 msoLogger.debug("ran through the main method for Application Contoller")
125 appcCode = client.getErrorCode()
126 appcMessage = client.getErrorMessage()
128 catch (BpmnError e) {
129 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION_ARG, 'Caught exception in ' + method, "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "Exception is:\n" + e);
130 appcMessage = e.getMessage()
132 execution.setVariable("errorCode", appcCode)
133 if (appcCode == '0' && action != null) {
134 if (action.equals(Action.Lock)) {
135 execution.setVariable("rollbackVnfLock", true)
137 if (action.equals(Action.Unlock)) {
138 execution.setVariable("rollbackVnfLock", false)
140 if (action.equals(Action.Start)) {
141 execution.setVariable("rollbackVnfStop", true)
143 if (action.equals(Action.Stop)) {
144 execution.setVariable("rollbackVnfStop", false)
146 if (action.equals(Action.QuiesceTraffic)) {
147 execution.setVariable("rollbackQuiesceTraffic", true)
149 if (action.equals(Action.ResumeTraffic)) {
150 execution.setVariable("rollbackQuiesceTraffic", false)
153 execution.setVariable("errorText", appcMessage)
154 execution.setVariable("responsePayload", responsePayload)
155 msoLogger.debug("Error Message: " + appcMessage)
156 msoLogger.debug("ERROR CODE: " + execution.getVariable("errorCode"))
157 msoLogger.trace("End of runCommand ")