From 9c0c4279c0fd4e195af7a79449b356fd8e86856c Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Fri, 1 Mar 2019 14:47:01 -0500 Subject: Implement a separate task to query CatalogDB for Restore script value for the script task Implement a separate task to query CatalogDB for CloudSite info for CM flows. Change-Id: Id9dc4da9a7d50b50b691f30a8e0a5ce68eec1739 Issue-ID: SO-1586 Signed-off-by: Benjamin, Max (mb388a) --- .../bpmn/infrastructure/scripts/VnfCmBase.groovy | 20 +- .../main/resources/process/VnfInPlaceUpdate.bpmn | 779 +++++++++++++-------- .../flowspecific/tasks/CloudSiteCatalogUtils.java | 76 ++ .../tasks/CloudSiteCatalogUtilsTest.java | 88 +++ 4 files changed, 667 insertions(+), 296 deletions(-) create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CloudSiteCatalogUtils.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CloudSiteCatalogUtilsTest.java (limited to 'bpmn') diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/VnfCmBase.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/VnfCmBase.groovy index 4237a8d6a4..32fc46a84f 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/VnfCmBase.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/VnfCmBase.groovy @@ -264,24 +264,8 @@ public abstract class VnfCmBase extends AbstractServiceTaskProcessor { execution.setVariable("vmIdList", vmidsArray.toString()) execution.setVariable("vserverIdList", vserveridsArray.toString()) } - } - - if (cloudRegionId != null) { - AAIUri cloudRegionUri = AAIUriFactory.createResourceUri(AAIObjectType.DEFAULT_CLOUD_REGION, cloudRegionId) - // Check if this client region exists - if (!client.exists(cloudRegionUri)) { - msoLogger.debug("Cloud Region with cloudRegionId " + cloudRegionId + " does not exist in A&AI") - exceptionUtil.buildAndThrowWorkflowException(execution, 404, "Cloud Region with cloudRegionId " + cloudRegionId + " does not exist in A&AI") - } - - AAIResultWrapper aaiRWCloud = client.get(cloudRegionUri) + } - Map resultCloud = aaiRWCloud.asMap() - - String aicIdentity = resultCloud.get("identity-url") - msoLogger.debug("aicIdentity from A&AI is: " + aicIdentity) - execution.setVariable("aicIdentity", aicIdentity) - } // preserve relationships if exist Optional relationships = aaiRW.getRelationships() @@ -825,7 +809,5 @@ public abstract class VnfCmBase extends AbstractServiceTaskProcessor { } msoLogger.trace("Exit postProcessRollback ") } - - } diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/VnfInPlaceUpdate.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/VnfInPlaceUpdate.bpmn index 3c42320302..3663badb6e 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/VnfInPlaceUpdate.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/VnfInPlaceUpdate.bpmn @@ -131,7 +131,7 @@ uvfm.postProcessRollback(execution)]]> - + SequenceFlow_0y0jt4l SequenceFlow_053qjfy @@ -169,8 +169,8 @@ uvfm.setVnfInMaintFlagInAAI(execution, false) ]]> - SequenceFlow_053qjfy SequenceFlow_179tyul + SequenceFlow_1us5byg SequenceFlow_0usxnlk SequenceFlow_1c0vdki SequenceFlow_11o5j55 - + SequenceFlow_1uno5rs SequenceFlow_162mm0m @@ -295,13 +295,15 @@ uvfm.abortProcessing(execution)]]> SequenceFlow_1quapjx SequenceFlow_101n488 SequenceFlow_021ah63 + SequenceFlow_015qhj5 + SequenceFlow_1xeh8rb - @@ -371,15 +373,6 @@ uvfm.checkIfClosedLoopDisabledInAAI(execution) - - SequenceFlow_0du9273 - SequenceFlow_032tm9y - SequenceFlow_179z9vl - - SequenceFlow_032tm9y @@ -434,7 +427,7 @@ uvfm.setClosedLoopDisabledInAAI(execution, true) SequenceFlow_1fuaq5k SequenceFlow_04gth9f - + SequenceFlow_0if6xj4 @@ -594,11 +587,11 @@ uvfm.setClosedLoopDisabledInAAI(execution, false) (execution.getVariable("disposition") == "Retry" && execution.getVariable("workStep") == "Lock")]]> - + - @@ -653,9 +646,9 @@ uvfm.setClosedLoopDisabledInAAI(execution, false) - + SequenceFlow_1ar6ikk - + SequenceFlow_1nlqlwn @@ -718,12 +711,12 @@ uvfm.setClosedLoopDisabledInAAI(execution, false) - + - SequenceFlow_1c0vdki SequenceFlow_0if6xj4 + SequenceFlow_10yw9oj SequenceFlow_19ba94v @@ -888,8 +881,8 @@ execution.getVariable(retryVariableName) < execution.getVariable("maxRetryCount" - SequenceFlow_1fuaq5k SequenceFlow_1v59be9 + SequenceFlow_0ugaydb SequenceFlow_04rprct @@ -934,6 +927,107 @@ execution.getVariable(retryVariableName) < execution.getVariable("maxRetryCount" SequenceFlow_1j81s6b SequenceFlow_0qy68ib + + + SequenceFlow_02zphll + + + + + SequenceFlow_0ayfzd3 + SequenceFlow_10yw9oj + SequenceFlow_1qdt3ml + + + + SequenceFlow_1qdt3ml + + + + + + + + + + + + + + + + + + + SequenceFlow_1c0vdki + SequenceFlow_02zphll + SequenceFlow_0ayfzd3 + + + + + + SequenceFlow_015qhj5 + + + + + + + SequenceFlow_1xeh8rb + + + + + SequenceFlow_1c2q423 + SequenceFlow_0ugaydb + SequenceFlow_1ouddzv + + + + + + + + SequenceFlow_12k801c + + + + SequenceFlow_1ouddzv + + + + + + + + + + + + + + + + SequenceFlow_1fuaq5k + SequenceFlow_12k801c + SequenceFlow_1c2q423 + + + SequenceFlow_0du9273 + SequenceFlow_032tm9y + SequenceFlow_179z9vl + + + + + SequenceFlow_053qjfy + SequenceFlow_1us5byg + @@ -945,9 +1039,9 @@ execution.getVariable(retryVariableName) < execution.getVariable("maxRetryCount" - + - + @@ -978,30 +1072,30 @@ execution.getVariable(retryVariableName) < execution.getVariable("maxRetryCount" - + - - - - + + + + - + - + - + - - - - + + + + - + @@ -1059,12 +1153,12 @@ execution.getVariable(retryVariableName) < execution.getVariable("maxRetryCount" - - - - + + + + - + @@ -1075,25 +1169,17 @@ execution.getVariable(retryVariableName) < execution.getVariable("maxRetryCount" - - - - - - + + - + - - - - - + - + @@ -1120,7 +1206,7 @@ execution.getVariable(retryVariableName) < execution.getVariable("maxRetryCount" - + @@ -1147,24 +1233,24 @@ execution.getVariable(retryVariableName) < execution.getVariable("maxRetryCount" - - + + - + - - + + - + - - + + - + @@ -1262,41 +1348,41 @@ execution.getVariable(retryVariableName) < execution.getVariable("maxRetryCount" - + - + - + - + - - + + - + - + - + - + - + - - + + - + @@ -1322,10 +1408,10 @@ execution.getVariable(retryVariableName) < execution.getVariable("maxRetryCount" - - + + - + @@ -1488,9 +1574,6 @@ execution.getVariable(retryVariableName) < execution.getVariable("maxRetryCount" - - - @@ -1602,393 +1685,394 @@ execution.getVariable(retryVariableName) < execution.getVariable("maxRetryCount" - + - + - - + + + + + + - + - + - + - - + + - + - - + + - + - + - + - - + + - + - + - + - + - + - - + + - + - + - + - - + + - + - - - - - - + + - + - - + + - + - + - + - - + + + + + + - + - + - + - - - - + + + + - + - + - + - - + + - + - - + + - + - + - + - - + + - + - + - + - - + + - + - + - + - - + + - + - - + + - + - + - + - + - + - - + + - + - - + + - + - + - + - + - + - - - - + + - + - + - + - - + + - + - + - - + + - + - + - + - - + + - + - - + + - + - + - + - + - + - - + + - + - - + + - + - + - + - + - + - - - - + + - + - + - + - - + + + - + - - + + - + - - + + - + - - + + - + - + - + - - + + - + - - + + - + - - + + - + @@ -2020,52 +2104,52 @@ execution.getVariable(retryVariableName) < execution.getVariable("maxRetryCount" - + - + - + - + - + - + - + - + - + - + - + - + - - + + - + - + - + @@ -2075,21 +2159,21 @@ execution.getVariable(retryVariableName) < execution.getVariable("maxRetryCount" - + - + - + - + - + - + @@ -2156,31 +2240,31 @@ execution.getVariable(retryVariableName) < execution.getVariable("maxRetryCount" - + - + - + - + - + - - + + - + @@ -2253,13 +2337,13 @@ execution.getVariable(retryVariableName) < execution.getVariable("maxRetryCount" - + - + - + @@ -2297,6 +2381,147 @@ execution.getVariable(retryVariableName) < execution.getVariable("maxRetryCount" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CloudSiteCatalogUtils.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CloudSiteCatalogUtils.java new file mode 100644 index 0000000000..bba883e727 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CloudSiteCatalogUtils.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.so.bpmn.infrastructure.flowspecific.tasks; + +import java.util.Optional; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.db.catalog.beans.CloudSite; +import org.onap.so.logger.MsoLogger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class CloudSiteCatalogUtils { + + private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, CloudSiteCatalogUtils.class); + @Autowired + private ExceptionBuilder exceptionUtil; + + @Autowired + private CatalogDbClient catalogDbClient; + + + public void getIdentityUrlFromCloudSite(DelegateExecution execution) { + String cloudRegionId = (String) execution.getVariable("lcpCloudRegionId"); + + if (cloudRegionId != null) { + Optional cloudSite = getCloudSite(cloudRegionId); + if (!cloudSite.isPresent()) { + msoLogger.debug("Cloud Region with cloudRegionId " + cloudRegionId + " not found in Catalog DB"); + exceptionUtil.buildAndThrowWorkflowException(execution, 404, "Cloud Region with cloudRegionId " + cloudRegionId + " not found in Catalog DB"); + } + + if (cloudSite.get().getIdentityService() == null) { + msoLogger.debug("No identityService found for Cloud Region with cloudRegionId " + cloudRegionId + " in Catalog DB"); + exceptionUtil.buildAndThrowWorkflowException(execution, 404, "No identityService found for Cloud Region with cloudRegionId " + cloudRegionId + " in Catalog DB"); + } + String identityUrl = cloudSite.get().getIdentityService().getIdentityUrl(); + + msoLogger.debug("identityUrl from Catalog DB is: " + identityUrl); + execution.setVariable("identityUrl", identityUrl); + } + } + + protected Optional getCloudSite(String id) { + if (id == null) { + return Optional.empty(); + } + CloudSite cloudSite = catalogDbClient.getCloudSite(id); + + if (cloudSite != null) { + return Optional.of(cloudSite); + } else { + return(Optional.of(catalogDbClient.getCloudSiteByClliAndAicVersion(id,"2.5"))); + } + } +} \ No newline at end of file diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CloudSiteCatalogUtilsTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CloudSiteCatalogUtilsTest.java new file mode 100644 index 0000000000..125c97109c --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CloudSiteCatalogUtilsTest.java @@ -0,0 +1,88 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ +package org.onap.so.bpmn.infrastructure.flowspecific.tasks; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; +import java.util.Optional; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.onap.so.bpmn.BaseTaskTest; + +import org.onap.so.db.catalog.beans.CloudIdentity; +import org.onap.so.db.catalog.beans.CloudSite; + +public class CloudSiteCatalogUtilsTest extends BaseTaskTest { + + @InjectMocks + private CloudSiteCatalogUtils cloudSiteCatalogUtils = new CloudSiteCatalogUtils(); + + @Test + public void testGetCloudSiteGetVersion30Test() throws Exception { + CloudSite cloudSite = new CloudSite(); + String testCloudSiteId = "testCloudSiteId"; + cloudSite.setClli(testCloudSiteId); + doReturn(cloudSite).when(catalogDbClient).getCloudSite(testCloudSiteId); + Optional actualCloudSite = cloudSiteCatalogUtils.getCloudSite(testCloudSiteId); + assertEquals(actualCloudSite.get().getClli(), testCloudSiteId); + } + + @Test + public void testGetCloudSiteGetVersion25Test() throws Exception { + CloudSite cloudSite = new CloudSite(); + String testCloudSiteId = "testCloudSiteId"; + cloudSite.setClli(testCloudSiteId); + doReturn(null).when(catalogDbClient).getCloudSite(testCloudSiteId); + doReturn(cloudSite).when(catalogDbClient).getCloudSiteByClliAndAicVersion(testCloudSiteId, "2.5"); + Optional actualCloudSite = cloudSiteCatalogUtils.getCloudSite(testCloudSiteId); + assertEquals(actualCloudSite.get().getClli(), testCloudSiteId); + } + + @Test + public void testGetIdentityUrlFromCloudSiteSuccessTest() throws Exception { + CloudSite cloudSite = new CloudSite(); + String testCloudSiteId = "testCloudSiteId"; + String testIdentityUrl = "testIdentityUrl"; + delegateExecution.setVariable("lcpCloudRegionId", testCloudSiteId); + cloudSite.setClli(testCloudSiteId); + CloudIdentity cloudIdentity = new CloudIdentity(); + cloudIdentity.setIdentityUrl(testIdentityUrl); + cloudSite.setIdentityService(cloudIdentity); + doReturn(cloudSite).when(catalogDbClient).getCloudSite(testCloudSiteId); + cloudSiteCatalogUtils.getIdentityUrlFromCloudSite(delegateExecution); + String actualIdentityUrl = (String) delegateExecution.getVariable("identityUrl"); + assertEquals(testIdentityUrl, actualIdentityUrl); + } + + @Test + public void testGetIdentityUrlFromCloudSiteNoCloudIdProvidedTest() throws Exception { + CloudSite cloudSite = new CloudSite(); + String testCloudSiteId = "testCloudSiteId"; + String testIdentityUrl = "testIdentityUrl"; + cloudSite.setClli(testCloudSiteId); + CloudIdentity cloudIdentity = new CloudIdentity(); + cloudIdentity.setIdentityUrl(testIdentityUrl); + cloudSite.setIdentityService(cloudIdentity); + doReturn(cloudSite).when(catalogDbClient).getCloudSite(testCloudSiteId); + cloudSiteCatalogUtils.getIdentityUrlFromCloudSite(delegateExecution); + String actualIdentityUrl = (String) delegateExecution.getVariable("identityUrl"); + assertEquals(null, actualIdentityUrl); + } +} -- cgit 1.2.3-korg