997d20036f96bd8fb9d488fe875d7e5add028165
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / aai / tasks / AAIFlagTasks.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure.aai.tasks;
24
25 import org.onap.so.bpmn.common.BuildingBlockExecution;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
27 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
28 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
29 import org.onap.so.client.exception.ExceptionBuilder;
30 import org.onap.so.client.orchestration.AAIVnfResources;
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 public class AAIFlagTasks {
38     private static final Logger logger = LoggerFactory.getLogger(AAIFlagTasks.class);
39
40
41     @Autowired
42     private AAIVnfResources aaiVnfResources;
43     @Autowired
44     private ExceptionBuilder exceptionUtil;
45     @Autowired
46     private ExtractPojosForBB extractPojosForBB;
47
48     public void checkVnfInMaintFlag(BuildingBlockExecution execution) {
49         boolean inMaint = false;
50         try {
51             GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
52             String vnfId = vnf.getVnfId();
53             inMaint = aaiVnfResources.checkInMaintFlag(vnfId);
54         } catch (Exception ex) {
55             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
56         }
57         if (inMaint) {
58             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "VNF is in maintenance in A&AI");
59         }
60     }
61
62     public void modifyVnfInMaintFlag(BuildingBlockExecution execution, boolean inMaint) {
63         try {
64             GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
65
66             GenericVnf copiedGenericVnf = genericVnf.shallowCopyId();
67
68             copiedGenericVnf.setInMaint(inMaint);
69             genericVnf.setInMaint(inMaint);
70
71             aaiVnfResources.updateObjectVnf(copiedGenericVnf);
72         } catch (Exception ex) {
73             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
74         }
75     }
76
77     public void checkVnfClosedLoopDisabledFlag(BuildingBlockExecution execution) {
78         boolean isClosedLoopDisabled = false;
79         try {
80             GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
81             String vnfId = vnf.getVnfId();
82             isClosedLoopDisabled = aaiVnfResources.checkVnfClosedLoopDisabledFlag(vnfId);
83         } catch (Exception ex) {
84             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
85         }
86         if (isClosedLoopDisabled) {
87             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "VNF Close Loop Disabled in A&AI");
88         }
89     }
90
91     public void modifyVnfClosedLoopDisabledFlag(BuildingBlockExecution execution, boolean closedLoopDisabled) {
92         try {
93             GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
94
95             GenericVnf copiedGenericVnf = genericVnf.shallowCopyId();
96             copiedGenericVnf.setClosedLoopDisabled(closedLoopDisabled);
97             genericVnf.setClosedLoopDisabled(closedLoopDisabled);
98
99             aaiVnfResources.updateObjectVnf(copiedGenericVnf);
100         } catch (Exception ex) {
101             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
102         }
103     }
104
105     public void checkVnfPserversLockedFlag(BuildingBlockExecution execution) {
106         boolean inPserversLocked = false;
107         try {
108             GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
109             String vnfId = vnf.getVnfId();
110             inPserversLocked = aaiVnfResources.checkVnfPserversLockedFlag(vnfId);
111         } catch (Exception ex) {
112             logger.warn("Exception on checking pservers: " + ex.getMessage());
113         }
114         if (inPserversLocked) {
115             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "VNF PServers in Locked in A&AI");
116         }
117     }
118 }