diff options
author | Mnushkin, Dmitry <dmitry.mnushkin@att.com> | 2019-06-26 11:14:28 -0400 |
---|---|---|
committer | Max Benjamin <max.benjamin@att.com> | 2019-06-27 21:02:12 +0000 |
commit | 9306c021d9434f4ce8d0dfa9dd9ecb63974f11e6 (patch) | |
tree | 38cf4d19007101ad651fcde376b2f23592308f26 | |
parent | 8e42b4e3fd9c00d73d371ccdbe2147733821bb56 (diff) |
enhance workflowaction to handle resume func
init code for RESUME with junit passing
overwrite URI on resume op from original request
Change-Id: I1eee2bd66aa20804ba4a2834d269b5947565b9dc
Issue-ID: SO-2055
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
6 files changed, 362 insertions, 125 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java index 8ac5f6e69b..f8d5402260 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java @@ -23,6 +23,9 @@ package org.onap.so.bpmn.servicedecomposition.tasks; import java.io.IOException; +import java.io.ObjectOutputStream; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.Optional; @@ -42,6 +45,7 @@ import org.onap.aai.domain.yang.VolumeGroups; import org.onap.aai.domain.yang.VpnBinding; import org.onap.so.bpmn.common.InjectionHelper; import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException; import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException; import org.onap.so.client.aai.AAIObjectPlurals; @@ -59,6 +63,7 @@ import org.onap.so.db.catalog.beans.VfModuleCustomization; import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization; import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.beans.RequestProcessingData; import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.serviceinstancebeans.CloudConfiguration; import org.onap.so.serviceinstancebeans.ModelType; @@ -69,7 +74,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; @@ -79,6 +87,9 @@ public class BBInputSetupUtils { private static final Logger logger = LoggerFactory.getLogger(BBInputSetupUtils.class); private ObjectMapper objectMapper = new ObjectMapper(); private static final String REQUEST_ERROR = "Could not find request."; + private static final String DATA_LOAD_ERROR = "Could not process loading data from database"; + private static final String DATA_PARSE_ERROR = "Could not parse data"; + private static final String PROCESSING_DATA_NAME_EXECUTION_FLOWS = "flowExecutionPath"; @Autowired protected CatalogDbClient catalogDbClient; @@ -139,6 +150,66 @@ public class BBInputSetupUtils { } } + public void persistFlowExecutionPath(String requestId, List<ExecuteBuildingBlock> flowsToExecute) { + + if (requestId != null) { + List<String> flows = new ArrayList<>(); + ObjectMapper om = new ObjectMapper(); + try { + for (ExecuteBuildingBlock ebb : flowsToExecute) { + flows.add(om.writeValueAsString(ebb)); + } + } catch (JsonProcessingException e) { + logger.error(DATA_PARSE_ERROR, e); + } + + this.requestsDbClient.persistProcessingData(flows.toString(), requestId); + } else { + logger.debug(REQUEST_ERROR); + } + } + + public InfraActiveRequests loadInfraActiveRequestById(String requestId) { + + return this.requestsDbClient.getInfraActiveRequestbyRequestId(requestId); + } + + public InfraActiveRequests loadOriginalInfraActiveRequestById(String requestId) { + + return this.requestsDbClient.getInfraActiveRequestbyRequestId( + this.requestsDbClient.getInfraActiveRequestbyRequestId(requestId).getOriginalRequestId()); + } + + public List<ExecuteBuildingBlock> loadOriginalFlowExecutionPath(String requestId) { + + List<ExecuteBuildingBlock> asList = null; + if (requestId != null) { + + InfraActiveRequests request = loadInfraActiveRequestById(requestId); + + if (request.getOriginalRequestId() != null) { + + RequestProcessingData requestProcessingData = + this.requestsDbClient.getRequestProcessingDataBySoRequestIdAndName( + request.getOriginalRequestId(), PROCESSING_DATA_NAME_EXECUTION_FLOWS); + + ObjectMapper om = new ObjectMapper(); + try { + ExecuteBuildingBlock[] asArray = + om.readValue(requestProcessingData.getValue(), ExecuteBuildingBlock[].class); + asList = Arrays.asList(asArray); + } catch (Exception e) { + logger.error(DATA_LOAD_ERROR, e); + } + } + + } else { + logger.debug(REQUEST_ERROR); + } + + return asList; + } + public Service getCatalogServiceByModelUUID(String modelUUID) { return catalogDbClient.getServiceByID(modelUUID); } diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java index 25135a0254..189947595a 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java @@ -25,6 +25,7 @@ import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.doReturn; @@ -57,6 +58,7 @@ import org.onap.aai.domain.yang.VolumeGroups; import org.onap.so.bpmn.common.InjectionHelper; import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription; +import org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock; import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.MultipleObjectsFoundException; import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException; import org.onap.so.client.aai.AAIObjectPlurals; @@ -70,6 +72,7 @@ import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization; import org.onap.so.db.catalog.client.CatalogDbClient; import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.beans.RequestProcessingData; import org.onap.so.db.request.client.RequestsDbClient; import org.onap.so.serviceinstancebeans.CloudConfiguration; import org.onap.so.serviceinstancebeans.ModelInfo; @@ -832,4 +835,34 @@ public class BBInputSetupUtilsTest { assertEquals(actualVolumeGroup, Optional.empty()); } + + @Test + public void loadOriginalFlowExecutionPathTest() throws Exception { + + String requestId = "123"; + String flowsToExecuteString = + "[{\"buildingBlock\":{\"mso-id\":\"2f9ddc4b-4dcf-4129-a35f-be1625ae0176\",\"bpmn-flow-name\":\"DeactivateFabricConfigurationBB\",\"key\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"is-virtual-link\":false,\"virtual-link-key\":null},\"requestId\":\"9c944122-d161-4280-8594-48c06a9d96d5\",\"apiVersion\":\"7\",\"resourceId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"requestAction\":\"deleteInstance\",\"vnfType\":\"\",\"aLaCarte\":true,\"homing\":false,\"workflowResourceIds\":{\"serviceInstanceId\":\"ff9dae72-05bb-4277-ad2b-1b082467c138\",\"vnfId\":\"84a29830-e533-4f20-a838-910c740bf24c\",\"networkId\":\"\",\"volumeGroupId\":\"\",\"vfModuleId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"networkCollectionId\":null,\"configurationId\":\"10f8a3a3-91bf-4821-9515-c01b2864dff0\",\"instanceGroupId\":\"\"},\"requestDetails\":{\"modelInfo\":{\"modelCustomizationName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelInvariantId\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelType\":\"vfModule\",\"modelId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelVersion\":\"1\",\"modelCustomizationUuid\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelVersionId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelCustomizationId\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelUuid\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelInvariantUuid\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelInstanceName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\"},\"requestInfo\":{\"source\":\"VID\",\"suppressRollback\":false,\"requestorId\":\"pj8646\"},\"cloudConfiguration\":{\"tenantId\":\"e2a6af59d1cb43b2874e943bbbf8470a\",\"cloudOwner\":\"att-nc\",\"lcpCloudRegionId\":\"auk51b\"},\"requestParameters\":{\"testApi\":\"GR_API\"}},\"configurationResourceKeys\":{\"vfModuleCustomizationUUID\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"vnfResourceCustomizationUUID\":\"a80f05b8-d651-44af-b999-8ed78fb4582f\",\"cvnfcCustomizationUUID\":\"69cce457-9ffd-4359-962b-0596a1e83ad1\",\"vnfcName\":\"zauk51bmcmr01mcm001\"}},{\"buildingBlock\":{\"mso-id\":\"1ca5584e-38a9-4c3f-a4b4-99b0d42089ba\",\"bpmn-flow-name\":\"UnassignFabricConfigurationBB\",\"key\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"is-virtual-link\":false,\"virtual-link-key\":null},\"requestId\":\"9c944122-d161-4280-8594-48c06a9d96d5\",\"apiVersion\":\"7\",\"resourceId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"requestAction\":\"deleteInstance\",\"vnfType\":\"\",\"aLaCarte\":true,\"homing\":false,\"workflowResourceIds\":{\"serviceInstanceId\":\"ff9dae72-05bb-4277-ad2b-1b082467c138\",\"vnfId\":\"84a29830-e533-4f20-a838-910c740bf24c\",\"networkId\":\"\",\"volumeGroupId\":\"\",\"vfModuleId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"networkCollectionId\":null,\"configurationId\":\"10f8a3a3-91bf-4821-9515-c01b2864dff0\",\"instanceGroupId\":\"\"},\"requestDetails\":{\"modelInfo\":{\"modelCustomizationName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelInvariantId\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelType\":\"vfModule\",\"modelId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelVersion\":\"1\",\"modelCustomizationUuid\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelVersionId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelCustomizationId\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelUuid\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelInvariantUuid\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelInstanceName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\"},\"requestInfo\":{\"source\":\"VID\",\"suppressRollback\":false,\"requestorId\":\"pj8646\"},\"cloudConfiguration\":{\"tenantId\":\"e2a6af59d1cb43b2874e943bbbf8470a\",\"cloudOwner\":\"att-nc\",\"lcpCloudRegionId\":\"auk51b\"},\"requestParameters\":{\"testApi\":\"GR_API\"}},\"configurationResourceKeys\":{\"vfModuleCustomizationUUID\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"vnfResourceCustomizationUUID\":\"a80f05b8-d651-44af-b999-8ed78fb4582f\",\"cvnfcCustomizationUUID\":\"69cce457-9ffd-4359-962b-0596a1e83ad1\",\"vnfcName\":\"zauk51bmcmr01mcm001\"}},{\"buildingBlock\":{\"mso-id\":\"68d16097-4810-477d-803b-8322106106ef\",\"bpmn-flow-name\":\"DeactivateVfModuleBB\",\"key\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"is-virtual-link\":false,\"virtual-link-key\":null},\"requestId\":\"9c944122-d161-4280-8594-48c06a9d96d5\",\"apiVersion\":\"7\",\"resourceId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"requestAction\":\"deleteInstance\",\"vnfType\":\"\",\"aLaCarte\":true,\"homing\":false,\"workflowResourceIds\":{\"serviceInstanceId\":\"ff9dae72-05bb-4277-ad2b-1b082467c138\",\"vnfId\":\"84a29830-e533-4f20-a838-910c740bf24c\",\"networkId\":\"\",\"volumeGroupId\":\"\",\"vfModuleId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"networkCollectionId\":null,\"configurationId\":\"10f8a3a3-91bf-4821-9515-c01b2864dff0\",\"instanceGroupId\":\"\"},\"requestDetails\":{\"modelInfo\":{\"modelCustomizationName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelInvariantId\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelType\":\"vfModule\",\"modelId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelVersion\":\"1\",\"modelCustomizationUuid\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelVersionId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelCustomizationId\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelUuid\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelInvariantUuid\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelInstanceName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\"},\"requestInfo\":{\"source\":\"VID\",\"suppressRollback\":false,\"requestorId\":\"pj8646\"},\"cloudConfiguration\":{\"tenantId\":\"e2a6af59d1cb43b2874e943bbbf8470a\",\"cloudOwner\":\"att-nc\",\"lcpCloudRegionId\":\"auk51b\"},\"requestParameters\":{\"testApi\":\"GR_API\"}},\"configurationResourceKeys\":null},{\"buildingBlock\":{\"mso-id\":\"0b02eb09-bc23-4329-b19e-716dcca4e4a6\",\"bpmn-flow-name\":\"DeleteVfModuleBB\",\"key\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"is-virtual-link\":false,\"virtual-link-key\":null},\"requestId\":\"9c944122-d161-4280-8594-48c06a9d96d5\",\"apiVersion\":\"7\",\"resourceId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"requestAction\":\"deleteInstance\",\"vnfType\":\"\",\"aLaCarte\":true,\"homing\":false,\"workflowResourceIds\":{\"serviceInstanceId\":\"ff9dae72-05bb-4277-ad2b-1b082467c138\",\"vnfId\":\"84a29830-e533-4f20-a838-910c740bf24c\",\"networkId\":\"\",\"volumeGroupId\":\"\",\"vfModuleId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"networkCollectionId\":null,\"configurationId\":\"10f8a3a3-91bf-4821-9515-c01b2864dff0\",\"instanceGroupId\":\"\"},\"requestDetails\":{\"modelInfo\":{\"modelCustomizationName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelInvariantId\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelType\":\"vfModule\",\"modelId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelVersion\":\"1\",\"modelCustomizationUuid\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelVersionId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelCustomizationId\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelUuid\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelInvariantUuid\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelInstanceName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\"},\"requestInfo\":{\"source\":\"VID\",\"suppressRollback\":false,\"requestorId\":\"pj8646\"},\"cloudConfiguration\":{\"tenantId\":\"e2a6af59d1cb43b2874e943bbbf8470a\",\"cloudOwner\":\"att-nc\",\"lcpCloudRegionId\":\"auk51b\"},\"requestParameters\":{\"testApi\":\"GR_API\"}},\"configurationResourceKeys\":null},{\"buildingBlock\":{\"mso-id\":\"bcf95d05-0782-44ff-920d-d5100525c275\",\"bpmn-flow-name\":\"UnassignVfModuleBB\",\"key\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"is-virtual-link\":false,\"virtual-link-key\":null},\"requestId\":\"9c944122-d161-4280-8594-48c06a9d96d5\",\"apiVersion\":\"7\",\"resourceId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"requestAction\":\"deleteInstance\",\"vnfType\":\"\",\"aLaCarte\":true,\"homing\":false,\"workflowResourceIds\":{\"serviceInstanceId\":\"ff9dae72-05bb-4277-ad2b-1b082467c138\",\"vnfId\":\"84a29830-e533-4f20-a838-910c740bf24c\",\"networkId\":\"\",\"volumeGroupId\":\"\",\"vfModuleId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"networkCollectionId\":null,\"configurationId\":\"10f8a3a3-91bf-4821-9515-c01b2864dff0\",\"instanceGroupId\":\"\"},\"requestDetails\":{\"modelInfo\":{\"modelCustomizationName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelInvariantId\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelType\":\"vfModule\",\"modelId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelVersion\":\"1\",\"modelCustomizationUuid\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelVersionId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelCustomizationId\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelUuid\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelInvariantUuid\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelInstanceName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\"},\"requestInfo\":{\"source\":\"VID\",\"suppressRollback\":false,\"requestorId\":\"pj8646\"},\"cloudConfiguration\":{\"tenantId\":\"e2a6af59d1cb43b2874e943bbbf8470a\",\"cloudOwner\":\"att-nc\",\"lcpCloudRegionId\":\"auk51b\"},\"requestParameters\":{\"testApi\":\"GR_API\"}},\"configurationResourceKeys\":null}]"; + ObjectMapper om = new ObjectMapper(); + List<ExecuteBuildingBlock> expectedFlowsToExecute = null; + try { + ExecuteBuildingBlock[] asArray = om.readValue(flowsToExecuteString, ExecuteBuildingBlock[].class); + expectedFlowsToExecute = Arrays.asList(asArray); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + InfraActiveRequests request = new InfraActiveRequests(); + request.setRequestId("requestId"); + request.setOriginalRequestId("originalRequestId"); + doReturn(request).when(MOCK_requestsDbClient).getInfraActiveRequestbyRequestId(anyString()); + RequestProcessingData rpd = new RequestProcessingData(); + rpd.setValue(flowsToExecuteString); + doReturn(rpd).when(MOCK_requestsDbClient).getRequestProcessingDataBySoRequestIdAndName(anyString(), + anyString()); + + List<ExecuteBuildingBlock> flowsToExecute = bbInputSetupUtils.loadOriginalFlowExecutionPath(requestId); + assertEquals(expectedFlowsToExecute.size(), flowsToExecute.size()); + } + } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java index 0553afb318..e3a943214d 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java @@ -62,10 +62,8 @@ import org.onap.so.client.orchestration.AAIConfigurationResources; import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization; import org.onap.so.db.catalog.beans.CollectionResourceCustomization; import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization; -import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization; import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization; import org.onap.so.db.catalog.beans.CvnfcCustomization; -import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization; import org.onap.so.db.catalog.beans.VfModuleCustomization; import org.onap.so.db.catalog.beans.macro.NorthBoundRequest; import org.onap.so.db.catalog.beans.macro.OrchestrationFlow; @@ -74,7 +72,6 @@ import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.ModelType; import org.onap.so.serviceinstancebeans.Networks; import org.onap.so.serviceinstancebeans.RelatedInstance; -import org.onap.so.serviceinstancebeans.RelatedInstanceList; import org.onap.so.serviceinstancebeans.RequestDetails; import org.onap.so.serviceinstancebeans.Service; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; @@ -149,7 +146,7 @@ public class WorkflowAction { final String bpmnRequest = (String) execution.getVariable(BBConstants.G_BPMN_REQUEST); final boolean aLaCarte = (boolean) execution.getVariable(BBConstants.G_ALACARTE); final String apiVersion = (String) execution.getVariable(BBConstants.G_APIVERSION); - final String uri = (String) execution.getVariable(BBConstants.G_URI); + String uri = (String) execution.getVariable(BBConstants.G_URI); final String vnfType = (String) execution.getVariable(VNF_TYPE); String serviceInstanceId = (String) execution.getVariable("serviceInstanceId"); final String serviceType = @@ -183,6 +180,11 @@ public class WorkflowAction { suppressRollback = false; } execution.setVariable("suppressRollback", suppressRollback); + if (isUriResume(uri)) { + logger.debug("replacing URI {}", uri); + uri = bbInputSetupUtils.loadOriginalInfraActiveRequestById(requestId).getRequestUrl(); + logger.debug("for RESUME with original value {}", uri); + } Resource resource = extractResourceIdAndTypeFromUri(uri); WorkflowType resourceType = resource.getResourceType(); execution.setVariable("resourceName", resourceType.toString()); @@ -200,140 +202,148 @@ public class WorkflowAction { execution.setVariable("resourceId", resourceId); execution.setVariable("resourceType", resourceType); - if (aLaCarte) { - if (orchFlows == null || orchFlows.isEmpty()) { - orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, aLaCarte, - cloudOwner, serviceType); - } - String key = ""; - ModelInfo modelInfo = sIRequest.getRequestDetails().getModelInfo(); - if (modelInfo != null) { - if (modelInfo.getModelType().equals(ModelType.service)) { - key = modelInfo.getModelVersionId(); - } else { - key = modelInfo.getModelCustomizationId(); - } - } - boolean isConfiguration = isConfiguration(orchFlows); - Resource resourceKey = new Resource(resourceType, key, aLaCarte); - if (isConfiguration && !requestAction.equalsIgnoreCase(CREATEINSTANCE)) { - List<ExecuteBuildingBlock> configBuildingBlocks = getConfigBuildingBlocks( - new ConfigBuildingBlocksDataObject().setsIRequest(sIRequest).setOrchFlows(orchFlows) - .setRequestId(requestId).setResourceKey(resourceKey).setApiVersion(apiVersion) - .setResourceId(resourceId).setRequestAction(requestAction).setaLaCarte(aLaCarte) - .setVnfType(vnfType).setWorkflowResourceIds(workflowResourceIds) - .setRequestDetails(requestDetails).setExecution(execution)); - - flowsToExecute.addAll(configBuildingBlocks); - } - orchFlows = orchFlows.stream().filter(item -> !item.getFlowName().contains(FABRIC_CONFIGURATION)) - .collect(Collectors.toList()); - for (OrchestrationFlow orchFlow : orchFlows) { - ExecuteBuildingBlock ebb = buildExecuteBuildingBlock(orchFlow, requestId, resourceKey, apiVersion, - resourceId, requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails, false, - null, false); - flowsToExecute.add(ebb); + if (isRequestMacroServiceResume(aLaCarte, resourceType, requestAction, serviceInstanceId)) { + flowsToExecute = bbInputSetupUtils.loadOriginalFlowExecutionPath(requestId); + if (flowsToExecute == null) { + buildAndThrowException(execution, "Could not resume Macro flow. Error loading execution path."); } } else { - boolean foundRelated = false; - boolean containsService = false; - if (resourceType == WorkflowType.SERVICE && requestAction.equalsIgnoreCase(ASSIGNINSTANCE)) { - // SERVICE-MACRO-ASSIGN will always get user params with a - // service. - if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) { - List<Map<String, Object>> userParams = - sIRequest.getRequestDetails().getRequestParameters().getUserParams(); - for (Map<String, Object> params : userParams) { - if (params.containsKey(USERPARAMSERVICE)) { - containsService = true; + if (aLaCarte) { + if (orchFlows == null || orchFlows.isEmpty()) { + orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, aLaCarte, + cloudOwner, serviceType); + } + String key = ""; + ModelInfo modelInfo = sIRequest.getRequestDetails().getModelInfo(); + if (modelInfo != null) { + if (modelInfo.getModelType().equals(ModelType.service)) { + key = modelInfo.getModelVersionId(); + } else { + key = modelInfo.getModelCustomizationId(); + } + } + boolean isConfiguration = isConfiguration(orchFlows); + Resource resourceKey = new Resource(resourceType, key, aLaCarte); + if (isConfiguration && !requestAction.equalsIgnoreCase(CREATEINSTANCE)) { + List<ExecuteBuildingBlock> configBuildingBlocks = getConfigBuildingBlocks( + new ConfigBuildingBlocksDataObject().setsIRequest(sIRequest).setOrchFlows(orchFlows) + .setRequestId(requestId).setResourceKey(resourceKey).setApiVersion(apiVersion) + .setResourceId(resourceId).setRequestAction(requestAction).setaLaCarte(aLaCarte) + .setVnfType(vnfType).setWorkflowResourceIds(workflowResourceIds) + .setRequestDetails(requestDetails).setExecution(execution)); + + flowsToExecute.addAll(configBuildingBlocks); + } + orchFlows = orchFlows.stream().filter(item -> !item.getFlowName().contains(FABRIC_CONFIGURATION)) + .collect(Collectors.toList()); + for (OrchestrationFlow orchFlow : orchFlows) { + ExecuteBuildingBlock ebb = buildExecuteBuildingBlock(orchFlow, requestId, resourceKey, + apiVersion, resourceId, requestAction, aLaCarte, vnfType, workflowResourceIds, + requestDetails, false, null, false); + flowsToExecute.add(ebb); + } + } else { + boolean foundRelated = false; + boolean containsService = false; + if (resourceType == WorkflowType.SERVICE && requestAction.equalsIgnoreCase(ASSIGNINSTANCE)) { + // SERVICE-MACRO-ASSIGN will always get user params with a + // service. + if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) { + List<Map<String, Object>> userParams = + sIRequest.getRequestDetails().getRequestParameters().getUserParams(); + for (Map<String, Object> params : userParams) { + if (params.containsKey(USERPARAMSERVICE)) { + containsService = true; + } + } + if (containsService) { + traverseUserParamsService(execution, resourceCounter, sIRequest, requestAction); + } + } else { + buildAndThrowException(execution, + "Service-Macro-Assign request details must contain user params with a service"); + } + } else if (resourceType == WorkflowType.SERVICE && requestAction.equalsIgnoreCase(CREATEINSTANCE)) { + // SERVICE-MACRO-CREATE will get user params with a service, + // a service with a network, a service with a + // networkcollection, OR an empty service. + // If user params is just a service or null and macro + // queries the SI and finds a VNF, macro fails. + + if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) { + List<Map<String, Object>> userParams = + sIRequest.getRequestDetails().getRequestParameters().getUserParams(); + for (Map<String, Object> params : userParams) { + if (params.containsKey(USERPARAMSERVICE)) { + containsService = true; + } } } if (containsService) { - traverseUserParamsService(execution, resourceCounter, sIRequest, requestAction); + foundRelated = + traverseUserParamsService(execution, resourceCounter, sIRequest, requestAction); + } + if (!foundRelated) { + traverseCatalogDbService(execution, sIRequest, resourceCounter, aaiResourceIds); } + } else if (resourceType == WorkflowType.SERVICE + && (requestAction.equalsIgnoreCase("activateInstance") + || requestAction.equalsIgnoreCase("unassignInstance") + || requestAction.equalsIgnoreCase("deleteInstance") + || requestAction.equalsIgnoreCase("activate" + FABRIC_CONFIGURATION))) { + // SERVICE-MACRO-ACTIVATE, SERVICE-MACRO-UNASSIGN, and + // SERVICE-MACRO-DELETE + // Will never get user params with service, macro will have + // to query the SI in AAI to find related instances. + traverseAAIService(execution, resourceCounter, resourceId, aaiResourceIds); + } else if (resourceType == WorkflowType.SERVICE + && requestAction.equalsIgnoreCase("deactivateInstance")) { + resourceCounter.add(new Resource(WorkflowType.SERVICE, "", false)); + } else if (resourceType == WorkflowType.VNF && (requestAction.equalsIgnoreCase("replaceInstance") + || (requestAction.equalsIgnoreCase("recreateInstance")))) { + traverseAAIVnf(execution, resourceCounter, workflowResourceIds.getServiceInstanceId(), + workflowResourceIds.getVnfId(), aaiResourceIds); } else { - buildAndThrowException(execution, - "Service-Macro-Assign request details must contain user params with a service"); + buildAndThrowException(execution, "Current Macro Request is not supported"); } - } else if (resourceType == WorkflowType.SERVICE && requestAction.equalsIgnoreCase(CREATEINSTANCE)) { - // SERVICE-MACRO-CREATE will get user params with a service, - // a service with a network, a service with a - // networkcollection, OR an empty service. - // If user params is just a service or null and macro - // queries the SI and finds a VNF, macro fails. - - if (sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) { - List<Map<String, Object>> userParams = - sIRequest.getRequestDetails().getRequestParameters().getUserParams(); - for (Map<String, Object> params : userParams) { - if (params.containsKey(USERPARAMSERVICE)) { - containsService = true; - } - } + String foundObjects = ""; + for (WorkflowType type : WorkflowType.values()) { + foundObjects = foundObjects + type + " - " + resourceCounter.stream() + .filter(x -> type.equals(x.getResourceType())).collect(Collectors.toList()).size() + + " "; } - if (containsService) { - foundRelated = traverseUserParamsService(execution, resourceCounter, sIRequest, requestAction); + logger.info("Found {}", foundObjects); + + if (orchFlows == null || orchFlows.isEmpty()) { + orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, aLaCarte, + cloudOwner, serviceType); } - if (!foundRelated) { - traverseCatalogDbService(execution, sIRequest, resourceCounter, aaiResourceIds); + flowsToExecute = buildExecuteBuildingBlockList(orchFlows, resourceCounter, requestId, apiVersion, + resourceId, resourceType, requestAction, aLaCarte, vnfType, workflowResourceIds, + requestDetails); + if (!resourceCounter.stream().filter(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType()) + .collect(Collectors.toList()).isEmpty()) { + logger.info("Sorting for Vlan Tagging"); + flowsToExecute = sortExecutionPathByObjectForVlanTagging(flowsToExecute, requestAction); + } + // By default, enable homing at VNF level for CREATEINSTANCE and ASSIGNINSTANCE + if (resourceType == WorkflowType.SERVICE + && (requestAction.equals(CREATEINSTANCE) || requestAction.equals(ASSIGNINSTANCE)) + && !resourceCounter.stream().filter(x -> WorkflowType.VNF.equals(x.getResourceType())) + .collect(Collectors.toList()).isEmpty()) { + execution.setVariable("homing", true); + execution.setVariable("calledHoming", false); + } + if (resourceType == WorkflowType.SERVICE && (requestAction.equalsIgnoreCase(ASSIGNINSTANCE) + || requestAction.equalsIgnoreCase(CREATEINSTANCE))) { + generateResourceIds(flowsToExecute, resourceCounter, serviceInstanceId); + } else { + updateResourceIdsFromAAITraversal(flowsToExecute, resourceCounter, aaiResourceIds, + serviceInstanceId); } - } else if (resourceType == WorkflowType.SERVICE && (requestAction.equalsIgnoreCase("activateInstance") - || requestAction.equalsIgnoreCase("unassignInstance") - || requestAction.equalsIgnoreCase("deleteInstance") - || requestAction.equalsIgnoreCase("activate" + FABRIC_CONFIGURATION))) { - // SERVICE-MACRO-ACTIVATE, SERVICE-MACRO-UNASSIGN, and - // SERVICE-MACRO-DELETE - // Will never get user params with service, macro will have - // to query the SI in AAI to find related instances. - traverseAAIService(execution, resourceCounter, resourceId, aaiResourceIds); - } else if (resourceType == WorkflowType.SERVICE - && requestAction.equalsIgnoreCase("deactivateInstance")) { - resourceCounter.add(new Resource(WorkflowType.SERVICE, "", false)); - } else if (resourceType == WorkflowType.VNF && (requestAction.equalsIgnoreCase("replaceInstance") - || (requestAction.equalsIgnoreCase("recreateInstance")))) { - traverseAAIVnf(execution, resourceCounter, workflowResourceIds.getServiceInstanceId(), - workflowResourceIds.getVnfId(), aaiResourceIds); - } else { - buildAndThrowException(execution, "Current Macro Request is not supported"); - } - String foundObjects = ""; - for (WorkflowType type : WorkflowType.values()) { - foundObjects = foundObjects + type + " - " + resourceCounter.stream() - .filter(x -> type.equals(x.getResourceType())).collect(Collectors.toList()).size() + " "; - } - logger.info("Found {}", foundObjects); - - if (orchFlows == null || orchFlows.isEmpty()) { - orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, aLaCarte, - cloudOwner, serviceType); - } - flowsToExecute = - buildExecuteBuildingBlockList(orchFlows, resourceCounter, requestId, apiVersion, resourceId, - resourceType, requestAction, aLaCarte, vnfType, workflowResourceIds, requestDetails); - if (!resourceCounter.stream().filter(x -> WorkflowType.NETWORKCOLLECTION == x.getResourceType()) - .collect(Collectors.toList()).isEmpty()) { - logger.info("Sorting for Vlan Tagging"); - flowsToExecute = sortExecutionPathByObjectForVlanTagging(flowsToExecute, requestAction); - } - // By default, enable homing at VNF level for CREATEINSTANCE and ASSIGNINSTANCE - if (resourceType == WorkflowType.SERVICE - && (requestAction.equals(CREATEINSTANCE) || requestAction.equals(ASSIGNINSTANCE)) - && !resourceCounter.stream().filter(x -> WorkflowType.VNF.equals(x.getResourceType())) - .collect(Collectors.toList()).isEmpty()) { - execution.setVariable("homing", true); - execution.setVariable("calledHoming", false); - } - if (resourceType == WorkflowType.SERVICE && (requestAction.equalsIgnoreCase(ASSIGNINSTANCE) - || requestAction.equalsIgnoreCase(CREATEINSTANCE))) { - generateResourceIds(flowsToExecute, resourceCounter, serviceInstanceId); - } else { - updateResourceIdsFromAAITraversal(flowsToExecute, resourceCounter, aaiResourceIds, - serviceInstanceId); } } - - // If the user set "Homing_Solution" to "none", disable homing, else if "Homing_Solution" is - // specified, + // If the user set "Homing_Solution" to "none", disable homing, else if "Homing_Solution" is specified, // enable it. if (sIRequest.getRequestDetails().getRequestParameters() != null && sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) { @@ -359,6 +369,10 @@ public class WorkflowAction { logger.info(ebb.getBuildingBlock().getBpmnFlowName()); flowNames.add(ebb.getBuildingBlock().getBpmnFlowName()); } + + if (!aLaCarte) { + bbInputSetupUtils.persistFlowExecutionPath(requestId, flowsToExecute); + } execution.setVariable("flowNames", flowNames); execution.setVariable(BBConstants.G_CURRENT_SEQUENCE, 0); execution.setVariable("retryCount", 0); @@ -1477,4 +1491,17 @@ public class WorkflowAction { } exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, runtimeErrorMessage); } + + protected boolean isUriResume(String uri) { + return uri.endsWith("/resume"); + } + + protected boolean isRequestMacroServiceResume(boolean aLaCarte, WorkflowType resourceType, String requestAction, + String serviceInstanceId) { + return (!aLaCarte && resourceType == WorkflowType.SERVICE + && (requestAction.equalsIgnoreCase(ASSIGNINSTANCE) || requestAction.equalsIgnoreCase(CREATEINSTANCE)) + && (serviceInstanceId != null && serviceInstanceId.trim().length() > 1) + && (bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId) != null)); + } } + diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java index 176a09a04b..918a474b8a 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java @@ -26,6 +26,7 @@ import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; 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.junit.Assert.assertThat; @@ -96,6 +97,8 @@ import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.VfModuleCustomization; import org.onap.so.db.catalog.beans.macro.NorthBoundRequest; import org.onap.so.db.catalog.beans.macro.OrchestrationFlow; +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.beans.RequestProcessingData; import org.onap.so.serviceinstancebeans.RequestDetails; import org.onap.so.serviceinstancebeans.RequestParameters; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; @@ -1195,6 +1198,49 @@ public class WorkflowActionTest extends BaseTaskTest { } @Test + public void selectExecutionListMacroResumeTest() throws Exception { + String gAction = "createInstance"; + String resource = "Service"; + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + String bpmnRequest = + new String(Files.readAllBytes(Paths.get("src/test/resources/__files/Macro/ServiceMacroAssign.json"))); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", false); + execution.setVariable("apiVersion", "7"); + execution.setVariable("requestUri", "v6/serviceInstances/123"); + + NorthBoundRequest northBoundRequest = new NorthBoundRequest(); + List<OrchestrationFlow> orchFlows = createFlowList("AssignServiceInstanceBB"); + northBoundRequest.setOrchestrationFlowList(orchFlows); + + Service service = new Service(); + service.setModelUUID("3c40d244-808e-42ca-b09a-256d83d19d0a"); + + ServiceInstance si = new ServiceInstance(); + + when(bbSetupUtils.getAAIServiceInstanceById("123")).thenReturn(si); + when(catalogDbClient.getServiceByID("3c40d244-808e-42ca-b09a-256d83d19d0a")).thenReturn(service); + + String flowsToExecuteString = + "[{\"buildingBlock\":{\"mso-id\":\"2f9ddc4b-4dcf-4129-a35f-be1625ae0176\",\"bpmn-flow-name\":\"AssignServiceInstanceBB\",\"key\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"is-virtual-link\":false,\"virtual-link-key\":null},\"requestId\":\"9c944122-d161-4280-8594-48c06a9d96d5\",\"apiVersion\":\"7\",\"resourceId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"requestAction\":\"deleteInstance\",\"vnfType\":\"\",\"aLaCarte\":true,\"homing\":false,\"workflowResourceIds\":{\"serviceInstanceId\":\"ff9dae72-05bb-4277-ad2b-1b082467c138\",\"vnfId\":\"84a29830-e533-4f20-a838-910c740bf24c\",\"networkId\":\"\",\"volumeGroupId\":\"\",\"vfModuleId\":\"d1d35800-783d-42d3-82f6-d654c5054a6e\",\"networkCollectionId\":null,\"configurationId\":\"10f8a3a3-91bf-4821-9515-c01b2864dff0\",\"instanceGroupId\":\"\"},\"requestDetails\":{\"modelInfo\":{\"modelCustomizationName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelInvariantId\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelType\":\"vfModule\",\"modelId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\",\"modelVersion\":\"1\",\"modelCustomizationUuid\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelVersionId\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelCustomizationId\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"modelUuid\":\"00d15ebb-c80e-43c1-80f0-90c40dde70b0\",\"modelInvariantUuid\":\"8028fcc0-96dc-427d-a4de-4536245943da\",\"modelInstanceName\":\"McmrNcUpVnf20191..cr_mccm_fc_base..module-0\"},\"requestInfo\":{\"source\":\"VID\",\"suppressRollback\":false,\"requestorId\":\"pj8646\"},\"cloudConfiguration\":{\"tenantId\":\"e2a6af59d1cb43b2874e943bbbf8470a\",\"cloudOwner\":\"att-nc\",\"lcpCloudRegionId\":\"auk51b\"},\"requestParameters\":{\"testApi\":\"GR_API\"}},\"configurationResourceKeys\":{\"vfModuleCustomizationUUID\":\"7adc7c29-21a3-40a2-b8b6-5d4ad08b68e9\",\"vnfResourceCustomizationUUID\":\"a80f05b8-d651-44af-b999-8ed78fb4582f\",\"cvnfcCustomizationUUID\":\"69cce457-9ffd-4359-962b-0596a1e83ad1\",\"vnfcName\":\"zauk51bmcmr01mcm001\"}}]"; + ObjectMapper om = new ObjectMapper(); + List<ExecuteBuildingBlock> flowsToExecute = null; + try { + ExecuteBuildingBlock[] asArray = om.readValue(flowsToExecuteString, ExecuteBuildingBlock[].class); + flowsToExecute = Arrays.asList(asArray); + } catch (Exception e) { + e.printStackTrace(); + } + + when(bbSetupUtils.loadOriginalFlowExecutionPath(anyString())).thenReturn(flowsToExecute); + + workflowAction.selectExecutionList(execution); + List<ExecuteBuildingBlock> ebbs = (List<ExecuteBuildingBlock>) execution.getVariable("flowsToExecute"); + assertEqualsBulkFlowName(ebbs, "AssignServiceInstanceBB"); + } + + @Test public void getRelatedResourcesInVfModuleTest() throws Exception { org.onap.aai.domain.yang.Vnfc vnfc = new org.onap.aai.domain.yang.Vnfc(); vnfc.setModelInvariantId("modelInvariantId"); @@ -1424,6 +1470,21 @@ public class WorkflowActionTest extends BaseTaskTest { } @Test + public void isUriResumeTest() { + assertTrue(workflowAction.isUriResume( + "http://localhost:9100/onap/so/infra/orchestrationRequests/v7/requests/2f8ab587-ef6a-4456-b7b2-d73f9363dabd/resume")); + assertFalse(workflowAction.isUriResume("/v6/serviceInstances/123/vnfs/1234/vfmodules/5678/replace")); + } + + @Test + public void isRequestMacroServiceResumeTest() { + ServiceInstance si = new ServiceInstance(); + when(bbSetupUtils.getAAIServiceInstanceById(anyString())).thenReturn(si); + assertFalse(workflowAction.isRequestMacroServiceResume(false, WorkflowType.SERVICE, "createInstance", "")); + assertTrue(workflowAction.isRequestMacroServiceResume(false, WorkflowType.SERVICE, "createInstance", "123")); + } + + @Test public void populateResourceIdsFromApiHandlerTest() { execution.setVariable("serviceInstanceId", "123"); execution.setVariable("vnfId", "888"); diff --git a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java index 1abc21dfc8..ba2d021010 100644 --- a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java @@ -34,5 +34,8 @@ public interface RequestProcessingDataRepository extends JpaRepository<RequestPr RequestProcessingData findOneBySoRequestIdAndGroupingIdAndName(@Param("SO_REQUEST_ID") String soRequestId, @Param("GROUPING_ID") String groupingId, @Param("NAME") String name); + RequestProcessingData findOneBySoRequestIdAndName(@Param("SO_REQUEST_ID") String soRequestId, + @Param("NAME") String name); + List<RequestProcessingData> findBySoRequestIdOrderByGroupingIdDesc(@Param("SO_REQUEST_ID") String soRequestId); } diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java index 9ab0f3b680..c0ce59dc66 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java @@ -72,6 +72,8 @@ public class RequestsDbClient { private static final String REQUEST_ID = "REQUEST_ID"; private static final String OPERATIONAL_ENVIRONMENT_ID = "OPERATIONAL_ENV_ID"; private static final String SERVICE_MODEL_VERSION_ID = "SERVICE_MODEL_VERSION_ID"; + private static final String FLOW_EXECUTION_PATH = "flowExecutionPath"; + private static final String BPMN_EXECUTION_DATA_TAG = "BPMNExecutionData"; @Value("${mso.adapters.requestDb.endpoint:#{null}}") protected String endpoint; @@ -95,6 +97,8 @@ public class RequestsDbClient { private String findOneByServiceIdAndOperationIdURI = "/findOneByServiceIdAndOperationId"; + private String findOneByRequestId = "/infraActiveRequests/search/findOneByRequestId"; + private String findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestIdURI = "/findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestId"; @@ -110,6 +114,8 @@ public class RequestsDbClient { private static final String findBySoRequestIdAndGroupIdAndName = "/requestProcessingData/search/findOneBySoRequestIdAndGroupingIdAndName"; + private static final String findBySoRequestIdAndName = "/requestProcessingData/search/findOneBySoRequestIdAndName"; + private static final String findBySoRequestIdOrderByGroupingIdDesc = "/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc"; @@ -136,6 +142,7 @@ public class RequestsDbClient { + findOneByOperationalEnvIdAndServiceModelVersionIdAndRequestIdURI; findAllByOperationalEnvIdAndRequestIdURI = endpoint + OPERATIONAL_ENV_SERVICE_MODEL_STATUS_SEARCH + findAllByOperationalEnvIdAndRequestIdURI; + findOneByRequestId = endpoint + findOneByRequestId; } private ClientFactory getClientFactory() { @@ -361,6 +368,27 @@ public class RequestsDbClient { .queryParam(GROUPING_ID, groupingId).build().toString())); } + public RequestProcessingData getRequestProcessingDataBySoRequestIdAndName(String soRequestId, String name) { + return getClientFactory().create(RequestProcessingData.class) + .get(getUri(UriBuilder.fromUri(endpoint + findBySoRequestIdAndName) + .queryParam(SO_REQUEST_ID, soRequestId).queryParam(NAME, name).build().toString())); + } + + + public void persistProcessingData(String flowExecutionPath, String requestId) { + + HttpHeaders headers = getHttpHeaders(); + URI uri = getUri(requestProcessingDataURI); + RequestProcessingData rpd = new RequestProcessingData(); + rpd.setName(FLOW_EXECUTION_PATH); + rpd.setSoRequestId(requestId); + rpd.setValue(flowExecutionPath); + rpd.setTag(BPMN_EXECUTION_DATA_TAG); + + HttpEntity<RequestProcessingData> entity = new HttpEntity<>(rpd, headers); + restTemplate.postForLocation(uri, entity); + } + private List<RequestProcessingData> getRequestProcessingData(URI uri) { Iterable<RequestProcessingData> requestProcessingDataIterator = getClientFactory().create(RequestProcessingData.class).getAll(uri); @@ -370,6 +398,20 @@ public class RequestsDbClient { return requestProcessingDataList; } + public InfraActiveRequests findOneByRequestId(String requestId) { + try { + HttpEntity<?> entity = getHttpEntity(); + return restTemplate.exchange( + getUri(UriBuilder.fromUri(findOneByRequestId).queryParam(REQUEST_ID, requestId).build().toString()), + HttpMethod.GET, entity, InfraActiveRequests.class).getBody(); + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + return null; + } + throw e; + } + } + // From and To are defaulted to ignore start/endtime on query to database public List<InfraActiveRequests> getRequest(final Map<String, String[]> filters) { String url = UriBuilder.fromUri(getUri(getInfraActiveRequests)).queryParam("from", "0") |