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