/*-
* ============LICENSE_START=======================================================
- * ONAP : APP-C
+ * ONAP : APPC
* ================================================================================
- * Copyright (C) 2017 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
+ *
* ============LICENSE_END=========================================================
*/
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.onap.appc.dg.objects.InventoryModel;
+import org.onap.appc.dg.objects.Node;
+import org.onap.appc.dg.objects.VnfcDependencyModel;
+import org.onap.appc.domainmodel.Vnf;
+import org.onap.appc.domainmodel.Vnfc;
+import org.onap.appc.domainmodel.Vserver;
+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;
+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 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.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.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.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 org.onap.appc.dg.objects.InventoryModel;
-import org.onap.appc.dg.objects.Node;
-import org.onap.appc.dg.objects.VnfcDependencyModel;
-import org.onap.appc.domainmodel.Vnf;
-import org.onap.appc.domainmodel.Vserver;
-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.*;
-
-import java.util.*;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
+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;
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 {
+ if(input.getRequestInfo()==null){
+ throw new APPCException("Request info is missing in the input");
+ }
SequenceGenerator seqGenerator = SequenceGeneratorFactory.getInstance()
.createSequenceGenerator(VNFOperation.findByString(input.getRequestInfo().getAction().name()));
SequenceGeneratorInput seqGenInput = buildSeqGenInput(input);
List<Transaction> transactions = seqGenerator.generateSequence(seqGenInput);
- rpcResult = buildSuccessResponse(transactions);
- } catch (APPCException e) {
+ 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);
}
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){
- ActionIdentifier actionIdentifier = null;
- if(transaction.getActionIdentifier() != null){
- actionIdentifier = new ActionIdentifierBuilder()
- .setVnfId(transaction.getActionIdentifier().getVnfId())
- .setVnfcName(transaction.getActionIdentifier().getVnfcName())
- .setVserverId(transaction.getActionIdentifier().getvServerId())
- .build();
- }
-
- List<PrecheckOptions> precheckOptions = new LinkedList<>();
- if(transaction.getPrecheckOptions()!=null){
- for(PreCheckOption option:transaction.getPrecheckOptions()){
- PrecheckOptions precheckOption = new PrecheckOptionsBuilder()
- .setParamName(option.getParamName())
- .setParamValue(option.getParamValue())
- .setPreTransactionId(option.getPreTransactionId())
- .setRule(option.getRule())
- .build();
- precheckOptions.add(precheckOption);
- }
- }
-
+ for(Transaction transaction: transactions) {
+ ActionIdentifier actionIdentifier = buildActionIdentifierForResponse(transaction);
+ List<PrecheckOptions> precheckOptions = buildPrecheckOptionsForResponse(transaction);
List<Responses> responseList = getResponses(transaction);
-
Transactions transactionObj
= new TransactionsBuilder()
.setActionIdentifier(actionIdentifier)
.withResult(builder.build()).build();
}
+ private ActionIdentifier buildActionIdentifierForResponse(Transaction transaction) {
+ log.info("Adding action identifiers to response.");
+ ActionIdentifier actionIdentifier = null;
+ if(transaction.getActionIdentifier() != null){
+ actionIdentifier = new ActionIdentifierBuilder()
+ .setVnfId(transaction.getActionIdentifier().getVnfId())
+ .setVnfcName(transaction.getActionIdentifier().getVnfcName())
+ .setVserverId(transaction.getActionIdentifier().getvServerId())
+ .build();
+ }
+ return actionIdentifier;
+ }
+
+ private List<PrecheckOptions> buildPrecheckOptionsForResponse(Transaction transaction) {
+ log.info("Adding Precheck options to response");
+ List<PrecheckOptions> precheckOptions = new LinkedList<>();
+ if(transaction.getPrecheckOptions() != null){
+ for(PreCheckOption option:transaction.getPrecheckOptions()){
+ PrecheckOptions precheckOption = new PrecheckOptionsBuilder()
+ .setParamName(option.getParamName())
+ .setParamValue(option.getParamValue())
+ .setPreTransactionId(option.getPreTransactionId())
+ .setRule(option.getRule())
+ .build();
+ precheckOptions.add(precheckOption);
+ }
+ }
+ 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){
+ responseActionBuilder = responseActionBuilder.setJump(Integer.parseInt(responseActions.get(Constants.ResponseAction.JUMP.getAction())));
+ }
Responses response = new ResponsesBuilder()
.setResponseMessage(resp.getResponseMessage())
.setResponseAction(responseActionBuilder.build())
private SequenceGeneratorInput buildSeqGenInput(GenerateSequenceInput input) throws APPCException {
+ log.info("Building SequenceGeneratorInput from Yang object GenerateSequenceInput.");
validateMandatory(input);
- RequestInfoBuilder requestInfobuilder = new RequestInfoBuilder()
- .action(input.getRequestInfo().getAction().name())
- .actionLevel(input.getRequestInfo().getActionLevel().getName().toLowerCase())
- .payload(input.getRequestInfo().getPayload());
-
- if(input.getRequestInfo().getActionIdentifier() !=null){
- requestInfobuilder = requestInfobuilder
- .actionIdentifier()
- .vnfId(input.getRequestInfo().getActionIdentifier().getVnfId())
- .vnfcName(input.getRequestInfo().getActionIdentifier().getVnfcName())
- .vServerId(input.getRequestInfo().getActionIdentifier().getVserverId());
- }
-
- RequestInfo requestInfo = requestInfobuilder.build();
-
+ RequestInfo requestInfo = buildRequestInfoForSeqGenInput(input);
InventoryModel inventoryModel = readInventoryModel(input);
VnfcDependencyModel dependencyModel = readDependencyModel(input);
+ if(dependencyModel != null){
+ validateInventoryModelWithDependencyModel(dependencyModel, inventoryModel);
+ }
+
+ CapabilityModel capModel = buildCapabilitiesForSeqGenInput(input);
SequenceGeneratorInputBuilder builder = new SequenceGeneratorInputBuilder()
.requestInfo(requestInfo)
.inventoryModel(inventoryModel)
- .dependendcyModel(dependencyModel);
+ .dependendcyModel(dependencyModel)
+ .capabilityModel(capModel);
+
+ builder = buildTunableParamsForSeqGenInput(input, builder);
- if(input.getCapabilities() !=null){
+ return builder.build();
+ }
+
+ private SequenceGeneratorInputBuilder buildTunableParamsForSeqGenInput(GenerateSequenceInput input, SequenceGeneratorInputBuilder builder) {
+ log.info("Initializing Tunable Parameters based on YANG object.");
+ 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());
+ }
+ }
+ return builder;
+ }
+
+ public CapabilityModel buildCapabilitiesForSeqGenInput(GenerateSequenceInput input) {
+ log.info("Initializing capabilities based on YANG object.");
+
+ 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 new CapabilityModel(vnfCapabilities, vfModuleCapabilities, vmCapabilities, vnfcCapabilities);
+ }
- 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());
+ private void validateInventoryModelWithDependencyModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel) throws APPCException {
+ Set<String> dependencyModelVnfcSet = new HashSet<>();
+ Set<String> dependencyModelMandatoryVnfcSet = new HashSet<>();
+ Set<String> inventoryModelVnfcsSet = new HashSet<>();
+
+ for (Node<Vnfc> node : dependencyModel.getDependencies()) {
+ dependencyModelVnfcSet.add(node.getChild().getVnfcType().toLowerCase());
+ if (node.getChild().isMandatory()) {
+ dependencyModelMandatoryVnfcSet.add(node.getChild().getVnfcType().toLowerCase());
+ }
+ }
+
+ for (Vnfc vnfc : inventoryModel.getVnf().getVnfcs()) {
+ inventoryModelVnfcsSet.add(vnfc.getVnfcType().toLowerCase());
+ }
+
+ // if dependency model and inventory model contains same set of VNFCs, validation succeed and hence return
+ if (dependencyModelVnfcSet.equals(inventoryModelVnfcsSet)) {
+ return;
+ }
+
+ if (inventoryModelVnfcsSet.size() >= dependencyModelVnfcSet.size()) {
+ Set<String> difference = new HashSet<>(inventoryModelVnfcsSet);
+ difference.removeAll(dependencyModelVnfcSet);
+ log.error("Dependency model is missing following vnfc type(s): " + difference);
+ throw new APPCException("Dependency model is missing following vnfc type(s): " + difference);
+ } else {
+ Set<String> difference = new HashSet<>(dependencyModelMandatoryVnfcSet);
+ difference.removeAll(inventoryModelVnfcsSet);
+ if (difference.size() > 0) {
+ log.error("Inventory model is missing following mandatory vnfc type(s): " + difference);
+ throw new APPCException("VMs missing for the mandatory VNFC : " + difference);
}
}
- return builder.build();
}
+ private RequestInfo buildRequestInfoForSeqGenInput(GenerateSequenceInput input) {
+ log.info("Building RequestInfo from Yang object");
+ RequestInfoBuilder requestInfobuilder = buildRequestInformation(input);
+
+ if(input.getRequestInfo().getActionIdentifier() != null){
+ requestInfobuilder = buildActionIdentifiers(input, requestInfobuilder);
+ }
+
+ return requestInfobuilder.build();
+ }
+
+ private RequestInfoBuilder buildActionIdentifiers(GenerateSequenceInput input, RequestInfoBuilder requestInfobuilder) {
+ log.info("Initializing actionIdentifier for RequestInfo");
+ requestInfobuilder = requestInfobuilder
+ .actionIdentifier()
+ .vnfId(input.getRequestInfo().getActionIdentifier().getVnfId())
+ .vnfcName(input.getRequestInfo().getActionIdentifier().getVnfcName())
+ .vServerId(input.getRequestInfo().getActionIdentifier().getVserverId());
+ return requestInfobuilder;
+ }
+
+ private RequestInfoBuilder buildRequestInformation(GenerateSequenceInput input) {
+ log.info("Initializing action, actionLevel and payload for RequestInfo");
+ return new RequestInfoBuilder()
+ .action(input.getRequestInfo().getAction().name())
+ .actionLevel(input.getRequestInfo().getActionLevel().getName().toLowerCase())
+ .payload(input.getRequestInfo().getPayload());
+ }
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) {
+ log.error("vnfInfo is null in the input");
+ throw new APPCException("vnfInfo is missing in the input");
+ }
+ if(input.getInventoryInfo().getVnfInfo().getVm().isEmpty()){
+ log.error("Null vm information in input.");
+ throw new APPCException("VnfInfo is missing in the input");
+ }
+ log.info("Mandatory information present in the request.");
}
- private VnfcDependencyModel readDependencyModel(GenerateSequenceInput input) {
- if(input.getDependencyInfo() == null || input.getDependencyInfo().getVnfcs() ==null || input.getDependencyInfo().getVnfcs().isEmpty()){
+ 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()){
+ 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<>();
- for(Vnfcs vnfcObj:vnfcs){
- org.onap.appc.domainmodel.Vnfc vnfc;
- Node<org.onap.appc.domainmodel.Vnfc> currentNode = readNode(vnfcObj.getVnfcType(),dependencies);
- if(currentNode == null){
- vnfc = new org.onap.appc.domainmodel.Vnfc(vnfcObj.getVnfcType(),vnfcObj.getResilience());
- currentNode = new Node<>(vnfc);
- dependencies.add(currentNode);
- }
- else{
- currentNode.getChild().setResilienceType(vnfcObj.getResilience());
- currentNode.getChild().setMandatory(vnfcObj.isMandatory());
- }
- for(String parentVnfcType:vnfcObj.getParents()){
- Node<org.onap.appc.domainmodel.Vnfc> parentNode = readNode(parentVnfcType,dependencies);
+ 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()) {
+ parentVnfcs.add(parentVnfcType);
+ Node<Vnfc> parentNode = readNode(parentVnfcType, dependencies);
if(parentNode == null){
- org.onap.appc.domainmodel.Vnfc parentVnfc = new org.onap.appc.domainmodel.Vnfc(parentVnfcType,null);
+ Vnfc parentVnfc = new Vnfc();
+ parentVnfc.setVnfcType(parentVnfcType);
parentNode = new Node<>(parentVnfc);
currentNode.addParent(parentVnfc);
dependencies.add(parentNode);
}
}
}
+ for(String parent:parentVnfcs){
+ if(!allVnfcTypes.contains(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);
+ if(currentNode == null){
+ currentNode = new Node<>(vnfc);
+ dependencies.add(currentNode);
+ }
+ else{
+ currentNode.getChild().setResilienceType(vnfcObj.getResilience());
+ currentNode.getChild().setMandatory(vnfcObj.isMandatory());
+ }
+ return currentNode;
+ }
+
private Node<org.onap.appc.domainmodel.Vnfc> readNode(String vnfcType, Set<Node<org.onap.appc.domainmodel.Vnfc>> dependencies) {
for(Node<org.onap.appc.domainmodel.Vnfc> node : dependencies){
if(node.getChild().getVnfcType().equalsIgnoreCase(vnfcType)){
}
private InventoryModel readInventoryModel(GenerateSequenceInput input) throws APPCException {
- if (input.getInventoryInfo().getVnfInfo()== null) {
- throw new APPCException("vnfInfo is not provided in the input");
- }
- Vnf vnf = new Vnf(input.getInventoryInfo().getVnfInfo().getVnfId(),
- input.getInventoryInfo().getVnfInfo().getVnfType(),null);
+ log.info("Initializing InventoryModel from Yang input model");
+ Vnf vnf = createVnfForInventoryModel(input);
+ 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()){
+ org.onap.appc.domainmodel.Vnfc vnfc = entry.getKey();
+ List<Vserver> vmList = entry.getValue();
+ vnfc.addVservers(vmList);
+ }
+ return new InventoryModel(vnf);
+ }
- Map<org.onap.appc.domainmodel.Vnfc,List<Vserver>> map = new HashMap<>();
- for(Vm vm:input.getInventoryInfo().getVnfInfo().getVm()){
+ private void buildVserverDetailsForInventoryModel(GenerateSequenceInput input, Vnf vnf, Map<Vnfc, List<Vserver>> map) throws APPCException {
+ if(input.getInventoryInfo().getVnfInfo().getVm().size() < 1) {
+ throw new APPCException("vnfInfo is missing in the input");
+ }
+ for(Vm vm:input.getInventoryInfo().getVnfInfo().getVm()) {
if(StringUtils.isBlank(vm.getVserverId())){
throw new APPCException("vserver-id not found ");
}
- if(StringUtils.isBlank(vm.getVnfc().getVnfcType())){
- throw new APPCException("vnfc-type not found for vserver " + vm.getVserverId());
- }
- if(StringUtils.isBlank(vm.getVnfc().getVnfcName())){
- throw new APPCException("vnfc-name not found for vserver " + vm.getVserverId());
+ Vserver vserver=new Vserver();
+ vserver.setId(vm.getVserverId());
+ if(!StringUtils.isBlank(vm.getVnfc().getVnfcName()) &&
+ !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) {
+ vms = new LinkedList<>();
+ map.put(vfc,vms);
+ }
+ vms.add(vserver);
}
+ vnf.addVserver(vserver);
+ }
+ }
- org.onap.appc.domainmodel.Vnfc vnfc = new org.onap.appc.domainmodel.Vnfc(vm.getVnfc().getVnfcType(),null,vm.getVnfc().getVnfcName());
- List<Vserver> vms = map.get(vnfc);
- if(vms ==null){
- vms = new LinkedList<>();
- map.put(vnfc,vms);
- }
- vms.add(new Vserver(null,null,vm.getVserverId(),null,null));
- }
- 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.addVms(vmList);
- vnf.addVnfc(vnfc);
- }
- return new InventoryModel(vnf);
+ private Vnf createVnfForInventoryModel(GenerateSequenceInput input) {
+ log.info("Setting VnfId and VnfType values for Vnf Inventory Model ");
+ Vnf vnf=new Vnf();
+ vnf.setVnfId(input.getInventoryInfo().getVnfInfo().getVnfId());
+ vnf.setVnfType(input.getInventoryInfo().getVnfInfo().getVnfType());
+ vnf.setIdentityUrl(input.getInventoryInfo().getVnfInfo().getIdentityUrl());
+ 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