From 713caa11c4e881d591de603bc351017b2750aaa8 Mon Sep 17 00:00:00 2001 From: Patrik Cmil Date: Thu, 24 Oct 2024 22:39:05 +0200 Subject: [PATCH 1/7] Replace strings in GetWorkflowTransportAction.java Signed-off-by: Patrik Cmil --- .../transport/GetWorkflowTransportAction.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/opensearch/flowframework/transport/GetWorkflowTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/GetWorkflowTransportAction.java index 59b129baf..9c8545b27 100644 --- a/src/main/java/org/opensearch/flowframework/transport/GetWorkflowTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/GetWorkflowTransportAction.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.get.GetRequest; import org.opensearch.action.support.ActionFilters; @@ -104,12 +105,16 @@ protected void doExecute(Task task, WorkflowRequest request, ActionListener { - String errorMessage = "Failed to retrieve template (" + workflowId + ") from global context."; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to retrieve template ({}) from global context.", + workflowId + ).getFormattedMessage(); logger.error(errorMessage, exception); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(exception))); })); From 0c4e6000ad84cc838856317c113032db1e21bd11 Mon Sep 17 00:00:00 2001 From: Patrik Cmil Date: Sun, 27 Oct 2024 23:18:21 +0100 Subject: [PATCH 2/7] Replace strings in 5 files Signed-off-by: Patrik Cmil --- .../transport/SearchWorkflowTransportAction.java | 4 +++- .../workflow/AbstractRetryableWorkflowStep.java | 12 +++++++++--- .../flowframework/workflow/DeployModelStep.java | 5 ++++- .../flowframework/workflow/ReindexStep.java | 11 +++++++++-- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/opensearch/flowframework/transport/SearchWorkflowTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/SearchWorkflowTransportAction.java index 46f0afb10..afb2b184f 100644 --- a/src/main/java/org/opensearch/flowframework/transport/SearchWorkflowTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/SearchWorkflowTransportAction.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.search.SearchRequest; import org.opensearch.action.search.SearchResponse; @@ -48,7 +49,8 @@ protected void doExecute(Task task, SearchRequest request, ActionListener { - String errorMessage = workflowStep + " failed"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("{} failed", workflowStep).getFormattedMessage(); logger.error(errorMessage, exception); mlTaskListener.onFailure(new WorkflowStepException(errorMessage, RestStatus.BAD_REQUEST)); })); diff --git a/src/main/java/org/opensearch/flowframework/workflow/DeployModelStep.java b/src/main/java/org/opensearch/flowframework/workflow/DeployModelStep.java index e51100f04..923650c20 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/DeployModelStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/DeployModelStep.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.support.PlainActionFuture; import org.opensearch.core.action.ActionListener; @@ -109,7 +110,9 @@ public void onResponse(MLDeployModelResponse mlDeployModelResponse) { @Override public void onFailure(Exception ex) { Exception e = getSafeException(ex); - String errorMessage = (e == null ? "Failed to deploy model " + modelId : e.getMessage()); + String errorMessage = (e == null + ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed to deploy model {}", modelId).getFormattedMessage() + : e.getMessage()); logger.error(errorMessage, e); deployModelFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); } diff --git a/src/main/java/org/opensearch/flowframework/workflow/ReindexStep.java b/src/main/java/org/opensearch/flowframework/workflow/ReindexStep.java index 18ce60f14..c4427e049 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/ReindexStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/ReindexStep.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.support.PlainActionFuture; import org.opensearch.client.Client; @@ -150,7 +151,9 @@ public void onResponse(BulkByScrollResponse bulkByScrollResponse) { reIndexFuture.onFailure(new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST)); } } catch (Exception e) { - String errorMessage = "Failed to parse and update new created resource"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to parse and update new created resource" + ).getFormattedMessage(); logger.error(errorMessage, e); reIndexFuture.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); } @@ -158,7 +161,11 @@ public void onResponse(BulkByScrollResponse bulkByScrollResponse) { @Override public void onFailure(Exception e) { - String errorMessage = "Failed to reindex from source " + sourceIndices + " to " + destinationIndex; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to reindex from source {} to {}", + sourceIndices, + destinationIndex + ).getFormattedMessage(); logger.error(errorMessage, e); reIndexFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); } From d168f5df9e160732296019b122761692df15bafe Mon Sep 17 00:00:00 2001 From: Patrik Cmil Date: Mon, 28 Oct 2024 23:14:21 +0100 Subject: [PATCH 3/7] Replace strings in 10 files Signed-off-by: Patrik Cmil --- .../flowframework/model/WorkflowNode.java | 6 ++++- .../ReprovisionWorkflowTransportAction.java | 26 ++++++++++++++----- .../workflow/AbstractCreatePipelineStep.java | 5 +++- .../workflow/AbstractUpdatePipelineStep.java | 5 +++- .../workflow/UndeployModelStep.java | 5 +++- 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/opensearch/flowframework/model/WorkflowNode.java b/src/main/java/org/opensearch/flowframework/model/WorkflowNode.java index 980e9755b..7331f1475 100644 --- a/src/main/java/org/opensearch/flowframework/model/WorkflowNode.java +++ b/src/main/java/org/opensearch/flowframework/model/WorkflowNode.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.common.unit.TimeValue; import org.opensearch.core.rest.RestStatus; import org.opensearch.core.xcontent.ToXContentObject; @@ -171,7 +172,10 @@ public static WorkflowNode parse(XContentParser parser) throws IOException { String configurationsString = ParseUtils.parseArbitraryStringToObjectMapToString(configurationsMap); userInputs.put(inputFieldName, configurationsString); } catch (Exception ex) { - String errorMessage = "Failed to parse" + inputFieldName + "map"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to parse {} map", + inputFieldName + ).getFormattedMessage(); logger.error(errorMessage, ex); throw new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST); } diff --git a/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java index 867c61f60..8e501228b 100644 --- a/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/ReprovisionWorkflowTransportAction.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; @@ -145,7 +146,10 @@ protected void doExecute(Task task, ReprovisionWorkflowRequest request, ActionLi xContentRegistry ); } catch (Exception e) { - String errorMessage = "Failed to get workflow state for workflow " + workflowId; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to get workflow state for workflow {}", + workflowId + ).getFormattedMessage(); logger.error(errorMessage, e); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); } @@ -195,9 +199,12 @@ private void executeReprovisionRequest( try { workflowProcessSorter.validate(updatedProcessSequence, pluginsService); } catch (Exception e) { - String errormessage = "Workflow validation failed for workflow " + request.getWorkflowId(); - logger.error(errormessage, e); - listener.onFailure(new FlowFrameworkException(errormessage, RestStatus.BAD_REQUEST)); + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Workflow validation failed for workflow {}", + request.getWorkflowId() + ).getFormattedMessage(); + logger.error(errorMessage, e); + listener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST)); } List reprovisionProcessSequence = workflowProcessSorter.createReprovisionSequence( workflowId, @@ -212,7 +219,8 @@ private void executeReprovisionRequest( flowFrameworkIndicesHandler.updateFlowFrameworkSystemIndexDoc(workflowId, newState, ActionListener.wrap(updateResponse -> { }, exception -> { - String errorMessage = "Failed to update workflow state: " + workflowId; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Failed to update workflow state: {}", workflowId) + .getFormattedMessage(); logger.error(errorMessage, exception); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(exception))); })); @@ -240,7 +248,8 @@ private void executeReprovisionRequest( listener.onResponse(new WorkflowResponse(workflowId)); }, exception -> { - String errorMessage = "Failed to update workflow state: " + workflowId; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Failed to update workflow state: {}", workflowId) + .getFormattedMessage(); logger.error(errorMessage, exception); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(exception))); }) @@ -249,7 +258,10 @@ private void executeReprovisionRequest( if (exception instanceof FlowFrameworkException) { listener.onFailure(exception); } else { - String errorMessage = "Failed to get workflow state for workflow " + workflowId; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to get workflow state for workflow {}", + workflowId + ).getFormattedMessage(); logger.error(errorMessage, exception); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(exception))); } diff --git a/src/main/java/org/opensearch/flowframework/workflow/AbstractCreatePipelineStep.java b/src/main/java/org/opensearch/flowframework/workflow/AbstractCreatePipelineStep.java index bbaa77204..f16c87ef7 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/AbstractCreatePipelineStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/AbstractCreatePipelineStep.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.ingest.PutPipelineRequest; import org.opensearch.action.search.PutSearchPipelineRequest; @@ -110,7 +111,9 @@ public void onResponse(AcknowledgedResponse acknowledgedResponse) { @Override public void onFailure(Exception ex) { Exception e = getSafeException(ex); - String errorMessage = (e == null ? "Failed step " + pipelineToBeCreated : e.getMessage()); + String errorMessage = (e == null + ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed step {}", pipelineToBeCreated).getFormattedMessage() + : e.getMessage()); logger.error(errorMessage, e); createPipelineFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); } diff --git a/src/main/java/org/opensearch/flowframework/workflow/AbstractUpdatePipelineStep.java b/src/main/java/org/opensearch/flowframework/workflow/AbstractUpdatePipelineStep.java index e57796f02..5c3e3a52f 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/AbstractUpdatePipelineStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/AbstractUpdatePipelineStep.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.support.PlainActionFuture; import org.opensearch.action.support.master.AcknowledgedResponse; @@ -115,7 +116,9 @@ public void onResponse(AcknowledgedResponse acknowledgedResponse) { @Override public void onFailure(Exception ex) { Exception e = getSafeException(ex); - String errorMessage = (e == null ? "Failed step " + pipelineToBeCreated : e.getMessage()); + String errorMessage = (e == null + ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed step {}", pipelineToBeCreated).getFormattedMessage() + : e.getMessage()); logger.error(errorMessage, e); createPipelineFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); } diff --git a/src/main/java/org/opensearch/flowframework/workflow/UndeployModelStep.java b/src/main/java/org/opensearch/flowframework/workflow/UndeployModelStep.java index ab7bc1f16..433315f44 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/UndeployModelStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/UndeployModelStep.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchException; import org.opensearch.action.FailedNodeException; @@ -99,7 +100,9 @@ public void onResponse(MLUndeployModelsResponse mlUndeployModelsResponse) { @Override public void onFailure(Exception ex) { Exception e = getSafeException(ex); - String errorMessage = (e == null ? "Failed to undeploy model " + modelId : e.getMessage()); + String errorMessage = (e == null + ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed to undeploy model {}", modelId).getFormattedMessage() + : e.getMessage()); logger.error(errorMessage, e); undeployModelFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); } From 7cd4a0ee8085b4382e5a51dfbcf61b7c568b1ab2 Mon Sep 17 00:00:00 2001 From: Patrik Cmil Date: Mon, 4 Nov 2024 16:42:44 +0100 Subject: [PATCH 4/7] Replace strings in 40 files Signed-off-by: Patrik Cmil --- .../indices/FlowFrameworkIndicesHandler.java | 121 ++++++++++++++---- .../rest/RestCreateWorkflowAction.java | 10 +- .../rest/RestDeleteWorkflowAction.java | 5 +- .../rest/RestDeprovisionWorkflowAction.java | 5 +- .../rest/RestGetWorkflowAction.java | 5 +- .../rest/RestGetWorkflowStateAction.java | 5 +- .../rest/RestGetWorkflowStepAction.java | 5 +- .../rest/RestProvisionWorkflowAction.java | 5 +- .../CreateWorkflowTransportAction.java | 64 ++++++--- .../DeleteWorkflowTransportAction.java | 4 +- .../DeprovisionWorkflowTransportAction.java | 9 +- .../GetWorkflowStateTransportAction.java | 10 +- .../GetWorkflowStepTransportAction.java | 4 +- .../ProvisionWorkflowTransportAction.java | 26 +++- .../SearchWorkflowStateTransportAction.java | 4 +- .../flowframework/util/ParseUtils.java | 14 +- .../AbstractRegisterLocalModelStep.java | 14 +- .../workflow/CreateConnectorStep.java | 5 +- .../workflow/CreateIndexStep.java | 10 +- .../workflow/DeleteAgentStep.java | 5 +- .../workflow/DeleteConnectorStep.java | 6 +- .../workflow/DeleteIndexStep.java | 5 +- .../workflow/DeleteIngestPipelineStep.java | 6 +- .../workflow/DeleteModelStep.java | 5 +- .../workflow/DeleteSearchPipelineStep.java | 6 +- .../workflow/RegisterAgentStep.java | 5 +- .../workflow/RegisterModelGroupStep.java | 5 +- .../workflow/RegisterRemoteModelStep.java | 8 +- .../workflow/UpdateIndexStep.java | 13 +- .../workflow/WorkflowStepFactory.java | 21 ++- 30 files changed, 319 insertions(+), 91 deletions(-) diff --git a/src/main/java/org/opensearch/flowframework/indices/FlowFrameworkIndicesHandler.java b/src/main/java/org/opensearch/flowframework/indices/FlowFrameworkIndicesHandler.java index f05a162ff..2db99f040 100644 --- a/src/main/java/org/opensearch/flowframework/indices/FlowFrameworkIndicesHandler.java +++ b/src/main/java/org/opensearch/flowframework/indices/FlowFrameworkIndicesHandler.java @@ -196,7 +196,8 @@ public void initFlowFrameworkIndexIfAbsent(FlowFrameworkIndex index, ActionListe internalListener.onResponse(false); } }, e -> { - String errorMessage = "Failed to create index " + indexName; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Failed to create index {}", indexName) + .getFormattedMessage(); logger.error(errorMessage, e); internalListener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); }); @@ -232,7 +233,10 @@ public void initFlowFrameworkIndexIfAbsent(FlowFrameworkIndex index, ActionListe ); } }, exception -> { - String errorMessage = "Failed to update index setting for: " + indexName; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to update index setting for: {}", + indexName + ).getFormattedMessage(); logger.error(errorMessage, exception); internalListener.onFailure( new FlowFrameworkException(errorMessage, ExceptionsHelper.status(exception)) @@ -244,7 +248,10 @@ public void initFlowFrameworkIndexIfAbsent(FlowFrameworkIndex index, ActionListe ); } }, exception -> { - String errorMessage = "Failed to update index " + indexName; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to update index {}", + indexName + ).getFormattedMessage(); logger.error(errorMessage, exception); internalListener.onFailure( new FlowFrameworkException(errorMessage, ExceptionsHelper.status(exception)) @@ -257,7 +264,10 @@ public void initFlowFrameworkIndexIfAbsent(FlowFrameworkIndex index, ActionListe internalListener.onResponse(true); } }, e -> { - String errorMessage = "Failed to update index mapping for " + indexName; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to update index mapping for {}", + indexName + ).getFormattedMessage(); logger.error(errorMessage, e); internalListener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); })); @@ -267,7 +277,8 @@ public void initFlowFrameworkIndexIfAbsent(FlowFrameworkIndex index, ActionListe } } } catch (Exception e) { - String errorMessage = "Failed to init index " + indexName; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Failed to init index {}", indexName) + .getFormattedMessage(); logger.error(errorMessage, e); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); } @@ -331,7 +342,8 @@ public void putTemplateToGlobalContext(Template template, ActionListener { - String errorMessage = "Failed to create workflow_state index"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Failed to create workflow_state index") + .getFormattedMessage(); logger.error(errorMessage, e); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); })); @@ -424,7 +438,10 @@ public void updateTemplateInGlobalContext( boolean ignoreNotStartedCheck ) { if (!doesIndexExist(GLOBAL_CONTEXT_INDEX)) { - String errorMessage = "Failed to update template for workflow_id : " + documentId + ", global_context index does not exist."; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to update template for workflow_id : {}, global_context index does not exist.", + documentId + ).getFormattedMessage(); logger.error(errorMessage); listener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST)); return; @@ -443,20 +460,25 @@ public void updateTemplateInGlobalContext( .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); client.index(request, ActionListener.runBefore(listener, context::restore)); } catch (Exception e) { - String errorMessage = "Failed to update global_context entry : " + documentId; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to update global_context entry : {}", + documentId + ).getFormattedMessage(); logger.error(errorMessage, e); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); } } else { - String errorMessage = "The template can not be updated unless its provisioning state is NOT_STARTED: " - + documentId - + ". Deprovision the workflow to reset the state."; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "The template can not be updated unless its provisioning state is NOT_STARTED: {}. Deprovision the workflow to reset the state.", + documentId + ).getFormattedMessage(); logger.error(errorMessage); listener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST)); } }, listener); } else { - String errorMessage = "Failed to get template: " + documentId; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Failed to get template: {}", documentId) + .getFormattedMessage(); logger.error(errorMessage); listener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST)); } @@ -476,12 +498,16 @@ public void doesTemplateExist(String documentId, Consumer booleanRe try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) { client.get(getRequest, ActionListener.wrap(response -> { booleanResultConsumer.accept(response.isExists()); }, exception -> { context.restore(); - String errorMessage = "Failed to get template " + documentId; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Failed to get template {}", documentId) + .getFormattedMessage(); logger.error(errorMessage); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(exception))); })); } catch (Exception e) { - String errorMessage = "Failed to retrieve template from global context: " + documentId; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to retrieve template from global context: {}", + documentId + ).getFormattedMessage(); logger.error(errorMessage, e); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); } @@ -515,7 +541,8 @@ public void getProvisioningProgress( WorkflowState workflowState = WorkflowState.parse(parser); provisioningProgressConsumer.accept(Optional.of(ProvisioningProgress.valueOf(workflowState.getProvisioningProgress()))); } catch (Exception e) { - String errorMessage = "Failed to parse workflow state " + documentId; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Failed to parse workflow state {}", documentId) + .getFormattedMessage(); logger.error(errorMessage, e); listener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.INTERNAL_SERVER_ERROR)); } @@ -524,7 +551,9 @@ public void getProvisioningProgress( provisioningProgressConsumer.accept(Optional.empty()); })); } catch (Exception e) { - String errorMessage = "Failed to retrieve workflow state to check provisioning status"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to retrieve workflow state to check provisioning status" + ).getFormattedMessage(); logger.error(errorMessage, e); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); } @@ -566,7 +595,9 @@ public void canDeleteWorkflowStateDoc( ) ); } catch (Exception e) { - String errorMessage = "Failed to parse workflow state " + documentId; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Failed to parse workflow state {}", documentId) + .getFormattedMessage(); + ; logger.error(errorMessage, e); listener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.INTERNAL_SERVER_ERROR)); } @@ -575,7 +606,9 @@ public void canDeleteWorkflowStateDoc( canDeleteStateConsumer.accept(Boolean.FALSE); })); } catch (Exception e) { - String errorMessage = "Failed to retrieve workflow state to check provisioning status"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to retrieve workflow state to check provisioning status" + ).getFormattedMessage(); logger.error(errorMessage, e); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); } @@ -593,7 +626,11 @@ public void updateFlowFrameworkSystemIndexDoc( ActionListener listener ) { if (!doesIndexExist(WORKFLOW_STATE_INDEX)) { - String errorMessage = "Failed to update document " + documentId + " due to missing " + WORKFLOW_STATE_INDEX + " index"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to update document {} due to missing {} index", + documentId, + WORKFLOW_STATE_INDEX + ).getFormattedMessage(); logger.error(errorMessage); listener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST)); } else { @@ -606,7 +643,11 @@ public void updateFlowFrameworkSystemIndexDoc( updateRequest.retryOnConflict(RETRIES); client.update(updateRequest, ActionListener.runBefore(listener, context::restore)); } catch (Exception e) { - String errorMessage = "Failed to update " + WORKFLOW_STATE_INDEX + " entry : " + documentId; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to update {} entry : {}", + WORKFLOW_STATE_INDEX, + documentId + ).getFormattedMessage(); logger.error(errorMessage, e); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); } @@ -625,7 +666,11 @@ public void updateFlowFrameworkSystemIndexDoc( ActionListener listener ) { if (!doesIndexExist(WORKFLOW_STATE_INDEX)) { - String errorMessage = "Failed to update document " + documentId + " due to missing " + WORKFLOW_STATE_INDEX + " index"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to update document {} due to missing {} index", + documentId, + WORKFLOW_STATE_INDEX + ).getFormattedMessage(); logger.error(errorMessage); listener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST)); } else { @@ -638,7 +683,11 @@ public void updateFlowFrameworkSystemIndexDoc( // TODO: decide what condition can be considered as an update conflict and add retry strategy client.update(updateRequest, ActionListener.runBefore(listener, context::restore)); } catch (Exception e) { - String errorMessage = "Failed to update " + WORKFLOW_STATE_INDEX + " entry : " + documentId; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to update {} entry : {}", + WORKFLOW_STATE_INDEX, + documentId + ).getFormattedMessage(); logger.error(errorMessage, e); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); } @@ -652,7 +701,11 @@ public void updateFlowFrameworkSystemIndexDoc( */ public void deleteFlowFrameworkSystemIndexDoc(String documentId, ActionListener listener) { if (!doesIndexExist(WORKFLOW_STATE_INDEX)) { - String errorMessage = "Failed to delete document " + documentId + " due to missing " + WORKFLOW_STATE_INDEX + " index"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to delete document {} due to missing {} index", + documentId, + WORKFLOW_STATE_INDEX + ).getFormattedMessage(); logger.error(errorMessage); listener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST)); } else { @@ -661,7 +714,11 @@ public void deleteFlowFrameworkSystemIndexDoc(String documentId, ActionListener< deleteRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); client.delete(deleteRequest, ActionListener.runBefore(listener, context::restore)); } catch (Exception e) { - String errorMessage = "Failed to delete " + WORKFLOW_STATE_INDEX + " entry : " + documentId; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to delete {} entry : {}", + WORKFLOW_STATE_INDEX, + documentId + ).getFormattedMessage(); logger.error(errorMessage, e); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); } @@ -687,7 +744,11 @@ public void addResourceToStateIndex( String resourceName = getResourceByWorkflowStep(workflowStepName); ResourceCreated newResource = new ResourceCreated(workflowStepName, nodeId, resourceName, resourceId); if (!doesIndexExist(WORKFLOW_STATE_INDEX)) { - String errorMessage = "Failed to update state for " + workflowId + " due to missing " + WORKFLOW_STATE_INDEX + " index"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to update state for {} due to missing {} index", + workflowId, + WORKFLOW_STATE_INDEX + ).getFormattedMessage(); logger.error(errorMessage); listener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.NOT_FOUND)); } else { @@ -711,7 +772,11 @@ public void addResourceToStateIndex( */ public void deleteResourceFromStateIndex(String workflowId, ResourceCreated resourceToDelete, ActionListener listener) { if (!doesIndexExist(WORKFLOW_STATE_INDEX)) { - String errorMessage = "Failed to update state for " + workflowId + " due to missing " + WORKFLOW_STATE_INDEX + " index"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to update state for {} due to missing {} index", + workflowId, + WORKFLOW_STATE_INDEX + ).getFormattedMessage(); logger.error(errorMessage); listener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.NOT_FOUND)); } else { diff --git a/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java b/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java index 8acfab16a..b4850152a 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.client.node.NodeClient; import org.opensearch.core.action.ActionListener; @@ -193,8 +194,9 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli throw ex; } else { RestStatus status = ex instanceof IOException ? RestStatus.BAD_REQUEST : ExceptionsHelper.status(ex); - String errorMessage = - "failure parsing request body when a use case is given, make sure to provide a map with values that are either Strings, Arrays, or Map of Strings to Strings"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "failure parsing request body when a use case is given, make sure to provide a map with values that are either Strings, Arrays, or Map of Strings to Strings" + ).getFormattedMessage(); logger.error(errorMessage, ex); throw new FlowFrameworkException(errorMessage, status); } @@ -242,7 +244,9 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli XContentBuilder exceptionBuilder = ex.toXContent(channel.newErrorBuilder(), ToXContent.EMPTY_PARAMS); channel.sendResponse(new BytesRestResponse(ex.getRestStatus(), exceptionBuilder)); } catch (IOException e) { - String errorMessage = "IOException: Failed to send back create workflow exception"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "IOException: Failed to send back create workflow exception" + ).getFormattedMessage(); logger.error(errorMessage, e); channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage)); } diff --git a/src/main/java/org/opensearch/flowframework/rest/RestDeleteWorkflowAction.java b/src/main/java/org/opensearch/flowframework/rest/RestDeleteWorkflowAction.java index ebef48c86..4062ba47f 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestDeleteWorkflowAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestDeleteWorkflowAction.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.client.node.NodeClient; import org.opensearch.core.action.ActionListener; @@ -92,7 +93,9 @@ protected BaseRestHandler.RestChannelConsumer prepareRequest(RestRequest request XContentBuilder exceptionBuilder = ex.toXContent(channel.newErrorBuilder(), ToXContent.EMPTY_PARAMS); channel.sendResponse(new BytesRestResponse(ex.getRestStatus(), exceptionBuilder)); } catch (IOException e) { - String errorMessage = "IOException: Failed to send back delete workflow exception"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "IOException: Failed to send back delete workflow exception" + ).getFormattedMessage(); logger.error(errorMessage, e); channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage)); } diff --git a/src/main/java/org/opensearch/flowframework/rest/RestDeprovisionWorkflowAction.java b/src/main/java/org/opensearch/flowframework/rest/RestDeprovisionWorkflowAction.java index d75255b8d..7f75c8980 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestDeprovisionWorkflowAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestDeprovisionWorkflowAction.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.client.node.NodeClient; import org.opensearch.core.action.ActionListener; @@ -94,7 +95,9 @@ protected BaseRestHandler.RestChannelConsumer prepareRequest(RestRequest request XContentBuilder exceptionBuilder = ex.toXContent(channel.newErrorBuilder(), ToXContent.EMPTY_PARAMS); channel.sendResponse(new BytesRestResponse(ex.getRestStatus(), exceptionBuilder)); } catch (IOException e) { - String errorMessage = "IOException: Failed to send back deprovision workflow exception"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "IOException: Failed to send back deprovision workflow exception" + ).getFormattedMessage(); logger.error(errorMessage, e); channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage)); } diff --git a/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowAction.java b/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowAction.java index 81141a380..cbfaea94d 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowAction.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.client.node.NodeClient; import org.opensearch.core.action.ActionListener; @@ -91,7 +92,9 @@ protected BaseRestHandler.RestChannelConsumer prepareRequest(RestRequest request XContentBuilder exceptionBuilder = ex.toXContent(channel.newErrorBuilder(), ToXContent.EMPTY_PARAMS); channel.sendResponse(new BytesRestResponse(ex.getRestStatus(), exceptionBuilder)); } catch (IOException e) { - String errorMessage = "IOException: Failed to send back get workflow exception"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "IOException: Failed to send back get workflow exception" + ).getFormattedMessage(); logger.error(errorMessage, e); channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage)); } diff --git a/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStateAction.java b/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStateAction.java index bdf4df35f..2d9a57fb1 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStateAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStateAction.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.client.node.NodeClient; import org.opensearch.core.action.ActionListener; @@ -87,7 +88,9 @@ protected BaseRestHandler.RestChannelConsumer prepareRequest(RestRequest request XContentBuilder exceptionBuilder = ex.toXContent(channel.newErrorBuilder(), ToXContent.EMPTY_PARAMS); channel.sendResponse(new BytesRestResponse(ex.getRestStatus(), exceptionBuilder)); } catch (IOException e) { - String errorMessage = "IOException: Failed to send back get workflow state exception"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "IOException: Failed to send back get workflow state exception" + ).getFormattedMessage(); logger.error(errorMessage, e); channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage)); } diff --git a/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStepAction.java b/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStepAction.java index b889cede7..d0b98765b 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStepAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStepAction.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.client.node.NodeClient; import org.opensearch.core.action.ActionListener; @@ -91,7 +92,9 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli XContentBuilder exceptionBuilder = ex.toXContent(channel.newErrorBuilder(), ToXContent.EMPTY_PARAMS); channel.sendResponse(new BytesRestResponse(ex.getRestStatus(), exceptionBuilder)); } catch (IOException e) { - String errorMessage = "IOException: Failed to send back get workflow step exception"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "IOException: Failed to send back get workflow step exception" + ).getFormattedMessage(); logger.error(errorMessage, e); channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage)); } diff --git a/src/main/java/org/opensearch/flowframework/rest/RestProvisionWorkflowAction.java b/src/main/java/org/opensearch/flowframework/rest/RestProvisionWorkflowAction.java index 6ae56905c..20e8d5979 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestProvisionWorkflowAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestProvisionWorkflowAction.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.client.node.NodeClient; import org.opensearch.core.action.ActionListener; @@ -98,7 +99,9 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli XContentBuilder exceptionBuilder = ex.toXContent(channel.newErrorBuilder(), ToXContent.EMPTY_PARAMS); channel.sendResponse(new BytesRestResponse(ex.getRestStatus(), exceptionBuilder)); } catch (IOException e) { - String errorMessage = "IOException: Failed to send back provision workflow exception"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "IOException: Failed to send back provision workflow exception" + ).getFormattedMessage(); logger.error(errorMessage, e); channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage)); } diff --git a/src/main/java/org/opensearch/flowframework/transport/CreateWorkflowTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/CreateWorkflowTransportAction.java index 72b2e8a12..47bfe9323 100644 --- a/src/main/java/org/opensearch/flowframework/transport/CreateWorkflowTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/CreateWorkflowTransportAction.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.get.GetRequest; import org.opensearch.action.search.SearchRequest; @@ -201,7 +202,10 @@ private void createExecute(WorkflowRequest request, User user, ActionListener { if (FALSE.equals(max)) { - String errorMessage = "Maximum workflows limit reached: " + flowFrameworkSettings.getMaxWorkflows(); + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Maximum workflows limit reached: {}", + flowFrameworkSettings.getMaxWorkflows() + ).getFormattedMessage(); logger.error(errorMessage); FlowFrameworkException ffe = new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST); listener.onFailure(ffe); @@ -256,7 +263,9 @@ private void createExecute(WorkflowRequest request, User user, ActionListener { listener.onResponse(new WorkflowResponse(provisionResponse.getWorkflowId())); }, exception -> { - String errorMessage = "Provisioning failed."; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Provisioning failed." + ).getFormattedMessage(); logger.error(errorMessage, exception); if (exception instanceof FlowFrameworkException) { listener.onFailure(exception); @@ -274,7 +283,9 @@ private void createExecute(WorkflowRequest request, User user, ActionListener { - String errorMessage = "Failed to save workflow state"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to save workflow state" + ).getFormattedMessage(); logger.error(errorMessage, exception); if (exception instanceof FlowFrameworkException) { listener.onFailure(exception); @@ -284,7 +295,9 @@ private void createExecute(WorkflowRequest request, User user, ActionListener { - String errorMessage = "Failed to save use case template"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to save use case template" + ).getFormattedMessage(); logger.error(errorMessage, exception); if (exception instanceof FlowFrameworkException) { listener.onFailure(exception); @@ -297,7 +310,8 @@ private void createExecute(WorkflowRequest request, User user, ActionListener { - String errorMessage = "Failed to initialize config index"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Failed to initialize config index") + .getFormattedMessage(); logger.error(errorMessage, exception); if (exception instanceof FlowFrameworkException) { listener.onFailure(exception); @@ -307,7 +321,10 @@ private void createExecute(WorkflowRequest request, User user, ActionListener { - String errorMessage = "Failed to update use case template " + request.getWorkflowId(); + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to update use case template {}", + request.getWorkflowId() + ).getFormattedMessage(); logger.error(errorMessage, exception); if (exception instanceof FlowFrameworkException) { listener.onFailure(exception); @@ -350,7 +367,10 @@ private void createExecute(WorkflowRequest request, User user, ActionListener { listener.onResponse(new WorkflowResponse(reprovisionResponse.getWorkflowId())); }, exception -> { - String errorMessage = "Reprovisioning failed for workflow " + workflowId; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Reprovisioning failed for workflow {}", + workflowId + ).getFormattedMessage(); logger.error(errorMessage, exception); if (exception instanceof FlowFrameworkException) { listener.onFailure(exception); @@ -382,9 +402,10 @@ private void createExecute(WorkflowRequest request, User user, ActionListener { - String errorMessage = "Failed to update workflow " - + request.getWorkflowId() - + " in template index"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to update workflow {} in template index", + request.getWorkflowId() + ).getFormattedMessage(); logger.error(errorMessage, exception); if (exception instanceof FlowFrameworkException) { listener.onFailure(exception); @@ -399,7 +420,10 @@ private void createExecute(WorkflowRequest request, User user, ActionListener { - String errorMessage = "Failed to update use case template " + request.getWorkflowId(); + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to update use case template {}", + request.getWorkflowId() + ).getFormattedMessage(); logger.error(errorMessage, exception); if (exception instanceof FlowFrameworkException) { listener.onFailure(exception); @@ -411,12 +435,18 @@ private void createExecute(WorkflowRequest request, User user, ActionListener { - String errorMessage = "Failed to retrieve template (" + workflowId + ") from global context."; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to retrieve template ({}) from global context.", + workflowId + ).getFormattedMessage(); logger.error(errorMessage, exception); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(exception))); })); @@ -444,12 +474,14 @@ void checkMaxWorkflows(TimeValue requestTimeOut, Integer maxWorkflow, ActionList context.restore(); internalListener.onResponse(searchResponse.getHits().getTotalHits().value < maxWorkflow); }, exception -> { - String errorMessage = "Unable to fetch the workflows"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Unable to fetch the workflows") + .getFormattedMessage(); logger.error(errorMessage, exception); internalListener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(exception))); })); } catch (Exception e) { - String errorMessage = "Unable to fetch the workflows"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Unable to fetch the workflows") + .getFormattedMessage(); logger.error(errorMessage, e); internalListener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); } diff --git a/src/main/java/org/opensearch/flowframework/transport/DeleteWorkflowTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/DeleteWorkflowTransportAction.java index 2974f522f..7ba767979 100644 --- a/src/main/java/org/opensearch/flowframework/transport/DeleteWorkflowTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/DeleteWorkflowTransportAction.java @@ -11,6 +11,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.util.Booleans; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.action.delete.DeleteRequest; import org.opensearch.action.delete.DeleteResponse; import org.opensearch.action.support.ActionFilters; @@ -97,7 +98,8 @@ protected void doExecute(Task task, WorkflowRequest request, ActionListener { - String errorMessage = "Failed to get workflow state for workflow " + workflowId; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to get workflow state for workflow {}", + workflowId + ).getFormattedMessage(); logger.error(errorMessage, exception); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(exception))); })); diff --git a/src/main/java/org/opensearch/flowframework/transport/GetWorkflowStateTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/GetWorkflowStateTransportAction.java index b8e0eaf2a..bf374e055 100644 --- a/src/main/java/org/opensearch/flowframework/transport/GetWorkflowStateTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/GetWorkflowStateTransportAction.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.get.GetRequest; import org.opensearch.action.support.ActionFilters; @@ -96,7 +97,8 @@ protected void doExecute(Task task, GetWorkflowStateRequest request, ActionListe ); } catch (Exception e) { - String errorMessage = "Failed to get workflow: " + workflowId; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Failed to get workflow: {}", workflowId) + .getFormattedMessage(); logger.error(errorMessage, e); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); } @@ -123,7 +125,8 @@ private void executeGetWorkflowStateRequest( WorkflowState workflowState = WorkflowState.parse(parser); listener.onResponse(new GetWorkflowStateResponse(workflowState, request.getAll())); } catch (Exception e) { - String errorMessage = "Failed to parse workflowState: " + r.getId(); + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Failed to parse workflowState: {}", r.getId()) + .getFormattedMessage(); logger.error(errorMessage, e); listener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST)); } @@ -134,7 +137,8 @@ private void executeGetWorkflowStateRequest( if (e instanceof IndexNotFoundException) { listener.onFailure(new FlowFrameworkException("Fail to find workflow status of " + workflowId, RestStatus.NOT_FOUND)); } else { - String errorMessage = "Failed to get workflow status of: " + workflowId; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Failed to get workflow status of: {}", workflowId) + .getFormattedMessage(); logger.error(errorMessage, e); listener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.NOT_FOUND)); } diff --git a/src/main/java/org/opensearch/flowframework/transport/GetWorkflowStepTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/GetWorkflowStepTransportAction.java index 5994bfe4a..c35fe1ae7 100644 --- a/src/main/java/org/opensearch/flowframework/transport/GetWorkflowStepTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/GetWorkflowStepTransportAction.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.support.ActionFilters; import org.opensearch.action.support.HandledTransportAction; @@ -68,7 +69,8 @@ protected void doExecute(Task task, WorkflowRequest request, ActionListener { listener.onResponse(new WorkflowResponse(request.getWorkflowId())); }, exception -> { - String errorMessage = "Failed to update use case template " + request.getWorkflowId(); + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to update use case template {}", + request.getWorkflowId() + ).getFormattedMessage(); logger.error(errorMessage, exception); if (exception instanceof FlowFrameworkException) { listener.onFailure(exception); @@ -224,7 +234,10 @@ private void executeProvisionRequest( true ); }, exception -> { - String errorMessage = "Failed to update workflow state: " + workflowId; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to update workflow state: {}", + workflowId + ).getFormattedMessage(); logger.error(errorMessage, exception); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(exception))); }) @@ -244,7 +257,10 @@ private void executeProvisionRequest( logger.error("Workflow validation failed for workflow {}", workflowId); listener.onFailure(exception); } else { - String errorMessage = "Failed to retrieve template from global context for workflow " + workflowId; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to retrieve template from global context for workflow {}", + workflowId + ).getFormattedMessage(); logger.error(errorMessage, exception); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(exception))); } diff --git a/src/main/java/org/opensearch/flowframework/transport/SearchWorkflowStateTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/SearchWorkflowStateTransportAction.java index f20c57adb..e68430a14 100644 --- a/src/main/java/org/opensearch/flowframework/transport/SearchWorkflowStateTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/SearchWorkflowStateTransportAction.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.search.SearchRequest; import org.opensearch.action.search.SearchResponse; @@ -48,7 +49,8 @@ protected void doExecute(Task task, SearchRequest request, ActionListener execute( mlInputBuilder.modelInterface(parameters); } catch (Exception ex) { - String errorMessage = "Failed to create model interface"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Failed to create model interface") + .getFormattedMessage(); logger.error(errorMessage, ex); registerLocalModelFuture.onFailure(new WorkflowStepException(errorMessage, RestStatus.BAD_REQUEST)); } @@ -201,7 +203,10 @@ public PlainActionFuture execute( ActionListener deployUpdateListener = ActionListener.wrap( deployUpdateResponse -> registerLocalModelFuture.onResponse(mlTaskWorkflowData), deployUpdateException -> { - String errorMessage = "Failed to update simulated deploy step resource " + id; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to update simulated deploy step resource {}", + id + ).getFormattedMessage(); logger.error(errorMessage, deployUpdateException); registerLocalModelFuture.onFailure( new FlowFrameworkException(errorMessage, ExceptionsHelper.status(deployUpdateException)) @@ -223,7 +228,10 @@ public PlainActionFuture execute( ); }, exception -> { Exception e = getSafeException(exception); - String errorMessage = (e == null ? "Failed to register local model in step " + currentNodeId : e.getMessage()); + String errorMessage = (e == null + ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed to register local model in step {}", currentNodeId) + .getFormattedMessage() + : e.getMessage()); logger.error(errorMessage, e); registerLocalModelFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); })); diff --git a/src/main/java/org/opensearch/flowframework/workflow/CreateConnectorStep.java b/src/main/java/org/opensearch/flowframework/workflow/CreateConnectorStep.java index cd9d2e2ac..91f012ace 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/CreateConnectorStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/CreateConnectorStep.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.support.PlainActionFuture; import org.opensearch.core.action.ActionListener; @@ -97,7 +98,9 @@ public void onResponse(MLCreateConnectorResponse mlCreateConnectorResponse) { @Override public void onFailure(Exception ex) { Exception e = getSafeException(ex); - String errorMessage = (e == null ? "Failed to create connector" : ex.getMessage()); + String errorMessage = (e == null + ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed to create connector").getFormattedMessage() + : ex.getMessage()); logger.error(errorMessage, e); createConnectorFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); } diff --git a/src/main/java/org/opensearch/flowframework/workflow/CreateIndexStep.java b/src/main/java/org/opensearch/flowframework/workflow/CreateIndexStep.java index 3ac82cb7a..4d594b0c5 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/CreateIndexStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/CreateIndexStep.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.admin.indices.create.CreateIndexRequest; import org.opensearch.action.support.PlainActionFuture; @@ -99,7 +100,10 @@ public PlainActionFuture execute( createIndexRequest.source(sourceAsMap, LoggingDeprecationHandler.INSTANCE); } } catch (Exception ex) { - String errorMessage = "Failed to create the index" + indexName + ", _doc is not permitted in mapping"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to create the index {}, _doc is not permitted in mapping", + indexName + ).getFormattedMessage(); logger.error(errorMessage, ex); createIndexFuture.onFailure(new WorkflowStepException(errorMessage, RestStatus.BAD_REQUEST)); } @@ -115,7 +119,9 @@ public PlainActionFuture execute( ); }, ex -> { Exception e = getSafeException(ex); - String errorMessage = (e == null ? "Failed to create the index " + indexName : e.getMessage()); + String errorMessage = (e == null + ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed to create the index {}", indexName).getFormattedMessage() + : e.getMessage()); logger.error(errorMessage, e); createIndexFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); })); diff --git a/src/main/java/org/opensearch/flowframework/workflow/DeleteAgentStep.java b/src/main/java/org/opensearch/flowframework/workflow/DeleteAgentStep.java index b14d2a1bc..41accccf3 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/DeleteAgentStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/DeleteAgentStep.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchStatusException; import org.opensearch.action.delete.DeleteResponse; @@ -98,7 +99,9 @@ public void onFailure(Exception ex) { ) ); } else { - String errorMessage = (e == null ? "Failed to delete agent " + agentId : e.getMessage()); + String errorMessage = (e == null + ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed to delete agent {}", agentId).getFormattedMessage() + : e.getMessage()); logger.error(errorMessage, e); deleteAgentFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); } diff --git a/src/main/java/org/opensearch/flowframework/workflow/DeleteConnectorStep.java b/src/main/java/org/opensearch/flowframework/workflow/DeleteConnectorStep.java index 6a1a5e0c7..bfa10be20 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/DeleteConnectorStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/DeleteConnectorStep.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.delete.DeleteResponse; import org.opensearch.action.support.PlainActionFuture; @@ -85,7 +86,10 @@ public void onResponse(DeleteResponse deleteResponse) { @Override public void onFailure(Exception ex) { Exception e = getSafeException(ex); - String errorMessage = (e == null ? "Failed to delete connector " + connectorId : e.getMessage()); + String errorMessage = (e == null + ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed to delete connector {}", connectorId) + .getFormattedMessage() + : e.getMessage()); logger.error(errorMessage, e); deleteConnectorFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); } diff --git a/src/main/java/org/opensearch/flowframework/workflow/DeleteIndexStep.java b/src/main/java/org/opensearch/flowframework/workflow/DeleteIndexStep.java index 31783c55e..261d061b4 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/DeleteIndexStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/DeleteIndexStep.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.admin.indices.delete.DeleteIndexRequest; import org.opensearch.action.support.PlainActionFuture; @@ -86,7 +87,9 @@ public PlainActionFuture execute( ); }, ex -> { Exception e = getSafeException(ex); - String errorMessage = (e == null ? "Failed to delete the index " + indexName : e.getMessage()); + String errorMessage = (e == null + ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed to delete the index {}", indexName).getFormattedMessage() + : e.getMessage()); logger.error(errorMessage, e); deleteIndexFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); })); diff --git a/src/main/java/org/opensearch/flowframework/workflow/DeleteIngestPipelineStep.java b/src/main/java/org/opensearch/flowframework/workflow/DeleteIngestPipelineStep.java index 473b1655c..674a18f70 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/DeleteIngestPipelineStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/DeleteIngestPipelineStep.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.ingest.DeletePipelineRequest; import org.opensearch.action.support.PlainActionFuture; @@ -86,7 +87,10 @@ public PlainActionFuture execute( ); }, ex -> { Exception e = getSafeException(ex); - String errorMessage = (e == null ? "Failed to delete the ingest pipeline " + pipelineId : e.getMessage()); + String errorMessage = (e == null + ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed to delete the ingest pipeline {}", pipelineId) + .getFormattedMessage() + : e.getMessage()); logger.error(errorMessage, e); deletePipelineFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); })); diff --git a/src/main/java/org/opensearch/flowframework/workflow/DeleteModelStep.java b/src/main/java/org/opensearch/flowframework/workflow/DeleteModelStep.java index 888dc7276..15c5b8c0e 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/DeleteModelStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/DeleteModelStep.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.OpenSearchStatusException; import org.opensearch.action.delete.DeleteResponse; @@ -99,7 +100,9 @@ public void onFailure(Exception ex) { ) ); } else { - String errorMessage = (e == null ? "Failed to delete model " + modelId : e.getMessage()); + String errorMessage = (e == null + ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed to delete model {}", modelId).getFormattedMessage() + : e.getMessage()); logger.error(errorMessage, e); deleteModelFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); } diff --git a/src/main/java/org/opensearch/flowframework/workflow/DeleteSearchPipelineStep.java b/src/main/java/org/opensearch/flowframework/workflow/DeleteSearchPipelineStep.java index a391ef20d..b35cdf525 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/DeleteSearchPipelineStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/DeleteSearchPipelineStep.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.search.DeleteSearchPipelineRequest; import org.opensearch.action.support.PlainActionFuture; @@ -86,7 +87,10 @@ public PlainActionFuture execute( ); }, ex -> { Exception e = getSafeException(ex); - String errorMessage = (e == null ? "Failed to delete the search pipeline " + pipelineId : e.getMessage()); + String errorMessage = (e == null + ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed to delete the search pipeline {}", pipelineId) + .getFormattedMessage() + : e.getMessage()); logger.error(errorMessage, e); deleteSearchPipelineFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); })); diff --git a/src/main/java/org/opensearch/flowframework/workflow/RegisterAgentStep.java b/src/main/java/org/opensearch/flowframework/workflow/RegisterAgentStep.java index 5eed7a864..9671667b3 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/RegisterAgentStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/RegisterAgentStep.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.support.PlainActionFuture; import org.opensearch.common.Nullable; @@ -107,7 +108,9 @@ public void onResponse(MLRegisterAgentResponse mlRegisterAgentResponse) { @Override public void onFailure(Exception ex) { Exception e = getSafeException(ex); - String errorMessage = (e == null ? "Failed to register the agent" : e.getMessage()); + String errorMessage = (e == null + ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed to register the agent").getFormattedMessage() + : e.getMessage()); logger.error(errorMessage, e); registerAgentModelFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); } diff --git a/src/main/java/org/opensearch/flowframework/workflow/RegisterModelGroupStep.java b/src/main/java/org/opensearch/flowframework/workflow/RegisterModelGroupStep.java index 6cc990429..79e78d374 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/RegisterModelGroupStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/RegisterModelGroupStep.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.support.PlainActionFuture; import org.opensearch.core.action.ActionListener; @@ -95,7 +96,9 @@ public void onResponse(MLRegisterModelGroupResponse mlRegisterModelGroupResponse @Override public void onFailure(Exception ex) { Exception e = getSafeException(ex); - String errorMessage = (e == null ? "Failed to register model group" : e.getMessage()); + String errorMessage = (e == null + ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed to register model group").getFormattedMessage() + : e.getMessage()); logger.error(errorMessage, e); registerModelGroupFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); } diff --git a/src/main/java/org/opensearch/flowframework/workflow/RegisterRemoteModelStep.java b/src/main/java/org/opensearch/flowframework/workflow/RegisterRemoteModelStep.java index 72b56ab79..02b5e1158 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/RegisterRemoteModelStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/RegisterRemoteModelStep.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.support.PlainActionFuture; import org.opensearch.common.xcontent.XContentHelper; @@ -132,7 +133,8 @@ public PlainActionFuture execute( builder.modelInterface(parameters); } catch (Exception ex) { - String errorMessage = "Failed to create model interface"; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Failed to create model interface") + .getFormattedMessage(); logger.error(errorMessage, ex); registerRemoteModelFuture.onFailure(new WorkflowStepException(errorMessage, RestStatus.BAD_REQUEST)); } @@ -209,7 +211,9 @@ private void completeRegisterFutureExceptionally(String errorMessage, Exception @Override public void onFailure(Exception ex) { Exception e = getSafeException(ex); - String errorMessage = (e == null ? "Failed to register remote model" : e.getMessage()); + String errorMessage = (e == null + ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed to register remote model").getFormattedMessage() + : e.getMessage()); logger.error(errorMessage, e); registerRemoteModelFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); } diff --git a/src/main/java/org/opensearch/flowframework/workflow/UpdateIndexStep.java b/src/main/java/org/opensearch/flowframework/workflow/UpdateIndexStep.java index 719ef7237..727eb31a6 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/UpdateIndexStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/UpdateIndexStep.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.admin.indices.settings.get.GetSettingsRequest; import org.opensearch.action.admin.indices.settings.put.UpdateSettingsRequest; @@ -155,7 +156,10 @@ public PlainActionFuture execute( }, ex -> { Exception e = getSafeException(ex); String errorMessage = (e == null - ? "Failed to update the index settings for index " + indexName + ? ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to update the index settings for index {}", + indexName + ).getFormattedMessage() : e.getMessage()); logger.error(errorMessage, e); updateIndexFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); @@ -163,7 +167,12 @@ public PlainActionFuture execute( } }, ex -> { Exception e = getSafeException(ex); - String errorMessage = (e == null ? "Failed to retrieve the index settings for index " + indexName : e.getMessage()); + String errorMessage = (e == null + ? ParameterizedMessageFactory.INSTANCE.newMessage( + "Failed to retrieve the index settings for index {}", + indexName + ).getFormattedMessage() + : e.getMessage()); logger.error(errorMessage, e); updateIndexFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); })); diff --git a/src/main/java/org/opensearch/flowframework/workflow/WorkflowStepFactory.java b/src/main/java/org/opensearch/flowframework/workflow/WorkflowStepFactory.java index 65e8dea78..a63c187d7 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/WorkflowStepFactory.java +++ b/src/main/java/org/opensearch/flowframework/workflow/WorkflowStepFactory.java @@ -10,6 +10,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.client.Client; import org.opensearch.common.unit.TimeValue; import org.opensearch.core.common.Strings; @@ -371,7 +372,10 @@ public static TimeValue getTimeoutByWorkflowType(String workflowStep) throws Flo } } } - String errorMessage = "Unable to find workflow timeout for step: " + workflowStep; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Unable to find workflow timeout for step: {}", + workflowStep + ).getFormattedMessage(); logger.error(errorMessage); throw new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST); } @@ -390,7 +394,10 @@ public static List getRequiredPluginsByWorkflowType(String workflowStep) } } } - String errorMessage = "Unable to find workflow required plugins for step: " + workflowStep; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Unable to find workflow required plugins for step: {}", + workflowStep + ).getFormattedMessage(); logger.error(errorMessage); throw new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST); } @@ -409,7 +416,10 @@ public static List getOutputByWorkflowType(String workflowStep) throws F } } } - String errorMessage = "Unable to find workflow output for step " + workflowStep; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Unable to find workflow output for step {}", + workflowStep + ).getFormattedMessage(); logger.error(errorMessage); throw new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST); } @@ -428,7 +438,10 @@ public static List getInputByWorkflowType(String workflowStep) throws Fl } } } - String errorMessage = "Unable to find workflow input for step: " + workflowStep; + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "Unable to find workflow input for step: {}", + workflowStep + ).getFormattedMessage(); logger.error(errorMessage); throw new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST); } From 7419752d279b9bc8163a8b534f67f41a2c5ac983 Mon Sep 17 00:00:00 2001 From: Patrik Cmil Date: Wed, 6 Nov 2024 20:45:10 +0100 Subject: [PATCH 5/7] Changed back strings, which were not be parametrized Signed-off-by: Patrik Cmil --- .../indices/FlowFrameworkIndicesHandler.java | 17 +++++---------- .../rest/RestCreateWorkflowAction.java | 10 +++------ .../rest/RestDeleteWorkflowAction.java | 5 +---- .../rest/RestDeprovisionWorkflowAction.java | 5 +---- .../rest/RestGetWorkflowAction.java | 5 +---- .../rest/RestGetWorkflowStateAction.java | 5 +---- .../rest/RestGetWorkflowStepAction.java | 5 +---- .../rest/RestProvisionWorkflowAction.java | 5 +---- .../CreateWorkflowTransportAction.java | 21 ++++++------------- .../DeleteWorkflowTransportAction.java | 4 +--- .../DeprovisionWorkflowTransportAction.java | 3 +-- .../GetWorkflowStepTransportAction.java | 4 +--- .../transport/GetWorkflowTransportAction.java | 3 +-- .../SearchWorkflowStateTransportAction.java | 4 +--- .../SearchWorkflowTransportAction.java | 4 +--- .../flowframework/util/ParseUtils.java | 3 +-- .../AbstractRegisterLocalModelStep.java | 3 +-- .../workflow/CreateConnectorStep.java | 5 +---- .../workflow/RegisterAgentStep.java | 5 +---- .../workflow/RegisterModelGroupStep.java | 5 +---- .../workflow/RegisterRemoteModelStep.java | 8 ++----- .../flowframework/workflow/ReindexStep.java | 4 +--- 22 files changed, 34 insertions(+), 99 deletions(-) diff --git a/src/main/java/org/opensearch/flowframework/indices/FlowFrameworkIndicesHandler.java b/src/main/java/org/opensearch/flowframework/indices/FlowFrameworkIndicesHandler.java index 2db99f040..0ef0a7adb 100644 --- a/src/main/java/org/opensearch/flowframework/indices/FlowFrameworkIndicesHandler.java +++ b/src/main/java/org/opensearch/flowframework/indices/FlowFrameworkIndicesHandler.java @@ -342,8 +342,7 @@ public void putTemplateToGlobalContext(Template template, ActionListener { - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Failed to create workflow_state index") - .getFormattedMessage(); + String errorMessage = "Failed to create workflow_state index"; logger.error(errorMessage, e); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); })); @@ -551,9 +548,7 @@ public void getProvisioningProgress( provisioningProgressConsumer.accept(Optional.empty()); })); } catch (Exception e) { - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( - "Failed to retrieve workflow state to check provisioning status" - ).getFormattedMessage(); + String errorMessage = "Failed to retrieve workflow state to check provisioning status"; logger.error(errorMessage, e); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); } @@ -606,9 +601,7 @@ public void canDeleteWorkflowStateDoc( canDeleteStateConsumer.accept(Boolean.FALSE); })); } catch (Exception e) { - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( - "Failed to retrieve workflow state to check provisioning status" - ).getFormattedMessage(); + String errorMessage = "Failed to retrieve workflow state to check provisioning status"; logger.error(errorMessage, e); listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); } diff --git a/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java b/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java index b4850152a..8acfab16a 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java @@ -10,7 +10,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.client.node.NodeClient; import org.opensearch.core.action.ActionListener; @@ -194,9 +193,8 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli throw ex; } else { RestStatus status = ex instanceof IOException ? RestStatus.BAD_REQUEST : ExceptionsHelper.status(ex); - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( - "failure parsing request body when a use case is given, make sure to provide a map with values that are either Strings, Arrays, or Map of Strings to Strings" - ).getFormattedMessage(); + String errorMessage = + "failure parsing request body when a use case is given, make sure to provide a map with values that are either Strings, Arrays, or Map of Strings to Strings"; logger.error(errorMessage, ex); throw new FlowFrameworkException(errorMessage, status); } @@ -244,9 +242,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli XContentBuilder exceptionBuilder = ex.toXContent(channel.newErrorBuilder(), ToXContent.EMPTY_PARAMS); channel.sendResponse(new BytesRestResponse(ex.getRestStatus(), exceptionBuilder)); } catch (IOException e) { - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( - "IOException: Failed to send back create workflow exception" - ).getFormattedMessage(); + String errorMessage = "IOException: Failed to send back create workflow exception"; logger.error(errorMessage, e); channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage)); } diff --git a/src/main/java/org/opensearch/flowframework/rest/RestDeleteWorkflowAction.java b/src/main/java/org/opensearch/flowframework/rest/RestDeleteWorkflowAction.java index 4062ba47f..ebef48c86 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestDeleteWorkflowAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestDeleteWorkflowAction.java @@ -10,7 +10,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.client.node.NodeClient; import org.opensearch.core.action.ActionListener; @@ -93,9 +92,7 @@ protected BaseRestHandler.RestChannelConsumer prepareRequest(RestRequest request XContentBuilder exceptionBuilder = ex.toXContent(channel.newErrorBuilder(), ToXContent.EMPTY_PARAMS); channel.sendResponse(new BytesRestResponse(ex.getRestStatus(), exceptionBuilder)); } catch (IOException e) { - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( - "IOException: Failed to send back delete workflow exception" - ).getFormattedMessage(); + String errorMessage = "IOException: Failed to send back delete workflow exception"; logger.error(errorMessage, e); channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage)); } diff --git a/src/main/java/org/opensearch/flowframework/rest/RestDeprovisionWorkflowAction.java b/src/main/java/org/opensearch/flowframework/rest/RestDeprovisionWorkflowAction.java index 7f75c8980..d75255b8d 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestDeprovisionWorkflowAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestDeprovisionWorkflowAction.java @@ -10,7 +10,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.client.node.NodeClient; import org.opensearch.core.action.ActionListener; @@ -95,9 +94,7 @@ protected BaseRestHandler.RestChannelConsumer prepareRequest(RestRequest request XContentBuilder exceptionBuilder = ex.toXContent(channel.newErrorBuilder(), ToXContent.EMPTY_PARAMS); channel.sendResponse(new BytesRestResponse(ex.getRestStatus(), exceptionBuilder)); } catch (IOException e) { - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( - "IOException: Failed to send back deprovision workflow exception" - ).getFormattedMessage(); + String errorMessage = "IOException: Failed to send back deprovision workflow exception"; logger.error(errorMessage, e); channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage)); } diff --git a/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowAction.java b/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowAction.java index cbfaea94d..81141a380 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowAction.java @@ -10,7 +10,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.client.node.NodeClient; import org.opensearch.core.action.ActionListener; @@ -92,9 +91,7 @@ protected BaseRestHandler.RestChannelConsumer prepareRequest(RestRequest request XContentBuilder exceptionBuilder = ex.toXContent(channel.newErrorBuilder(), ToXContent.EMPTY_PARAMS); channel.sendResponse(new BytesRestResponse(ex.getRestStatus(), exceptionBuilder)); } catch (IOException e) { - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( - "IOException: Failed to send back get workflow exception" - ).getFormattedMessage(); + String errorMessage = "IOException: Failed to send back get workflow exception"; logger.error(errorMessage, e); channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage)); } diff --git a/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStateAction.java b/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStateAction.java index 2d9a57fb1..bdf4df35f 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStateAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStateAction.java @@ -10,7 +10,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.client.node.NodeClient; import org.opensearch.core.action.ActionListener; @@ -88,9 +87,7 @@ protected BaseRestHandler.RestChannelConsumer prepareRequest(RestRequest request XContentBuilder exceptionBuilder = ex.toXContent(channel.newErrorBuilder(), ToXContent.EMPTY_PARAMS); channel.sendResponse(new BytesRestResponse(ex.getRestStatus(), exceptionBuilder)); } catch (IOException e) { - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( - "IOException: Failed to send back get workflow state exception" - ).getFormattedMessage(); + String errorMessage = "IOException: Failed to send back get workflow state exception"; logger.error(errorMessage, e); channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage)); } diff --git a/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStepAction.java b/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStepAction.java index d0b98765b..b889cede7 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStepAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStepAction.java @@ -10,7 +10,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.client.node.NodeClient; import org.opensearch.core.action.ActionListener; @@ -92,9 +91,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli XContentBuilder exceptionBuilder = ex.toXContent(channel.newErrorBuilder(), ToXContent.EMPTY_PARAMS); channel.sendResponse(new BytesRestResponse(ex.getRestStatus(), exceptionBuilder)); } catch (IOException e) { - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( - "IOException: Failed to send back get workflow step exception" - ).getFormattedMessage(); + String errorMessage = "IOException: Failed to send back get workflow step exception"; logger.error(errorMessage, e); channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage)); } diff --git a/src/main/java/org/opensearch/flowframework/rest/RestProvisionWorkflowAction.java b/src/main/java/org/opensearch/flowframework/rest/RestProvisionWorkflowAction.java index 20e8d5979..6ae56905c 100644 --- a/src/main/java/org/opensearch/flowframework/rest/RestProvisionWorkflowAction.java +++ b/src/main/java/org/opensearch/flowframework/rest/RestProvisionWorkflowAction.java @@ -10,7 +10,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.client.node.NodeClient; import org.opensearch.core.action.ActionListener; @@ -99,9 +98,7 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli XContentBuilder exceptionBuilder = ex.toXContent(channel.newErrorBuilder(), ToXContent.EMPTY_PARAMS); channel.sendResponse(new BytesRestResponse(ex.getRestStatus(), exceptionBuilder)); } catch (IOException e) { - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( - "IOException: Failed to send back provision workflow exception" - ).getFormattedMessage(); + String errorMessage = "IOException: Failed to send back provision workflow exception"; logger.error(errorMessage, e); channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage)); } diff --git a/src/main/java/org/opensearch/flowframework/transport/CreateWorkflowTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/CreateWorkflowTransportAction.java index 47bfe9323..813613a32 100644 --- a/src/main/java/org/opensearch/flowframework/transport/CreateWorkflowTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/CreateWorkflowTransportAction.java @@ -263,9 +263,7 @@ private void createExecute(WorkflowRequest request, User user, ActionListener { listener.onResponse(new WorkflowResponse(provisionResponse.getWorkflowId())); }, exception -> { - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( - "Provisioning failed." - ).getFormattedMessage(); + String errorMessage = "Provisioning failed."; logger.error(errorMessage, exception); if (exception instanceof FlowFrameworkException) { listener.onFailure(exception); @@ -283,9 +281,7 @@ private void createExecute(WorkflowRequest request, User user, ActionListener { - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( - "Failed to save workflow state" - ).getFormattedMessage(); + String errorMessage = "Failed to save workflow state"; logger.error(errorMessage, exception); if (exception instanceof FlowFrameworkException) { listener.onFailure(exception); @@ -295,9 +291,7 @@ private void createExecute(WorkflowRequest request, User user, ActionListener { - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( - "Failed to save use case template" - ).getFormattedMessage(); + String errorMessage = "Failed to save use case template"; logger.error(errorMessage, exception); if (exception instanceof FlowFrameworkException) { listener.onFailure(exception); @@ -310,8 +304,7 @@ private void createExecute(WorkflowRequest request, User user, ActionListener { - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Failed to initialize config index") - .getFormattedMessage(); + String errorMessage = "Failed to initialize config index"; logger.error(errorMessage, exception); if (exception instanceof FlowFrameworkException) { listener.onFailure(exception); @@ -474,14 +467,12 @@ void checkMaxWorkflows(TimeValue requestTimeOut, Integer maxWorkflow, ActionList context.restore(); internalListener.onResponse(searchResponse.getHits().getTotalHits().value < maxWorkflow); }, exception -> { - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Unable to fetch the workflows") - .getFormattedMessage(); + String errorMessage = "Unable to fetch the workflows"; logger.error(errorMessage, exception); internalListener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(exception))); })); } catch (Exception e) { - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Unable to fetch the workflows") - .getFormattedMessage(); + String errorMessage = "Unable to fetch the workflows"; logger.error(errorMessage, e); internalListener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); } diff --git a/src/main/java/org/opensearch/flowframework/transport/DeleteWorkflowTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/DeleteWorkflowTransportAction.java index 7ba767979..2974f522f 100644 --- a/src/main/java/org/opensearch/flowframework/transport/DeleteWorkflowTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/DeleteWorkflowTransportAction.java @@ -11,7 +11,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.core.util.Booleans; -import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.action.delete.DeleteRequest; import org.opensearch.action.delete.DeleteResponse; import org.opensearch.action.support.ActionFilters; @@ -98,8 +97,7 @@ protected void doExecute(Task task, WorkflowRequest request, ActionListener execute( mlInputBuilder.modelInterface(parameters); } catch (Exception ex) { - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Failed to create model interface") - .getFormattedMessage(); + String errorMessage = "Failed to create model interface"; logger.error(errorMessage, ex); registerLocalModelFuture.onFailure(new WorkflowStepException(errorMessage, RestStatus.BAD_REQUEST)); } diff --git a/src/main/java/org/opensearch/flowframework/workflow/CreateConnectorStep.java b/src/main/java/org/opensearch/flowframework/workflow/CreateConnectorStep.java index 91f012ace..cd9d2e2ac 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/CreateConnectorStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/CreateConnectorStep.java @@ -10,7 +10,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.support.PlainActionFuture; import org.opensearch.core.action.ActionListener; @@ -98,9 +97,7 @@ public void onResponse(MLCreateConnectorResponse mlCreateConnectorResponse) { @Override public void onFailure(Exception ex) { Exception e = getSafeException(ex); - String errorMessage = (e == null - ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed to create connector").getFormattedMessage() - : ex.getMessage()); + String errorMessage = (e == null ? "Failed to create connector" : ex.getMessage()); logger.error(errorMessage, e); createConnectorFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); } diff --git a/src/main/java/org/opensearch/flowframework/workflow/RegisterAgentStep.java b/src/main/java/org/opensearch/flowframework/workflow/RegisterAgentStep.java index 9671667b3..5eed7a864 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/RegisterAgentStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/RegisterAgentStep.java @@ -10,7 +10,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.support.PlainActionFuture; import org.opensearch.common.Nullable; @@ -108,9 +107,7 @@ public void onResponse(MLRegisterAgentResponse mlRegisterAgentResponse) { @Override public void onFailure(Exception ex) { Exception e = getSafeException(ex); - String errorMessage = (e == null - ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed to register the agent").getFormattedMessage() - : e.getMessage()); + String errorMessage = (e == null ? "Failed to register the agent" : e.getMessage()); logger.error(errorMessage, e); registerAgentModelFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); } diff --git a/src/main/java/org/opensearch/flowframework/workflow/RegisterModelGroupStep.java b/src/main/java/org/opensearch/flowframework/workflow/RegisterModelGroupStep.java index 79e78d374..6cc990429 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/RegisterModelGroupStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/RegisterModelGroupStep.java @@ -10,7 +10,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.support.PlainActionFuture; import org.opensearch.core.action.ActionListener; @@ -96,9 +95,7 @@ public void onResponse(MLRegisterModelGroupResponse mlRegisterModelGroupResponse @Override public void onFailure(Exception ex) { Exception e = getSafeException(ex); - String errorMessage = (e == null - ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed to register model group").getFormattedMessage() - : e.getMessage()); + String errorMessage = (e == null ? "Failed to register model group" : e.getMessage()); logger.error(errorMessage, e); registerModelGroupFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); } diff --git a/src/main/java/org/opensearch/flowframework/workflow/RegisterRemoteModelStep.java b/src/main/java/org/opensearch/flowframework/workflow/RegisterRemoteModelStep.java index 02b5e1158..72b56ab79 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/RegisterRemoteModelStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/RegisterRemoteModelStep.java @@ -10,7 +10,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.opensearch.ExceptionsHelper; import org.opensearch.action.support.PlainActionFuture; import org.opensearch.common.xcontent.XContentHelper; @@ -133,8 +132,7 @@ public PlainActionFuture execute( builder.modelInterface(parameters); } catch (Exception ex) { - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("Failed to create model interface") - .getFormattedMessage(); + String errorMessage = "Failed to create model interface"; logger.error(errorMessage, ex); registerRemoteModelFuture.onFailure(new WorkflowStepException(errorMessage, RestStatus.BAD_REQUEST)); } @@ -211,9 +209,7 @@ private void completeRegisterFutureExceptionally(String errorMessage, Exception @Override public void onFailure(Exception ex) { Exception e = getSafeException(ex); - String errorMessage = (e == null - ? ParameterizedMessageFactory.INSTANCE.newMessage("Failed to register remote model").getFormattedMessage() - : e.getMessage()); + String errorMessage = (e == null ? "Failed to register remote model" : e.getMessage()); logger.error(errorMessage, e); registerRemoteModelFuture.onFailure(new WorkflowStepException(errorMessage, ExceptionsHelper.status(e))); } diff --git a/src/main/java/org/opensearch/flowframework/workflow/ReindexStep.java b/src/main/java/org/opensearch/flowframework/workflow/ReindexStep.java index c4427e049..a733f63e3 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/ReindexStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/ReindexStep.java @@ -151,9 +151,7 @@ public void onResponse(BulkByScrollResponse bulkByScrollResponse) { reIndexFuture.onFailure(new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST)); } } catch (Exception e) { - String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( - "Failed to parse and update new created resource" - ).getFormattedMessage(); + String errorMessage = "Failed to parse and update new created resource"; logger.error(errorMessage, e); reIndexFuture.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e))); } From 5b840493f64b848264c6615df82e365ea618c399 Mon Sep 17 00:00:00 2001 From: Patrik Cmil Date: Thu, 7 Nov 2024 22:08:48 +0100 Subject: [PATCH 6/7] Update CHANGELOG.md Signed-off-by: Patrik Cmil --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85afee43f..97db1586a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,3 +22,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) ### Documentation ### Maintenance ### Refactoring +- Replace String concatenation with Log4j ParameterizedMessage for readability ([#943](https://github.com/opensearch-project/flow-framework/pull/943)) \ No newline at end of file From 91fd142975d96f6d635571d42bfe8d3539598756 Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Thu, 7 Nov 2024 18:35:16 -0800 Subject: [PATCH 7/7] Add EOF line break Signed-off-by: Daniel Widdis --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97db1586a..a08001273 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,4 +22,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) ### Documentation ### Maintenance ### Refactoring -- Replace String concatenation with Log4j ParameterizedMessage for readability ([#943](https://github.com/opensearch-project/flow-framework/pull/943)) \ No newline at end of file +- Replace String concatenation with Log4j ParameterizedMessage for readability ([#943](https://github.com/opensearch-project/flow-framework/pull/943))