2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Ericsson. All rights reserved.
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.bpmn.infrastructure.adapter.vnfm.tasks;
22 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_FINISHED_STATES;
23 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_RETRIEVAL_STATES;
24 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_STATUS_PARAM_NAME;
25 import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStateEnum;
26 import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.QueryJobResponse;
27 import org.onap.so.bpmn.common.BuildingBlockExecution;
28 import org.onap.so.client.exception.ExceptionBuilder;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.stereotype.Component;
33 import com.google.common.base.Optional;
38 * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech)
42 public class MonitorVnfmJobTask {
44 private static final Logger LOGGER = LoggerFactory.getLogger(MonitorVnfmJobTask.class);
45 protected final ExceptionBuilder exceptionUtil;
46 protected final VnfmAdapterServiceProvider vnfmAdapterServiceProvider;
49 public MonitorVnfmJobTask(final VnfmAdapterServiceProvider vnfmAdapterServiceProvider,
50 final ExceptionBuilder exceptionUtil) {
51 this.vnfmAdapterServiceProvider = vnfmAdapterServiceProvider;
52 this.exceptionUtil = exceptionUtil;
56 * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
57 * @return boolean to indicate whether job has competed or not
59 public boolean hasOperationFinished(final BuildingBlockExecution execution) {
60 LOGGER.debug("Executing hasOperationFinished ...");
62 final Optional<OperationStateEnum> operationStatusOption = execution.getVariable(OPERATION_STATUS_PARAM_NAME);
63 if (operationStatusOption != null && operationStatusOption.isPresent()) {
64 return OPERATION_FINISHED_STATES.contains(operationStatusOption.get());
66 LOGGER.debug("OperationStatus is not present yet... ");
67 LOGGER.debug("Finished executing hasOperationFinished ...");
72 * This method calls the Vnfm adapter and gets the Operation status of the job
74 * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
75 * @param jobId unique job id
76 * @return Operation State
78 protected Optional<OperationStateEnum> getOperationStatus(final BuildingBlockExecution execution,
81 final Optional<QueryJobResponse> instantiateOperationJobStatus =
82 vnfmAdapterServiceProvider.getInstantiateOperationJobStatus(jobId);
84 if (instantiateOperationJobStatus.isPresent()) {
85 final QueryJobResponse queryJobResponse = instantiateOperationJobStatus.get();
87 if (!OPERATION_RETRIEVAL_STATES.contains(queryJobResponse.getOperationStatusRetrievalStatus())) {
88 final String message = "Recevied invalid operation reterivel state: "
89 + queryJobResponse.getOperationStatusRetrievalStatus();
90 LOGGER.error(message);
91 exceptionUtil.buildAndThrowWorkflowException(execution, 1203, message);
93 if (queryJobResponse.getOperationState() != null) {
94 final OperationStateEnum operationStatus = queryJobResponse.getOperationState();
95 LOGGER.debug("Operation {} with {} and operation retrieval status : {}", queryJobResponse.getId(),
96 operationStatus, queryJobResponse.getOperationStatusRetrievalStatus());
97 return Optional.of(queryJobResponse.getOperationState());
100 LOGGER.debug("Operation {} without operationStatus and operation retrieval status :{}",
101 queryJobResponse.getId(), queryJobResponse.getOperationStatusRetrievalStatus());
103 return Optional.absent();