2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.bpmn.infrastructure.validations;
23 import java.util.Optional;
24 import java.util.regex.Pattern;
26 import org.onap.so.bpmn.common.BuildingBlockExecution;
27 import org.onap.so.bpmn.common.validation.PreBuildingBlockValidator;
28 import org.onap.so.bpmn.common.validation.Skip;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
30 import org.onap.so.client.exception.ExceptionBuilder;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Component;
38 public class CloudRegionOrchestrationValidator implements PreBuildingBlockValidator {
40 private static Logger logger = LoggerFactory.getLogger(CloudRegionOrchestrationValidator.class);
41 private final Pattern pattern = Pattern.compile("(?:Activate|Assign|Create|Deactivate|Delete|Unassign|Update)(?:Network|Vnf|VfModule|VolumeGroup|FabricConfiguration)BB");
44 private ExceptionBuilder exceptionBuilder;
47 public boolean shouldRunFor(String bbName) {
48 return pattern.matcher(bbName).find();
52 public Optional<String> validate(BuildingBlockExecution execution) {
55 CloudRegion cloudRegion = execution.getGeneralBuildingBlock().getCloudRegion();
56 if (Boolean.TRUE.equals(cloudRegion.getOrchestrationDisabled())) {
57 msg = String.format("Error: The request has failed due to orchestration currently disabled for the target cloud region %s for cloud owner %s",
58 cloudRegion.getLcpCloudRegionId(), cloudRegion.getCloudOwner());
60 return Optional.ofNullable(msg);
64 logger.error("failed to validate", e);
65 exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e);
67 return Optional.empty();