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.
13 package org.onap.nbi.apis.serviceorder.workflow;
15 import org.onap.nbi.apis.serviceorder.SoClient;
16 import org.onap.nbi.apis.serviceorder.model.ActionType;
17 import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
18 import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
19 import org.onap.nbi.apis.serviceorder.model.StateType;
20 import org.onap.nbi.apis.serviceorder.model.consumer.GetE2ERequestStatusResponse;
21 import org.onap.nbi.apis.serviceorder.model.consumer.GetRequestStatusResponse;
22 import org.onap.nbi.apis.serviceorder.model.consumer.RequestState;
23 import org.onap.nbi.apis.serviceorder.service.ServiceOrderService;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.stereotype.Service;
30 public class SOGetStatusManager {
32 private static final Logger LOGGER = LoggerFactory.getLogger(SOGetStatusManager.class);
35 private ServiceOrderService serviceOrderService;
38 private SoClient soClient;
42 public void pollRequestStatus(ServiceOrder serviceOrder, ServiceOrderItem serviceOrderItem, boolean e2eService)
43 throws InterruptedException {
45 pollE2ESoRequestStatus(serviceOrder, serviceOrderItem);
47 pollSoRequestStatus(serviceOrder, serviceOrderItem);
55 private void pollSoRequestStatus(ServiceOrder serviceOrder,
56 ServiceOrderItem orderItem) throws InterruptedException {
57 boolean stopPolling = false;
58 String requestId = orderItem.getRequestId();
59 GetRequestStatusResponse response = null;
62 while (!stopPolling) {
63 response = soClient.callGetRequestStatus(requestId);
64 if (response != null) {
65 if (response.getRequest().getRequestStatus().getPercentProgress() != 100) {
68 LOGGER.debug("orderitem id {} still in progress from so", orderItem.getId());
69 } else if (RequestState.COMPLETE != response.getRequest().getRequestStatus().getRequestState()) {
70 serviceOrderService.updateOrderItemState(serviceOrder, orderItem, StateType.FAILED);
72 LOGGER.debug("orderitem id {} failed, response from request status {}", orderItem.getId(),
73 response.getRequest().getRequestStatus().getRequestState());
75 updateOrderItemIfStatusCompleted(serviceOrder, orderItem);
77 LOGGER.debug("orderitem id {} completed");
81 LOGGER.debug("orderitem id {} still in progress from so", orderItem.getId());
85 LOGGER.debug("orderitem id {} stop polling from getrequeststatus, 3 retries done", orderItem.getId());
91 private void updateOrderItemIfStatusCompleted(ServiceOrder serviceOrder, ServiceOrderItem orderItem) {
92 if(orderItem.getAction()!= ActionType.MODIFY){
93 serviceOrderService.updateOrderItemState(serviceOrder, orderItem, StateType.COMPLETED);
95 if(StateType.INPROGRESS_MODIFY_REQUEST_CREATE_SEND ==orderItem.getState()){
96 serviceOrderService.updateOrderItemState(serviceOrder, orderItem, StateType.COMPLETED);
98 serviceOrderService.updateOrderItemState(serviceOrder,orderItem,StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE);
103 private void pollE2ESoRequestStatus(ServiceOrder serviceOrder, ServiceOrderItem orderItem)
104 throws InterruptedException {
105 boolean stopPolling = false;
106 String operationId = orderItem.getRequestId();
107 String serviceId = orderItem.getService().getId();
109 GetE2ERequestStatusResponse response = null;
110 final String ERROR = "error";
111 final String FINISHED = "finished";
112 final String PROCESSING = "processing";
113 String result = null;
114 while (!stopPolling) {
115 response = soClient.callE2EGetRequestStatus(operationId, serviceId);
116 if (response != null) {
117 result = response.getOperation().getResult();
118 if (PROCESSING.equals(result)) {
121 LOGGER.debug("orderitem id {} still in progress from so", orderItem.getId());
122 } else if (ERROR.equals(result)) {
123 serviceOrderService.updateOrderItemState(serviceOrder, orderItem, StateType.FAILED);
125 LOGGER.debug("orderitem id {} failed, response from request status {}", orderItem.getId(),
126 response.getOperation().getResult());
127 } else if (FINISHED.equals(result)) {
128 updateOrderItemIfStatusCompleted(serviceOrder, orderItem);
130 LOGGER.debug("orderitem id {} completed");
134 LOGGER.debug("orderitem id {} still in progress from so", orderItem.getId());
136 if (nbRetries == 3) {
138 LOGGER.debug("orderitem id {} stop polling from getrequeststatus, 3 retries done", orderItem.getId());