Improve coverage FlowControlNode #5
[appc.git] / appc-config / appc-flow-controller / provider / src / main / java / org / onap / appc / flow / controller / node / FlowControlNode.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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  *
19  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.appc.flow.controller.node;
24
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;
58
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;
73 import java.util.Map;
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;
101
102 public class FlowControlNode implements SvcLogicJavaPlugin {
103
104   private static final EELFLogger log = EELFManager.getInstance().getLogger(FlowControlNode.class);
105   private static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR";
106
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);
111     try {
112       responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
113       SvcLogicContext localContext = new SvcLogicContext();
114
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);
121
122       FlowControlDBService dbService = FlowControlDBService.initialise();
123       dbService.getFlowReferenceData(ctx, inParams, localContext);
124
125       for (String key : localContext.getAttributeKeySet()) {
126         log.debug("processFlow " + key + "=" + ctx.getAttribute(key));
127       }
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));
131       }
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());
137     }
138   }
139
140   private void processFlowSequence(Map<String, String> inParams, SvcLogicContext ctx, SvcLogicContext localContext)
141       throws Exception {
142
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));
149     }
150     if (localContext.getAttribute(SEQUENCE_TYPE) != null) {
151       if (localContext.getAttribute(GENERATION_NODE) != null) {
152         GraphExecutor transactionExecutor = new GraphExecutor();
153         Boolean generatorExists = transactionExecutor.hasGraph(
154             "APPC_COMMOM",
155             localContext.getAttribute(GENERATION_NODE),
156             null,
157             "sync"
158         );
159
160         if (generatorExists) {
161           flowSequence = transactionExecutor.executeGraph(
162               "APPC_COMMOM",
163               localContext.getAttribute(GENERATION_NODE),
164               null, "sync", null)
165               .getProperty(FLOW_SEQUENCE);
166         } else {
167           throw new Exception("Can not find Custom defined Flow Generator for "
168               + localContext.getAttribute(GENERATION_NODE));
169         }
170
171       } else if ((localContext.getAttribute(SEQUENCE_TYPE)).equalsIgnoreCase(DESINGTIME)) {
172
173         localContext.setAttribute(VNFC_TYPE, ctx.getAttribute(VNFC_TYPE));
174         flowSequence = dbService.getDesignTimeFlowModel(localContext);
175
176         if (flowSequence == null) {
177           throw new Exception("Flow Sequence is not found User Designed VNF " + ctx.getAttribute(VNF_TYPE));
178         }
179
180       } else if ((localContext.getAttribute(SEQUENCE_TYPE)).equalsIgnoreCase(RUNTIME)) {
181
182         Transaction transaction = new Transaction();
183         String input = collectInputParams(ctx, transaction);
184         log.info("CollectInputParamsData-Input: " + input);
185
186         RestExecutor restExe = new RestExecutor();
187         Map<String, String> flowSeq = restExe.execute(transaction, localContext);
188
189         JSONObject sequence = new JSONObject(flowSeq.get("restResponse"));
190         if (sequence.has("output")) {
191           flowSequence = sequence.getJSONObject("output").toString();
192         }
193         log.info("MultistepSequenceGenerator-Output: " + flowSequence);
194
195         if (flowSequence == null) {
196           throw new Exception("Failed to get the Flow Sequece runtime for VNF type"
197               + ctx.getAttribute(VNF_TYPE));
198         }
199
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)
204
205         throw new Exception("Flow Sequence not found for " + ctx.getAttribute(VNF_TYPE));
206
207       } else {
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");
211       }
212
213     } else {
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);
219     }
220
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");
225   }
226
227   private void executeAllTransaction(HashMap<Integer, Transaction> transactionMap, SvcLogicContext ctx)
228       throws Exception {
229
230     String fn = "FlowExecutorNode.executeAllTransaction ";
231     int retry = 0;
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());
238         continue;
239       }
240       if (transaction.getExecutionType() != null) {
241         switch (transaction.getExecutionType()) {
242           case GRAPH:
243             flowExecutor = new GraphExecutor();
244             break;
245           case NODE:
246             flowExecutor = new NodeExecutor();
247             break;
248           case REST:
249             flowExecutor = new RestExecutor();
250             break;
251           default:
252             throw new Exception("No Executor found for transaction ID" + transaction.getTransactionId());
253         }
254         flowExecutor.execute(transaction, ctx);
255         ResponseAction responseAction = handleResponse(transaction);
256
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);
260         }
261         if (responseAction.isIntermediateMessage()) {
262           log.debug(fn + "Sending Intermediate Message back  .... ");
263           sendIntermediateMessage();
264         }
265         if (responseAction.getRetry() != null && Integer.parseInt(responseAction.getRetry()) > retry) {
266           log.debug(fn + "Ooppss!!! We will retry again ....... ");
267           key--;
268           retry++;
269           log.debug(fn + "key =" + key + "retry =" + retry);
270         }
271         if (responseAction.isIgnore()) {
272           log.debug(fn + "Ignoring this Error and moving ahead  ....... ");
273           continue;
274         }
275         if (responseAction.isStop()) {
276           log.debug(fn + "Need to Stop  ....... ");
277           break;
278         }
279         if (responseAction.getJump() != null && Integer.parseInt(responseAction.getJump()) > 0) {
280           key = Integer.parseInt(responseAction.getJump());
281           key--;
282         }
283         log.debug(fn + "key =" + key + "retry =" + retry);
284
285       } else {
286         throw new Exception("Don't know how to execute transaction ID " + transaction.getTransactionId());
287       }
288     }
289   }
290
291   private void sendIntermediateMessage() {
292     // TODO Auto-generated method stub
293   }
294
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);
299   }
300
301   private boolean preProcessor(HashMap<Integer, Transaction> transactionMap, Transaction transaction)
302       throws IOException {
303
304     log.debug("Starting Preprocessing Logic ");
305     boolean runThisStep = false;
306     try {
307       if (transaction.getPrecheck() != null
308           && transaction.getPrecheck().getPrecheckOptions() != null
309           && !transaction.getPrecheck().getPrecheckOptions().isEmpty()) {
310
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());
320
321           if (("any").equalsIgnoreCase(transaction.getPrecheck().getPrecheckOperator()) && runThisStep) {
322             break;
323           }
324         }
325       } else {
326         log.debug("No Pre check defined for transaction ID " + transaction.getTransactionId());
327         runThisStep = true;
328       }
329     } catch (Exception e) {
330       log.error("Error occured when Preprocessing Logic ", e);
331       throw e;
332     }
333     log.debug("Returing process current Transaction = " + runThisStep);
334     return runThisStep;
335   }
336
337   private HashMap<Integer, Transaction> createTransactionMap(String flowSequence, SvcLogicContext localContext)
338       throws Exception {
339
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);
348     }
349     return transMap;
350   }
351
352   private void compileFlowDependencies(Transaction transaction, SvcLogicContext localContext)
353       throws Exception {
354
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());
359
360     if ((localContext.getAttribute(SEQUENCE_TYPE) == null)
361         || (localContext.getAttribute(SEQUENCE_TYPE) != null
362         && !localContext.getAttribute(SEQUENCE_TYPE)
363         .equalsIgnoreCase(DESINGTIME))) {
364
365       localContext.setAttribute("artifact-content", mapper.writeValueAsString(transaction));
366       dbService.loadSequenceIntoDB(localContext);
367     }
368     //get a field in transction class as transactionhandle interface and register the Handler here for each trnactions
369   }
370
371   private String collectInputParams(SvcLogicContext ctx, Transaction transaction) throws Exception {
372
373     String fn = "FlowExecuteNode.collectInputParams";
374     Properties prop = loadProperties();
375     log.info("Loaded Properties " + prop.toString());
376
377     String vnfId = ctx.getAttribute(VNF_ID);
378     String inputData = null;
379     log.debug(fn + "vnfId :" + vnfId);
380
381     if (StringUtils.isBlank(vnfId)) {
382       throw new Exception("VnfId is missing");
383     }
384
385     try {
386       ActionIdentifier actionIdentifier = new ActionIdentifier();
387       log.debug("Enter ActionIdentifier");
388       if (StringUtils.isNotBlank(vnfId)) {
389         actionIdentifier.setVnfId(vnfId);
390       }
391       if (StringUtils.isNotBlank(ctx.getAttribute(VSERVER_ID))) {
392         actionIdentifier.setVserverId(ctx.getAttribute(VSERVER_ID));
393       }
394       if (StringUtils.isNotBlank(ctx.getAttribute(VNFC_NAME))) {
395         actionIdentifier.setVnfcName(ctx.getAttribute(VNFC_NAME));
396       }
397       log.info("ActionIdentifierData" + actionIdentifier.toString());
398
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());
406
407       InventoryInfo inventoryInfo = getInventoryInfo(ctx, vnfId);
408       DependencyInfo dependencyInfo = getDependencyInfo(ctx);
409       Capabilities capabilities = getCapabilitiesData(ctx);
410
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());
418
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);
424
425     } catch (Exception e) {
426       log.error("Error occurred in " + fn, e);
427     }
428
429     String resourceUri = prop.getProperty(SEQ_GENERATOR_URL);
430     log.info(fn + "resourceUri= " + resourceUri);
431
432     EncryptionTool et = EncryptionTool.getInstance();
433     String pass = et.decrypt(prop.getProperty(SEQ_GENERATOR_PWD));
434
435     transaction.setPayload(inputData);
436     transaction.setExecutionRPC("POST");
437     transaction.setuId(prop.getProperty(SEQ_GENERATOR_UID));
438     transaction.setPswd(pass);
439     transaction.setExecutionEndPoint(resourceUri);
440
441     return inputData;
442   }
443
444   private DependencyInfo getDependencyInfo(SvcLogicContext ctx) throws Exception {
445
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);
451
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);
460
461       log.info("Dependency Output:" + dependencyInfo.toString());
462     }
463     return dependencyInfo;
464   }
465
466   private Capabilities getCapabilitiesData(SvcLogicContext ctx) throws Exception {
467
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);
473
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());
480
481       JsonNode vnfs = capabilitiesNode.findValue(VNF);
482       List<String> vnfsList = new ArrayList<>();
483       if (vnfs != null) {
484         for (int i = 0; i < vnfs.size(); i++) {
485           String vnf = vnfs.get(i).asText();
486           vnfsList.add(vnf);
487         }
488       }
489
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);
496         }
497       }
498
499       JsonNode vnfcs = capabilitiesNode.findValue(VNFC);
500       List<String> vnfcsList = new ArrayList<>();
501       if (vnfcs != null) {
502         for (int i = 0; i < vnfcs.size(); i++) {
503           String vnfc1 = vnfcs.get(i).asText();
504           vnfcsList.add(vnfc1);
505         }
506       }
507
508       JsonNode vms = capabilitiesNode.findValue(VM);
509       List<String> vmList = new ArrayList<>();
510       if (vms != null) {
511         for (int i = 0; i < vms.size(); i++) {
512           String vm1 = vms.get(i).asText();
513           vmList.add(vm1);
514         }
515       }
516
517       capabilities.getVnfc().addAll(vnfcsList);
518       capabilities.getVnf().addAll(vnfsList);
519       capabilities.getVfModule().addAll(vfModulesList);
520       capabilities.getVm().addAll(vmList);
521
522       log.info("Capabilities Output:" + capabilities.toString());
523     }
524     return capabilities;
525   }
526
527   private InventoryInfo getInventoryInfo(SvcLogicContext ctx, String vnfId) throws Exception {
528     String fn = "FlowExecutorNode.getInventoryInfo";
529
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"));
534
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);
539
540       Vm vm = new Vm();
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);
546         if (vnfcCount > 0) {
547           vnfc.setVnfcName(ctx.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-name"));
548           vnfc.setVnfcType(ctx.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-type"));
549           vm.setVnfc(vnfc);
550         }
551         vnfInfo.getVm().add(vm);
552       }
553     }
554     InventoryInfo inventoryInfo = new InventoryInfo();
555     inventoryInfo.setVnfInfo(vnfInfo);
556     log.info(fn + "Inventory Output:" + inventoryInfo.toString());
557
558     return inventoryInfo;
559   }
560
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);
566     }
567     String propFile = propDir + APPC_FLOW_CONTROLLER;
568     try (InputStream propStream = new FileInputStream(propFile)) {
569
570       props.load(propStream);
571
572     } catch (Exception e) {
573       throw new Exception("Could not load properties file " + propFile, e);
574     }
575     return props;
576   }
577 }