Skip to content

Commit

Permalink
fixing test and enhancing error message
Browse files Browse the repository at this point in the history
Signed-off-by: Amit Galitzky <[email protected]>
  • Loading branch information
amitgalitz committed Mar 20, 2024
1 parent ce78f8f commit 583ec86
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli
}
} catch (Exception ex) {
RestStatus status = ex instanceof IOException ? RestStatus.BAD_REQUEST : ExceptionsHelper.status(ex);
String errorMessage = "failure parsing request body when a use case is given";
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ public static Map<String, String> parseJsonFileToStringToStringMap(String path)
* Takes an input string, then checks if there is an array in the string with backslashes around strings
* (e.g. "[\"text\", \"hello\"]" to "["text", "hello"]"), this is needed for processors that take in string arrays,
* This also removes the quotations around the array making the array valid to consume
* (e.g. "weights": "[0.7, 0.3]" -> "weights": [0.7, 0.3])
* (e.g. "weights": "[0.7, 0.3]" to "weights": [0.7, 0.3])
* @param input The inputString given to be transformed
* @return the transformed string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,19 @@ public PlainActionFuture<WorkflowData> execute(
byte[] byteArr = configurations.getBytes(StandardCharsets.UTF_8);
BytesReference configurationsBytes = new BytesArray(byteArr);
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
if (!configurations.isEmpty()) {
Map<String, Object> sourceAsMap = XContentHelper.convertToMap(configurationsBytes, false, MediaTypeRegistry.JSON).v2();
sourceAsMap = prepareMappings(sourceAsMap);
createIndexRequest.source(sourceAsMap, LoggingDeprecationHandler.INSTANCE);

try {
if (!configurations.isEmpty()) {
Map<String, Object> sourceAsMap = XContentHelper.convertToMap(configurationsBytes, false, MediaTypeRegistry.JSON).v2();
sourceAsMap = prepareMappings(sourceAsMap);
createIndexRequest.source(sourceAsMap, LoggingDeprecationHandler.INSTANCE);
}
} catch (Exception ex) {
String errorMessage = "Failed to create the index"
+ indexName
+ " due to incorrect mapping, make sure you aren't providing _doc in mapping";
logger.error(errorMessage, ex);
createIndexFuture.onFailure(new WorkflowStepException(errorMessage, RestStatus.BAD_REQUEST));
}

client.admin().indices().create(createIndexRequest, ActionListener.wrap(acknowledgedResponse -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ public void setUp() throws Exception {
this.flowFrameworkIndicesHandler = mock(FlowFrameworkIndicesHandler.class);
MockitoAnnotations.openMocks(this);
String configurations =
"{\"settings\":{\"index\":{\"number_of_shards\":2,\"number_of_replicas\":1}},\"mappings\":{\"_doc\":{\"properties\":{\"age\":{\"type\":\"integer\"}}}},\"aliases\":{\"sample-alias1\":{}}}";

"{\"settings\":{\"index\":{\"number_of_shards\":2,\"number_of_replicas\":1}},\"mappings\":{\"properties\":{\"age\":{\"type\":\"integer\"}}},\"aliases\":{\"sample-alias1\":{}}}";
inputData = new WorkflowData(
Map.ofEntries(Map.entry(INDEX_NAME, "demo"), Map.entry(CONFIGURATIONS, configurations)),
"test-id",
Expand Down

0 comments on commit 583ec86

Please sign in to comment.