From fdc8f787e9874f82409cdb2eae0475162d6519aa Mon Sep 17 00:00:00 2001 From: "Plummer, Brittany" Date: Thu, 6 Feb 2020 11:26:19 -0500 Subject: optimize camunda process instance history Set buinessKey to requestId. Added plugin to pass businessKey to subprocesses Updated process-instance and activity-instance lookups to filter response Removed duplicate tests and updated att history lookup Updated businessKey to be set to mso-request-id Updated snapshot version to fix build issues Removed query param from properties. added uribuilder Updated to use uriBuilder.build().toString() Updated unit tests to lookup by procesInstanceId to fix build failure Issue-ID: SO-2650 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I357053c52a75ee5149a56392ce866dbb654b541d --- .../so/apihandlerinfra/CamundaRequestHandler.java | 33 ++++++++++++++++------ .../so/apihandlerinfra/RequestHandlerUtils.java | 11 ++------ 2 files changed, 28 insertions(+), 16 deletions(-) (limited to 'mso-api-handlers/mso-api-handler-infra/src/main/java/org') diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/CamundaRequestHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/CamundaRequestHandler.java index e9f17c42d0..17377d881a 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/CamundaRequestHandler.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/CamundaRequestHandler.java @@ -2,10 +2,10 @@ package org.onap.so.apihandlerinfra; import java.security.GeneralSecurityException; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.ws.rs.core.UriBuilder; import javax.xml.bind.DatatypeConverter; import org.camunda.bpm.engine.impl.persistence.entity.HistoricActivityInstanceEntity; import org.camunda.bpm.engine.impl.persistence.entity.HistoricProcessInstanceEntity; @@ -42,10 +42,29 @@ public class CamundaRequestHandler { @Autowired private Environment env; + private String buildCamundaUrlString(boolean historyLookup, boolean sort, boolean active, String lookupId) { + UriBuilder uriBuilder = UriBuilder.fromUri(env.getProperty("mso.camundaURL")); + if (historyLookup) { + uriBuilder.path(env.getProperty("mso.camunda.rest.history.uri")); + uriBuilder.queryParam("processInstanceBusinessKey", lookupId); + if (active) { + uriBuilder.queryParam("active", true); + } + if (sort) { + uriBuilder.queryParam("sortBy", "startTime"); + uriBuilder.queryParam("sortOrder", "desc"); + } + } else { + uriBuilder.path(env.getProperty("mso.camunda.rest.activity.uri")); + uriBuilder.queryParam("processInstanceId", lookupId); + } + uriBuilder.queryParam("maxResults", 1); + return uriBuilder.build().toString(); + } + public ResponseEntity> getCamundaProcessInstanceHistory(String requestId, - boolean retry) { - String path = env.getProperty("mso.camunda.rest.history.uri") + requestId; - String targetUrl = env.getProperty("mso.camundaURL") + path; + boolean retry, boolean activeOnly, boolean sort) { + String targetUrl = buildCamundaUrlString(true, sort, activeOnly, requestId); HttpHeaders headers = setCamundaHeaders(env.getRequiredProperty("mso.camundaAuth"), env.getRequiredProperty("mso.msoKey")); @@ -77,8 +96,7 @@ public class CamundaRequestHandler { protected ResponseEntity> getCamundaActivityHistory(String processInstanceId) { RestTemplate restTemplate = getRestTemplate(false); - String path = env.getProperty("mso.camunda.rest.activity.uri") + processInstanceId; - String targetUrl = env.getProperty("mso.camundaURL") + path; + String targetUrl = buildCamundaUrlString(false, false, false, processInstanceId); HttpHeaders headers = setCamundaHeaders(env.getRequiredProperty("mso.camundaAuth"), env.getRequiredProperty("mso.msoKey")); HttpEntity requestEntity = new HttpEntity<>(headers); @@ -92,7 +110,7 @@ public class CamundaRequestHandler { String taskInformation = null; try { - response = getCamundaProcessInstanceHistory(requestId, false); + response = getCamundaProcessInstanceHistory(requestId, false, false, true); } catch (RestClientException e) { logger.warn("Error querying Camunda for process-instance history for requestId: {}, exception: {}", requestId, e.getMessage()); @@ -112,7 +130,6 @@ public class CamundaRequestHandler { String taskInformation = null; if (historicProcessInstanceList != null && !historicProcessInstanceList.isEmpty()) { - Collections.reverse(historicProcessInstanceList); processInstanceId = historicProcessInstanceList.get(0).getId(); } else { logger.warn("No processInstances returned for requestId: {} to get TaskInformation", requestId); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java index 0c6ad0ba22..75b7e74d49 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java @@ -356,7 +356,7 @@ public class RequestHandlerUtils extends AbstractRestHandler { String requestId = duplicateRecord.getRequestId(); ResponseEntity> response = null; try { - response = camundaRequestHandler.getCamundaProcessInstanceHistory(requestId, true); + response = camundaRequestHandler.getCamundaProcessInstanceHistory(requestId, true, true, false); } catch (RestClientException e) { logger.error("Error querying Camunda for process-instance history for requestId: {}, exception: {}", requestId, e.getMessage()); @@ -370,13 +370,8 @@ public class RequestHandlerUtils extends AbstractRestHandler { if (response.getBody().isEmpty()) { updateStatus(duplicateRecord, Status.COMPLETE, "Request Completed"); - } - for (HistoricProcessInstance instance : response.getBody()) { - if (("ACTIVE").equals(instance.getState())) { - return true; - } else { - updateStatus(duplicateRecord, Status.COMPLETE, "Request Completed"); - } + } else { + return true; } return false; } -- cgit 1.2.3-korg