diff options
author | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2019-02-19 18:00:41 -0500 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2019-02-19 21:53:08 -0500 |
commit | 2fdc72da4f188853421fcb3b425c398267c6d2e3 (patch) | |
tree | c290e06c792750107bbb0c7b81611ac9f4117b2e /bpmn/so-bpmn-tasks/src | |
parent | 6ca9bedf6206a98991acb742206ce0b8113684fa (diff) |
Create Pre Building Block validator
Use Flowvalidator shouldRunFor method to check if flow needs to be
validated.
Create Pre Building Block validator to check if cloud-region
orchestration-disabled is true
Change-Id: I2f1dca16c97505292d9b99f7e206713e4963261f
Issue-ID: SO-1534
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
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")); + } +} |