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=========================================================
20 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
22 import java.util.HashMap;
23 import java.util.Optional;
25 import org.onap.appc.client.lcm.model.Action;
26 import org.onap.so.bpmn.common.BuildingBlockExecution;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
28 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
29 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
30 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
31 import org.onap.so.client.appc.ApplicationControllerAction;
32 import org.onap.so.client.exception.ExceptionBuilder;
33 import org.onap.so.db.catalog.client.CatalogDbClient;
34 import org.onap.so.db.catalog.beans.ControllerSelectionReference;
35 import org.onap.so.logger.MessageEnum;
36 import org.onap.so.logger.MsoLogger;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.stereotype.Component;
41 public class GenericVnfHealthCheck {
43 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, GenericVnfHealthCheck.class);
45 private ExceptionBuilder exceptionUtil;
47 private ExtractPojosForBB extractPojosForBB;
49 private CatalogDbClient catalogDbClient;
51 private ApplicationControllerAction appCClient;
53 public void setParamsForGenericVnfHealthCheck(BuildingBlockExecution execution) {
55 GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
58 ControllerSelectionReference controllerSelectionReference;
59 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
60 String vnfId = vnf.getVnfId();
61 String vnfName = vnf.getVnfName();
62 String vnfType = vnf.getVnfType();
63 String oamIpAddress = vnf.getIpv4OamAddress();
64 String actionCategory = Action.HealthCheck.toString();
65 controllerSelectionReference = catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory(vnfType, actionCategory);
66 String controllerName = controllerSelectionReference.getControllerName();
68 execution.setVariable("vnfId", vnfId);
69 execution.setVariable("vnfName", vnfName);
70 execution.setVariable("oamIpAddress", oamIpAddress);
71 execution.setVariable("vnfHostIpAddress", oamIpAddress);
72 execution.setVariable("msoRequestId", gBBInput.getRequestContext().getMsoRequestId());
73 execution.setVariable("action", actionCategory);
74 execution.setVariable("controllerType", controllerName);
76 } catch (Exception ex) {
77 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
81 public void callAppcClient(BuildingBlockExecution execution) {
82 msoLogger.trace("Start runAppcCommand ");
83 String appcCode = "1002";
84 String appcMessage = "";
87 action = Action.valueOf(execution.getVariable("action"));
88 String msoRequestId = execution.getVariable("msoRequestId");
89 String vnfId = execution.getVariable("vnfId");
90 Optional<String> payload = null;
91 if(execution.getVariable("payload") != null){
92 String pay = execution.getVariable("payload");
93 payload = Optional.of(pay);
95 String controllerType = execution.getVariable("controllerType");
96 HashMap<String, String> payloadInfo = new HashMap<String, String>();
97 payloadInfo.put("vnfName", execution.getVariable("vnfName"));
98 payloadInfo.put("vfModuleId",execution.getVariable("vfModuleId"));
99 payloadInfo.put("oamIpAddress",execution.getVariable("oamIpAddress"));
100 payloadInfo.put("vnfHostIpAddress",execution.getVariable("vnfHostIpAddress"));
102 msoLogger.debug("Running APP-C action: " + action.toString());
103 msoLogger.debug("VNFID: " + vnfId);
104 //PayloadInfo contains extra information that adds on to payload before making request to appc
105 appCClient.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType);
106 appcCode = appCClient.getErrorCode();
107 appcMessage = appCClient.getErrorMessage();
109 } catch (Exception e) {
110 msoLogger.error(MessageEnum.BPMN_GENERAL_EXCEPTION, "Caught exception in runAppcCommand in GenericVnfHealthCheck", "BPMN", MsoLogger.getServiceName(), MsoLogger.ErrorCode.UnknownError, "APPC Error", e);
111 appcMessage = e.getMessage();
113 msoLogger.error("Error Message: " + appcMessage);
114 msoLogger.error("ERROR CODE: " + appcCode);
115 msoLogger.trace("End of runAppCommand ");
116 if (appcCode != null && !appcCode.equals("0")) {
117 exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage);