Improve coverage FlowControlNode #8
[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.core.type.TypeReference;
63 import com.fasterxml.jackson.databind.DeserializationFeature;
64 import com.fasterxml.jackson.databind.JsonNode;
65 import com.fasterxml.jackson.databind.ObjectMapper;
66 import com.fasterxml.jackson.databind.SerializationFeature;
67 import java.io.IOException;
68 import java.util.ArrayList;
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     localContext
154         .getAttributeKeySet()
155         .forEach(key -> log.debug(key + "=" + ctx.getAttribute(key)));
156
157     String flowSequence = getFlowSequence(inParams, ctx, localContext);
158
159     log.debug("Received Flow Sequence : " + flowSequence);
160     HashMap<Integer, Transaction> transactionMap = createTransactionMap(flowSequence, localContext);
161     executeAllTransaction(transactionMap, ctx);
162     log.info("Executed all the transaction successfully");
163   }
164
165   String getFlowSequence(Map<String, String> inParams, SvcLogicContext ctx, SvcLogicContext localContext) throws Exception {
166     String flowSequence = null;
167     if (localContext.getAttribute(SEQUENCE_TYPE) != null) {
168       if (localContext.getAttribute(GENERATION_NODE) != null) {
169         GraphExecutor transactionExecutor = new GraphExecutor();
170         Boolean generatorExists = transactionExecutor.hasGraph(
171             "APPC_COMMOM",
172             localContext.getAttribute(GENERATION_NODE),
173             null,
174             "sync"
175         );
176
177         if (generatorExists) {
178           flowSequence = transactionExecutor.executeGraph(
179               "APPC_COMMOM",
180               localContext.getAttribute(GENERATION_NODE),
181               null, "sync", null)
182               .getProperty(FLOW_SEQUENCE);
183         } else {
184           throw new Exception("Can not find Custom defined Flow Generator for "
185               + localContext.getAttribute(GENERATION_NODE));
186         }
187
188       } else if ((localContext.getAttribute(SEQUENCE_TYPE)).equalsIgnoreCase(DESINGTIME)) {
189
190         localContext.setAttribute(VNFC_TYPE, ctx.getAttribute(VNFC_TYPE));
191         flowSequence = dbService.getDesignTimeFlowModel(localContext);
192
193         if (flowSequence == null) {
194           throw new Exception("Flow Sequence is not found User Designed VNF " + ctx.getAttribute(VNF_TYPE));
195         }
196
197       } else if ((localContext.getAttribute(SEQUENCE_TYPE)).equalsIgnoreCase(RUNTIME)) {
198
199         Transaction transaction = new Transaction();
200         String input = collectInputParams(ctx, transaction);
201         log.info("CollectInputParamsData-Input: " + input);
202
203         RestExecutor restExe = new RestExecutor();
204         Map<String, String> flowSeq = restExe.execute(transaction, localContext);
205
206         JSONObject sequence = new JSONObject(flowSeq.get("restResponse"));
207         if (sequence.has("output")) {
208           flowSequence = sequence.getJSONObject("output").toString();
209         }
210         log.info("MultistepSequenceGenerator-Output: " + flowSequence);
211
212         if (flowSequence == null) {
213           throw new Exception("Failed to get the Flow Sequece runtime for VNF type"
214               + ctx.getAttribute(VNF_TYPE));
215         }
216
217       } else if ((localContext.getAttribute(SEQUENCE_TYPE)).equalsIgnoreCase(EXTERNAL)) {
218         //String input = collectInputParams(localContext);
219         //    flowSequnce = ""; //get it from the External interface calling the Rest End point - TBD
220         //if(flowSequnce == null)
221
222         throw new Exception("Flow Sequence not found for " + ctx.getAttribute(VNF_TYPE));
223
224       } else {
225         //No other type of model supported...
226         //in Future can get flowModel from other generators which will be included here
227         throw new Exception("No information found for sequence Owner Design-Time Vs Run-Time");
228       }
229
230     } else {
231       FlowGenerator flowGenerator = new FlowGenerator();
232       Transactions trans = flowGenerator.createSingleStepModel(inParams, ctx);
233       ObjectMapper mapper = new ObjectMapper();
234       flowSequence = mapper.writeValueAsString(trans);
235       log.debug("Single step Flow Sequence : " + flowSequence);
236     }
237     return flowSequence;
238   }
239
240   private void executeAllTransaction(HashMap<Integer, Transaction> transactionMap, SvcLogicContext ctx)
241       throws Exception {
242
243     String fn = "FlowExecutorNode.executeAllTransaction ";
244     int retry = 0;
245     FlowExecutorInterface flowExecutor;
246     for (int key = 1; key <= transactionMap.size(); key++) {
247       log.debug(fn + "Starting transactions ID " + key + " :)=" + retry);
248       Transaction transaction = transactionMap.get(key);
249       if (!preProcessor(transactionMap, transaction)) {
250         log.info("Skipping Transaction ID " + transaction.getTransactionId());
251         continue;
252       }
253       if (transaction.getExecutionType() != null) {
254         switch (transaction.getExecutionType()) {
255           case GRAPH:
256             flowExecutor = new GraphExecutor();
257             break;
258           case NODE:
259             flowExecutor = new NodeExecutor();
260             break;
261           case REST:
262             flowExecutor = new RestExecutor();
263             break;
264           default:
265             throw new Exception("No Executor found for transaction ID" + transaction.getTransactionId());
266         }
267         flowExecutor.execute(transaction, ctx);
268         ResponseAction responseAction = handleResponse(transaction);
269
270         if (responseAction.getWait() != null && Integer.parseInt(responseAction.getWait()) > 0) {
271           log.debug(fn + "Going to Sleep .... " + responseAction.getWait());
272           Thread.sleep(Integer.parseInt(responseAction.getWait()) * 1000L);
273         }
274         if (responseAction.isIntermediateMessage()) {
275           log.debug(fn + "Sending Intermediate Message back  .... ");
276           sendIntermediateMessage();
277         }
278         if (responseAction.getRetry() != null && Integer.parseInt(responseAction.getRetry()) > retry) {
279           log.debug(fn + "Ooppss!!! We will retry again ....... ");
280           key--;
281           retry++;
282           log.debug(fn + "key =" + key + "retry =" + retry);
283         }
284         if (responseAction.isIgnore()) {
285           log.debug(fn + "Ignoring this Error and moving ahead  ....... ");
286           continue;
287         }
288         if (responseAction.isStop()) {
289           log.debug(fn + "Need to Stop  ....... ");
290           break;
291         }
292         if (responseAction.getJump() != null && Integer.parseInt(responseAction.getJump()) > 0) {
293           key = Integer.parseInt(responseAction.getJump());
294           key--;
295         }
296         log.debug(fn + "key =" + key + "retry =" + retry);
297
298       } else {
299         throw new Exception("Don't know how to execute transaction ID " + transaction.getTransactionId());
300       }
301     }
302   }
303
304   private void sendIntermediateMessage() {
305     // TODO Auto-generated method stub
306   }
307
308   private ResponseAction handleResponse(Transaction transaction) {
309     log.info("Handling Response for transaction Id " + transaction.getTransactionId());
310     DefaultResponseHandler defaultHandler = new DefaultResponseHandler();
311     return defaultHandler.handlerResponse(transaction);
312   }
313
314   private boolean preProcessor(HashMap<Integer, Transaction> transactionMap, Transaction transaction)
315       throws IOException {
316
317     log.debug("Starting Preprocessing Logic ");
318     boolean runThisStep = false;
319     try {
320       if (transaction.getPrecheck() != null
321           && transaction.getPrecheck().getPrecheckOptions() != null
322           && !transaction.getPrecheck().getPrecheckOptions().isEmpty()) {
323
324         List<PrecheckOption> precheckOptions = transaction.getPrecheck().getPrecheckOptions();
325         for (PrecheckOption precheck : precheckOptions) {
326           Transaction trans = transactionMap.get(precheck.getpTransactionID());
327           ObjectMapper mapper = new ObjectMapper();
328           log.info("Mapper= " + mapper.writeValueAsString(trans));
329           HashMap trmap = mapper.readValue(mapper.writeValueAsString(trans), HashMap.class);
330           runThisStep = trmap.get(precheck.getParamName()) != null
331               && ((String) trmap.get(precheck.getParamName()))
332               .equalsIgnoreCase(precheck.getParamValue());
333
334           if (("any").equalsIgnoreCase(transaction.getPrecheck().getPrecheckOperator()) && runThisStep) {
335             break;
336           }
337         }
338       } else {
339         log.debug("No Pre check defined for transaction ID " + transaction.getTransactionId());
340         runThisStep = true;
341       }
342     } catch (Exception e) {
343       log.error("Error occured when Preprocessing Logic ", e);
344       throw e;
345     }
346     log.debug("Returing process current Transaction = " + runThisStep);
347     return runThisStep;
348   }
349
350   private HashMap<Integer, Transaction> createTransactionMap(String flowSequence, SvcLogicContext localContext)
351       throws Exception {
352
353     ObjectMapper mapper = new ObjectMapper();
354     Transactions transactions = mapper.readValue(flowSequence, Transactions.class);
355     HashMap<Integer, Transaction> transMap = new HashMap<>();
356     for (Transaction transaction : transactions.getTransactions()) {
357       compileFlowDependencies(transaction, localContext);
358       //parse the Transactions Object and create records in process_flow_status table
359       //loadTransactionIntoStatus(transactions, ctx);
360       transMap.put(transaction.getTransactionId(), transaction);
361     }
362     return transMap;
363   }
364
365   private void compileFlowDependencies(Transaction transaction, SvcLogicContext localContext)
366       throws Exception {
367
368     dbService.populateModuleAndRPC(transaction, localContext.getAttribute(VNF_TYPE));
369     ObjectMapper mapper = new ObjectMapper();
370     log.debug("Individual Transaction Details :" + transaction.toString());
371
372     if ((localContext.getAttribute(SEQUENCE_TYPE) == null)
373         || (localContext.getAttribute(SEQUENCE_TYPE) != null
374         && !localContext.getAttribute(SEQUENCE_TYPE)
375         .equalsIgnoreCase(DESINGTIME))) {
376
377       localContext.setAttribute("artifact-content", mapper.writeValueAsString(transaction));
378       dbService.loadSequenceIntoDB(localContext);
379     }
380     //get a field in transction class as transactionhandle interface and register the Handler here for each trnactions
381   }
382
383   private String collectInputParams(SvcLogicContext ctx, Transaction transaction) throws Exception {
384
385     String fn = "FlowExecuteNode.collectInputParams";
386     Properties prop = loadProperties();
387     log.info("Loaded Properties " + prop.toString());
388
389     String vnfId = ctx.getAttribute(VNF_ID);
390     String inputData = null;
391     log.debug(fn + "vnfId :" + vnfId);
392
393     if (StringUtils.isBlank(vnfId)) {
394       throw new Exception("VnfId is missing");
395     }
396
397     try {
398       ActionIdentifier actionIdentifier = new ActionIdentifier();
399       log.debug("Enter ActionIdentifier");
400       if (StringUtils.isNotBlank(vnfId)) {
401         actionIdentifier.setVnfId(vnfId);
402       }
403       if (StringUtils.isNotBlank(ctx.getAttribute(VSERVER_ID))) {
404         actionIdentifier.setVserverId(ctx.getAttribute(VSERVER_ID));
405       }
406       if (StringUtils.isNotBlank(ctx.getAttribute(VNFC_NAME))) {
407         actionIdentifier.setVnfcName(ctx.getAttribute(VNFC_NAME));
408       }
409       log.info("ActionIdentifierData" + actionIdentifier.toString());
410
411       RequestInfo requestInfo = new RequestInfo();
412       log.info("Enter RequestInfo");
413       requestInfo.setAction(ctx.getAttribute(REQUEST_ACTION));
414       requestInfo.setActionLevel(ctx.getAttribute(ACTION_LEVEL));
415       requestInfo.setPayload(ctx.getAttribute(PAYLOAD));
416       requestInfo.setActionIdentifier(actionIdentifier);
417       log.debug("RequestInfo: " + requestInfo.toString());
418
419       InventoryInfo inventoryInfo = new InventoryInfoExtractor().getInventoryInfo(ctx, vnfId);
420       DependencyInfo dependencyInfo = getDependencyInfo(ctx);
421       Capabilities capabilities = getCapabilitiesData(ctx);
422
423       Input input = new Input();
424       log.info("Enter InputData");
425       input.setRequestInfo(requestInfo);
426       input.setInventoryInfo(inventoryInfo);
427       input.setDependencyInfo(dependencyInfo);
428       input.setCapabilities(capabilities);
429       log.info(fn + "Input parameters:" + input.toString());
430
431       ObjectMapper mapper = new ObjectMapper();
432       mapper.setSerializationInclusion(Include.NON_NULL);
433       mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
434       inputData = mapper.writeValueAsString(input);
435       log.info("InputDataJson:" + inputData);
436
437     } catch (Exception e) {
438       log.error("Error occurred in " + fn, e);
439     }
440
441     String resourceUri = prop.getProperty(SEQ_GENERATOR_URL);
442     log.info(fn + "resourceUri= " + resourceUri);
443
444     EncryptionTool et = EncryptionTool.getInstance();
445     String pass = et.decrypt(prop.getProperty(SEQ_GENERATOR_PWD));
446
447     transaction.setPayload(inputData);
448     transaction.setExecutionRPC("POST");
449     transaction.setuId(prop.getProperty(SEQ_GENERATOR_UID));
450     transaction.setPswd(pass);
451     transaction.setExecutionEndPoint(resourceUri);
452
453     return inputData;
454   }
455
456   DependencyInfo getDependencyInfo(SvcLogicContext ctx) throws SvcLogicException, IOException {
457
458     String fn = "FlowExecutorNode.getDependencyInfo";
459     String dependencyData = dbService.getDependencyInfo(ctx);
460     log.info(fn + "dependencyDataInput:" + dependencyData);
461
462     DependencyInfo dependencyInfo = new DependencyInfo();
463     if (dependencyData == null) {
464       return dependencyInfo;
465     }
466
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 dependencyInfoData = mapper.readTree(dependencyData).get("dependencyInfo");
471     JsonNode vnfcData = mapper.readTree(dependencyData).get("vnfcs");
472     dependencyInfo.getVnfcs().addAll(mapper.readValue(vnfcData.toString(), new TypeReference<List<Vnfcs>>(){}));
473
474     log.info("Dependency Output:" + dependencyInfo.toString());
475     return dependencyInfo;
476   }
477
478   Capabilities getCapabilitiesData(SvcLogicContext ctx) throws SvcLogicException, IOException {
479
480     String fn = "FlowExecutorNode.getCapabilitiesData";
481     String capabilitiesData = dbService.getCapabilitiesData(ctx);
482     log.info(fn + "capabilitiesDataInput:" + capabilitiesData);
483
484     Capabilities capabilities = new Capabilities();
485     if (capabilitiesData == null) {
486       return capabilities;
487     }
488
489     ObjectMapper mapper = new ObjectMapper();
490     mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
491     mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
492
493     JsonNode capabilitiesNode = mapper.readTree(capabilitiesData);
494     log.info("capabilitiesNode:" + capabilitiesNode.toString());
495
496     capabilities.getVfModule().addAll(extractParameterList(mapper, capabilitiesNode, VF_MODULE));
497     capabilities.getVnfc().addAll(extractParameterList(mapper, capabilitiesNode, VNFC));
498     capabilities.getVnf().addAll(extractParameterList(mapper, capabilitiesNode, VNF));
499     capabilities.getVm().addAll(extractParameterList(mapper, capabilitiesNode, VM));
500
501     log.info("Capabilities Output:" + capabilities.toString());
502
503     return capabilities;
504   }
505
506   private <T> List<T> extractParameterList(ObjectMapper mapper, JsonNode root, String parameter) throws IOException {
507     JsonNode parameterNode = root.get(parameter);
508     if (parameterNode == null) {
509       return new ArrayList<>();
510     }
511     return mapper.readValue(parameterNode.toString(), new TypeReference<List<T>>() {});
512   }
513
514   private Properties loadProperties() throws Exception {
515     String directory = envVariables.getenv(SDNC_CONFIG_DIR_VAR);
516     if (directory == null) {
517       throw new Exception("Cannot find Property file -" + SDNC_CONFIG_DIR_VAR);
518     }
519     String path = directory + APPC_FLOW_CONTROLLER;
520     return PropertiesLoader.load(path);
521   }
522 }