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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.tasks;
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;
32 * @author Waqas Ikram (waqas.ikram@est.tech)
35 public abstract class MonitorSol003AdapterNodeTask extends AbstractNetworkServiceTask {
37 private static final Logger LOGGER = LoggerFactory.getLogger(MonitorSol003AdapterNodeTask.class);
38 private final AaiServiceProvider aaiServiceProvider;
40 protected MonitorSol003AdapterNodeTask(final DatabaseServiceProvider databaseServiceProvider,
41 final AaiServiceProvider aaiServiceProvider) {
42 super(databaseServiceProvider);
43 this.aaiServiceProvider = aaiServiceProvider;
47 * Check the final status of vnf in A&AI
49 * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
51 public void getNodeStatus(final DelegateExecution execution) {
53 LOGGER.debug("Executing getNodeStatus ...");
54 final String vnfId = (String) execution.getVariable(NF_INST_ID_PARAM_NAME);
56 LOGGER.debug("Query A&AI for generic VNF using vnfID: {}", vnfId);
57 final Optional<GenericVnf> aaiGenericVnfOptional = aaiServiceProvider.getGenericVnf(vnfId);
59 if (aaiGenericVnfOptional.isEmpty()) {
60 abortOperation(execution, "Unable to find generic vnf in A&AI using vnfId" + vnfId);
62 final GenericVnf genericVnf = aaiGenericVnfOptional.get();
63 final String orchestrationStatus = genericVnf.getOrchestrationStatus();
64 LOGGER.debug("Found generic vnf with orchestration status : {}", orchestrationStatus);
66 execution.setVariable(getNodeStatusVariableName(), isOrchestrationStatusValid(orchestrationStatus));
68 } catch (final Exception exception) {
69 LOGGER.error("Unable to get vnf from AAI", exception);
70 abortOperation(execution, "Unable to get vnf from AAI");
75 * Get variable to store in execution context
77 * @return the variable name
79 public abstract String getNodeStatusVariableName();
82 * @param orchestrationStatus the orchestration status from A&AI
83 * @return true if valid
85 public abstract boolean isOrchestrationStatusValid(final String orchestrationStatus);
87 public void timeOutLogFailue(final DelegateExecution execution) {
88 final String message = "Node operation time out";
89 LOGGER.error(message);
90 abortOperation(execution, message);
93 AaiServiceProvider getAaiServiceProvider() {
94 return aaiServiceProvider;