From c41c04b7b53bce7354d8cd1d47db3144e267a599 Mon Sep 17 00:00:00 2001 From: "waqas.ikram" Date: Tue, 11 Apr 2023 13:57:39 +0100 Subject: Adding namespace support Change-Id: Iac15ae319f335dd67a660c2cf7ac051cf1c9077e Issue-ID: SO-4097 Signed-off-by: waqas.ikram --- .../adapter/cnfm/tasks/CnfInstantiateTask.java | 54 ++++++++++++++-------- .../adapter/cnfm/tasks/CnfInstantiateTaskTest.java | 25 +++------- .../cnfm/tasks/StubbedBuildingBlockExecution.java | 4 +- 3 files changed, 42 insertions(+), 41 deletions(-) (limited to 'bpmn/so-bpmn-tasks') diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java index c7f3310391..b9fb235e99 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTask.java @@ -23,27 +23,28 @@ package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks; import static java.util.Objects.isNull; import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.CLOUD_OWNER_PARAM_KEY; import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.CLOUD_REGION_PARAM_KEY; +import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.NAMESPACE_KEY; import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.RESOURCE_ID_KEY; import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.SERVICE_INSTANCE_ID_PARAM_KEY; import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.SERVICE_INSTANCE_NAME_PARAM_KEY; import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.TENANT_ID_PARAM_KEY; import java.net.URI; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; import java.util.Optional; -import org.apache.groovy.util.Maps; import org.onap.logging.filter.base.ONAPComponents; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.cnfm.lcm.model.AsInfoModificationRequestDeploymentItems; import org.onap.so.cnfm.lcm.model.AsInstance; import org.onap.so.cnfm.lcm.model.CreateAsRequest; import org.onap.so.cnfm.lcm.model.InstantiateAsRequest; -import org.onap.so.cnfm.lcm.model.AsInfoModificationRequestDeploymentItems; import org.onap.so.serviceinstancebeans.CloudConfiguration; import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.RequestDetails; @@ -62,6 +63,7 @@ import org.springframework.stereotype.Component; */ @Component public class CnfInstantiateTask { + private static final String DEPLOYMENT_ITEMS_KEY = "deploymentItems"; private static final String CREATE_AS_REQUEST_OBJECT = "CreateAsRequestObject"; private static final String INSTANTIATE_AS_REQUEST_OBJECT = "InstantiateAsRequest"; private static final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl"; @@ -105,11 +107,19 @@ public class CnfInstantiateTask { final CreateAsRequest createAsRequest = new CreateAsRequest().asdId(modelInfo.getModelVersionId()) .asInstanceName(requestDetails.getRequestInfo().getInstanceName()) - .additionalParams(Maps.of(CLOUD_OWNER_PARAM_KEY, cloudConfiguration.getCloudOwner(), - CLOUD_REGION_PARAM_KEY, cloudConfiguration.getLcpCloudRegionId(), TENANT_ID_PARAM_KEY, - cloudConfiguration.getTenantId(), SERVICE_INSTANCE_ID_PARAM_KEY, - serviceInstance.getServiceInstanceId(), SERVICE_INSTANCE_NAME_PARAM_KEY, - serviceInstance.getServiceInstanceName(), RESOURCE_ID_KEY, resourceId)); + .putAdditionalParamsItem(CLOUD_OWNER_PARAM_KEY, cloudConfiguration.getCloudOwner()) + .putAdditionalParamsItem(CLOUD_REGION_PARAM_KEY, cloudConfiguration.getLcpCloudRegionId()) + .putAdditionalParamsItem(TENANT_ID_PARAM_KEY, cloudConfiguration.getTenantId()) + .putAdditionalParamsItem(SERVICE_INSTANCE_ID_PARAM_KEY, serviceInstance.getServiceInstanceId()) + .putAdditionalParamsItem(SERVICE_INSTANCE_NAME_PARAM_KEY, serviceInstance.getServiceInstanceName()) + .putAdditionalParamsItem(RESOURCE_ID_KEY, resourceId); + + final List> userParams = requestDetails.getRequestParameters().getUserParams(); + if (userParams != null) { + userParams.stream().filter(entry -> entry.containsKey(NAMESPACE_KEY)).findAny() + .ifPresent(userParam -> createAsRequest.putAdditionalParamsItem(NAMESPACE_KEY, + userParam.get(NAMESPACE_KEY))); + } LOGGER.debug("Adding CreateAsRequest to execution {}", createAsRequest); @@ -152,20 +162,16 @@ public class CnfInstantiateTask { (ExecuteBuildingBlock) execution.getVariable("buildingBlock"); final RequestDetails requestDetails = executeBuildingBlock.getRequestDetails(); final InstantiateAsRequest instantiateAsRequest = new InstantiateAsRequest(); + if (requestDetails != null && requestDetails.getRequestParameters() != null) { - List> userParams = requestDetails.getRequestParameters().getUserParams(); + final List> userParams = requestDetails.getRequestParameters().getUserParams(); if (userParams != null && !userParams.isEmpty()) { - List deploymentItems = new ArrayList<>(); - List deploymentItemsReq = new ArrayList<>(); - for (Map userParam : userParams) { - if (userParam.containsKey("deploymentItems")) { - deploymentItems = (ArrayList) userParam.get("deploymentItems"); - break; - } - } - for (Object deploymentItem : deploymentItems) { - Map deploymentItemMap = (Map) deploymentItem; - AsInfoModificationRequestDeploymentItems item = new AsInfoModificationRequestDeploymentItems(); + final List deploymentItems = getDeploymentItems(userParams); + final List deploymentItemsReq = new ArrayList<>(); + for (final Object deploymentItem : deploymentItems) { + final Map deploymentItemMap = (Map) deploymentItem; + final AsInfoModificationRequestDeploymentItems item = + new AsInfoModificationRequestDeploymentItems(); item.setDeploymentItemsId(deploymentItemMap.get("deploymentItemsId").toString()); item.setLifecycleParameterKeyValues(deploymentItemMap.get("lifecycleParameterKeyValues")); deploymentItemsReq.add(item); @@ -188,7 +194,7 @@ public class CnfInstantiateTask { try { final InstantiateAsRequest instantiateAsRequest = execution.getVariable(INSTANTIATE_AS_REQUEST_OBJECT); final String asInstanceId = execution.getVariable(AS_INSTANCE_ID); - Optional cnfStatusCheckURL = + final Optional cnfStatusCheckURL = cnfmHttpServiceProvider.invokeInstantiateAsRequest(instantiateAsRequest, asInstanceId); execution.setVariable(CNFM_REQUEST_STATUS_CHECK_URL, cnfStatusCheckURL.orElseThrow()); execution.setVariable(MONITOR_JOB_NAME, "Instantiate"); @@ -199,4 +205,12 @@ public class CnfInstantiateTask { } } + private List getDeploymentItems(final List> userParams) { + for (final Map userParam : userParams) { + if (userParam.containsKey(DEPLOYMENT_ITEMS_KEY)) { + return (ArrayList) userParam.get(DEPLOYMENT_ITEMS_KEY); + } + } + return Collections.emptyList(); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTaskTest.java index 79b47776f2..1268828a20 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTaskTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/CnfInstantiateTaskTest.java @@ -21,6 +21,7 @@ package org.onap.so.bpmn.infrastructure.adapter.cnfm.tasks; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; @@ -32,6 +33,7 @@ import static org.mockito.Mockito.when; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.INPUT_PARAMETER; import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.CLOUD_OWNER_PARAM_KEY; import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.CLOUD_REGION_PARAM_KEY; +import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.NAMESPACE_KEY; import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.TENANT_ID_PARAM_KEY; import java.util.Collections; import java.util.Optional; @@ -43,9 +45,7 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.InputParameter; -import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; -import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.cnfm.lcm.model.AsInstance; import org.onap.so.cnfm.lcm.model.CreateAsRequest; @@ -66,8 +66,7 @@ public class CnfInstantiateTaskTest { private static final String AS_INSTANCE_ID = "asInstanceid"; private static final String CLOUD_OWNER = "CloudOwner"; private static final String LCP_CLOUD_REGION_ID = "RegionOne"; - private static final String CNF_ID = UUID.randomUUID().toString(); - private static final String CNF_NAME = "CNF_NAME"; + private static final String NAME_SPACE = "default"; private static final String JOB_ID = UUID.randomUUID().toString(); @Mock @@ -92,6 +91,8 @@ public class CnfInstantiateTaskTest { assertEquals(LCP_CLOUD_REGION_ID, actual.getAdditionalParams().get(CLOUD_REGION_PARAM_KEY).toString()); assertEquals(StubbedBuildingBlockExecution.getTenantId(), actual.getAdditionalParams().get(TENANT_ID_PARAM_KEY).toString()); + assertEquals(NAME_SPACE, actual.getAdditionalParams().get(NAMESPACE_KEY).toString()); + } @Test @@ -157,6 +158,8 @@ public class CnfInstantiateTaskTest { final InstantiateAsRequest actual = stubbedExecution.getVariable(INSTANTIATE_AS_REQUEST_OBJECT); assertNotNull(actual); assertNotNull(actual.getDeploymentItems()); + assertEquals(1, actual.getDeploymentItems().size()); + assertFalse(actual.getDeploymentItems().get(0).getDeploymentItemsId().isBlank()); } private Optional getAsInstance() { @@ -165,20 +168,6 @@ public class CnfInstantiateTaskTest { return Optional.of(response); } - private GenericVnf getGenericVnf() { - final GenericVnf genericVnf = new GenericVnf(); - genericVnf.setVnfId(CNF_ID); - genericVnf.setModelInfoGenericVnf(getModelInfoGenericVnf()); - genericVnf.setVnfName(CNF_NAME); - return genericVnf; - } - - private ModelInfoGenericVnf getModelInfoGenericVnf() { - final ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); - modelInfoGenericVnf.setModelInstanceName(MODEL_INSTANCE_NAME); - return modelInfoGenericVnf; - } - private CnfInstantiateTask getCnfInstantiateTask() { return new CnfInstantiateTask(mockedCnfmHttpServiceProvider, exceptionUtil); } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/StubbedBuildingBlockExecution.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/StubbedBuildingBlockExecution.java index 3b16feda18..d4474f292d 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/StubbedBuildingBlockExecution.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/cnfm/tasks/StubbedBuildingBlockExecution.java @@ -27,10 +27,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; -import org.jetbrains.kotlin.codegen.intrinsics.LateinitIsInitialized; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.common.exceptions.RequiredExecutionVariableExeception; -import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; @@ -154,7 +152,7 @@ public class StubbedBuildingBlockExecution implements BuildingBlockExecution { deploymentItems.add(deploymentItemMap); Map userParamsMap = new HashMap<>(); userParamsMap.put("deploymentItems", deploymentItems); - userParamsMap.put("namespace", "Namespace"); + userParamsMap.put("namespace", "default"); List> userParams = new ArrayList<>(); userParams.add(userParamsMap); RequestParameters requestParameters = new RequestParameters(); -- cgit 1.2.3-korg