mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-22 21:05:23 +00:00
Today, once you add a watch to watcher, it's always active. Being "active" means that the watch is registered with the trigger engine (scheduled) and will be executed when its trigger is triggered. Quite often, ppl want to have an option to deactivate/disable a registered watch. Such that while the watch definition still exists in watcher, it is "inactive" and is never triggered. The only way to do this today is using a "hack" where you can change the watch schedule to a cron expression targeting a really far date in the future (say somewhere around 2050). Again.. this is very hackish and it requires changing the actual definition of the watch (you loose its original trigger). This commit introduces the notion of an active/inactive watch.. here are the differences between the two states: - active: the watch is registered with watcher and with the trigger engine and will be executed when its trigger is fired by the engine - inactive: the watch is registered with watcher, but is not registered with the trigger engine. An inactive watch will never be fired, regardless of its trigger. This commit also adds two new APIs: - `_watcher/watch/{id}/_activate` - `_watcher/watch/{id}/_deactivate` to activate and deactivate existing watches. In addition, the Put Watch API now accepts an `active` parameter that indicates the initial state of the put watch (by default set to `true`, i.e. "active"). Closes elastic/elasticsearch#90 Original commit: elastic/x-pack-elasticsearch@37b9ab4d54
116 lines
2.9 KiB
Plaintext
116 lines
2.9 KiB
Plaintext
[[api-java]]
|
|
=== Java API
|
|
Watcher provides a Java client called WatcherClient that adds support for the Watcher APIs to the standard Java clients
|
|
that ship with Elasticsearch ({java-client-ref}/transport-client.html[Transport Client] or
|
|
the {java-client-ref}/node-client.html[Node Client]).
|
|
|
|
==== Installing WatcherClient
|
|
|
|
To use the `WatcherClient` you will need to make sure the `elasticsearch-watcher` JAR file is in the classpath. You can
|
|
extract the jar from the downloaded watcher plugin itself.
|
|
|
|
If you use Maven to manage dependencies, add the following to the `pom.xml`:
|
|
|
|
[source,xml]
|
|
--------------------------------------------------
|
|
<project ...>
|
|
|
|
<repositories>
|
|
<!-- add the elasticsearch repo -->
|
|
<repository>
|
|
<id>elasticsearch-releases</id>
|
|
<url>http://maven.elasticsearch.org/releases</url>
|
|
<releases>
|
|
<enabled>true</enabled>
|
|
</releases>
|
|
<snapshots>
|
|
<enabled>false</enabled>
|
|
</snapshots>
|
|
</repository>
|
|
...
|
|
</repositories>
|
|
...
|
|
|
|
<dependencies>
|
|
<!-- add the Watcher jar as a dependency -->
|
|
<dependency>
|
|
<groupId>org.elasticsearch.plugin</groupId>
|
|
<artifactId>elasticsearch-watcher</artifactId>
|
|
<version>2.0.0</version>
|
|
</dependency>
|
|
...
|
|
</dependencies>
|
|
...
|
|
|
|
</project>
|
|
--------------------------------------------------
|
|
|
|
If you use Gradle, add the dependencies to `build.gradle`:
|
|
|
|
[source,groovy]
|
|
--------------------------------------------------------------
|
|
repositories {
|
|
/* ... Any other repositories ... */
|
|
|
|
// Add the Elasticsearch Maven Repository
|
|
maven {
|
|
url "http://maven.elasticsearch.org/releases"
|
|
}
|
|
}
|
|
|
|
dependencies {
|
|
// Provide the Watcher jar on the classpath for compilation and at runtime
|
|
compile "org.elasticsearch.plugin:elasticsearch-watcher:2.0.0"
|
|
|
|
/* ... */
|
|
}
|
|
--------------------------------------------------------------
|
|
|
|
You can manually download the http://maven.elasticsearch.org/releases/org/elasticsearch/plugin/elasticsearch-watcher/2.0.0/elasticsearch-watcher-2.0.0.jar[Watcher JAR]
|
|
directly from our Maven repository.
|
|
|
|
==== Creating the WatcherClient
|
|
|
|
Creating the `WatcherClient` can simply be done as the following snippet shows:
|
|
|
|
[source,java]
|
|
--------------------------------------------------
|
|
import org.elasticsearch.watcher.client.WatcherClient;
|
|
...
|
|
|
|
Client client = ... // create and initialize either the transport or the node client
|
|
|
|
WatcherClient watcherClient = new WatcherClient(client);
|
|
--------------------------------------------------
|
|
|
|
include::java/put-watch.asciidoc[]
|
|
|
|
include::java/get-watch.asciidoc[]
|
|
|
|
include::java/delete-watch.asciidoc[]
|
|
|
|
include::java/execute-watch.asciidoc[]
|
|
|
|
include::java/ack-watch.asciidoc[]
|
|
|
|
include::java/activate-watch.asciidoc[]
|
|
|
|
include::java/deactivate-watch.asciidoc[]
|
|
|
|
include::java/stats.asciidoc[]
|
|
|
|
include::java/service.asciidoc[]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|