summaryrefslogtreecommitdiffstats
path: root/appc-sequence-generator/appc-sequence-generator-bundle/src/main
diff options
context:
space:
mode:
authorRamya Balaji <rb111y@att.com>2018-01-02 21:58:59 -0500
committerSkip Wonnell <skip@att.com>2018-01-04 21:10:36 +0000
commit13b9505921e2cbbd4b155a78bfdaa5caa3375ec0 (patch)
tree7c661f5c3c8b7895cad1d4c3c90b9077ba74c1fd /appc-sequence-generator/appc-sequence-generator-bundle/src/main
parent9ebb5ddcb60345dea668049c73f5f2d9c3cdf731 (diff)
Updated SDC listener and dependent bundles
Changes related to SDC adapter.Also includes sequence generator changes and changes to appc-dg-shared. Issue-ID: APPC-355 Change-Id: Ib8a0b1d304199db6d2595291539b266885842d63 Signed-off-by: Ramya Balaji <rb111y@att.com>
Diffstat (limited to 'appc-sequence-generator/appc-sequence-generator-bundle/src/main')
-rw-r--r--appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dgplugin/impl/SequenceGeneratorPluginImpl.java123
-rw-r--r--appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/RestartSequenceGenerator.java108
-rw-r--r--appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/SequenceGeneratorFactory.java4
-rw-r--r--appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StartSequenceGenerator.java144
-rw-r--r--appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StopSequenceGenerator.java141
-rw-r--r--appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/Constants.java11
-rw-r--r--appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/provider/SequenceGeneratorProvider.java309
7 files changed, 603 insertions, 237 deletions
diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dgplugin/impl/SequenceGeneratorPluginImpl.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dgplugin/impl/SequenceGeneratorPluginImpl.java
index c0ea4134c..8e44bc3bd 100644
--- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dgplugin/impl/SequenceGeneratorPluginImpl.java
+++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/dgplugin/impl/SequenceGeneratorPluginImpl.java
@@ -27,8 +27,10 @@ import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.commons.lang3.StringUtils;
-import org.onap.appc.dg.objects.*;
+import org.onap.appc.dg.flowbuilder.exception.InvalidDependencyModelException;
+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;
@@ -43,7 +45,12 @@ import org.onap.appc.seqgen.objects.Transaction;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import java.io.IOException;
-import java.util.*;
+import java.util.Map;
+import java.util.List;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.HashMap;
+import java.util.LinkedList;
public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin {
@@ -79,6 +86,9 @@ public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin {
sequenceGeneratorInput.setInventoryModel(inventoryModel);
VnfcDependencyModel dependencyModel = buildDependencyModel(inputJson);
+ if(dependencyModel!=null){
+ validateInventoryModelWithDependencyModel(dependencyModel,inventoryModel);
+ }
sequenceGeneratorInput.setDependencyModel(dependencyModel);
return sequenceGeneratorInput;
@@ -92,13 +102,54 @@ public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin {
if (operation == null) {
throw new APPCException("Invalid Action " + action);
}
+ if(Constants.ActionLevel.findByString(sequenceGeneratorInput.getRequestInfo().getActionLevel().toUpperCase())==null){
+ throw new APPCException("Invalid Action Level " + sequenceGeneratorInput.getRequestInfo().getActionLevel());
+ }
SequenceGenerator sequenceGenerator = SequenceGeneratorFactory.getInstance().createSequenceGenerator(operation);
return sequenceGenerator.generateSequence(sequenceGeneratorInput);
}
+ 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);
+ logger.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) {
+ logger.error("Inventory model is missing following mandatory vnfc type(s): " + difference);
+ throw new APPCException("VMs missing for the mandatory VNFC : " + difference);
+ }
+ }
+ }
+
// Dependency model is an optional attribute and may contain null values
private VnfcDependencyModel buildDependencyModel(String inputJson) throws IOException, APPCException {
Set<Node<Vnfc>> dependency = new HashSet<>();
+ Set<String> parentVnfcs=new HashSet<>();
+ Set<String> allVnfcTypes=new HashSet<>();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
JsonNode rootNode = objectMapper.readTree(inputJson);
@@ -106,9 +157,13 @@ public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin {
if (vnfcs != null) {
for (JsonNode vnfcNode : vnfcs) {
String vnfcType = readVnfcType(vnfcNode);
+ allVnfcTypes.add(vnfcType);
String mandatory = readMandatory(vnfcNode);
String resilience = readResilience(vnfcNode);
- Vnfc vnfc = new Vnfc(vnfcType, resilience, null, Boolean.parseBoolean(mandatory));
+ Vnfc vnfc = new Vnfc();
+ vnfc.setVnfcType(vnfcType);
+ vnfc.setResilienceType(resilience);
+ vnfc.setMandatory(Boolean.parseBoolean(mandatory));
Node<Vnfc> currentNode = getNode(dependency, vnfcType);
if (currentNode == null) {
currentNode = new Node<>(vnfc);
@@ -120,11 +175,14 @@ public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin {
JsonNode parents = vnfcNode.get("parents");
for (JsonNode parent : parents) {
String parentVnfcType = parent.asText();
+ parentVnfcs.add(parentVnfcType);
Node<Vnfc> parentNode = getNode(dependency, parentVnfcType);
if (parentNode != null) {
currentNode.addParent(parentNode.getChild());
} else {
- Vnfc parentVnfc = new Vnfc(parentVnfcType, null, null, false);
+ Vnfc parentVnfc=new Vnfc();
+ parentVnfc.setVnfcType(parentVnfcType);
+ parentVnfc.setMandatory(false);
parentNode = new Node<>(parentVnfc);
currentNode.addParent(parentVnfc);
dependency.add(parentNode);
@@ -132,6 +190,11 @@ public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin {
}
}
+ for(String parent:parentVnfcs){
+ if(!allVnfcTypes.contains(parent)){
+ throw new APPCException("Dependency model missing vnfc type "+parent);
+ }
+ }
return new VnfcDependencyModel(dependency);
}
return null;
@@ -184,7 +247,6 @@ public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin {
private InventoryModel buildInventoryModel(String inputJson) throws IOException, APPCException {
ObjectMapper objectMapper = new ObjectMapper();
- objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
JsonNode jsonNode = objectMapper.readTree(inputJson);
JsonNode inventoryInfo = jsonNode.get("inventory-info");
if (inventoryInfo == null) {
@@ -197,45 +259,40 @@ public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin {
String vnfId = vnfInfo.get("vnf-id").asText();
String vnfType = vnfInfo.get("vnf-type").asText();
- String vnfVersion = vnfInfo.get("vnf-version").asText();
-
- Vnf vnf = new Vnf(vnfId, vnfType, vnfVersion);
-
- JsonNode vms = vnfInfo.get("vm");
-
+ Vnf vnf =new Vnf();
+ vnf.setVnfId(vnfId);
+ vnf.setVnfType(vnfType);
Map<Vnfc, List<Vserver>> vfcs = new HashMap<>();
+ JsonNode vms = vnfInfo.get("vm");
+ if(vms.size()<1){
+ throw new APPCException("vm info not provided in the input");
+ }
for (JsonNode vm : vms) {
if(vm.get("vserver-id")== null){
throw new APPCException("vserver-id not found ");
}
String vserverId = vm.get("vserver-id").asText();
- Vserver vserver = new Vserver(null, null, vserverId, null, null);
- JsonNode vnfc = vm.get("vnfc");
- if (vnfc.get("vnfc-name") == null) {
- throw new APPCException("vnfc-name not found for vserver " + vserverId);
- }
- String vnfcName = vnfc.get("vnfc-name").asText();
- if (vnfc.get("vnfc-type") == null) {
- throw new APPCException("vnfc-type not found for vserver " + vserverId);
- }
- String vnfcType = vnfc.get("vnfc-type").asText();
- if (StringUtils.isEmpty(vnfcType)) {
- throw new APPCException("vserver " + vserverId + " is not associated with any vnfc");
- }
- Vnfc vfc = new Vnfc(vnfcType, null, vnfcName);
- List<Vserver> vServers = vfcs.get(vfc);
- if (vServers == null) {
- vServers = new LinkedList<>();
- vfcs.put(vfc, vServers);
+ Vserver vserver = new Vserver();
+ vserver.setId(vserverId);
+ if (vm.get("vnfc")!=null&& vm.get("vnfc").get("vnfc-name") != null && vm.get("vnfc").get("vnfc-type")!= null) {
+ Vnfc vfc = new Vnfc();
+ vfc.setVnfcType(vm.get("vnfc").get("vnfc-type").asText());
+ vfc.setVnfcName(vm.get("vnfc").get("vnfc-name").asText());
+ vserver.setVnfc(vfc);
+ List<Vserver> vServers = vfcs.get(vfc);
+ if (vServers == null) {
+ vServers = new LinkedList<>();
+ vfcs.put(vfc, vServers);
+ }
+ vServers.add(vserver);
}
- vServers.add(vserver);
+ vnf.addVserver(vserver);
}
for (Map.Entry<Vnfc, List<Vserver>> entry : vfcs.entrySet()) {
Vnfc vnfc = entry.getKey();
List<Vserver> vServers = vfcs.get(vnfc);
- vnfc.addVms(vServers);
- vnf.addVnfc(vnfc);
+ vnfc.addVservers(vServers);
}
return new InventoryModel(vnf);
diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/RestartSequenceGenerator.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/RestartSequenceGenerator.java
new file mode 100644
index 000000000..49fad50de
--- /dev/null
+++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/RestartSequenceGenerator.java
@@ -0,0 +1,108 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.seqgen.impl;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.onap.appc.domainmodel.Vserver;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.seqgen.SequenceGenerator;
+import org.onap.appc.seqgen.objects.ActionIdentifier;
+import org.onap.appc.seqgen.objects.Constants;
+import org.onap.appc.seqgen.objects.Response;
+import org.onap.appc.seqgen.objects.SequenceGeneratorInput;
+import org.onap.appc.seqgen.objects.Transaction;;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+public class RestartSequenceGenerator implements SequenceGenerator{
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(RestartSequenceGenerator.class);
+
+ @Override
+ public List<Transaction> generateSequence(SequenceGeneratorInput input) throws APPCException {
+ logger.info("Generating sequence without dependency model");
+ return generateSequenceWithOutDependency(input);
+ }
+
+ private List<Transaction> generateSequenceWithOutDependency(SequenceGeneratorInput input) {
+ List<Transaction> transactionList = new LinkedList<>();
+ Integer transactionId = 1;
+ List<Vserver> vservers = input.getInventoryModel().getVnf().getVservers();
+ List<Integer> transactionIds = new LinkedList<>();
+ for (Vserver vm : vservers) {
+ Transaction transactionStop = new Transaction();
+ transactionStop.setTransactionId(transactionId);
+ transactionIds.add(transactionId++);
+ transactionStop.setAction(Constants.Action.STOP.getActionType());
+ transactionStop.setActionLevel(Constants.ActionLevel.VM.getAction());
+ ActionIdentifier actionIdentifier = new ActionIdentifier();
+ actionIdentifier.setvServerId(vm.getId());
+ transactionStop.setActionIdentifier(actionIdentifier);
+ transactionStop.setPayload(input.getRequestInfo().getPayload());
+ if (vservers.size()>1) {
+ Response failureResponse = new Response();
+ failureResponse.setResponseMessage(Constants.ResponseMessage.FAILURE.getResponse());
+ Map<String,String> failureAction = new HashMap<>();
+ if(!checkLastVM(vservers,vm.getId()))
+ {
+ failureAction.put(Constants.ResponseAction.JUMP.getAction(), String.valueOf(transactionId+1));
+ failureResponse.setResponseAction(failureAction);
+ transactionStop.addResponse(failureResponse);
+ }
+ }
+ transactionList.add(transactionStop);
+ Transaction transactionStart = new Transaction();
+ transactionStart.setTransactionId(transactionId);
+ transactionIds.add(transactionId++);
+ transactionStart.setAction(Constants.Action.START.getActionType());
+ transactionStart.setActionLevel(Constants.ActionLevel.VM.getAction());
+ ActionIdentifier actionIdentifierStart = new ActionIdentifier();
+ actionIdentifierStart.setvServerId(vm.getId());
+ transactionStart.setActionIdentifier(actionIdentifierStart);
+ transactionStart.setPayload(input.getRequestInfo().getPayload());
+ if (vservers.size()>1) {
+ Response failureResponse = new Response();
+ failureResponse.setResponseMessage(Constants.ResponseMessage.FAILURE.getResponse());
+ Map<String,String> failureAction = new HashMap<>();
+ if(!checkLastVM(vservers,vm.getId()))
+ {
+ failureAction.put(Constants.ResponseAction.JUMP.getAction(),transactionId.toString());
+ failureResponse.setResponseAction(failureAction);
+ transactionStart.addResponse(failureResponse);
+ }
+ }
+ transactionList.add(transactionStart);
+ }
+ return transactionList;
+ }
+
+ private boolean checkLastVM(List<Vserver> vservers, String vmId){
+ Vserver vm= vservers.get(vservers.size()-1);
+ return vm.getId().equals(vmId);
+ }
+}
diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/SequenceGeneratorFactory.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/SequenceGeneratorFactory.java
index 3c6a11962..15d88c9cf 100644
--- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/SequenceGeneratorFactory.java
+++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/SequenceGeneratorFactory.java
@@ -47,7 +47,9 @@ public class SequenceGeneratorFactory {
return new StartSequenceGenerator();
case Stop:
return new StopSequenceGenerator();
- default:
+ case Restart:
+ return new RestartSequenceGenerator();
+ default:
throw new APPCException("Sequence Generator does not support operation " + operation.name());
}
}
diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StartSequenceGenerator.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StartSequenceGenerator.java
index dcffaafd8..9c9ba8dd8 100644
--- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StartSequenceGenerator.java
+++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StartSequenceGenerator.java
@@ -24,6 +24,7 @@ import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import org.apache.commons.lang3.StringUtils;
import org.onap.appc.dg.flowbuilder.FlowBuilder;
+import org.onap.appc.dg.flowbuilder.exception.InvalidDependencyModelException;
import org.onap.appc.dg.flowbuilder.impl.FlowBuilderFactory;
import org.onap.appc.dg.objects.FlowStrategies;
import org.onap.appc.dg.objects.InventoryModel;
@@ -33,11 +34,30 @@ import org.onap.appc.domainmodel.Vnfc;
import org.onap.appc.domainmodel.Vserver;
import org.onap.appc.exceptions.APPCException;
import org.onap.appc.seqgen.SequenceGenerator;
-import org.onap.appc.seqgen.objects.*;
+import org.onap.appc.seqgen.objects.ActionIdentifier;
+import org.onap.appc.seqgen.objects.Constants;
+import org.onap.appc.seqgen.objects.PreCheckOption;
+import org.onap.appc.seqgen.objects.Response;
+import org.onap.appc.seqgen.objects.SequenceGeneratorInput;
+import org.onap.appc.seqgen.objects.Transaction;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
-import static org.onap.appc.seqgen.objects.Constants.*;
+import static org.onap.appc.seqgen.objects.Constants.Action;
+import static org.onap.appc.seqgen.objects.Constants.ActionLevel;
+import static org.onap.appc.seqgen.objects.Constants.ResponseAction;
+import static org.onap.appc.seqgen.objects.Constants.ResponseMessage;
+import static org.onap.appc.seqgen.objects.Constants.PreCheckOperator;
+import static org.onap.appc.seqgen.objects.Constants.Capabilties;
+import static org.onap.appc.seqgen.objects.Constants.CapabilityLevel;
+import static org.onap.appc.seqgen.objects.Constants.RETRY_COUNT_VALUE;
+import static org.onap.appc.seqgen.objects.Constants.WAIT_TIME;
+import static org.onap.appc.seqgen.objects.Constants.RETRY_COUNT;
+import static org.onap.appc.seqgen.objects.Constants.WAIT_TIME_VALUE;;
public class StartSequenceGenerator implements SequenceGenerator {
@@ -47,27 +67,27 @@ public class StartSequenceGenerator implements SequenceGenerator {
List<Transaction> transactionList = new LinkedList<>();
Integer transactionId = 1;
- List<Vnfc> invVnfcList = input.getInventoryModel().getVnf().getVnfcs();
- boolean singleTransaction=checkSingleTransaction(invVnfcList);
- for (Vnfc vnfc : invVnfcList) {
- List<Vserver> vms = vnfc.getVserverList();
- List<Integer> transactionIds = new LinkedList<>();
- for (Vserver vm : vms) {
- Transaction transaction = new Transaction();
- transaction.setTransactionId(transactionId);
- transactionIds.add(transactionId++);
- transaction.setAction(Action.START.getActionType());
- transaction.setActionLevel(ActionLevel.VM.getAction());
- ActionIdentifier actionIdentifier = new ActionIdentifier();
- actionIdentifier.setvServerId(vm.getId());
- transaction.setActionIdentifier(actionIdentifier);
- transaction.setPayload(input.getRequestInfo().getPayload());
- if(!singleTransaction){
- updateResponse(transaction);
- }
-
- transactionList.add(transaction);
+ List<Vserver> vservers = input.getInventoryModel().getVnf().getVservers();
+ List<Integer> transactionIds = new LinkedList<>();
+ for (Vserver vm : vservers) {
+ Transaction transaction = new Transaction();
+ transaction.setTransactionId(transactionId);
+ transactionIds.add(transactionId++);
+ transaction.setAction(Action.START.getActionType());
+ transaction.setActionLevel(ActionLevel.VM.getAction());
+ ActionIdentifier actionIdentifier = new ActionIdentifier();
+ actionIdentifier.setvServerId(vm.getId());
+ transaction.setActionIdentifier(actionIdentifier);
+ transaction.setPayload(input.getRequestInfo().getPayload());
+ if(vservers.size()>1){
+ Response ignoreResponse = new Response();
+ ignoreResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse());
+ Map<String, String> ignoreAction = new HashMap<>();
+ ignoreAction.put(ResponseAction.IGNORE.getAction(), Boolean.TRUE.toString());
+ ignoreResponse.setResponseAction(ignoreAction);
+ transaction.addResponse(ignoreResponse);
}
+ transactionList.add(transaction);
}
return transactionList;
}
@@ -112,7 +132,12 @@ public class StartSequenceGenerator implements SequenceGenerator {
actionIdentifier.setvServerId(vm.getId());
transaction.setActionIdentifier(actionIdentifier);
transaction.setPayload(input.getRequestInfo().getPayload());
- updateResponse(transaction);
+ Response ignoreResponse = new Response();
+ ignoreResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse());
+ Map<String, String> ignoreAction = new HashMap<>();
+ ignoreAction.put(ResponseAction.IGNORE.getAction(), Boolean.TRUE.toString());
+ ignoreResponse.setResponseAction(ignoreAction);
+ transaction.addResponse(ignoreResponse);
transactionList.add(transaction);
}
boolean startApplicationSupported = readApplicationStartCapability(input);
@@ -126,10 +151,7 @@ public class StartSequenceGenerator implements SequenceGenerator {
startAppTransaction.setActionIdentifier(startActionIdentifier);
startAppTransaction.setPayload(input.getRequestInfo().getPayload());
- List<PreCheckOption> preCheckOptions = new LinkedList<>();
- for (Integer vmTransactionId : transactionIds) {
- setPreCheckOptions(preCheckOptions, vmTransactionId);
- }
+ List<PreCheckOption> preCheckOptions = buildPreCheckOptions(transactionIds);
startAppTransaction.setPreCheckOperator(PreCheckOperator.ANY.getOperator());
startAppTransaction.setPrecheckOptions(preCheckOptions);
transactionList.add(startAppTransaction);
@@ -174,32 +196,42 @@ public class StartSequenceGenerator implements SequenceGenerator {
return transactionList;
}
- private void setPreCheckOptions(List<PreCheckOption> preCheckOptions, Integer vmTransactionId) {
- PreCheckOption option = new PreCheckOption();
- option.setPreTransactionId(vmTransactionId);
- option.setParamName("status");
- option.setParamValue("success");
- preCheckOptions.add(option);
+ private List<PreCheckOption> buildPreCheckOptions(List<Integer> transactionIds) {
+ List<PreCheckOption> preCheckOptions = new LinkedList<>();
+ for (Integer vmTransactionId : transactionIds) {
+ PreCheckOption option = new PreCheckOption();
+ option.setPreTransactionId(vmTransactionId);
+ option.setParamName("status");
+ option.setParamValue("success");
+ preCheckOptions.add(option);
+ }
+ return preCheckOptions;
}
@Override
public List<Transaction> generateSequence(SequenceGeneratorInput input) throws APPCException {
- if(input.getRequestInfo().getActionLevel().equals(ActionLevel.VM.getAction())||input.getRequestInfo().getActionLevel().equals(ActionLevel.VNFC.getAction())||
- input.getRequestInfo().getActionLevel().equals(ActionLevel.VNF.getAction())||input.getRequestInfo().getActionLevel().equals(ActionLevel.VF_MODULE.getAction())) {
if (input.getRequestInfo().getActionLevel().equals(ActionLevel.VNF.getAction()) && input.getDependencyModel() != null) {
- FlowStrategies flowStrategy = readStartFlowStrategy(input);
- VnfcFlowModel flowModel = buildFlowModel(input.getInventoryModel()
- , input.getDependencyModel(), flowStrategy);
- logger.debug("Flow Model " + flowModel);
- return generateSequenceWithDependencyModel(flowModel, input);
+ if(isVnfcPresent(input)) {
+ FlowStrategies flowStrategy = readFlowStrategy(input);
+ VnfcFlowModel flowModel = null;
+ try {
+ flowModel = buildFlowModel(input.getInventoryModel()
+ , input.getDependencyModel(), flowStrategy);
+ } catch (InvalidDependencyModelException invalidDependencyModelException) {
+ logger.error("Error Generating Sequence", invalidDependencyModelException);
+ throw new APPCException(invalidDependencyModelException.getMessage(), invalidDependencyModelException);
+ }
+ logger.debug("Flow Model " + flowModel);
+ return generateSequenceWithDependencyModel(flowModel, input);
+ }
+ else throw new APPCException("Vnfc details is missing in the input");
} else {
logger.info("Generating sequence without dependency model");
return generateSequenceWithOutDependency(input);
}
- }throw new APPCException("Invalid action level "+input.getRequestInfo().getActionLevel());
}
- private VnfcFlowModel buildFlowModel(InventoryModel inventoryModel, VnfcDependencyModel dependencyModel, FlowStrategies flowStrategy) throws APPCException {
+ private VnfcFlowModel buildFlowModel(InventoryModel inventoryModel, VnfcDependencyModel dependencyModel, FlowStrategies flowStrategy) throws APPCException, InvalidDependencyModelException {
FlowBuilder flowBuilder = FlowBuilderFactory.getInstance().getFlowBuilder(flowStrategy);
if (flowBuilder == null) {
throw new APPCException("Flow Strategy not supported " + flowStrategy);
@@ -207,22 +239,17 @@ public class StartSequenceGenerator implements SequenceGenerator {
return flowBuilder.buildFlowModel(dependencyModel, inventoryModel);
}
- private FlowStrategies readStartFlowStrategy(SequenceGeneratorInput sequenceGeneratorInput) throws APPCException {
+ private FlowStrategies readFlowStrategy(SequenceGeneratorInput sequenceGeneratorInput) {
Map<String, String> tunableParams = sequenceGeneratorInput.getTunableParams();
- FlowStrategies strategy;
+ FlowStrategies strategy=null;
String strategyStr = null;
if (tunableParams != null) {
strategyStr = tunableParams.get(Constants.STRATEGY);
- if (StringUtils.isBlank(strategyStr)) {
- return FlowStrategies.FORWARD;
- }
-
strategy = FlowStrategies.findByString(strategyStr);
- if (strategy != null) {
- return strategy;
- }
}
- throw new APPCException("Invalid Strategy " + strategyStr);
+ if (strategy == null)
+ strategy= FlowStrategies.FORWARD;
+ return strategy;
}
private boolean readHealthCheckCapabilites(Map<String, List<String>> capabilities) {
@@ -259,6 +286,17 @@ public class StartSequenceGenerator implements SequenceGenerator {
}
}
+ private boolean isVnfcPresent(SequenceGeneratorInput input){
+ boolean vnfcPresent=true;
+ List<Vserver> vservers = input.getInventoryModel().getVnf().getVservers();
+ for (Vserver vm : vservers) {
+ if(!(vm.getVnfc()!=null&& vm.getVnfc().getVnfcType()!=null&& vm.getVnfc().getVnfcName()!=null)){
+ vnfcPresent=false;break;
+ }
+ }
+ return vnfcPresent;
+ }
+
private Integer readWaitTime(SequenceGeneratorInput input) throws APPCException {
String paramValStr = input.getTunableParams().get(WAIT_TIME);
if (StringUtils.isEmpty(paramValStr)) {
diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StopSequenceGenerator.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StopSequenceGenerator.java
index 77bee6b83..dcbdd8949 100644
--- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StopSequenceGenerator.java
+++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StopSequenceGenerator.java
@@ -23,6 +23,7 @@ package org.onap.appc.seqgen.impl;
import org.apache.commons.lang3.StringUtils;
import org.onap.appc.dg.flowbuilder.FlowBuilder;
import org.onap.appc.dg.flowbuilder.impl.FlowBuilderFactory;
+import org.onap.appc.dg.flowbuilder.exception.InvalidDependencyModelException;
import org.onap.appc.dg.objects.FlowStrategies;
import org.onap.appc.dg.objects.InventoryModel;
import org.onap.appc.dg.objects.VnfcDependencyModel;
@@ -31,77 +32,78 @@ import org.onap.appc.domainmodel.Vnfc;
import org.onap.appc.domainmodel.Vserver;
import org.onap.appc.exceptions.APPCException;
import org.onap.appc.seqgen.SequenceGenerator;
-import org.onap.appc.seqgen.objects.*;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
+import org.onap.appc.seqgen.objects.ActionIdentifier;
+import org.onap.appc.seqgen.objects.Constants;
+import org.onap.appc.seqgen.objects.Response;
+import org.onap.appc.seqgen.objects.SequenceGeneratorInput;
+import org.onap.appc.seqgen.objects.Transaction;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
-import static org.onap.appc.seqgen.objects.Constants.*;
+import static org.onap.appc.seqgen.objects.Constants.Action;
+import static org.onap.appc.seqgen.objects.Constants.ActionLevel;
+import static org.onap.appc.seqgen.objects.Constants.ResponseAction;
+import static org.onap.appc.seqgen.objects.Constants.ResponseMessage;
+import static org.onap.appc.seqgen.objects.Constants.Capabilties;
public class StopSequenceGenerator implements SequenceGenerator {
- private static final EELFLogger logger = EELFManager.getInstance().getLogger(StartSequenceGenerator.class);
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(StopSequenceGenerator.class);
@Override
public List<Transaction> generateSequence(SequenceGeneratorInput input) throws APPCException {
- if(input.getRequestInfo().getActionLevel().equals(ActionLevel.VM.getAction())||input.getRequestInfo().getActionLevel().equals(ActionLevel.VNFC.getAction())||
- input.getRequestInfo().getActionLevel().equals(ActionLevel.VNF.getAction())||input.getRequestInfo().getActionLevel().equals(ActionLevel.VF_MODULE.getAction())) {
- if (input.getRequestInfo().getActionLevel().equals(ActionLevel.VNF.getAction()) && input.getDependencyModel() != null) {
- FlowStrategies flowStrategy = readStopFlowStrategy(input);
- VnfcFlowModel flowModel = buildFlowModel(input.getInventoryModel()
- , input.getDependencyModel(), flowStrategy);
+ if (input.getRequestInfo().getActionLevel().equals(ActionLevel.VNF.getAction()) && input.getDependencyModel() != null ) {
+ if(isVnfcPresent(input)) {
+ FlowStrategies flowStrategy = readFlowStrategy(input);
+ VnfcFlowModel flowModel = null;
+ try {
+ flowModel = buildFlowModel(input.getInventoryModel(), input.getDependencyModel(), flowStrategy);
+ } catch (InvalidDependencyModelException invalidDependencyModelException) {
+ logger.error("Error Generating Sequence", invalidDependencyModelException);
+ throw new APPCException(invalidDependencyModelException.getMessage(), invalidDependencyModelException);
+ }
logger.debug("Flow Model " + flowModel);
return generateSequenceWithDependencyModel(flowModel, input);
+ }
+ else throw new APPCException("Vnfc details missing in the input");
} else {
logger.info("Generating sequence without dependency model");
return generateSequenceWithOutDependency(input);
}
- }throw new APPCException("Invalid action level "+input.getRequestInfo().getActionLevel());
-
}
+
private List<Transaction> generateSequenceWithOutDependency(SequenceGeneratorInput input){
List<Transaction> transactionList = new LinkedList<>();
Integer transactionId = 1;
+ List<Vserver> vservers = input.getInventoryModel().getVnf().getVservers();
List<Integer> transactionIds = new LinkedList<>();
- List<Vnfc> invVnfcList = input.getInventoryModel().getVnf().getVnfcs();
- boolean singleTransaction=checkSingleTransaction(invVnfcList);
- for (Vnfc vnfc : invVnfcList) {
- List<Vserver> vms = vnfc.getVserverList();
- for(Vserver vm:vms){
- Transaction transaction = new Transaction();
- transaction.setTransactionId(transactionId);
- transactionIds.add(transactionId++);
- transaction.setAction(Action.STOP.getActionType());
- transaction.setActionLevel(ActionLevel.VM.getAction());
- ActionIdentifier actionIdentifier = new ActionIdentifier();
- actionIdentifier.setvServerId(vm.getId());
- transaction.setActionIdentifier(actionIdentifier);
- transaction.setPayload(input.getRequestInfo().getPayload());
- if(!singleTransaction){
- updateStopResponse(transaction);
- }
- transactionList.add(transaction);
- }
+ for (Vserver vm : vservers) {
+ Transaction transaction = new Transaction();
+ transaction.setTransactionId(transactionId);
+ transactionIds.add(transactionId++);
+ transaction.setAction(Action.STOP.getActionType());
+ transaction.setActionLevel(ActionLevel.VM.getAction());
+ ActionIdentifier actionIdentifier = new ActionIdentifier();
+ actionIdentifier.setvServerId(vm.getId());
+ transaction.setActionIdentifier(actionIdentifier);
+ transaction.setPayload(input.getRequestInfo().getPayload());
+ if(vservers.size()>1){
+ Response failureResponse = new Response();
+ failureResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse());
+ Map<String,String> failureAction = new HashMap<>();
+ failureAction.put(ResponseAction.IGNORE.getAction(),Boolean.TRUE.toString());
+ failureResponse.setResponseAction(failureAction);
+ transaction.addResponse(failureResponse);
}
- return transactionList;
- }
-
- private void updateStopResponse(Transaction transaction) {
- Response failureResponse = new Response();
- failureResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse());
- Map<String,String> failureAction = new HashMap<>();
- failureAction.put(ResponseAction.IGNORE.getAction(),Boolean.TRUE.toString());
- failureResponse.setResponseAction(failureAction);
- transaction.addResponse(failureResponse);
- }
- private boolean checkSingleTransaction(List<Vnfc> invVnfcList) {
- int vServerCount=0;
- for(Vnfc vnfc : invVnfcList) {
- List<Vserver> vms = vnfc.getVserverList();
- vServerCount=vServerCount+vms.size();
- }
- return vServerCount <= 1;
+ transactionList.add(transaction);
+ }
+ return transactionList;
}
private List<Transaction> generateSequenceWithDependencyModel(VnfcFlowModel flowModel,SequenceGeneratorInput input){
@@ -122,7 +124,12 @@ public class StopSequenceGenerator implements SequenceGenerator {
stopActionIdentifier .setVnfcName(vnfc.getVnfcName());
stopAppTransaction.setActionIdentifier(stopActionIdentifier );
stopAppTransaction.setPayload(input.getRequestInfo().getPayload());
- updateStopResponse(stopAppTransaction);
+ Response failureResponse = new Response();
+ failureResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse());
+ Map<String,String> failureAction = new HashMap<>();
+ failureAction.put(ResponseAction.IGNORE.getAction(),Boolean.TRUE.toString());
+ failureResponse.setResponseAction(failureAction);
+ stopAppTransaction.addResponse(failureResponse);
transactionList.add(stopAppTransaction);
}
List<Vserver> vms = vnfc.getVserverList();
@@ -136,8 +143,12 @@ public class StopSequenceGenerator implements SequenceGenerator {
actionIdentifier.setvServerId(vm.getId());
transaction.setActionIdentifier(actionIdentifier);
transaction.setPayload(input.getRequestInfo().getPayload());
-
- updateStopResponse(transaction);
+ Response failureResponse = new Response();
+ failureResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse());
+ Map<String,String> failureAction = new HashMap<>();
+ failureAction.put(ResponseAction.IGNORE.getAction(),Boolean.TRUE.toString());
+ failureResponse.setResponseAction(failureAction);
+ transaction.addResponse(failureResponse);
transactionList.add(transaction);
}
}
@@ -145,7 +156,7 @@ public class StopSequenceGenerator implements SequenceGenerator {
return transactionList;
}
- private VnfcFlowModel buildFlowModel(InventoryModel inventoryModel, VnfcDependencyModel dependencyModel, FlowStrategies flowStrategy) throws APPCException {
+ private VnfcFlowModel buildFlowModel(InventoryModel inventoryModel, VnfcDependencyModel dependencyModel, FlowStrategies flowStrategy) throws APPCException, InvalidDependencyModelException {
FlowBuilder flowBuilder = FlowBuilderFactory.getInstance().getFlowBuilder(flowStrategy);
if (flowBuilder == null) {
throw new APPCException("Flow Strategy not supported " + flowStrategy);
@@ -153,22 +164,30 @@ public class StopSequenceGenerator implements SequenceGenerator {
return flowBuilder.buildFlowModel(dependencyModel, inventoryModel);
}
- private FlowStrategies readStopFlowStrategy(SequenceGeneratorInput sequenceGeneratorInput) throws APPCException {
+ private FlowStrategies readFlowStrategy(SequenceGeneratorInput sequenceGeneratorInput) {
Map<String, String> tunableParams = sequenceGeneratorInput.getTunableParams();
- FlowStrategies strategy;
+ FlowStrategies strategy = null;
String strategyStr = null;
if (tunableParams != null) {
strategyStr = tunableParams.get(Constants.STRATEGY);
- if (StringUtils.isBlank(strategyStr)) {
- return FlowStrategies.REVERSE;
- }
strategy = FlowStrategies.findByString(strategyStr);
- if (strategy != null) {
- return strategy;
+ }
+ if (strategy == null)
+ strategy= FlowStrategies.REVERSE;
+ return strategy;
+ }
+
+ private boolean isVnfcPresent(SequenceGeneratorInput input){
+ boolean vnfcPresent=true;
+ List<Vserver> vservers = input.getInventoryModel().getVnf().getVservers();
+ for (Vserver vm : vservers) {
+ if(!(vm.getVnfc()!=null&& vm.getVnfc().getVnfcType()!=null&& vm.getVnfc().getVnfcName()!=null)){
+ vnfcPresent=false;break;
}
}
- throw new APPCException("Invalid Strategy " + strategyStr);
+ return vnfcPresent;
}
+
private boolean readApplicationStopCapability(SequenceGeneratorInput input) {
Map<String,List<String>> capability = input.getCapability();
if(capability!= null){
diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/Constants.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/Constants.java
index 476c5b718..c648c973c 100644
--- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/Constants.java
+++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/Constants.java
@@ -67,7 +67,7 @@ public class Constants {
}
public enum ResponseAction{
- STOP("stop"),RETRY("retry"),IGNORE("ignore"),WAIT("wait"),CONTINUE("Continue");
+ STOP("stop"),RETRY("retry"),IGNORE("ignore"),WAIT("wait"),CONTINUE("Continue"),JUMP("jump");
ResponseAction(String action) {
this.action=action;
@@ -101,9 +101,18 @@ public class Constants {
ActionLevel(String action){
this.action=action;
}
+
public String getAction() {
return action;
}
+
+ public static ActionLevel findByString(String actoinLevel) {
+ for (ActionLevel acnlevel : ActionLevel.values()) {
+ if (acnlevel.name().equals(actoinLevel))
+ return acnlevel;
+ }
+ return null;
+ }
}
public enum PreCheckOperator{
diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/provider/SequenceGeneratorProvider.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/provider/SequenceGeneratorProvider.java
index ad9a68705..26e9f899a 100644
--- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/provider/SequenceGeneratorProvider.java
+++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/provider/SequenceGeneratorProvider.java
@@ -46,14 +46,26 @@ 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.*;
-
-import java.util.*;
+import org.onap.appc.seqgen.objects.Constants;
+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 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;
@@ -100,6 +112,9 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
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);
@@ -113,33 +128,12 @@ 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){
- 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);
- }
- }
-
+ ActionIdentifier actionIdentifier = buildActionIdentifierForResponse(transaction);
+ List<PrecheckOptions> precheckOptions = buildPrecheckOptionsForResponse(transaction);
List<Responses> responseList = getResponses(transaction);
-
Transactions transactionObj
= new TransactionsBuilder()
.setActionIdentifier(actionIdentifier)
@@ -162,6 +156,35 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
.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) {
List<Responses> responseList = new LinkedList<>();
for(Response resp : transaction.getResponses()){
@@ -183,6 +206,9 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
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())
@@ -194,32 +220,43 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
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);
+ }
SequenceGeneratorInputBuilder builder = new SequenceGeneratorInputBuilder()
.requestInfo(requestInfo)
.inventoryModel(inventoryModel)
.dependendcyModel(dependencyModel);
+ builder = buildCapabilitiesForSeqGenInput(input, builder);
+
+ builder = buildTunableParamsForSeqGenInput(input, builder);
+
+ 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;
+ }
+
+ private SequenceGeneratorInputBuilder buildCapabilitiesForSeqGenInput(GenerateSequenceInput input, SequenceGeneratorInputBuilder builder) {
+ log.info("Initializing capabilities based on YANG object.");
if(input.getCapabilities() !=null){
if(input.getCapabilities().getVnf()!=null){
builder = builder.capability("vnf",input.getCapabilities().getVnf());
@@ -235,16 +272,73 @@ 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());
+ return builder;
+ }
+
+ 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());
}
}
- return builder.build();
+
+ 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);
+ }
+ }
+ }
+
+ 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){
@@ -256,30 +350,39 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
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) {
+ 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<>();
+ Set<String> parentVnfcs=new HashSet<>();
+ Set<String> allVnfcTypes=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());
- }
+ 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()){
- Node<org.onap.appc.domainmodel.Vnfc> parentNode = readNode(parentVnfcType,dependencies);
+ 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);
@@ -289,9 +392,27 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
}
}
}
+ 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)){
@@ -302,40 +423,52 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
}
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);
+ }
+
+ 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());
+ 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());
+ return vnf;
}
private RpcResult<GenerateSequenceOutput> buildFailureResponse(String errorMessage){