From 44ffcde54cb7d832232a32fe7a60b4849bef447a Mon Sep 17 00:00:00 2001 From: tragait Date: Fri, 4 Sep 2020 13:34:35 +0100 Subject: multiple pnf fix Signed-off-by: tragait Change-Id: I3d9d0ebb38da1fb286f097828551e981a0f95a65 Signed-off-by: tragait Issue-ID: SO-3223 Signed-off-by: tragait --- .../resources/process/GenericPnfSWUPDownload.bpmn | 192 ++++++------ .../process/GenericPnfSoftwareUpgrade.bpmn | 252 ++++++++-------- .../resources/process/ServiceLevelUpgrade.bpmn | 333 ++++++++++++--------- .../process/ServiceLevelUpgradeTest.java | 81 +++-- .../src/test/resources/response/PnfDemo1_aai.json | 42 +++ .../src/test/resources/response/PnfDemo_aai.json | 42 +++ .../src/test/resources/response/Pnf_aai.json | 42 --- .../resources/response/Service_instance_aai.json | 10 + .../infrastructure/service/level/ServiceLevel.java | 119 ++++++++ .../service/level/ServiceLevelPreparable.java | 98 ------ .../service/level/impl/ServiceLevelConstants.java | 4 + .../service/level/impl/ServiceLevelPostcheck.java | 2 +- .../level/impl/ServiceLevelPreparation.java | 10 +- .../level/impl/ServiceLevelRequestDispatcher.java | 22 +- .../service/level/impl/ServiceLevelUpgrade.java | 12 +- 15 files changed, 712 insertions(+), 549 deletions(-) create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/PnfDemo1_aai.json create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/PnfDemo_aai.json delete mode 100644 bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/Pnf_aai.json create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevel.java delete mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparable.java (limited to 'bpmn') diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfSWUPDownload.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfSWUPDownload.bpmn index 8b1b8367f8..6a0b260a70 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfSWUPDownload.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfSWUPDownload.bpmn @@ -1,10 +1,10 @@ - + SequenceFlow_1fdclh0 - + SequenceFlow_1fdclh0 SequenceFlow_0kusy70 @@ -144,6 +144,88 @@ pnfSwUpgrade.prepareCompletion(execution) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -186,68 +268,21 @@ pnfSwUpgrade.prepareCompletion(execution) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + @@ -266,50 +301,15 @@ pnfSwUpgrade.prepareCompletion(execution) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfSoftwareUpgrade.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfSoftwareUpgrade.bpmn index f4a6196fc1..9b8ce4a7b7 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfSoftwareUpgrade.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/GenericPnfSoftwareUpgrade.bpmn @@ -1,10 +1,10 @@ - + SequenceFlow_1ng4b6l - + SequenceFlow_1ng4b6l SequenceFlow_12ejx4m @@ -174,6 +174,110 @@ pnfSwUpgrade.prepareFalloutHandler(execution) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -183,20 +287,12 @@ pnfSwUpgrade.prepareFalloutHandler(execution) - - - - - - - - @@ -212,160 +308,59 @@ pnfSwUpgrade.prepareFalloutHandler(execution) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - - + + + @@ -373,13 +368,18 @@ pnfSwUpgrade.prepareFalloutHandler(execution) - - + + + + + + + + + + + - - - - diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ServiceLevelUpgrade.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ServiceLevelUpgrade.bpmn index 3d37430723..8ff1a1efec 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ServiceLevelUpgrade.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ServiceLevelUpgrade.bpmn @@ -12,19 +12,21 @@ Flow_10jgbxm - + Flow_1y3cptr Flow_0y1ebox Flow_0mbp7mv + Flow_19tmp99 Flow_0y1ebox - - Flow_0trmo7s - Flow_1z06yyv + + Flow_0zjsp5x Flow_0mxq0qe + Flow_05x2cqc + Flow_02elm5b Flow_0mxq0qe @@ -40,7 +42,7 @@ - Flow_1z06yyv + Flow_02elm5b Flow_01gwzx9 @@ -48,16 +50,9 @@ Flow_1ru18s3 - Flow_1v0mxe7 - Flow_1p4xkdj - - Flow_1b392qs - Flow_1v0mxe7 - import org.onap.so.bpmn.infrastructure.scripts.* -def pnfSwUpgrade = new GenericPnfSoftwareUpgrade() -pnfSwUpgrade.sendResponse(execution) - + Flow_1ptk2a3 + Flow_0l67uzl Flow_0frhsd0 @@ -94,24 +89,23 @@ pnfSwUpgrade.prepareFalloutHandler(execution) - + - - - - - #{execution.getVariable("ControllerStatus").equals("Success")} + + + ${!execution.getVariable("ControllerStatus").equals("Success")} + + + ${!execution.getVariable("ControllerStatus").equals("Success")} - #{execution.getVariable("ControllerStatus").equals("Success")} - - #{execution.getVariable("ControllerStatus").equals("Success")} + ${execution.getVariable("pnfCounter") >= execution.getVariable("pnfSize")} @@ -123,10 +117,9 @@ pnfSwUpgrade.prepareFalloutHandler(execution) - Flow_1p4xkdj - Flow_0trmo7s + Flow_0rpnl02 + Flow_0zjsp5x - @@ -137,7 +130,7 @@ pnfSwUpgrade.prepareFalloutHandler(execution) - Flow_01gwzx9 + Flow_0g6gkgx Flow_1y3cptr @@ -151,7 +144,7 @@ pnfSwUpgrade.prepareFalloutHandler(execution) Flow_05ohtnj Flow_0ny61qm - + #{execution.getVariable("ControllerStatus").equals("Success")} @@ -159,6 +152,29 @@ pnfSwUpgrade.prepareFalloutHandler(execution) + + + + + + ${execution.getVariable("pnfCounter") < execution.getVariable("pnfSize")} + + + ${execution.getVariable("pnfCounter") < execution.getVariable("pnfSize")} + + + ${execution.getVariable("pnfCounter") >= execution.getVariable("pnfSize")} + + + Flow_1ptk2a3 + Flow_05x2cqc + Flow_0rpnl02 + + + Flow_01gwzx9 + Flow_19tmp99 + Flow_0g6gkgx + @@ -166,212 +182,237 @@ pnfSwUpgrade.prepareFalloutHandler(execution) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - - - + + + + - + - - + + - - - - - - + + - - + + - + - - - - - - - - - - + + - - - - + + + + - + - - + + - + - - + + - - - - - - - - - + + - + - - - - - - + + - + - - + + - - + + - - + + - - + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - - + + - - + + - - + + - + - + - + - + - - - - - - - - - - - - - - - diff --git a/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/ServiceLevelUpgradeTest.java b/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/ServiceLevelUpgradeTest.java index bdad46f3ca..4322ff5bdf 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/ServiceLevelUpgradeTest.java +++ b/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/ServiceLevelUpgradeTest.java @@ -62,7 +62,8 @@ public class ServiceLevelUpgradeTest extends BaseBPMNTest { private static final Map executionVariables = new HashMap(); private static final String REQUEST_ID = "50ae41ad-049c-4fe2-9950-539f111120f5"; private static final String SERVICE_INSTANCE_ID = "5df8b6de-2083-11e7-93ae-92361f002676"; - private final String[] actionNames = new String[5]; + private final String[] actionNames = new String[10]; + private final String[] pnfNames = new String[10]; private final String CLASSNAME = getClass().getSimpleName(); private String requestObject; private String responseObject; @@ -73,10 +74,26 @@ public class ServiceLevelUpgradeTest extends BaseBPMNTest { @Before public void setUp() throws IOException { actionNames[0] = "healthCheck"; - actionNames[1] = "preCheck"; - actionNames[2] = "downloadNESw"; - actionNames[3] = "activateNESw"; - actionNames[4] = "postCheck"; + actionNames[1] = "healthCheck"; + actionNames[2] = "preCheck"; + actionNames[3] = "downloadNESw"; + actionNames[4] = "activateNESw"; + actionNames[5] = "postCheck"; + actionNames[6] = "preCheck"; + actionNames[7] = "downloadNESw"; + actionNames[8] = "activateNESw"; + actionNames[9] = "postCheck"; + + pnfNames[0] = "PNFDemo"; + pnfNames[1] = "PNFDemo1"; + pnfNames[2] = "PNFDemo"; + pnfNames[3] = "PNFDemo"; + pnfNames[4] = "PNFDemo"; + pnfNames[5] = "PNFDemo"; + pnfNames[6] = "PNFDemo1"; + pnfNames[7] = "PNFDemo1"; + pnfNames[8] = "PNFDemo1"; + pnfNames[9] = "PNFDemo1"; executionVariables.clear(); @@ -125,22 +142,22 @@ public class ServiceLevelUpgradeTest extends BaseBPMNTest { } // Layout is to reflect the bpmn visual layout - assertThat(pi).isEnded().hasPassedInOrder("Event_02mc8tr", "Activity_18vue7u", "Activity_0qgmx7a", - "Activity_09bqns0", "Activity_0n17xou", "Gateway_1nr51kr", "Activity_0snmatn", "Activity_1q4o9fx", - "Gateway_02fectw", "Activity_1hp67qz", "Gateway_18ch73t", "Activity_0ft7fa2", "Gateway_1vq11i7", - "Activity_1n4rk7m", "Activity_1lz38px", "Event_12983th"); + assertThat(pi).isEnded().hasPassedInOrder("Event_02mc8tr", "Activity_18vue7u", "Activity_09bqns0", + "Activity_02vp5np", "Activity_0n17xou", "Gateway_1nr51kr", "Activity_0snmatn", "Activity_0e6w886", + "Activity_1q4o9fx", "Gateway_02fectw", "Activity_1hp67qz", "Gateway_18ch73t", "Activity_0ft7fa2", + "Gateway_1vq11i7", "Activity_1n4rk7m", "Activity_1lz38px", "Event_12983th"); List detailedMessages = grpcNettyServer.getDetailedMessages(); assertThat(detailedMessages.size() == 5); int count = 0; + String action = ""; try { for (ExecutionServiceInput eSI : detailedMessages) { - for (String action : actionNames) { - if (action.equals(eSI.getActionIdentifiers().getActionName()) - && eSI.getCommonHeader().getRequestId().equals(msoRequestId)) { - checkWithActionName(eSI, action); - count++; - } + action = actionNames[count]; + if (action.equals(eSI.getActionIdentifiers().getActionName()) + && eSI.getCommonHeader().getRequestId().equals(msoRequestId)) { + checkWithActionName(eSI, action, pnfNames[count]); + count++; } } } catch (Exception e) { @@ -155,7 +172,8 @@ public class ServiceLevelUpgradeTest extends BaseBPMNTest { .singleResult() == null; } - private void checkWithActionName(ExecutionServiceInput executionServiceInput, String action) { + private void checkWithActionName(final ExecutionServiceInput executionServiceInput, final String action, + final String pnfName) { logger.info("Checking the " + action + " request"); ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers(); @@ -174,10 +192,10 @@ public class ServiceLevelUpgradeTest extends BaseBPMNTest { Struct payload = executionServiceInput.getPayload(); Struct requeststruct = payload.getFieldsOrThrow(action + "-request").getStructValue(); - assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).isEqualTo("PNFDemo"); + assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).isEqualTo(pnfName); Struct propertiesStruct = requeststruct.getFieldsOrThrow(action + "-properties").getStructValue(); - assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).isEqualTo("PNFDemo"); + assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).isEqualTo(pnfName); assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue()) .isEqualTo("d88da85c-d9e8-4f73-b837-3a72a431622b"); assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue()) @@ -188,25 +206,42 @@ public class ServiceLevelUpgradeTest extends BaseBPMNTest { final String sIUrl = "/business/customers/customer/5df8b6de-2083-11e7-93ae-92361f002676/service-subscriptions/service-subscription/pNF/service-instances/service-instance/ETE_Customer_807c7a02-249c-4db8-9fa9-bee973fe08ce"; - final String aaiPnfEntry = FileUtil.readResourceFile("response/Pnf_aai.json"); + final String aaiPnfDemoEntry = FileUtil.readResourceFile("response/PnfDemo_aai.json"); + final String aaiPnfDemo1Entry = FileUtil.readResourceFile("response/PnfDemo1_aai.json"); final String aaiServiceInstanceEntry = FileUtil.readResourceFile("response/Service_instance_aai.json"); /** - * PUT the PNF correlation ID to AAI. + * PUT the PNF correlation ID PnfDemo to AAI. */ wireMockServer.stubFor(put(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo"))); /** - * Get the PNF entry from AAI. + * PUT the PNF correlation ID PnfDemo1 to AAI. + */ + wireMockServer.stubFor(put(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo1"))); + + /** + * Get the PNF entry PnfDemo from AAI. + */ + wireMockServer.stubFor( + get(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo")).willReturn(okJson(aaiPnfDemoEntry))); + + /** + * Get the PNF entry PnfDemo1 from AAI. */ wireMockServer.stubFor( - get(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo")).willReturn(okJson(aaiPnfEntry))); + get(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo1")).willReturn(okJson(aaiPnfDemo1Entry))); /** - * Post the pnf to AAI + * Post the pnf PnfDemo to AAI */ wireMockServer.stubFor(post(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo"))); + /** + * Post the pnf PnfDemo1 to AAI + */ + wireMockServer.stubFor(post(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo1"))); + /** * Get the Service Instance to AAI. */ diff --git a/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/PnfDemo1_aai.json b/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/PnfDemo1_aai.json new file mode 100644 index 0000000000..189d2c5a9b --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/PnfDemo1_aai.json @@ -0,0 +1,42 @@ +{ + "pnf-name": "PNFDemo1", + "pnf-id": "37c6e19d-6d9f-4085-98a9-d3fcbaf3a616", + "equip-type": "val8", + "equip-vendor": "Ericsson", + "equip-model": "val6", + "ipaddress-v4-oam": "10.10.10.44", + "sw-version": "5gDUv18.05.201", + "in-maint": false, + "serial-number": "7061ZW3", + "ipaddress-v6-oam": "2001:0db8:0:0:0:0:1428:57ab", + "resource-version": "1595010038094", + "nf-role": "gNB", + "relationship-list": { + "relationship": [ + { + "related-to": "service-instance", + "related-link": "/aai/v11/business/customers/customer/ETE_Customer_807c7a02-249c-4db8-9fa9-bee973fe08ce/service-subscriptions/service-subscription/pNF/service-instances/service-instance/5df8b6de-2083-11e7-93ae-92361f002676", + "relationship-data": [ + { + "relationship-key": "customer.global-customer-id", + "relationship-value": "ETE_Customer_807c7a02-249c-4db8-9fa9-bee973fe08ce" + }, + { + "relationship-key": "service-subscription.service-type", + "relationship-value": "pNF" + }, + { + "relationship-key": "service-instance.service-instance-id", + "relationship-value": "5df8b6de-2083-11e7-93ae-92361f002676" + } + ], + "related-to-property": [ + { + "property-key": "service-instance.service-instance-name", + "property-value": "Service_Ete_Name123452c4-3d7f-42ce-8188-818fab951269" + } + ] + } + ] + } +}, \ No newline at end of file diff --git a/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/PnfDemo_aai.json b/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/PnfDemo_aai.json new file mode 100644 index 0000000000..865600c800 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/PnfDemo_aai.json @@ -0,0 +1,42 @@ +{ + "pnf-name": "PNFDemo", + "pnf-id": "27c6e19d-6d9f-4085-98a9-d3fcbaf3a616", + "equip-type": "val8", + "equip-vendor": "Ericsson", + "equip-model": "val6", + "ipaddress-v4-oam": "10.10.10.43", + "sw-version": "5gDUv18.05.201", + "in-maint": false, + "serial-number": "6061ZW3", + "ipaddress-v6-oam": "2001:0db8:0:0:0:0:1428:57ab", + "resource-version": "1595010038094", + "nf-role": "gNB", + "relationship-list": { + "relationship": [ + { + "related-to": "service-instance", + "related-link": "/aai/v11/business/customers/customer/ETE_Customer_807c7a02-249c-4db8-9fa9-bee973fe08ce/service-subscriptions/service-subscription/pNF/service-instances/service-instance/5df8b6de-2083-11e7-93ae-92361f002676", + "relationship-data": [ + { + "relationship-key": "customer.global-customer-id", + "relationship-value": "ETE_Customer_807c7a02-249c-4db8-9fa9-bee973fe08ce" + }, + { + "relationship-key": "service-subscription.service-type", + "relationship-value": "pNF" + }, + { + "relationship-key": "service-instance.service-instance-id", + "relationship-value": "5df8b6de-2083-11e7-93ae-92361f002676" + } + ], + "related-to-property": [ + { + "property-key": "service-instance.service-instance-name", + "property-value": "Service_Ete_Name123452c4-3d7f-42ce-8188-818fab951269" + } + ] + } + ] + } +}, \ No newline at end of file diff --git a/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/Pnf_aai.json b/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/Pnf_aai.json deleted file mode 100644 index 865600c800..0000000000 --- a/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/Pnf_aai.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "pnf-name": "PNFDemo", - "pnf-id": "27c6e19d-6d9f-4085-98a9-d3fcbaf3a616", - "equip-type": "val8", - "equip-vendor": "Ericsson", - "equip-model": "val6", - "ipaddress-v4-oam": "10.10.10.43", - "sw-version": "5gDUv18.05.201", - "in-maint": false, - "serial-number": "6061ZW3", - "ipaddress-v6-oam": "2001:0db8:0:0:0:0:1428:57ab", - "resource-version": "1595010038094", - "nf-role": "gNB", - "relationship-list": { - "relationship": [ - { - "related-to": "service-instance", - "related-link": "/aai/v11/business/customers/customer/ETE_Customer_807c7a02-249c-4db8-9fa9-bee973fe08ce/service-subscriptions/service-subscription/pNF/service-instances/service-instance/5df8b6de-2083-11e7-93ae-92361f002676", - "relationship-data": [ - { - "relationship-key": "customer.global-customer-id", - "relationship-value": "ETE_Customer_807c7a02-249c-4db8-9fa9-bee973fe08ce" - }, - { - "relationship-key": "service-subscription.service-type", - "relationship-value": "pNF" - }, - { - "relationship-key": "service-instance.service-instance-id", - "relationship-value": "5df8b6de-2083-11e7-93ae-92361f002676" - } - ], - "related-to-property": [ - { - "property-key": "service-instance.service-instance-name", - "property-value": "Service_Ete_Name123452c4-3d7f-42ce-8188-818fab951269" - } - ] - } - ] - } -}, \ No newline at end of file diff --git a/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/Service_instance_aai.json b/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/Service_instance_aai.json index 53fb210478..8ea4263bbe 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/Service_instance_aai.json +++ b/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/Service_instance_aai.json @@ -29,6 +29,16 @@ "relationship-value": "PNFDemo" } ] + }, + { + "related-to": "pnf", + "related-link": "/aai/v11/network/pnfs/pnf/PNFDemo1", + "relationship-data": [ + { + "relationship-key": "pnf.pnf-name", + "relationship-value": "PNFDemo1" + } + ] } ] } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevel.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevel.java new file mode 100644 index 0000000000..b8f5ec9674 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevel.java @@ -0,0 +1,119 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.service.level; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import jline.internal.Log; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.bpmn.infrastructure.service.level.impl.ServiceLevelConstants; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.db.catalog.beans.Workflow; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * Parent class for Service level upgrade Execution, it should be extended for service level upgrade tasks. + */ +public class ServiceLevel { + + protected static final Logger LOG = LoggerFactory.getLogger(ServiceLevel.class); + + @Autowired + protected ExceptionBuilder exceptionBuilder; + + @Autowired + protected CatalogDbClient catalogDbClient; + + private static final String PNF_NAME_LIST = "pnfNameList"; + + private static final String PNF_COUNTER = "pnfCounter"; + + /** + * Fetches workflow names based on the controller scope and operation name. + * + * @param scope Controller scope + * @param operationName healthcheck/softwareUpgrade + * @return String value of Workflow name + */ + protected String fetchWorkflowUsingScope(final String scope, String operationName) { + Optional wflName = Optional.empty(); + try { + List workflows = catalogDbClient.findWorkflowByOperationName(operationName); + if (!workflows.isEmpty()) { + wflName = Optional.ofNullable( + workflows.stream().filter(workflow -> workflow.getResourceTarget().equalsIgnoreCase(scope)) + .findFirst().get().getName()); + } + } catch (Exception e) { + // do nothing and assign the default workflow in finally + LOG.error("Error occurred while fetching workflow name from CatalogDb {}", e); + } finally { + if (wflName.isEmpty()) { + wflName = Optional.of(ServiceLevelConstants.WORKFLOW_OPERATIONS_MAP.get(operationName).get(scope)); + } + } + return wflName.get(); + + } + + /** + * This method validates the execution parameters to be passed for health check workflow. + * + * @param execution Delegate execution obj + * @param scope Controller scope * Throws workflow exception if validation fails + */ + protected void validateParamsWithScope(DelegateExecution execution, final String scope, List params) { + List invalidVariables = new ArrayList<>(); + for (String param : params) { + if (!execution.hasVariable(param) || execution.getVariable(param) == null + || String.valueOf(execution.getVariable(param)).isEmpty()) { + invalidVariables.add(param); + } + } + if (invalidVariables.size() > 0) { + LOG.error("Validation error for the {} health check attributes: {}", scope, invalidVariables); + exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE, + "Validation of health check workflow parameters failed for the scope: " + scope); + } + + } + + /** + * This method set correct value of pnf name for health check and software upgrade workflow. + * + * @param delegateExecution Delegate execution obj + */ + public void pnfCounterExecution(DelegateExecution delegateExecution) { + LOG.debug("Running execute block for activity id: {}, name: {}", delegateExecution.getCurrentActivityId(), + delegateExecution.getCurrentActivityName()); + + final List pnfNameList = (List) delegateExecution.getVariable(PNF_NAME_LIST); + final int pnfCounter = (int) delegateExecution.getVariable(PNF_COUNTER); + + delegateExecution.setVariable(ServiceLevelConstants.PNF_NAME, pnfNameList.get(pnfCounter)); + delegateExecution.setVariable(PNF_COUNTER, pnfCounter + 1); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparable.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparable.java deleted file mode 100644 index e26195158d..0000000000 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparable.java +++ /dev/null @@ -1,98 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.bpmn.infrastructure.service.level; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import org.camunda.bpm.engine.delegate.DelegateExecution; -import org.onap.so.bpmn.infrastructure.service.level.impl.ServiceLevelConstants; -import org.onap.so.client.exception.ExceptionBuilder; -import org.onap.so.db.catalog.beans.Workflow; -import org.onap.so.db.catalog.client.CatalogDbClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; - -/** - * Parent class for Service level upgrade Execution, it should be extended for service level upgrade tasks. - */ -public class ServiceLevelPreparable { - - protected static final Logger LOG = LoggerFactory.getLogger(ServiceLevelPreparable.class); - - @Autowired - protected ExceptionBuilder exceptionBuilder; - - @Autowired - protected CatalogDbClient catalogDbClient; - - /** - * Fetches workflow names based on the controller scope and operation name. - * - * @param scope Controller scope - * @param operationName healthcheck/softwareUpgrade - * @return String value of Workflow name - */ - protected String fetchWorkflowUsingScope(final String scope, String operationName) { - Optional wflName = Optional.empty(); - try { - List workflows = catalogDbClient.findWorkflowByOperationName(operationName); - if (!workflows.isEmpty()) { - wflName = Optional.ofNullable( - workflows.stream().filter(workflow -> workflow.getResourceTarget().equalsIgnoreCase(scope)) - .findFirst().get().getName()); - } - } catch (Exception e) { - // do nothing and assign the default workflow in finally - LOG.error("Error occurred while fetching workflow name from CatalogDb {}", e); - } finally { - if (wflName.isEmpty()) { - wflName = Optional.of(ServiceLevelConstants.WORKFLOW_OPERATIONS_MAP.get(operationName).get(scope)); - } - } - return wflName.get(); - - } - - /** - * This method validates the execution parameters to be passed for health check workflow. - * - * @param execution Delegate execution obj - * @param scope Controller scope * Throws workflow exception if validation fails - */ - protected void validateParamsWithScope(DelegateExecution execution, final String scope, List params) { - List invalidVariables = new ArrayList<>(); - for (String param : params) { - if (!execution.hasVariable(param) || execution.getVariable(param) == null - || String.valueOf(execution.getVariable(param)).isEmpty()) { - invalidVariables.add(param); - } - } - if (invalidVariables.size() > 0) { - LOG.error("Validation error for the {} health check attributes: {}", scope, invalidVariables); - exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE, - "Validation of health check workflow parameters failed for the scope: " + scope); - } - - } - -} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelConstants.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelConstants.java index 7b73fff20c..b0b12b5276 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelConstants.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelConstants.java @@ -38,6 +38,10 @@ public class ServiceLevelConstants { public static final String SW_UP_OPERATION = "ResourceSoftwareUpgrade"; public static final String CONTROLLER_STATUS = "ControllerStatus"; public static final int ERROR_CODE = 601; + public static final String PNF_COUNTER = "pnfCounter"; + public static final int COUNT_ZERO = 0; + public static final String PNF_NAME_LIST = "pnfNameList"; + public static final String PNF_SIZE = "pnfSize"; // TODO GenericVNFHealthCheck and GenericVnfSoftwareUpgrade workflow names should be updated once the workflow is // implemented. diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPostcheck.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPostcheck.java index fad28e315e..8e720c3e53 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPostcheck.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPostcheck.java @@ -8,6 +8,6 @@ import org.springframework.stereotype.Component; public class ServiceLevelPostcheck implements JavaDelegate { @Override public void execute(DelegateExecution delegateExecution) throws Exception { - // TODO : Set serviceInstance to aai + // Write your postcheck operations here, if any } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPreparation.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPreparation.java index 59884ecbc2..6cb3461001 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPreparation.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPreparation.java @@ -26,7 +26,7 @@ import java.util.List; import java.util.Map; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; -import org.onap.so.bpmn.infrastructure.service.level.ServiceLevelPreparable; +import org.onap.so.bpmn.infrastructure.service.level.ServiceLevel; import org.springframework.stereotype.Component; @@ -35,10 +35,10 @@ import org.springframework.stereotype.Component; * validation. */ @Component("ServiceLevelPreparation") -public class ServiceLevelPreparation extends ServiceLevelPreparable implements JavaDelegate { +public class ServiceLevelPreparation extends ServiceLevel implements JavaDelegate { private static final List PNF_HEALTH_CHECK_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID, - ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST, ServiceLevelConstants.PNF_NAME); + ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST); // TODO Update the list with vnf health check parameters if any validation needed private static final List VNF_HEALTH_CHECK_PARAMS = Collections.emptyList(); @@ -48,6 +48,9 @@ public class ServiceLevelPreparation extends ServiceLevelPreparable implements J @Override public void execute(DelegateExecution execution) throws Exception { + LOG.debug("Running execute block for activity id: {}, name: {}", execution.getCurrentActivityId(), + execution.getCurrentActivityName()); + if (execution.hasVariable(ServiceLevelConstants.RESOURCE_TYPE) && execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE) != null) { final String controllerScope = (String) execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE); @@ -60,6 +63,7 @@ public class ServiceLevelPreparation extends ServiceLevelPreparable implements J LOG.info("Parameters validated successfully for {}", wflName); execution.setVariable(ServiceLevelConstants.HEALTH_CHECK_WORKFLOW_TO_INVOKE, wflName); execution.setVariable(ServiceLevelConstants.CONTROLLER_STATUS, ServiceLevelConstants.EMPTY_STRING); + execution.setVariable(ServiceLevelConstants.PNF_COUNTER, ServiceLevelConstants.COUNT_ZERO); } else { exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE, "Invalid Controller scope to prepare resource level health check"); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelRequestDispatcher.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelRequestDispatcher.java index 5b20a86cb7..5d9295dc95 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelRequestDispatcher.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelRequestDispatcher.java @@ -23,6 +23,7 @@ package org.onap.so.bpmn.infrastructure.service.level.impl; import com.fasterxml.jackson.databind.ObjectMapper; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; +import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.ServiceInstance; import org.onap.aaiclient.client.aai.AAIRestClientI; import org.onap.aaiclient.client.aai.AAIRestClientImpl; @@ -34,7 +35,11 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; +import java.util.stream.Collector; +import java.util.stream.Collectors; import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.*; /** @@ -83,21 +88,18 @@ public class ServiceLevelRequestDispatcher implements JavaDelegate { Optional optionalSi = restClient.getServiceInstanceById(serviceInstanceId, serviceType, globalSubscriberId); - if (!optionalSi.isPresent()) { - - } - optionalSi.ifPresentOrElse(serviceInstance -> { - final String pnfName = serviceInstance.getRelationshipList().getRelationship().stream() - .filter(x -> x.getRelatedTo().contains("pnf")).findFirst().get().getRelationshipData().stream() - .filter(data -> data.getRelationshipKey().contains("pnf.pnf-name")).findFirst().get() - .getRelationshipValue(); - if (pnfName == null || pnfName.isEmpty()) { + final List pnfNameList = serviceInstance.getRelationshipList().getRelationship().stream() + .filter(x -> x.getRelatedTo().contains("pnf")).flatMap(x -> x.getRelationshipData().stream()) + .filter(data -> data.getRelationshipKey().contains("pnf.pnf-name")) + .map(x -> x.getRelationshipValue()).collect(Collectors.toList()); + if (pnfNameList == null || pnfNameList.size() == 0) { logger.warn( "Unable to find the PNF for service instance id: " + serviceInstance.getServiceInstanceId()); return; } - delegateExecution.setVariable(ServiceLevelConstants.PNF_NAME, pnfName); + delegateExecution.setVariable(ServiceLevelConstants.PNF_NAME_LIST, pnfNameList); + delegateExecution.setVariable(ServiceLevelConstants.PNF_SIZE, pnfNameList.size()); delegateExecution.setVariable(ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.PNF); }, () -> { throwExceptionWithWarn(delegateExecution, "Unable to find the service instance: " + serviceInstanceId); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelUpgrade.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelUpgrade.java index 9d7d8efb65..a3a8f6e714 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelUpgrade.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelUpgrade.java @@ -26,14 +26,14 @@ import java.util.List; import java.util.Map; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; -import org.onap.so.bpmn.infrastructure.service.level.ServiceLevelPreparable; +import org.onap.so.bpmn.infrastructure.service.level.ServiceLevel; import org.springframework.stereotype.Component; @Component -public class ServiceLevelUpgrade extends ServiceLevelPreparable implements JavaDelegate { +public class ServiceLevelUpgrade extends ServiceLevel implements JavaDelegate { private static final List PNF_SOFTWARE_UP_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID, - ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST, ServiceLevelConstants.PNF_NAME); + ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST); // TODO Update the list with vnf software upgrade parameters if any validation needed private static final List VNF_SOFTWARE_UP_PARAMS = Collections.emptyList(); @@ -44,6 +44,9 @@ public class ServiceLevelUpgrade extends ServiceLevelPreparable implements JavaD @Override public void execute(DelegateExecution execution) throws Exception { + LOG.debug("Running execute block for activity id: {}, name: {}", execution.getCurrentActivityId(), + execution.getCurrentActivityName()); + if (execution.hasVariable(ServiceLevelConstants.RESOURCE_TYPE) && execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE) != null) { final String controllerScope = (String) execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE); @@ -54,7 +57,8 @@ public class ServiceLevelUpgrade extends ServiceLevelPreparable implements JavaD validateParamsWithScope(execution, controllerScope, SOFTWARE_UP_PARAMS_MAP.get(controllerScope)); LOG.info("Parameters validated successfully for {}", wflName); execution.setVariable(ServiceLevelConstants.SOFTWARE_WORKFLOW_TO_INVOKE, wflName); - execution.setVariable(ServiceLevelConstants.CONTROLLER_STATUS, ""); + execution.setVariable(ServiceLevelConstants.CONTROLLER_STATUS, ServiceLevelConstants.EMPTY_STRING); + execution.setVariable(ServiceLevelConstants.PNF_COUNTER, ServiceLevelConstants.COUNT_ZERO); } else { exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE, "Invalid Controller scope for resource level software upgrade"); -- cgit 1.2.3-korg