From e01546664d8d945ae83c625ab278b04ee0b9a331 Mon Sep 17 00:00:00 2001 From: tragait Date: Thu, 23 Jul 2020 17:49:06 +0100 Subject: [SO] create service upgrade workflow Issue-ID: SO-2925 Signed-off-by: tragait Change-Id: Ia10497fed1f42dea3e0469bc08ba0169862d3e71 Signed-off-by: tragait --- .../resources/process/ServiceLevelUpgrade.bpmn | 377 +++++++++++++++++++++ .../process/ServiceLevelUpgradeTest.java | 255 ++++++++++++++ .../resources/request/ServiceLevelUpgradeTest.json | 48 +++ .../src/test/resources/response/Pnf_aai.json | 42 +++ .../response/ServiceLevelUpgradeTest.json | 27 ++ .../ServiceLevelUpgradeTest_catalogdb.json | 39 +++ .../resources/response/Service_instance_aai.json | 35 ++ .../level/AbstractServiceLevelPreparable.java | 15 +- .../service/level/impl/ServiceLevelConstants.java | 20 ++ .../service/level/impl/ServiceLevelPostcheck.java | 13 + .../level/impl/ServiceLevelPreparation.java | 37 +- .../level/impl/ServiceLevelRequestDispatcher.java | 131 +++++++ .../service/level/impl/ServiceLevelUpgrade.java | 54 +++ .../level/impl/UpdateServiceInstanceInAai.java | 123 +++++++ .../service/level/ServiceLevelPreparationTest.java | 24 +- .../onap/aaiclient/client/aai/AAIRestClientI.java | 7 + .../aaiclient/client/aai/AAIRestClientImpl.java | 24 ++ 17 files changed, 1231 insertions(+), 40 deletions(-) create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ServiceLevelUpgrade.bpmn create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/ServiceLevelUpgradeTest.java create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/test/resources/request/ServiceLevelUpgradeTest.json create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/Pnf_aai.json create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/ServiceLevelUpgradeTest.json create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/ServiceLevelUpgradeTest_catalogdb.json create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/Service_instance_aai.json create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelConstants.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPostcheck.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelRequestDispatcher.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelUpgrade.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/UpdateServiceInstanceInAai.java 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 new file mode 100644 index 0000000000..a1d4178962 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/ServiceLevelUpgrade.bpmn @@ -0,0 +1,377 @@ + + + + + Flow_0nrz340 + + + Flow_0nrz340 + Flow_1b392qs + + + Flow_10jgbxm + + + + Flow_1y3cptr + Flow_0y1ebox + Flow_0mbp7mv + + + Flow_0y1ebox + + + + Flow_0trmo7s + Flow_1z06yyv + Flow_0mxq0qe + + + Flow_0mxq0qe + + + + Flow_1ru18s3 + Flow_1tcnzdx + Flow_0l67uzl + + + Flow_1tcnzdx + + + + Flow_1z06yyv + Flow_01gwzx9 + + + Flow_05ohtnj + Flow_1ru18s3 + + + Flow_1v0mxe7 + Flow_1p4xkdj + + + Flow_1b392qs + Flow_1v0mxe7 + import org.onap.so.bpmn.infrastructure.scripts.* +def pnfSwUpgrade = new PNFSoftwareUpgrade() +pnfSwUpgrade.sendResponse(execution) + + + Flow_0l67uzl + Flow_0frhsd0 + import org.onap.so.bpmn.infrastructure.scripts.* +def pnfSwUpgrade = new PNFSoftwareUpgrade() +pnfSwUpgrade.prepareCompletion(execution) + + + Flow_0frhsd0 + Flow_10jgbxm + + + + Flow_0iayg6u + + + + Flow_0iayg6u + Flow_0lb7zv5 + import org.onap.so.bpmn.infrastructure.scripts.* +def pnfSwUpgrade = new PNFSoftwareUpgrade() +pnfSwUpgrade.prepareFalloutHandler(execution) + + + Flow_0lb7zv5 + Flow_1peoyur + + + Flow_1peoyur + + + + + + + + + + + + + + #{execution.getVariable("ControllerStatus").equals("Success")} + + + + + + #{execution.getVariable("ControllerStatus").equals("Success")} + + + + + #{execution.getVariable("ControllerStatus").equals("Success")} + + + + + + + + + + + + Flow_1p4xkdj + Flow_0trmo7s + + + + + + + + + + + + + Flow_01gwzx9 + Flow_1y3cptr + + + + Flow_0mbp7mv + Flow_0dyc3kv + + + + Flow_0dyc3kv + Flow_05ohtnj + Flow_0ny61qm + + + #{execution.getVariable("ControllerStatus").equals("Success")} + + + Flow_0ny61qm + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 new file mode 100644 index 0000000000..805597cd12 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/test/java/org/onap/so/bpmn/infrastructure/process/ServiceLevelUpgradeTest.java @@ -0,0 +1,255 @@ +/*- + * ============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.process; + +import com.google.protobuf.Struct; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.junit.Before; +import org.junit.Test; +import org.onap.aaiclient.client.aai.AAIVersion; +import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers; +import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader; +import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput; +import org.onap.so.BaseBPMNTest; +import org.onap.so.GrpcNettyServer; +import org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames; +import org.onap.so.bpmn.mock.FileUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static org.assertj.core.api.Assertions.fail; +import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat; + +/** + * Basic Integration test for ServiceLevelUpgrade.bpmn workflow. + */ +public class ServiceLevelUpgradeTest extends BaseBPMNTest { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + private static final long WORKFLOW_WAIT_TIME = 1000L; + + private static final String TEST_PROCESSINSTANCE_KEY = "ServiceLevelUpgrade"; + private static final AAIVersion VERSION = AAIVersion.LATEST; + 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 CLASSNAME = getClass().getSimpleName(); + private String requestObject; + private String responseObject; + + @Autowired + private GrpcNettyServer grpcNettyServer; + + @Before + public void setUp() throws IOException { + actionNames[0] = "healthCheck"; + actionNames[1] = "preCheck"; + actionNames[2] = "downloadNESw"; + actionNames[3] = "activateNESw"; + actionNames[4] = "postCheck"; + + executionVariables.clear(); + + requestObject = FileUtil.readResourceFile("request/" + CLASSNAME + ".json"); + responseObject = FileUtil.readResourceFile("response/" + CLASSNAME + ".json"); + + executionVariables.put("bpmnRequest", requestObject); + executionVariables.put("requestId", REQUEST_ID); + executionVariables.put("serviceInstanceId", SERVICE_INSTANCE_ID); + + + /** + * This variable indicates that the flow was invoked asynchronously. It's injected by {@link WorkflowProcessor}. + */ + executionVariables.put("isAsyncProcess", "true"); + executionVariables.put(ExecutionVariableNames.PRC_CUSTOMIZATION_UUID, "38dc9a92-214c-11e7-93ae-92361f002680"); + + /** + * Temporary solution to add pnfCorrelationId to context. this value is getting from the request to SO api + * handler and then convert to CamudaInput + */ + executionVariables.put(ExecutionVariableNames.PNF_CORRELATION_ID, "PNFDemo"); + } + + + @Test + public void workflow_validInput_expectedOutput() throws InterruptedException { + + mockCatalogDb(); + mockRequestDb(); + mockAai(); + + final String msoRequestId = UUID.randomUUID().toString(); + executionVariables.put(ExecutionVariableNames.MSO_REQUEST_ID, msoRequestId); + + final String testBusinessKey = UUID.randomUUID().toString(); + logger.info("Test the process instance: {} with business key: {}", TEST_PROCESSINSTANCE_KEY, testBusinessKey); + + ProcessInstance pi = + runtimeService.startProcessInstanceByKey(TEST_PROCESSINSTANCE_KEY, testBusinessKey, executionVariables); + + int waitCount = 10; + while (!isProcessInstanceEnded() && waitCount >= 0) { + Thread.sleep(WORKFLOW_WAIT_TIME); + waitCount--; + } + + // 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"); + + List detailedMessages = grpcNettyServer.getDetailedMessages(); + assertThat(detailedMessages.size() == 5); + int count = 0; + try { + for (ExecutionServiceInput eSI : detailedMessages) { + for (String action : actionNames) { + if (action.equals(eSI.getActionIdentifiers().getActionName()) + && eSI.getCommonHeader().getRequestId().equals(msoRequestId)) { + checkWithActionName(eSI, action); + count++; + } + } + } + } catch (Exception e) { + e.printStackTrace(); + fail("PNFSoftwareUpgrade request exception", e); + } + assertThat(count == actionNames.length); + } + + private boolean isProcessInstanceEnded() { + return runtimeService.createProcessInstanceQuery().processDefinitionKey(TEST_PROCESSINSTANCE_KEY) + .singleResult() == null; + } + + private void checkWithActionName(ExecutionServiceInput executionServiceInput, String action) { + + logger.info("Checking the " + action + " request"); + ActionIdentifiers actionIdentifiers = executionServiceInput.getActionIdentifiers(); + + /** + * the fields of actionIdentifiers should match the one in the response/PnfHealthCheck_catalogdb.json. + */ + assertThat(actionIdentifiers.getBlueprintName()).isEqualTo("test_pnf_software_upgrade_restconf"); + assertThat(actionIdentifiers.getBlueprintVersion()).isEqualTo("1.0.0"); + assertThat(actionIdentifiers.getActionName()).isEqualTo(action); + assertThat(actionIdentifiers.getMode()).isEqualTo("async"); + + CommonHeader commonHeader = executionServiceInput.getCommonHeader(); + assertThat(commonHeader.getOriginatorId()).isEqualTo("SO"); + + Struct payload = executionServiceInput.getPayload(); + Struct requeststruct = payload.getFieldsOrThrow(action + "-request").getStructValue(); + + assertThat(requeststruct.getFieldsOrThrow("resolution-key").getStringValue()).isEqualTo("PNFDemo"); + Struct propertiesStruct = requeststruct.getFieldsOrThrow(action + "-properties").getStructValue(); + + assertThat(propertiesStruct.getFieldsOrThrow("pnf-name").getStringValue()).isEqualTo("PNFDemo"); + assertThat(propertiesStruct.getFieldsOrThrow("service-model-uuid").getStringValue()) + .isEqualTo("d88da85c-d9e8-4f73-b837-3a72a431622b"); + assertThat(propertiesStruct.getFieldsOrThrow("pnf-customization-uuid").getStringValue()) + .isEqualTo("38dc9a92-214c-11e7-93ae-92361f002680"); + } + + private void mockAai() { + + 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 aaiServiceInstanceEntry = FileUtil.readResourceFile("response/Service_instance_aai.json"); + + /** + * PUT the PNF correlation ID to AAI. + */ + wireMockServer.stubFor(put(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo"))); + + /** + * Get the PNF entry from AAI. + */ + wireMockServer.stubFor( + get(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo")).willReturn(okJson(aaiPnfEntry))); + + /** + * Post the pnf to AAI + */ + wireMockServer.stubFor(post(urlEqualTo("/aai/" + VERSION + "/network/pnfs/pnf/PNFDemo"))); + + /** + * Get the Service Instance to AAI. + */ + wireMockServer.stubFor(get(urlEqualTo("/aai/" + VERSION + sIUrl)).willReturn(okJson(aaiServiceInstanceEntry))); + + /** + * Post the Service Instance to AAI. + */ + wireMockServer.stubFor(post(urlEqualTo("/aai/" + VERSION + sIUrl))); + } + + private void mockRequestDb() { + /** + * Update Request DB + */ + wireMockServer.stubFor(put(urlEqualTo("/infraActiveRequests/" + REQUEST_ID))); + + } + + /** + * Mock the catalobdb rest interface. + */ + private void mockCatalogDb() { + + String catalogdbClientResponse = FileUtil.readResourceFile("response/" + CLASSNAME + "_catalogdb.json"); + + + /** + * Return valid json for the model UUID in the request file. + */ + wireMockServer + .stubFor(get(urlEqualTo("/v2/serviceResources?serviceModelUuid=d88da85c-d9e8-4f73-b837-3a72a431622b")) + .willReturn(okJson(responseObject))); + + /** + * Return valid json for the service model InvariantUUID as specified in the request file. + */ + wireMockServer.stubFor( + get(urlEqualTo("/v2/serviceResources?serviceModelInvariantUuid=fe41489e-1563-46a3-b90a-1db629e4375b")) + .willReturn(okJson(responseObject))); + + /** + * Return valid spring data rest json for the service model UUID as specified in the request file. + */ + wireMockServer.stubFor(get(urlEqualTo( + "/pnfResourceCustomization/search/findPnfResourceCustomizationByModelUuid?SERVICE_MODEL_UUID=d88da85c-d9e8-4f73-b837-3a72a431622b")) + .willReturn(okJson(catalogdbClientResponse))); + } + +} diff --git a/bpmn/so-bpmn-infrastructure-flows/src/test/resources/request/ServiceLevelUpgradeTest.json b/bpmn/so-bpmn-infrastructure-flows/src/test/resources/request/ServiceLevelUpgradeTest.json new file mode 100644 index 0000000000..b5cce60094 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/test/resources/request/ServiceLevelUpgradeTest.json @@ -0,0 +1,48 @@ +{ + "requestDetails":{ + "subscriberInfo":{ + "globalSubscriberId":"ETE_Customer_807c7a02-249c-4db8-9fa9-bee973fe08ce" + }, + "requestInfo":{ + "suppressRollback": false, + "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", + "requestorId": "demo", + "instanceName":"testInstanceName", + "source":"VID" + }, + "cloudConfiguration":{ + "lcpCloudRegionId": "RegionOne", + "tenantId": "7320ec4a5b9d4589ba7c4412ccfd290f", + "cloudOwner": "CloudOwner" + }, + "requestParameters":{ + "subscriptionServiceType": "pNF", + "userParams":[ + { + "name":"targetSoftwareVersion", + "value":"demo-sw-ver2.0.0" + }, + { + "name":"pnfName", + "value":"PNFDemo" + } + ], + "aLaCarte": false, + "payload": "{\"k1\": \"v1\"}" + }, + "project":{ + "projectName": "ServiceLevelUpgrade" + }, + "owningEntity":{ + "owningEntityId":"67f2e84c-734d-4e90-a1e4-d2ffa2e75849", + "owningEntityName":"OE-Test" + }, + "modelInfo":{ + "modelVersion": "2.0", + "modelVersionId": "d88da85c-d9e8-4f73-b837-3a72a431622b", + "modelInvariantId": "fe41489e-1563-46a3-b90a-1db629e4375b", + "modelName": "Demo_svc", + "modelType": "service" + } + } +} \ 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 new file mode 100644 index 0000000000..865600c800 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/Pnf_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/ServiceLevelUpgradeTest.json b/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/ServiceLevelUpgradeTest.json new file mode 100644 index 0000000000..ec92552c5e --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/ServiceLevelUpgradeTest.json @@ -0,0 +1,27 @@ +{ + "serviceResources":{ + "modelInfo":{ + "modelVersion": "2.0", + "modelVersionId": "d88da85c-d9e8-4f73-b837-3a72a431622b", + "modelInvariantId": "fe41489e-1563-46a3-b90a-1db629e4375b", + "modelName": "Demo_svc", + "modelType": "service" + }, + "serviceType":"pNF", + "environmentContext":"Luna", + "serviceRole":"NA", + "workloadContext":"Oxygen", + "serviceVnfs":[ + + ], + "serviceNetworks":[ + + ], + "serviceAllottedResources":[ + + ], + "configResource":[ + + ] + } +} \ No newline at end of file diff --git a/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/ServiceLevelUpgradeTest_catalogdb.json b/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/ServiceLevelUpgradeTest_catalogdb.json new file mode 100644 index 0000000000..faec947fec --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/ServiceLevelUpgradeTest_catalogdb.json @@ -0,0 +1,39 @@ +{ + "_embedded": { + "pnfResourceCustomization": [ + { + "modelCustomizationUUID": "38dc9a92-214c-11e7-93ae-92361f002680", + "modelInstanceName": "PNF routing", + "created": "2019-03-08 12:00:29.000", + "nfFunction": "routing", + "nfType": "routing", + "nfRole": "routing", + "nfNamingCode": "routing", + "multiStageDesign": null, + "resourceInput": null, + "blueprintName": "test_pnf_software_upgrade_restconf", + "blueprintVersion": "1.0.0", + "skipPostInstConf": false, + "softwareVersion": "1.0.0", + "creationTimestamp": "2019-03-08T12:00:29.000+0000", + "controllerActor": "cds", + "_links": { + "self": { + "href": "http://localhost:41023/pnfResourceCustomization/38dc9a92-214c-11e7-93ae-92361f002680" + }, + "pnfResourceCustomization": { + "href": "http://localhost:41023/pnfResourceCustomization/38dc9a92-214c-11e7-93ae-92361f002680" + }, + "pnfResources": { + "href": "http://localhost:41023/pnfResourceCustomization/38dc9a92-214c-11e7-93ae-92361f002680/pnfResources" + } + } + } + ] + }, + "_links": { + "self": { + "href": "http://localhost:41023/pnfResourceCustomization/search/findPnfResourceCustomizationByModelUuid?SERVICE_MODEL_UUID=4df8b6de-2083-11e7-93ae-92361f002676" + } + } +} \ 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 new file mode 100644 index 0000000000..53fb210478 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/test/resources/response/Service_instance_aai.json @@ -0,0 +1,35 @@ +{ + "service-instance-id": "5df8b6de-2083-11e7-93ae-92361f002676", + "service-instance-name": "Service_Ete_Name123452c4-3d7f-42ce-8188-818fab951269", + "environment-context": "General_Revenue-Bearing", + "workload-context": "Production", + "model-version-id": "d88da85c-d9e8-4f73-b837-3a72a431622b", + "modelInvariantId": "fe41489e-1563-46a3-b90a-1db629e4375b", + "resource-version": "1595258335377", + "selflink": "restconf/config/GENERIC-RESOURCE-API:services/service/5df8b6de-2083-11e7-93ae-92361f002676/service-data/service-topology/", + "orchestration-status": "Assigned", + "relationship-list": { + "relationship": [ + { + "related-to": "owning-entity", + "related-link": "/aai/v11/business/owning-entities/owning-entity/67f2e84c-734d-4e90-a1e4-d2ffa2e75849", + "relationship-data": [ + { + "relationship-key": "owning-entity.owning-entity-id", + "relationship-value": "67f2e84c-734d-4e90-a1e4-d2ffa2e75849" + } + ] + }, + { + "related-to": "pnf", + "related-link": "/aai/v11/network/pnfs/pnf/PNFDemo", + "relationship-data": [ + { + "relationship-key": "pnf.pnf-name", + "relationship-value": "PNFDemo" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/AbstractServiceLevelPreparable.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/AbstractServiceLevelPreparable.java index 36db549486..0671354bd6 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/AbstractServiceLevelPreparable.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/AbstractServiceLevelPreparable.java @@ -21,6 +21,7 @@ package org.onap.so.bpmn.infrastructure.service.level; 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.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,15 +34,6 @@ import java.util.List; */ public abstract class AbstractServiceLevelPreparable { - protected static final String WORKFLOW_TO_INVOKE = "healthCheckWorkflow"; - protected static final String GENERIC_PNF_HEALTH_CHECK_WORKFLOW = "GenericPnfHealthCheck"; - protected static final String GENERIC_PNF_SOFTWARE_UPGRADE_WORKFLOW = "GenericPnfSoftwareUpgrade"; - protected static final String RESOURCE_TYPE = "RESOURCE_TYPE"; - protected static final int ERROR_CODE = 601; - - // TODO This value needs to be updated once vnf health check workflow is available - protected static final String GENERIC_VNF_HEALTH_CHECK_WORKFLOW = "GenericVNFHealthCheck"; - protected static final Logger LOG = LoggerFactory.getLogger(AbstractServiceLevelPreparable.class); @Autowired @@ -61,8 +53,7 @@ public abstract class AbstractServiceLevelPreparable { * @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) - throws Exception { + 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 @@ -72,7 +63,7 @@ public abstract class AbstractServiceLevelPreparable { } if (invalidVariables.size() > 0) { LOG.error("Validation error for the {} health check attributes: {}", scope, invalidVariables); - exceptionBuilder.buildAndThrowWorkflowException(execution, ERROR_CODE, + 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 new file mode 100644 index 0000000000..34ebb308c3 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelConstants.java @@ -0,0 +1,20 @@ +package org.onap.so.bpmn.infrastructure.service.level.impl; + +public class ServiceLevelConstants { + public static final String BPMN_REQUEST = "bpmnRequest"; + public static final String RESOURCE_TYPE = "resourceType"; + public static final String SERVICE_INSTANCE_ID = "serviceInstanceId"; + public static final String PNF_NAME = "pnfName"; + public static final String PNF = "pnf"; + public static final String VNF = "vnf"; + public static final String EMPTY_STRING = ""; + public static final String WORKFLOW_TO_INVOKE = "healthCheckWorkflow"; + public static final String SOFTWARE_WORKFLOW_TO_INVOKE = "softwareUpgradeWorkflow"; + public static final String GENERIC_PNF_HEALTH_CHECK_WORKFLOW = "GenericPnfHealthCheck"; + public static final String PNF_SOFTWARE_UPGRADE_WORKFLOW = "PNFSoftwareUpgrade"; + public static final String CONTROLLER_STATUS = "ControllerStatus"; + public static final int ERROR_CODE = 601; + // TODO This value needs to be updated once vnf health check workflow is available + protected static final String GENERIC_VNF_HEALTH_CHECK_WORKFLOW = "GenericVNFHealthCheck"; + +} 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 new file mode 100644 index 0000000000..fad28e315e --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelPostcheck.java @@ -0,0 +1,13 @@ +package org.onap.so.bpmn.infrastructure.service.level.impl; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.delegate.JavaDelegate; +import org.springframework.stereotype.Component; + +@Component +public class ServiceLevelPostcheck implements JavaDelegate { + @Override + public void execute(DelegateExecution delegateExecution) throws Exception { + // TODO : Set serviceInstance to aai + } +} 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 52521ce16b..5b772760f0 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 @@ -27,7 +27,6 @@ import org.springframework.stereotype.Component; import java.util.Arrays; import java.util.List; - /** * Fetches health check workflow based on the controller_scope. Invoke the corresponding health check workflow after * validation. @@ -35,24 +34,26 @@ import java.util.List; @Component("ServiceLevelPreparation") public class ServiceLevelPreparation extends AbstractServiceLevelPreparable implements JavaDelegate { - // Health check parameters to be validated for pnf resource - private static final List PNF_HC_PARAMS = Arrays.asList("SERVICE_MODEL_INFO", "SERVICE_INSTANCE_NAME", - "PNF_CORRELATION_ID", "MODEL_UUID", "PNF_UUID", "PRC_BLUEPRINT_NAME", "PRC_BLUEPRINT_VERSION", - "PRC_CUSTOMIZATION_UUID", "RESOURCE_CUSTOMIZATION_UUID_PARAM", "PRC_INSTANCE_NAME", "PRC_CONTROLLER_ACTOR", - "REQUEST_PAYLOAD"); + private static final List PNF_HC_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID, + ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST, ServiceLevelConstants.PNF_NAME); @Override public void execute(DelegateExecution execution) throws Exception { - if (execution.hasVariable(RESOURCE_TYPE) && execution.getVariable(RESOURCE_TYPE) != null) { - final String controllerScope = (String) execution.getVariable(RESOURCE_TYPE); + if (execution.hasVariable(ServiceLevelConstants.RESOURCE_TYPE) + && execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE) != null) { + final String controllerScope = (String) execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE); LOG.debug("Scope retrieved from delegate execution: " + controllerScope); final String wflName = fetchWorkflowUsingScope(execution, controllerScope); - LOG.debug("Health check workflow fetched for the scope: {}", wflName); - validateParamsWithScope(execution, controllerScope, PNF_HC_PARAMS); - LOG.info("Parameters validated successfully for {}", wflName); - execution.setVariable(WORKFLOW_TO_INVOKE, wflName); + LOG.debug("Health check workflow fetched for the scope: {} is: {}", controllerScope, wflName); + + if (ServiceLevelConstants.PNF.equalsIgnoreCase(controllerScope)) { + validateParamsWithScope(execution, controllerScope, PNF_HC_PARAMS); + LOG.info("Parameters validated successfully for {}", wflName); + } + execution.setVariable(ServiceLevelConstants.WORKFLOW_TO_INVOKE, wflName); + execution.setVariable(ServiceLevelConstants.CONTROLLER_STATUS, ServiceLevelConstants.EMPTY_STRING); } else { - exceptionBuilder.buildAndThrowWorkflowException(execution, ERROR_CODE, + exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE, "Controller scope not found to invoke resource level health check"); } } @@ -61,14 +62,14 @@ public class ServiceLevelPreparation extends AbstractServiceLevelPreparable impl public String fetchWorkflowUsingScope(DelegateExecution execution, final String scope) { String wflName = null; switch (scope.toLowerCase()) { - case "pnf": - wflName = GENERIC_PNF_HEALTH_CHECK_WORKFLOW; + case ServiceLevelConstants.PNF: + wflName = ServiceLevelConstants.GENERIC_PNF_HEALTH_CHECK_WORKFLOW; break; - case "vnf": - wflName = GENERIC_VNF_HEALTH_CHECK_WORKFLOW; + case ServiceLevelConstants.VNF: + wflName = ServiceLevelConstants.GENERIC_VNF_HEALTH_CHECK_WORKFLOW; break; default: - exceptionBuilder.buildAndThrowWorkflowException(execution, ERROR_CODE, + exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE, "No valid health check work flow retrieved for the scope: " + scope); } return wflName; 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 new file mode 100644 index 0000000000..5b20a86cb7 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelRequestDispatcher.java @@ -0,0 +1,131 @@ +/*- + * ============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.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.ServiceInstance; +import org.onap.aaiclient.client.aai.AAIRestClientI; +import org.onap.aaiclient.client.aai.AAIRestClientImpl; +import org.onap.so.bpmn.core.json.JsonUtils; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.serviceinstancebeans.RequestDetails; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import java.io.IOException; +import java.util.Optional; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.*; + +/** + * This implementation of {@link JavaDelegate} is used to populate the execution object for Service level upgrade + */ +@Component +public class ServiceLevelRequestDispatcher implements JavaDelegate { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + @Autowired + private ExceptionBuilder exceptionUtil; + + @Autowired + private ObjectMapper mapper; + + @Override + public void execute(DelegateExecution delegateExecution) throws Exception { + logger.debug("Running execute block for activity id: {}, name: {}", delegateExecution.getCurrentActivityId(), + delegateExecution.getCurrentActivityName()); + + RequestDetails bpmnRequestDetails = requestVerification(delegateExecution); + + final String serviceInstanceId = String.valueOf(delegateExecution.getVariable(SERVICE_INSTANCE_ID)); + final String serviceType = bpmnRequestDetails.getRequestParameters().getSubscriptionServiceType(); + final String globalSubscriberId = bpmnRequestDetails.getSubscriberInfo().getGlobalSubscriberId(); + + final String modelInvariantId = bpmnRequestDetails.getModelInfo().getModelInvariantId(); + final String modelId = bpmnRequestDetails.getModelInfo().getModelUuid(); + final String modelVersion = bpmnRequestDetails.getModelInfo().getModelVersion(); + + if (ServiceLevelConstants.PNF.equalsIgnoreCase(serviceType)) { + getAndSetPnfNameFromServiceInstance(serviceInstanceId, serviceType, globalSubscriberId, delegateExecution); + } + + // TODO : handling for vnf + + logger.trace("Completed dispatcher request for ServiceLevelUpgrade."); + } + + private void getAndSetPnfNameFromServiceInstance(final String serviceInstanceId, final String serviceType, + final String globalSubscriberId, DelegateExecution delegateExecution) { + + AAIRestClientI restClient = new AAIRestClientImpl(); + + 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()) { + logger.warn( + "Unable to find the PNF for service instance id: " + serviceInstance.getServiceInstanceId()); + return; + } + delegateExecution.setVariable(ServiceLevelConstants.PNF_NAME, pnfName); + delegateExecution.setVariable(ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.PNF); + }, () -> { + throwExceptionWithWarn(delegateExecution, "Unable to find the service instance: " + serviceInstanceId); + }); + } + + private RequestDetails requestVerification(DelegateExecution delegateExecution) throws IOException { + RequestDetails bpmnRequestDetails = mapper.readValue(JsonUtils.getJsonValue( + String.valueOf(delegateExecution.getVariable(ServiceLevelConstants.BPMN_REQUEST)), "requestDetails"), + RequestDetails.class); + + throwIfNull(delegateExecution, bpmnRequestDetails.getModelInfo(), SERVICE_MODEL_INFO); + throwIfNull(delegateExecution, bpmnRequestDetails.getRequestInfo(), "RequestInfo"); + throwIfNull(delegateExecution, bpmnRequestDetails.getRequestParameters(), "RequestParameters"); + throwIfNull(delegateExecution, bpmnRequestDetails.getRequestParameters().getUserParams(), "UserParams"); + + return bpmnRequestDetails; + } + + private void throwIfNull(DelegateExecution delegateExecution, Object obj, String param) { + if (obj == null) { + throwExceptionWithWarn(delegateExecution, + "Unable to find the parameter: " + param + " in the execution context"); + } + } + + private void throwExceptionWithWarn(DelegateExecution delegateExecution, String exceptionMsg) { + logger.warn(exceptionMsg); + exceptionUtil.buildAndThrowWorkflowException(delegateExecution, ServiceLevelConstants.ERROR_CODE, exceptionMsg); + } +} 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 new file mode 100644 index 0000000000..dfc77d6f0c --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/ServiceLevelUpgrade.java @@ -0,0 +1,54 @@ +package org.onap.so.bpmn.infrastructure.service.level.impl; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.delegate.JavaDelegate; +import org.onap.so.bpmn.infrastructure.service.level.AbstractServiceLevelPreparable; +import org.springframework.stereotype.Component; +import java.util.Arrays; +import java.util.List; + +@Component +public class ServiceLevelUpgrade extends AbstractServiceLevelPreparable implements JavaDelegate { + + private static final List PNF_SWU_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID, + ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST, ServiceLevelConstants.PNF_NAME); + + @Override + protected String fetchWorkflowUsingScope(DelegateExecution execution, String scope) { + String wflName = null; + switch (scope.toLowerCase()) { + case ServiceLevelConstants.PNF: + wflName = ServiceLevelConstants.PNF_SOFTWARE_UPGRADE_WORKFLOW; + break; + case ServiceLevelConstants.VNF: + wflName = ServiceLevelConstants.GENERIC_VNF_HEALTH_CHECK_WORKFLOW; + break; + default: + exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE, + "No valid health check work flow retrieved for the scope: " + scope); + } + return wflName; + } + + @Override + public void execute(DelegateExecution execution) throws Exception { + if (execution.hasVariable(ServiceLevelConstants.RESOURCE_TYPE) + && execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE) != null) { + final String controllerScope = (String) execution.getVariable(ServiceLevelConstants.RESOURCE_TYPE); + LOG.debug("Scope retrieved from delegate execution: " + controllerScope); + final String wflName = fetchWorkflowUsingScope(execution, controllerScope); + LOG.debug("Health check workflow fetched for the scope: {} is: {}", controllerScope, wflName); + + if ("pnf".equalsIgnoreCase(controllerScope)) { + validateParamsWithScope(execution, controllerScope, PNF_SWU_PARAMS); + LOG.info("Parameters validated successfully for {}", wflName); + execution.setVariable(ServiceLevelConstants.SOFTWARE_WORKFLOW_TO_INVOKE, wflName); + execution.setVariable(ServiceLevelConstants.CONTROLLER_STATUS, ""); + } + + } else { + exceptionBuilder.buildAndThrowWorkflowException(execution, ServiceLevelConstants.ERROR_CODE, + "Controller scope not found to invoke resource level health check"); + } + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/UpdateServiceInstanceInAai.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/UpdateServiceInstanceInAai.java new file mode 100644 index 0000000000..c9bd607b8b --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/service/level/impl/UpdateServiceInstanceInAai.java @@ -0,0 +1,123 @@ +/*- + * ============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.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.ServiceInstance; +import org.onap.aaiclient.client.aai.AAIRestClientI; +import org.onap.aaiclient.client.aai.AAIRestClientImpl; +import org.onap.so.bpmn.core.json.JsonUtils; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.serviceinstancebeans.RequestDetails; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import java.io.IOException; +import java.util.Optional; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.SERVICE_MODEL_INFO; + +@Component +public class UpdateServiceInstanceInAai implements JavaDelegate { + + @Autowired + private ExceptionBuilder exceptionUtil; + + private final Logger logger = LoggerFactory.getLogger(getClass()); + private static final String BPMN_REQUEST = "bpmnRequest"; + private static final String PNF_RESOURCE = "pnf"; + private static final String SERVICE_INSTANCE_ID = "serviceInstanceId"; + + // ERROR CODE for variable not found in the delegation Context + private static final int ERROR_CODE = 601; + + @Autowired + private ObjectMapper mapper; + + @Override + public void execute(DelegateExecution delegateExecution) throws Exception { + logger.debug("Running execute block for activity id: {}, name: {}", delegateExecution.getCurrentActivityId(), + delegateExecution.getCurrentActivityName()); + + RequestDetails bpmnRequestDetails = requestVerification(delegateExecution); + + final String serviceInstanceId = String.valueOf(delegateExecution.getVariable(SERVICE_INSTANCE_ID)); + final String serviceType = bpmnRequestDetails.getRequestParameters().getSubscriptionServiceType(); + final String globalSubscriberId = bpmnRequestDetails.getSubscriberInfo().getGlobalSubscriberId(); + + final String modelId = bpmnRequestDetails.getModelInfo().getModelUuid(); + + if (PNF_RESOURCE.equalsIgnoreCase(serviceType)) { + getAndSetServiceInstance(serviceInstanceId, serviceType, globalSubscriberId, modelId); + } + + // TODO : handling for vnf + + logger.trace("Completed updating request for ServiceLevelUpgrade."); + } + + private void getAndSetServiceInstance(final String serviceInstanceId, final String serviceType, + final String globalSubscriberId, String modelVersionId) { + + AAIRestClientI restClient = new AAIRestClientImpl(); + + Optional optionalSi = + restClient.getServiceInstanceById(serviceInstanceId, serviceType, globalSubscriberId); + + if (!optionalSi.isPresent()) { + // throwExceptionWithWarn(delegateExecution, "Unable to find the service instance: " + serviceInstanceId); + } + + ServiceInstance serviceInstance = optionalSi.get(); + + serviceInstance.setModelVersionId(modelVersionId); + + restClient.updateServiceInstance(serviceInstanceId, serviceType, globalSubscriberId, serviceInstance); + + } + + private RequestDetails requestVerification(DelegateExecution delegateExecution) throws IOException { + RequestDetails bpmnRequestDetails = mapper.readValue( + JsonUtils.getJsonValue(String.valueOf(delegateExecution.getVariable(BPMN_REQUEST)), "requestDetails"), + RequestDetails.class); + + throwIfNull(delegateExecution, bpmnRequestDetails.getModelInfo(), SERVICE_MODEL_INFO); + throwIfNull(delegateExecution, bpmnRequestDetails.getRequestInfo(), "RequestInfo"); + throwIfNull(delegateExecution, bpmnRequestDetails.getRequestParameters(), "RequestParameters"); + throwIfNull(delegateExecution, bpmnRequestDetails.getRequestParameters().getUserParams(), "UserParams"); + + return bpmnRequestDetails; + } + + private void throwIfNull(DelegateExecution delegateExecution, Object obj, String param) { + if (obj == null) { + throwExceptionWithWarn(delegateExecution, + "Unable to find the parameter: " + param + " in the execution context"); + } + } + + private void throwExceptionWithWarn(DelegateExecution delegateExecution, String exceptionMsg) { + logger.warn(exceptionMsg); + exceptionUtil.buildAndThrowWorkflowException(delegateExecution, ERROR_CODE, exceptionMsg); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparationTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparationTest.java index a99ee7d2df..340b2776a4 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparationTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/service/level/ServiceLevelPreparationTest.java @@ -28,6 +28,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; +import org.onap.so.bpmn.infrastructure.service.level.impl.ServiceLevelConstants; import org.onap.so.bpmn.infrastructure.service.level.impl.ServiceLevelPreparation; import org.onap.so.client.exception.ExceptionBuilder; import org.springframework.beans.factory.annotation.Autowired; @@ -38,9 +39,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; -import static org.onap.so.bpmn.infrastructure.service.level.AbstractServiceLevelPreparable.RESOURCE_TYPE; -import static org.onap.so.bpmn.infrastructure.service.level.AbstractServiceLevelPreparable.WORKFLOW_TO_INVOKE; - @RunWith(SpringJUnit4ClassRunner.class) @@ -50,10 +48,13 @@ public class ServiceLevelPreparationTest { private static final String TEST_PNF_SCOPE = "pnf"; private static final String TEST_PROCESS_KEY = "testProcessKey"; private static final String PROCESS_KEY_VALUE = "testProcessKeyValue"; - private static final List PNF_HEALTH_CHECK_PARAMS = Arrays.asList("SERVICE_MODEL_INFO", - "SERVICE_INSTANCE_NAME", "PNF_CORRELATION_ID", "MODEL_UUID", "PNF_UUID", "PRC_BLUEPRINT_NAME", - "PRC_BLUEPRINT_VERSION", "PRC_CUSTOMIZATION_UUID", "RESOURCE_CUSTOMIZATION_UUID_PARAM", "PRC_INSTANCE_NAME", - "PRC_CONTROLLER_ACTOR", "REQUEST_PAYLOAD"); + private static final String BPMN_REQUEST = "bpmnRequest"; + private static final String RESOURCE_TYPE = "resourceType"; + private static final String SERVICE_INSTANCE_ID = "serviceInstanceId"; + private static final String PNF_NAME = "pnfName"; + private static final List PNF_HEALTH_CHECK_PARAMS = Arrays.asList(ServiceLevelConstants.SERVICE_INSTANCE_ID, + ServiceLevelConstants.RESOURCE_TYPE, ServiceLevelConstants.BPMN_REQUEST, ServiceLevelConstants.PNF_NAME); + private Map pnfHealthCheckTestParams = new HashMap<>(); @Autowired @@ -89,6 +90,9 @@ public class ServiceLevelPreparationTest { } execution.setVariable(RESOURCE_TYPE, TEST_PNF_SCOPE); execution.setVariable(TEST_PROCESS_KEY, PROCESS_KEY_VALUE); + execution.setVariable(BPMN_REQUEST, "bpmnRequestValue"); + execution.setVariable(SERVICE_INSTANCE_ID, "serviceInstanceIdValue"); + execution.setVariable(PNF_NAME, "PnfDemo"); invalidExecution.setVariables(execution.getVariables()); } @@ -97,13 +101,13 @@ public class ServiceLevelPreparationTest { public void executePnfUpgradeSuccessTest() throws Exception { serviceLevelPrepare.execute(execution); // Expect the pnf health check workflow to be set in to execution if validation is successful - assertThat(String.valueOf(execution.getVariable(WORKFLOW_TO_INVOKE))).isEqualTo("GenericPnfHealthCheck"); + assertThat(String.valueOf(execution.getVariable(ServiceLevelConstants.WORKFLOW_TO_INVOKE))) + .isEqualTo("GenericPnfHealthCheck"); } @Test public void validateFailureParamsForPnfTest() throws Exception { - invalidExecution.removeVariable("PNF_UUID"); - invalidExecution.setVariable("PRC_BLUEPRINT_NAME", null); + invalidExecution.removeVariable(BPMN_REQUEST); // BPMN exception is thrown in case of validation failure or invalid execution thrown.expect(BpmnError.class); serviceLevelPrepare.validateParamsWithScope(invalidExecution, TEST_PNF_SCOPE, PNF_HEALTH_CHECK_PARAMS); diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIRestClientI.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIRestClientI.java index ef6ca00a32..3b08761568 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIRestClientI.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIRestClientI.java @@ -26,6 +26,7 @@ import java.util.Optional; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.Pnf; import org.onap.aai.domain.yang.Pserver; +import org.onap.aai.domain.yang.ServiceInstance; public interface AAIRestClientI { @@ -40,4 +41,10 @@ public interface AAIRestClientI { void createPnf(String pnfId, Pnf pnf); void updatePnf(String pnfId, Pnf pnf); + + Optional getServiceInstanceById(String serviceInstanceId, String serviceType, + String globalSubscriberId); + + void updateServiceInstance(String globalSubscriberId, String serviceType, String serviceInstanceId, + ServiceInstance serviceInstance); } diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIRestClientImpl.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIRestClientImpl.java index 886891a34e..0aff965ac0 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIRestClientImpl.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIRestClientImpl.java @@ -31,14 +31,18 @@ import javax.ws.rs.core.Response; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.Pnf; import org.onap.aai.domain.yang.Pserver; +import org.onap.aai.domain.yang.ServiceInstance; import org.onap.aaiclient.client.aai.entities.CustomQuery; import org.onap.aaiclient.client.aai.entities.Results; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; import org.onap.aaiclient.client.graphinventory.Format; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class AAIRestClientImpl implements AAIRestClientI { + private final Logger log = LoggerFactory.getLogger(getClass()); private static final String PSERVER_VNF_QUERY = "pservers-fromVnf"; @Override @@ -97,4 +101,24 @@ public class AAIRestClientImpl implements AAIRestClientI { public void updatePnf(String pnfId, Pnf pnf) { new AAIResourcesClient().update(AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnfId), pnf); } + + @Override + public Optional getServiceInstanceById(String globalSubscriberId, String serviceType, + String serviceInstanceId) { + Response response = new AAIResourcesClient().getFullResponse(AAIUriFactory + .createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)); + return Optional.ofNullable(response.readEntity(ServiceInstance.class)); + } + + @Override + public void updateServiceInstance(String globalSubscriberId, String serviceType, String serviceInstanceId, + ServiceInstance serviceInstance) { + try { + new AAIResourcesClient().update(AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, + globalSubscriberId, serviceType, serviceInstanceId), serviceInstance); + } catch (Throwable ex) { + log.error("Exception happened while updating ServiceInstance, Exception: {}", ex.getLocalizedMessage()); + throw new RuntimeException(ex); + } + } } -- cgit 1.2.3-korg