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.
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
20 * ============LICENSE_END=========================================================
23 package org.onap.appc.flow.controller.node;
25 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.ACTION_LEVEL;
26 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.APPC_FLOW_CONTROLLER;
27 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.DESINGTIME;
28 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.EXTERNAL;
29 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.FLOW_SEQUENCE;
30 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.GENERATION_NODE;
31 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.GRAPH;
32 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_PARAM_RESPONSE_PREFIX;
33 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.NODE;
34 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_PARAM_ERROR_MESSAGE;
35 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_PARAM_STATUS;
36 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_STATUS_FAILURE;
37 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_STATUS_MESSAGE;
38 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.OUTPUT_STATUS_SUCCESS;
39 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.PAYLOAD;
40 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REQUEST_ACTION;
41 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REQUEST_ID;
42 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.RESPONSE_PREFIX;
43 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.REST;
44 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.RUNTIME;
45 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.SEQUENCE_TYPE;
46 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.SEQ_GENERATOR_PWD;
47 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.SEQ_GENERATOR_UID;
48 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.SEQ_GENERATOR_URL;
49 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VF_MODULE;
50 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VM;
51 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF;
52 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNFC;
53 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNFC_NAME;
54 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNFC_TYPE;
55 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF_ID;
56 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VNF_TYPE;
57 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.VSERVER_ID;
59 import com.att.eelf.configuration.EELFLogger;
60 import com.att.eelf.configuration.EELFManager;
61 import com.fasterxml.jackson.annotation.JsonInclude.Include;
62 import com.fasterxml.jackson.databind.DeserializationFeature;
63 import com.fasterxml.jackson.databind.JsonNode;
64 import com.fasterxml.jackson.databind.ObjectMapper;
65 import com.fasterxml.jackson.databind.SerializationFeature;
66 import java.io.FileInputStream;
67 import java.io.IOException;
68 import java.io.InputStream;
69 import java.util.ArrayList;
70 import java.util.Arrays;
71 import java.util.HashMap;
72 import java.util.List;
74 import java.util.Properties;
75 import org.apache.commons.lang3.StringUtils;
76 import org.json.JSONObject;
77 import org.onap.appc.flow.controller.ResponseHandlerImpl.DefaultResponseHandler;
78 import org.onap.appc.flow.controller.data.PrecheckOption;
79 import org.onap.appc.flow.controller.data.ResponseAction;
80 import org.onap.appc.flow.controller.data.Transaction;
81 import org.onap.appc.flow.controller.data.Transactions;
82 import org.onap.appc.flow.controller.dbervices.FlowControlDBService;
83 import org.onap.appc.flow.controller.executorImpl.GraphExecutor;
84 import org.onap.appc.flow.controller.executorImpl.NodeExecutor;
85 import org.onap.appc.flow.controller.executorImpl.RestExecutor;
86 import org.onap.appc.flow.controller.interfaceData.ActionIdentifier;
87 import org.onap.appc.flow.controller.interfaceData.Capabilities;
88 import org.onap.appc.flow.controller.interfaceData.DependencyInfo;
89 import org.onap.appc.flow.controller.interfaceData.Input;
90 import org.onap.appc.flow.controller.interfaceData.InventoryInfo;
91 import org.onap.appc.flow.controller.interfaceData.RequestInfo;
92 import org.onap.appc.flow.controller.interfaceData.Vm;
93 import org.onap.appc.flow.controller.interfaceData.VnfInfo;
94 import org.onap.appc.flow.controller.interfaceData.Vnfcs;
95 import org.onap.appc.flow.controller.interfaceData.Vnfcslist;
96 import org.onap.appc.flow.controller.interfaces.FlowExecutorInterface;
97 import org.onap.appc.flow.controller.utils.EncryptionTool;
98 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
99 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
100 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
102 public class FlowControlNode implements SvcLogicJavaPlugin {
104 private static final EELFLogger log = EELFManager.getInstance().getLogger(FlowControlNode.class);
105 private static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR";
107 public void processFlow(Map<String, String> inParams, SvcLogicContext ctx)
108 throws SvcLogicException {
109 log.debug("Received processParamKeys call with params : " + inParams);
110 String responsePrefix = inParams.get(INPUT_PARAM_RESPONSE_PREFIX);
112 responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
113 SvcLogicContext localContext = new SvcLogicContext();
115 localContext.setAttribute(REQUEST_ID, ctx.getAttribute(REQUEST_ID));
116 localContext.setAttribute(VNF_TYPE, ctx.getAttribute(VNF_TYPE));
117 localContext.setAttribute(REQUEST_ACTION, ctx.getAttribute(REQUEST_ACTION));
118 localContext.setAttribute(ACTION_LEVEL, ctx.getAttribute(ACTION_LEVEL));
119 localContext.setAttribute(RESPONSE_PREFIX, responsePrefix);
120 ctx.setAttribute(RESPONSE_PREFIX, responsePrefix);
122 FlowControlDBService dbService = FlowControlDBService.initialise();
123 dbService.getFlowReferenceData(ctx, inParams, localContext);
125 for (String key : localContext.getAttributeKeySet()) {
126 log.debug("processFlow " + key + "=" + ctx.getAttribute(key));
128 processFlowSequence(inParams, ctx, localContext);
129 if (!ctx.getAttribute(responsePrefix + OUTPUT_PARAM_STATUS).equals(OUTPUT_STATUS_SUCCESS)) {
130 throw new SvcLogicException(ctx.getAttribute(responsePrefix + OUTPUT_STATUS_MESSAGE));
132 } catch (Exception e) {
133 ctx.setAttribute(responsePrefix + OUTPUT_PARAM_STATUS, OUTPUT_STATUS_FAILURE);
134 ctx.setAttribute(responsePrefix + OUTPUT_PARAM_ERROR_MESSAGE, e.getMessage());
135 log.error("Error occurred in processFlow ", e);
136 throw new SvcLogicException(e.getMessage());
140 private void processFlowSequence(Map<String, String> inParams, SvcLogicContext ctx, SvcLogicContext localContext)
143 String fn = "FlowExecutorNode.processflowSequence";
144 log.debug(fn + "Received model for flow : " + localContext.toString());
145 FlowControlDBService dbService = FlowControlDBService.initialise();
146 String flowSequence = null;
147 for (String key : localContext.getAttributeKeySet()) {
148 log.debug(key + "=" + ctx.getAttribute(key));
150 if (localContext.getAttribute(SEQUENCE_TYPE) != null) {
151 if (localContext.getAttribute(GENERATION_NODE) != null) {
152 GraphExecutor transactionExecutor = new GraphExecutor();
153 Boolean generatorExists = transactionExecutor.hasGraph(
155 localContext.getAttribute(GENERATION_NODE),
160 if (generatorExists) {
161 flowSequence = transactionExecutor.executeGraph(
163 localContext.getAttribute(GENERATION_NODE),
165 .getProperty(FLOW_SEQUENCE);
167 throw new Exception("Can not find Custom defined Flow Generator for "
168 + localContext.getAttribute(GENERATION_NODE));
171 } else if ((localContext.getAttribute(SEQUENCE_TYPE)).equalsIgnoreCase(DESINGTIME)) {
173 localContext.setAttribute(VNFC_TYPE, ctx.getAttribute(VNFC_TYPE));
174 flowSequence = dbService.getDesignTimeFlowModel(localContext);
176 if (flowSequence == null) {
177 throw new Exception("Flow Sequence is not found User Designed VNF " + ctx.getAttribute(VNF_TYPE));
180 } else if ((localContext.getAttribute(SEQUENCE_TYPE)).equalsIgnoreCase(RUNTIME)) {
182 Transaction transaction = new Transaction();
183 String input = collectInputParams(ctx, transaction);
184 log.info("CollectInputParamsData-Input: " + input);
186 RestExecutor restExe = new RestExecutor();
187 Map<String, String> flowSeq = restExe.execute(transaction, localContext);
189 JSONObject sequence = new JSONObject(flowSeq.get("restResponse"));
190 if (sequence.has("output")) {
191 flowSequence = sequence.getJSONObject("output").toString();
193 log.info("MultistepSequenceGenerator-Output: " + flowSequence);
195 if (flowSequence == null) {
196 throw new Exception("Failed to get the Flow Sequece runtime for VNF type"
197 + ctx.getAttribute(VNF_TYPE));
200 } else if ((localContext.getAttribute(SEQUENCE_TYPE)).equalsIgnoreCase(EXTERNAL)) {
201 //String input = collectInputParams(localContext);
202 // flowSequnce = ""; //get it from the External interface calling the Rest End point - TBD
203 //if(flowSequnce == null)
205 throw new Exception("Flow Sequence not found for " + ctx.getAttribute(VNF_TYPE));
208 //No other type of model supported...
209 //in Future can get flowModel from other generators which will be included here
210 throw new Exception("No information found for sequence Owner Design-Time Vs Run-Time");
214 FlowGenerator flowGenerator = new FlowGenerator();
215 Transactions trans = flowGenerator.createSingleStepModel(inParams, ctx);
216 ObjectMapper mapper = new ObjectMapper();
217 flowSequence = mapper.writeValueAsString(trans);
218 log.debug("Single step Flow Sequence : " + flowSequence);
221 log.debug("Received Flow Sequence : " + flowSequence);
222 HashMap<Integer, Transaction> transactionMap = createTransactionMap(flowSequence, localContext);
223 executeAllTransaction(transactionMap, ctx);
224 log.info("Executed all the transaction successfully");
227 private void executeAllTransaction(HashMap<Integer, Transaction> transactionMap, SvcLogicContext ctx)
230 String fn = "FlowExecutorNode.executeAllTransaction ";
232 FlowExecutorInterface flowExecutor;
233 for (int key = 1; key <= transactionMap.size(); key++) {
234 log.debug(fn + "Starting transactions ID " + key + " :)=" + retry);
235 Transaction transaction = transactionMap.get(key);
236 if (!preProcessor(transactionMap, transaction)) {
237 log.info("Skipping Transaction ID " + transaction.getTransactionId());
240 if (transaction.getExecutionType() != null) {
241 switch (transaction.getExecutionType()) {
243 flowExecutor = new GraphExecutor();
246 flowExecutor = new NodeExecutor();
249 flowExecutor = new RestExecutor();
252 throw new Exception("No Executor found for transaction ID" + transaction.getTransactionId());
254 flowExecutor.execute(transaction, ctx);
255 ResponseAction responseAction = handleResponse(transaction);
257 if (responseAction.getWait() != null && Integer.parseInt(responseAction.getWait()) > 0) {
258 log.debug(fn + "Going to Sleep .... " + responseAction.getWait());
259 Thread.sleep(Integer.parseInt(responseAction.getWait()) * 1000L);
261 if (responseAction.isIntermediateMessage()) {
262 log.debug(fn + "Sending Intermediate Message back .... ");
263 sendIntermediateMessage();
265 if (responseAction.getRetry() != null && Integer.parseInt(responseAction.getRetry()) > retry) {
266 log.debug(fn + "Ooppss!!! We will retry again ....... ");
269 log.debug(fn + "key =" + key + "retry =" + retry);
271 if (responseAction.isIgnore()) {
272 log.debug(fn + "Ignoring this Error and moving ahead ....... ");
275 if (responseAction.isStop()) {
276 log.debug(fn + "Need to Stop ....... ");
279 if (responseAction.getJump() != null && Integer.parseInt(responseAction.getJump()) > 0) {
280 key = Integer.parseInt(responseAction.getJump());
283 log.debug(fn + "key =" + key + "retry =" + retry);
286 throw new Exception("Don't know how to execute transaction ID " + transaction.getTransactionId());
291 private void sendIntermediateMessage() {
292 // TODO Auto-generated method stub
295 private ResponseAction handleResponse(Transaction transaction) {
296 log.info("Handling Response for transaction Id " + transaction.getTransactionId());
297 DefaultResponseHandler defaultHandler = new DefaultResponseHandler();
298 return defaultHandler.handlerResponse(transaction);
301 private boolean preProcessor(HashMap<Integer, Transaction> transactionMap, Transaction transaction)
304 log.debug("Starting Preprocessing Logic ");
305 boolean runThisStep = false;
307 if (transaction.getPrecheck() != null
308 && transaction.getPrecheck().getPrecheckOptions() != null
309 && !transaction.getPrecheck().getPrecheckOptions().isEmpty()) {
311 List<PrecheckOption> precheckOptions = transaction.getPrecheck().getPrecheckOptions();
312 for (PrecheckOption precheck : precheckOptions) {
313 Transaction trans = transactionMap.get(precheck.getpTransactionID());
314 ObjectMapper mapper = new ObjectMapper();
315 log.info("Mapper= " + mapper.writeValueAsString(trans));
316 HashMap trmap = mapper.readValue(mapper.writeValueAsString(trans), HashMap.class);
317 runThisStep = trmap.get(precheck.getParamName()) != null
318 && ((String) trmap.get(precheck.getParamName()))
319 .equalsIgnoreCase(precheck.getParamValue());
321 if (("any").equalsIgnoreCase(transaction.getPrecheck().getPrecheckOperator()) && runThisStep) {
326 log.debug("No Pre check defined for transaction ID " + transaction.getTransactionId());
329 } catch (Exception e) {
330 log.error("Error occured when Preprocessing Logic ", e);
333 log.debug("Returing process current Transaction = " + runThisStep);
337 private HashMap<Integer, Transaction> createTransactionMap(String flowSequence, SvcLogicContext localContext)
340 ObjectMapper mapper = new ObjectMapper();
341 Transactions transactions = mapper.readValue(flowSequence, Transactions.class);
342 HashMap<Integer, Transaction> transMap = new HashMap<>();
343 for (Transaction transaction : transactions.getTransactions()) {
344 compileFlowDependencies(transaction, localContext);
345 //parse the Transactions Object and create records in process_flow_status table
346 //loadTransactionIntoStatus(transactions, ctx);
347 transMap.put(transaction.getTransactionId(), transaction);
352 private void compileFlowDependencies(Transaction transaction, SvcLogicContext localContext)
355 FlowControlDBService dbService = FlowControlDBService.initialise();
356 dbService.populateModuleAndRPC(transaction, localContext.getAttribute(VNF_TYPE));
357 ObjectMapper mapper = new ObjectMapper();
358 log.debug("Individual Transaction Details :" + transaction.toString());
360 if ((localContext.getAttribute(SEQUENCE_TYPE) == null)
361 || (localContext.getAttribute(SEQUENCE_TYPE) != null
362 && !localContext.getAttribute(SEQUENCE_TYPE)
363 .equalsIgnoreCase(DESINGTIME))) {
365 localContext.setAttribute("artifact-content", mapper.writeValueAsString(transaction));
366 dbService.loadSequenceIntoDB(localContext);
368 //get a field in transction class as transactionhandle interface and register the Handler here for each trnactions
371 private String collectInputParams(SvcLogicContext ctx, Transaction transaction) throws Exception {
373 String fn = "FlowExecuteNode.collectInputParams";
374 Properties prop = loadProperties();
375 log.info("Loaded Properties " + prop.toString());
377 String vnfId = ctx.getAttribute(VNF_ID);
378 String inputData = null;
379 log.debug(fn + "vnfId :" + vnfId);
381 if (StringUtils.isBlank(vnfId)) {
382 throw new Exception("VnfId is missing");
386 ActionIdentifier actionIdentifier = new ActionIdentifier();
387 log.debug("Enter ActionIdentifier");
388 if (StringUtils.isNotBlank(vnfId)) {
389 actionIdentifier.setVnfId(vnfId);
391 if (StringUtils.isNotBlank(ctx.getAttribute(VSERVER_ID))) {
392 actionIdentifier.setVserverId(ctx.getAttribute(VSERVER_ID));
394 if (StringUtils.isNotBlank(ctx.getAttribute(VNFC_NAME))) {
395 actionIdentifier.setVnfcName(ctx.getAttribute(VNFC_NAME));
397 log.info("ActionIdentifierData" + actionIdentifier.toString());
399 RequestInfo requestInfo = new RequestInfo();
400 log.info("Enter RequestInfo");
401 requestInfo.setAction(ctx.getAttribute(REQUEST_ACTION));
402 requestInfo.setActionLevel(ctx.getAttribute(ACTION_LEVEL));
403 requestInfo.setPayload(ctx.getAttribute(PAYLOAD));
404 requestInfo.setActionIdentifier(actionIdentifier);
405 log.debug("RequestInfo: " + requestInfo.toString());
407 InventoryInfo inventoryInfo = getInventoryInfo(ctx, vnfId);
408 DependencyInfo dependencyInfo = getDependencyInfo(ctx);
409 Capabilities capabilities = getCapabilitiesData(ctx);
411 Input input = new Input();
412 log.info("Enter InputData");
413 input.setRequestInfo(requestInfo);
414 input.setInventoryInfo(inventoryInfo);
415 input.setDependencyInfo(dependencyInfo);
416 input.setCapabilities(capabilities);
417 log.info(fn + "Input parameters:" + input.toString());
419 ObjectMapper mapper = new ObjectMapper();
420 mapper.setSerializationInclusion(Include.NON_NULL);
421 mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
422 inputData = mapper.writeValueAsString(input);
423 log.info("InputDataJson:" + inputData);
425 } catch (Exception e) {
426 log.error("Error occurred in " + fn, e);
429 String resourceUri = prop.getProperty(SEQ_GENERATOR_URL);
430 log.info(fn + "resourceUri= " + resourceUri);
432 EncryptionTool et = EncryptionTool.getInstance();
433 String pass = et.decrypt(prop.getProperty(SEQ_GENERATOR_PWD));
435 transaction.setPayload(inputData);
436 transaction.setExecutionRPC("POST");
437 transaction.setuId(prop.getProperty(SEQ_GENERATOR_UID));
438 transaction.setPswd(pass);
439 transaction.setExecutionEndPoint(resourceUri);
444 private DependencyInfo getDependencyInfo(SvcLogicContext ctx) throws Exception {
446 String fn = "FlowExecutorNode.getDependencyInfo";
447 DependencyInfo dependencyInfo = new DependencyInfo();
448 FlowControlDBService dbService = FlowControlDBService.initialise();
449 String dependencyData = dbService.getDependencyInfo(ctx);
450 log.info(fn + "dependencyDataInput:" + dependencyData);
452 if (dependencyData != null) {
453 ObjectMapper mapper = new ObjectMapper();
454 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
455 mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
456 //JsonNode dependencyInfoData = mapper.readTree(dependencyData).get("dependencyInfo");
457 JsonNode vnfcData = mapper.readTree(dependencyData).get("vnfcs");
458 List<Vnfcs> vnfclist = Arrays.asList(mapper.readValue(vnfcData.toString(), Vnfcs[].class));
459 dependencyInfo.getVnfcs().addAll(vnfclist);
461 log.info("Dependency Output:" + dependencyInfo.toString());
463 return dependencyInfo;
466 private Capabilities getCapabilitiesData(SvcLogicContext ctx) throws Exception {
468 String fn = "FlowExecutorNode.getCapabilitiesData";
469 Capabilities capabilities = new Capabilities();
470 FlowControlDBService dbService = FlowControlDBService.initialise();
471 String capabilitiesData = dbService.getCapabilitiesData(ctx);
472 log.info(fn + "capabilitiesDataInput:" + capabilitiesData);
474 if (capabilitiesData != null) {
475 ObjectMapper mapper = new ObjectMapper();
476 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
477 mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
478 JsonNode capabilitiesNode = mapper.readValue(capabilitiesData, JsonNode.class);
479 log.info("capabilitiesNode:" + capabilitiesNode.toString());
481 JsonNode vnfs = capabilitiesNode.findValue(VNF);
482 List<String> vnfsList = new ArrayList<>();
484 for (int i = 0; i < vnfs.size(); i++) {
485 String vnf = vnfs.get(i).asText();
490 JsonNode vfModules = capabilitiesNode.findValue(VF_MODULE);
491 List<String> vfModulesList = new ArrayList<>();
492 if (vfModules != null) {
493 for (int i = 0; i < vfModules.size(); i++) {
494 String vfModule = vfModules.get(i).asText();
495 vfModulesList.add(vfModule);
499 JsonNode vnfcs = capabilitiesNode.findValue(VNFC);
500 List<String> vnfcsList = new ArrayList<>();
502 for (int i = 0; i < vnfcs.size(); i++) {
503 String vnfc1 = vnfcs.get(i).asText();
504 vnfcsList.add(vnfc1);
508 JsonNode vms = capabilitiesNode.findValue(VM);
509 List<String> vmList = new ArrayList<>();
511 for (int i = 0; i < vms.size(); i++) {
512 String vm1 = vms.get(i).asText();
517 capabilities.getVnfc().addAll(vnfcsList);
518 capabilities.getVnf().addAll(vnfsList);
519 capabilities.getVfModule().addAll(vfModulesList);
520 capabilities.getVm().addAll(vmList);
522 log.info("Capabilities Output:" + capabilities.toString());
527 private InventoryInfo getInventoryInfo(SvcLogicContext ctx, String vnfId) throws Exception {
528 String fn = "FlowExecutorNode.getInventoryInfo";
530 VnfInfo vnfInfo = new VnfInfo();
531 vnfInfo.setVnfId(vnfId);
532 vnfInfo.setVnfName(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name"));
533 vnfInfo.setVnfType(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type"));
535 String vmcount = ctx.getAttribute("tmp.vnfInfo.vm-count");
536 if (StringUtils.isNotBlank(vmcount)) {
537 int vmCount = Integer.parseInt(vmcount);
538 log.info(fn + "vmcount:" + vmCount);
541 Vnfcslist vnfc = new Vnfcslist();
542 for (int i = 0; i < vmCount; i++) {
543 vm.setVserverId(ctx.getAttribute("tmp.vnfInfo.vm[" + i + "].vserver-id"));
544 String vnfccount = ctx.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-count");
545 int vnfcCount = Integer.parseInt(vnfccount);
547 vnfc.setVnfcName(ctx.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-name"));
548 vnfc.setVnfcType(ctx.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-type"));
551 vnfInfo.getVm().add(vm);
554 InventoryInfo inventoryInfo = new InventoryInfo();
555 inventoryInfo.setVnfInfo(vnfInfo);
556 log.info(fn + "Inventory Output:" + inventoryInfo.toString());
558 return inventoryInfo;
561 private static Properties loadProperties() throws Exception {
562 Properties props = new Properties();
563 String propDir = System.getenv(SDNC_CONFIG_DIR_VAR);
564 if (propDir == null) {
565 throw new Exception("Cannot find Property file -" + SDNC_CONFIG_DIR_VAR);
567 String propFile = propDir + APPC_FLOW_CONTROLLER;
568 try (InputStream propStream = new FileInputStream(propFile)) {
570 props.load(propStream);
572 } catch (Exception e) {
573 throw new Exception("Could not load properties file " + propFile, e);