CheckStyle corrections only
[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 com.att.eelf.configuration.EELFLogger;
26 import com.att.eelf.configuration.EELFManager;
27 import com.fasterxml.jackson.annotation.JsonInclude.Include;
28 import com.fasterxml.jackson.databind.DeserializationFeature;
29 import com.fasterxml.jackson.databind.JsonNode;
30 import com.fasterxml.jackson.databind.ObjectMapper;
31 import com.fasterxml.jackson.databind.SerializationFeature;
32 import java.io.FileInputStream;
33 import java.io.IOException;
34 import java.io.InputStream;
35 import java.util.ArrayList;
36 import java.util.Arrays;
37 import java.util.HashMap;
38 import java.util.List;
39 import java.util.Map;
40 import java.util.Properties;
41 import org.apache.commons.lang3.StringUtils;
42 import org.json.JSONObject;
43 import org.onap.appc.flow.controller.ResponseHandlerImpl.DefaultResponseHandler;
44 import org.onap.appc.flow.controller.data.PrecheckOption;
45 import org.onap.appc.flow.controller.data.ResponseAction;
46 import org.onap.appc.flow.controller.data.Transaction;
47 import org.onap.appc.flow.controller.data.Transactions;
48 import org.onap.appc.flow.controller.dbervices.FlowControlDBService;
49 import org.onap.appc.flow.controller.executorImpl.GraphExecutor;
50 import org.onap.appc.flow.controller.executorImpl.NodeExecutor;
51 import org.onap.appc.flow.controller.executorImpl.RestExecutor;
52 import org.onap.appc.flow.controller.interfaceData.ActionIdentifier;
53 import org.onap.appc.flow.controller.interfaceData.Capabilities;
54 import org.onap.appc.flow.controller.interfaceData.DependencyInfo;
55 import org.onap.appc.flow.controller.interfaceData.Input;
56 import org.onap.appc.flow.controller.interfaceData.InventoryInfo;
57 import org.onap.appc.flow.controller.interfaceData.RequestInfo;
58 import org.onap.appc.flow.controller.interfaceData.Vm;
59 import org.onap.appc.flow.controller.interfaceData.VnfInfo;
60 import org.onap.appc.flow.controller.interfaceData.Vnfcs;
61 import org.onap.appc.flow.controller.interfaceData.Vnfcslist;
62 import org.onap.appc.flow.controller.interfaces.FlowExecutorInterface;
63 import org.onap.appc.flow.controller.utils.EncryptionTool;
64 import org.onap.appc.flow.controller.utils.FlowControllerConstants;
65 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
66 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
67 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
68
69 public class FlowControlNode implements SvcLogicJavaPlugin {
70
71     private static final EELFLogger log = EELFManager.getInstance().getLogger(FlowControlNode.class);
72     private static final String SDNC_CONFIG_DIR_VAR = "SDNC_CONFIG_DIR";
73
74     public void processFlow(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
75         log.debug("Received processParamKeys call with params : " + inParams);
76         String responsePrefix = inParams.get(FlowControllerConstants.INPUT_PARAM_RESPONSE_PRIFIX);
77         try {
78             responsePrefix = StringUtils.isNotBlank(responsePrefix) ? (responsePrefix + ".") : "";
79             SvcLogicContext localContext = new SvcLogicContext();
80
81             localContext.setAttribute(FlowControllerConstants.REQUEST_ID,
82                 ctx.getAttribute(FlowControllerConstants.REQUEST_ID));
83             localContext.setAttribute(FlowControllerConstants.VNF_TYPE,
84                 ctx.getAttribute(FlowControllerConstants.VNF_TYPE));
85             localContext.setAttribute(FlowControllerConstants.REQUEST_ACTION,
86                 ctx.getAttribute(FlowControllerConstants.REQUEST_ACTION));
87             localContext.setAttribute(FlowControllerConstants.ACTION_LEVEL,
88                 ctx.getAttribute(FlowControllerConstants.ACTION_LEVEL));
89             localContext.setAttribute(FlowControllerConstants.RESPONSE_PREFIX,
90                 responsePrefix);
91             ctx.setAttribute(FlowControllerConstants.RESPONSE_PREFIX,
92                 responsePrefix);
93
94             FlowControlDBService dbservice = FlowControlDBService.initialise();
95             dbservice.getFlowReferenceData(ctx, inParams, localContext);
96
97             for (Object key : localContext.getAttributeKeySet()) {
98                 String parmName = (String) key;
99                 String parmValue = ctx.getAttribute(parmName);
100                 log.debug("processFlow " + parmName +  "="  + parmValue);
101
102             }
103             processFlowSequence(inParams, ctx, localContext);
104             if (!ctx.getAttribute(responsePrefix + FlowControllerConstants.OUTPUT_PARAM_STATUS)
105                 .equals(FlowControllerConstants.OUTPUT_STATUS_SUCCESS)) {
106
107                 throw new SvcLogicException(
108                     ctx.getAttribute(responsePrefix + FlowControllerConstants.OUTPUT_STATUS_MESSAGE));
109             }
110
111         } catch (Exception e) {
112             ctx.setAttribute(responsePrefix + FlowControllerConstants.OUTPUT_PARAM_STATUS,
113                 FlowControllerConstants.OUTPUT_STATUS_FAILURE);
114             ctx.setAttribute(responsePrefix + FlowControllerConstants.OUTPUT_PARAM_ERROR_MESSAGE,
115                 e.getMessage());
116             log.error("Error occured in processFlow ", e);
117             throw new SvcLogicException(e.getMessage());
118         }
119     }
120
121     private void processFlowSequence(Map<String, String> inParams, SvcLogicContext ctx, SvcLogicContext localContext)
122         throws Exception {
123
124         String fn = "FlowExecutorNode.processflowSequence";
125         log.debug(fn + "Received model for flow : " + localContext.toString());
126         FlowControlDBService dbservice = FlowControlDBService.initialise();
127         String flowSequnce = null;
128         for (Object key : localContext.getAttributeKeySet()) {
129             String parmName = (String) key;
130             String parmValue = ctx.getAttribute(parmName);
131             log.debug(parmName +  "="  + parmValue);
132
133         }
134         if (localContext.getAttribute(FlowControllerConstants.SEQUENCE_TYPE) != null) {
135             if (localContext.getAttribute(FlowControllerConstants.GENERATION_NODE) != null) {
136                 GraphExecutor transactionExecutor = new GraphExecutor();
137                 Boolean generatorExists = transactionExecutor.hasGraph(
138                     "APPC_COMMOM",
139                     localContext.getAttribute(FlowControllerConstants.GENERATION_NODE),
140                     null,
141                     "sync");
142
143                 if (generatorExists) {
144                     flowSequnce = transactionExecutor.executeGraph(
145                         "APPC_COMMOM",
146                         localContext.getAttribute(FlowControllerConstants.GENERATION_NODE),
147                         null, "sync", null)
148                         .getProperty(FlowControllerConstants.FLOW_SEQUENCE);
149                 } else {
150                     throw new Exception("Can not find Custom defined Flow Generator for "
151                         + localContext.getAttribute(FlowControllerConstants.GENERATION_NODE));
152                 }
153
154             } else if ((localContext.getAttribute(FlowControllerConstants.SEQUENCE_TYPE))
155                 .equalsIgnoreCase(FlowControllerConstants.DESINGTIME)) {
156
157                 localContext.setAttribute(FlowControllerConstants.VNFC_TYPE,
158                     ctx.getAttribute(FlowControllerConstants.VNFC_TYPE));
159                 flowSequnce = dbservice.getDesignTimeFlowModel(localContext);
160
161                 if (flowSequnce == null) {
162                     throw new Exception("Flow Sequence is not found User Desinged VNF "
163                         + ctx.getAttribute(FlowControllerConstants.VNF_TYPE));
164                 }
165
166             } else if ((localContext.getAttribute(FlowControllerConstants.SEQUENCE_TYPE))
167                 .equalsIgnoreCase(FlowControllerConstants.RUNTIME)) {
168
169                 Transaction transaction = new Transaction();
170                 String input = collectInputParams(ctx,transaction);
171                 log.info("CollectInputParamsData-Input: " + input);
172
173                 RestExecutor restExe = new RestExecutor();
174                 Map<String,String> flowSeq = restExe.execute(transaction, localContext);
175
176                 JSONObject sequence = new JSONObject(flowSeq.get("restResponse"));
177                 if (sequence.has("output")) {
178                     flowSequnce = sequence.getJSONObject("output").toString();
179                 }
180                 log.info("MultistepSequenceGenerator-Output: " + flowSequnce);
181
182                 if (flowSequnce == null) {
183                     throw new Exception("Failed to get the Flow Sequece runtime for VNF type"
184                         + ctx.getAttribute(FlowControllerConstants.VNF_TYPE));
185                 }
186
187             } else if ((localContext.getAttribute(FlowControllerConstants.SEQUENCE_TYPE))
188                 .equalsIgnoreCase(FlowControllerConstants.EXTERNAL)) {
189                 //String input = collectInputParams(localContext);
190                 //    flowSequnce = ""; //get it from the External interface calling the Rest End point - TBD
191                 //if(flowSequnce == null)
192
193                 throw new Exception("Flow Sequence not found for "
194                     + ctx.getAttribute(FlowControllerConstants.VNF_TYPE));
195
196             } else {
197                 //No other type of model supported...
198                 //in Future can get flowModel from other generators which will be included here
199                 throw new Exception("No information found for sequence Owner Design-Time Vs Run-Time" );
200             }
201
202         } else {
203             FlowGenerator flowGenerator = new FlowGenerator();
204             Transactions trans = flowGenerator.createSingleStepModel(inParams,ctx);
205             ObjectMapper mapper = new ObjectMapper();
206             flowSequnce = mapper.writeValueAsString(trans);
207             log.debug("Single step Flow Sequence : " + flowSequnce);
208         }
209
210         log.debug("Received Flow Sequence : " + flowSequnce);
211         HashMap<Integer, Transaction> transactionMap = createTransactionMap(flowSequnce, localContext);
212         exeuteAllTransaction(transactionMap, ctx);
213         log.info("Executed all the transacstion successfully");
214     }
215
216     private void exeuteAllTransaction(HashMap<Integer, Transaction> transactionMap, SvcLogicContext ctx)
217         throws Exception {
218
219         String fn = "FlowExecutorNode.exeuteAllTransaction ";
220         int retry = 0;
221         FlowExecutorInterface flowExecutor;
222         for (int key = 1; key <= transactionMap.size() ; key++) {
223             log.debug(fn + "Starting transactions ID " + key + " :)=" + retry);
224             Transaction transaction = transactionMap.get(key);
225             if (!preProcessor(transactionMap, transaction)) {
226                 log.info("Skipping Transaction ID " +  transaction.getTransactionId());
227                 continue;
228             }
229             if (transaction.getExecutionType() != null) {
230                 switch (transaction.getExecutionType()) {
231                     case FlowControllerConstants.GRAPH :
232                         flowExecutor = new GraphExecutor();
233                         break;
234                     case FlowControllerConstants.NODE :
235                         flowExecutor =  new NodeExecutor();
236                         break;
237                     case FlowControllerConstants.REST :
238                         flowExecutor = new RestExecutor();
239                         break;
240                     default :
241                         throw new Exception("No Executor found for transaction ID" + transaction.getTransactionId());
242                 }
243                 flowExecutor.execute(transaction, ctx);
244                 ResponseAction responseAction = handleResponse(transaction);
245
246                 if (responseAction.getWait() != null && Integer.parseInt(responseAction.getWait()) > 0) {
247                     log.debug(fn + "Going to Sleep .... " + responseAction.getWait());
248                     Thread.sleep(Integer.parseInt(responseAction.getWait()) * 1000L);
249                 }
250                 if (responseAction.isIntermediateMessage()) {
251                     log.debug(fn + "Sending Intermediate Message back  .... ");
252                     sendIntermediateMessage();
253                 }
254                 if (responseAction.getRetry() != null && Integer.parseInt(responseAction.getRetry()) > retry ) {
255                     log.debug(fn + "Ooppss!!! We will retry again ....... ");
256                     key--;
257                     retry++;
258                     log.debug(fn + "key =" +  key +  "retry =" + retry);
259                 }
260                 if (responseAction.isIgnore()) {
261                     log.debug(fn + "Ignoring this Error and moving ahead  ....... ");
262                     continue;
263                 }
264                 if (responseAction.isStop()) {
265                     log.debug(fn + "Need to Stop  ....... ");
266                     break;
267                 }
268                 if (responseAction.getJump() != null && Integer.parseInt(responseAction.getJump()) > 0 ) {
269                     key = Integer.parseInt(responseAction.getJump());
270                     key --;
271                 }
272                 log.debug(fn + "key =" +  key +  "retry =" + retry);
273
274             } else {
275                 throw new Exception("Don't know how to execute transaction ID " + transaction.getTransactionId());
276             }
277         }
278
279     }
280
281     private void sendIntermediateMessage() {
282         // TODO Auto-generated method stub
283     }
284
285     private ResponseAction handleResponse(Transaction transaction) {
286         log.info("Handling Response for transaction Id " + transaction.getTransactionId());
287         DefaultResponseHandler defaultHandler = new DefaultResponseHandler();
288         return defaultHandler.handlerResponse(transaction);
289     }
290
291     private boolean preProcessor(HashMap<Integer, Transaction> transactionMap, Transaction transaction)
292         throws IOException {
293
294         log.debug("Starting Preprocessing Logic ");
295         boolean runthisStep = false;
296         try {
297             if (transaction.getPrecheck() != null
298                 && transaction.getPrecheck().getPrecheckOptions() != null
299                 && !transaction.getPrecheck().getPrecheckOptions().isEmpty()) {
300
301                 List<PrecheckOption> precheckOptions  = transaction.getPrecheck().getPrecheckOptions();
302                 for (PrecheckOption precheck : precheckOptions) {
303                     Transaction trans = transactionMap.get(precheck.getpTransactionID());
304                     ObjectMapper mapper = new ObjectMapper();
305                     log.info("Mapper= " + mapper.writeValueAsString(trans));
306                     HashMap trmap = mapper.readValue(mapper.writeValueAsString(trans), HashMap.class);
307                     if (trmap.get(precheck.getParamName()) != null
308                         && ((String) trmap.get(precheck.getParamName())).equalsIgnoreCase(precheck.getParamValue())) {
309                         runthisStep = true;
310                     } else {
311                         runthisStep = false;
312                     }
313
314                     if (("any").equalsIgnoreCase(transaction.getPrecheck().getPrecheckOperator()) && runthisStep) {
315                         break;
316                     }
317                 }
318             } else {
319                 log.debug("No Pre check defined for transaction ID " + transaction.getTransactionId());
320                 runthisStep = true;
321             }
322         } catch(Exception e) {
323             log.error("Error occured when Preprocessing Logic ", e);
324             throw e;
325         }
326         log.debug("Returing process current Transaction = " + runthisStep);
327         return runthisStep ;
328     }
329
330     private HashMap<Integer, Transaction> createTransactionMap(String flowSequnce, SvcLogicContext localContext)
331         throws Exception {
332
333         ObjectMapper mapper = new ObjectMapper();
334         Transactions transactions = mapper.readValue(flowSequnce,Transactions.class);
335         HashMap<Integer, Transaction> transMap = new HashMap<>();
336         for (Transaction transaction : transactions.getTransactions()) {
337             compileFlowDependencies(transaction, localContext);
338             //parse the Transactions Object and create records in process_flow_status table
339             //loadTransactionIntoStatus(transactions, ctx);
340             transMap.put(transaction.getTransactionId(), transaction);
341         }
342         return transMap;
343     }
344
345     private void compileFlowDependencies(Transaction transaction, SvcLogicContext localContext) throws Exception {
346
347         FlowControlDBService dbservice = FlowControlDBService.initialise();
348         dbservice.populateModuleAndRPC(transaction, localContext.getAttribute(FlowControllerConstants.VNF_TYPE));
349         ObjectMapper mapper = new ObjectMapper();
350         log.debug("Indivisual Transaction Details :" + transaction.toString());
351
352         if ((localContext.getAttribute(FlowControllerConstants.SEQUENCE_TYPE) == null)
353             || (localContext.getAttribute(FlowControllerConstants.SEQUENCE_TYPE) != null
354             && ! localContext.getAttribute(FlowControllerConstants.SEQUENCE_TYPE)
355             .equalsIgnoreCase(FlowControllerConstants.DESINGTIME))) {
356
357             localContext.setAttribute("artifact-content", mapper.writeValueAsString(transaction));
358             dbservice.loadSequenceIntoDB(localContext);
359         }
360         //get a field in transction class as transactionhandle interface and register the Handler here for each trnactions
361     }
362
363     private String collectInputParams(SvcLogicContext ctx,Transaction transaction) throws Exception {
364
365         String fn = "FlowExecuteNode.collectInputParams";
366         Properties prop = loadProperties();
367         log.info("Loaded Properties " + prop.toString());
368
369         String vnfId = ctx.getAttribute(FlowControllerConstants.VNF_ID);
370         String inputData = null;
371         log.debug(fn + "vnfId :" + vnfId);
372
373         if (StringUtils.isBlank(vnfId)) {
374             throw new Exception("VnfId is missing");
375         }
376
377         try {
378             ActionIdentifier actionIdentifier = new ActionIdentifier();
379             log.debug("Enter ActionIdentifier");
380             if (StringUtils.isNotBlank(vnfId)) {
381                 actionIdentifier.setVnfId(vnfId);
382             }
383             if (StringUtils.isNotBlank(ctx.getAttribute(FlowControllerConstants.VSERVER_ID))) {
384                 actionIdentifier.setVserverId(ctx.getAttribute(FlowControllerConstants.VSERVER_ID));
385             }
386             if (StringUtils.isNotBlank(ctx.getAttribute(FlowControllerConstants.VNFC_NAME))) {
387                 actionIdentifier.setVnfcName(ctx.getAttribute(FlowControllerConstants.VNFC_NAME));
388             }
389             log.info("ActionIdentifierData" + actionIdentifier.toString());
390
391             RequestInfo requestInfo = new RequestInfo();
392             log.info("Enter RequestInfo");
393             requestInfo.setAction(ctx.getAttribute(FlowControllerConstants.REQUEST_ACTION));
394             requestInfo.setActionLevel(ctx.getAttribute(FlowControllerConstants.ACTION_LEVEL));
395             requestInfo.setPayload(ctx.getAttribute(FlowControllerConstants.PAYLOAD));
396             requestInfo.setActionIdentifier(actionIdentifier);
397             log.debug("RequestInfo: " + requestInfo.toString());
398
399             InventoryInfo inventoryInfo = getInventoryInfo(ctx, vnfId);
400             DependencyInfo dependencyInfo = getDependencyInfo(ctx);
401             Capabilities capabilites = getCapabilitesData(ctx);
402
403             Input input = new Input();
404             log.info("Enter InputData");
405             input.setRequestInfo(requestInfo);
406             input.setInventoryInfo(inventoryInfo);
407             input.setDependencyInfo(dependencyInfo);
408             input.setCapabilities(capabilites);
409             log.info(fn + "Input parameters:" + input.toString());
410
411             ObjectMapper mapper = new ObjectMapper();
412             mapper.setSerializationInclusion(Include.NON_NULL);
413             mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
414             inputData = mapper.writeValueAsString(input);
415             log.info("InputDataJson:" + inputData);
416
417         } catch (Exception e) {
418             log.error("Error occured in " + fn, e);
419         }
420
421         String resourceUri = prop.getProperty(FlowControllerConstants.SEQ_GENERATOR_URL);
422         log.info(fn + "resourceUri= " + resourceUri);
423
424         EncryptionTool et = EncryptionTool.getInstance();
425         String pass = et.decrypt(prop.getProperty(FlowControllerConstants.SEQ_GENERATOR_PWD));
426
427         transaction.setPayload(inputData);
428         transaction.setExecutionRPC("POST");
429         transaction.setuId(prop.getProperty(FlowControllerConstants.SEQ_GENERATOR_UID));
430         transaction.setPswd(pass);
431         transaction.setExecutionEndPoint(resourceUri);
432
433         return inputData;
434     }
435
436     private DependencyInfo getDependencyInfo(SvcLogicContext ctx) throws Exception {
437
438         String fn = "FlowExecutorNode.getDependencyInfo";
439         DependencyInfo dependencyInfo = new DependencyInfo();
440         FlowControlDBService dbservice = FlowControlDBService.initialise();
441         String dependencyData = dbservice.getDependencyInfo(ctx);
442         log.info(fn + "dependencyDataInput:" + dependencyData);
443
444         if (dependencyData != null) {
445             ObjectMapper mapper = new ObjectMapper();
446             mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
447             mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
448             //JsonNode dependencyInfoData = mapper.readTree(dependencyData).get("dependencyInfo");
449             JsonNode vnfcData = mapper.readTree(dependencyData).get("vnfcs");
450             List<Vnfcs> vnfclist = Arrays.asList(mapper.readValue(vnfcData.toString(), Vnfcs[].class));
451             dependencyInfo.getVnfcs().addAll(vnfclist);
452
453             log.info("Dependency Output:" + dependencyInfo.toString());
454         }
455         return dependencyInfo;
456     }
457
458     private Capabilities getCapabilitesData(SvcLogicContext ctx) throws Exception {
459
460         String fn = "FlowExecutorNode.getCapabilitesData";
461         Capabilities capabilities = new Capabilities();
462         FlowControlDBService dbservice = FlowControlDBService.initialise();
463         String capabilitiesData = dbservice.getCapabilitiesData(ctx);
464         log.info(fn + "capabilitiesDataInput:" + capabilitiesData);
465
466         if (capabilitiesData != null) {
467             ObjectMapper mapper = new ObjectMapper();
468             mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
469             mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
470             JsonNode capabilitiesNode = mapper.readValue(capabilitiesData,JsonNode.class);
471             log.info("capabilitiesNode:" + capabilitiesNode.toString());
472
473             JsonNode vnfs = capabilitiesNode.findValue(FlowControllerConstants.VNF);
474             List<String> vnfsList = new ArrayList<>();
475             if (vnfs != null) {
476                 for (int i = 0; i < vnfs.size(); i++) {
477                     String vnf = vnfs.get(i).asText();
478                     vnfsList.add(vnf);
479                 }
480             }
481
482             JsonNode vfModules = capabilitiesNode.findValue(FlowControllerConstants.VF_MODULE);
483             List<String> vfModulesList = new ArrayList<>();
484             if (vfModules != null) {
485                 for (int i = 0; i < vfModules.size(); i++) {
486                     String vfModule = vfModules.get(i).asText();
487                     vfModulesList.add(vfModule);
488                 }
489             }
490
491             JsonNode vnfcs = capabilitiesNode.findValue(FlowControllerConstants.VNFC);
492             List<String> vnfcsList = new ArrayList<>();
493             if (vnfcs != null) {
494                 for (int i = 0; i < vnfcs.size(); i++) {
495                     String vnfc1 = vnfcs.get(i).asText();
496                     vnfcsList.add(vnfc1);
497                 }
498             }
499
500             JsonNode vms = capabilitiesNode.findValue(FlowControllerConstants.VM);
501             List<String> vmList = new ArrayList<>();
502             if (vms != null) {
503                 for (int i = 0; i < vms.size(); i++) {
504                     String vm1 = vms.get(i).asText();
505                     vmList.add(vm1);
506                 }
507             }
508
509             capabilities.getVnfc().addAll(vnfcsList);
510             capabilities.getVnf().addAll(vnfsList);
511             capabilities.getVfModule().addAll(vfModulesList);
512             capabilities.getVm().addAll(vmList);
513
514             log.info("Capabilities Output:" + capabilities.toString());
515         }
516         return capabilities;
517     }
518
519     private InventoryInfo getInventoryInfo(SvcLogicContext ctx, String vnfId) throws Exception {
520         String fn = "FlowExecutorNode.getInventoryInfo";
521
522         VnfInfo vnfInfo = new VnfInfo();
523         vnfInfo.setVnfId(vnfId);
524         vnfInfo.setVnfName(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-name"));
525         vnfInfo.setVnfType(ctx.getAttribute("tmp.vnfInfo.vnf.vnf-type"));
526
527         String vmcount = ctx.getAttribute("tmp.vnfInfo.vm-count");
528         if (StringUtils.isNotBlank(vmcount)) {
529             int vmCount = Integer.parseInt(vmcount);
530             log.info(fn + "vmcount:" + vmCount);
531
532             Vm vm = new Vm();
533             Vnfcslist vnfc = new Vnfcslist();
534             for (int i = 0; i < vmCount; i++) {
535                 vm.setVserverId(ctx.getAttribute("tmp.vnfInfo.vm[" + i + "].vserver-id"));
536                 String vnfccount = ctx.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-count");
537                 int vnfcCount = Integer.parseInt(vnfccount);
538                 if (vnfcCount > 0) {
539                     vnfc.setVnfcName(ctx.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-name"));
540                     vnfc.setVnfcType(ctx.getAttribute("tmp.vnfInfo.vm[" + i + "].vnfc-type"));
541                     vm.setVnfc(vnfc);
542                 }
543                 vnfInfo.getVm().add(vm);
544             }
545         }
546         InventoryInfo inventoryInfo = new InventoryInfo();
547         inventoryInfo.setVnfInfo(vnfInfo);
548         log.info(fn + "Inventory Output:" + inventoryInfo.toString());
549
550         return inventoryInfo;
551     }
552
553     private static Properties loadProperties() throws Exception {
554         Properties props = new Properties();
555         String propDir = System.getenv(SDNC_CONFIG_DIR_VAR);
556         if (propDir == null) {
557             throw new Exception("Cannot find Property file -" + SDNC_CONFIG_DIR_VAR);
558         }
559         String propFile = propDir + FlowControllerConstants.APPC_FLOW_CONTROLLER;
560         try (InputStream propStream = new FileInputStream(propFile)) {
561
562             props.load(propStream);
563
564         } catch (Exception e) {
565             throw new Exception("Could not load properties file " + propFile, e);
566         }
567         return props;
568     }
569 }