aboutsummaryrefslogtreecommitdiffstats
path: root/appc-sequence-generator/appc-sequence-generator-bundle/src/main
diff options
context:
space:
mode:
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.java84
-rw-r--r--appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/RestartSequenceGenerator.java64
-rw-r--r--appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StartSequenceGenerator.java87
-rw-r--r--appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StopSequenceGenerator.java65
-rw-r--r--appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/CapabilityModel.java45
-rw-r--r--appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/Constants.java14
-rw-r--r--appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/SequenceGeneratorInput.java14
-rw-r--r--appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/SequenceGeneratorInputBuilder.java18
-rw-r--r--appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/provider/SequenceGeneratorProvider.java62
9 files changed, 372 insertions, 81 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 a53c408e8..111085e18 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
@@ -42,7 +42,9 @@ import org.onap.appc.exceptions.APPCException;
import org.onap.appc.seqgen.SequenceGenerator;
import org.onap.appc.seqgen.dgplugin.SequenceGeneratorPlugin;
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.ActionLevel;
import org.onap.appc.seqgen.objects.SequenceGeneratorInput;
import org.onap.appc.seqgen.objects.Transaction;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
@@ -51,7 +53,9 @@ import java.io.IOException;
import java.util.Map;
import java.util.List;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Set;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
@@ -67,10 +71,15 @@ public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin {
try {
SequenceGeneratorInput sequenceGeneratorInput = buildSequenceGeneratorInput(inputJSON);
List<Transaction> sequence = generateSequence(sequenceGeneratorInput);
- String output = objectMapper.writeValueAsString(sequence);
- logger.debug("Sequence Generator Output " + output);
-
- context.setAttribute("output", output);
+ if (sequence.isEmpty()) {
+ logger.error("Error generating sequence");
+ context.setAttribute("error-code", "450");
+ context.setAttribute("error-message", "Request is not supported");
+ } else {
+ String output = objectMapper.writeValueAsString(sequence);
+ logger.debug("Sequence Generator Output " + output);
+ context.setAttribute("output", output);
+ }
} catch (Exception e) {
logger.error("Error generating sequence", e);
context.setAttribute("error-code", "401");
@@ -89,13 +98,16 @@ public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin {
sequenceGeneratorInput.setInventoryModel(inventoryModel);
VnfcDependencyModel dependencyModel = buildDependencyModel(inputJson);
- if(dependencyModel!=null){
+ if(dependencyModel != null){
validateInventoryModelWithDependencyModel(dependencyModel,inventoryModel);
}
sequenceGeneratorInput.setDependencyModel(dependencyModel);
+ CapabilityModel capModel = buildCapabilitiesModel(inputJson);
+ sequenceGeneratorInput.setCapabilityModel(capModel);
return sequenceGeneratorInput;
}
+
private List<Transaction> generateSequence(SequenceGeneratorInput sequenceGeneratorInput) throws Exception {
if (sequenceGeneratorInput.getRequestInfo() == null) {
throw new APPCException("Request info is not provided in the input");
@@ -286,6 +298,7 @@ public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin {
Vnfc vfc = new Vnfc();
vfc.setVnfcType(vm.get("vnfc").get("vnfc-type").asText());
vfc.setVnfcName(vm.get("vnfc").get("vnfc-name").asText());
+ vfc.setVnfcFunctionCode(vm.get("vnfc").get("vnfc-function-code").asText());
vserver.setVnfc(vfc);
List<Vserver> vServers = vfcs.get(vfc);
if (vServers == null) {
@@ -305,4 +318,65 @@ public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin {
return new InventoryModel(vnf);
}
+ private CapabilityModel buildCapabilitiesModel(String inputJson) throws IOException, APPCException {
+ logger.info("Entering buildCapabilitiesModel");
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ JsonNode jsonNode = objectMapper.readTree(inputJson);
+ JsonNode capabilitiesNode = jsonNode.get("capabilities");
+ if (capabilitiesNode == null) {
+ return null;
+ }
+
+ List<String> vnfCapabilities = new ArrayList<>();
+ List<String> vfModuleCapabilities = new ArrayList<>();
+ Map<String, List<String>> vmCapabilities = new HashMap<>();
+ List<String> vnfcCapabilities = new ArrayList<>();
+
+ JsonNode vnfNode = capabilitiesNode.get(ActionLevel.VNF.getAction());
+ JsonNode vfModuleNode = capabilitiesNode.get(ActionLevel.VF_MODULE.getAction());
+ JsonNode vmNode = capabilitiesNode.get(ActionLevel.VM.getAction());
+ JsonNode vnfcNode = capabilitiesNode.get(ActionLevel.VNFC.getAction());
+
+ if (vnfNode != null && vnfNode.isArray() ) {
+ for (JsonNode nodes : vnfNode) {
+ vnfCapabilities.add(nodes.asText());
+ }
+ }
+ if (vfModuleNode != null && vfModuleNode.isArray() ){
+ for (JsonNode nodes : vfModuleNode) {
+ vfModuleCapabilities.add(nodes.asText());
+ }
+ }
+ if (vmNode != null && vmNode.isArray() ){
+ for (JsonNode jNode : vmNode) {
+ logger.debug("jNode=" + jNode);
+ Iterator<Map.Entry<String,JsonNode>> fldIter = jNode.fields();
+ while (fldIter.hasNext()) {
+ Map.Entry<String,JsonNode> currentEntry = fldIter.next();
+ logger.debug("currentEntry.getKey()=" + currentEntry.getKey());
+ logger.debug("currentEntry.getValue()=" + currentEntry.getValue());
+ if (currentEntry.getValue().isArray()) {
+ logger.debug("currentEntry.getValue().isArray() is true");
+ List<String> ls = new ArrayList<String>();
+ for (JsonNode node: currentEntry.getValue()) {
+ ls.add(node.asText());
+ }
+ vmCapabilities.put(currentEntry.getKey(), ls);
+ }
+ }
+ }
+ }
+ if (vnfcNode != null && vnfcNode.isArray() ){
+ for (JsonNode nodes : vnfcNode) {
+ vnfcCapabilities.add(nodes.asText());
+ }
+ }
+ logger.info("vnfCapabilities=" + vnfCapabilities);
+ logger.info("vfModuleCapabilities=" + vfModuleCapabilities);
+ logger.info("vmCapabilities=" + vmCapabilities);
+ logger.info("vnfcCapabilities=" + vnfcCapabilities);
+
+ return new CapabilityModel(vnfCapabilities, vfModuleCapabilities, vmCapabilities, vnfcCapabilities);
+ }
}
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
index 5ab0b5408..2f5080d0b 100644
--- 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
@@ -31,6 +31,7 @@ import org.onap.appc.domainmodel.Vserver;
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.Constants.Action;
import org.onap.appc.seqgen.objects.Response;
import org.onap.appc.seqgen.objects.SequenceGeneratorInput;
import org.onap.appc.seqgen.objects.Transaction;
@@ -57,6 +58,11 @@ public class RestartSequenceGenerator implements SequenceGenerator{
List<Integer> transactionIds = new LinkedList<>();
PayloadGenerator payloadGenerator = new PayloadGenerator();
for (Vserver vm : vservers) {
+ // check vm-Restart-capabilities for this vm's vnfc-function-code (before incrementing transactionId)
+ String vmVnfcFunctionCode = vm.getVnfc().getVnfcFunctionCode();
+ if (!vmSupportsRestart(input, vmVnfcFunctionCode)) {
+ continue;
+ }
Transaction transactionStop = new Transaction();
transactionStop.setTransactionId(transactionId);
transactionIds.add(transactionId++);
@@ -73,12 +79,12 @@ public class RestartSequenceGenerator implements SequenceGenerator{
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));
+ //if(!checkLastVM(vservers,vm.getId()))
+ //{
+ failureAction.put(Constants.ResponseAction.STOP.getAction(), String.valueOf(transactionId+1));
failureResponse.setResponseAction(failureAction);
transactionStop.addResponse(failureResponse);
- }
+ //}
}
transactionList.add(transactionStop);
Transaction transactionStart = new Transaction();
@@ -95,20 +101,58 @@ public class RestartSequenceGenerator implements SequenceGenerator{
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());
+ //if(!checkLastVM(vservers,vm.getId()))
+ //{
+ //failureAction.put(Constants.ResponseAction.JUMP.getAction(),transactionId.toString());
+ failureAction.put(Constants.ResponseAction.STOP.getAction(),transactionId.toString());
failureResponse.setResponseAction(failureAction);
transactionStart.addResponse(failureResponse);
- }
+ //}
}
transactionList.add(transactionStart);
}
return transactionList;
}
+
+ private boolean vmSupportsRestart(SequenceGeneratorInput input, String vnfcFunctionCode) {
+ boolean vmSupported = true;
+ if (input.getCapability() == null) {
+ logger.info("vmSupportsRestart: " + "Capabilities model is null, returning vmSupported=" + vmSupported);
+ return vmSupported;
+ }
+ Map<String, List<String>> vmCapabilities = input.getCapability().getVmCapabilities();
+ logger.info("vmSupportsRestart: vnfcFunctionCode=" + vnfcFunctionCode + ", vmCapabilities=" + vmCapabilities);
+ if (vmCapabilities != null) {
+ if (!vmCapabilities.isEmpty()) {
+ vmSupported = false;
+ if (vmCapabilities.get(Action.RESTART.getActionType()) != null) {
+ if (vnfcFunctionCode != null && !vnfcFunctionCode.isEmpty()) {
+ for (String enabledFuncCode : vmCapabilities.get(Action.RESTART.getActionType()) ) {
+ if (enabledFuncCode.equalsIgnoreCase(vnfcFunctionCode)) {
+ vmSupported = true;
+ logger.info("vmSupportsRestart: vnfcFunctionCode=" + vnfcFunctionCode + " found in vmCapabilties");
+ break;
+ }
+ }
+ } else {
+ logger.info("vmSupportsRestart: " + "Inventory vnfcFunctionCode is null or empty");
+ }
+ } else {
+ logger.info("vmSupportsRestart: " + "Given action in vm entry in Capabilities model is null");
+ }
+ } else {
+ logger.info("vmSupportsRestart: " + "Vm entry in Capabilities model is empty");
+ }
+ } else {
+ logger.info("vmSupportsRestart: " + "Vm entry in Capabilities model is null");
+ }
+
+ logger.info("vmSupportsRestart: " + "returning vmSupported=" + vmSupported);
+ return vmSupported;
+ }
- private boolean checkLastVM(List<Vserver> vservers, String vmId){
+ private boolean checkLastVM(List<Vserver> vservers, String vmId){
Vserver vm= vservers.get(vservers.size()-1);
return vm.getId().equals(vmId);
}
-}
+} \ No newline at end of file
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 8c24fe24c..105173f33 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
@@ -39,6 +39,7 @@ 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.CapabilityModel;
import org.onap.appc.seqgen.objects.Constants;
import org.onap.appc.seqgen.objects.PreCheckOption;
import org.onap.appc.seqgen.objects.Response;
@@ -76,6 +77,11 @@ public class StartSequenceGenerator implements SequenceGenerator {
List<Vserver> vservers = input.getInventoryModel().getVnf().getVservers();
List<Integer> transactionIds = new LinkedList<>();
for (Vserver vm : vservers) {
+ // check vm-Start-capabilities for this vm's vnfc-function-code (before incrementing transactionId)
+ String vmVnfcFunctionCode = vm.getVnfc().getVnfcFunctionCode();
+ if (!vmSupportsStart(input, vmVnfcFunctionCode)) {
+ continue;
+ }
Transaction transaction = new Transaction();
transaction.setTransactionId(transactionId);
transactionIds.add(transactionId++);
@@ -92,7 +98,7 @@ public class StartSequenceGenerator implements SequenceGenerator {
Response ignoreResponse = new Response();
ignoreResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse());
Map<String, String> ignoreAction = new HashMap<>();
- ignoreAction.put(ResponseAction.IGNORE.getAction(), Boolean.TRUE.toString());
+ ignoreAction.put(ResponseAction.STOP.getAction(), Boolean.TRUE.toString());
ignoreResponse.setResponseAction(ignoreAction);
transaction.addResponse(ignoreResponse);
}
@@ -114,7 +120,7 @@ public class StartSequenceGenerator implements SequenceGenerator {
Response ignoreResponse = new Response();
ignoreResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse());
Map<String, String> ignoreAction = new HashMap<>();
- ignoreAction.put(ResponseAction.IGNORE.getAction(), Boolean.TRUE.toString());
+ ignoreAction.put(ResponseAction.STOP.getAction(), Boolean.TRUE.toString());
ignoreResponse.setResponseAction(ignoreAction);
transaction.addResponse(ignoreResponse);
}
@@ -132,6 +138,11 @@ public class StartSequenceGenerator implements SequenceGenerator {
List<Integer> transactionIds = new LinkedList<>();
if(!vms.isEmpty()) {
for (Vserver vm : vms) {
+ // check vm-Start-capabilities for this vm's vnfc-function-code (before incrementing transactionId)
+ String vmVnfcFunctionCode = vm.getVnfc().getVnfcFunctionCode();
+ if (!vmSupportsStart(input, vmVnfcFunctionCode)) {
+ continue;
+ }
Transaction transaction = new Transaction();
transaction.setTransactionId(transactionId);
transactionIds.add(transactionId++);
@@ -144,7 +155,7 @@ public class StartSequenceGenerator implements SequenceGenerator {
Response ignoreResponse = new Response();
ignoreResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse());
Map<String, String> ignoreAction = new HashMap<>();
- ignoreAction.put(ResponseAction.IGNORE.getAction(), Boolean.TRUE.toString());
+ ignoreAction.put(ResponseAction.STOP.getAction(), Boolean.TRUE.toString());
ignoreResponse.setResponseAction(ignoreAction);
transaction.addResponse(ignoreResponse);
transactionList.add(transaction);
@@ -261,23 +272,27 @@ public class StartSequenceGenerator implements SequenceGenerator {
return strategy;
}
- private boolean readHealthCheckCapabilites(Map<String, List<String>> capabilities) {
- if (capabilities != null) {
- List<String> vnfcCapabilities = capabilities.get(CapabilityLevel.VNFC.getLevel());
- if (vnfcCapabilities != null)
- return vnfcCapabilities.stream()
- .anyMatch(p -> Capabilties.HEALTH_CHECK.getCapability().equalsIgnoreCase(p));
+ private boolean readHealthCheckCapabilites(CapabilityModel capabilities) {
+ if (capabilities == null) {
+ return true;
}
+ List<String> vnfcCapabilities = capabilities.getVnfcCapabilities();
+ if (vnfcCapabilities != null)
+ return vnfcCapabilities.stream()
+ .anyMatch(p -> Capabilties.HEALTH_CHECK.getCapability().equalsIgnoreCase(p));
+
return false;
}
private boolean readApplicationStartCapability(SequenceGeneratorInput input) {
- Map<String, List<String>> capability = input.getCapability();
- if (capability != null) {
- List<String> vnfcCapabilities = capability.get(CapabilityLevel.VNFC.getLevel());
- if (vnfcCapabilities != null)
- return vnfcCapabilities.stream().anyMatch(p -> Capabilties.START_APPLICATION.getCapability().equalsIgnoreCase(p));
- }
+ CapabilityModel capability = input.getCapability();
+ if (capability == null)
+ return true;
+ List<String> vnfcCapabilities = capability.getVnfcCapabilities();
+ if (vnfcCapabilities != null)
+ return vnfcCapabilities.stream()
+ .anyMatch(p -> Capabilties.START_APPLICATION.getCapability().equalsIgnoreCase(p));
+
return false;
}
@@ -300,7 +315,8 @@ public class StartSequenceGenerator implements SequenceGenerator {
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;
+ vnfcPresent=false;
+ break;
}
}
return vnfcPresent;
@@ -319,4 +335,41 @@ public class StartSequenceGenerator implements SequenceGenerator {
throw new APPCException(message);
}
}
-}
+
+ private boolean vmSupportsStart(SequenceGeneratorInput input, String vnfcFunctionCode) {
+ boolean vmSupported = true;
+ if (input.getCapability() == null) {
+ logger.info("vmSupportsStart: " + "Capabilities model is null, returning vmSupported=" + vmSupported);
+ return vmSupported;
+ }
+ Map<String, List<String>> vmCapabilities = input.getCapability().getVmCapabilities();
+ logger.info("vmSupportsStart: vnfcFunctionCode=" + vnfcFunctionCode + ", vmCapabilities=" + vmCapabilities);
+ if (vmCapabilities != null) {
+ if (!vmCapabilities.isEmpty()) {
+ vmSupported = false;
+ if (vmCapabilities.get(Action.START.getActionType()) != null) {
+ if (vnfcFunctionCode != null && !vnfcFunctionCode.isEmpty()) {
+ for (String enabledFuncCode : vmCapabilities.get(Action.START.getActionType()) ) {
+ if (enabledFuncCode.equalsIgnoreCase(vnfcFunctionCode)) {
+ vmSupported = true;
+ logger.info("vmSupportsStart: vnfcFunctionCode=" + vnfcFunctionCode + " found in vmCapabilties");
+ break;
+ }
+ }
+ } else {
+ logger.info("vmSupportsStart: " + "Inventory vnfcFunctionCode is null or empty");
+ }
+ } else {
+ logger.info("vmSupportsStart: " + "Given action in vm entry in Capabilities model is null");
+ }
+ } else {
+ logger.info("vmSupportsStart: " + "Vm entry in Capabilities model is empty");
+ }
+ } else {
+ logger.info("vmSupportsStart: " + "Vm entry in Capabilities model is null");
+ }
+
+ logger.info("vmSupportsStart: " + "returning vmSupported=" + vmSupported);
+ return vmSupported;
+ }
+} \ No newline at end of file
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 9b73b0848..8b60dede4 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
@@ -39,6 +39,7 @@ import org.onap.appc.seqgen.SequenceGenerator;
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.CapabilityModel;
import org.onap.appc.seqgen.objects.Constants;
import org.onap.appc.seqgen.objects.Response;
import org.onap.appc.seqgen.objects.SequenceGeneratorInput;
@@ -90,6 +91,11 @@ public class StopSequenceGenerator implements SequenceGenerator {
List<Vserver> vservers = input.getInventoryModel().getVnf().getVservers();
List<Integer> transactionIds = new LinkedList<>();
for (Vserver vm : vservers) {
+ // check vm-Stop-capabilities for this vm's vnfc-function-code (before incrementing transactionId)
+ String vmVnfcFunctionCode = vm.getVnfc().getVnfcFunctionCode();
+ if (!vmSupportsStop(input, vmVnfcFunctionCode)) {
+ continue;
+ }
Transaction transaction = new Transaction();
transaction.setTransactionId(transactionId);
transactionIds.add(transactionId++);
@@ -106,7 +112,7 @@ public class StopSequenceGenerator implements SequenceGenerator {
Response failureResponse = new Response();
failureResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse());
Map<String,String> failureAction = new HashMap<>();
- failureAction.put(ResponseAction.IGNORE.getAction(),Boolean.TRUE.toString());
+ failureAction.put(ResponseAction.STOP.getAction(),Boolean.TRUE.toString());
failureResponse.setResponseAction(failureAction);
transaction.addResponse(failureResponse);
}
@@ -136,13 +142,17 @@ public class StopSequenceGenerator implements SequenceGenerator {
Response failureResponse = new Response();
failureResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse());
Map<String,String> failureAction = new HashMap<>();
- failureAction.put(ResponseAction.IGNORE.getAction(),Boolean.TRUE.toString());
+ failureAction.put(ResponseAction.STOP.getAction(),Boolean.TRUE.toString());
failureResponse.setResponseAction(failureAction);
stopAppTransaction.addResponse(failureResponse);
transactionList.add(stopAppTransaction);
}
List<Vserver> vms = vnfc.getVserverList();
for(Vserver vm:vms){
+ String vmVnfcFunctionCode = vm.getVnfc().getVnfcFunctionCode();
+ if (!vmSupportsStop(input, vmVnfcFunctionCode)) {
+ continue;
+ }
Transaction transaction = new Transaction();
transaction.setTransactionId(transactionId);
transactionIds.add(transactionId++);
@@ -155,7 +165,7 @@ public class StopSequenceGenerator implements SequenceGenerator {
Response failureResponse = new Response();
failureResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse());
Map<String,String> failureAction = new HashMap<>();
- failureAction.put(ResponseAction.IGNORE.getAction(),Boolean.TRUE.toString());
+ failureAction.put(ResponseAction.STOP.getAction(),Boolean.TRUE.toString());
failureResponse.setResponseAction(failureAction);
transaction.addResponse(failureResponse);
transactionList.add(transaction);
@@ -198,14 +208,51 @@ public class StopSequenceGenerator implements SequenceGenerator {
}
private boolean readApplicationStopCapability(SequenceGeneratorInput input) {
- Map<String,List<String>> capability = input.getCapability();
- if(capability!= null){
- List<String> vnfcCapabilities = capability.get(Constants.CapabilityLevel.VNFC.getLevel());
- if(vnfcCapabilities!=null)
- return vnfcCapabilities.stream().anyMatch(p -> Capabilties.STOP_APPLICATION.getCapability().equalsIgnoreCase(p));
+ CapabilityModel capability = input.getCapability();
+ if (capability == null) {
+ return true;
}
+ List<String> vnfcCapabilities = capability.getVnfcCapabilities();
+ if(vnfcCapabilities!=null)
+ return vnfcCapabilities.stream().anyMatch(p -> Capabilties.STOP_APPLICATION.getCapability().equalsIgnoreCase(p));
+
return false;
}
+ private boolean vmSupportsStop(SequenceGeneratorInput input, String vnfcFunctionCode) {
+ boolean vmSupported = true;
+ if (input.getCapability() == null) {
+ logger.info("vmSupportsStop: " + "Capabilities model is null, returning vmSupported=" + vmSupported);
+ return vmSupported;
+ }
+ Map<String, List<String>> vmCapabilities = input.getCapability().getVmCapabilities();
+ logger.info("vmSupportsStop: vnfcFunctionCode=" + vnfcFunctionCode + ", vmCapabilities=" + vmCapabilities);
+ if (vmCapabilities != null) {
+ if (!vmCapabilities.isEmpty()) {
+ vmSupported = false;
+ if (vmCapabilities.get(Action.STOP.getActionType()) != null) {
+ if (vnfcFunctionCode != null && !vnfcFunctionCode.isEmpty()) {
+ for (String enabledFuncCode : vmCapabilities.get(Action.STOP.getActionType()) ) {
+ if (enabledFuncCode.equalsIgnoreCase(vnfcFunctionCode)) {
+ vmSupported = true;
+ logger.info("vmSupportsStop: vnfcFunctionCode=" + vnfcFunctionCode + " found in vmCapabilties");
+ break;
+ }
+ }
+ } else {
+ logger.info("vmSupportsStop: " + "Inventory vnfcFunctionCode is null or empty");
+ }
+ } else {
+ logger.info("vmSupportsStop: " + "Given action in vm entry in Capabilities model is null");
+ }
+ } else {
+ logger.info("vmSupportsStop: " + "Vm entry in Capabilities model is empty");
+ }
+ } else {
+ logger.info("vmSupportsStop: " + "Vm entry in Capabilities model is null");
+ }
-}
+ logger.info("vmSupportsStop: " + "returning vmSupported=" + vmSupported);
+ return vmSupported;
+ }
+} \ No newline at end of file
diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/CapabilityModel.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/CapabilityModel.java
new file mode 100644
index 000000000..9b0478754
--- /dev/null
+++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/CapabilityModel.java
@@ -0,0 +1,45 @@
+package org.onap.appc.seqgen.objects;
+
+import java.util.List;
+import java.util.Map;
+
+public class CapabilityModel {
+
+ private List<String> vnfCapabilities;
+ private List<String> vfModuleCapabilities;
+ private Map<String, List<String>> vmCapabilities;
+ private List<String> vnfcCapabilities;
+
+ public CapabilityModel() {
+ }
+
+ public CapabilityModel( List<String> vnfCapabilities,
+ List<String> vfModuleCapabilities,
+ Map<String, List<String>> vmCapabilities,
+ List<String> vnfcCapabilities) {
+
+ this.vnfCapabilities = vnfCapabilities;
+ this.vfModuleCapabilities = vfModuleCapabilities;
+ this.vmCapabilities = vmCapabilities;
+ this.vnfcCapabilities = vnfcCapabilities;
+ }
+ public List<String> getVnfCapabilities() {
+ return vnfCapabilities;
+ }
+ public List<String> getVfModuleCapabilities() {
+ return vfModuleCapabilities;
+ }
+ public Map<String,List<String>> getVmCapabilities() {
+ return vmCapabilities;
+ }
+ public List<String> getVnfcCapabilities() {
+ return vnfcCapabilities;
+ }
+ @Override
+ public String toString() {
+ return "CapabilitiesModel = " + "vnf=" + getVnfCapabilities() +
+ "vfModule=" + getVfModuleCapabilities() +
+ "vm=" + getVmCapabilities() +
+ "vnfc=" + getVnfcCapabilities();
+ }
+}
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 025c7698d..5b82b9e8e 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
@@ -85,7 +85,19 @@ public class Constants {
}
public enum Action{
- START("Start"),START_APPLICATION("StartApplication"),HEALTH_CHECK("HealthCheck"),STOP_APPLICATION("StopApplication"),STOP("Stop");
+ ATTACH_VOLUME("AttachVolume"),
+ DETACH_VOLUME("DetachVolume"),
+ EVACUATE("Evacuate"),
+ MIGRATE("Migrate"),
+ REBOOT("Reboot"),
+ REBUILD("Rebuild"),
+ RESTART("Restart"),
+ SNAPSHOT("Snapshot"),
+ START("Start"),
+ STOP("Stop"),
+ START_APPLICATION("StartApplication"),
+ HEALTH_CHECK("HealthCheck"),
+ STOP_APPLICATION("StopApplication");
Action(String actionType) {
this.actionType=actionType;
diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/SequenceGeneratorInput.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/SequenceGeneratorInput.java
index d847b690b..c6778a8fc 100644
--- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/SequenceGeneratorInput.java
+++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/SequenceGeneratorInput.java
@@ -31,7 +31,6 @@ import org.onap.appc.dg.objects.InventoryModel;
import org.onap.appc.dg.objects.VnfcDependencyModel;
import javax.validation.constraints.NotNull;
-import java.util.List;
import java.util.Map;
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@@ -42,17 +41,14 @@ public class SequenceGeneratorInput {
@JsonProperty("request-info")
private RequestInfo requestInfo;
- @JsonIgnore
private InventoryModel inventoryModel;
- @JsonIgnore
private VnfcDependencyModel dependencyModel;
@JsonProperty("tunable-parameters")
private Map<String,String> tunableParams;
- @JsonProperty("capabilities")
- private Map<String,List<String>> capability;
+ private CapabilityModel capabilityModel;
public RequestInfo getRequestInfo() {
return requestInfo;
@@ -86,11 +82,11 @@ public class SequenceGeneratorInput {
this.tunableParams = tunableParams;
}
- public Map<String, List<String>> getCapability() {
- return capability;
+ public CapabilityModel getCapability() {
+ return capabilityModel;
}
- public void setCapability(Map<String, List<String>> capability) {
- this.capability = capability;
+ public void setCapabilityModel(CapabilityModel capabilityModel) {
+ this.capabilityModel = capabilityModel;
}
}
diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/SequenceGeneratorInputBuilder.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/SequenceGeneratorInputBuilder.java
index 21b8f7b55..6066a9af1 100644
--- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/SequenceGeneratorInputBuilder.java
+++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/objects/SequenceGeneratorInputBuilder.java
@@ -40,21 +40,13 @@ public class SequenceGeneratorInputBuilder {
private Map<String,String> tunableParams;
- private Map<String,List<String>> capability;
-
+ private CapabilityModel capabilityModel;
+
public SequenceGeneratorInputBuilder requestInfo(RequestInfo requestInfo){
this.requestInfo = requestInfo;
return this;
}
- public SequenceGeneratorInputBuilder capability(String level,List<String> capabilities){
- if(this.capability ==null){
- this.capability = new HashMap<>();
- }
- this.capability.put(level,capabilities);
- return this;
- }
-
public SequenceGeneratorInputBuilder tunableParameter(String key,String value){
if(this.tunableParams ==null){
this.tunableParams = new HashMap<>();
@@ -73,10 +65,14 @@ public class SequenceGeneratorInputBuilder {
return this;
}
+ public SequenceGeneratorInputBuilder capabilityModel(CapabilityModel model) {
+ this.capabilityModel = model;
+ return this;
+ }
public SequenceGeneratorInput build(){
SequenceGeneratorInput input = new SequenceGeneratorInput();
input.setRequestInfo(this.requestInfo);
- input.setCapability(this.capability);
+ input.setCapabilityModel(this.capabilityModel);
input.setInventoryModel(this.inventoryModel);
input.setDependencyModel(this.dependencyModel);
input.setTunableParams(this.tunableParams);
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 940cc2ab7..86d51e393 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
@@ -45,7 +45,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;
@@ -128,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);
}
@@ -195,6 +201,7 @@ 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();
@@ -240,12 +247,13 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
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);
@@ -264,24 +272,39 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
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){
- if(input.getCapabilities().getVnf() != null){
- builder = builder.capability("vnf", input.getCapabilities().getVnf());
+
+ 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){
+ vnfCapabilities = input.getCapabilities().getVnf();
}
- if(input.getCapabilities().getVnfc() != null){
- builder = builder.capability("vnfc", input.getCapabilities().getVnfc());
+ if(input.getCapabilities().getVnfc()!=null){
+ vfModuleCapabilities = input.getCapabilities().getVnfc();
}
- if(input.getCapabilities().getVm() != null){
- builder = builder.capability("vm", input.getCapabilities().getVm());
+ if(input.getCapabilities().getVm()!=null){
+ 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());
+ if(input.getCapabilities().getVfModule()!=null){
+ vnfcCapabilities = input.getCapabilities().getVfModule();
}
}
-
- return builder;
+ return new CapabilityModel(vnfCapabilities, vfModuleCapabilities, vmCapabilities, vnfcCapabilities);
}
private void validateInventoryModelWithDependencyModel(VnfcDependencyModel dependencyModel, InventoryModel inventoryModel) throws APPCException {
@@ -460,6 +483,7 @@ public class SequenceGeneratorProvider implements AutoCloseable,SequenceGenerato
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) {
@@ -481,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.setCode((errorCode != 0)? errorCode : 401);
statusBuilder.setMessage(errorMessage);
sequenceGeneratorOutputBuilder.setStatus(statusBuilder.build());
return RpcResultBuilder