diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src')
3 files changed, 214 insertions, 274 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidator.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidator.java index e2dd73f9ec..f233de2baa 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidator.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidator.java @@ -11,9 +11,9 @@ * 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. @@ -24,9 +24,15 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks; -import java.util.EnumSet; -import java.util.Set; import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; +import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; import org.onap.so.client.exception.BBObjectNotFoundException; @@ -45,6 +51,8 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.client.HttpClientErrorException; +import java.util.EnumSet; +import java.util.Set; @Component public class OrchestrationStatusValidator { @@ -57,9 +65,6 @@ public class OrchestrationStatusValidator { private static final String ORCHESTRATION_VALIDATION_FAIL = "Orchestration Status Validation failed. ResourceType=(%s), TargetAction=(%s), OrchestrationStatus=(%s)"; private static final String ORCHESTRATION_STATUS_VALIDATION_RESULT = "orchestrationStatusValidationResult"; - private static final String ALACARTE = "aLaCarte"; - private static final String MULTI_STAGE_DESIGN_OFF = "false"; - private static final String MULTI_STAGE_DESIGN_ON = "true"; private static final String RESOURCE_EXIST_STATUS_MESSAGE = "The %s was found to already exist, thus no new %s was created in the cloud via this request"; private static final String RESOURCE_NOT_EXIST_STATUS_MESSAGE = @@ -79,20 +84,11 @@ public class OrchestrationStatusValidator { /** * This method validate's the status of the OrchestrationStatus against the buildingBlockDetail ResourceType - * - * @param execution */ public void validateOrchestrationStatus(BuildingBlockExecution execution) { try { - OrchestrationStatusValidationDirective previousOrchestrationStatusValidationResult = - execution.getVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT); - execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, null); - - boolean aLaCarte = (boolean) execution.getVariable(ALACARTE); - String buildingBlockFlowName = execution.getFlowToBeCalled(); - BuildingBlockDetail buildingBlockDetail = catalogDbClient.getBuildingBlockDetail(buildingBlockFlowName); if (buildingBlockDetail == null) { @@ -100,63 +96,10 @@ public class OrchestrationStatusValidator { String.format(BUILDING_BLOCK_DETAIL_NOT_FOUND, buildingBlockFlowName)); } - OrchestrationStatus orchestrationStatus; - - switch (buildingBlockDetail.getResourceType()) { - case SERVICE: - org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstance = - extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); - orchestrationStatus = serviceInstance.getOrchestrationStatus(); - break; - case VNF: - org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf genericVnf = - extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); - orchestrationStatus = genericVnf.getOrchestrationStatus(); - break; - case VF_MODULE: - org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule = - extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); - orchestrationStatus = vfModule.getOrchestrationStatus(); - break; - case VOLUME_GROUP: - org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup volumeGroup = - extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID); - orchestrationStatus = volumeGroup.getOrchestrationStatus(); - break; - case NETWORK: - org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network network = - extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID); - orchestrationStatus = network.getOrchestrationStatus(); - break; - case NETWORK_COLLECTION: - org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInst = - extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); - org.onap.so.bpmn.servicedecomposition.bbobjects.Collection networkCollection = - serviceInst.getCollection(); - orchestrationStatus = networkCollection.getOrchestrationStatus(); - break; - case CONFIGURATION: - org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration configuration = - extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID); - orchestrationStatus = configuration.getOrchestrationStatus(); - break; - case INSTANCE_GROUP: - org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup instanceGroup = - extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID); - orchestrationStatus = instanceGroup.getOrchestrationStatus(); - break; - case NO_VALIDATE: - // short circuit and exit method - execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, - OrchestrationStatusValidationDirective.VALIDATION_SKIPPED); - return; - default: - // can't currently get here, so not tested. Added in case enum is expanded - // without a change to this - // code - throw new OrchestrationStatusValidationException( - String.format(UNKNOWN_RESOURCE_TYPE, buildingBlockFlowName, - buildingBlockDetail.getResourceType(), buildingBlockDetail.getTargetAction())); + OrchestrationStatus orchestrationStatus = + getOrchestrationStatus(execution, buildingBlockFlowName, buildingBlockDetail); + if (buildingBlockDetail.getResourceType().equals(ResourceType.NO_VALIDATE)) { + return; } if (orchestrationStatus == null) { @@ -199,6 +142,66 @@ public class OrchestrationStatusValidator { } } + private OrchestrationStatus getOrchestrationStatus(BuildingBlockExecution execution, String buildingBlockFlowName, + BuildingBlockDetail buildingBlockDetail) + throws BBObjectNotFoundException, OrchestrationStatusValidationException { + OrchestrationStatus orchestrationStatus = null; + + switch (buildingBlockDetail.getResourceType()) { + case SERVICE: + ServiceInstance serviceInstance = + extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); + orchestrationStatus = serviceInstance.getOrchestrationStatus(); + break; + case VNF: + GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); + orchestrationStatus = genericVnf.getOrchestrationStatus(); + break; + case VF_MODULE: + VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); + orchestrationStatus = vfModule.getOrchestrationStatus(); + break; + case VOLUME_GROUP: + VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID); + orchestrationStatus = volumeGroup.getOrchestrationStatus(); + break; + case NETWORK: + L3Network network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID); + orchestrationStatus = network.getOrchestrationStatus(); + break; + case NETWORK_COLLECTION: + Collection networkCollection = getNetworkCollection(execution); + orchestrationStatus = networkCollection.getOrchestrationStatus(); + break; + case CONFIGURATION: + Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID); + orchestrationStatus = configuration.getOrchestrationStatus(); + break; + case INSTANCE_GROUP: + InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID); + orchestrationStatus = instanceGroup.getOrchestrationStatus(); + break; + case NO_VALIDATE: + // short circuit and exit method + execution.setVariable(ORCHESTRATION_STATUS_VALIDATION_RESULT, + OrchestrationStatusValidationDirective.VALIDATION_SKIPPED); + break; + default: + // can't currently get here, so not tested. Added in case enum is expanded + // without a change to this + // code + throw new OrchestrationStatusValidationException( + String.format(UNKNOWN_RESOURCE_TYPE, buildingBlockFlowName, + buildingBlockDetail.getResourceType(), buildingBlockDetail.getTargetAction())); + } + return orchestrationStatus; + } + + private Collection getNetworkCollection(BuildingBlockExecution execution) throws BBObjectNotFoundException { + ServiceInstance serviceInst = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); + return serviceInst.getCollection(); + } + private void updatedResourceStatus(BuildingBlockExecution execution, BuildingBlockDetail buildingBlockDetail) { if (cloudResources.contains(buildingBlockDetail.getResourceType())) { 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 25c22867fa..cc89d00e29 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 @@ -826,27 +826,8 @@ public class WorkflowAction { private void traverseNetworkCollectionResourceCustomization(List<Resource> resourceList, CollectionResourceCustomization collectionResourceCustomization) { - if (collectionResourceCustomization == null) { - logger.debug("No Network Collection Customization found"); - return; - } - resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, - collectionResourceCustomization.getModelCustomizationUUID(), false)); - logger.debug("Found a network collection"); - if (collectionResourceCustomization.getCollectionResource() == null) { - logger.debug("No Network Collection found. collectionResource is null"); - return; - } - if (collectionResourceCustomization.getCollectionResource().getInstanceGroup() == null) { - logger.debug("No Instance Group found for network collection."); + if (collectionResourceCustomizationShouldNotBeProcessed(resourceList, collectionResourceCustomization)) return; - } - String toscaNodeType = - collectionResourceCustomization.getCollectionResource().getInstanceGroup().getToscaNodeType(); - if (!toscaNodeTypeHasNetworkCollection(toscaNodeType)) { - logger.debug("Instance Group tosca node type does not contain NetworkCollection: {}", toscaNodeType); - return; - } int minNetworks = 0; org.onap.so.db.catalog.beans.InstanceGroup instanceGroup = collectionResourceCustomization.getCollectionResource().getInstanceGroup(); @@ -860,7 +841,7 @@ public class WorkflowAction { break; } } - if (collectionInstCust != null && collectionInstCust.getSubInterfaceNetworkQuantity() != null) { + if (interfaceNetworkQuantityIsAvailableInCollection(collectionInstCust)) { minNetworks = collectionInstCust.getSubInterfaceNetworkQuantity(); } } @@ -884,6 +865,37 @@ public class WorkflowAction { } } + private boolean collectionResourceCustomizationShouldNotBeProcessed(List<Resource> resourceList, + CollectionResourceCustomization collectionResourceCustomization) { + if (collectionResourceCustomization == null) { + logger.debug("No Network Collection Customization found"); + return true; + } + resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, + collectionResourceCustomization.getModelCustomizationUUID(), false)); + logger.debug("Found a network collection"); + if (collectionResourceCustomization.getCollectionResource() == null) { + logger.debug("No Network Collection found. collectionResource is null"); + return true; + } + if (collectionResourceCustomization.getCollectionResource().getInstanceGroup() == null) { + logger.debug("No Instance Group found for network collection."); + return true; + } + String toscaNodeType = + collectionResourceCustomization.getCollectionResource().getInstanceGroup().getToscaNodeType(); + if (!toscaNodeTypeHasNetworkCollection(toscaNodeType)) { + logger.debug("Instance Group tosca node type does not contain NetworkCollection: {}", toscaNodeType); + return true; + } + return false; + } + + private boolean interfaceNetworkQuantityIsAvailableInCollection( + CollectionResourceInstanceGroupCustomization collectionInstCust) { + return collectionInstCust != null && collectionInstCust.getSubInterfaceNetworkQuantity() != null; + } + private boolean toscaNodeTypeHasNetworkCollection(String toscaNodeType) { return toscaNodeType != null && toscaNodeType.contains(NETWORKCOLLECTION); } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidatorTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidatorTest.java index b9feeedc14..98f84414db 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidatorTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/OrchestrationStatusValidatorTest.java @@ -4,12 +4,14 @@ * ================================================================================ * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Copyright (C) 2020 Nokia 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. @@ -20,31 +22,20 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.when; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import org.camunda.bpm.engine.delegate.BpmnError; -import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; +import org.mockito.Mock; import org.mockito.Mockito; import org.onap.so.bpmn.BaseTaskTest; -import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.exception.OrchestrationStatusValidationException; import org.onap.so.db.catalog.beans.BuildingBlockDetail; import org.onap.so.db.catalog.beans.OrchestrationAction; import org.onap.so.db.catalog.beans.OrchestrationStatus; @@ -52,7 +43,16 @@ import org.onap.so.db.catalog.beans.OrchestrationStatusStateTransitionDirective; import org.onap.so.db.catalog.beans.OrchestrationStatusValidationDirective; import org.onap.so.db.catalog.beans.ResourceType; import org.onap.so.db.request.beans.InfraActiveRequests; -import org.springframework.beans.factory.annotation.Autowired; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class OrchestrationStatusValidatorTest extends BaseTaskTest { @@ -62,6 +62,9 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { private static final String vfModuleNotExistExpectedMessage = "The VfModule was not found, thus no VfModule was deleted in the cloud via this request"; + @Mock + private ExceptionBuilder exceptionBuilder; + @InjectMocks protected OrchestrationStatusValidator orchestrationStatusValidator = new OrchestrationStatusValidator(); @@ -72,11 +75,8 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { execution.setVariable("aLaCarte", true); execution.setVariable("flowToBeCalled", flowToBeCalled); - BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); - buildingBlockDetail.setBuildingBlockName("AssignServiceInstanceBB"); - buildingBlockDetail.setId(1); - buildingBlockDetail.setResourceType(ResourceType.SERVICE); - buildingBlockDetail.setTargetAction(OrchestrationAction.ASSIGN); + BuildingBlockDetail buildingBlockDetail = + getBuildingBlockDetail("AssignServiceInstanceBB", ResourceType.SERVICE, OrchestrationAction.ASSIGN); doReturn(buildingBlockDetail).when(catalogDbClient).getBuildingBlockDetail(flowToBeCalled); @@ -88,12 +88,8 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { .thenReturn(serviceInstance); OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = - new OrchestrationStatusStateTransitionDirective(); - orchestrationStatusStateTransitionDirective.setFlowDirective(OrchestrationStatusValidationDirective.CONTINUE); - orchestrationStatusStateTransitionDirective.setId(1); - orchestrationStatusStateTransitionDirective.setOrchestrationStatus(OrchestrationStatus.PRECREATED); - orchestrationStatusStateTransitionDirective.setResourceType(ResourceType.SERVICE); - orchestrationStatusStateTransitionDirective.setTargetAction(OrchestrationAction.ASSIGN); + getOrchestrationStatusStateTransitionDirective(OrchestrationStatusValidationDirective.CONTINUE, + OrchestrationStatus.PRECREATED, ResourceType.SERVICE, OrchestrationAction.ASSIGN); doReturn(orchestrationStatusStateTransitionDirective).when(catalogDbClient) .getOrchestrationStatusStateTransitionDirective(ResourceType.SERVICE, OrchestrationStatus.PRECREATED, @@ -107,6 +103,19 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { Mockito.verifyZeroInteractions(requestsDbClient); } + private OrchestrationStatusStateTransitionDirective getOrchestrationStatusStateTransitionDirective( + OrchestrationStatusValidationDirective aContinue, OrchestrationStatus precreated, ResourceType service, + OrchestrationAction assign) { + OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = + new OrchestrationStatusStateTransitionDirective(); + orchestrationStatusStateTransitionDirective.setFlowDirective(aContinue); + orchestrationStatusStateTransitionDirective.setId(1); + orchestrationStatusStateTransitionDirective.setOrchestrationStatus(precreated); + orchestrationStatusStateTransitionDirective.setResourceType(service); + orchestrationStatusStateTransitionDirective.setTargetAction(assign); + return orchestrationStatusStateTransitionDirective; + } + @Test public void test_validateOrchestrationStatusConfiguration() throws Exception { lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, "configurationId"); @@ -124,11 +133,8 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { execution.setVariable("flowToBeCalled", flowToBeCalled); execution.setVariable("aLaCarte", true); - BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); - buildingBlockDetail.setBuildingBlockName("UnassignFabricConfigurationBB"); - buildingBlockDetail.setId(1); - buildingBlockDetail.setResourceType(ResourceType.CONFIGURATION); - buildingBlockDetail.setTargetAction(OrchestrationAction.UNASSIGN); + BuildingBlockDetail buildingBlockDetail = getBuildingBlockDetail("UnassignFabricConfigurationBB", + ResourceType.CONFIGURATION, OrchestrationAction.UNASSIGN); doReturn(buildingBlockDetail).when(catalogDbClient).getBuildingBlockDetail(flowToBeCalled); @@ -140,13 +146,8 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { .thenReturn(configuration); OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = - new OrchestrationStatusStateTransitionDirective(); - orchestrationStatusStateTransitionDirective - .setFlowDirective(OrchestrationStatusValidationDirective.SILENT_SUCCESS); - orchestrationStatusStateTransitionDirective.setId(1); - orchestrationStatusStateTransitionDirective.setOrchestrationStatus(OrchestrationStatus.PRECREATED); - orchestrationStatusStateTransitionDirective.setResourceType(ResourceType.CONFIGURATION); - orchestrationStatusStateTransitionDirective.setTargetAction(OrchestrationAction.UNASSIGN); + getOrchestrationStatusStateTransitionDirective(OrchestrationStatusValidationDirective.SILENT_SUCCESS, + OrchestrationStatus.PRECREATED, ResourceType.CONFIGURATION, OrchestrationAction.UNASSIGN); doReturn(orchestrationStatusStateTransitionDirective).when(catalogDbClient) .getOrchestrationStatusStateTransitionDirective(ResourceType.CONFIGURATION, @@ -160,44 +161,30 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { Mockito.verifyZeroInteractions(requestsDbClient); } - @Ignore @Test - public void test_validateOrchestrationStatus_buildingBlockDetailNotFound() throws Exception { - expectedException.expect(BpmnError.class); - + public void test_validateOrchestrationStatus_buildingBlockDetailNotFound() { String flowToBeCalled = "AssignServiceInstanceBB"; - execution.setVariable("flowToBeCalled", flowToBeCalled); - doReturn(null).when(catalogDbClient).getBuildingBlockDetail(flowToBeCalled); orchestrationStatusValidator.validateOrchestrationStatus(execution); + + verify(exceptionBuilder).buildAndThrowWorkflowException(eq(execution), eq(7000), + any(OrchestrationStatusValidationException.class)); } - @Ignore @Test - public void test_validateOrchestrationStatus_orchestrationValidationFail() throws Exception { - expectedException.expect(BpmnError.class); - + public void test_validateOrchestrationStatus_orchestrationValidationFail() { String flowToBeCalled = "AssignServiceInstanceBB"; - execution.setVariable("flowToBeCalled", flowToBeCalled); - - BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); - buildingBlockDetail.setBuildingBlockName("AssignServiceInstanceBB"); - buildingBlockDetail.setId(1); - buildingBlockDetail.setResourceType(ResourceType.SERVICE); - buildingBlockDetail.setTargetAction(OrchestrationAction.ASSIGN); + BuildingBlockDetail buildingBlockDetail = + getBuildingBlockDetail("AssignServiceInstanceBB", ResourceType.SERVICE, OrchestrationAction.ASSIGN); doReturn(buildingBlockDetail).when(catalogDbClient).getBuildingBlockDetail(flowToBeCalled); OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = - new OrchestrationStatusStateTransitionDirective(); - orchestrationStatusStateTransitionDirective.setFlowDirective(OrchestrationStatusValidationDirective.FAIL); - orchestrationStatusStateTransitionDirective.setId(1); - orchestrationStatusStateTransitionDirective.setOrchestrationStatus(OrchestrationStatus.PRECREATED); - orchestrationStatusStateTransitionDirective.setResourceType(ResourceType.SERVICE); - orchestrationStatusStateTransitionDirective.setTargetAction(OrchestrationAction.ASSIGN); + getOrchestrationStatusStateTransitionDirective(OrchestrationStatusValidationDirective.FAIL, + OrchestrationStatus.PRECREATED, ResourceType.SERVICE, OrchestrationAction.ASSIGN); doReturn(orchestrationStatusStateTransitionDirective).when(catalogDbClient) .getOrchestrationStatusStateTransitionDirective(ResourceType.SERVICE, OrchestrationStatus.PRECREATED, @@ -206,32 +193,23 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { orchestrationStatusValidator.validateOrchestrationStatus(execution); Mockito.verifyZeroInteractions(requestsDbClient); + verify(exceptionBuilder).buildAndThrowWorkflowException(eq(execution), eq(7000), + any(NullPointerException.class)); } - @Ignore @Test - public void test_validateOrchestrationStatus_orchestrationValidationNotFound() throws Exception { - expectedException.expect(BpmnError.class); - + public void test_validateOrchestrationStatus_orchestrationValidationNotFound() { String flowToBeCalled = "AssignServiceInstanceBB"; - execution.setVariable("flowToBeCalled", flowToBeCalled); - BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); - buildingBlockDetail.setBuildingBlockName("AssignServiceInstanceBB"); - buildingBlockDetail.setId(1); - buildingBlockDetail.setResourceType(ResourceType.SERVICE); - buildingBlockDetail.setTargetAction(OrchestrationAction.ASSIGN); + BuildingBlockDetail buildingBlockDetail = + getBuildingBlockDetail("AssignServiceInstanceBB", ResourceType.SERVICE, OrchestrationAction.ASSIGN); doReturn(buildingBlockDetail).when(catalogDbClient).getBuildingBlockDetail(flowToBeCalled); OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = - new OrchestrationStatusStateTransitionDirective(); - orchestrationStatusStateTransitionDirective.setFlowDirective(OrchestrationStatusValidationDirective.FAIL); - orchestrationStatusStateTransitionDirective.setId(1); - orchestrationStatusStateTransitionDirective.setOrchestrationStatus(OrchestrationStatus.PRECREATED); - orchestrationStatusStateTransitionDirective.setResourceType(ResourceType.SERVICE); - orchestrationStatusStateTransitionDirective.setTargetAction(OrchestrationAction.ASSIGN); + getOrchestrationStatusStateTransitionDirective(OrchestrationStatusValidationDirective.FAIL, + OrchestrationStatus.PRECREATED, ResourceType.SERVICE, OrchestrationAction.ASSIGN); doReturn(orchestrationStatusStateTransitionDirective).when(catalogDbClient) .getOrchestrationStatusStateTransitionDirective(ResourceType.NETWORK, OrchestrationStatus.PRECREATED, @@ -240,24 +218,33 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { orchestrationStatusValidator.validateOrchestrationStatus(execution); Mockito.verifyZeroInteractions(requestsDbClient); + verify(exceptionBuilder).buildAndThrowWorkflowException(eq(execution), eq(7000), + any(NullPointerException.class)); + } + + private BuildingBlockDetail getBuildingBlockDetail(String assignServiceInstanceBB, ResourceType service, + OrchestrationAction assign) { + BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); + buildingBlockDetail.setBuildingBlockName(assignServiceInstanceBB); + buildingBlockDetail.setId(1); + buildingBlockDetail.setResourceType(service); + buildingBlockDetail.setTargetAction(assign); + return buildingBlockDetail; } @Test - public void test_validateOrchestrationStatus_unassignNotFound() throws Exception { + public void test_validateOrchestrationStatus_unassignNotFound() { String flowToBeCalled = "UnassignServiceInstanceBB"; execution.setVariable("flowToBeCalled", flowToBeCalled); execution.setVariable("aLaCarte", true); - BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); - buildingBlockDetail.setBuildingBlockName("UnassignServiceInstanceBB"); - buildingBlockDetail.setId(1); - buildingBlockDetail.setResourceType(ResourceType.SERVICE); - buildingBlockDetail.setTargetAction(OrchestrationAction.UNASSIGN); + BuildingBlockDetail buildingBlockDetail = + getBuildingBlockDetail("UnassignServiceInstanceBB", ResourceType.SERVICE, OrchestrationAction.UNASSIGN); doReturn(buildingBlockDetail).when(catalogDbClient).getBuildingBlockDetail(flowToBeCalled); - lookupKeyMap = new HashMap<ResourceKey, String>(); + lookupKeyMap = new HashMap<>(); orchestrationStatusValidator.validateOrchestrationStatus(execution); @@ -285,21 +272,14 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { vfModule.setOrchestrationStatus(OrchestrationStatus.PENDING_ACTIVATION); when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule); - BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); - buildingBlockDetail.setBuildingBlockName("CreateVfModuleBB"); - buildingBlockDetail.setId(1); - buildingBlockDetail.setResourceType(ResourceType.VF_MODULE); - buildingBlockDetail.setTargetAction(OrchestrationAction.CREATE); + BuildingBlockDetail buildingBlockDetail = + getBuildingBlockDetail("CreateVfModuleBB", ResourceType.VF_MODULE, OrchestrationAction.CREATE); doReturn(buildingBlockDetail).when(catalogDbClient).getBuildingBlockDetail(flowToBeCalled); OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = - new OrchestrationStatusStateTransitionDirective(); - orchestrationStatusStateTransitionDirective.setFlowDirective(OrchestrationStatusValidationDirective.CONTINUE); - orchestrationStatusStateTransitionDirective.setId(1); - orchestrationStatusStateTransitionDirective.setOrchestrationStatus(OrchestrationStatus.PENDING_ACTIVATION); - orchestrationStatusStateTransitionDirective.setResourceType(ResourceType.VF_MODULE); - orchestrationStatusStateTransitionDirective.setTargetAction(OrchestrationAction.CREATE); + getOrchestrationStatusStateTransitionDirective(OrchestrationStatusValidationDirective.CONTINUE, + OrchestrationStatus.PENDING_ACTIVATION, ResourceType.VF_MODULE, OrchestrationAction.CREATE); doReturn(orchestrationStatusStateTransitionDirective).when(catalogDbClient) .getOrchestrationStatusStateTransitionDirective(ResourceType.VF_MODULE, @@ -334,22 +314,14 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { vfModule.setOrchestrationStatus(OrchestrationStatus.PENDING_ACTIVATION); when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule); - BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); - buildingBlockDetail.setBuildingBlockName("CreateVfModuleBB"); - buildingBlockDetail.setId(1); - buildingBlockDetail.setResourceType(ResourceType.VF_MODULE); - buildingBlockDetail.setTargetAction(OrchestrationAction.CREATE); + BuildingBlockDetail buildingBlockDetail = + getBuildingBlockDetail("CreateVfModuleBB", ResourceType.VF_MODULE, OrchestrationAction.CREATE); doReturn(buildingBlockDetail).when(catalogDbClient).getBuildingBlockDetail(flowToBeCalled); OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = - new OrchestrationStatusStateTransitionDirective(); - orchestrationStatusStateTransitionDirective - .setFlowDirective(OrchestrationStatusValidationDirective.SILENT_SUCCESS); - orchestrationStatusStateTransitionDirective.setId(1); - orchestrationStatusStateTransitionDirective.setOrchestrationStatus(OrchestrationStatus.PENDING_ACTIVATION); - orchestrationStatusStateTransitionDirective.setResourceType(ResourceType.VF_MODULE); - orchestrationStatusStateTransitionDirective.setTargetAction(OrchestrationAction.CREATE); + getOrchestrationStatusStateTransitionDirective(OrchestrationStatusValidationDirective.SILENT_SUCCESS, + OrchestrationStatus.PENDING_ACTIVATION, ResourceType.VF_MODULE, OrchestrationAction.CREATE); doReturn(orchestrationStatusStateTransitionDirective).when(catalogDbClient) .getOrchestrationStatusStateTransitionDirective(ResourceType.VF_MODULE, @@ -387,11 +359,8 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { setGenericVnf().setModelInfoGenericVnf(modelInfoGenericVnf); setVfModule().setOrchestrationStatus(OrchestrationStatus.PENDING_ACTIVATION); - BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); - buildingBlockDetail.setBuildingBlockName("CreateVfModuleBB"); - buildingBlockDetail.setId(1); - buildingBlockDetail.setResourceType(ResourceType.VF_MODULE); - buildingBlockDetail.setTargetAction(OrchestrationAction.CREATE); + BuildingBlockDetail buildingBlockDetail = + getBuildingBlockDetail("CreateVfModuleBB", ResourceType.VF_MODULE, OrchestrationAction.CREATE); doReturn(buildingBlockDetail).when(catalogDbClient).getBuildingBlockDetail(flowToBeCalled); @@ -402,13 +371,8 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule); OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = - new OrchestrationStatusStateTransitionDirective(); - orchestrationStatusStateTransitionDirective - .setFlowDirective(OrchestrationStatusValidationDirective.SILENT_SUCCESS); - orchestrationStatusStateTransitionDirective.setId(1); - orchestrationStatusStateTransitionDirective.setOrchestrationStatus(OrchestrationStatus.PENDING_ACTIVATION); - orchestrationStatusStateTransitionDirective.setResourceType(ResourceType.VF_MODULE); - orchestrationStatusStateTransitionDirective.setTargetAction(OrchestrationAction.CREATE); + getOrchestrationStatusStateTransitionDirective(OrchestrationStatusValidationDirective.SILENT_SUCCESS, + OrchestrationStatus.PENDING_ACTIVATION, ResourceType.VF_MODULE, OrchestrationAction.CREATE); doReturn(orchestrationStatusStateTransitionDirective).when(catalogDbClient) .getOrchestrationStatusStateTransitionDirective(ResourceType.VF_MODULE, @@ -446,11 +410,8 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { setGenericVnf().setModelInfoGenericVnf(modelInfoGenericVnf); setVfModule().setOrchestrationStatus(OrchestrationStatus.ASSIGNED); - BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); - buildingBlockDetail.setBuildingBlockName("CreateVfModuleBB"); - buildingBlockDetail.setId(1); - buildingBlockDetail.setResourceType(ResourceType.VF_MODULE); - buildingBlockDetail.setTargetAction(OrchestrationAction.CREATE); + BuildingBlockDetail buildingBlockDetail = + getBuildingBlockDetail("CreateVfModuleBB", ResourceType.VF_MODULE, OrchestrationAction.CREATE); doReturn(buildingBlockDetail).when(catalogDbClient).getBuildingBlockDetail(flowToBeCalled); @@ -461,13 +422,8 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule); OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = - new OrchestrationStatusStateTransitionDirective(); - orchestrationStatusStateTransitionDirective - .setFlowDirective(OrchestrationStatusValidationDirective.SILENT_SUCCESS); - orchestrationStatusStateTransitionDirective.setId(1); - orchestrationStatusStateTransitionDirective.setOrchestrationStatus(OrchestrationStatus.PENDING_ACTIVATION); - orchestrationStatusStateTransitionDirective.setResourceType(ResourceType.VF_MODULE); - orchestrationStatusStateTransitionDirective.setTargetAction(OrchestrationAction.CREATE); + getOrchestrationStatusStateTransitionDirective(OrchestrationStatusValidationDirective.SILENT_SUCCESS, + OrchestrationStatus.PENDING_ACTIVATION, ResourceType.VF_MODULE, OrchestrationAction.CREATE); doReturn(orchestrationStatusStateTransitionDirective).when(catalogDbClient) .getOrchestrationStatusStateTransitionDirective(ResourceType.VF_MODULE, OrchestrationStatus.ASSIGNED, @@ -505,11 +461,8 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { setGenericVnf().setModelInfoGenericVnf(modelInfoGenericVnf); setVfModule().setOrchestrationStatus(OrchestrationStatus.PENDING_ACTIVATION); - BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); - buildingBlockDetail.setBuildingBlockName("CreateVfModuleBB"); - buildingBlockDetail.setId(1); - buildingBlockDetail.setResourceType(ResourceType.VF_MODULE); - buildingBlockDetail.setTargetAction(OrchestrationAction.ACTIVATE); + BuildingBlockDetail buildingBlockDetail = + getBuildingBlockDetail("CreateVfModuleBB", ResourceType.VF_MODULE, OrchestrationAction.ACTIVATE); doReturn(buildingBlockDetail).when(catalogDbClient).getBuildingBlockDetail(flowToBeCalled); @@ -520,13 +473,8 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule); OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = - new OrchestrationStatusStateTransitionDirective(); - orchestrationStatusStateTransitionDirective - .setFlowDirective(OrchestrationStatusValidationDirective.SILENT_SUCCESS); - orchestrationStatusStateTransitionDirective.setId(1); - orchestrationStatusStateTransitionDirective.setOrchestrationStatus(OrchestrationStatus.PENDING_ACTIVATION); - orchestrationStatusStateTransitionDirective.setResourceType(ResourceType.VF_MODULE); - orchestrationStatusStateTransitionDirective.setTargetAction(OrchestrationAction.ACTIVATE); + getOrchestrationStatusStateTransitionDirective(OrchestrationStatusValidationDirective.SILENT_SUCCESS, + OrchestrationStatus.PENDING_ACTIVATION, ResourceType.VF_MODULE, OrchestrationAction.ACTIVATE); doReturn(orchestrationStatusStateTransitionDirective).when(catalogDbClient) .getOrchestrationStatusStateTransitionDirective(ResourceType.VF_MODULE, @@ -564,11 +512,8 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { setGenericVnf().setModelInfoGenericVnf(modelInfoGenericVnf); setVfModule().setOrchestrationStatus(OrchestrationStatus.PENDING_ACTIVATION); - BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); - buildingBlockDetail.setBuildingBlockName("CreateVfModuleBB"); - buildingBlockDetail.setId(1); - buildingBlockDetail.setResourceType(ResourceType.VF_MODULE); - buildingBlockDetail.setTargetAction(OrchestrationAction.CREATE); + BuildingBlockDetail buildingBlockDetail = + getBuildingBlockDetail("CreateVfModuleBB", ResourceType.VF_MODULE, OrchestrationAction.CREATE); doReturn(buildingBlockDetail).when(catalogDbClient).getBuildingBlockDetail(flowToBeCalled); @@ -579,13 +524,8 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule); OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = - new OrchestrationStatusStateTransitionDirective(); - orchestrationStatusStateTransitionDirective - .setFlowDirective(OrchestrationStatusValidationDirective.SILENT_SUCCESS); - orchestrationStatusStateTransitionDirective.setId(1); - orchestrationStatusStateTransitionDirective.setOrchestrationStatus(OrchestrationStatus.PENDING_ACTIVATION); - orchestrationStatusStateTransitionDirective.setResourceType(ResourceType.VF_MODULE); - orchestrationStatusStateTransitionDirective.setTargetAction(OrchestrationAction.ACTIVATE); + getOrchestrationStatusStateTransitionDirective(OrchestrationStatusValidationDirective.SILENT_SUCCESS, + OrchestrationStatus.PENDING_ACTIVATION, ResourceType.VF_MODULE, OrchestrationAction.ACTIVATE); doReturn(orchestrationStatusStateTransitionDirective).when(catalogDbClient) .getOrchestrationStatusStateTransitionDirective(ResourceType.VF_MODULE, @@ -611,11 +551,8 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { @Test public void continueValidationActivatedTest() throws Exception { String flowToBeCalled = "DeactivateVnfBB"; - BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); - buildingBlockDetail.setBuildingBlockName(flowToBeCalled); - buildingBlockDetail.setId(1); - buildingBlockDetail.setResourceType(ResourceType.VF_MODULE); - buildingBlockDetail.setTargetAction(OrchestrationAction.DEACTIVATE); + BuildingBlockDetail buildingBlockDetail = + getBuildingBlockDetail(flowToBeCalled, ResourceType.VF_MODULE, OrchestrationAction.DEACTIVATE); when(catalogDbClient.getBuildingBlockDetail(flowToBeCalled)).thenReturn(buildingBlockDetail); org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule vfModule = @@ -625,12 +562,8 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule); OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = - new OrchestrationStatusStateTransitionDirective(); - orchestrationStatusStateTransitionDirective.setFlowDirective(OrchestrationStatusValidationDirective.CONTINUE); - orchestrationStatusStateTransitionDirective.setId(1); - orchestrationStatusStateTransitionDirective.setOrchestrationStatus(OrchestrationStatus.ACTIVATED); - orchestrationStatusStateTransitionDirective.setResourceType(ResourceType.VF_MODULE); - orchestrationStatusStateTransitionDirective.setTargetAction(OrchestrationAction.DEACTIVATE); + getOrchestrationStatusStateTransitionDirective(OrchestrationStatusValidationDirective.CONTINUE, + OrchestrationStatus.ACTIVATED, ResourceType.VF_MODULE, OrchestrationAction.DEACTIVATE); doReturn(orchestrationStatusStateTransitionDirective).when(catalogDbClient) .getOrchestrationStatusStateTransitionDirective(ResourceType.VF_MODULE, OrchestrationStatus.ACTIVATED, OrchestrationAction.DEACTIVATE); @@ -666,22 +599,14 @@ public class OrchestrationStatusValidatorTest extends BaseTaskTest { vfModule.setOrchestrationStatus(OrchestrationStatus.PENDING_ACTIVATION); when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule); - BuildingBlockDetail buildingBlockDetail = new BuildingBlockDetail(); - buildingBlockDetail.setBuildingBlockName("DeleteVfModuleBB"); - buildingBlockDetail.setId(1); - buildingBlockDetail.setResourceType(ResourceType.VF_MODULE); - buildingBlockDetail.setTargetAction(OrchestrationAction.CREATE); + BuildingBlockDetail buildingBlockDetail = + getBuildingBlockDetail("DeleteVfModuleBB", ResourceType.VF_MODULE, OrchestrationAction.CREATE); doReturn(buildingBlockDetail).when(catalogDbClient).getBuildingBlockDetail(flowToBeCalled); OrchestrationStatusStateTransitionDirective orchestrationStatusStateTransitionDirective = - new OrchestrationStatusStateTransitionDirective(); - orchestrationStatusStateTransitionDirective - .setFlowDirective(OrchestrationStatusValidationDirective.SILENT_SUCCESS); - orchestrationStatusStateTransitionDirective.setId(1); - orchestrationStatusStateTransitionDirective.setOrchestrationStatus(OrchestrationStatus.PENDING_ACTIVATION); - orchestrationStatusStateTransitionDirective.setResourceType(ResourceType.VF_MODULE); - orchestrationStatusStateTransitionDirective.setTargetAction(OrchestrationAction.CREATE); + getOrchestrationStatusStateTransitionDirective(OrchestrationStatusValidationDirective.SILENT_SUCCESS, + OrchestrationStatus.PENDING_ACTIVATION, ResourceType.VF_MODULE, OrchestrationAction.CREATE); doReturn(orchestrationStatusStateTransitionDirective).when(catalogDbClient) .getOrchestrationStatusStateTransitionDirective(ResourceType.VF_MODULE, |