2 * Copyright (c) 2018 Orange
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5 * the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 * specific language governing permissions and limitations under the License.
14 package org.onap.nbi.apis.serviceorder.workflow;
16 import org.onap.nbi.apis.serviceorder.SoClient;
17 import org.onap.nbi.apis.serviceorder.model.ActionType;
18 import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
19 import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
20 import org.onap.nbi.apis.serviceorder.model.StateType;
21 import org.onap.nbi.apis.serviceorder.model.consumer.GetE2ERequestStatusResponse;
22 import org.onap.nbi.apis.serviceorder.model.consumer.GetRequestStatusResponse;
23 import org.onap.nbi.apis.serviceorder.model.consumer.RequestState;
24 import org.onap.nbi.apis.serviceorder.service.ServiceOrderService;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.stereotype.Service;
31 public class SOGetStatusManager {
33 private static final Logger LOGGER = LoggerFactory.getLogger(SOGetStatusManager.class);
36 private ServiceOrderService serviceOrderService;
39 private SoClient soClient;
41 public void pollRequestStatus(ServiceOrder serviceOrder, ServiceOrderItem serviceOrderItem, boolean e2eService) {
43 pollE2ESoRequestStatus(serviceOrder, serviceOrderItem);
45 pollSoRequestStatus(serviceOrder, serviceOrderItem);
53 private void pollSoRequestStatus(ServiceOrder serviceOrder, ServiceOrderItem orderItem) {
54 String requestId = orderItem.getRequestId();
55 GetRequestStatusResponse response = null;
57 response = soClient.callGetRequestStatus(requestId);
58 if (response != null) {
59 orderItem.setPercentProgress(String.valueOf(response.getRequest().getRequestStatus().getPercentProgress()));
60 if (response.getRequest().getRequestStatus().getPercentProgress() != 100) {
61 LOGGER.debug("orderitem id {} still in progress from so", orderItem.getId());
62 } else if (RequestState.COMPLETE != response.getRequest().getRequestStatus().getRequestState()) {
63 serviceOrderService.updateOrderItemState(serviceOrder, orderItem, StateType.FAILED);
64 LOGGER.debug("orderitem id {} failed, response from request status {}", orderItem.getId(),
65 response.getRequest().getRequestStatus().getRequestState());
67 updateOrderItemIfStatusCompleted(serviceOrder, orderItem);
68 LOGGER.debug("orderitem id {} completed");
71 LOGGER.debug("orderitem id {} still in progress from so", orderItem.getId());
76 private void updateOrderItemIfStatusCompleted(ServiceOrder serviceOrder, ServiceOrderItem orderItem) {
77 if (orderItem.getAction() != ActionType.MODIFY) {
78 serviceOrderService.updateOrderItemState(serviceOrder, orderItem, StateType.COMPLETED);
80 if (StateType.INPROGRESS_MODIFY_REQUEST_CREATE_SEND == orderItem.getState()) {
81 serviceOrderService.updateOrderItemState(serviceOrder, orderItem, StateType.COMPLETED);
83 serviceOrderService.updateOrderItemState(serviceOrder, orderItem,
84 StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE);
89 private void pollE2ESoRequestStatus(ServiceOrder serviceOrder, ServiceOrderItem orderItem) {
90 String operationId = orderItem.getRequestId();
91 String serviceId = orderItem.getService().getId();
92 GetE2ERequestStatusResponse response = null;
93 final String ERROR = "error";
94 final String FINISHED = "finished";
95 final String PROCESSING = "processing";
97 response = soClient.callE2EGetRequestStatus(operationId, serviceId);
98 if (response != null) {
99 orderItem.setPercentProgress(response.getOperation().getProgress());
100 result = response.getOperation().getResult();
101 if (PROCESSING.equals(result)) {
102 LOGGER.debug("orderitem id {} still in progress from so", orderItem.getId());
103 } else if (ERROR.equals(result)) {
104 serviceOrderService.updateOrderItemState(serviceOrder, orderItem, StateType.FAILED);
105 LOGGER.debug("orderitem id {} failed, response from request status {}", orderItem.getId(),
106 response.getOperation().getResult());
107 } else if (FINISHED.equals(result)) {
108 updateOrderItemIfStatusCompleted(serviceOrder, orderItem);
109 LOGGER.debug("orderitem id {} completed");
112 LOGGER.debug("orderitem id {} still in progress from so", orderItem.getId());