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.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;
37 public class AAIFlagTasks {
40 private AAIVnfResources aaiVnfResources;
42 private ExceptionBuilder exceptionUtil;
44 private ExtractPojosForBB extractPojosForBB;
46 public void checkVnfInMaintFlag(BuildingBlockExecution execution) {
47 boolean inMaint = false;
49 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
50 String vnfId = vnf.getVnfId();
51 inMaint = aaiVnfResources.checkInMaintFlag(vnfId);
52 } catch (Exception ex) {
53 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
56 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "VNF is in maintenance in A&AI");
60 public void modifyVnfInMaintFlag(BuildingBlockExecution execution, boolean inMaint) {
62 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
64 GenericVnf copiedGenericVnf = genericVnf.shallowCopyId();
66 copiedGenericVnf.setInMaint(inMaint);
67 genericVnf.setInMaint(inMaint);
69 aaiVnfResources.updateObjectVnf(copiedGenericVnf);
70 } catch (Exception ex) {
71 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
75 public void checkVnfClosedLoopDisabledFlag(BuildingBlockExecution execution) {
76 boolean isClosedLoopDisabled = false;
78 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
79 String vnfId = vnf.getVnfId();
80 isClosedLoopDisabled = aaiVnfResources.checkVnfClosedLoopDisabledFlag(vnfId);
81 } catch (Exception ex) {
82 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
84 if (isClosedLoopDisabled) {
85 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "VNF Close Loop Disabled in A&AI");
89 public void modifyVnfClosedLoopDisabledFlag(BuildingBlockExecution execution, boolean closedLoopDisabled) {
91 GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
93 GenericVnf copiedGenericVnf = genericVnf.shallowCopyId();
94 copiedGenericVnf.setClosedLoopDisabled(closedLoopDisabled);
95 genericVnf.setClosedLoopDisabled(closedLoopDisabled);
97 aaiVnfResources.updateObjectVnf(copiedGenericVnf);
98 } catch (Exception ex) {
99 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
103 public void checkVnfPserversLockedFlag(BuildingBlockExecution execution) {
104 boolean inPserversLocked = false;
106 GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
107 String vnfId = vnf.getVnfId();
108 inPserversLocked = aaiVnfResources.checkVnfPserversLockedFlag(vnfId);
109 } catch (Exception ex) {
110 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
112 if (inPserversLocked) {
113 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "VNF PServers in Locked in A&AI");