diff options
author | Keighron, Lori (lk2924) <lk2924@us.att.com> | 2019-11-11 17:53:30 -0500 |
---|---|---|
committer | Takamune Cho <takamune.cho@att.com> | 2019-11-20 01:34:04 +0000 |
commit | 7b1313a9d6621f8c16dee4a21136f7d825a42c1d (patch) | |
tree | bbbede0a3f99bd7cabc3ddd6425c7416008462f2 /appc-sequence-generator/appc-sequence-generator-bundle/src/main | |
parent | d6801d69b3d29ce0aa99d3214f7cf4bfd02fb706 (diff) |
Add vm caps fixes to sequence-generator code (vm caps)
Add vm caps fixes to sequence-generator code (vm caps)
output/start.json not needed
Change-Id: Id3f65d2780d9d92ab971c9c6ed5ab60669135808
Issue-ID: APPC-1787
Signed-off-by: Keighron, Lori (lk2924) <lk2924@att.com>
Diffstat (limited to 'appc-sequence-generator/appc-sequence-generator-bundle/src/main')
4 files changed, 100 insertions, 69 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 111085e18..25e8d872f 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 @@ -72,12 +72,12 @@ public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin { SequenceGeneratorInput sequenceGeneratorInput = buildSequenceGeneratorInput(inputJSON); List<Transaction> sequence = generateSequence(sequenceGeneratorInput); if (sequence.isEmpty()) { - logger.error("Error generating sequence"); + logger.error("Transaction list is empty"); 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); + logger.info("Sequence Generator Output " + output); context.setAttribute("output", output); } } catch (Exception e) { @@ -294,11 +294,14 @@ public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin { Vserver vserver = new Vserver(); vserver.setId(vserverId); vserver.setUrl(vmId); - 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()); - vfc.setVnfcFunctionCode(vm.get("vnfc").get("vnfc-function-code").asText()); + Vnfc vfc = new Vnfc(); + if (vm.get("vnfc") != null ) { + if (vm.get("vnfc").get("vnfc-name") != null) + vfc.setVnfcName(vm.get("vnfc").get("vnfc-name").asText()); + if (vm.get("vnfc").get("vnfc-type") != null) + vfc.setVnfcType(vm.get("vnfc").get("vnfc-type").asText()); + if (vm.get("vnfc").get("vnfc-function-code") != null) + vfc.setVnfcFunctionCode(vm.get("vnfc").get("vnfc-function-code").asText()); vserver.setVnfc(vfc); List<Vserver> vServers = vfcs.get(vfc); if (vServers == null) { @@ -318,6 +321,7 @@ public class SequenceGeneratorPluginImpl implements SequenceGeneratorPlugin { return new InventoryModel(vnf); } + private CapabilityModel buildCapabilitiesModel(String inputJson) throws IOException, APPCException { logger.info("Entering buildCapabilitiesModel"); 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 2f5080d0b..5c83df4e0 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 @@ -32,6 +32,7 @@ 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.Constants.ResponseAction; import org.onap.appc.seqgen.objects.Response; import org.onap.appc.seqgen.objects.SequenceGeneratorInput; import org.onap.appc.seqgen.objects.Transaction; @@ -59,8 +60,7 @@ public class RestartSequenceGenerator implements SequenceGenerator{ 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)) { + if (!vmSupportsRestart(input, vm)) { continue; } Transaction transactionStop = new Transaction(); @@ -79,9 +79,9 @@ 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.STOP.getAction(), String.valueOf(transactionId+1)); + //if(!checkLastVM(vservers,vm.getId())) { + //failureAction.put(Constants.ResponseAction.STOP.getAction(), String.valueOf(transactionId+1)); + failureAction.put(ResponseAction.STOP.getAction(), Boolean.TRUE.toString()); failureResponse.setResponseAction(failureAction); transactionStop.addResponse(failureResponse); //} @@ -101,10 +101,9 @@ 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()); - failureAction.put(Constants.ResponseAction.STOP.getAction(),transactionId.toString()); + //if(!checkLastVM(vservers,vm.getId())) { + //failureAction.put(Constants.ResponseAction.JUMP.getAction(),transactionId.toString()); + failureAction.put(ResponseAction.STOP.getAction(), Boolean.TRUE.toString()); failureResponse.setResponseAction(failureAction); transactionStart.addResponse(failureResponse); //} @@ -114,28 +113,37 @@ public class RestartSequenceGenerator implements SequenceGenerator{ return transactionList; } - private boolean vmSupportsRestart(SequenceGeneratorInput input, String vnfcFunctionCode) { + private boolean vmSupportsRestart(SequenceGeneratorInput input, Vserver vm) { 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; + List<String> vmCapsForThisAction = vmCapabilities.get(Action.RESTART.getActionType()); + if (vmCapsForThisAction != null) { + vmSupported = false; + if (!vmCapsForThisAction.isEmpty()) { + if (vm.getVnfc() != null) { + String vnfcFunctionCode = vm.getVnfc().getVnfcFunctionCode(); + if (vnfcFunctionCode != null && !vnfcFunctionCode.isEmpty()) { + for (String s : vmCapabilities.get(Action.RESTART.getActionType()) ) { + if (s.equalsIgnoreCase(vnfcFunctionCode)) { + vmSupported = true; + logger.info("vmSupportsRestart: vnfcFunctionCode=" + vnfcFunctionCode + " found in vmCapabilities"); + break; + } + } + } else { + logger.info("vmSupportsRestart: " + "Inventory vnfcFunctionCode is null or empty"); } - } + } else { + logger.info("vmSupportsRestart: " + "Inventory vnfc is null or empty"); + } } else { - logger.info("vmSupportsRestart: " + "Inventory vnfcFunctionCode is null or empty"); + logger.info("vmSupportsRestart: " + "Given action in vm entry in Capabilities model is empty"); } } else { logger.info("vmSupportsRestart: " + "Given action in vm entry in Capabilities model is null"); @@ -147,10 +155,11 @@ public class RestartSequenceGenerator implements SequenceGenerator{ logger.info("vmSupportsRestart: " + "Vm entry in Capabilities model is null"); } - logger.info("vmSupportsRestart: " + "returning vmSupported=" + vmSupported); + logger.info("vmSupportsRestart: " + "returning vmSupported=" + vmSupported + ", " + ((vmSupported)?"including":"excluding") + " vm=" + vm.getId()); return vmSupported; } + 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/StartSequenceGenerator.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/onap/appc/seqgen/impl/StartSequenceGenerator.java index 105173f33..f709374e8 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 @@ -78,8 +78,7 @@ public class StartSequenceGenerator implements SequenceGenerator { 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)) { + if (!vmSupportsStart(input, vm)) { continue; } Transaction transaction = new Transaction(); @@ -139,8 +138,7 @@ public class StartSequenceGenerator implements SequenceGenerator { 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)) { + if (!vmSupportsStart(input, vm)) { continue; } Transaction transaction = new Transaction(); @@ -336,28 +334,37 @@ public class StartSequenceGenerator implements SequenceGenerator { } } - private boolean vmSupportsStart(SequenceGeneratorInput input, String vnfcFunctionCode) { + private boolean vmSupportsStart(SequenceGeneratorInput input, Vserver vm) { 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; + List<String> vmCapsForThisAction = vmCapabilities.get(Action.START.getActionType()); + if (vmCapsForThisAction != null) { + vmSupported = false; + if (!vmCapsForThisAction.isEmpty()) { + if (vm.getVnfc() != null) { + String vnfcFunctionCode = vm.getVnfc().getVnfcFunctionCode(); + if (vnfcFunctionCode != null && !vnfcFunctionCode.isEmpty()) { + for (String s : vmCapabilities.get(Action.START.getActionType()) ) { + if (s.equalsIgnoreCase(vnfcFunctionCode)) { + vmSupported = true; + logger.info("vmSupportsStart: vnfcFunctionCode=" + vnfcFunctionCode + " found in vmCapabilities"); + break; + } + } + } else { + logger.info("vmSupportsStart: " + "Inventory vnfcFunctionCode is null or empty"); } - } + } else { + logger.info("vmSupportsStart: " + "Inventory vnfc is null or empty"); + } } else { - logger.info("vmSupportsStart: " + "Inventory vnfcFunctionCode is null or empty"); + logger.info("vmSupportsStart: " + "Given action in vm entry in Capabilities model is empty"); } } else { logger.info("vmSupportsStart: " + "Given action in vm entry in Capabilities model is null"); @@ -369,7 +376,7 @@ public class StartSequenceGenerator implements SequenceGenerator { logger.info("vmSupportsStart: " + "Vm entry in Capabilities model is null"); } - logger.info("vmSupportsStart: " + "returning vmSupported=" + vmSupported); + logger.info("vmSupportsStart: " + "returning vmSupported=" + vmSupported + ", " + ((vmSupported)?"including":"excluding") + " vm=" + vm.getId()); 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 8b60dede4..c0d161a9a 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 @@ -83,7 +83,7 @@ public class StopSequenceGenerator implements SequenceGenerator { } } - private List<Transaction> generateSequenceWithOutDependency(SequenceGeneratorInput input)throws Exception{ + private List<Transaction> generateSequenceWithOutDependency(SequenceGeneratorInput input) throws Exception{ String payload = null; PayloadGenerator payloadGenerator = new PayloadGenerator(); List<Transaction> transactionList = new LinkedList<>(); @@ -92,8 +92,7 @@ public class StopSequenceGenerator implements SequenceGenerator { 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)) { + if (!vmSupportsStop(input, vm)) { continue; } Transaction transaction = new Transaction(); @@ -121,7 +120,8 @@ public class StopSequenceGenerator implements SequenceGenerator { return transactionList; } - private List<Transaction> generateSequenceWithDependencyModel(VnfcFlowModel flowModel,SequenceGeneratorInput input){ + private List<Transaction> generateSequenceWithDependencyModel(VnfcFlowModel flowModel, + SequenceGeneratorInput input) throws Exception { List<Transaction> transactionList = new LinkedList<>(); Integer transactionId = 1; List<Integer> transactionIds = new LinkedList<>(); @@ -149,8 +149,7 @@ public class StopSequenceGenerator implements SequenceGenerator { } List<Vserver> vms = vnfc.getVserverList(); for(Vserver vm:vms){ - String vmVnfcFunctionCode = vm.getVnfc().getVnfcFunctionCode(); - if (!vmSupportsStop(input, vmVnfcFunctionCode)) { + if (!vmSupportsStop(input, vm)) { continue; } Transaction transaction = new Transaction(); @@ -175,7 +174,8 @@ public class StopSequenceGenerator implements SequenceGenerator { return transactionList; } - private VnfcFlowModel buildFlowModel(InventoryModel inventoryModel, VnfcDependencyModel dependencyModel, FlowStrategies flowStrategy) throws APPCException, InvalidDependencyModelException { + 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); @@ -201,7 +201,8 @@ public class StopSequenceGenerator 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; @@ -213,34 +214,44 @@ public class StopSequenceGenerator implements SequenceGenerator { return true; } List<String> vnfcCapabilities = capability.getVnfcCapabilities(); - if(vnfcCapabilities!=null) - return vnfcCapabilities.stream().anyMatch(p -> Capabilties.STOP_APPLICATION.getCapability().equalsIgnoreCase(p)); + if(vnfcCapabilities != null) + return vnfcCapabilities.stream() + .anyMatch(p -> Capabilties.STOP_APPLICATION.getCapability().equalsIgnoreCase(p)); return false; } - private boolean vmSupportsStop(SequenceGeneratorInput input, String vnfcFunctionCode) { + private boolean vmSupportsStop(SequenceGeneratorInput input, Vserver vm) { 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; + List<String> vmCapsForThisAction = vmCapabilities.get(Action.STOP.getActionType()); + if (vmCapsForThisAction != null) { + vmSupported = false; + if (!vmCapsForThisAction.isEmpty()) { + if (vm.getVnfc() != null) { + String vnfcFunctionCode = vm.getVnfc().getVnfcFunctionCode(); + if (vnfcFunctionCode != null && !vnfcFunctionCode.isEmpty()) { + for (String s : vmCapabilities.get(Action.STOP.getActionType()) ) { + if (s.equalsIgnoreCase(vnfcFunctionCode)) { + vmSupported = true; + logger.info("vmSupportsStop: vnfcFunctionCode=" + vnfcFunctionCode + " found in vmCapabilities"); + break; + } + } + } else { + logger.info("vmSupportsStop: " + "Inventory vnfcFunctionCode is null or empty"); } - } + } else { + logger.info("vmSupportsStop: " + "Inventory vnfc is null or empty"); + } } else { - logger.info("vmSupportsStop: " + "Inventory vnfcFunctionCode is null or empty"); + logger.info("vmSupportsStop: " + "Given action in vm entry in Capabilities model is empty"); } } else { logger.info("vmSupportsStop: " + "Given action in vm entry in Capabilities model is null"); @@ -252,7 +263,7 @@ public class StopSequenceGenerator implements SequenceGenerator { logger.info("vmSupportsStop: " + "Vm entry in Capabilities model is null"); } - logger.info("vmSupportsStop: " + "returning vmSupported=" + vmSupported); + logger.info("vmSupportsStop: " + "returning vmSupported=" + vmSupported + ", " + ((vmSupported)?"including":"excluding") + " vm=" + vm.getId()); return vmSupported; } }
\ No newline at end of file |