2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Ericsson. All rights reserved.
4 * ================================================================================
5 * Copyright (C) 2019 Samsung
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
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.CREATE_VNF_RESPONSE_PARAM_NAME;
23 import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_STATUS_PARAM_NAME;
24 import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.CreateVnfResponse;
25 import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStateEnum;
26 import org.onap.so.bpmn.common.BuildingBlockExecution;
27 import org.onap.so.client.exception.ExceptionBuilder;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.stereotype.Component;
32 import com.google.common.base.Optional;
36 * @author waqas.ikram@est.tech
40 public class MonitorVnfmCreateJobTask extends MonitorVnfmJobTask {
42 private static final Logger LOGGER = LoggerFactory.getLogger(MonitorVnfmCreateJobTask.class);
45 public MonitorVnfmCreateJobTask(final VnfmAdapterServiceProvider vnfmAdapterServiceProvider,
46 final ExceptionBuilder exceptionUtil) {
47 super(vnfmAdapterServiceProvider, exceptionUtil);
51 * Get the current operation status of instantiation job
53 * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
55 public void getCurrentOperationStatus(final BuildingBlockExecution execution) {
57 LOGGER.debug("Executing getCurrentOperationStatus ...");
58 final CreateVnfResponse vnfInstantiateResponse = execution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME);
59 execution.setVariable(OPERATION_STATUS_PARAM_NAME,
60 getOperationStatus(execution, vnfInstantiateResponse.getJobId()));
61 LOGGER.debug("Finished executing getCurrentOperationStatus ...");
62 } catch (final Exception exception) {
63 final String message = "Unable to invoke get current Operation status";
64 LOGGER.error(message);
65 exceptionUtil.buildAndThrowWorkflowException(execution, 1209, message);
71 * Log and throw exception on timeout for job status
73 * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
75 public void timeOutLogFailue(final BuildingBlockExecution execution) {
76 final String message = "Instantiation operation time out";
77 LOGGER.error(message);
78 exceptionUtil.buildAndThrowWorkflowException(execution, 1205, message);
82 * Check the final status of instantiation throw exception if not completed successfully
84 * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
86 public void checkIfOperationWasSuccessful(final BuildingBlockExecution execution) {
87 LOGGER.debug("Executing checkIfOperationWasSuccessful ...");
88 final Optional<OperationStateEnum> operationStatusOption = execution.getVariable(OPERATION_STATUS_PARAM_NAME);
89 final CreateVnfResponse vnfInstantiateResponse = execution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME);
90 if (operationStatusOption == null || !operationStatusOption.isPresent()) {
91 final String message = "Unable to instantiate jobId: "
92 + (vnfInstantiateResponse != null ? vnfInstantiateResponse.getJobId() : "null")
93 + "Unable to retrieve OperationStatus";
94 LOGGER.error(message);
95 exceptionUtil.buildAndThrowWorkflowException(execution, 1206, message);
96 } else if (operationStatusOption != null && operationStatusOption.isPresent()) {
97 final OperationStateEnum operationStatus = operationStatusOption.get();
98 if (operationStatus != OperationStateEnum.COMPLETED) {
99 final String message = "Unable to instantiate jobId: "
100 + (vnfInstantiateResponse != null ? vnfInstantiateResponse.getJobId() : "null")
101 + " OperationStatus: " + operationStatus;
102 LOGGER.error(message);
103 exceptionUtil.buildAndThrowWorkflowException(execution, 1207, message);
105 LOGGER.debug("Successfully completed instatiation of job {}", vnfInstantiateResponse);