Merge "Removing so-monitoring module"
[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 / MonitorSol003AdapterCreateJobTask.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.CREATE_VNF_RESPONSE_PARAM_NAME;
23 import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.OPERATION_STATUS_PARAM_NAME;
24 import org.camunda.bpm.engine.delegate.DelegateExecution;
25 import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.CreateVnfResponse;
26 import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStateEnum;
27 import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.vnfm.Sol003AdapterServiceProvider;
28 import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider;
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
34 /**
35  * @author Waqas Ikram (waqas.ikram@est.tech)
36  *
37  */
38 @Component
39 public class MonitorSol003AdapterCreateJobTask extends MonitorSol003AdapterJobTask {
40
41     private static final Logger LOGGER = LoggerFactory.getLogger(MonitorSol003AdapterCreateJobTask.class);
42
43     @Autowired
44     public MonitorSol003AdapterCreateJobTask(final Sol003AdapterServiceProvider sol003AdapterServiceProvider,
45             final DatabaseServiceProvider databaseServiceProvider) {
46         super(sol003AdapterServiceProvider, databaseServiceProvider);
47     }
48
49     public void getCurrentOperationStatus(final DelegateExecution execution) {
50         try {
51             LOGGER.debug("Executing getCurrentOperationStatus  ...");
52             final CreateVnfResponse vnfInstantiateResponse =
53                     (CreateVnfResponse) execution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME);
54             execution.setVariable(OPERATION_STATUS_PARAM_NAME,
55                     getOperationStatus(execution, vnfInstantiateResponse.getJobId()));
56             LOGGER.debug("Finished executing getCurrentOperationStatus ...");
57         } catch (final Exception exception) {
58             final String message = "Unable to invoke get current Operation status";
59             LOGGER.error(message, exception);
60             abortOperation(execution, message);
61
62         }
63     }
64
65     /**
66      * Log and throw exception on timeout for job status
67      *
68      * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
69      */
70     public void timeOutLogFailue(final DelegateExecution execution) {
71         final String message = "Instantiation operation time out";
72         LOGGER.error(message);
73         abortOperation(execution, message);
74     }
75
76     /**
77      * Check the final status of instantiation throw exception if not completed successfully
78      *
79      * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
80      */
81     public void checkIfOperationWasSuccessful(final DelegateExecution execution) {
82         LOGGER.debug("Executing checkIfOperationWasSuccessful  ...");
83         final OperationStateEnum operationStatus =
84                 (OperationStateEnum) execution.getVariable(OPERATION_STATUS_PARAM_NAME);
85         final CreateVnfResponse vnfInstantiateResponse =
86                 (CreateVnfResponse) execution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME);
87
88         if (operationStatus == null) {
89             final String message = "Unable to instantiate jobId: "
90                     + (vnfInstantiateResponse != null ? vnfInstantiateResponse.getJobId() : "null")
91                     + "Unable to retrieve OperationStatus";
92             LOGGER.error(message);
93             abortOperation(execution, message);
94         }
95         if (operationStatus != OperationStateEnum.COMPLETED) {
96             final String message = "Unable to instantiate jobId: "
97                     + (vnfInstantiateResponse != null ? vnfInstantiateResponse.getJobId() : "null")
98                     + " OperationStatus: " + operationStatus;
99             LOGGER.error(message);
100             abortOperation(execution, message);
101         }
102
103         LOGGER.debug("Successfully completed instatiation of job {}", vnfInstantiateResponse);
104     }
105 }