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: execute watch API #35868
Merged
Merged
HLRC: execute watch API #35868
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
601a3c7
broekn
romseygeek fd1687c
Merge remote-tracking branch 'origin/master' into hlrc-execute-watch
romseygeek 3262fcd
WIP
romseygeek 7a462df
Move ObjectPath, XContentSoure and XContentUtils to core
romseygeek 89b3903
Merge remote-tracking branch 'origin/master' into hlrc-execute-watch
romseygeek c0bb8c3
Revert "Move ObjectPath, XContentSoure and XContentUtils to core"
romseygeek 6330da1
Move ObjectPath and XContentUtils into lib/x-content
romseygeek 42328d4
Merge branch 'xcontentutils' into hlrc-execute-watch
romseygeek 6d5232c
Merge remote-tracking branch 'origin/master' into hlrc-execute-watch
romseygeek 9c0aaed
WIP
romseygeek 98ddc40
Merge remote-tracking branch 'origin/master' into hlrc-execute-watch
romseygeek d5a4db8
warnings
romseygeek 54225ca
WIP
romseygeek e8ddc04
WIP
romseygeek 696fb6b
HLRC comparison tests
romseygeek 62da9c5
Merge remote-tracking branch 'origin/master' into hlrc-execute-watch
romseygeek aaadc9f
Tests; docs
romseygeek 933bc40
javadoc
romseygeek 3e90aa9
license headers; imports
romseygeek c611744
imports
romseygeek a1dfd0a
imports
romseygeek a6d4c0d
Merge remote-tracking branch 'origin/master' into hlrc-execute-watch
romseygeek c4e3fe4
Fix docs test
romseygeek ba11a6f
Check record-execution validation
romseygeek a8abe2b
Remove 404 exclusions
romseygeek 492b507
Merge remote-tracking branch 'origin/master' into hlrc-execute-watch
romseygeek 3d67c6a
Merge remote-tracking branch 'origin/master' into hlrc-execute-watch
romseygeek c779b34
feedback
romseygeek 5b231e7
feedback
romseygeek 64541a6
Merge remote-tracking branch 'origin/master' into hlrc-execute-watch
romseygeek 72a9a29
Merge remote-tracking branch 'origin/master' into hlrc-execute-watch
romseygeek File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
85 changes: 85 additions & 0 deletions
85
client/rest-high-level/src/main/java/org/elasticsearch/client/common/XContentSource.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,85 @@ | ||
/* | ||
* 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.common; | ||
|
||
import org.elasticsearch.common.xcontent.ObjectPath; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.common.xcontent.XContentUtils; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Encapsulates the xcontent source | ||
*/ | ||
public class XContentSource { | ||
|
||
private final Object data; | ||
|
||
/** | ||
* Constructs a new XContentSource out of the given parser | ||
*/ | ||
public XContentSource(XContentParser parser) throws IOException { | ||
this.data = XContentUtils.readValue(parser, parser.nextToken()); | ||
} | ||
|
||
/** | ||
* @return true if the top level value of the source is a map | ||
*/ | ||
public boolean isMap() { | ||
return data instanceof Map; | ||
} | ||
|
||
/** | ||
* @return The source as a map | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public Map<String, Object> getAsMap() { | ||
return (Map<String, Object>) data; | ||
} | ||
|
||
/** | ||
* @return true if the top level value of the source is a list | ||
*/ | ||
public boolean isList() { | ||
return data instanceof List; | ||
} | ||
|
||
/** | ||
* @return The source as a list | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public List<Object> getAsList() { | ||
return (List<Object>) data; | ||
} | ||
|
||
/** | ||
* Extracts a value identified by the given path in the source. | ||
* | ||
* @param path a dot notation path to the requested value | ||
* @return The extracted value or {@code null} if no value is associated with the given path | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public <T> T getValue(String path) { | ||
return (T) ObjectPath.eval(path, data); | ||
} | ||
|
||
} |
175 changes: 175 additions & 0 deletions
175
...t/rest-high-level/src/main/java/org/elasticsearch/client/watcher/ExecuteWatchRequest.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,175 @@ | ||
/* | ||
* 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.common.Nullable; | ||
import org.elasticsearch.common.bytes.BytesArray; | ||
import org.elasticsearch.common.bytes.BytesReference; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
/** | ||
* An execute watch request to execute a watch by id or inline | ||
*/ | ||
public class ExecuteWatchRequest implements Validatable, ToXContentObject { | ||
|
||
public enum ActionExecutionMode { | ||
SIMULATE, FORCE_SIMULATE, EXECUTE, FORCE_EXECUTE, SKIP | ||
} | ||
|
||
private final String id; | ||
private final BytesReference watchContent; | ||
|
||
private boolean ignoreCondition = false; | ||
private boolean recordExecution = false; | ||
private boolean debug = false; | ||
|
||
@Nullable | ||
private BytesReference triggerData = null; | ||
|
||
@Nullable | ||
private BytesReference alternativeInput = null; | ||
|
||
private Map<String, ActionExecutionMode> actionModes = new HashMap<>(); | ||
|
||
/** | ||
* Execute an existing watch on the cluster | ||
* | ||
* @param id the id of the watch to execute | ||
*/ | ||
public static ExecuteWatchRequest byId(String id) { | ||
return new ExecuteWatchRequest(Objects.requireNonNull(id, "Watch id cannot be null"), null); | ||
} | ||
|
||
/** | ||
* Execute an inline watch | ||
* @param watchContent the JSON definition of the watch | ||
*/ | ||
public static ExecuteWatchRequest inline(String watchContent) { | ||
return new ExecuteWatchRequest(null, Objects.requireNonNull(watchContent, "Watch content cannot be null")); | ||
} | ||
|
||
private ExecuteWatchRequest(String id, String watchContent) { | ||
this.id = id; | ||
this.watchContent = watchContent == null ? null : new BytesArray(watchContent); | ||
} | ||
|
||
public String getId() { | ||
return this.id; | ||
} | ||
|
||
/** | ||
* @param ignoreCondition set if the condition for this execution be ignored | ||
*/ | ||
public void setIgnoreCondition(boolean ignoreCondition) { | ||
this.ignoreCondition = ignoreCondition; | ||
} | ||
|
||
public boolean ignoreCondition() { | ||
return ignoreCondition; | ||
} | ||
|
||
/** | ||
* @param recordExecution Sets if this execution be recorded in the history index | ||
*/ | ||
public void setRecordExecution(boolean recordExecution) { | ||
if (watchContent != null && recordExecution) { | ||
throw new IllegalArgumentException("The execution of an inline watch cannot be recorded"); | ||
} | ||
this.recordExecution = recordExecution; | ||
} | ||
|
||
public boolean recordExecution() { | ||
return recordExecution; | ||
} | ||
|
||
/** | ||
* @param alternativeInput Sets the alternative input | ||
*/ | ||
public void setAlternativeInput(String alternativeInput) { | ||
this.alternativeInput = new BytesArray(alternativeInput); | ||
} | ||
|
||
/** | ||
* @param data A JSON string representing the data that should be associated with the trigger event. | ||
*/ | ||
public void setTriggerData(String data) { | ||
this.triggerData = new BytesArray(data); | ||
} | ||
|
||
/** | ||
* Sets the action execution mode for the give action (identified by its id). | ||
* | ||
* @param actionId the action id. | ||
* @param actionMode the execution mode of the action. | ||
*/ | ||
public void setActionMode(String actionId, ActionExecutionMode actionMode) { | ||
Objects.requireNonNull(actionId, "actionId cannot be null"); | ||
actionModes.put(actionId, actionMode); | ||
} | ||
|
||
public Map<String, ActionExecutionMode> getActionModes() { | ||
return this.actionModes; | ||
} | ||
|
||
/** | ||
* @param debug indicates whether the watch should execute in debug mode. In debug mode the | ||
* returned watch record will hold the execution {@code vars} | ||
*/ | ||
public void setDebug(boolean debug) { | ||
this.debug = debug; | ||
} | ||
|
||
public boolean isDebug() { | ||
return debug; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "execute[" + id + "]"; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
if (triggerData != null) { | ||
builder.rawField("trigger_data", triggerData.streamInput(), XContentType.JSON); | ||
} | ||
if (alternativeInput != null) { | ||
builder.rawField("alternative_input", alternativeInput.streamInput(), XContentType.JSON); | ||
} | ||
if (actionModes.size() > 0) { | ||
builder.field("action_modes", actionModes); | ||
} | ||
if (watchContent != null) { | ||
builder.rawField("watch", watchContent.streamInput(), XContentType.JSON); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} | ||
|
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.