-
Notifications
You must be signed in to change notification settings - Fork 24.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for 'ack watch' to the HLRC. (#33962)
- Loading branch information
1 parent
ac0da70
commit 28deda6
Showing
11 changed files
with
592 additions
and
0 deletions.
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
96 changes: 96 additions & 0 deletions
96
client/rest-high-level/src/main/java/org/elasticsearch/client/watcher/AckWatchRequest.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,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 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 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
Oops, something went wrong.