59ff71ab0c4f20ea8762b6392fe25d552947371e
[so.git] /
1 /*-
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
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.bpmn.infrastructure.adapter.vnfm.tasks;
21
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.bpmn.common.BuildingBlockExecution;
25 import org.onap.so.client.exception.ExceptionBuilder;
26 import org.onap.vnfmadapter.v1.model.CreateVnfResponse;
27 import org.onap.vnfmadapter.v1.model.OperationStateEnum;
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;
33
34
35 /**
36  * @author waqas.ikram@est.tech
37  *
38  */
39 @Component
40 public class MonitorVnfmCreateJobTask extends MonitorVnfmJobTask{
41
42   private static final Logger LOGGER = LoggerFactory.getLogger(MonitorVnfmCreateJobTask.class);
43
44   @Autowired
45   public MonitorVnfmCreateJobTask(final VnfmAdapterServiceProvider vnfmAdapterServiceProvider,
46       final ExceptionBuilder exceptionUtil) {
47     super(vnfmAdapterServiceProvider, exceptionUtil);
48   }
49
50   /**
51    * Get the current operation status of instantiation job
52    * 
53    * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
54    */
55   public void getCurrentOperationStatus(final BuildingBlockExecution execution) {
56     LOGGER.debug("Executing getCurrentOperationStatus  ...");
57     final CreateVnfResponse vnfInstantiateResponse = execution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME);
58     execution.setVariable(OPERATION_STATUS_PARAM_NAME, getOperationStatus(execution, vnfInstantiateResponse.getJobId()));
59     LOGGER.debug("Finished executing getCurrentOperationStatus ...");
60   }
61
62   /**
63    * Log and throw exception on timeout for job status
64    * 
65    * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
66    */
67   public void timeOutLogFailue(final BuildingBlockExecution execution) {
68     final String message = "Instantiation operation time out";
69     LOGGER.error(message);
70     exceptionUtil.buildAndThrowWorkflowException(execution, 1205, message);
71   }
72
73   /**
74    * Check the final status of instantiation throw exception if not completed successfully
75    * 
76    * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl}
77    */
78   public void checkIfOperationWasSuccessful(final BuildingBlockExecution execution) {
79     LOGGER.debug("Executing checkIfOperationWasSuccessful  ...");
80     final Optional<OperationStateEnum> operationStatusOption = execution.getVariable(OPERATION_STATUS_PARAM_NAME);
81     final CreateVnfResponse vnfInstantiateResponse = execution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME);
82     if (operationStatusOption == null || !operationStatusOption.isPresent()) {
83       final String message = "Unable to instantiate jobId: "
84           + (vnfInstantiateResponse != null ? vnfInstantiateResponse.getJobId() : "null")
85           + "Unable to retrieve OperationStatus";
86       LOGGER.error(message);
87       exceptionUtil.buildAndThrowWorkflowException(execution, 1206, message);
88     }
89     if (operationStatusOption.isPresent()) {
90       final OperationStateEnum operationStatus = operationStatusOption.get();
91       if (operationStatus != OperationStateEnum.COMPLETED) {
92         final String message = "Unable to instantiate jobId: "
93             + (vnfInstantiateResponse != null ? vnfInstantiateResponse.getJobId() : "null") + " OperationStatus: "
94             + operationStatus;
95         LOGGER.error(message);
96         exceptionUtil.buildAndThrowWorkflowException(execution, 1207, message);
97       }
98       LOGGER.debug("Successfully completed instatiation of job {}", vnfInstantiateResponse);
99     }
100   }
101 }