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.MsoLogger;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.stereotype.Component;
40 public class GenericVnfHealthCheck {
42 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, GenericVnfHealthCheck.class);
44 private ExceptionBuilder exceptionUtil;
46 private ExtractPojosForBB extractPojosForBB;
48 private CatalogDbClient catalogDbClient;
50 private ApplicationControllerAction appCClient;
52 public void setParamsForGenericVnfHealthCheck(BuildingBlockExecution execution) {
54 GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
57 ControllerSelectionReference controllerSelectionReference;
58 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID));
59 String vnfId = vnf.getVnfId();
60 String vnfName = vnf.getVnfName();
61 String vnfType = vnf.getVnfType();
62 String oamIpAddress = vnf.getIpv4OamAddress();
63 String actionCategory = Action.HealthCheck.toString();
64 controllerSelectionReference = catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory(vnfType, actionCategory);
65 String controllerName = controllerSelectionReference.getControllerName();
67 execution.setVariable("vnfId", vnfId);
68 execution.setVariable("vnfName", vnfName);
69 execution.setVariable("oamIpAddress", oamIpAddress);
70 execution.setVariable("vnfHostIpAddress", oamIpAddress);
71 execution.setVariable("msoRequestId", gBBInput.getRequestContext().getMsoRequestId());
72 execution.setVariable("action", actionCategory);
73 execution.setVariable("controllerType", controllerName);
75 } catch (Exception ex) {
76 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
80 public void callAppcClient(BuildingBlockExecution execution) {
84 action = Action.valueOf(execution.getVariable("action"));
85 String msoRequestId = execution.getVariable("msoRequestId");
86 String vnfId = execution.getVariable("vnfId");
87 Optional<String> payload = null;
88 if(execution.getVariable("payload") != null){
89 String pay = execution.getVariable("payload");
90 payload = Optional.of(pay);
92 String controllerType = execution.getVariable("controllerType");
93 HashMap<String, String> payloadInfo = new HashMap<String, String>();
94 payloadInfo.put("vnfName", execution.getVariable("vnfName"));
95 payloadInfo.put("vfModuleId",execution.getVariable("vfModuleId"));
96 payloadInfo.put("oamIpAddress",execution.getVariable("oamIpAddress"));
97 payloadInfo.put("vnfHostIpAddress",execution.getVariable("vnfHostIpAddress"));
98 //PayloadInfo contains extra information that adds on to payload before making request to appc
99 appCClient.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType);
101 } catch (Exception ex) {
102 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);