001c3698017592b55323366ba50917966eff09e9
[so.git] / so-etsi-nfvo / so-etsi-nfvo-ns-lcm / so-etsi-nfvo-ns-lcm-bpmn-flows / src / main / java / org / onap / so / etsi / nfvo / ns / lcm / bpmn / flows / tasks / MonitorSol003AdapterNodeTask.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.tasks;
21
22 import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NF_INST_ID_PARAM_NAME;
23 import java.util.Optional;
24 import org.camunda.bpm.engine.delegate.DelegateExecution;
25 import org.onap.aai.domain.yang.GenericVnf;
26 import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.aai.AaiServiceProvider;
27 import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 /**
32  * @author Waqas Ikram (waqas.ikram@est.tech)
33  *
34  */
35 public abstract class MonitorSol003AdapterNodeTask extends AbstractNetworkServiceTask {
36
37     private static final Logger LOGGER = LoggerFactory.getLogger(MonitorSol003AdapterNodeTask.class);
38     private final AaiServiceProvider aaiServiceProvider;
39
40     protected MonitorSol003AdapterNodeTask(final DatabaseServiceProvider databaseServiceProvider,
41             final AaiServiceProvider aaiServiceProvider) {
42         super(databaseServiceProvider);
43         this.aaiServiceProvider = aaiServiceProvider;
44     }
45
46     /**
47      * Check the final status of vnf in A&AI
48      *
49      * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
50      */
51     public void getNodeStatus(final DelegateExecution execution) {
52         try {
53             LOGGER.debug("Executing getNodeStatus  ...");
54             final String vnfId = (String) execution.getVariable(NF_INST_ID_PARAM_NAME);
55
56             LOGGER.debug("Query A&AI for generic VNF using vnfID: {}", vnfId);
57             final Optional<GenericVnf> aaiGenericVnfOptional = aaiServiceProvider.getGenericVnf(vnfId);
58
59             if (aaiGenericVnfOptional.isEmpty()) {
60                 abortOperation(execution, "Unable to find generic vnf in A&AI using vnfId" + vnfId);
61             }
62             final GenericVnf genericVnf = aaiGenericVnfOptional.get();
63             final String orchestrationStatus = genericVnf.getOrchestrationStatus();
64             LOGGER.debug("Found generic vnf with orchestration status : {}", orchestrationStatus);
65
66             execution.setVariable(getNodeStatusVariableName(), isOrchestrationStatusValid(orchestrationStatus));
67
68         } catch (final Exception exception) {
69             LOGGER.error("Unable to get vnf from AAI", exception);
70             abortOperation(execution, "Unable to get vnf from AAI");
71         }
72     }
73
74     /**
75      * Get variable to store in execution context
76      *
77      * @return the variable name
78      */
79     public abstract String getNodeStatusVariableName();
80
81     /**
82      * @param orchestrationStatus the orchestration status from A&AI
83      * @return true if valid
84      */
85     public abstract boolean isOrchestrationStatusValid(final String orchestrationStatus);
86
87     public void timeOutLogFailue(final DelegateExecution execution) {
88         final String message = "Node operation time out";
89         LOGGER.error(message);
90         abortOperation(execution, message);
91     }
92
93     AaiServiceProvider getAaiServiceProvider() {
94         return aaiServiceProvider;
95     }
96 }