summaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks/src/main
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2019-02-19 18:00:41 -0500
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-02-19 21:53:08 -0500
commit2fdc72da4f188853421fcb3b425c398267c6d2e3 (patch)
treec290e06c792750107bbb0c7b81611ac9f4117b2e /bpmn/so-bpmn-tasks/src/main
parent6ca9bedf6206a98991acb742206ce0b8113684fa (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/main')
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/validations/CloudRegionOrchestrationValidator.java48
1 files changed, 48 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();
+ }
+
+}