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.openecomp.mso.client.appc;
23 import java.util.HashMap;
24 import java.util.List;
26 import org.openecomp.mso.client.appc.ApplicationControllerSupport.StatusCategory;
27 import org.openecomp.mso.bpmn.appc.payload.PayloadClient;
28 import org.openecomp.mso.bpmn.core.json.JsonUtils;
29 import org.openecomp.mso.client.appc.ApplicationControllerOrchestrator;
30 import java.util.Optional;
31 import org.onap.appc.client.lcm.model.Action;
32 import org.onap.appc.client.lcm.model.Status;
33 import com.att.eelf.configuration.EELFLogger;
34 import com.att.eelf.configuration.EELFManager;
35 import com.att.eelf.configuration.EELFLogger.Level;
36 import java.lang.NoSuchMethodError;
37 import com.fasterxml.jackson.core.JsonProcessingException;
38 import com.fasterxml.jackson.core.type.TypeReference;
39 import com.fasterxml.jackson.databind.JsonMappingException;
40 import com.fasterxml.jackson.databind.ObjectMapper;
43 public class ApplicationControllerAction {
44 protected ApplicationControllerOrchestrator client = new ApplicationControllerOrchestrator();
45 private String errorCode = "1002";
46 private String errorMessage = "Unable to reach App C Servers";
47 protected final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
49 public void runAppCCommand(Action action, String msoRequestId, String vnfId, Optional<String> payload, HashMap<String, String> payloadInfo, String controllerType){ Status appCStatus = null;
51 String vnfName = payloadInfo.getOrDefault("vnfName", "");
52 String aicIdentity = payloadInfo.getOrDefault("vnfName","");
53 String vnfHostIpAddress = payloadInfo.getOrDefault("vnfHostIpAddress","");
54 String vmIdList = payloadInfo.getOrDefault("vmIdList", "");
55 String identityUrl = payloadInfo.getOrDefault("identityUrl", "");
58 appCStatus = resumeTrafficAction(msoRequestId, vnfId, vnfName, controllerType);
62 appCStatus = startStopAction(action, msoRequestId, vnfId, aicIdentity, controllerType);
66 appCStatus = client.vnfCommand(action, msoRequestId, vnfId, Optional.empty(), controllerType);
69 appCStatus = quiesceTrafficAction(msoRequestId, vnfId, payload, vnfName, controllerType);
72 appCStatus = healthCheckAction(msoRequestId, vnfId, vnfName, vnfHostIpAddress, controllerType);
75 String vmIds = JsonUtils.getJsonValue(vmIdList, "vmIds");
77 ObjectMapper mapper = new ObjectMapper();
78 List<String> vmIdJsonList = mapper.readValue(vmIds, new TypeReference<List<String>>(){});
80 while(i < vmIdJsonList.size()){
81 vmId = vmIdJsonList.get(i);
82 appCStatus = snapshotAction(msoRequestId, vnfId, vmId, identityUrl, controllerType);
87 appCStatus = payloadAction(action, msoRequestId, vnfId, payload, controllerType);
90 case UpgradePostCheck:
93 appCStatus = upgradeAction(action,msoRequestId, vnfId, payload, vnfName, controllerType);
96 errorMessage = "Unable to idenify Action request for AppCClient";
99 if(appCStatus != null){
100 errorCode = Integer.toString(appCStatus.getCode());
101 errorMessage = appCStatus.getMessage();
104 if(ApplicationControllerSupport.getCategoryOf(appCStatus).equals(StatusCategory.NORMAL)){
108 catch(JsonProcessingException e){
109 auditLogger.log(Level.ERROR, "Incorrect Payload format for action request" + action.toString(),e, e.getMessage());
110 errorMessage = e.getMessage();
112 catch(ApplicationControllerOrchestratorException e){
113 auditLogger.log(Level.ERROR, "Error building Appc request: ", e, e.getMessage());
115 errorMessage = e.getMessage();
117 catch (NoSuchMethodError e) {
118 auditLogger.log(Level.ERROR, "Error building Appc request: ", e, e.getMessage());
119 errorMessage = e.getMessage();
122 auditLogger.log(Level.ERROR, "Error building Appc request: ", e, e.getMessage());
123 errorMessage = e.getMessage();
127 private Status payloadAction(Action action, String msoRequestId, String vnfId, Optional<String> payload, String controllerType) throws JsonProcessingException, IllegalArgumentException,ApplicationControllerOrchestratorException{
128 if(!(payload.isPresent())){
129 throw new IllegalArgumentException("Payload is not present for " + action.toString());
131 return client.vnfCommand(action, msoRequestId, vnfId, payload, controllerType);
134 private Status quiesceTrafficAction(String msoRequestId, String vnfId, Optional<String> payload, String vnfName, String controllerType) throws JsonProcessingException, IllegalArgumentException,ApplicationControllerOrchestratorException{
135 if(!(payload.isPresent())){
136 throw new IllegalArgumentException("Payload is not present for " + Action.QuiesceTraffic.toString());
138 payload = PayloadClient.quiesceTrafficFormat(payload, vnfName);
139 return client.vnfCommand(Action.QuiesceTraffic, msoRequestId, vnfId, payload, controllerType);
142 private Status upgradeAction(Action action, String msoRequestId, String vnfId, Optional<String> payload, String vnfName, String controllerType) throws JsonProcessingException, IllegalArgumentException,ApplicationControllerOrchestratorException{
143 if(!(payload.isPresent())){
144 throw new IllegalArgumentException("Payload is not present for " + action.toString());
146 payload = PayloadClient.upgradeFormat(payload, vnfName);
147 return client.vnfCommand(action, msoRequestId, vnfId, payload, controllerType);
150 private Status resumeTrafficAction(String msoRequestId, String vnfId, String vnfName, String controllerType)throws JsonProcessingException, ApplicationControllerOrchestratorException{
151 Optional<String> payload = PayloadClient.resumeTrafficFormat(vnfName);
152 return client.vnfCommand(Action.ResumeTraffic, msoRequestId, vnfId, payload, controllerType);
155 private Status startStopAction(Action action, String msoRequestId, String vnfId, String aicIdentity, String controllerType)throws JsonProcessingException, ApplicationControllerOrchestratorException{
156 Optional<String> payload = PayloadClient.startStopFormat(aicIdentity);
157 return client.vnfCommand(action, msoRequestId, vnfId, payload, controllerType);
160 private Status healthCheckAction(String msoRequestId, String vnfId, String vnfName, String vnfHostIpAddress, String controllerType)throws JsonProcessingException, ApplicationControllerOrchestratorException{
161 Optional<String> payload = PayloadClient.healthCheckFormat(vnfName, vnfHostIpAddress);
162 return client.vnfCommand(Action.HealthCheck, msoRequestId, vnfId, payload, controllerType);
165 private Status snapshotAction(String msoRequestId, String vnfId, String vmId, String identityUrl, String controllerType) throws JsonProcessingException, ApplicationControllerOrchestratorException{
166 Optional<String> payload = PayloadClient.snapshotFormat(vmId, identityUrl);
167 return client.vnfCommand(Action.Snapshot, msoRequestId, vnfId, payload, controllerType);
170 public String getErrorMessage(){
174 public String getErrorCode(){