2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 package org.onap.so.bpmn.infrastructure.flowspecific.tasks;
24 import java.util.HashMap;
25 import java.util.Optional;
26 import org.camunda.bpm.engine.delegate.BpmnError;
27 import org.onap.appc.client.lcm.model.Action;
28 import org.onap.so.bpmn.common.BuildingBlockExecution;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
30 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
31 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
32 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
33 import org.onap.so.client.appc.ApplicationControllerAction;
34 import org.onap.so.client.exception.ExceptionBuilder;
35 import org.onap.so.db.catalog.client.CatalogDbClient;
36 import org.onap.so.db.catalog.beans.ControllerSelectionReference;
37 import org.onap.so.logger.ErrorCode;
38 import org.onap.so.logger.MessageEnum;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41 import org.springframework.beans.factory.annotation.Autowired;
42 import org.springframework.stereotype.Component;
45 public class GenericVnfHealthCheck {
47 private static final Logger logger = LoggerFactory.getLogger(GenericVnfHealthCheck.class);
49 private ExceptionBuilder exceptionUtil;
51 private ExtractPojosForBB extractPojosForBB;
53 private CatalogDbClient catalogDbClient;
55 private ApplicationControllerAction appCClient;
57 public void setParamsForGenericVnfHealthCheck(BuildingBlockExecution execution) {
59 GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
62 ControllerSelectionReference controllerSelectionReference;
63 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
64 String vnfId = vnf.getVnfId();
65 String vnfName = vnf.getVnfName();
66 String vnfType = vnf.getVnfType();
67 String oamIpAddress = vnf.getIpv4OamAddress();
68 String actionCategory = Action.HealthCheck.toString();
69 controllerSelectionReference = catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory(vnfType, actionCategory);
70 String controllerName = controllerSelectionReference.getControllerName();
72 execution.setVariable("vnfId", vnfId);
73 execution.setVariable("vnfName", vnfName);
74 execution.setVariable("oamIpAddress", oamIpAddress);
75 execution.setVariable("vnfHostIpAddress", oamIpAddress);
76 execution.setVariable("msoRequestId", gBBInput.getRequestContext().getMsoRequestId());
77 execution.setVariable("action", actionCategory);
78 execution.setVariable("controllerType", controllerName);
80 } catch (Exception ex) {
81 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
85 public void callAppcClient(BuildingBlockExecution execution) {
86 logger.trace("Start runAppcCommand ");
87 String appcCode = "1002";
88 String appcMessage = "";
91 action = Action.valueOf(execution.getVariable("action"));
92 String msoRequestId = execution.getVariable("msoRequestId");
93 String vnfId = execution.getVariable("vnfId");
94 Optional<String> payload = null;
95 if(execution.getVariable("payload") != null){
96 String pay = execution.getVariable("payload");
97 payload = Optional.of(pay);
99 String controllerType = execution.getVariable("controllerType");
100 HashMap<String, String> payloadInfo = new HashMap<String, String>();
101 payloadInfo.put("vnfName", execution.getVariable("vnfName"));
102 payloadInfo.put("vfModuleId",execution.getVariable("vfModuleId"));
103 payloadInfo.put("oamIpAddress",execution.getVariable("oamIpAddress"));
104 payloadInfo.put("vnfHostIpAddress",execution.getVariable("vnfHostIpAddress"));
106 logger.debug("Running APP-C action: {}", action.toString());
107 logger.debug("VNFID: {}", vnfId);
108 //PayloadInfo contains extra information that adds on to payload before making request to appc
109 appCClient.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType);
110 appcCode = appCClient.getErrorCode();
111 appcMessage = appCClient.getErrorMessage();
112 } catch (BpmnError ex) {
113 logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
114 "Caught exception in GenericVnfHealthCheck", "BPMN", ErrorCode.UnknownError.getValue(), ex);
115 appcMessage = ex.getMessage();
116 exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage);
117 } catch (Exception e) {
118 if (e instanceof java.util.concurrent.TimeoutException )
120 appcMessage = "Request to APPC timed out. ";
121 logger.error("{} {} {} {} {}", MessageEnum.RA_CONNECTION_EXCEPTION.toString(),
122 "Caught timedOut exception in runAppcCommand in GenericVnfHealthCheck", "BPMN",
123 ErrorCode.UnknownError.getValue(), "APPC Error", e);
127 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION.toString(),
128 "Caught exception in runAppcCommand in GenericVnfHealthCheck", "BPMN",
129 ErrorCode.UnknownError.getValue(), "APPC Error", e);
130 appcMessage = e.getMessage();
131 exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage);
134 logger.error("Error Message: " + appcMessage);
135 logger.error("ERROR CODE: " + appcCode);
136 logger.trace("End of runAppCommand ");
137 if (appcCode != null && !appcCode.equals("0")) {
138 exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage);