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