Openstack adapter can't resolve HEAT parameter
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / validations / CloudRegionOrchestrationValidator.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.validations;
22
23 import java.util.Optional;
24 import java.util.regex.Pattern;
25
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;
35
36 @Component
37 @Skip
38 public class CloudRegionOrchestrationValidator implements PreBuildingBlockValidator {
39
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");
42         
43         @Autowired
44         private ExceptionBuilder exceptionBuilder;
45
46         @Override
47         public boolean shouldRunFor(String bbName) {
48                 return pattern.matcher(bbName).find();
49         }
50                 
51         @Override
52         public Optional<String> validate(BuildingBlockExecution execution) {
53                 String msg = null;
54                 try {
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());
59                                 logger.error(msg);
60                                 return Optional.ofNullable(msg);
61                         }
62                 }
63                 catch(Exception e) {
64                         logger.error("failed to validate", e);
65                         exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, e);    
66                 }
67                 return Optional.empty();
68         }
69
70 }