From d9b623bfb74762a99976fe9f882719241de7c41b Mon Sep 17 00:00:00 2001 From: Shailesh Jagannath Padave Date: Mon, 18 Nov 2024 22:48:57 +0530 Subject: [PATCH] Added endpoint --- .../service/WorkflowBulkService.java | 10 ++++ .../service/WorkflowBulkServiceImpl.java | 53 ++++++++++++++----- .../controllers/WorkflowBulkResource.java | 15 ++++++ 3 files changed, 66 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/com/netflix/conductor/service/WorkflowBulkService.java b/core/src/main/java/com/netflix/conductor/service/WorkflowBulkService.java index 8ea185be7..3be0ffe89 100644 --- a/core/src/main/java/com/netflix/conductor/service/WorkflowBulkService.java +++ b/core/src/main/java/com/netflix/conductor/service/WorkflowBulkService.java @@ -14,6 +14,7 @@ import java.util.List; +import com.netflix.conductor.model.WorkflowModel; import org.springframework.validation.annotation.Validated; import com.netflix.conductor.common.model.BulkResponse; @@ -86,4 +87,13 @@ BulkResponse terminateRemove( List workflowIds, String reason, boolean archiveWorkflow); + + BulkResponse searchWorkflow( + @NotEmpty(message = "WorkflowIds list cannot be null.") + @Size( + max = MAX_REQUEST_ITEMS, + message = + "Cannot process more than {max} workflows. Please use multiple requests.") + List workflowIds, + boolean includeTasks); } diff --git a/core/src/main/java/com/netflix/conductor/service/WorkflowBulkServiceImpl.java b/core/src/main/java/com/netflix/conductor/service/WorkflowBulkServiceImpl.java index 30e52e3b1..715c77b4c 100644 --- a/core/src/main/java/com/netflix/conductor/service/WorkflowBulkServiceImpl.java +++ b/core/src/main/java/com/netflix/conductor/service/WorkflowBulkServiceImpl.java @@ -14,6 +14,7 @@ import java.util.List; +import com.netflix.conductor.model.WorkflowModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -43,7 +44,7 @@ public WorkflowBulkServiceImpl( * * @param workflowIds - list of workflow Ids to perform pause operation on * @return bulk response object containing a list of succeeded workflows and a list of failed - * ones with errors + * ones with errors */ public BulkResponse pauseWorkflow(List workflowIds) { @@ -70,7 +71,7 @@ public BulkResponse pauseWorkflow(List workflowIds) { * * @param workflowIds - list of workflow Ids to perform resume operation on * @return bulk response object containing a list of succeeded workflows and a list of failed - * ones with errors + * ones with errors */ public BulkResponse resumeWorkflow(List workflowIds) { BulkResponse bulkResponse = new BulkResponse<>(); @@ -93,10 +94,10 @@ public BulkResponse resumeWorkflow(List workflowIds) { /** * Restart the list of workflows. * - * @param workflowIds - list of workflow Ids to perform restart operation on + * @param workflowIds - list of workflow Ids to perform restart operation on * @param useLatestDefinitions if true, use latest workflow and task definitions upon restart * @return bulk response object containing a list of succeeded workflows and a list of failed - * ones with errors + * ones with errors */ public BulkResponse restart(List workflowIds, boolean useLatestDefinitions) { BulkResponse bulkResponse = new BulkResponse<>(); @@ -121,7 +122,7 @@ public BulkResponse restart(List workflowIds, boolean useLatestD * * @param workflowIds - list of workflow Ids to perform retry operation on * @return bulk response object containing a list of succeeded workflows and a list of failed - * ones with errors + * ones with errors */ public BulkResponse retry(List workflowIds) { BulkResponse bulkResponse = new BulkResponse<>(); @@ -145,10 +146,10 @@ public BulkResponse retry(List workflowIds) { * Terminate workflows execution. * * @param workflowIds - list of workflow Ids to perform terminate operation on - * @param reason - description to be specified for the terminated workflow for future - * references. + * @param reason - description to be specified for the terminated workflow for future + * references. * @return bulk response object containing a list of succeeded workflows and a list of failed - * ones with errors + * ones with errors */ public BulkResponse terminate(List workflowIds, String reason) { BulkResponse bulkResponse = new BulkResponse<>(); @@ -171,7 +172,7 @@ public BulkResponse terminate(List workflowIds, String reason) { /** * Removes a list of workflows from the system. * - * @param workflowIds List of WorkflowIDs of the workflows you want to remove from system. + * @param workflowIds List of WorkflowIDs of the workflows you want to remove from system. * @param archiveWorkflow Archives the workflow and associated tasks instead of removing them. */ public BulkResponse deleteWorkflow(List workflowIds, boolean archiveWorkflow) { @@ -197,11 +198,11 @@ public BulkResponse deleteWorkflow(List workflowIds, boolean arc /** * Terminates execution for workflows in a list, then removes each workflow. * - * @param workflowIds List of workflow IDs to terminate and delete. - * @param reason Reason for terminating the workflow. + * @param workflowIds List of workflow IDs to terminate and delete. + * @param reason Reason for terminating the workflow. * @param archiveWorkflow Archives the workflow and associated tasks instead of removing them. * @return bulk response object containing a list of succeeded workflows and a list of failed - * ones with errors + * ones with errors */ public BulkResponse terminateRemove( List workflowIds, String reason, boolean archiveWorkflow) { @@ -233,4 +234,32 @@ public BulkResponse terminateRemove( } return bulkResponse; } + + /** + * Fetch workflow details for given workflowIds. + * + * @param workflowIds List of workflow IDs to terminate and delete. + * @param includeTasks includes tasks from workflow + * @return bulk response object containing a list of workflow details + */ + @Override + public BulkResponse searchWorkflow(List workflowIds, boolean includeTasks) { + BulkResponse bulkResponse = new BulkResponse<>(); + for (String workflowId : workflowIds) { + try { + WorkflowModel workflowModel = workflowExecutor.getWorkflow(workflowId, includeTasks); + bulkResponse.appendSuccessResponse(workflowModel); + } catch (Exception e) { + LOGGER.error( + "bulk search exception, workflowId {}, message: {} ", + workflowId, + e.getMessage(), + e); + bulkResponse.appendFailedResponse(workflowId, e.getMessage()); + } + } + return bulkResponse; + } + + } diff --git a/rest/src/main/java/com/netflix/conductor/rest/controllers/WorkflowBulkResource.java b/rest/src/main/java/com/netflix/conductor/rest/controllers/WorkflowBulkResource.java index b9f36679d..9a7da24e5 100644 --- a/rest/src/main/java/com/netflix/conductor/rest/controllers/WorkflowBulkResource.java +++ b/rest/src/main/java/com/netflix/conductor/rest/controllers/WorkflowBulkResource.java @@ -14,6 +14,7 @@ import java.util.List; +import com.netflix.conductor.model.WorkflowModel; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -141,4 +142,18 @@ public BulkResponse terminateRemove( @RequestParam(value = "reason", required = false) String reason) { return workflowBulkService.terminateRemove(workflowIds, reason, archiveWorkflow); } + + /** + * Search workflows for given list of workflows. + * + * @param workflowIds - list of workflow Ids to be searched + * @return bulk response object containing a list of workflows + */ + @PostMapping("/search") + public BulkResponse searchWorkflow( + @RequestBody List workflowIds, + @RequestParam(value = "includeTasks", defaultValue = "true", required = false) + boolean includeTasks) { + return workflowBulkService.searchWorkflow(workflowIds, includeTasks); + } }