Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace String concatenation with Log4j ParameterizedMessage for readability #943

Merged
merged 11 commits into from
Nov 11, 2024

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -171,7 +172,10 @@
String configurationsString = ParseUtils.parseArbitraryStringToObjectMapToString(configurationsMap);
userInputs.put(inputFieldName, configurationsString);
} catch (Exception ex) {
String errorMessage = "Failed to parse" + inputFieldName + "map";
String errorMessage = ParameterizedMessageFactory.INSTANCE.newMessage(

Check warning on line 175 in src/main/java/org/opensearch/flowframework/model/WorkflowNode.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/model/WorkflowNode.java#L175

Added line #L175 was not covered by tests
"Failed to parse {} map",
inputFieldName
).getFormattedMessage();

Check warning on line 178 in src/main/java/org/opensearch/flowframework/model/WorkflowNode.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/model/WorkflowNode.java#L178

Added line #L178 was not covered by tests
logger.error(errorMessage, ex);
throw new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -193,8 +194,9 @@
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(

Check warning on line 197 in src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java#L197

Added line #L197 was not covered by tests
"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();

Check warning on line 199 in src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java#L199

Added line #L199 was not covered by tests
logger.error(errorMessage, ex);
throw new FlowFrameworkException(errorMessage, status);
}
Expand Down Expand Up @@ -242,7 +244,9 @@
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(

Check warning on line 247 in src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java#L247

Added line #L247 was not covered by tests
"IOException: Failed to send back create workflow exception"
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
).getFormattedMessage();

Check warning on line 249 in src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/rest/RestCreateWorkflowAction.java#L249

Added line #L249 was not covered by tests
logger.error(errorMessage, e);
channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,7 +93,9 @@
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(

Check warning on line 96 in src/main/java/org/opensearch/flowframework/rest/RestDeleteWorkflowAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/rest/RestDeleteWorkflowAction.java#L96

Added line #L96 was not covered by tests
"IOException: Failed to send back delete workflow exception"
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
).getFormattedMessage();

Check warning on line 98 in src/main/java/org/opensearch/flowframework/rest/RestDeleteWorkflowAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/rest/RestDeleteWorkflowAction.java#L98

Added line #L98 was not covered by tests
logger.error(errorMessage, e);
channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,7 +95,9 @@
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(

Check warning on line 98 in src/main/java/org/opensearch/flowframework/rest/RestDeprovisionWorkflowAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/rest/RestDeprovisionWorkflowAction.java#L98

Added line #L98 was not covered by tests
"IOException: Failed to send back deprovision workflow exception"
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
).getFormattedMessage();

Check warning on line 100 in src/main/java/org/opensearch/flowframework/rest/RestDeprovisionWorkflowAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/rest/RestDeprovisionWorkflowAction.java#L100

Added line #L100 was not covered by tests
logger.error(errorMessage, e);
channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,7 +92,9 @@
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(

Check warning on line 95 in src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowAction.java#L95

Added line #L95 was not covered by tests
"IOException: Failed to send back get workflow exception"
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
).getFormattedMessage();

Check warning on line 97 in src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowAction.java#L97

Added line #L97 was not covered by tests
logger.error(errorMessage, e);
channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,7 +88,9 @@
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(

Check warning on line 91 in src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStateAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStateAction.java#L91

Added line #L91 was not covered by tests
"IOException: Failed to send back get workflow state exception"
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
).getFormattedMessage();

Check warning on line 93 in src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStateAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStateAction.java#L93

Added line #L93 was not covered by tests
logger.error(errorMessage, e);
channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,7 +92,9 @@
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(

Check warning on line 95 in src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStepAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStepAction.java#L95

Added line #L95 was not covered by tests
"IOException: Failed to send back get workflow step exception"
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
).getFormattedMessage();

Check warning on line 97 in src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStepAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/rest/RestGetWorkflowStepAction.java#L97

Added line #L97 was not covered by tests
logger.error(errorMessage, e);
channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -98,7 +99,9 @@
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(

Check warning on line 102 in src/main/java/org/opensearch/flowframework/rest/RestProvisionWorkflowAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/rest/RestProvisionWorkflowAction.java#L102

Added line #L102 was not covered by tests
"IOException: Failed to send back provision workflow exception"
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
).getFormattedMessage();

Check warning on line 104 in src/main/java/org/opensearch/flowframework/rest/RestProvisionWorkflowAction.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/rest/RestProvisionWorkflowAction.java#L104

Added line #L104 was not covered by tests
logger.error(errorMessage, e);
channel.sendResponse(new BytesRestResponse(ExceptionsHelper.status(e), errorMessage));
}
Expand Down
Loading
Loading