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