-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add support for 'ack watch' to the HLRC. #33962
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f46819b
Implement request conversion.
jtibshirani 1e0128b
Implement response conversion.
jtibshirani 884f970
Add an ack watch endpoint.
jtibshirani c4c52ff
Add documentation.
jtibshirani 5848d9a
Merge remote-tracking branch 'upstream/master' into ack-watch
jtibshirani 91f917c
Move request validation into the constructor.
jtibshirani 629078f
Merge remote-tracking branch 'upstream/master' into ack-watch
jtibshirani 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
96 changes: 96 additions & 0 deletions
96
client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/AckWatchRequest.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,96 @@ | ||
| /* | ||
| * 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.watcher; | ||
|
|
||
| import org.elasticsearch.client.Validatable; | ||
| import org.elasticsearch.client.ValidationException; | ||
| import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest; | ||
|
|
||
| import java.util.Locale; | ||
|
|
||
| /** | ||
| * A request to explicitly acknowledge a watch. | ||
| */ | ||
| public class AckWatchRequest implements Validatable { | ||
|
|
||
| private final String watchId; | ||
| private final String[] actionIds; | ||
|
|
||
| public AckWatchRequest(String watchId, String... actionIds) { | ||
| validateIds(watchId, actionIds); | ||
| this.watchId = watchId; | ||
| this.actionIds = actionIds; | ||
| } | ||
|
|
||
| private void validateIds(String watchId, String... actionIds) { | ||
| ValidationException exception = new ValidationException(); | ||
| if (watchId == null) { | ||
| exception.addValidationError("watch id is missing"); | ||
| } else if (PutWatchRequest.isValidId(watchId) == false) { | ||
| exception.addValidationError("watch id contains whitespace"); | ||
| } | ||
|
|
||
| if (actionIds != null) { | ||
| for (String actionId : actionIds) { | ||
| if (actionId == null) { | ||
| exception.addValidationError(String.format(Locale.ROOT, "action id may not be null")); | ||
| } else if (PutWatchRequest.isValidId(actionId) == false) { | ||
| exception.addValidationError( | ||
| String.format(Locale.ROOT, "action id [%s] contains whitespace", actionId)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (!exception.validationErrors().isEmpty()) { | ||
| throw exception; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @return The ID of the watch to be acked. | ||
| */ | ||
| public String getWatchId() { | ||
| return watchId; | ||
| } | ||
|
|
||
| /** | ||
| * @return The IDs of the actions to be acked. If omitted, | ||
| * all actions for the given watch will be acknowledged. | ||
| */ | ||
| public String[] getActionIds() { | ||
| return actionIds; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| StringBuilder sb = new StringBuilder("ack [").append(watchId).append("]"); | ||
| if (actionIds.length > 0) { | ||
| sb.append("["); | ||
| for (int i = 0; i < actionIds.length; i++) { | ||
| if (i > 0) { | ||
| sb.append(", "); | ||
| } | ||
| sb.append(actionIds[i]); | ||
| } | ||
| sb.append("]"); | ||
| } | ||
| return sb.toString(); | ||
| } | ||
| } | ||
61 changes: 61 additions & 0 deletions
61
client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/AckWatchResponse.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,61 @@ | ||
| /* | ||
| * 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.watcher; | ||
|
|
||
| import org.elasticsearch.common.ParseField; | ||
| import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
| import org.elasticsearch.common.xcontent.XContentParser; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * The response from an 'ack watch' request. | ||
| */ | ||
| public class AckWatchResponse { | ||
|
|
||
| private final WatchStatus status; | ||
|
|
||
| public AckWatchResponse(WatchStatus status) { | ||
| this.status = status; | ||
| } | ||
|
|
||
| /** | ||
| * @return the status of the requested watch. If an action was | ||
| * successfully acknowledged, this will be reflected in its status. | ||
| */ | ||
| public WatchStatus getStatus() { | ||
| return status; | ||
| } | ||
|
|
||
| private static final ParseField STATUS_FIELD = new ParseField("status"); | ||
| private static ConstructingObjectParser<AckWatchResponse, Void> PARSER = | ||
| new ConstructingObjectParser<>("ack_watch_response", true, | ||
| a -> new AckWatchResponse((WatchStatus) a[0])); | ||
|
|
||
| static { | ||
| PARSER.declareObject(ConstructingObjectParser.constructorArg(), | ||
| (parser, context) -> WatchStatus.parse(parser), | ||
| STATUS_FIELD); | ||
| } | ||
|
|
||
| public static AckWatchResponse fromXContent(XContentParser parser) throws IOException { | ||
| return PARSER.parse(parser, null); | ||
| } | ||
| } |
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.
We should try to put all the validation we can into the constructors themselves, because this layer of validation, while it does work, does not tell you where the actual error in setting a bad value came from. There are a lot of
requireNotNullin constructors, so lets move any logic possible into thermThere 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.
👍