lower code smells
[appc.git] / appc-sequence-generator / appc-sequence-generator-bundle / src / main / java / org / onap / appc / seqgen / provider / SequenceGeneratorProvider.java
index f00a054..cc7a144 100644 (file)
@@ -2,9 +2,11 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.appc.seqgen.provider;
 
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-import com.google.common.util.concurrent.Futures;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 import org.apache.commons.lang.StringUtils;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
-import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
-import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.GenerateSequenceInput;
-import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.GenerateSequenceOutput;
-import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.GenerateSequenceOutputBuilder;
-import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.SequenceGeneratorService;
-import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.dependency.info.dependency.info.Vnfcs;
-import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.inventory.info.inventory.info.vnf.info.Vm;
-import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.StatusBuilder;
-import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.Transactions;
-import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.TransactionsBuilder;
-import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.transactions.ActionIdentifier;
-import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.transactions.*;
-import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.transactions.responses.ResponseActionBuilder;
-import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
 import org.onap.appc.dg.objects.InventoryModel;
 import org.onap.appc.dg.objects.Node;
 import org.onap.appc.dg.objects.VnfcDependencyModel;
@@ -55,7 +44,9 @@ import org.onap.appc.domainmodel.lcm.VNFOperation;
 import org.onap.appc.exceptions.APPCException;
 import org.onap.appc.seqgen.SequenceGenerator;
 import org.onap.appc.seqgen.impl.SequenceGeneratorFactory;
+import org.onap.appc.seqgen.objects.CapabilityModel;
 import org.onap.appc.seqgen.objects.Constants;
+import org.onap.appc.seqgen.objects.Constants.Action;
 import org.onap.appc.seqgen.objects.PreCheckOption;
 import org.onap.appc.seqgen.objects.RequestInfo;
 import org.onap.appc.seqgen.objects.RequestInfoBuilder;
@@ -63,28 +54,45 @@ import org.onap.appc.seqgen.objects.Response;
 import org.onap.appc.seqgen.objects.SequenceGeneratorInput;
 import org.onap.appc.seqgen.objects.SequenceGeneratorInputBuilder;
 import org.onap.appc.seqgen.objects.Transaction;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.GenerateSequenceInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.GenerateSequenceOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.GenerateSequenceOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.SequenceGeneratorService;
+import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.dependency.info.dependency.info.Vnfcs;
+import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.inventory.info.inventory.info.vnf.info.Vm;
+import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.StatusBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.Transactions;
+import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.TransactionsBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.transactions.ActionIdentifier;
+import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.transactions.ActionIdentifierBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.transactions.PrecheckOptions;
+import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.transactions.PrecheckOptionsBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.transactions.Responses;
+import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.transactions.ResponsesBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.sequencegenerator.rev170706.response.transactions.responses.ResponseActionBuilder;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
 
 
-public class SequenceGeneratorProvider implements AutoCloseable,SequenceGeneratorService{
+public class SequenceGeneratorProvider implements AutoCloseable,SequenceGeneratorService {
     protected DataBroker dataBroker;
     protected RpcProviderRegistry rpcRegistry;
-    protected NotificationProviderService notificationService;
+    protected NotificationPublishService notificationService;
     protected BindingAwareBroker.RpcRegistration<SequenceGeneratorService> rpcRegistration;
     private final EELFLogger log = EELFManager.getInstance().getLogger(SequenceGeneratorProvider.class);
     private final ExecutorService executor;
-    private final static String APP_NAME = "SequenceGeneratorProvider";
+    private static final String APP_NAME = "SequenceGeneratorProvider";
 
-    public SequenceGeneratorProvider(DataBroker dataBroker2, NotificationProviderService notificationProviderService
-            RpcProviderRegistry rpcRegistry2) {
+    public SequenceGeneratorProvider(DataBroker dataBroker2, NotificationPublishService notificationProviderService,
+            RpcProviderRegistry rpcRegistry2) {
         log.info("Creating provider for " + APP_NAME);
         executor = Executors.newFixedThreadPool(1);
         this.dataBroker = dataBroker2;
@@ -104,14 +112,14 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
         if(this.executor != null){
             executor.shutdown();
         }
-        if(this.rpcRegistration != null){
+        if(this.rpcRegistration != null) {
             rpcRegistration.close();
         }
         log.info("Successfully closed provider for " + APP_NAME);
     }
 
     @Override
-    public Future<RpcResult<GenerateSequenceOutput>> generateSequence(GenerateSequenceInput input) {
+    public ListenableFuture<RpcResult<GenerateSequenceOutput>> generateSequence(GenerateSequenceInput input) {
         RpcResult<GenerateSequenceOutput> rpcResult=null;
         log.debug("Received input = " + input );
         try {
@@ -122,10 +130,14 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
                     .createSequenceGenerator(VNFOperation.findByString(input.getRequestInfo().getAction().name()));
             SequenceGeneratorInput seqGenInput = buildSeqGenInput(input);
             List<Transaction> transactions = seqGenerator.generateSequence(seqGenInput);
-            rpcResult = buildSuccessResponse(transactions);
+            if (transactions.isEmpty()) {
+                rpcResult = buildFailureResponse("Request is not supported", 450);
+            } else {
+                rpcResult = buildSuccessResponse(transactions);
+            }
         } catch (Exception e) {
             log.error("Error Generating Sequence",e);
-            rpcResult = buildFailureResponse(e.getMessage());
+            rpcResult = buildFailureResponse(e.getMessage(), 0);
         }
         return Futures.immediateFuture(rpcResult);
     }
@@ -133,7 +145,7 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
     private RpcResult<GenerateSequenceOutput> buildSuccessResponse(List<Transaction> transactions) {
         log.info("Building response from the list of transactions");
         List<Transactions> transactionList = new LinkedList<>();
-        for(Transaction transaction:transactions){
+        for(Transaction transaction: transactions) {
             ActionIdentifier actionIdentifier = buildActionIdentifierForResponse(transaction);
             List<PrecheckOptions> precheckOptions = buildPrecheckOptionsForResponse(transaction);
             List<Responses> responseList = getResponses(transaction);
@@ -175,7 +187,7 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
     private List<PrecheckOptions> buildPrecheckOptionsForResponse(Transaction transaction) {
         log.info("Adding Precheck options to response");
         List<PrecheckOptions> precheckOptions = new LinkedList<>();
-        if(transaction.getPrecheckOptions()!=null){
+        if(transaction.getPrecheckOptions() != null){
             for(PreCheckOption option:transaction.getPrecheckOptions()){
                 PrecheckOptions precheckOption = new PrecheckOptionsBuilder()
                         .setParamName(option.getParamName())
@@ -189,27 +201,28 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
         return precheckOptions;
     }
     private List<Responses> getResponses(Transaction transaction) {
+        log.info("Building response from the Transaction");
         List<Responses> responseList = new LinkedList<>();
         for(Response resp : transaction.getResponses()){
             Map<String,String> responseActions = resp.getResponseAction();
             ResponseActionBuilder responseActionBuilder = new ResponseActionBuilder();
-            if(responseActions.get(Constants.ResponseAction.WAIT.getAction())!=null){
+            if(responseActions.get(Constants.ResponseAction.WAIT.getAction()) != null){
                 responseActionBuilder = responseActionBuilder.setWait(Integer.parseInt(responseActions.get(Constants.ResponseAction.WAIT.getAction())));
             }
-            if(responseActions.get(Constants.ResponseAction.RETRY.getAction())!=null){
+            if(responseActions.get(Constants.ResponseAction.RETRY.getAction()) != null){
                 responseActionBuilder = responseActionBuilder.setRetry(Integer.parseInt(responseActions.get(Constants.ResponseAction.RETRY.getAction())));
             }
             if(responseActions.get(Constants.ResponseAction.CONTINUE.getAction().toLowerCase())!=null){
                 responseActionBuilder = responseActionBuilder
                         .setContinue(Boolean.parseBoolean(responseActions.get(Constants.ResponseAction.CONTINUE.getAction().toLowerCase())));
             }
-            if(responseActions.get(Constants.ResponseAction.IGNORE.getAction()) !=null){
+            if(responseActions.get(Constants.ResponseAction.IGNORE.getAction()) != null){
                 responseActionBuilder = responseActionBuilder.setIgnore(Boolean.parseBoolean(responseActions.get(Constants.ResponseAction.IGNORE.getAction())));
             }
-            if(responseActions.get(Constants.ResponseAction.STOP.getAction()) !=null){
+            if(responseActions.get(Constants.ResponseAction.STOP.getAction()) != null){
                 responseActionBuilder = responseActionBuilder.setStop(Boolean.parseBoolean(responseActions.get(Constants.ResponseAction.STOP.getAction())));
             }
-            if(responseActions.get(Constants.ResponseAction.JUMP.getAction()) !=null){
+            if(responseActions.get(Constants.ResponseAction.JUMP.getAction()) != null){
                 responseActionBuilder = responseActionBuilder.setJump(Integer.parseInt(responseActions.get(Constants.ResponseAction.JUMP.getAction())));
             }
             Responses response = new ResponsesBuilder()
@@ -230,16 +243,17 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
         InventoryModel inventoryModel = readInventoryModel(input);
 
         VnfcDependencyModel dependencyModel = readDependencyModel(input);
-        if(dependencyModel!=null){
-            validateInventoryModelWithDependencyModel(dependencyModel,inventoryModel);
+        if(dependencyModel != null){
+            validateInventoryModelWithDependencyModel(dependencyModel, inventoryModel);
         }
 
+        CapabilityModel capModel = buildCapabilitiesForSeqGenInput(input);
+
         SequenceGeneratorInputBuilder builder = new SequenceGeneratorInputBuilder()
                 .requestInfo(requestInfo)
                 .inventoryModel(inventoryModel)
-                .dependendcyModel(dependencyModel);
-
-        builder = buildCapabilitiesForSeqGenInput(input, builder);
+                .dependendcyModel(dependencyModel)
+                .capabilityModel(capModel);
 
         builder = buildTunableParamsForSeqGenInput(input, builder);
 
@@ -251,31 +265,46 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
         if(input.getTunableParameters() != null){
             builder = builder.tunableParameter(Constants.RETRY_COUNT,String.valueOf(input.getTunableParameters().getRetryCount()))
                     .tunableParameter(Constants.WAIT_TIME,String.valueOf(input.getTunableParameters().getWaitTime()));
-            if(input.getTunableParameters().getStrategy() !=null){
-                builder  = builder.tunableParameter(Constants.STRATEGY,input.getTunableParameters().getStrategy().name());
+            if(input.getTunableParameters().getStrategy() != null){
+                builder = builder.tunableParameter(Constants.STRATEGY,input.getTunableParameters().getStrategy().name());
             }
         }
         return builder;
     }
 
-    private SequenceGeneratorInputBuilder buildCapabilitiesForSeqGenInput(GenerateSequenceInput input, SequenceGeneratorInputBuilder builder) {
+    public CapabilityModel buildCapabilitiesForSeqGenInput(GenerateSequenceInput input) {
         log.info("Initializing capabilities based on YANG object.");
-        if(input.getCapabilities() !=null){
+        
+        List<String> vnfCapabilities = null;
+        List<String> vfModuleCapabilities = null;
+        Map<String, List<String>> vmCapabilities = null;
+        List<String> vnfcCapabilities = null;
+        
+        if(input.getCapabilities()!=null){
             if(input.getCapabilities().getVnf()!=null){
-                builder = builder.capability("vnf",input.getCapabilities().getVnf());
+                vnfCapabilities = input.getCapabilities().getVnf();
             }
             if(input.getCapabilities().getVnfc()!=null){
-                builder = builder.capability("vnfc",input.getCapabilities().getVnfc());
+                vfModuleCapabilities = input.getCapabilities().getVnfc();
             }
             if(input.getCapabilities().getVm()!=null){
-                builder = builder.capability("vm",input.getCapabilities().getVm());
+                vmCapabilities = new HashMap<String, List<String>>();
+                vmCapabilities.put(Action.ATTACH_VOLUME.getActionType(), input.getCapabilities().getVm().getAttachVolume());
+                vmCapabilities.put(Action.DETACH_VOLUME.getActionType(), input.getCapabilities().getVm().getDetachVolume());
+                vmCapabilities.put(Action.EVACUATE.getActionType(), input.getCapabilities().getVm().getEvacuate());
+                vmCapabilities.put(Action.MIGRATE.getActionType(), input.getCapabilities().getVm().getMigrate());
+                vmCapabilities.put(Action.REBOOT.getActionType(), input.getCapabilities().getVm().getReboot());
+                vmCapabilities.put(Action.REBUILD.getActionType(), input.getCapabilities().getVm().getRebuild());
+                vmCapabilities.put(Action.RESTART.getActionType(), input.getCapabilities().getVm().getRestart());
+                vmCapabilities.put(Action.SNAPSHOT.getActionType(), input.getCapabilities().getVm().getSnapshot());
+                vmCapabilities.put(Action.START.getActionType(), input.getCapabilities().getVm().getStart());
+                vmCapabilities.put(Action.STOP.getActionType(), input.getCapabilities().getVm().getStop());
             }
             if(input.getCapabilities().getVfModule()!=null){
-                builder = builder.capability("vf-module",input.getCapabilities().getVfModule());
+                vnfcCapabilities = input.getCapabilities().getVfModule();
             }
         }
-
-        return builder;
+        return new CapabilityModel(vnfCapabilities, vfModuleCapabilities, vmCapabilities, vnfcCapabilities);
     }
 
     private void validateInventoryModelWithDependencyModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel) throws APPCException {
@@ -318,7 +347,7 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
         log.info("Building RequestInfo from Yang object");
         RequestInfoBuilder requestInfobuilder = buildRequestInformation(input);
 
-        if(input.getRequestInfo().getActionIdentifier() !=null){
+        if(input.getRequestInfo().getActionIdentifier() != null){
             requestInfobuilder = buildActionIdentifiers(input, requestInfobuilder);
         }
 
@@ -344,16 +373,16 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
     }
 
     private void validateMandatory(GenerateSequenceInput input) throws APPCException {
-        if(input.getRequestInfo() ==null){
+        if(input.getRequestInfo() == null){
             throw new APPCException("Request Info is not present in the request");
         }
-        if(input.getRequestInfo().getAction() ==null){
+        if(input.getRequestInfo().getAction() == null){
             throw new APPCException("Action is not present in the request");
         }
-        if(input.getInventoryInfo() ==null){
+        if(input.getInventoryInfo() == null){
             throw new APPCException("inventoryInfo is not provided in the input");
         }
-        if (input.getInventoryInfo().getVnfInfo()== null) {
+        if (input.getInventoryInfo().getVnfInfo() == null) {
             log.error("vnfInfo is null in the input");
             throw new APPCException("vnfInfo is missing in the input");
         }
@@ -366,23 +395,23 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
 
     private VnfcDependencyModel readDependencyModel(GenerateSequenceInput input) throws APPCException{
         log.info("Initializing DependencyModel from YANG model.");
-        if(input.getDependencyInfo() == null || input.getDependencyInfo().getVnfcs() ==null || input.getDependencyInfo().getVnfcs().isEmpty()){
+        if(input.getDependencyInfo() == null || input.getDependencyInfo().getVnfcs() == null || input.getDependencyInfo().getVnfcs().isEmpty()){
             log.info("No dependency model information is present for the request.");
             return null;
         }
         List<Vnfcs> vnfcs = input.getDependencyInfo().getVnfcs();
         Set<Node<org.onap.appc.domainmodel.Vnfc>> dependencies = new HashSet<>();
-        Set<String> parentVnfcs=new HashSet<>();
-        Set<String> allVnfcTypes=new HashSet<>();
-        for(Vnfcs vnfcObj:vnfcs){
+        Set<String> parentVnfcs = new HashSet<>();
+        Set<String> allVnfcTypes = new HashSet<>();
+        for(Vnfcs vnfcObj:vnfcs) {
             org.onap.appc.domainmodel.Vnfc vnfc = new org.onap.appc.domainmodel.Vnfc();
             vnfc.setVnfcType(vnfcObj.getVnfcType());
             allVnfcTypes.add(vnfcObj.getVnfcType());
             vnfc.setResilienceType(vnfcObj.getResilience());
             Node<Vnfc> currentNode = buildVnfcNodeForDependenyInfo(dependencies, vnfcObj, vnfc);
-            for(String parentVnfcType:vnfcObj.getParents()){
+            for(String parentVnfcType:vnfcObj.getParents()) {
                 parentVnfcs.add(parentVnfcType);
-                Node<Vnfc> parentNode = readNode(parentVnfcType,dependencies);
+                Node<Vnfc> parentNode = readNode(parentVnfcType, dependencies);
                 if(parentNode == null){
                     Vnfc parentVnfc = new Vnfc();
                     parentVnfc.setVnfcType(parentVnfcType);
@@ -397,14 +426,14 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
         }
         for(String parent:parentVnfcs){
             if(!allVnfcTypes.contains(parent)){
-                throw new APPCException("Dependency model missing vnfc type "+parent);
+                throw new APPCException("Dependency model missing vnfc type " + parent);
             }
         }
         return new VnfcDependencyModel(dependencies);
     }
 
     private Node<Vnfc> buildVnfcNodeForDependenyInfo(Set<Node<Vnfc>> dependencies, Vnfcs vnfcObj, Vnfc vnfc) {
-        Node<Vnfc> currentNode = readNode(vnfcObj.getVnfcType(),dependencies);
+        Node<Vnfc> currentNode = readNode(vnfcObj.getVnfcType(), dependencies);
         if(currentNode == null){
             currentNode = new Node<>(vnfc);
             dependencies.add(currentNode);
@@ -429,9 +458,9 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
 
         log.info("Initializing InventoryModel from Yang input model");
         Vnf vnf = createVnfForInventoryModel(input);
-        Map<org.onap.appc.domainmodel.Vnfc,List<Vserver>> map = new HashMap<>();
+        Map<org.onap.appc.domainmodel.Vnfc, List<Vserver>> map = new HashMap<>();
         buildVserverDetailsForInventoryModel(input, vnf, map);
-        for(Map.Entry<org.onap.appc.domainmodel.Vnfc,List<Vserver>> entry:map.entrySet()){
+        for(Map.Entry<org.onap.appc.domainmodel.Vnfc, List<Vserver>> entry:map.entrySet()){
             org.onap.appc.domainmodel.Vnfc vnfc = entry.getKey();
             List<Vserver> vmList = entry.getValue();
             vnfc.addVservers(vmList);
@@ -440,23 +469,24 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
     }
 
     private void buildVserverDetailsForInventoryModel(GenerateSequenceInput input, Vnf vnf, Map<Vnfc, List<Vserver>> map) throws APPCException {
-        if(input.getInventoryInfo().getVnfInfo().getVm().size()<1){
+        if(input.getInventoryInfo().getVnfInfo().getVm().size() < 1) {
             throw  new APPCException("vnfInfo is missing  in the input");
         }
-        for(Vm vm:input.getInventoryInfo().getVnfInfo().getVm()){
+        for(Vm vm:input.getInventoryInfo().getVnfInfo().getVm()) {
             if(StringUtils.isBlank(vm.getVserverId())){
                 throw new APPCException("vserver-id not found ");
             }
             Vserver vserver=new Vserver();
             vserver.setId(vm.getVserverId());
             if(!StringUtils.isBlank(vm.getVnfc().getVnfcName()) &&
-                !StringUtils.isBlank(vm.getVnfc().getVnfcType())){
+                !StringUtils.isBlank(vm.getVnfc().getVnfcType())) {
                 Vnfc vfc = new Vnfc();
                 vfc.setVnfcName(vm.getVnfc().getVnfcName());
                 vfc.setVnfcType(vm.getVnfc().getVnfcType());
+                vfc.setVnfcFunctionCode(vm.getVnfc().getVnfcFunctionCode());
                 vserver.setVnfc(vfc);
                 List<Vserver> vms = map.get(vfc);
-                if(vms ==null){
+                if(vms ==null) {
                     vms = new LinkedList<>();
                     map.put(vfc,vms);
                 }
@@ -475,10 +505,10 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
         return vnf;
     }
 
-    private RpcResult<GenerateSequenceOutput> buildFailureResponse(String errorMessage){
+    private RpcResult<GenerateSequenceOutput> buildFailureResponse(String errorMessage, int errorCode){
         GenerateSequenceOutputBuilder sequenceGeneratorOutputBuilder=new GenerateSequenceOutputBuilder();
-        StatusBuilder statusBuilder =new StatusBuilder();
-        statusBuilder.setCode(401);
+        StatusBuilder statusBuilder = new StatusBuilder();
+        statusBuilder.setCode((errorCode != 0)? errorCode : 401);
         statusBuilder.setMessage(errorMessage);
         sequenceGeneratorOutputBuilder.setStatus(statusBuilder.build());
         return RpcResultBuilder