Merge "Add subscription for notifications"
[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     @Autowired
41     private AAIVnfResources aaiVnfResources;
42     @Autowired
43     private ExceptionBuilder exceptionUtil;
44     @Autowired
45     private ExtractPojosForBB extractPojosForBB;
46
47     public void checkVnfInMaintFlag(BuildingBlockExecution execution) {
48         boolean inMaint = false;
49         try {
50             GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
51             String vnfId = vnf.getVnfId();
52             inMaint = aaiVnfResources.checkInMaintFlag(vnfId);
53         } catch (Exception ex) {
54             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
55         }
56         if (inMaint) {
57             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "VNF is in maintenance in A&AI");
58         }
59     }
60
61     public void modifyVnfInMaintFlag(BuildingBlockExecution execution, boolean inMaint) {
62         try {
63             GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
64
65             GenericVnf copiedGenericVnf = genericVnf.shallowCopyId();
66
67             copiedGenericVnf.setInMaint(inMaint);
68             genericVnf.setInMaint(inMaint);
69
70             aaiVnfResources.updateObjectVnf(copiedGenericVnf);
71         } catch (Exception ex) {
72             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
73         }
74     }
75
76     public void checkVnfClosedLoopDisabledFlag(BuildingBlockExecution execution) {
77         boolean isClosedLoopDisabled = false;
78         try {
79             GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
80             String vnfId = vnf.getVnfId();
81             isClosedLoopDisabled = aaiVnfResources.checkVnfClosedLoopDisabledFlag(vnfId);
82         } catch (Exception ex) {
83             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
84         }
85         if (isClosedLoopDisabled) {
86             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "VNF Close Loop Disabled in A&AI");
87         }
88     }
89
90     public void modifyVnfClosedLoopDisabledFlag(BuildingBlockExecution execution, boolean closedLoopDisabled) {
91         try {
92             GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
93
94             GenericVnf copiedGenericVnf = genericVnf.shallowCopyId();
95             copiedGenericVnf.setClosedLoopDisabled(closedLoopDisabled);
96             genericVnf.setClosedLoopDisabled(closedLoopDisabled);
97
98             aaiVnfResources.updateObjectVnf(copiedGenericVnf);
99         } catch (Exception ex) {
100             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
101         }
102     }
103
104     public void checkVnfPserversLockedFlag(BuildingBlockExecution execution) {
105         boolean inPserversLocked = false;
106         try {
107             GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
108             String vnfId = vnf.getVnfId();
109             inPserversLocked = aaiVnfResources.checkVnfPserversLockedFlag(vnfId);
110         } catch (Exception ex) {
111             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
112         }
113         if (inPserversLocked) {
114             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "VNF PServers in Locked in A&AI");
115         }
116     }
117 }