Skip to content

Commit

Permalink
verify workflow through post api call (#563)
Browse files Browse the repository at this point in the history
Signed-off-by: jowg-amazon <[email protected]>
(cherry picked from commit 773b5c9)
  • Loading branch information
jowg-amazon authored and github-actions[bot] committed Sep 13, 2023
1 parent 0b4bc08 commit 5d5bb96
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,14 @@ protected Map<String, Object> searchWorkflow(String workflowId) throws IOExcepti
" }\n" +
" }\n" +
"}";
List<SearchHit> hits = executeSearch(ScheduledJob.SCHEDULED_JOBS_INDEX, workflowRequest);
List<SearchHit> hits = executeWorkflowSearch("/_plugins/_alerting/monitors", workflowRequest);

if (hits.size() == 0) {
return new HashMap<>();
}

SearchHit hit = hits.get(0);
return (Map<String, Object>) hit.getSourceAsMap().get("workflow");
return (Map<String, Object>) hit.getSourceAsMap();
}


Expand Down Expand Up @@ -412,6 +413,16 @@ protected List<SearchHit> executeSearch(String index, String request, Boolean re
return Arrays.asList(searchResponse.getHits().getHits());
}

protected List<SearchHit> executeWorkflowSearch(String url, String request) throws IOException {

Response response = makeRequest(client(), "POST", String.format(Locale.getDefault(), "%s/_search", url), Collections.emptyMap(), new StringEntity(request), new BasicHeader("Content-Type", "application/json"));
Assert.assertEquals("Workflow search failed", RestStatus.OK, restStatus(response));

SearchResponse searchResponse = SearchResponse.fromXContent(createParser(JsonXContent.jsonXContent, response.getEntity().getContent()));

return Arrays.asList(searchResponse.getHits().getHits());
}

protected SearchResponse executeSearchAndGetResponse(String index, String request, Boolean refresh) throws IOException {
if (refresh) {
refreshIndex(index);
Expand Down

0 comments on commit 5d5bb96

Please sign in to comment.