diff options
author | Steve Smokowski <ss835w@att.com> | 2019-02-20 13:13:45 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-02-20 13:13:45 +0000 |
commit | 20a24c8e780890d4e63b281e5de16080d322bf17 (patch) | |
tree | a4a27e0a9b9963560cc59e1b3e4a0a65d5e08e41 /bpmn/so-bpmn-tasks/src | |
parent | 75a0957c5d544bf96bbcfba1594d1e23b417a01e (diff) | |
parent | 2fdc72da4f188853421fcb3b425c398267c6d2e3 (diff) |
Merge "Create Pre Building Block validator"
Diffstat (limited to 'bpmn/so-bpmn-tasks/src')
2 files changed, 145 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidator.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidator.java new file mode 100644 index 0000000000..7a433c06a6 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidator.java @@ -0,0 +1,48 @@ +package org.onap.so.bpmn.infrastructure.validations; + +import java.util.Optional; +import java.util.regex.Pattern; + +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.validation.PreBuildingBlockValidator; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.client.exception.ExceptionBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class CloudRegionOrchestrationValidator implements PreBuildingBlockValidator { + + private static Logger logger = LoggerFactory.getLogger(CloudRegionOrchestrationValidator.class); + private final Pattern pattern = Pattern.compile("(?:Activate|Assign|Create|Deactivate|Delete|Unassign|Update)(?:Network|Vnf|VfModule|VolumeGroup|FabricConfiguration)BB"); + + @Autowired + private ExceptionBuilder exceptionBuilder; + + @Override + public boolean shouldRunFor(String bbName) { + return pattern.matcher(bbName).find(); + } + + @Override + public Optional<String> validate(BuildingBlockExecution execution) { + String msg = null; + try { + CloudRegion cloudRegion = execution.getGeneralBuildingBlock().getCloudRegion(); + if (Boolean.TRUE.equals(cloudRegion.getOrchestrationDisabled())) { + msg = String.format("Error: The request has failed due to orchestration currently disabled for the target cloud region %s for cloud owner %s", + cloudRegion.getLcpCloudRegionId(), cloudRegion.getCloudOwner()); + logger.error(msg); + return Optional.ofNullable(msg); + } + } + catch(Exception e) { + logger.error("failed to validate", e); + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e); + } + return Optional.empty(); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidatorTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidatorTest.java new file mode 100644 index 0000000000..f6988fdcd4 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidatorTest.java @@ -0,0 +1,97 @@ +package org.onap.so.bpmn.infrastructure.validations; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import java.util.Optional; +import java.util.Set; + +import org.junit.Before; +import org.junit.Test; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; + +public class CloudRegionOrchestrationValidatorTest { + + private BuildingBlockExecution mockExecution; + private CloudRegion cloudRegion; + + @Before + public void setUp() { + cloudRegion = new CloudRegion(); + cloudRegion.setCloudOwner("CloudOwner"); + cloudRegion.setLcpCloudRegionId("my-region-id"); + GeneralBuildingBlock gbb = new GeneralBuildingBlock(); + gbb.setCloudRegion(cloudRegion); + mockExecution = mock(BuildingBlockExecution.class); + doReturn(gbb).when(mockExecution).getGeneralBuildingBlock(); + } + + @Test + public void validateDisabledTest() { + cloudRegion.setOrchestrationDisabled(true); + CloudRegionOrchestrationValidator validation = new CloudRegionOrchestrationValidator(); + Optional<String> result = validation.validate(mockExecution); + assertEquals("Error: The request has failed due to orchestration currently disabled for the target cloud region my-region-id for cloud owner CloudOwner", + result.get()); + } + + @Test + public void validateNotDisabledTest() { + cloudRegion.setOrchestrationDisabled(false); + CloudRegionOrchestrationValidator validation = new CloudRegionOrchestrationValidator(); + Optional<String> result = validation.validate(mockExecution); + assertFalse(result.isPresent()); + } + + @Test + public void validateDisabledIsNullTest() { + CloudRegionOrchestrationValidator validation = new CloudRegionOrchestrationValidator(); + Optional<String> result = validation.validate(mockExecution); + assertFalse(result.isPresent()); + } + + @Test + public void shouldRunForTest() { + CloudRegionOrchestrationValidator validator = new CloudRegionOrchestrationValidator(); + assertTrue(validator.shouldRunFor("ActivateNetworkBB")); + assertTrue(validator.shouldRunFor("AssignNetworkBB")); + assertTrue(validator.shouldRunFor("CreateNetworkBB")); + assertTrue(validator.shouldRunFor("DeactivateNetworkBB")); + assertTrue(validator.shouldRunFor("DeleteNetworkBB")); + assertTrue(validator.shouldRunFor("UnassignNetworkBB")); + assertTrue(validator.shouldRunFor("UpdateNetworkBB")); + + assertTrue(validator.shouldRunFor("ActivateVnfBB")); + assertTrue(validator.shouldRunFor("AssignVnfBB")); + assertTrue(validator.shouldRunFor("UnassignVnfBB")); + assertTrue(validator.shouldRunFor("DeactivateVnfBB")); + + assertTrue(validator.shouldRunFor("ActivateVfModuleBB")); + assertTrue(validator.shouldRunFor("AssignVfModuleBB")); + assertTrue(validator.shouldRunFor("CreateVfModuleBB")); + assertTrue(validator.shouldRunFor("DeactivateVfModuleBB")); + assertTrue(validator.shouldRunFor("DeleteVfModuleBB")); + assertTrue(validator.shouldRunFor("UnassignVfModuleBB")); + + assertTrue(validator.shouldRunFor("ActivateVolumeGroupBB")); + assertTrue(validator.shouldRunFor("AssignVolumeGroupBB")); + assertTrue(validator.shouldRunFor("CreateVolumeGroupBB")); + assertTrue(validator.shouldRunFor("DeactivateVolumeGroupBB")); + assertTrue(validator.shouldRunFor("DeleteVolumeGroupBB")); + assertTrue(validator.shouldRunFor("UnassignVolumeGroupBB")); + + assertTrue(validator.shouldRunFor("ActivateFabricConfigurationBB")); + assertTrue(validator.shouldRunFor("AssignFabricConfigurationBB")); + assertTrue(validator.shouldRunFor("UnassignFabricConfigurationBB")); + assertTrue(validator.shouldRunFor("DeactivateFabricConfigurationBB")); + + assertFalse(validator.shouldRunFor("AssignServiceInstanceBB")); + assertFalse(validator.shouldRunFor("AAICheckVnfInMaintBB")); + assertFalse(validator.shouldRunFor("ChangeModelVfModuleBB")); + assertFalse(validator.shouldRunFor("CreateNetworkCollectionBB")); + } +} |