From fd1e1a795f881d60f10ba196697af04c7fa00f3c Mon Sep 17 00:00:00 2001 From: sarada prasad sahoo Date: Mon, 22 Jul 2019 16:55:12 +0530 Subject: Enhanced List Level flow with backward support Modified the e2e service instance flow to support both new list types groups along with backward compatibility to support old types alloted resources, network etc. Change-Id: I1cb128e259c54b80009840914b2c1cee8cf8a4df Issue-ID: SO-1393 Signed-off-by: sarada prasad sahoo --- .../workflow/service/WorkflowAsyncResource.java | 32 +++++++++++++++++++--- .../common/workflow/service/WorkflowResource.java | 2 +- 2 files changed, 29 insertions(+), 5 deletions(-) (limited to 'bpmn/mso-infrastructure-bpmn/src/main/java/org/onap') diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResource.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResource.java index e8e4b85cae..ace6e1937d 100644 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResource.java +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResource.java @@ -101,7 +101,7 @@ public class WorkflowAsyncResource extends ProcessEngineAwareService { try { MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, getRequestId(inputVariables)); processor.startProcess(processKey, variableMap); - WorkflowResponse response = waitForResponse(getRequestId(inputVariables)); + WorkflowResponse response = waitForResponse(inputVariables); return Response.status(202).entity(response).build(); } catch (WorkflowProcessorException e) { WorkflowResponse response = e.getWorkflowResponse(); @@ -112,9 +112,12 @@ public class WorkflowAsyncResource extends ProcessEngineAwareService { } } - private WorkflowResponse waitForResponse(String requestId) throws Exception { + private WorkflowResponse waitForResponse(Map inputVariables) throws Exception { + String requestId = getRequestId(inputVariables); long currentWaitTime = 0; - while (DEFAULT_WAIT_TIME > currentWaitTime) { + long waitTime = getWaitTime(inputVariables); + logger.debug("WorkflowAsyncResource.waitForResponse using timeout: " + waitTime); + while (waitTime > currentWaitTime) { Thread.sleep(workflowPollInterval); currentWaitTime = currentWaitTime + workflowPollInterval; WorkflowContext foundContext = contextHolder.getWorkflowContext(requestId); @@ -123,7 +126,7 @@ public class WorkflowAsyncResource extends ProcessEngineAwareService { return buildResponse(foundContext); } } - throw new Exception("TimeOutOccured"); + throw new Exception("TimeOutOccured in WorkflowAsyncResource.waitForResponse for time " + waitTime + "ms"); } private WorkflowResponse buildUnkownError(String requestId, String error) { @@ -171,4 +174,25 @@ public class WorkflowAsyncResource extends ProcessEngineAwareService { return inputVariables; } + /** + * Returns the wait time, this is used by the resource on how long it should wait to send a response If none + * specified DEFAULT_WAIT_TIME is used + * + * @param inputVariables + * @return + */ + private long getWaitTime(Map inputVariables) { + String timeout = inputVariables.get("mso-service-request-timeout") == null ? null + : inputVariables.get("mso-service-request-timeout").toString(); + + if (timeout != null) { + try { + return Long.parseLong(timeout) * 1000; + } catch (NumberFormatException nex) { + logger.debug("Invalid input for mso-service-request-timeout"); + } + } + return DEFAULT_WAIT_TIME; + } + } diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowResource.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowResource.java index 20f3eb4fee..bcc3739c32 100644 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowResource.java +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowResource.java @@ -116,7 +116,7 @@ public class WorkflowResource extends ProcessEngineAwareService { long timeToWaitAfterProcessEnded = uriInfo == null ? 5000 : 60000; AtomicLong timeProcessEnded = new AtomicLong(0); boolean endedWithNoResponse = false; - + logger.debug(LOGMARKER + "WorkflowResource.startProcessInstanceByKey using timeout: " + waitTime); while (now <= endTime) { Thread.sleep(pollingInterval); -- cgit 1.2.3-korg