-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
HLRC support for getTask #35166
HLRC support for getTask #35166
Conversation
Pinging @elastic/es-core-infra |
c5ec7ea
to
b3d2af0
Compare
this.nodeId = nodeId; | ||
this.taskId = taskId; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some redundant empty lines here, can we remove them?
public static GetTaskResponse fromXContent(XContentParser parser) { | ||
return PARSER.apply(parser, null); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some minor new lines formatting would be nice to fix
request.setJsonEntity("{" + " \"source\": {\n" + " \"index\": \"source1\"\n" + " },\n" + " \"dest\": {\n" | ||
+ " \"index\": \"dest\"\n" + " }" + "}"); | ||
Response response = lowClient.performRequest(request); | ||
String responseBody = EntityUtils.toString(response.getEntity()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feel free to use entityAsMap - available from super dlass
TaskId childTaskId = new TaskId(taskId.toString()); | ||
GetTaskRequest gtr = new GetTaskRequest(childTaskId.getNodeId(), childTaskId.getId()); | ||
Optional<GetTaskResponse> getTaskResponse = execute(gtr, highLevelClient().tasks()::get, highLevelClient().tasks()::getAsync); | ||
assertTrue(getTaskResponse.isPresent()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this or assertions below might become flakey as there is no guarantee that the task will finish so quickly
would you consider waiting here for the status to finish?
BooleanSupplier hasUpgradeCompleted = checkCompletionStatus(task);
awaitBusy(hasUpgradeCompleted);
}
}
private BooleanSupplier checkCompletionStatus(TaskId taskId) {
return () -> {
try {
Response response = client().performRequest(new Request("GET", "/_tasks/" + taskId.toString()));
return (boolean) entityAsMap(response).get("completed");
} catch (IOException e) {
fail(e.getMessage());
return false;
}
};
}
have a look at my draft https://github.com/elastic/elasticsearch/pull/35202/files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that a problem? My test is only asserting that the taskID exists and has the right description. The status (completed Vs in-progress) is not assumed and presumably it's beneficial for the test to potentially exercise both scenarios?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair point, but is this guaranteed that Optional.isPresent will always pass? I think it is possible that with unlucky timing the task will not be created by the time we call getTaskResponse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as we discussed, that would be impossible to get an ID without a resource on already being created, loooks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very good to me, but left some minor comments
try { | ||
response = client.performRequest(req); | ||
} catch (ResponseException e) { | ||
if (404 == e.getResponse().getStatusLine().getStatusCode()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use RestStatus.NOT_FOUND.getStatus()
here instead of just 404
. The async method will need to be updated too.
client.performRequestAsync(req, responseListener); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra line
@@ -1387,6 +1387,39 @@ public final void fieldCapsAsync(FieldCapabilitiesRequest fieldCapabilitiesReque | |||
throw new IOException("Unable to parse response body for " + response, e); | |||
} | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra line
assertThat("the return type for method [" + method + "] is incorrect", | ||
method.getReturnType().getSimpleName(), endsWith("Response")); | ||
// It's acceptable for 404s to be represented as empty Optionals | ||
if (!method.getReturnType().isAssignableFrom(Optional.class)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we ensure that the thing in the optional endsWith("Response"), as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did have a stab at that and I'm not sure I can get at it via reflection. The best I could get was that the Optional class used in the response has a generic type of T
. I suspect type erasure might prevent me from seeing that level of detail at runtime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, i was unsure myself :)
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; | ||
|
||
public class GetTaskResponse { | ||
private final boolean completed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spacing is messed up here and below the getters
public Optional<GetTaskResponse> get(GetTaskRequest request, RequestOptions options) throws IOException { | ||
return restHighLevelClient.performRequestAndParseOptionalEntity(request, TasksRequestConverters::getTask, options, | ||
GetTaskResponse::fromXContent); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spaces extra line
restHighLevelClient.performRequestAsyncAndParseOptionalEntity(request, TasksRequestConverters::getTask, options, | ||
GetTaskResponse::fromXContent, listener); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra line
@@ -54,4 +55,12 @@ static Request listTasks(ListTasksRequest listTaskRequest) { | |||
.putParam("group_by", "none"); | |||
return request; | |||
} | |||
|
|||
static Request getTask(GetTaskRequest getTaskRequest) { | |||
Request request = new Request(HttpGet.METHOD_NAME, "_tasks/" + getTaskRequest.getNodeId() + ":" + getTaskRequest.getTaskId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use the EndpointBuilder here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also added a method to EndpointBuilder for colon separated parts
static Request getTask(GetTaskRequest getTaskRequest) { | ||
Request request = new Request(HttpGet.METHOD_NAME, "_tasks/" + getTaskRequest.getNodeId() + ":" + getTaskRequest.getTaskId()); | ||
RequestConverters.Params params = new RequestConverters.Params(request); | ||
params.withTimeout(getTaskRequest.getTimeout()).withWaitForCompletion(getTaskRequest.getWaitForCompletion()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can u put these on 2 lines? u can keep builder if u want, its just easier to see it split on 2 lines
d8665bf
to
753677c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nits. i dont need to see it again.
|
||
static Request getTask(GetTaskRequest getTaskRequest) { | ||
String endpoint = new EndpointBuilder().addPathPartAsIs("_tasks") | ||
.addColonSeparatedPathParts(getTaskRequest.getNodeId(), Long.toString(getTaskRequest.getTaskId())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking this couldve just been a
.addPathPart(getTaskRequest.getNodeId() + ":" + Long.toString(getTaskRequest.getTaskId()))
since its technically one "path part" in a URL. Then there is no need for an extra method there. I was just trying to ensure we were using the EndpointBuilder in all the RequestConverters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I saw a precedent for comma-delimited parts in EndPointBuilder and assumed colon-delimited would be another variant. I guess it's not that common a convention so I removed it.
} | ||
|
||
/** | ||
* Timeout to wait for any async actions this request must take. It must take anywhere from 0 to 2. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im not sure i like these comments.. I know they are in server, but what does "it must take anywhere from 0 to 2" mean...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if there is a upper bound, maybe we should validate it in validate()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a copy-and-paste from the server
equivalent. I'll take a closer look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the comment. I don't see any validation code related to it so did not add anything to a validate() method. (General note: if we duplicate validation logic client and server-side is that not trappy code-maintenance-wise?)
@@ -1014,6 +1014,11 @@ EndpointBuilder addPathPart(String... parts) { | |||
return this; | |||
} | |||
|
|||
EndpointBuilder addColonSeparatedPathParts(String... parts) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im not sure this is needed, we can handle it in the method.
after approving, I realized we did not have a |
fe38da3
to
3fc4226
Compare
Given a GetTaskRequest the API returns an Optional which is empty in the case of 404s or returns a TaskInfo object if found. Added Helper methods in RestHighLevelClient for returning empty Optionals when hitting 404s
… (this is acceptable for 404s)
…th new method), added (inconclusive) test for situation where GetTaskRequest has waitForCompletion=true. Conclusive test would require long-running tasks.
3fc4226
to
ff8436f
Compare
* master: Address handling of OS pretty name on some OS (elastic#35451) HLRC support for getTask (elastic#35166) upgrade to lucene-8.0.0-snapshot-6d9c714052 (elastic#35428) Add docs for CCR stats API (elastic#35439) Fix the names of CCR stats endpoints in usage API (elastic#35438) Switch to default to no build qualifier (elastic#35415) Clarify S3 repository storage class parameter (elastic#35400) SQL: Fix query translation for scripted queries (elastic#35408) [TEST] Instead of ignoring the ccr downgrade to basic license qa test avoid the assertions that check the log files, because that does not work on Windows. The rest of the test is still useful and should work on Windows CI. Upgrade to Joda 2.10.1 (elastic#35410) HLRest: model role and privileges (elastic#35128)
* master: Address handling of OS pretty name on some OS (elastic#35451) HLRC support for getTask (elastic#35166) upgrade to lucene-8.0.0-snapshot-6d9c714052 (elastic#35428)
* master: (22 commits) Introduce CCR getting started guide (elastic#35434) Correct typo in BuildPlugin exception message (elastic#35458) Correct implemented interface of ParsedReverseNested (elastic#35455) [ML] Fix find_file_structure NPE with should_trim_fields (elastic#35465) Handle OS pretty name on old OS without OS release (elastic#35453) Register remote cluster compress setting (elastic#35464) [DOCS] Clarify results_index_name description (elastic#35463) [TEST] add missing doc tests for HLRC GetRollupIndexCaps API [HLRC] Add GetRollupIndexCaps API (elastic#35102) Geo: enables coerce support in WKT polygon parser (elastic#35414) [ILM] fix retry so it picks up latest policy and executes async action (elastic#35406) Address handling of OS pretty name on some OS (elastic#35451) HLRC support for getTask (elastic#35166) upgrade to lucene-8.0.0-snapshot-6d9c714052 (elastic#35428) Add docs for CCR stats API (elastic#35439) Fix the names of CCR stats endpoints in usage API (elastic#35438) Switch to default to no build qualifier (elastic#35415) Clarify S3 repository storage class parameter (elastic#35400) SQL: Fix query translation for scripted queries (elastic#35408) [TEST] Instead of ignoring the ccr downgrade to basic license qa test avoid the assertions that check the log files, because that does not work on Windows. The rest of the test is still useful and should work on Windows CI. ...
Given a GetTaskRequest the API returns an Optional which is empty in the case of 404s or returns a GetTaskResponse object if found.
Also added Helper methods in RestHighLevelClient for returning empty Optionals when hitting 404s as discussed here
Relates to #27205