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