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) --- .../CloudRegionOrchestrationValidator.java | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidator.java (limited to 'bpmn/so-bpmn-tasks/src/main') 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(); + } + +} -- cgit 1.2.3-korg