-
Notifications
You must be signed in to change notification settings - Fork 25.3k
HLRC support for getTask #35166
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
Merged
Merged
HLRC support for getTask #35166
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3db51c3
HLRC support for getTask.
markharwood 438dbe7
Unused import
markharwood 7ae45d2
Relaxed RestHighLevelClientTests to allow methods to return Optionals…
markharwood 3b5aaf4
Remove unused imports
markharwood dd4cb00
Javadoc fix for new method
markharwood d43d008
Fixed various whitespace violations, added use of EndpointBuilder (wi…
markharwood 6ab1881
Unused imports
markharwood 4a1e344
Added GetTaskResponseTest, tidied endpoint building, removed weird Ja…
markharwood ff8436f
Renamed due to failing name convention checks
markharwood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
client/rest-high-level/src/main/java/org/elasticsearch/client/tasks/GetTaskRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.elasticsearch.client.tasks; | ||
|
||
import org.elasticsearch.client.Validatable; | ||
import org.elasticsearch.client.ValidationException; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
public class GetTaskRequest implements Validatable { | ||
private final String nodeId; | ||
private final long taskId; | ||
private boolean waitForCompletion = false; | ||
private TimeValue timeout = null; | ||
|
||
public GetTaskRequest(String nodeId, long taskId) { | ||
this.nodeId = nodeId; | ||
this.taskId = taskId; | ||
} | ||
|
||
public String getNodeId() { | ||
return nodeId; | ||
} | ||
|
||
public long getTaskId() { | ||
return taskId; | ||
} | ||
|
||
/** | ||
* Should this request wait for all found tasks to complete? | ||
*/ | ||
public boolean getWaitForCompletion() { | ||
return waitForCompletion; | ||
} | ||
|
||
/** | ||
* Should this request wait for all found tasks to complete? | ||
*/ | ||
public GetTaskRequest setWaitForCompletion(boolean waitForCompletion) { | ||
this.waitForCompletion = waitForCompletion; | ||
return this; | ||
} | ||
|
||
/** | ||
* Timeout to wait for any async actions this request must take. It must take anywhere from 0 to 2. | ||
*/ | ||
public TimeValue getTimeout() { | ||
return timeout; | ||
} | ||
|
||
/** | ||
* Timeout to wait for any async actions this request must take. | ||
*/ | ||
public GetTaskRequest setTimeout(TimeValue timeout) { | ||
this.timeout = timeout; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Optional<ValidationException> validate() { | ||
final ValidationException validationException = new ValidationException(); | ||
if (timeout != null && !waitForCompletion) { | ||
validationException.addValidationError("Timeout settings are only accepted if waitForCompletion is also set"); | ||
} | ||
if (validationException.validationErrors().isEmpty()) { | ||
return Optional.empty(); | ||
} | ||
return Optional.of(validationException); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(nodeId, taskId, waitForCompletion, timeout); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
GetTaskRequest other = (GetTaskRequest) obj; | ||
return Objects.equals(nodeId, other.nodeId) && | ||
taskId == other.taskId && | ||
waitForCompletion == other.waitForCompletion && | ||
Objects.equals(timeout, other.timeout); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
client/rest-high-level/src/main/java/org/elasticsearch/client/tasks/GetTaskResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client.tasks; | ||
|
||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.tasks.TaskInfo; | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. spacing is messed up here and below the getters |
||
private final TaskInfo taskInfo; | ||
public static final ParseField COMPLETED = new ParseField("completed"); | ||
public static final ParseField TASK = new ParseField("task"); | ||
|
||
public GetTaskResponse(boolean completed, TaskInfo taskInfo) { | ||
this.completed = completed; | ||
this.taskInfo = taskInfo; | ||
} | ||
|
||
public boolean isCompleted() { | ||
return completed; | ||
} | ||
|
||
public TaskInfo getTaskInfo() { | ||
return taskInfo; | ||
} | ||
|
||
private static final ConstructingObjectParser<GetTaskResponse, Void> PARSER = new ConstructingObjectParser<>("get_task", | ||
true, a -> new GetTaskResponse((boolean) a[0], (TaskInfo) a[1])); | ||
static { | ||
PARSER.declareBoolean(constructorArg(), COMPLETED); | ||
PARSER.declareObject(constructorArg(), (p, c) -> TaskInfo.fromXContent(p), TASK); | ||
} | ||
|
||
public static GetTaskResponse fromXContent(XContentParser parser) { | ||
return PARSER.apply(parser, null); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some minor new lines formatting would be nice to fix |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 lookThere 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?)