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