From b321f7698fc2d49906a1da8b53d8fa08535ce1e2 Mon Sep 17 00:00:00 2001 From: saimedhi Date: Thu, 17 Oct 2024 15:48:59 -0700 Subject: [PATCH 1/6] Fixed Template Update Location and Improved Logger Statements in ReprovisionWorkflowTransportAction Signed-off-by: saimedhi --- CHANGELOG.md | 3 +- .../ReprovisionWorkflowTransportAction.java | 38 +++++++++++-------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7011716e..0a993b576 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,10 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) ### Features ### Enhancements ### Bug Fixes +- Fixed Template Update Location and Improved Logger Statements in ReprovisionWorkflowTransportAction ([#918](https://github.com/opensearch-project/flow-framework/pull/918)) ### Infrastructure - Set Java target compatibility to JDK 21 ([#730](https://github.com/opensearch-project/flow-framework/pull/730)) - Add knowledge base alert agent into sample templates ([#874](https://github.com/opensearch-project/flow-framework/pull/874)) - ### Documentation - Add alert summary agent template ([#873](https://github.com/opensearch-project/flow-framework/pull/873)) @@ -25,6 +25,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) - Incrementally remove resources from workflow state during deprovisioning ([#898](https://github.com/opensearch-project/flow-framework/pull/898)) ### Bug Fixes +- Fixed Template Update Location and Improved Logger Statements in ReprovisionWorkflowTransportAction ([#918](https://github.com/opensearch-project/flow-framework/pull/918)) ### Infrastructure ### Documentation - Add query assist data summary agent into sample templates ([#875](https://github.com/opensearch-project/flow-framework/pull/875)) diff --git a/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java index 54f6a332c..e5a8e484e 100644 --- a/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java @@ -270,19 +270,37 @@ private void executeWorkflowAsync( ActionListener listener ) { try { - threadPool.executor(PROVISION_WORKFLOW_THREAD_POOL).execute(() -> { executeWorkflow(template, workflowSequence, workflowId); }); + threadPool.executor(PROVISION_WORKFLOW_THREAD_POOL).execute(() -> { + updateTemplate(template, workflowId); + executeWorkflow(workflowSequence, workflowId); + }); } catch (Exception exception) { listener.onFailure(new FlowFrameworkException("Failed to execute workflow " + workflowId, ExceptionsHelper.status(exception))); } } /** - * Executes the given workflow sequence + * Replace template document * @param template The template to store after reprovisioning completes successfully + * @param workflowId The workflowId associated with the workflow that is executing + */ + private void updateTemplate(Template template, String workflowId) { + flowFrameworkIndicesHandler.updateTemplateInGlobalContext(workflowId, template, ActionListener.wrap(templateResponse -> { + logger.info("Updated template for {}", workflowId, State.COMPLETED); + }, exception -> { + String errorMessage = "Failed to update use case template for " + workflowId; + logger.error(errorMessage, exception); + }), + true // ignores NOT_STARTED state if request is to reprovision + ); + } + + /** + * Executes the given workflow sequence * @param workflowSequence The topologically sorted workflow to execute * @param workflowId The workflowId associated with the workflow that is executing */ - private void executeWorkflow(Template template, List workflowSequence, String workflowId) { + private void executeWorkflow(List workflowSequence, String workflowId) { String currentStepId = ""; try { Map> workflowFutureMap = new LinkedHashMap<>(); @@ -290,7 +308,7 @@ private void executeWorkflow(Template template, List workflowSequen List predecessors = processNode.predecessors(); logger.info( "Queueing process [{}].{}", - processNode.id(), + processNode.id() + processNode.workflowStep().getName(), predecessors.isEmpty() ? " Can start immediately!" : String.format( @@ -321,18 +339,6 @@ private void executeWorkflow(Template template, List workflowSequen logger.info("updated workflow {} state to {}", workflowId, State.COMPLETED); - // Replace template document - flowFrameworkIndicesHandler.updateTemplateInGlobalContext( - workflowId, - template, - ActionListener.wrap(templateResponse -> { - logger.info("Updated template for {}", workflowId, State.COMPLETED); - }, exception -> { - String errorMessage = "Failed to update use case template for " + workflowId; - logger.error(errorMessage, exception); - }), - true // ignores NOT_STARTED state if request is to reprovision - ); }, exception -> { logger.error("Failed to update workflow state for workflow {}", workflowId, exception); }) ); } catch (Exception ex) { From dfa823e1ad784aceed1a8b6b52c87230a02cad27 Mon Sep 17 00:00:00 2001 From: Sai Medhini Reddy Maryada <117196660+saimedhi@users.noreply.github.com> Date: Sun, 20 Oct 2024 20:13:04 -0700 Subject: [PATCH 2/6] Update ReprovisionWorkflowTransportAction.java Signed-off-by: Sai Medhini Reddy Maryada <117196660+saimedhi@users.noreply.github.com> --- .../ReprovisionWorkflowTransportAction.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java index e5a8e484e..c3755f3be 100644 --- a/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java @@ -271,9 +271,8 @@ private void executeWorkflowAsync( ) { try { threadPool.executor(PROVISION_WORKFLOW_THREAD_POOL).execute(() -> { - updateTemplate(template, workflowId); - executeWorkflow(workflowSequence, workflowId); - }); + updateTemplate( template,workflowId); + executeWorkflow(template, workflowSequence, workflowId); }); } catch (Exception exception) { listener.onFailure(new FlowFrameworkException("Failed to execute workflow " + workflowId, ExceptionsHelper.status(exception))); } @@ -284,23 +283,26 @@ private void executeWorkflowAsync( * @param template The template to store after reprovisioning completes successfully * @param workflowId The workflowId associated with the workflow that is executing */ - private void updateTemplate(Template template, String workflowId) { - flowFrameworkIndicesHandler.updateTemplateInGlobalContext(workflowId, template, ActionListener.wrap(templateResponse -> { - logger.info("Updated template for {}", workflowId, State.COMPLETED); - }, exception -> { - String errorMessage = "Failed to update use case template for " + workflowId; - logger.error(errorMessage, exception); - }), - true // ignores NOT_STARTED state if request is to reprovision + private void updateTemplate ( Template template, String workflowId) { + flowFrameworkIndicesHandler.updateTemplateInGlobalContext( + workflowId, + template, + ActionListener.wrap(templateResponse -> { + logger.info("Updated template for {}", workflowId); + }, exception -> { + logger.error("Failed to update use case template for {}", workflowId, exception); + }), + true // ignores NOT_STARTED state if request is to reprovision ); } /** * Executes the given workflow sequence + * @param template The template to store after reprovisioning completes successfully * @param workflowSequence The topologically sorted workflow to execute * @param workflowId The workflowId associated with the workflow that is executing */ - private void executeWorkflow(List workflowSequence, String workflowId) { + private void executeWorkflow(Template template, List workflowSequence, String workflowId) { String currentStepId = ""; try { Map> workflowFutureMap = new LinkedHashMap<>(); @@ -308,7 +310,7 @@ private void executeWorkflow(List workflowSequence, String workflow List predecessors = processNode.predecessors(); logger.info( "Queueing process [{}].{}", - processNode.id() + processNode.workflowStep().getName(), + String.format("%s (type: %s)", processNode.id(), processNode.workflowStep().getName()), predecessors.isEmpty() ? " Can start immediately!" : String.format( From d3245d52b4a8e6cbcd816867a8025d55e771043d Mon Sep 17 00:00:00 2001 From: saimedhi Date: Sun, 20 Oct 2024 20:18:30 -0700 Subject: [PATCH 3/6] Fixed Template Update Location and Improved Logger Statements in ReprovisionWorkflowTransportAction Signed-off-by: saimedhi --- .../ReprovisionWorkflowTransportAction.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java index c3755f3be..7767160a4 100644 --- a/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java @@ -271,8 +271,9 @@ private void executeWorkflowAsync( ) { try { threadPool.executor(PROVISION_WORKFLOW_THREAD_POOL).execute(() -> { - updateTemplate( template,workflowId); - executeWorkflow(template, workflowSequence, workflowId); }); + updateTemplate(template, workflowId); + executeWorkflow(template, workflowSequence, workflowId); + }); } catch (Exception exception) { listener.onFailure(new FlowFrameworkException("Failed to execute workflow " + workflowId, ExceptionsHelper.status(exception))); } @@ -283,16 +284,11 @@ private void executeWorkflowAsync( * @param template The template to store after reprovisioning completes successfully * @param workflowId The workflowId associated with the workflow that is executing */ - private void updateTemplate ( Template template, String workflowId) { - flowFrameworkIndicesHandler.updateTemplateInGlobalContext( - workflowId, - template, - ActionListener.wrap(templateResponse -> { - logger.info("Updated template for {}", workflowId); - }, exception -> { - logger.error("Failed to update use case template for {}", workflowId, exception); - }), - true // ignores NOT_STARTED state if request is to reprovision + private void updateTemplate(Template template, String workflowId) { + flowFrameworkIndicesHandler.updateTemplateInGlobalContext(workflowId, template, ActionListener.wrap(templateResponse -> { + logger.info("Updated template for {}", workflowId); + }, exception -> { logger.error("Failed to update use case template for {}", workflowId, exception); }), + true // ignores NOT_STARTED state if request is to reprovision ); } From 7ed681912791b638cd8662341328edcca362bbd5 Mon Sep 17 00:00:00 2001 From: saimedhi Date: Sun, 20 Oct 2024 21:59:43 -0700 Subject: [PATCH 4/6] Fixed Template Update Location and Improved Logger Statements in ReprovisionWorkflowTransportAction Signed-off-by: saimedhi --- .../transport/ReprovisionWorkflowTransportAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java index 7767160a4..fcaac7a1d 100644 --- a/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java @@ -306,7 +306,7 @@ private void executeWorkflow(Template template, List workflowSequen List predecessors = processNode.predecessors(); logger.info( "Queueing process [{}].{}", - String.format("%s (type: %s)", processNode.id(), processNode.workflowStep().getName()), + String.format(Locale.getDefault(), "%s (type: %s)", processNode.id(), processNode.workflowStep().getName()), predecessors.isEmpty() ? " Can start immediately!" : String.format( From 3a9085924eb90e07d5bc8f5c1b0692551737d757 Mon Sep 17 00:00:00 2001 From: saimedhi Date: Sun, 20 Oct 2024 22:08:50 -0700 Subject: [PATCH 5/6] Fixed Template Update Location and Improved Logger Statements in ReprovisionWorkflowTransportAction Signed-off-by: saimedhi --- .../transport/ReprovisionWorkflowTransportAction.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java index fcaac7a1d..867c61f60 100644 --- a/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java @@ -305,8 +305,9 @@ private void executeWorkflow(Template template, List workflowSequen for (ProcessNode processNode : workflowSequence) { List predecessors = processNode.predecessors(); logger.info( - "Queueing process [{}].{}", - String.format(Locale.getDefault(), "%s (type: %s)", processNode.id(), processNode.workflowStep().getName()), + "Queueing Process [{} (type: {})].{}", + processNode.id(), + processNode.workflowStep().getName(), predecessors.isEmpty() ? " Can start immediately!" : String.format( From 98ae7044a81e00f27664eb16ea61289bbda203c0 Mon Sep 17 00:00:00 2001 From: saimedhi Date: Mon, 21 Oct 2024 20:52:48 -0700 Subject: [PATCH 6/6] fixed changelog Signed-off-by: saimedhi --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a993b576..6b1bc8270 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,10 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) ### Features ### Enhancements ### Bug Fixes -- Fixed Template Update Location and Improved Logger Statements in ReprovisionWorkflowTransportAction ([#918](https://github.com/opensearch-project/flow-framework/pull/918)) ### Infrastructure - Set Java target compatibility to JDK 21 ([#730](https://github.com/opensearch-project/flow-framework/pull/730)) - Add knowledge base alert agent into sample templates ([#874](https://github.com/opensearch-project/flow-framework/pull/874)) + ### Documentation - Add alert summary agent template ([#873](https://github.com/opensearch-project/flow-framework/pull/873)) @@ -26,9 +26,11 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) ### Bug Fixes - Fixed Template Update Location and Improved Logger Statements in ReprovisionWorkflowTransportAction ([#918](https://github.com/opensearch-project/flow-framework/pull/918)) + ### Infrastructure ### Documentation - Add query assist data summary agent into sample templates ([#875](https://github.com/opensearch-project/flow-framework/pull/875)) + ### Maintenance ### Refactoring - Update workflow state without using painless script ([#894](https://github.com/opensearch-project/flow-framework/pull/894))