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);
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 =
70 catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory(vnfType, actionCategory);
71 String controllerName = controllerSelectionReference.getControllerName();
73 execution.setVariable("vnfId", vnfId);
74 execution.setVariable("vnfName", vnfName);
75 execution.setVariable("oamIpAddress", oamIpAddress);
76 execution.setVariable("vnfHostIpAddress", oamIpAddress);
77 execution.setVariable("msoRequestId", gBBInput.getRequestContext().getMsoRequestId());
78 execution.setVariable("action", actionCategory);
79 execution.setVariable("controllerType", controllerName);
81 } catch (Exception ex) {
82 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
86 public void callAppcClient(BuildingBlockExecution execution) {
87 logger.trace("Start runAppcCommand ");
88 String appcCode = "1002";
89 String appcMessage = "";
92 action = Action.valueOf(execution.getVariable("action"));
93 String msoRequestId = execution.getVariable("msoRequestId");
94 String vnfId = execution.getVariable("vnfId");
95 Optional<String> payload = null;
96 if (execution.getVariable("payload") != null) {
97 String pay = execution.getVariable("payload");
98 payload = Optional.of(pay);
100 String controllerType = execution.getVariable("controllerType");
101 HashMap<String, String> payloadInfo = new HashMap<String, String>();
102 payloadInfo.put("vnfName", execution.getVariable("vnfName"));
103 payloadInfo.put("vfModuleId", execution.getVariable("vfModuleId"));
104 payloadInfo.put("oamIpAddress", execution.getVariable("oamIpAddress"));
105 payloadInfo.put("vnfHostIpAddress", execution.getVariable("vnfHostIpAddress"));
107 logger.debug("Running APP-C action: {}", action.toString());
108 logger.debug("VNFID: {}", vnfId);
109 // PayloadInfo contains extra information that adds on to payload before making request to appc
110 appCClient.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType);
111 appcCode = appCClient.getErrorCode();
112 appcMessage = appCClient.getErrorMessage();
113 } catch (BpmnError ex) {
114 logger.error("{} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION_ARG.toString(),
115 "Caught exception in GenericVnfHealthCheck", "BPMN", ErrorCode.UnknownError.getValue(), ex);
116 appcMessage = ex.getMessage();
117 exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage);
118 } catch (Exception e) {
119 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);
126 logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION.toString(),
127 "Caught exception in runAppcCommand in GenericVnfHealthCheck", "BPMN",
128 ErrorCode.UnknownError.getValue(), "APPC Error", e);
129 appcMessage = e.getMessage();
130 exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage);
133 logger.error("Error Message: " + appcMessage);
134 logger.error("ERROR CODE: " + appcCode);
135 logger.trace("End of runAppCommand ");
136 if (appcCode != null && !appcCode.equals("0")) {
137 exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage);