diff options
Diffstat (limited to 'src/main')
6 files changed, 99 insertions, 95 deletions
diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/orchestrator/ExecutionTask.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/orchestrator/ExecutionTask.java index 9fd0505..1580cba 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/model/orchestrator/ExecutionTask.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/orchestrator/ExecutionTask.java @@ -32,7 +32,7 @@ public class ExecutionTask { private String reliedTasks; - private int nbRetries; + private Date createDate; private Date lastAttemptDate; @@ -71,14 +71,6 @@ public class ExecutionTask { this.reliedTasks = reliedTasks; } - public int getNbRetries() { - return nbRetries; - } - - public void setNbRetries(int nbRetries) { - this.nbRetries = nbRetries; - } - public Long getInternalId() { return internalId; } @@ -87,6 +79,13 @@ public class ExecutionTask { this.internalId = internalId; } + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } @Override public boolean equals(Object o) { @@ -97,14 +96,28 @@ public class ExecutionTask { return false; } ExecutionTask that = (ExecutionTask) o; - return nbRetries == that.nbRetries && Objects.equals(internalId, that.internalId) - && Objects.equals(orderItemId, that.orderItemId) && Objects.equals(reliedTasks, that.reliedTasks) - && Objects.equals(lastAttemptDate, that.lastAttemptDate) - && Objects.equals(serviceOrderInfoJson, that.serviceOrderInfoJson); + return Objects.equals(internalId, that.internalId) && + Objects.equals(orderItemId, that.orderItemId) && + Objects.equals(reliedTasks, that.reliedTasks) && + Objects.equals(createDate, that.createDate) && + Objects.equals(lastAttemptDate, that.lastAttemptDate) && + Objects.equals(serviceOrderInfoJson, that.serviceOrderInfoJson); } @Override public int hashCode() { - return Objects.hash(internalId, orderItemId, reliedTasks, nbRetries, lastAttemptDate, serviceOrderInfoJson); + return Objects.hash(internalId, orderItemId, reliedTasks, createDate, lastAttemptDate, serviceOrderInfoJson); + } + + @Override + public String toString() { + return "ExecutionTask{" + + "internalId=" + internalId + + ", orderItemId='" + orderItemId + '\'' + + ", reliedTasks='" + reliedTasks + '\'' + + ", createDate=" + createDate + + ", lastAttemptDate=" + lastAttemptDate + + ", serviceOrderInfoJson='" + serviceOrderInfoJson + '\'' + + '}'; } } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/service/ServiceOrderService.java b/src/main/java/org/onap/nbi/apis/serviceorder/service/ServiceOrderService.java index c6544af..47262e2 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/service/ServiceOrderService.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/service/ServiceOrderService.java @@ -33,6 +33,8 @@ public class ServiceOrderService { @Autowired ServiceOrderRepository serviceOrderRepository; + private static final String SERVICE_ID = "service.id"; + public ServiceOrder findServiceOrderById(String serviceOrderId){ return serviceOrderRepository.findOne(serviceOrderId); } @@ -111,7 +113,7 @@ public class ServiceOrderService { orderMessage.setCorrectionRequired(true); if ("101".equalsIgnoreCase(code)) { - orderMessage.setField("service.id"); + orderMessage.setField(SERVICE_ID); orderMessage.setMessageInformation("Missing Information - orderItem.service.id must be provided"); serviceOrderItem.addOrderItemMessageItem(orderMessage); } @@ -122,7 +124,7 @@ public class ServiceOrderService { serviceOrderItem.addOrderItemMessageItem(orderMessage); } if ("103".equalsIgnoreCase(code)) { - orderMessage.setField("service.id"); + orderMessage.setField(SERVICE_ID); orderMessage.setMessageInformation( "Inconsistence information provided. service.id must not be provided for add action"); serviceOrderItem.addOrderItemMessageItem(orderMessage); @@ -133,10 +135,14 @@ public class ServiceOrderService { serviceOrderItem.addOrderItemMessageItem(orderMessage); } if ("106".equalsIgnoreCase(code)) { - orderMessage.setField("service.id"); + orderMessage.setField(SERVICE_ID); orderMessage.setMessageInformation("Incorrect service.id provided – not found in Inventory (AAI)"); serviceOrderItem.addOrderItemMessageItem(orderMessage); } + if ("504".equalsIgnoreCase(code)) { + orderMessage.setMessageInformation("Service Orchestrator Service Instantiation timed out"); + serviceOrderItem.addOrderItemMessageItem(orderMessage); + } serviceOrderRepository.save(serviceOrder); } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOGetStatusManager.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOGetStatusManager.java index da3029d..df233d5 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOGetStatusManager.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOGetStatusManager.java @@ -39,8 +39,7 @@ public class SOGetStatusManager { - public void pollRequestStatus(ServiceOrder serviceOrder, ServiceOrderItem serviceOrderItem, boolean e2eService) - throws InterruptedException { + public void pollRequestStatus(ServiceOrder serviceOrder, ServiceOrderItem serviceOrderItem, boolean e2eService) { if (e2eService) { pollE2ESoRequestStatus(serviceOrder, serviceOrderItem); } else { @@ -53,40 +52,27 @@ public class SOGetStatusManager { * * @param orderItem */ private void pollSoRequestStatus(ServiceOrder serviceOrder, - ServiceOrderItem orderItem) throws InterruptedException { - boolean stopPolling = false; + ServiceOrderItem orderItem) { String requestId = orderItem.getRequestId(); GetRequestStatusResponse response = null; - int nbRetries = 0; - while (!stopPolling) { - response = soClient.callGetRequestStatus(requestId); - if (response != null) { - orderItem.setPercentProgress(String.valueOf(response.getRequest().getRequestStatus().getPercentProgress())); - if (response.getRequest().getRequestStatus().getPercentProgress() != 100) { - nbRetries++; - Thread.sleep(1000); - LOGGER.debug("orderitem id {} still in progress from so", orderItem.getId()); - } else if (RequestState.COMPLETE != response.getRequest().getRequestStatus().getRequestState()) { - serviceOrderService.updateOrderItemState(serviceOrder, orderItem, StateType.FAILED); - stopPolling = true; - LOGGER.debug("orderitem id {} failed, response from request status {}", orderItem.getId(), - response.getRequest().getRequestStatus().getRequestState()); - } else { - updateOrderItemIfStatusCompleted(serviceOrder, orderItem); - stopPolling = true; - LOGGER.debug("orderitem id {} completed"); - } - } else { - stopPolling = true; + response = soClient.callGetRequestStatus(requestId); + if (response != null) { + orderItem.setPercentProgress(String.valueOf(response.getRequest().getRequestStatus().getPercentProgress())); + if (response.getRequest().getRequestStatus().getPercentProgress() != 100) { LOGGER.debug("orderitem id {} still in progress from so", orderItem.getId()); + } else if (RequestState.COMPLETE != response.getRequest().getRequestStatus().getRequestState()) { + serviceOrderService.updateOrderItemState(serviceOrder, orderItem, StateType.FAILED); + LOGGER.debug("orderitem id {} failed, response from request status {}", orderItem.getId(), + response.getRequest().getRequestStatus().getRequestState()); + } else { + updateOrderItemIfStatusCompleted(serviceOrder, orderItem); + LOGGER.debug("orderitem id {} completed"); } - if (nbRetries == 3) { - stopPolling = true; - LOGGER.debug("orderitem id {} stop polling from getrequeststatus, 3 retries done", orderItem.getId()); - - } + } else { + LOGGER.debug("orderitem id {} still in progress from so", orderItem.getId()); } + } private void updateOrderItemIfStatusCompleted(ServiceOrder serviceOrder, ServiceOrderItem orderItem) { @@ -101,48 +87,31 @@ public class SOGetStatusManager { } } - private void pollE2ESoRequestStatus(ServiceOrder serviceOrder, ServiceOrderItem orderItem) - throws InterruptedException { - boolean stopPolling = false; + private void pollE2ESoRequestStatus(ServiceOrder serviceOrder, ServiceOrderItem orderItem) { String operationId = orderItem.getRequestId(); String serviceId = orderItem.getService().getId(); - int nbRetries = 0; GetE2ERequestStatusResponse response = null; final String ERROR = "error"; final String FINISHED = "finished"; final String PROCESSING = "processing"; String result = null; - while (!stopPolling) { - response = soClient.callE2EGetRequestStatus(operationId, serviceId); - if (response != null) { - orderItem.setPercentProgress(response.getOperation().getProgress()); - result = response.getOperation().getResult(); - if (PROCESSING.equals(result)) { - nbRetries++; - Thread.sleep(1000); - LOGGER.debug("orderitem id {} still in progress from so", orderItem.getId()); - } else if (ERROR.equals(result)) { - serviceOrderService.updateOrderItemState(serviceOrder, orderItem, StateType.FAILED); - stopPolling = true; - LOGGER.debug("orderitem id {} failed, response from request status {}", orderItem.getId(), - response.getOperation().getResult()); - } else if (FINISHED.equals(result)) { - updateOrderItemIfStatusCompleted(serviceOrder, orderItem); - stopPolling = true; - LOGGER.debug("orderitem id {} completed"); - } - } else { - stopPolling = true; + response = soClient.callE2EGetRequestStatus(operationId, serviceId); + if (response != null) { + orderItem.setPercentProgress(response.getOperation().getProgress()); + result = response.getOperation().getResult(); + if (PROCESSING.equals(result)) { LOGGER.debug("orderitem id {} still in progress from so", orderItem.getId()); + } else if (ERROR.equals(result)) { + serviceOrderService.updateOrderItemState(serviceOrder, orderItem, StateType.FAILED); + LOGGER.debug("orderitem id {} failed, response from request status {}", orderItem.getId(), + response.getOperation().getResult()); + } else if (FINISHED.equals(result)) { + updateOrderItemIfStatusCompleted(serviceOrder, orderItem); + LOGGER.debug("orderitem id {} completed"); } - if (nbRetries == 3) { - stopPolling = true; - LOGGER.debug("orderitem id {} stop polling from getrequeststatus, 3 retries done", orderItem.getId()); - - } + } else { + LOGGER.debug("orderitem id {} still in progress from so", orderItem.getId()); } } - - } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskManager.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskManager.java index fa1d5a2..eb95792 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskManager.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskManager.java @@ -13,6 +13,7 @@ package org.onap.nbi.apis.serviceorder.workflow; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -56,7 +57,7 @@ public class SOTaskManager { for (ServiceOrderItem orderItem : orderItems) { ExecutionTask task = new ExecutionTask(); task.setOrderItemId(orderItem.getId()); - task.setNbRetries(3); + task.setCreateDate(new Date()); StringBuilder sb = new StringBuilder(); for (OrderItemRelationship orderItemRelationship : orderItem.getOrderItemRelationship()) { sb.append(orderItemRelationship.getId()).append(" "); diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java index ea0e91f..b153ff1 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java @@ -33,6 +33,7 @@ import org.onap.nbi.exceptions.TechnicalException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @@ -54,12 +55,18 @@ public class SOTaskProcessor { @Autowired private SOGetStatusManager sOGetStatusManager; + @Value("${scheduler.pollingDurationInMins}") + private float pollingDurationInMins; + private static final Logger LOGGER = LoggerFactory.getLogger(SOTaskProcessor.class); /** * Run the ServiceOrchestrator processing for a serviceOrderItem which with any sub relations */ - public void processOrderItem(ExecutionTask executionTask) throws InterruptedException { + public void processOrderItem(ExecutionTask executionTask) { + + executionTask.setLastAttemptDate(new Date()); + executionTaskRepository.save(executionTask); ServiceOrderInfo serviceOrderInfo = getServiceOrderInfo(executionTask); @@ -82,19 +89,18 @@ public class SOTaskProcessor { } } - if (executionTask.getNbRetries() > 0 && StateType.FAILED != serviceOrderItem.getState() - ) { + boolean shouldStopPolling = shouldStopPolling(executionTask); + if (!shouldStopPolling && StateType.FAILED != serviceOrderItem.getState() + ) { // TODO lancer en asynchrone sOGetStatusManager.pollRequestStatus(serviceOrder, serviceOrderItem, e2eService); if (serviceOrderItem.getState().equals(StateType.COMPLETED)) { updateSuccessTask(executionTask); - } else if(shouldDecrementNbRetries(serviceOrderItem)){ - int nbRetries = executionTask.getNbRetries(); - executionTask.setNbRetries(--nbRetries); - executionTask.setLastAttemptDate(new Date()); - executionTaskRepository.save(executionTask); } + } else if (shouldStopPolling && StateType.FAILED != serviceOrderItem.getState()) { + serviceOrderService.addOrderItemMessage(serviceOrder, serviceOrderItem, "504"); + updateFailedTask(executionTask, serviceOrder); } else { updateFailedTask(executionTask, serviceOrder); } @@ -102,11 +108,6 @@ public class SOTaskProcessor { updateServiceOrder(serviceOrder); } - private boolean shouldDecrementNbRetries(ServiceOrderItem serviceOrderItem) { - return ActionType.MODIFY!=serviceOrderItem.getAction() || (StateType.INPROGRESS_MODIFY_REQUEST_CREATE_SEND ==serviceOrderItem.getState() || StateType.INPROGRESS_MODIFY_REQUEST_DELETE_SEND - ==serviceOrderItem.getState()); - } - private boolean shouldPostSo(ServiceOrderItem serviceOrderItem) { return StateType.ACKNOWLEDGED == serviceOrderItem.getState() || StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE == serviceOrderItem.getState(); } @@ -292,7 +293,7 @@ public class SOTaskProcessor { for (ExecutionTask taskToDelete : executionTasksToDelete) { if (taskToDelete.getOrderItemId().equals(item.getId())) { serviceOrderService.updateOrderItemState(serviceOrder, item, StateType.FAILED); - LOGGER.warn("task {} with orderitem id {} to failed cause orderitem id {} failed ", + LOGGER.warn("task {} with orderitem id {} failed cause orderitem id {} failed ", taskToDelete.getInternalId(), taskToDelete.getOrderItemId(), executionTask.getOrderItemId()); } @@ -322,5 +323,16 @@ public class SOTaskProcessor { return executionTasks; } - + private boolean shouldStopPolling(ExecutionTask executionTask) { + long createTimeinMillis = executionTask.getCreateDate().getTime(); + long lastAttemptTimeInMillis = executionTask.getLastAttemptDate().getTime(); + long differenceInMillis = lastAttemptTimeInMillis-createTimeinMillis; + float pollingDurationInMillis = pollingDurationInMins*60000; + LOGGER.debug("Task {} with orderitem id {}: Task create date: {} Task last attempt date: {}", + executionTask.getInternalId(), executionTask.getOrderItemId(), createTimeinMillis, + lastAttemptTimeInMillis); + LOGGER.debug("Difference {} and Polling Duration {}", + differenceInMillis, pollingDurationInMins); + return (differenceInMillis > pollingDurationInMillis); + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 11638c1..347d855 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -30,6 +30,9 @@ onap.cloudOwner=CloudOwner nbi.url=http://localhost:8080/nbi/api/v3 nbi.callForVNF=false +# SCHEDULER +scheduler.pollingDurationInMins=360 + # SDC sdc.host=http://10.0.3.1:8080 sdc.header.ecompInstanceId=demo |