diff --git a/CHANGELOG.md b/CHANGELOG.md index a34163339..7b1f657e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,3 +24,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)) diff --git a/src/main/java/org/opensearch/flowframework/indices/FlowFrameworkIndicesHandler.java b/src/main/java/org/opensearch/flowframework/indices/FlowFrameworkIndicesHandler.java index f05a162ff..0ef0a7adb 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))); } @@ -424,7 +435,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 +457,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 +495,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 +538,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)); } @@ -566,7 +590,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)); } @@ -593,7 +619,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 +636,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 +659,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 +676,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 +694,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 +707,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 +737,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 +765,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/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/CreateWorkflowTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/CreateWorkflowTransportAction.java index 72b2e8a12..813613a32 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); @@ -307,7 +314,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 +360,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 +395,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 +413,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 +428,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))); })); diff --git a/src/main/java/org/opensearch/flowframework/transport/DeprovisionWorkflowTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/DeprovisionWorkflowTransportAction.java index 2b8db025c..9699de5a4 100644 --- a/src/main/java/org/opensearch/flowframework/transport/DeprovisionWorkflowTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/DeprovisionWorkflowTransportAction.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.support.ActionFilters; @@ -166,7 +167,10 @@ private void executeDeprovisionRequest( ) ); }, exception -> { - 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/GetWorkflowTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/GetWorkflowTransportAction.java index 59b129baf..58d37edf0 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,7 +105,10 @@ 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))); })); diff --git a/src/main/java/org/opensearch/flowframework/transport/ProvisionWorkflowTransportAction.java b/src/main/java/org/opensearch/flowframework/transport/ProvisionWorkflowTransportAction.java index 1457cdb8e..45f374161 100644 --- a/src/main/java/org/opensearch/flowframework/transport/ProvisionWorkflowTransportAction.java +++ b/src/main/java/org/opensearch/flowframework/transport/ProvisionWorkflowTransportAction.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; @@ -138,7 +139,10 @@ 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/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/util/ParseUtils.java b/src/main/java/org/opensearch/flowframework/util/ParseUtils.java index cd598aa91..154e343fa 100644 --- a/src/main/java/org/opensearch/flowframework/util/ParseUtils.java +++ b/src/main/java/org/opensearch/flowframework/util/ParseUtils.java @@ -12,6 +12,7 @@ import com.google.gson.JsonParser; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.message.ParameterizedMessageFactory; import org.apache.lucene.search.join.ScoreMode; import org.opensearch.action.get.GetRequest; import org.opensearch.action.get.GetResponse; @@ -406,7 +407,10 @@ public static void getWorkflow( ); } } else { - 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); listener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.NOT_FOUND)); } @@ -455,7 +459,10 @@ public static void onGetWorkflowResponse( listener.onFailure(e); } } else { - 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); listener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.NOT_FOUND)); } 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/AbstractRegisterLocalModelStep.java b/src/main/java/org/opensearch/flowframework/workflow/AbstractRegisterLocalModelStep.java index 3f6d19219..4317c0087 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/AbstractRegisterLocalModelStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/AbstractRegisterLocalModelStep.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; @@ -201,7 +202,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 +227,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/AbstractRetryableWorkflowStep.java b/src/main/java/org/opensearch/flowframework/workflow/AbstractRetryableWorkflowStep.java index 3e6dc9a85..bf6585dc8 100644 --- a/src/main/java/org/opensearch/flowframework/workflow/AbstractRetryableWorkflowStep.java +++ b/src/main/java/org/opensearch/flowframework/workflow/AbstractRetryableWorkflowStep.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.action.support.PlainActionFuture; import org.opensearch.common.unit.TimeValue; import org.opensearch.common.util.concurrent.FutureUtils; @@ -94,12 +95,17 @@ protected void retryableGetMlTask( break; case FAILED: case COMPLETED_WITH_ERROR: - String errorMessage = workflowStep + " failed with error : " + response.getError(); + String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage( + "{} failed with error : {}", + workflowStep, + response.getError() + ).getFormattedMessage(); logger.error(errorMessage); mlTaskListener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST)); break; case CANCELLED: - errorMessage = workflowStep + " task was cancelled."; + errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage("{} task was cancelled.", workflowStep) + .getFormattedMessage(); logger.error(errorMessage); mlTaskListener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.REQUEST_TIMEOUT)); break; @@ -107,7 +113,7 @@ protected void retryableGetMlTask( // Task started or running, do nothing } }, exception -> { - 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/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/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/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..a733f63e3 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; @@ -158,7 +159,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))); } 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))); } 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); }