From 2fdc72da4f188853421fcb3b425c398267c6d2e3 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Tue, 19 Feb 2019 18:00:41 -0500 Subject: 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) --- .../bbobjects/CloudRegion.java | 8 ++ .../CloudRegionOrchestrationValidator.java | 48 +++++++++++ .../CloudRegionOrchestrationValidatorTest.java | 97 ++++++++++++++++++++++ common/pom.xml | 4 +- 4 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidator.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidatorTest.java diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/CloudRegion.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/CloudRegion.java index f39253e6aa..df1eeae1b6 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/CloudRegion.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/CloudRegion.java @@ -45,6 +45,8 @@ public class CloudRegion implements Serializable, ShallowCopy { private String complex; @JsonProperty("cloud-region-version") private String cloudRegionVersion; + @JsonProperty("orchestration-disabled") + private Boolean orchestrationDisabled; public String getLcpCloudRegionId() { return lcpCloudRegionId; @@ -88,6 +90,12 @@ public class CloudRegion implements Serializable, ShallowCopy { public void setComplex(String complex) { this.complex = complex; } + public Boolean getOrchestrationDisabled() { + return orchestrationDisabled; + } + public void setOrchestrationDisabled(Boolean orchestrationDisabled) { + this.orchestrationDisabled = orchestrationDisabled; + } @Override public boolean equals(final Object other) { if (!(other instanceof CloudRegion)) { 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 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 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 result = validation.validate(mockExecution); + assertFalse(result.isPresent()); + } + + @Test + public void validateDisabledIsNullTest() { + CloudRegionOrchestrationValidator validation = new CloudRegionOrchestrationValidator(); + Optional 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")); + } +} diff --git a/common/pom.xml b/common/pom.xml index 51c9ed3bcb..6bd142ddb2 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -47,9 +47,9 @@ spring-webmvc - org.onap.aai.aai-common + org.onap.aai.schema-service aai-schema - 1.4.1-SNAPSHOT + 1.0.0-SNAPSHOT org.modelmapper -- cgit 1.2.3-korg