2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.so.bpmn.infrastructure.aai.tasks;
25 import org.onap.so.bpmn.common.BuildingBlockExecution;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf;
28 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
29 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
30 import org.onap.so.client.exception.ExceptionBuilder;
31 import org.onap.so.client.orchestration.AAIPnfResources;
32 import org.onap.so.client.orchestration.AAIVnfResources;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Component;
39 public class AAIFlagTasks {
40 private static final Logger logger = LoggerFactory.getLogger(AAIFlagTasks.class);
44 private AAIVnfResources aaiVnfResources;
47 private AAIPnfResources aaiPnfResources;
49 private ExceptionBuilder exceptionUtil;
51 private ExtractPojosForBB extractPojosForBB;
53 public void checkVnfInMaintFlag(BuildingBlockExecution execution) {
54 boolean inMaint = false;
56 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
57 String vnfId = vnf.getVnfId();
58 inMaint = aaiVnfResources.checkInMaintFlag(vnfId);
59 } catch (Exception ex) {
60 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
63 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "VNF is in maintenance in A&AI");
67 public void modifyVnfInMaintFlag(BuildingBlockExecution execution, boolean inMaint) {
69 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
71 GenericVnf copiedGenericVnf = genericVnf.shallowCopyId();
73 copiedGenericVnf.setInMaint(inMaint);
74 genericVnf.setInMaint(inMaint);
76 aaiVnfResources.updateObjectVnf(copiedGenericVnf);
77 } catch (Exception ex) {
78 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
82 public void checkPnfInMaintFlag(BuildingBlockExecution execution) {
83 boolean inMaint = false;
85 Pnf pnf = extractPojosForBB.extractByKey(execution, ResourceKey.PNF);
86 String pnfName = pnf.getPnfName();
87 inMaint = aaiPnfResources.checkInMaintFlag(pnfName);
88 } catch (Exception ex) {
89 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
92 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "PNF is already in maintenance in A&AI");
96 public void modifyPnfInMaintFlag(BuildingBlockExecution execution, boolean inMaint) {
98 Pnf pnf = extractPojosForBB.extractByKey(execution, ResourceKey.PNF);
99 logger.info("In modifyPnfInMaintFlag pnfname: {}", pnf.getPnfName());
100 Pnf copiedPnf = pnf.shallowCopyId();
101 copiedPnf.setPnfName(pnf.getPnfName());
103 copiedPnf.setInMaint(inMaint);
104 pnf.setInMaint(inMaint);
105 logger.info("In modifyPnfInMaintFlag if block pnfInMaint: {}, copiedPnfInMaint: {}", pnf.isInMaint(),
106 copiedPnf.isInMaint());
107 aaiPnfResources.updateObjectPnf(copiedPnf);
109 } catch (Exception ex) {
110 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
115 public void checkVnfClosedLoopDisabledFlag(BuildingBlockExecution execution) {
116 boolean isClosedLoopDisabled = false;
118 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
119 String vnfId = vnf.getVnfId();
120 isClosedLoopDisabled = aaiVnfResources.checkVnfClosedLoopDisabledFlag(vnfId);
121 } catch (Exception ex) {
122 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
124 if (isClosedLoopDisabled) {
125 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "VNF Close Loop Disabled in A&AI");
129 public void modifyVnfClosedLoopDisabledFlag(BuildingBlockExecution execution, boolean closedLoopDisabled) {
131 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
133 GenericVnf copiedGenericVnf = genericVnf.shallowCopyId();
134 copiedGenericVnf.setClosedLoopDisabled(closedLoopDisabled);
135 genericVnf.setClosedLoopDisabled(closedLoopDisabled);
137 aaiVnfResources.updateObjectVnf(copiedGenericVnf);
138 } catch (Exception ex) {
139 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
143 public void checkVnfPserversLockedFlag(BuildingBlockExecution execution) {
144 boolean inPserversLocked = false;
146 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
147 String vnfId = vnf.getVnfId();
148 inPserversLocked = aaiVnfResources.checkVnfPserversLockedFlag(vnfId);
149 } catch (Exception ex) {
150 logger.warn("Exception on checking pservers: " + ex.getMessage());
152 if (inPserversLocked) {
153 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "VNF PServers in Locked in A&AI");