-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Fix HLRC parsing of CancelTasks response #47017
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
59f53dd
Fixing HLRC parsing of CancelTasks response (#45414)
jesinity 5680adf
doing the fixes
jesinity dbcf601
fixing tests.... in progress
jesinity 7314ddd
fixing tests done
jesinity e1e3e84
fixing comments for tests and doc
jesinity c3ae790
fixing doc generation
jesinity af28266
Merge branch 'master' into cancel-tasks-fix
elasticmachine 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 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 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 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
151 changes: 151 additions & 0 deletions
151
client/rest-high-level/src/main/java/org/elasticsearch/client/tasks/CancelTasksRequest.java
This file contains 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,151 @@ | ||
/* | ||
* 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.common.unit.TimeValue; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
public class CancelTasksRequest implements Validatable { | ||
|
||
private final List<String> nodes = new ArrayList<>(); | ||
private final List<String> actions = new ArrayList<>(); | ||
private Optional<TimeValue> timeout = Optional.empty(); | ||
private Optional<TaskId> parentTaskId = Optional.empty(); | ||
private Optional<TaskId> taskId = Optional.empty(); | ||
|
||
CancelTasksRequest(){} | ||
|
||
void setNodes(List<String> nodes) { | ||
this.nodes.addAll(nodes); | ||
} | ||
|
||
public List<String> getNodes() { | ||
return nodes; | ||
} | ||
|
||
void setTimeout(TimeValue timeout) { | ||
this.timeout = Optional.of(timeout); | ||
} | ||
|
||
public Optional<TimeValue> getTimeout() { | ||
return timeout; | ||
} | ||
|
||
void setActions(List<String> actions) { | ||
this.actions.addAll(actions); | ||
} | ||
|
||
public List<String> getActions() { | ||
return actions; | ||
} | ||
|
||
void setParentTaskId(TaskId parentTaskId) { | ||
this.parentTaskId = Optional.of(parentTaskId); | ||
} | ||
|
||
public Optional<TaskId> getParentTaskId() { | ||
return parentTaskId; | ||
} | ||
|
||
void setTaskId(TaskId taskId) { | ||
this.taskId = Optional.of(taskId); | ||
} | ||
|
||
public Optional<TaskId> getTaskId() { | ||
return taskId; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof CancelTasksRequest)) return false; | ||
CancelTasksRequest that = (CancelTasksRequest) o; | ||
return Objects.equals(getNodes(), that.getNodes()) && | ||
Objects.equals(getActions(), that.getActions()) && | ||
Objects.equals(getTimeout(), that.getTimeout()) && | ||
Objects.equals(getParentTaskId(), that.getParentTaskId()) && | ||
Objects.equals(getTaskId(), that.getTaskId()) ; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getNodes(), getActions(), getTimeout(), getParentTaskId(), getTaskId()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CancelTasksRequest{" + | ||
"nodes=" + nodes + | ||
", actions=" + actions + | ||
", timeout=" + timeout + | ||
", parentTaskId=" + parentTaskId + | ||
", taskId=" + taskId + | ||
'}'; | ||
} | ||
|
||
public static class Builder { | ||
private Optional<TimeValue> timeout = Optional.empty(); | ||
private Optional<TaskId> taskId = Optional.empty(); | ||
private Optional<TaskId> parentTaskId = Optional.empty(); | ||
private List<String> actionsFilter = new ArrayList<>(); | ||
private List<String> nodesFilter = new ArrayList<>(); | ||
|
||
public Builder withTimeout(TimeValue timeout){ | ||
this.timeout = Optional.of(timeout); | ||
return this; | ||
} | ||
|
||
public Builder withTaskId(TaskId taskId){ | ||
this.taskId = Optional.of(taskId); | ||
return this; | ||
} | ||
|
||
public Builder withParentTaskId(TaskId taskId){ | ||
this.parentTaskId = Optional.of(taskId); | ||
return this; | ||
} | ||
|
||
public Builder withActionsFiltered(List<String> actions){ | ||
this.actionsFilter.clear(); | ||
this.actionsFilter.addAll(actions); | ||
return this; | ||
} | ||
|
||
public Builder withNodesFiltered(List<String> nodes){ | ||
this.nodesFilter.clear(); | ||
this.nodesFilter.addAll(nodes); | ||
return this; | ||
} | ||
|
||
public CancelTasksRequest build() { | ||
CancelTasksRequest request = new CancelTasksRequest(); | ||
timeout.ifPresent(request::setTimeout); | ||
taskId.ifPresent(request::setTaskId); | ||
parentTaskId.ifPresent(request::setParentTaskId); | ||
request.setNodes(nodesFilter); | ||
request.setActions(actionsFilter); | ||
return request; | ||
} | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
client/rest-high-level/src/main/java/org/elasticsearch/client/tasks/CancelTasksResponse.java
This file contains 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,91 @@ | ||
/* | ||
* 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 java.io.IOException; | ||
import java.util.List; | ||
|
||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg; | ||
|
||
/** | ||
* cancel tasks response that contains | ||
* - task failures | ||
* - node failures | ||
* - tasks | ||
*/ | ||
public class CancelTasksResponse extends ListTasksResponse { | ||
|
||
CancelTasksResponse(List<NodeData> nodesInfoData, | ||
List<TaskOperationFailure> taskFailures, | ||
List<ElasticsearchException> nodeFailures) { | ||
super(nodesInfoData, taskFailures, nodeFailures); | ||
} | ||
|
||
public static CancelTasksResponse fromXContent(final XContentParser parser) throws IOException { | ||
return PARSER.parse(parser, null); | ||
} | ||
|
||
private static ConstructingObjectParser<CancelTasksResponse, Void> PARSER; | ||
|
||
static { | ||
ConstructingObjectParser<CancelTasksResponse, Void> parser = new ConstructingObjectParser<>("cancel_tasks_response", true, | ||
constructingObjects -> { | ||
int i = 0; | ||
@SuppressWarnings("unchecked") | ||
List<TaskOperationFailure> tasksFailures = (List<TaskOperationFailure>) constructingObjects[i++]; | ||
@SuppressWarnings("unchecked") | ||
List<ElasticsearchException> nodeFailures = (List<ElasticsearchException>) constructingObjects[i++]; | ||
@SuppressWarnings("unchecked") | ||
List<NodeData> nodesInfoData = (List<NodeData>) constructingObjects[i]; | ||
return new CancelTasksResponse(nodesInfoData, tasksFailures, nodeFailures); | ||
}); | ||
|
||
parser.declareObjectArray(optionalConstructorArg(), (p, c) -> | ||
TaskOperationFailure.fromXContent(p), new ParseField("task_failures")); | ||
parser.declareObjectArray(optionalConstructorArg(), (p, c) -> | ||
ElasticsearchException.fromXContent(p), new ParseField("node_failures")); | ||
parser.declareNamedObjects(optionalConstructorArg(), NodeData.PARSER, new ParseField("nodes")); | ||
PARSER = parser; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
return super.equals(o); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return super.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CancelTasksResponse{" + | ||
"taskFailures=" + taskFailures + | ||
", nodeFailures=" + nodeFailures + | ||
", nodesInfoData=" + nodesInfoData + | ||
", tasks=" + tasks + | ||
", taskGroups=" + taskGroups + | ||
'}'; | ||
} | ||
} |
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.
Lets remove this builder since some of the setters on the class itself already return this, and then add
return this;
to the methods in the Request that do not have them already.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.
maybe lets just remove the "return this" from the methods in the class and keep the builder, i think that makes more sense
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