diff options
author | mojahidi <mojahidul.islam@amdocs.com> | 2017-09-12 18:53:34 +0530 |
---|---|---|
committer | Patrick Brady <pb071s@att.com> | 2017-09-13 07:17:03 +0000 |
commit | 17a1e0e30e3a35ed4ad2ef91960bb58799b208b3 (patch) | |
tree | 3bcdc2a640c4668fc0d3a2a744ae1be9f3db5a65 /appc-sequence-generator/appc-sequence-generator-bundle/src | |
parent | f0852a8174e38cc0c203a21a59af98e6c3889d5f (diff) |
validate mandatry vnfc vm info is absent in invent
when the vnfc SMP is mandatory in the
dependency-info block but its corresponding vm details/info is not present in the inventory info validation error should be thrown
Issue-ID:APPC-204
Change-Id: I606da8ce086423cf3f23c87ab0166bfb9935875b
Signed-off-by: mojahidi <mojahidul.islam@amdocs.com>
Diffstat (limited to 'appc-sequence-generator/appc-sequence-generator-bundle/src')
5 files changed, 214 insertions, 83 deletions
diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/StartSequenceGenerator.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/StartSequenceGenerator.java index acdeddd30..73e1b843f 100644 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/StartSequenceGenerator.java +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/StartSequenceGenerator.java @@ -101,93 +101,77 @@ public class StartSequenceGenerator implements SequenceGenerator { for (Vnfc vnfc : vnfcs) { List<Vserver> vms = vnfc.getVserverList(); List<Integer> transactionIds = new LinkedList<>(); - transactionId = updateTransactions(input, transactionList, transactionId, vms, transactionIds); + if(!vms.isEmpty()) { + 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()); + updateResponse(transaction); + transactionList.add(transaction); + } + boolean startApplicationSupported = readApplicationStartCapability(input); + if (startApplicationSupported) { + Transaction startAppTransaction = new Transaction(); + startAppTransaction.setTransactionId(transactionId++); + startAppTransaction.setAction(Action.START_APPLICATION.getActionType()); + startAppTransaction.setActionLevel(ActionLevel.VNFC.getAction()); + ActionIdentifier startActionIdentifier = new ActionIdentifier(); + startActionIdentifier.setVnfcName(vnfc.getVnfcName()); + startAppTransaction.setActionIdentifier(startActionIdentifier); + startAppTransaction.setPayload(input.getRequestInfo().getPayload()); - boolean startApplicationSupported = readApplicationStartCapability(input); - transactionId = checkAndUpdateStartApplication(input, transactionList, transactionId, vnfc, transactionIds, startApplicationSupported); + List<PreCheckOption> preCheckOptions = new LinkedList<>(); + for (Integer vmTransactionId : transactionIds) { + setPreCheckOptions(preCheckOptions, vmTransactionId); + } + startAppTransaction.setPreCheckOperator(PreCheckOperator.ANY.getOperator()); + startAppTransaction.setPrecheckOptions(preCheckOptions); + transactionList.add(startAppTransaction); + } + boolean healthCheckSupported = readHealthCheckCapabilites(input.getCapability()); + if (healthCheckSupported) { + Transaction healthCheckTransaction = new Transaction(); + healthCheckTransaction.setTransactionId(transactionId++); + healthCheckTransaction.setAction(Action.HEALTH_CHECK.getActionType()); + healthCheckTransaction.setActionLevel(ActionLevel.VNFC.getAction()); + ActionIdentifier healthCheckActionIdentifier = new ActionIdentifier(); + healthCheckActionIdentifier.setVnfcName(vnfc.getVnfcName()); + healthCheckTransaction.setActionIdentifier(healthCheckActionIdentifier); + healthCheckTransaction.setPayload(input.getRequestInfo().getPayload()); - boolean healthCheckSupported = readHealthCheckCapabilites(input.getCapability()); - transactionId = checkAndUpdateHealthCheck(input, waitTime, retryCount, transactionList, transactionId, vnfc, healthCheckSupported); - } - } - return transactionList; - } - - private Integer checkAndUpdateHealthCheck(SequenceGeneratorInput input, Integer waitTime, Integer retryCount, List<Transaction> transactionList, Integer transactionId, Vnfc vnfc, boolean healthCheckSupported) { - if (healthCheckSupported) { - Transaction healthCheckTransaction = new Transaction(); - healthCheckTransaction.setTransactionId(transactionId++); - healthCheckTransaction.setAction(Action.HEALTH_CHECK.getActionType()); - healthCheckTransaction.setActionLevel(ActionLevel.VNFC.getAction()); - ActionIdentifier healthCheckActionIdentifier = new ActionIdentifier(); - healthCheckActionIdentifier.setVnfcName(vnfc.getVnfcName()); - healthCheckTransaction.setActionIdentifier(healthCheckActionIdentifier); - healthCheckTransaction.setPayload(input.getRequestInfo().getPayload()); - - Response retryResponse = new Response(); - retryResponse.setResponseMessage(ResponseMessage.UNHEALTHY.getResponse()); - Map<String, String> retryAction = new HashMap<>(); - retryAction.put(ResponseAction.RETRY.getAction(), retryCount.toString()); - retryAction.put(ResponseAction.WAIT.getAction(), waitTime.toString()); - retryResponse.setResponseAction(retryAction); - healthCheckTransaction.addResponse(retryResponse); - - Response healthyResponse = new Response(); - healthyResponse.setResponseMessage(ResponseMessage.HEALTHY.getResponse()); - Map<String, String> healthyAction = new HashMap<>(); - healthyAction.put(ResponseAction.CONTINUE.getAction().toLowerCase(), Boolean.TRUE.toString()); - healthyResponse.setResponseAction(healthyAction); - healthCheckTransaction.addResponse(healthyResponse); - - Response failureResponse = new Response(); - failureResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse()); - Map<String, String> failureResonseAction = new HashMap<>(); - failureResonseAction.put(ResponseAction.STOP.getAction(), Boolean.TRUE.toString()); - failureResponse.setResponseAction(failureResonseAction); - healthCheckTransaction.addResponse(failureResponse); - transactionList.add(healthCheckTransaction); - } - return transactionId; - } + Response retryResponse = new Response(); + retryResponse.setResponseMessage(ResponseMessage.UNHEALTHY.getResponse()); + Map<String, String> retryAction = new HashMap<>(); + retryAction.put(ResponseAction.RETRY.getAction(), retryCount.toString()); + retryAction.put(ResponseAction.WAIT.getAction(), waitTime.toString()); + retryResponse.setResponseAction(retryAction); + healthCheckTransaction.addResponse(retryResponse); - private Integer checkAndUpdateStartApplication(SequenceGeneratorInput input, List<Transaction> transactionList, Integer transactionId, Vnfc vnfc, List<Integer> transactionIds, boolean startApplicationSupported) { - if (startApplicationSupported) { - Transaction startAppTransaction = new Transaction(); - startAppTransaction.setTransactionId(transactionId++); - startAppTransaction.setAction(Action.START_APPLICATION.getActionType()); - startAppTransaction.setActionLevel(ActionLevel.VNFC.getAction()); - ActionIdentifier startActionIdentifier = new ActionIdentifier(); - startActionIdentifier.setVnfcName(vnfc.getVnfcName()); - startAppTransaction.setActionIdentifier(startActionIdentifier); - startAppTransaction.setPayload(input.getRequestInfo().getPayload()); + Response healthyResponse = new Response(); + healthyResponse.setResponseMessage(ResponseMessage.HEALTHY.getResponse()); + Map<String, String> healthyAction = new HashMap<>(); + healthyAction.put(ResponseAction.CONTINUE.getAction().toLowerCase(), Boolean.TRUE.toString()); + healthyResponse.setResponseAction(healthyAction); + healthCheckTransaction.addResponse(healthyResponse); - List<PreCheckOption> preCheckOptions = new LinkedList<>(); - for (Integer vmTransactionId : transactionIds) { - setPreCheckOptions(preCheckOptions, vmTransactionId); + Response failureResponse = new Response(); + failureResponse.setResponseMessage(ResponseMessage.FAILURE.getResponse()); + Map<String, String> failureResonseAction = new HashMap<>(); + failureResonseAction.put(ResponseAction.STOP.getAction(), Boolean.TRUE.toString()); + failureResponse.setResponseAction(failureResonseAction); + healthCheckTransaction.addResponse(failureResponse); + transactionList.add(healthCheckTransaction); + } + } } - startAppTransaction.setPreCheckOperator(PreCheckOperator.ANY.getOperator()); - startAppTransaction.setPrecheckOptions(preCheckOptions); - transactionList.add(startAppTransaction); - } - return transactionId; - } - - private Integer updateTransactions(SequenceGeneratorInput input, List<Transaction> transactionList, Integer transactionId, List<Vserver> vms, List<Integer> transactionIds) { - 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()); - - updateResponse(transaction); - transactionList.add(transaction); } - return transactionId; + return transactionList; } private void setPreCheckOptions(List<PreCheckOption> preCheckOptions, Integer vmTransactionId) { diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/StopSequenceGenerator.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/StopSequenceGenerator.java index 6dec0e61f..51edb99bf 100644 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/StopSequenceGenerator.java +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/main/java/org/openecomp/appc/seqgen/impl/StopSequenceGenerator.java @@ -113,7 +113,7 @@ public class StopSequenceGenerator implements SequenceGenerator { List<Vnfc> vnfcs = itr.next(); for(Vnfc vnfc:vnfcs){ boolean stopApplicationSupported = readApplicationStopCapability(input); - if(stopApplicationSupported){ + if(stopApplicationSupported && !vnfc.getVserverList().isEmpty()){ Transaction stopAppTransaction = new Transaction(); stopAppTransaction.setTransactionId(transactionId++); stopAppTransaction.setAction(Action.STOP_APPLICATION.getActionType()); diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/openecomp/appc/seqgen/TestSequenceGeneratorPlugin.java b/appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/openecomp/appc/seqgen/TestSequenceGeneratorPlugin.java index e36b9f09d..5ab75b634 100644 --- a/appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/openecomp/appc/seqgen/TestSequenceGeneratorPlugin.java +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/test/java/org/openecomp/appc/seqgen/TestSequenceGeneratorPlugin.java @@ -230,6 +230,22 @@ public class TestSequenceGeneratorPlugin { Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); } + @Test + public void testGenerateSequenceVnfcNotPresentInInventory() throws URISyntaxException, IOException { + String inputJSON = readInput("/input/CheckVNfcInInventory.json"); + + Map<String,String> params = new HashMap<>(); + SvcLogicContext context = new SvcLogicContext(); + context.setAttribute("inputJSON",inputJSON); + SequenceGeneratorPlugin plugin = new SequenceGeneratorPluginImpl(); + plugin.generateSequence(params,context); + + String outputJSON = context.getAttribute("output"); + String actualOutput = readOutput("/output/CheckVnfcInInventory.json"); + + Assert.assertEquals(outputJSON.trim(),actualOutput.trim()); + } + private String readInput(String inputFile) throws URISyntaxException, IOException { File file = new File(this.getClass().getResource(inputFile).toURI()); @@ -249,7 +265,7 @@ public class TestSequenceGeneratorPlugin { String output=new String(bFile); int start=output.indexOf("["); - int last=output.length()-1; + int last=output.length(); return output.substring(start,last); } diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/test/resources/input/CheckVNfcInInventory.json b/appc-sequence-generator/appc-sequence-generator-bundle/src/test/resources/input/CheckVNfcInInventory.json new file mode 100644 index 000000000..2630ee749 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/test/resources/input/CheckVNfcInInventory.json @@ -0,0 +1,130 @@ + +{ + "request-info": + { + "action": "Start", + "action-level": "vnf", + "action-identifier": + { + "vnf-id": "dbgx0001v" + }, + "payload": "ABC" + }, + "inventory-info": + { + "vnf-info": + { + "vnf-id" : "abc", + "vnf-name": "vSCP", + "vnf-type": "vSCP", + "vnf-version" : "1.0", + "vm": [ + { + "vserver-id" : "be_vserverid1", + "vnfc": + { + "vnfc-type": "BE", + "vnfc-name": "BE - Name" + } + + }, + { + "vserver-id" : "fe_vserverid1", + "vnfc": + { + "vnfc-type": "FE", + "vnfc-name": "FE - Name" + } + + }, + { + "vserver-id" : "fe_vserverid2", + "vnfc": + { + "vnfc-type": "FE", + "vnfc-name": "FE - Name" + } + + }, + { + "vserver-id" : "be_vserverid2", + "vnfc": + { + "vnfc-type": "BE", + "vnfc-name": "BE - Name" + } + + }, + { + "vserver-id" : "be_vserverid3", + "vnfc": + { + "vnfc-type": "BE", + "vnfc-name": "BE - Name" + } + + }, + { + "vserver-id" : "be_vserverid4", + "vnfc": + { + "vnfc-type": "BE", + "vnfc-name": "BE - Name" + } + + }, + { + "vserver-id" : "be_vserverid5", + "vnfc": + { + "vnfc-type": "BE", + "vnfc-name": "BE - Name" + } + + } + ] + } + }, + "dependency-info" : + { + "vnfcs" : [ + { + "vnfc-type" : "BE", + "mandatory" : "true", + "resilience": "Active-Active", + "parents" : [ + "SMP" + ] + }, + { + "vnfc-type" : "FE", + "mandatory" : "true", + "resilience": "Active-Active", + "parents" : [ + "BE" + ] + }, + { + "vnfc-type" : "SMP", + "mandatory" : "false", + "resilience": "Active-Passive", + "parents" : [] + } + ] + }, + "tunable-parameters" : + { + "strategy" : "FORWARD", + "wait-time" : "120", + "retry-count" : "5" + }, + "capabilities" : + { + "vnf": ["Stop", "Start", "StartApplication","StopApplication"], + "vf-module": ["Stop", "Start"], + "vm" : ["Stop", "Start"], + "vnfc": ["StopApplication", "StartApplication","HealthCheck"] + } +} + + diff --git a/appc-sequence-generator/appc-sequence-generator-bundle/src/test/resources/output/CheckVnfcInInventory.json b/appc-sequence-generator/appc-sequence-generator-bundle/src/test/resources/output/CheckVnfcInInventory.json new file mode 100644 index 000000000..8a23ec759 --- /dev/null +++ b/appc-sequence-generator/appc-sequence-generator-bundle/src/test/resources/output/CheckVnfcInInventory.json @@ -0,0 +1 @@ +[{"transactionId":1,"action":"Start","action-level":"vm","action-identifier":{"vserver-id":"be_vserverid1"},"payload":"ABC","responses":[{"response-message":"failure","response-action":{"ignore":"true"}}]},{"transactionId":2,"action":"Start","action-level":"vm","action-identifier":{"vserver-id":"be_vserverid2"},"payload":"ABC","responses":[{"response-message":"failure","response-action":{"ignore":"true"}}]},{"transactionId":3,"action":"Start","action-level":"vm","action-identifier":{"vserver-id":"be_vserverid3"},"payload":"ABC","responses":[{"response-message":"failure","response-action":{"ignore":"true"}}]},{"transactionId":4,"action":"Start","action-level":"vm","action-identifier":{"vserver-id":"be_vserverid4"},"payload":"ABC","responses":[{"response-message":"failure","response-action":{"ignore":"true"}}]},{"transactionId":5,"action":"Start","action-level":"vm","action-identifier":{"vserver-id":"be_vserverid5"},"payload":"ABC","responses":[{"response-message":"failure","response-action":{"ignore":"true"}}]},{"transactionId":6,"action":"StartApplication","action-level":"vnfc","action-identifier":{"vnfc-name":"BE - Name"},"payload":"ABC","precheck-operator":"any","precheck-options":[{"pre-transactionID":1,"param-name":"status","param-value":"success"},{"pre-transactionID":2,"param-name":"status","param-value":"success"},{"pre-transactionID":3,"param-name":"status","param-value":"success"},{"pre-transactionID":4,"param-name":"status","param-value":"success"},{"pre-transactionID":5,"param-name":"status","param-value":"success"}],"responses":[]},{"transactionId":7,"action":"HealthCheck","action-level":"vnfc","action-identifier":{"vnfc-name":"BE - Name"},"payload":"ABC","responses":[{"response-message":"unhealthy","response-action":{"wait":"120","retry":"5"}},{"response-message":"healthy","response-action":{"continue":"true"}},{"response-message":"failure","response-action":{"stop":"true"}}]},{"transactionId":8,"action":"Start","action-level":"vm","action-identifier":{"vserver-id":"fe_vserverid1"},"payload":"ABC","responses":[{"response-message":"failure","response-action":{"ignore":"true"}}]},{"transactionId":9,"action":"Start","action-level":"vm","action-identifier":{"vserver-id":"fe_vserverid2"},"payload":"ABC","responses":[{"response-message":"failure","response-action":{"ignore":"true"}}]},{"transactionId":10,"action":"StartApplication","action-level":"vnfc","action-identifier":{"vnfc-name":"FE - Name"},"payload":"ABC","precheck-operator":"any","precheck-options":[{"pre-transactionID":8,"param-name":"status","param-value":"success"},{"pre-transactionID":9,"param-name":"status","param-value":"success"}],"responses":[]},{"transactionId":11,"action":"HealthCheck","action-level":"vnfc","action-identifier":{"vnfc-name":"FE - Name"},"payload":"ABC","responses":[{"response-message":"unhealthy","response-action":{"wait":"120","retry":"5"}},{"response-message":"healthy","response-action":{"continue":"true"}},{"response-message":"failure","response-action":{"stop":"true"}}]}]
\ No newline at end of file |