Merge pull request elastic/elasticsearch#594 from elastic/upgrade_to_es_20
Upgrade to Elasticsearch 2.0.0-SNAPSHOT This moves the master branch to follow Elasticsearch 2.0.0-SNAPSHOT and fixes most problems that occurred during the upgrade. The remaining issues not yet fixed are: * `HttpClient` and the `Account` used for Email support need to install security manager which is not supported by the elasticsearch security policy. This is not yet resolved an requires fundamental changes and/or a rule in the core policy file. See elastic/elasticsearch#597 * Due to changes to the way Time/Byte settings are parsed settings without a unit must be upgraded. See elastic/elasticsearch#598 * REST tests are currently disabled due to some limitations from Elasticsearch core that don't allow to run 3rd party REST tests. See elastic/elasticsearch#599 Watcher now also inherits the elaticsearch-parent pom file and all it's properties. Original commit: elastic/x-pack-elasticsearch@1e03234e3e
This commit is contained in:
commit
d730917b53
317
pom.xml
317
pom.xml
|
@ -16,30 +16,17 @@
|
|||
</scm>
|
||||
|
||||
<parent>
|
||||
<groupId>org.sonatype.oss</groupId>
|
||||
<artifactId>oss-parent</artifactId>
|
||||
<version>7</version>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
<artifactId>elasticsearch-plugin</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<elasticsearch.version>1.5.0</elasticsearch.version>
|
||||
<lucene.maven.version>4.10.4</lucene.maven.version>
|
||||
<lucene.version>4.10.4</lucene.version>
|
||||
<shield.version>1.2.1</shield.version>
|
||||
<license.version>1.0.0</license.version>
|
||||
|
||||
<tests.jvms>auto</tests.jvms>
|
||||
<tests.shuffle>true</tests.shuffle>
|
||||
<tests.output>onerror</tests.output>
|
||||
<tests.client.ratio></tests.client.ratio>
|
||||
<tests.bwc.path>${project.basedir}/backwards</tests.bwc.path>
|
||||
<es.logger.level>INFO</es.logger.level>
|
||||
<tests.heap.size>512m</tests.heap.size>
|
||||
<tests.topn>5</tests.topn>
|
||||
<execution.hint.file>.local-${project.version}-execution-hints.log</execution.hint.file>
|
||||
<tests.rest>true</tests.rest>
|
||||
<tests.slow>false</tests.slow>
|
||||
<tests.timewarp>true</tests.timewarp>
|
||||
<elasticsearch.license.header>dev-tools/elasticsearch_license_header.txt</elasticsearch.license.header>
|
||||
<elasticsearch.license.headerDefinition>dev-tools/license_header_definition.xml</elasticsearch.license.headerDefinition>
|
||||
<license.plugin.version>2.0.0-SNAPSHOT</license.plugin.version>
|
||||
<shield.plugin.version>2.0.0-SNAPSHOT</shield.plugin.version>
|
||||
<tests.security.manager>false</tests.security.manager> <!-- some tests fail since they need setFactory permission -->
|
||||
<tests.rest>false</tests.rest> <!-- watcher can't run REST tests at this point -->
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -151,14 +138,14 @@
|
|||
<dependency>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
<artifactId>elasticsearch-license-plugin</artifactId>
|
||||
<version>${license.version}</version>
|
||||
<version>${license.plugin.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
<artifactId>elasticsearch-shield</artifactId>
|
||||
<version>${shield.version}</version>
|
||||
<version>${shield.plugin.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
@ -168,12 +155,6 @@
|
|||
<version>r239</version>
|
||||
</dependency>
|
||||
|
||||
<dependency> <!-- required for owasp to work -->
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>r05</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.lucene</groupId>
|
||||
<artifactId>lucene-core</artifactId>
|
||||
|
@ -191,6 +172,12 @@
|
|||
<artifactId>activation</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.spullara.mustache.java</groupId>
|
||||
<artifactId>compiler</artifactId>
|
||||
<version>0.8.13</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
@ -199,7 +186,7 @@
|
|||
<dependency>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
<artifactId>elasticsearch-shield</artifactId>
|
||||
<version>${shield.version}</version>
|
||||
<version>${shield.plugin.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
|
@ -210,7 +197,7 @@
|
|||
<dependency>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
<artifactId>elasticsearch-license-plugin</artifactId>
|
||||
<version>${license.version}</version>
|
||||
<version>${license.plugin.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
|
@ -254,6 +241,11 @@
|
|||
<url>http://download.java.net/maven/2/</url>
|
||||
<layout>default</layout>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>oss-snapshots</id>
|
||||
<name>Sonatype OSS Snapshots</name>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
|
@ -283,22 +275,10 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>1.3.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-versions</id>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireJavaVersion>
|
||||
<version>[1.7,)</version>
|
||||
</requireJavaVersion>
|
||||
</rules>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>buildnumber-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
@ -318,7 +298,7 @@
|
|||
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer</include>
|
||||
<include>com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer</include>
|
||||
<include>com.google.guava:guava</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
|
@ -367,245 +347,6 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
<fork>true</fork>
|
||||
<maxmem>512m</maxmem>
|
||||
<!-- REMOVE WHEN UPGRADE:
|
||||
see https://jira.codehaus.org/browse/MCOMPILER-209 it's a bug where
|
||||
incremental compilation doesn't work unless it's set to false causeing
|
||||
recompilation of the entire codebase each time without any changes. Should
|
||||
be fixed in version > 3.1
|
||||
-->
|
||||
<useIncrementalCompilation>false</useIncrementalCompilation>
|
||||
<compilerArgs>
|
||||
<arg>-XDignore.symbol.file</arg>
|
||||
</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.carrotsearch.randomizedtesting</groupId>
|
||||
<artifactId>junit4-maven-plugin</artifactId>
|
||||
<version>2.1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>tests</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>junit4</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<heartbeat>20</heartbeat>
|
||||
<jvmOutputAction>pipe,warn</jvmOutputAction>
|
||||
<leaveTemporary>true</leaveTemporary>
|
||||
<listeners>
|
||||
<report-ant-xml mavenExtensions="true"
|
||||
dir="${project.build.directory}/surefire-reports"/>
|
||||
<report-text
|
||||
showThrowable="true"
|
||||
showStackTraces="true"
|
||||
showOutput="${tests.output}"
|
||||
showStatusOk="false"
|
||||
showStatusError="true"
|
||||
showStatusFailure="true"
|
||||
showStatusIgnored="true"
|
||||
showSuiteSummary="true"
|
||||
timestamps="false"/>
|
||||
<report-execution-times historyLength="20" file="${basedir}/${execution.hint.file}"/>
|
||||
</listeners>
|
||||
<assertions>
|
||||
<enable/>
|
||||
<disable package="${tests.assertion.disabled}"/>
|
||||
<!-- pass org.elasticsearch to run without assertions -->
|
||||
</assertions>
|
||||
<parallelism>${tests.jvms}</parallelism>
|
||||
<balancers>
|
||||
<execution-times>
|
||||
<fileset dir="${basedir}" includes="${execution.hint.file}"/>
|
||||
</execution-times>
|
||||
</balancers>
|
||||
<includes>
|
||||
<include>**/*Tests.class</include>
|
||||
<include>**/*Test.class</include>
|
||||
<include>**/Test*.class</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/Abstract*.class</exclude>
|
||||
<exclude>**/*StressTest.class</exclude>
|
||||
</excludes>
|
||||
<jvmArgs>
|
||||
<param>-Xmx${tests.heap.size}</param>
|
||||
<param>-Xms${tests.heap.size}</param>
|
||||
<param>-Xss256k</param>
|
||||
<param>-XX:MaxDirectMemorySize=512m</param>
|
||||
<param>-Des.logger.prefix=</param>
|
||||
</jvmArgs>
|
||||
<shuffleOnSlave>${tests.shuffle}</shuffleOnSlave>
|
||||
<sysouts>${tests.verbose}</sysouts>
|
||||
<seed>${tests.seed}</seed>
|
||||
<haltOnFailure>${tests.failfast}</haltOnFailure>
|
||||
<uniqueSuiteNames>false</uniqueSuiteNames>
|
||||
<systemProperties>
|
||||
<java.io.tmpdir>.</java.io.tmpdir>
|
||||
<!-- we use '.' since this is different per JVM-->
|
||||
<!-- RandomizedTesting library system properties -->
|
||||
<tests.bwc>${tests.bwc}</tests.bwc>
|
||||
<tests.bwc.path>${tests.bwc.path}</tests.bwc.path>
|
||||
<tests.bwc.version>${tests.bwc.version}</tests.bwc.version>
|
||||
<tests.jvm.argline>${tests.jvm.argline}</tests.jvm.argline>
|
||||
<tests.processors>${tests.processors}</tests.processors>
|
||||
<tests.appendseed>${tests.appendseed}</tests.appendseed>
|
||||
<tests.iters>${tests.iters}</tests.iters>
|
||||
<tests.maxfailures>${tests.maxfailures}</tests.maxfailures>
|
||||
<tests.failfast>${tests.failfast}</tests.failfast>
|
||||
<tests.class>${tests.class}</tests.class>
|
||||
<tests.method>${tests.method}</tests.method>
|
||||
<tests.nightly>${tests.nightly}</tests.nightly>
|
||||
<tests.verbose>${tests.verbose}</tests.verbose>
|
||||
<tests.badapples>${tests.badapples}</tests.badapples>
|
||||
<tests.weekly>${tests.weekly}</tests.weekly>
|
||||
<tests.slow>${tests.slow}</tests.slow>
|
||||
<tests.awaitsfix>${tests.awaitsfix}</tests.awaitsfix>
|
||||
<tests.slow>${tests.slow}</tests.slow>
|
||||
<tests.timeoutSuite>${tests.timeoutSuite}</tests.timeoutSuite>
|
||||
<tests.showSuccess>${tests.showSuccess}</tests.showSuccess>
|
||||
<tests.integration>${tests.integration}</tests.integration>
|
||||
<tests.client.ratio>${tests.client.ratio}</tests.client.ratio>
|
||||
<tests.enable_mock_modules>${tests.enable_mock_modules}</tests.enable_mock_modules>
|
||||
<tests.assertion.disabled>${tests.assertion.disabled}</tests.assertion.disabled>
|
||||
<tests.rest>${tests.rest}</tests.rest>
|
||||
<tests.rest.suite>${tests.rest.suite}</tests.rest.suite>
|
||||
<tests.rest.blacklist>${tests.rest.blacklist}</tests.rest.blacklist>
|
||||
<tests.rest.spec>${tests.rest.spec}</tests.rest.spec>
|
||||
<tests.network>${tests.network}</tests.network>
|
||||
<tests.cluster>${tests.cluster}</tests.cluster>
|
||||
<tests.heap.size>${tests.heap.size}</tests.heap.size>
|
||||
<tests.filter>${tests.filter}</tests.filter>
|
||||
<tests.timewarp>${tests.timewarp}</tests.timewarp>
|
||||
<es.node.local>${env.ES_TEST_LOCAL}</es.node.local>
|
||||
<es.node.mode>${es.node.mode}</es.node.mode>
|
||||
<es.logger.level>${es.logger.level}</es.logger.level>
|
||||
<tests.security.manager>${tests.security.manager}</tests.security.manager>
|
||||
<tests.compatibility>${tests.compatibility}</tests.compatibility>
|
||||
<java.awt.headless>true</java.awt.headless>
|
||||
<!-- everything below is for security manager / test.policy -->
|
||||
<junit4.tempDir>${project.build.directory}</junit4.tempDir>
|
||||
<java.security.policy>${basedir}/tests.policy</java.security.policy>
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<!-- we skip surefire to work with randomized testing above -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.16</version>
|
||||
<configuration>
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>buildnumber-maven-plugin</artifactId>
|
||||
<version>1.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>validate</phase>
|
||||
<goals>
|
||||
<goal>create</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<doCheck>false</doCheck>
|
||||
<doUpdate>false</doUpdate>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>de.thetaphi</groupId>
|
||||
<artifactId>forbiddenapis</artifactId>
|
||||
<version>1.6.1</version>
|
||||
|
||||
<executions>
|
||||
<execution>
|
||||
<id>check-forbidden-apis</id>
|
||||
<configuration>
|
||||
<targetVersion>1.7</targetVersion>
|
||||
<!-- disallow undocumented classes like sun.misc.Unsafe: -->
|
||||
<internalRuntimeForbidden>true</internalRuntimeForbidden>
|
||||
<!-- if the used Java version is too new, don't fail, just do nothing: -->
|
||||
<failOnUnsupportedJava>false</failOnUnsupportedJava>
|
||||
<excludes>
|
||||
<exclude>jsr166e/**</exclude>
|
||||
<exclude>
|
||||
org/elasticsearch/common/lucene/search/Queries$QueryWrapperFilterFactory.class
|
||||
</exclude>
|
||||
<!-- end excludes for valid system-out -->
|
||||
<!-- start excludes for Unsafe -->
|
||||
<exclude>org/elasticsearch/common/util/UnsafeUtils.class</exclude>
|
||||
<!-- end excludes for Unsafe -->
|
||||
<!-- start excludes for Math.abs -->
|
||||
<exclude>org/elasticsearch/common/util/MathUtils.class</exclude>
|
||||
<exclude>org/elasticsearch/common/math/UnboxedMathUtils.class</exclude>
|
||||
<exclude>org/elasticsearch/cluster/routing/operation/plain/PlainOperationRouting.class
|
||||
</exclude>
|
||||
<!-- end excludes for Math.abs -->
|
||||
<!-- start exclude for FilteredQuery -->
|
||||
<exclude>org/elasticsearch/common/lucene/search/XFilteredQuery.class</exclude>
|
||||
<!-- end exclude for FilteredQuery -->
|
||||
<!-- start exclude for Channels utility class -->
|
||||
<exclude>org/elasticsearch/common/io/Channels.class</exclude>
|
||||
<!-- end exclude for Channels -->
|
||||
</excludes>
|
||||
<bundledSignatures>
|
||||
<!-- This will automatically choose the right signatures based on 'targetVersion': -->
|
||||
<bundledSignature>jdk-unsafe</bundledSignature>
|
||||
<bundledSignature>jdk-deprecated</bundledSignature>
|
||||
<bundledSignature>jdk-system-out</bundledSignature>
|
||||
</bundledSignatures>
|
||||
<signaturesFiles>
|
||||
<signaturesFile>core-signatures.txt</signaturesFile>
|
||||
<signaturesFile>all-signatures.txt</signaturesFile>
|
||||
</signaturesFiles>
|
||||
<!--<signatures>${forbidden.signatures}</signatures>-->
|
||||
</configuration>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>check</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>check-forbidden-test-apis</id>
|
||||
<configuration>
|
||||
<targetVersion>1.7</targetVersion>
|
||||
<!-- disallow undocumented classes like sun.misc.Unsafe: -->
|
||||
<internalRuntimeForbidden>true</internalRuntimeForbidden>
|
||||
<!-- if the used Java version is too new, don't fail, just do nothing: -->
|
||||
<failOnUnsupportedJava>false</failOnUnsupportedJava>
|
||||
<bundledSignatures>
|
||||
<!-- This will automatically choose the right signatures based on 'targetVersion': -->
|
||||
<bundledSignature>jdk-unsafe</bundledSignature>
|
||||
<bundledSignature>jdk-deprecated</bundledSignature>
|
||||
</bundledSignatures>
|
||||
<signaturesFiles>
|
||||
<signaturesFile>test-signatures.txt</signaturesFile>
|
||||
<signaturesFile>all-signatures.txt</signaturesFile>
|
||||
</signaturesFiles>
|
||||
<!--<signatures>${forbidden.test.signatures}</signatures>-->
|
||||
</configuration>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>testCheck</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<profiles>
|
||||
|
|
|
@ -22,12 +22,12 @@
|
|||
</excludes>
|
||||
</dependencySet>
|
||||
<dependencySet>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<useTransitiveDependencies>false</useTransitiveDependencies>
|
||||
<includes>
|
||||
<include>javax.mail:mail</include>
|
||||
<include>javax.activation:activation</include>
|
||||
</includes>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<useTransitiveDependencies>false</useTransitiveDependencies>
|
||||
<includes>
|
||||
<include>javax.mail:mail</include>
|
||||
<include>javax.activation:activation</include>
|
||||
</includes>
|
||||
</dependencySet>
|
||||
</dependencySets>
|
||||
</assembly>
|
||||
|
|
|
@ -6,18 +6,19 @@
|
|||
package org.elasticsearch.watcher;
|
||||
|
||||
|
||||
import org.elasticsearch.common.collect.ImmutableList;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.inject.SpawnModules;
|
||||
import org.elasticsearch.watcher.transport.WatcherTransportModule;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
|
||||
public class TransportClientWatcherModule extends AbstractModule implements SpawnModules {
|
||||
|
||||
@Override
|
||||
public Iterable<? extends Module> spawnModules() {
|
||||
return ImmutableList.of(new WatcherTransportModule());
|
||||
return Collections.singleton(new WatcherTransportModule());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,12 +9,12 @@ import org.elasticsearch.common.io.FastStringReader;
|
|||
import org.elasticsearch.common.io.Streams;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.joda.time.format.ISODateTimeFormat;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.format.ISODateTimeFormat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.elasticsearch.common.joda.time.DateTimeZone.UTC;
|
||||
/**
|
||||
*/
|
||||
public class WatcherBuild {
|
||||
|
@ -37,7 +37,7 @@ public class WatcherBuild {
|
|||
}
|
||||
String gitTimestampRaw = props.getProperty("timestamp");
|
||||
if (gitTimestampRaw != null) {
|
||||
timestamp = ISODateTimeFormat.dateTimeNoMillis().withZone(UTC).print(Long.parseLong(gitTimestampRaw));
|
||||
timestamp = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC).print(Long.parseLong(gitTimestampRaw));
|
||||
}
|
||||
versionName = props.getProperty("version", "NA");
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
package org.elasticsearch.watcher;
|
||||
|
||||
|
||||
import org.elasticsearch.common.collect.ImmutableList;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.inject.SpawnModules;
|
||||
|
@ -32,6 +31,8 @@ import org.elasticsearch.watcher.transport.WatcherTransportModule;
|
|||
import org.elasticsearch.watcher.trigger.TriggerModule;
|
||||
import org.elasticsearch.watcher.watch.WatchModule;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
public class WatcherModule extends AbstractModule implements SpawnModules {
|
||||
|
||||
|
@ -43,7 +44,7 @@ public class WatcherModule extends AbstractModule implements SpawnModules {
|
|||
|
||||
@Override
|
||||
public Iterable<? extends Module> spawnModules() {
|
||||
return ImmutableList.of(
|
||||
return Arrays.asList(
|
||||
new InitializingModule(),
|
||||
new LicenseModule(),
|
||||
new WatchModule(),
|
||||
|
|
|
@ -5,23 +5,26 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.collect.ImmutableList;
|
||||
import org.elasticsearch.common.component.LifecycleComponent;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.plugins.AbstractPlugin;
|
||||
import org.elasticsearch.script.ScriptModes;
|
||||
import org.elasticsearch.script.ScriptModule;
|
||||
import org.elasticsearch.watcher.actions.email.service.InternalEmailService;
|
||||
import org.elasticsearch.watcher.history.HistoryModule;
|
||||
import org.elasticsearch.watcher.license.LicenseService;
|
||||
import org.elasticsearch.watcher.support.Script;
|
||||
import org.elasticsearch.watcher.support.http.HttpClient;
|
||||
import org.elasticsearch.watcher.support.init.InitializingService;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.watcher.support.validation.WatcherSettingsValidation;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
|
||||
public class WatcherPlugin extends AbstractPlugin {
|
||||
|
||||
|
@ -56,6 +59,7 @@ public class WatcherPlugin extends AbstractPlugin {
|
|||
ImmutableList.<Class<? extends Module>>of(WatcherModule.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<Class<? extends LifecycleComponent>> services() {
|
||||
if (!enabled || transportClient) {
|
||||
|
@ -75,7 +79,7 @@ public class WatcherPlugin extends AbstractPlugin {
|
|||
@Override
|
||||
public Settings additionalSettings() {
|
||||
if (!enabled || transportClient) {
|
||||
return ImmutableSettings.EMPTY;
|
||||
return Settings.EMPTY;
|
||||
}
|
||||
Settings additionalSettings = settingsBuilder()
|
||||
.put(HistoryModule.additionalSettings(settings))
|
||||
|
@ -84,6 +88,10 @@ public class WatcherPlugin extends AbstractPlugin {
|
|||
return additionalSettings;
|
||||
}
|
||||
|
||||
public void onModule(ScriptModule module) {
|
||||
module.registerScriptContext(ScriptServiceProxy.INSTANCE);
|
||||
}
|
||||
|
||||
public static boolean watcherEnabled(Settings settings) {
|
||||
return settings.getAsBoolean(ENABLED_SETTING, true);
|
||||
}
|
||||
|
|
|
@ -6,13 +6,13 @@
|
|||
package org.elasticsearch.watcher;
|
||||
|
||||
|
||||
import org.elasticsearch.ElasticsearchIllegalStateException;
|
||||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.joda.time.PeriodType;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.PeriodType;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.index.engine.VersionConflictEngineException;
|
||||
|
@ -27,7 +27,6 @@ import org.elasticsearch.watcher.watch.WatchStore;
|
|||
import java.io.IOException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.elasticsearch.common.joda.time.DateTimeZone.UTC;
|
||||
|
||||
public class WatcherService extends AbstractComponent {
|
||||
|
||||
|
@ -156,7 +155,8 @@ public class WatcherService extends AbstractComponent {
|
|||
if (watch == null) {
|
||||
throw new WatcherException("watch [{}] does not exist", id);
|
||||
}
|
||||
if (watch.ack(clock.now(UTC), actionIds)) {
|
||||
// we need to create a safe copy of the status
|
||||
if (watch.ack(clock.now(DateTimeZone.UTC), actionIds)) {
|
||||
try {
|
||||
watchStore.updateStatus(watch);
|
||||
} catch (IOException ioe) {
|
||||
|
@ -165,7 +165,6 @@ public class WatcherService extends AbstractComponent {
|
|||
throw new WatcherException("failed to update the watch [{}] on ack, perhaps it was force deleted", vcee, watch.id());
|
||||
}
|
||||
}
|
||||
// we need to create a safe copy of the status
|
||||
return new WatchStatus(watch.status());
|
||||
} finally {
|
||||
lock.release();
|
||||
|
@ -178,7 +177,7 @@ public class WatcherService extends AbstractComponent {
|
|||
|
||||
private void ensureStarted() {
|
||||
if (state.get() != WatcherState.STARTED) {
|
||||
throw new ElasticsearchIllegalStateException("not started");
|
||||
throw new IllegalStateException("not started");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.actions;
|
||||
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.watcher.license.LicenseService;
|
||||
|
|
|
@ -9,16 +9,16 @@ import org.elasticsearch.common.Nullable;
|
|||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.watcher.WatcherException;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.elasticsearch.common.joda.time.DateTimeZone.UTC;
|
||||
import static org.elasticsearch.watcher.support.WatcherDateTimeUtils.dateTimeFormatter;
|
||||
|
||||
/**
|
||||
|
@ -219,7 +219,7 @@ public class ActionStatus implements ToXContent {
|
|||
private final State state;
|
||||
|
||||
public AckStatus(DateTime timestamp, State state) {
|
||||
this.timestamp = timestamp.toDateTime(UTC);
|
||||
this.timestamp = timestamp.toDateTime(DateTimeZone.UTC);
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
|
@ -289,7 +289,7 @@ public class ActionStatus implements ToXContent {
|
|||
}
|
||||
|
||||
static AckStatus readFrom(StreamInput in) throws IOException {
|
||||
DateTime timestamp = new DateTime(in.readLong(), UTC);
|
||||
DateTime timestamp = new DateTime(in.readLong(), DateTimeZone.UTC);
|
||||
State state = State.resolve(in.readByte());
|
||||
return new AckStatus(timestamp, state);
|
||||
}
|
||||
|
@ -310,7 +310,7 @@ public class ActionStatus implements ToXContent {
|
|||
private final String reason;
|
||||
|
||||
private Execution(DateTime timestamp, boolean successful, String reason) {
|
||||
this.timestamp = timestamp.toDateTime(UTC);
|
||||
this.timestamp = timestamp.toDateTime(DateTimeZone.UTC);
|
||||
this.successful = successful;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
@ -403,12 +403,12 @@ public class ActionStatus implements ToXContent {
|
|||
}
|
||||
|
||||
public static Execution readFrom(StreamInput in) throws IOException {
|
||||
DateTime timestamp = new DateTime(in.readLong(), UTC);
|
||||
DateTime timestamp = new DateTime(in.readLong(), DateTimeZone.UTC);
|
||||
boolean successful = in.readBoolean();
|
||||
if (successful) {
|
||||
return successful(timestamp);
|
||||
}
|
||||
return failure(timestamp, in.readSharedString());
|
||||
return failure(timestamp, in.readString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -418,7 +418,7 @@ public class ActionStatus implements ToXContent {
|
|||
private final String reason;
|
||||
|
||||
public Throttle(DateTime timestamp, String reason) {
|
||||
this.timestamp = timestamp.toDateTime(UTC);
|
||||
this.timestamp = timestamp.toDateTime(DateTimeZone.UTC);
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
|
@ -488,7 +488,7 @@ public class ActionStatus implements ToXContent {
|
|||
}
|
||||
|
||||
static Throttle readFrom(StreamInput in) throws IOException {
|
||||
DateTime timestamp = new DateTime(in.readLong(), UTC);
|
||||
DateTime timestamp = new DateTime(in.readLong(), DateTimeZone.UTC);
|
||||
return new Throttle(timestamp, in.readString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ public class ActionWrapper implements ToXContent {
|
|||
transform = transformRegistry.parse(watchId, parser);
|
||||
} else if (Throttler.Field.THROTTLE_PERIOD.match(currentFieldName)) {
|
||||
try {
|
||||
throttlePeriod = WatcherDateTimeUtils.parseTimeValue(parser, null);
|
||||
throttlePeriod = WatcherDateTimeUtils.parseTimeValue(parser, null, Throttler.Field.THROTTLE_PERIOD.toString());
|
||||
} catch (WatcherDateTimeUtils.ParseException pe) {
|
||||
throw new ActionException("could not parse action [{}/{}]. failed to parse field [{}] as time value", pe, watchId, actionId, currentFieldName);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
package org.elasticsearch.watcher.actions.email.service;
|
||||
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.watcher.support.secret.SecretService;
|
||||
|
||||
|
@ -153,7 +153,7 @@ public class Account {
|
|||
* "unreadable" keys. We'll then use these settings when crea
|
||||
*/
|
||||
static Properties loadSmtpProperties(Settings settings) {
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put(settings);
|
||||
Settings.Builder builder = Settings.builder().put(settings);
|
||||
replace(builder, "connection_timeout", "connectiontimeout");
|
||||
replace(builder, "write_timeout", "writetimeout");
|
||||
replace(builder, "local_address", "localaddress");
|
||||
|
@ -174,7 +174,7 @@ public class Account {
|
|||
return props;
|
||||
}
|
||||
|
||||
static void replace(ImmutableSettings.Builder settings, String currentKey, String newKey) {
|
||||
static void replace(Settings.Builder settings, String currentKey, String newKey) {
|
||||
String value = settings.remove(currentKey);
|
||||
if (value != null) {
|
||||
settings.put(newKey, value);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.actions.email.service;
|
||||
|
||||
import org.elasticsearch.common.SuppressForbidden;
|
||||
import org.elasticsearch.watcher.actions.email.service.support.BodyPartSource;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
@ -71,10 +72,12 @@ public abstract class Attachment extends BodyPartSource {
|
|||
this(id, path.getFileName().toString(), path, contentType);
|
||||
}
|
||||
|
||||
@SuppressForbidden(reason = "uses toFile")
|
||||
public File(String id, String name, Path path) {
|
||||
this(id, name, path, fileTypeMap.getContentType(path.toFile()));
|
||||
}
|
||||
|
||||
@SuppressForbidden(reason = "uses toFile")
|
||||
public File(String id, String name, Path path, String contentType) {
|
||||
super(id, name, contentType);
|
||||
this.path = path;
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.actions.email.service;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.base.Charsets;
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
import org.joda.time.DateTime;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.AddressException;
|
||||
|
@ -20,9 +20,9 @@ import javax.mail.internet.InternetAddress;
|
|||
import javax.mail.internet.MimeMessage;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
import static org.elasticsearch.common.joda.time.DateTimeZone.UTC;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -50,7 +50,7 @@ public class Email implements ToXContent {
|
|||
this.from = from;
|
||||
this.replyTo = replyTo;
|
||||
this.priority = priority;
|
||||
this.sentDate = sentDate != null ? sentDate : new DateTime(UTC);
|
||||
this.sentDate = sentDate != null ? sentDate : new DateTime(DateTimeZone.UTC);
|
||||
this.to = to;
|
||||
this.cc = cc;
|
||||
this.bcc = bcc;
|
||||
|
@ -425,7 +425,7 @@ public class Email implements ToXContent {
|
|||
}
|
||||
|
||||
public Address(String address, String personal) throws UnsupportedEncodingException {
|
||||
super(address, personal, Charsets.UTF_8.name());
|
||||
super(address, personal, StandardCharsets.UTF_8.name());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.actions.email.service;
|
||||
|
||||
import org.elasticsearch.common.SuppressForbidden;
|
||||
import org.elasticsearch.watcher.actions.email.service.support.BodyPartSource;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
|
@ -70,10 +71,12 @@ public abstract class Inline extends BodyPartSource {
|
|||
this(id, path.getFileName().toString(), path);
|
||||
}
|
||||
|
||||
@SuppressForbidden(reason = "uses toFile")
|
||||
public File(String id, String name, Path path) {
|
||||
this(id, name, path, fileTypeMap.getContentType(path.toFile()));
|
||||
}
|
||||
|
||||
@SuppressForbidden(reason = "uses toFile")
|
||||
public File(String id, String name, Path path, String contentType) {
|
||||
super(id, name, contentType);
|
||||
this.path = path;
|
||||
|
|
|
@ -5,11 +5,12 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.actions.email.service;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.node.settings.NodeSettingsService;
|
||||
import org.elasticsearch.watcher.shield.WatcherSettingsFilter;
|
||||
|
@ -77,11 +78,19 @@ public class InternalEmailService extends AbstractLifecycleComponent<InternalEma
|
|||
}
|
||||
|
||||
void reset(Settings nodeSettings) {
|
||||
Settings settings = ImmutableSettings.builder()
|
||||
.put(componentSettings)
|
||||
.put(nodeSettings.getComponentSettings(InternalEmailService.class))
|
||||
.build();
|
||||
accounts = createAccounts(settings, logger);
|
||||
Settings.Builder builder = Settings.builder();
|
||||
String prefix = "watcher.actions.email.service";
|
||||
for (String setting : settings.getAsMap().keySet()) {
|
||||
if (setting.startsWith("watcher.actions.email.service")) {
|
||||
builder.put(setting.substring(prefix.length()+1), settings.get(setting));
|
||||
}
|
||||
}
|
||||
for (String setting : nodeSettings.getAsMap().keySet()) {
|
||||
if (setting.startsWith("watcher.actions.email.service")) {
|
||||
builder.put(setting.substring(prefix.length()+1), settings.get(setting));
|
||||
}
|
||||
}
|
||||
accounts = createAccounts(builder.build(), logger);
|
||||
}
|
||||
|
||||
protected Accounts createAccounts(Settings settings, ESLogger logger) {
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.actions.email.service;
|
||||
|
||||
import org.elasticsearch.common.base.Charsets;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
|
@ -16,6 +15,7 @@ import javax.mail.internet.MimeBodyPart;
|
|||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
|
@ -79,15 +79,15 @@ public enum Profile implements ToXContent {
|
|||
|
||||
MimeBodyPart text = new MimeBodyPart();
|
||||
if (email.textBody != null) {
|
||||
text.setText(email.textBody, Charsets.UTF_8.name());
|
||||
text.setText(email.textBody, StandardCharsets.UTF_8.name());
|
||||
} else {
|
||||
text.setText("", Charsets.UTF_8.name());
|
||||
text.setText("", StandardCharsets.UTF_8.name());
|
||||
}
|
||||
alternative.addBodyPart(text);
|
||||
|
||||
if (email.htmlBody != null) {
|
||||
MimeBodyPart html = new MimeBodyPart();
|
||||
html.setText(email.htmlBody, Charsets.UTF_8.name(), "html");
|
||||
html.setText(email.htmlBody, StandardCharsets.UTF_8.name(), "html");
|
||||
alternative.addBodyPart(html);
|
||||
}
|
||||
|
||||
|
@ -199,9 +199,9 @@ public enum Profile implements ToXContent {
|
|||
message.setRecipients(Message.RecipientType.BCC, email.bcc.toArray());
|
||||
}
|
||||
if (email.subject != null) {
|
||||
message.setSubject(email.subject, Charsets.UTF_8.name());
|
||||
message.setSubject(email.subject, StandardCharsets.UTF_8.name());
|
||||
} else {
|
||||
message.setSubject("", Charsets.UTF_8.name());
|
||||
message.setSubject("", StandardCharsets.UTF_8.name());
|
||||
}
|
||||
|
||||
return message;
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.elasticsearch.action.index.IndexRequest;
|
|||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.mapper.internal.TimestampFieldMapper;
|
||||
import org.elasticsearch.watcher.actions.Action;
|
||||
import org.elasticsearch.watcher.actions.ExecutableAction;
|
||||
|
@ -108,7 +109,7 @@ public class ExecutableIndexAction extends ExecutableAction<IndexAction> {
|
|||
indexResponseToXContent(jsonBuilder, response);
|
||||
}
|
||||
jsonBuilder.endArray();
|
||||
return new IndexAction.Result.Success(new XContentSource(jsonBuilder.bytes()));
|
||||
return new IndexAction.Result.Success(new XContentSource(jsonBuilder.bytes(), XContentType.JSON));
|
||||
}
|
||||
|
||||
static void indexResponseToXContent(XContentBuilder builder, IndexResponse response) throws IOException {
|
||||
|
|
|
@ -8,6 +8,8 @@ package org.elasticsearch.watcher.actions.index;
|
|||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.watcher.actions.Action;
|
||||
import org.elasticsearch.watcher.support.xcontent.XContentSource;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
package org.elasticsearch.watcher.actions.throttler;
|
||||
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.joda.time.PeriodType;
|
||||
import org.joda.time.PeriodType;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.watcher.actions.ActionStatus;
|
||||
import org.elasticsearch.watcher.execution.WatchExecutionContext;
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.watcher.client;
|
||||
|
||||
import org.elasticsearch.action.ActionRequest;
|
||||
import org.elasticsearch.action.ActionRequestBuilder;
|
||||
import org.elasticsearch.action.ActionResponse;
|
||||
import org.elasticsearch.action.ClientAction;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
||||
/**
|
||||
* All watcher related actions should extend this base class.
|
||||
*/
|
||||
public abstract class WatcherAction<Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, Client>> extends ClientAction<Request, Response, RequestBuilder> {
|
||||
|
||||
protected WatcherAction(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
}
|
|
@ -8,6 +8,7 @@ package org.elasticsearch.watcher.client;
|
|||
import org.elasticsearch.action.ActionFuture;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.watcher.transport.actions.ack.AckWatchAction;
|
||||
import org.elasticsearch.watcher.transport.actions.ack.AckWatchRequest;
|
||||
|
@ -42,7 +43,7 @@ import org.elasticsearch.watcher.transport.actions.stats.WatcherStatsResponse;
|
|||
*/
|
||||
public class WatcherClient {
|
||||
|
||||
private final Client client;
|
||||
private final ElasticsearchClient client;
|
||||
|
||||
@Inject
|
||||
public WatcherClient(Client client) {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.condition;
|
||||
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
|
|
@ -7,20 +7,19 @@ package org.elasticsearch.watcher.condition.compare;
|
|||
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
import org.joda.time.DateTime;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.watcher.condition.Condition;
|
||||
import org.elasticsearch.watcher.support.WatcherDateTimeUtils;
|
||||
import org.elasticsearch.watcher.support.xcontent.WatcherXContentUtils;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.elasticsearch.common.joda.time.DateTimeZone.UTC;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -263,7 +262,7 @@ public class CompareCondition implements Condition {
|
|||
return null;
|
||||
}
|
||||
} else if (v1 instanceof Number){
|
||||
v1 = new DateTime(((Number) v1).longValue(), UTC);
|
||||
v1 = new DateTime(((Number) v1).longValue(), DateTimeZone.UTC);
|
||||
} else {
|
||||
// cannot convert to date...
|
||||
return null;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.condition.compare;
|
||||
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
import org.joda.time.DateTime;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.watcher.actions.email.DataAttachment;
|
||||
import org.elasticsearch.watcher.condition.ExecutableCondition;
|
||||
|
@ -14,6 +14,7 @@ import org.elasticsearch.watcher.support.Variables;
|
|||
import org.elasticsearch.watcher.support.WatcherDateTimeUtils;
|
||||
import org.elasticsearch.watcher.support.clock.Clock;
|
||||
import org.elasticsearch.watcher.support.xcontent.ObjectPath;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
@ -21,7 +22,6 @@ import java.util.Map;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.elasticsearch.common.joda.time.DateTimeZone.UTC;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -64,7 +64,7 @@ public class ExecutableCompareCondition extends ExecutableCondition<CompareCondi
|
|||
Matcher matcher = DATE_MATH_PATTERN.matcher((String) configuredValue);
|
||||
if (matcher.matches()) {
|
||||
String dateMath = matcher.group(1);
|
||||
configuredValue = WatcherDateTimeUtils.parseDateMath(dateMath, UTC, clock);
|
||||
configuredValue = WatcherDateTimeUtils.parseDateMath(dateMath, DateTimeZone.UTC, clock);
|
||||
resolvedValues.put(dateMath, WatcherDateTimeUtils.formatDate((DateTime) configuredValue));
|
||||
} else {
|
||||
// checking if the given value is a path expression
|
||||
|
|
|
@ -5,13 +5,11 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.execution;
|
||||
|
||||
import org.elasticsearch.ElasticsearchIllegalStateException;
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
|
||||
|
@ -28,13 +26,14 @@ import org.elasticsearch.watcher.trigger.TriggerEvent;
|
|||
import org.elasticsearch.watcher.watch.Watch;
|
||||
import org.elasticsearch.watcher.watch.WatchLockService;
|
||||
import org.elasticsearch.watcher.watch.WatchStore;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.elasticsearch.common.joda.time.DateTimeZone.UTC;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -65,7 +64,7 @@ public class ExecutionService extends AbstractComponent {
|
|||
this.watchStore = watchStore;
|
||||
this.watchLockService = watchLockService;
|
||||
this.clock = clock;
|
||||
this.defaultThrottlePeriod = componentSettings.getAsTime("default_throttle_period", TimeValue.timeValueSeconds(5));
|
||||
this.defaultThrottlePeriod = settings.getAsTime("watcher.execution.default_throttle_period", TimeValue.timeValueSeconds(5));
|
||||
maxStopTimeout = settings.getAsTime(DEFAULT_MAX_STOP_TIMEOUT_SETTING, DEFAULT_MAX_STOP_TIMEOUT);
|
||||
if (ExecutionService.this.defaultThrottlePeriod.millis() < 0) {
|
||||
settingsValidation.addError("watcher.execution.default_throttle_period", "time value cannot be negative");
|
||||
|
@ -162,12 +161,12 @@ public class ExecutionService extends AbstractComponent {
|
|||
|
||||
void processEventsAsync(Iterable<TriggerEvent> events) throws WatcherException {
|
||||
if (!started.get()) {
|
||||
throw new ElasticsearchIllegalStateException("not started");
|
||||
throw new IllegalStateException("not started");
|
||||
}
|
||||
final LinkedList<TriggeredWatch> triggeredWatches = new LinkedList<>();
|
||||
final LinkedList<TriggeredExecutionContext> contexts = new LinkedList<>();
|
||||
|
||||
DateTime now = clock.now(UTC);
|
||||
DateTime now = clock.now(DateTimeZone.UTC);
|
||||
for (TriggerEvent event : events) {
|
||||
Watch watch = watchStore.get(event.jobName());
|
||||
if (watch == null) {
|
||||
|
@ -203,12 +202,12 @@ public class ExecutionService extends AbstractComponent {
|
|||
|
||||
void processEventsSync(Iterable<TriggerEvent> events) throws WatcherException {
|
||||
if (!started.get()) {
|
||||
throw new ElasticsearchIllegalStateException("not started");
|
||||
throw new IllegalStateException("not started");
|
||||
}
|
||||
final LinkedList<TriggeredWatch> triggeredWatches = new LinkedList<>();
|
||||
final LinkedList<TriggeredExecutionContext> contexts = new LinkedList<>();
|
||||
|
||||
DateTime now = clock.now(UTC);
|
||||
DateTime now = clock.now(DateTimeZone.UTC);
|
||||
for (TriggerEvent event : events) {
|
||||
Watch watch = watchStore.get(event.jobName());
|
||||
if (watch == null) {
|
||||
|
@ -351,7 +350,7 @@ public class ExecutionService extends AbstractComponent {
|
|||
historyStore.put(record);
|
||||
triggeredWatchStore.delete(triggeredWatch.id());
|
||||
} else {
|
||||
TriggeredExecutionContext ctx = new TriggeredExecutionContext(watch, clock.now(UTC), triggeredWatch.triggerEvent(), defaultThrottlePeriod);
|
||||
TriggeredExecutionContext ctx = new TriggeredExecutionContext(watch, clock.now(DateTimeZone.UTC), triggeredWatch.triggerEvent(), defaultThrottlePeriod);
|
||||
executeAsync(ctx, triggeredWatch);
|
||||
counter++;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
package org.elasticsearch.watcher.execution;
|
||||
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.util.concurrent.EsExecutors;
|
||||
import org.elasticsearch.common.util.concurrent.EsThreadPoolExecutor;
|
||||
|
@ -28,7 +28,7 @@ public class InternalWatchExecutor implements WatchExecutor {
|
|||
if (!settings.names().isEmpty()) {
|
||||
// the TP is already configured in the node settings
|
||||
// no need for additional settings
|
||||
return ImmutableSettings.EMPTY;
|
||||
return Settings.EMPTY;
|
||||
}
|
||||
int availableProcessors = EsExecutors.boundedNumberOfProcessors(nodeSettings);
|
||||
return new ThreadPoolSettingsBuilder.Fixed(THREAD_POOL_NAME)
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.execution;
|
||||
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.joda.time.DateTime;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.watcher.actions.Action;
|
||||
import org.elasticsearch.watcher.actions.ActionWrapper;
|
||||
|
@ -14,11 +14,10 @@ import org.elasticsearch.watcher.condition.Condition;
|
|||
import org.elasticsearch.watcher.input.Input;
|
||||
import org.elasticsearch.watcher.trigger.manual.ManualTriggerEvent;
|
||||
import org.elasticsearch.watcher.watch.Watch;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.common.joda.time.DateTimeZone.UTC;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class ManualExecutionContext extends WatchExecutionContext {
|
||||
|
@ -147,7 +146,7 @@ public class ManualExecutionContext extends WatchExecutionContext {
|
|||
|
||||
public ManualExecutionContext build() {
|
||||
if (executionTime == null) {
|
||||
executionTime = DateTime.now(UTC);
|
||||
executionTime = DateTime.now(DateTimeZone.UTC);
|
||||
}
|
||||
return new ManualExecutionContext(watch, knownWatch, executionTime, triggerEvent, defaultThrottlePeriod, inputResult, conditionResult, actionModes.build(), recordExecution);
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ package org.elasticsearch.watcher.execution;
|
|||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.io.stream.Streamable;
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
import org.elasticsearch.common.joda.time.DateTimeZone;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.execution;
|
||||
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.watcher.trigger.TriggerEvent;
|
||||
import org.elasticsearch.watcher.watch.Watch;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
|
|
@ -20,10 +20,8 @@ import org.elasticsearch.action.search.SearchResponse;
|
|||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.cluster.ClusterState;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.collect.ImmutableList;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
|
@ -63,24 +61,24 @@ public class TriggeredWatchStore extends AbstractComponent {
|
|||
@Inject
|
||||
public TriggeredWatchStore(Settings settings, ClientProxy client, TemplateUtils templateUtils, TriggeredWatch.Parser triggeredWatchParser) {
|
||||
super(settings);
|
||||
this.scrollSize = componentSettings.getAsInt("scroll.size", 100);
|
||||
this.scrollSize = settings.getAsInt("watcher.execution.scroll.size", 100);
|
||||
this.client = client;
|
||||
this.scrollTimeout = componentSettings.getAsTime("scroll.timeout", TimeValue.timeValueSeconds(30));
|
||||
this.scrollTimeout = settings.getAsTime("watcher.execution.scroll.timeout", TimeValue.timeValueSeconds(30));
|
||||
this.templateUtils = templateUtils;
|
||||
this.customIndexSettings = updateTriggerWatchesSettings(settings);
|
||||
this.triggeredWatchParser = triggeredWatchParser;
|
||||
}
|
||||
|
||||
private Settings updateTriggerWatchesSettings(Settings nodeSettings) {
|
||||
Settings newSettings = ImmutableSettings.builder()
|
||||
Settings newSettings = Settings.builder()
|
||||
.put(nodeSettings.getAsSettings("watcher.triggered_watches.index"))
|
||||
.build();
|
||||
if (newSettings.names().isEmpty()) {
|
||||
return ImmutableSettings.EMPTY;
|
||||
return Settings.EMPTY;
|
||||
}
|
||||
|
||||
// Filter out forbidden settings:
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder();
|
||||
Settings.Builder builder = Settings.builder();
|
||||
for (Map.Entry<String, String> entry : newSettings.getAsMap().entrySet()) {
|
||||
String name = "index." + entry.getKey();
|
||||
if (forbiddenIndexSettings.contains(name)) {
|
||||
|
@ -161,7 +159,7 @@ public class TriggeredWatchStore extends AbstractComponent {
|
|||
public void putAll(final List<TriggeredWatch> triggeredWatches, final ActionListener<List<Integer>> listener) throws TriggeredWatchException {
|
||||
|
||||
if (triggeredWatches.isEmpty()) {
|
||||
listener.onResponse(ImmutableList.<Integer>of());
|
||||
listener.onResponse(Collections.EMPTY_LIST);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -169,7 +167,7 @@ public class TriggeredWatchStore extends AbstractComponent {
|
|||
put(triggeredWatches.get(0), new ActionListener<Boolean>() {
|
||||
@Override
|
||||
public void onResponse(Boolean success) {
|
||||
listener.onResponse(ImmutableList.of(0));
|
||||
listener.onResponse(Collections.singletonList(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.execution;
|
||||
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
|
||||
import org.elasticsearch.watcher.actions.ActionWrapper;
|
||||
|
@ -18,6 +17,7 @@ import org.elasticsearch.watcher.transform.Transform;
|
|||
import org.elasticsearch.watcher.trigger.TriggerEvent;
|
||||
import org.elasticsearch.watcher.watch.Payload;
|
||||
import org.elasticsearch.watcher.watch.Watch;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
|
|
@ -7,16 +7,14 @@ package org.elasticsearch.watcher.execution;
|
|||
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.watcher.actions.ExecutableActions;
|
||||
import org.elasticsearch.watcher.condition.Condition;
|
||||
import org.elasticsearch.watcher.condition.ConditionRegistry;
|
||||
import org.elasticsearch.watcher.input.Input;
|
||||
import org.elasticsearch.watcher.input.InputRegistry;
|
||||
import org.elasticsearch.watcher.support.WatcherDateTimeUtils;
|
||||
import org.elasticsearch.watcher.transform.Transform;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
|
|
@ -8,12 +8,12 @@ package org.elasticsearch.watcher.execution;
|
|||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.io.stream.Streamable;
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
import org.elasticsearch.common.joda.time.DateTimeZone;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.watcher.actions.ActionWrapper;
|
||||
import org.elasticsearch.watcher.actions.ExecutableActions;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.execution;
|
||||
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
import org.elasticsearch.common.joda.time.format.DateTimeFormatter;
|
||||
import org.elasticsearch.common.joda.time.format.ISODateTimeFormat;
|
||||
import org.elasticsearch.watcher.WatcherException;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
import org.joda.time.format.ISODateTimeFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -14,10 +14,9 @@ import org.elasticsearch.cluster.settings.ClusterDynamicSettings;
|
|||
import org.elasticsearch.cluster.settings.DynamicSettings;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
import org.elasticsearch.common.joda.time.format.DateTimeFormat;
|
||||
import org.elasticsearch.common.joda.time.format.DateTimeFormatter;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.node.settings.NodeSettingsService;
|
||||
|
@ -52,7 +51,7 @@ public class HistoryStore extends AbstractComponent implements NodeSettingsServi
|
|||
private final Lock stopLock = readWriteLock.writeLock();
|
||||
private final AtomicBoolean started = new AtomicBoolean(false);
|
||||
|
||||
private volatile Settings customIndexSettings = ImmutableSettings.EMPTY;
|
||||
private volatile Settings customIndexSettings = Settings.EMPTY;
|
||||
|
||||
@Inject
|
||||
public HistoryStore(Settings settings, ClientProxy client, TemplateUtils templateUtils, NodeSettingsService nodeSettingsService,
|
||||
|
@ -73,7 +72,7 @@ public class HistoryStore extends AbstractComponent implements NodeSettingsServi
|
|||
}
|
||||
|
||||
private void updateHistorySettings(Settings settings, boolean updateIndexTemplate) {
|
||||
Settings newSettings = ImmutableSettings.builder()
|
||||
Settings newSettings = Settings.builder()
|
||||
.put(settings.getAsSettings("watcher.history.index"))
|
||||
.build();
|
||||
if (newSettings.names().isEmpty()) {
|
||||
|
@ -81,7 +80,7 @@ public class HistoryStore extends AbstractComponent implements NodeSettingsServi
|
|||
}
|
||||
|
||||
boolean changed = false;
|
||||
ImmutableSettings.Builder builder = ImmutableSettings.builder().put(customIndexSettings);
|
||||
Settings.Builder builder = Settings.builder().put(customIndexSettings);
|
||||
|
||||
for (Map.Entry<String, String> entry : newSettings.getAsMap().entrySet()) {
|
||||
String name = "index." + entry.getKey();
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.input;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.watcher.input.http.HttpInput;
|
||||
import org.elasticsearch.watcher.input.none.NoneInput;
|
||||
|
|
|
@ -5,10 +5,8 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.input;
|
||||
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.input.http;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.collect.ImmutableSet;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.watcher.input.Input;
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.input.search;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.collect.ImmutableSet;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.watcher.input.Input;
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.license;
|
||||
|
||||
import org.elasticsearch.ElasticsearchIllegalStateException;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.license.plugin.LicenseVersion;
|
||||
import org.elasticsearch.watcher.WatcherVersion;
|
||||
|
@ -28,11 +27,11 @@ public class LicenseModule extends AbstractModule {
|
|||
try {
|
||||
getClass().getClassLoader().loadClass("org.elasticsearch.license.plugin.LicensePlugin");
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
throw new ElasticsearchIllegalStateException("watcher plugin requires the license plugin to be installed");
|
||||
throw new IllegalStateException("watcher plugin requires the license plugin to be installed");
|
||||
}
|
||||
|
||||
if (LicenseVersion.CURRENT.before(WatcherVersion.CURRENT.minLicenseCompatibilityVersion)) {
|
||||
throw new ElasticsearchIllegalStateException("watcher [" + WatcherVersion.CURRENT +
|
||||
throw new IllegalStateException("watcher [" + WatcherVersion.CURRENT +
|
||||
"] requires minimum license plugin version [" + WatcherVersion.CURRENT.minLicenseCompatibilityVersion +
|
||||
"], but installed license plugin version is [" + LicenseVersion.CURRENT + "]");
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
package org.elasticsearch.watcher.license;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.collect.ImmutableList;
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.joda.FormatDateTimeFormatter;
|
||||
|
@ -18,6 +17,7 @@ import org.elasticsearch.license.plugin.core.LicensesClientService;
|
|||
import org.elasticsearch.license.plugin.core.LicensesService;
|
||||
import org.elasticsearch.watcher.WatcherPlugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class LicenseService extends AbstractLifecycleComponent<LicenseService> {
|
|||
public LicenseService(Settings settings, LicensesClientService clientService) {
|
||||
super(settings);
|
||||
this.clientService = clientService;
|
||||
this.expirationLoggers = ImmutableList.of(
|
||||
this.expirationLoggers = Arrays.asList(
|
||||
new LicensesService.ExpirationCallback.Pre(days(7), days(30), days(1)) {
|
||||
@Override
|
||||
public void on(License license, LicensesService.ExpirationStatus status) {
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.shield;
|
||||
|
||||
import org.elasticsearch.ElasticsearchIllegalStateException;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.inject.Injector;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -69,7 +68,7 @@ public class ShieldIntegration {
|
|||
// lets check min compatibility
|
||||
ShieldVersion minVersion = ShieldVersion.fromId(minCompatibleShieldVersionId);
|
||||
if (!ShieldVersion.CURRENT.onOrAfter(minVersion)) {
|
||||
throw new ElasticsearchIllegalStateException("watcher [" + WatcherVersion.CURRENT + "] requires " +
|
||||
throw new IllegalStateException("watcher [" + WatcherVersion.CURRENT + "] requires " +
|
||||
"minimum shield plugin version [" + minVersion + "], but installed shield plugin version is " +
|
||||
"[" + ShieldVersion.CURRENT + "]");
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class ShieldSecretService extends AbstractComponent implements SecretServ
|
|||
@Inject
|
||||
public ShieldSecretService(Settings settings, CryptoService cryptoService) {
|
||||
super(settings);
|
||||
this.encryptSensitiveData = componentSettings.getAsBoolean("encrypt_sensitive_data", false);
|
||||
this.encryptSensitiveData = settings.getAsBoolean("watcher.shield.encrypt_sensitive_data", false);
|
||||
this.cryptoService = cryptoService;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ package org.elasticsearch.watcher.support;
|
|||
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -16,6 +15,7 @@ import org.elasticsearch.script.ScriptService.ScriptType;
|
|||
import org.elasticsearch.watcher.WatcherException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -55,7 +55,7 @@ public class Script implements ToXContent {
|
|||
}
|
||||
|
||||
public Map<String, Object> params() {
|
||||
return params != null ? params : ImmutableMap.<String, Object>of();
|
||||
return params != null ? params : Collections.EMPTY_MAP;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,15 +5,14 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support;
|
||||
|
||||
import com.google.common.base.Equivalence;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.watcher.WatcherException;
|
||||
import org.elasticsearch.common.base.Equivalence;
|
||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
|
||||
/**
|
||||
* The only true way today to compare search request object (outside of core) is to
|
||||
|
|
|
@ -10,7 +10,7 @@ import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRespo
|
|||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.io.Streams;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.watcher.WatcherException;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
|
@ -42,10 +42,14 @@ public class TemplateUtils extends AbstractComponent {
|
|||
if (is == null) {
|
||||
throw new FileNotFoundException("Resource [/" + templateName + ".json] not found in classpath");
|
||||
}
|
||||
final byte[] template = Streams.copyToByteArray(is);
|
||||
final byte[] template;
|
||||
try (BytesStreamOutput out = new BytesStreamOutput()) {
|
||||
Streams.copy(is, out);
|
||||
template = out.bytes().toBytes();
|
||||
}
|
||||
PutIndexTemplateRequest request = new PutIndexTemplateRequest(templateName).source(template);
|
||||
if (customSettings != null && customSettings.names().size() > 0) {
|
||||
Settings updatedSettings = ImmutableSettings.builder()
|
||||
Settings updatedSettings = Settings.builder()
|
||||
.put(request.settings())
|
||||
.put(customSettings)
|
||||
.build();
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support;
|
||||
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
||||
/**
|
||||
|
@ -18,7 +18,7 @@ public abstract class ThreadPoolSettingsBuilder<B extends ThreadPoolSettingsBuil
|
|||
}
|
||||
|
||||
protected final String name;
|
||||
private final ImmutableSettings.Builder builder = ImmutableSettings.builder();
|
||||
private final Settings.Builder builder = Settings.builder();
|
||||
|
||||
protected ThreadPoolSettingsBuilder(String name, String type) {
|
||||
this.name = name;
|
||||
|
|
|
@ -10,14 +10,14 @@ import org.elasticsearch.common.io.stream.StreamInput;
|
|||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.joda.DateMathParser;
|
||||
import org.elasticsearch.common.joda.FormatDateTimeFormatter;
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
import org.elasticsearch.common.joda.time.DateTimeZone;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.mapper.core.DateFieldMapper;
|
||||
import org.elasticsearch.watcher.WatcherException;
|
||||
import org.elasticsearch.watcher.support.clock.Clock;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.Callable;
|
||||
|
@ -28,7 +28,7 @@ import java.util.concurrent.TimeUnit;
|
|||
public class WatcherDateTimeUtils {
|
||||
|
||||
public static final FormatDateTimeFormatter dateTimeFormatter = DateFieldMapper.Defaults.DATE_TIME_FORMATTER;
|
||||
public static final DateMathParser dateMathParser = new DateMathParser(dateTimeFormatter, TimeUnit.SECONDS);
|
||||
public static final DateMathParser dateMathParser = new DateMathParser(dateTimeFormatter);
|
||||
|
||||
private WatcherDateTimeUtils() {
|
||||
}
|
||||
|
@ -130,11 +130,11 @@ public class WatcherDateTimeUtils {
|
|||
return in.readBoolean() ? new DateTime(in.readLong(), timeZone) : null;
|
||||
}
|
||||
|
||||
public static TimeValue parseTimeValue(XContentParser parser, TimeValue defaultValue) throws IOException {
|
||||
return parseTimeValue(parser, TimeUnit.MILLISECONDS, defaultValue);
|
||||
public static TimeValue parseTimeValue(XContentParser parser, TimeValue defaultValue, String settingName) throws IOException {
|
||||
return parseTimeValue(parser, TimeUnit.MILLISECONDS, defaultValue, settingName);
|
||||
}
|
||||
|
||||
public static TimeValue parseTimeValue(XContentParser parser, TimeUnit defaultTimeUnit, TimeValue defaultValue) throws IOException {
|
||||
public static TimeValue parseTimeValue(XContentParser parser, TimeUnit defaultTimeUnit, TimeValue defaultValue, String settingName) throws IOException {
|
||||
XContentParser.Token token = parser.currentToken();
|
||||
if (token == XContentParser.Token.VALUE_NULL) {
|
||||
return defaultValue;
|
||||
|
@ -147,11 +147,16 @@ public class WatcherDateTimeUtils {
|
|||
return new TimeValue(millis, defaultTimeUnit);
|
||||
}
|
||||
if (token == XContentParser.Token.VALUE_STRING) {
|
||||
TimeValue value = TimeValue.parseTimeValue(parser.text(), defaultValue);
|
||||
if (value.millis() < 0) {
|
||||
throw new ParseException("could not parse time value [{}]. Time value cannot be negative.", parser.text());
|
||||
try {
|
||||
TimeValue value = TimeValue.parseTimeValue(parser.text(), defaultValue, settingName);
|
||||
if (value.millis() < 0) {
|
||||
throw new ParseException("could not parse time value [{}]. Time value cannot be negative.", parser.text());
|
||||
}
|
||||
return value;
|
||||
} catch (ElasticsearchParseException ex) {
|
||||
throw new ParseException("failed to parse time unit", ex);
|
||||
}
|
||||
return value;
|
||||
|
||||
}
|
||||
throw new ParseException("could not parse time value. expected either a string or a numeric value but found [{}] instead", token);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.elasticsearch.common.ParseField;
|
|||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
import org.joda.time.DateTime;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.*;
|
||||
import org.elasticsearch.watcher.WatcherException;
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support.clock;
|
||||
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
import org.elasticsearch.common.joda.time.DateTimeZone;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support.clock;
|
||||
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
import org.elasticsearch.common.joda.time.DateTimeZone;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support.concurrent;
|
||||
|
||||
import org.elasticsearch.ElasticsearchIllegalStateException;
|
||||
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
|
||||
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
@ -28,7 +27,7 @@ public class FairKeyedLock<T> {
|
|||
while (true) {
|
||||
if (threadLocal.get() != null) {
|
||||
// if we are here, the thread already has the lock
|
||||
throw new ElasticsearchIllegalStateException("Lock already acquired in Thread" + Thread.currentThread().getId()
|
||||
throw new IllegalArgumentException("Lock already acquired in Thread" + Thread.currentThread().getId()
|
||||
+ " for key " + key);
|
||||
}
|
||||
KeyLock perNodeLock = map.get(key);
|
||||
|
@ -55,7 +54,7 @@ public class FairKeyedLock<T> {
|
|||
while (true) {
|
||||
if (threadLocal.get() != null) {
|
||||
// if we are here, the thread already has the lock
|
||||
throw new ElasticsearchIllegalStateException("Lock already acquired in Thread" + Thread.currentThread().getId()
|
||||
throw new IllegalArgumentException("Lock already acquired in Thread" + Thread.currentThread().getId()
|
||||
+ " for key " + key);
|
||||
}
|
||||
KeyLock perNodeLock = map.get(key);
|
||||
|
@ -85,7 +84,7 @@ public class FairKeyedLock<T> {
|
|||
public void release(T key) {
|
||||
KeyLock lock = threadLocal.get();
|
||||
if (lock == null) {
|
||||
throw new ElasticsearchIllegalStateException("Lock not acquired");
|
||||
throw new IllegalArgumentException("Lock not acquired");
|
||||
}
|
||||
release(key, lock);
|
||||
}
|
||||
|
@ -141,7 +140,7 @@ public class FairKeyedLock<T> {
|
|||
public void release(T key) {
|
||||
KeyLock keyLock = threadLocal.get();
|
||||
if (keyLock == null) {
|
||||
throw new ElasticsearchIllegalStateException("Lock not acquired");
|
||||
throw new IllegalArgumentException("Lock not acquired");
|
||||
}
|
||||
try {
|
||||
release(key, keyLock);
|
||||
|
|
|
@ -5,26 +5,27 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support.http;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.ElasticsearchTimeoutException;
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.common.base.Charsets;
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.io.Streams;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.watcher.support.http.auth.ApplicableHttpAuth;
|
||||
import org.elasticsearch.watcher.support.http.auth.HttpAuthRegistry;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.KeyStore;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.List;
|
||||
|
@ -56,15 +57,17 @@ public class HttpClient extends AbstractLifecycleComponent<HttpClient> {
|
|||
static final String SETTINGS_SSL_SHIELD_TRUSTSTORE_ALGORITHM = SETTINGS_SSL_SHIELD_PREFIX + "truststore.algorithm";
|
||||
|
||||
private final HttpAuthRegistry httpAuthRegistry;
|
||||
private final Environment env;
|
||||
private final TimeValue defaultConnectionTimeout;
|
||||
private final TimeValue defaultReadTimeout;
|
||||
|
||||
private SSLSocketFactory sslSocketFactory;
|
||||
|
||||
@Inject
|
||||
public HttpClient(Settings settings, HttpAuthRegistry httpAuthRegistry) {
|
||||
public HttpClient(Settings settings, HttpAuthRegistry httpAuthRegistry, Environment env) {
|
||||
super(settings);
|
||||
this.httpAuthRegistry = httpAuthRegistry;
|
||||
this.env = env;
|
||||
defaultConnectionTimeout = settings.getAsTime("watcher.http.default_connection_timeout", TimeValue.timeValueSeconds(10));
|
||||
defaultReadTimeout = settings.getAsTime("watcher.http.default_read_timeout", TimeValue.timeValueSeconds(10));
|
||||
}
|
||||
|
@ -139,10 +142,10 @@ public class HttpClient extends AbstractLifecycleComponent<HttpClient> {
|
|||
applicableAuth.apply(urlConnection);
|
||||
}
|
||||
urlConnection.setUseCaches(false);
|
||||
urlConnection.setRequestProperty("Accept-Charset", Charsets.UTF_8.name());
|
||||
urlConnection.setRequestProperty("Accept-Charset", StandardCharsets.UTF_8.name());
|
||||
if (request.body() != null) {
|
||||
urlConnection.setDoOutput(true);
|
||||
byte[] bytes = request.body().getBytes(Charsets.UTF_8.name());
|
||||
byte[] bytes = request.body().getBytes(StandardCharsets.UTF_8.name());
|
||||
urlConnection.setRequestProperty("Content-Length", String.valueOf(bytes.length));
|
||||
urlConnection.getOutputStream().write(bytes);
|
||||
urlConnection.getOutputStream().close();
|
||||
|
@ -167,7 +170,11 @@ public class HttpClient extends AbstractLifecycleComponent<HttpClient> {
|
|||
}
|
||||
logger.debug("http status code [{}]", statusCode);
|
||||
if (statusCode < 400) {
|
||||
byte[] body = Streams.copyToByteArray(urlConnection.getInputStream());
|
||||
final byte[] body;
|
||||
try (InputStream inputStream = urlConnection.getInputStream();ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
||||
Streams.copy(inputStream, outputStream);
|
||||
body = outputStream.toByteArray();
|
||||
}
|
||||
return new HttpResponse(statusCode, body, responseHeaders.build());
|
||||
}
|
||||
return new HttpResponse(statusCode, responseHeaders.build());
|
||||
|
@ -202,8 +209,8 @@ public class HttpClient extends AbstractLifecycleComponent<HttpClient> {
|
|||
logger.debug("using protocol [{}], keyStore [{}], keyStoreAlgorithm [{}], trustStore [{}] and trustAlgorithm [{}]", sslContextProtocol, keyStore, keyStoreAlgorithm, trustStore, trustStoreAlgorithm);
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance(sslContextProtocol);
|
||||
KeyManager[] keyManagers = keyManagers(keyStore, keyStorePassword, keyStoreAlgorithm, keyPassword);
|
||||
TrustManager[] trustManagers = trustManagers(trustStore, trustStorePassword, trustStoreAlgorithm);
|
||||
KeyManager[] keyManagers = keyManagers(env, keyStore, keyStorePassword, keyStoreAlgorithm, keyPassword);
|
||||
TrustManager[] trustManagers = trustManagers(env, trustStore, trustStorePassword, trustStoreAlgorithm);
|
||||
sslContext.init(keyManagers, trustManagers, new SecureRandom());
|
||||
return sslContext.getSocketFactory();
|
||||
} catch (Exception e) {
|
||||
|
@ -215,11 +222,11 @@ public class HttpClient extends AbstractLifecycleComponent<HttpClient> {
|
|||
return sslSocketFactory;
|
||||
}
|
||||
|
||||
private static KeyManager[] keyManagers(String keyStore, String keyStorePassword, String keyStoreAlgorithm, String keyPassword) {
|
||||
private static KeyManager[] keyManagers(Environment env, String keyStore, String keyStorePassword, String keyStoreAlgorithm, String keyPassword) {
|
||||
if (keyStore == null) {
|
||||
return null;
|
||||
}
|
||||
Path path = Paths.get(keyStore);
|
||||
Path path = env.homeFile().resolve(keyStore);
|
||||
if (Files.notExists(path)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -237,12 +244,12 @@ public class HttpClient extends AbstractLifecycleComponent<HttpClient> {
|
|||
}
|
||||
}
|
||||
|
||||
private static TrustManager[] trustManagers(String trustStore, String trustStorePassword, String trustStoreAlgorithm) {
|
||||
private static TrustManager[] trustManagers(Environment env, String trustStore, String trustStorePassword, String trustStoreAlgorithm) {
|
||||
try {
|
||||
// Load TrustStore
|
||||
KeyStore ks = null;
|
||||
if (trustStore != null) {
|
||||
Path trustStorePath = Paths.get(trustStore);
|
||||
Path trustStorePath = env.homeFile().resolve(trustStore);
|
||||
if (Files.exists(trustStorePath)) {
|
||||
ks = readKeystore(trustStorePath, trustStorePassword);
|
||||
}
|
||||
|
|
|
@ -5,12 +5,13 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support.http;
|
||||
|
||||
import org.elasticsearch.common.collect.ImmutableList;
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.inject.SpawnModules;
|
||||
import org.elasticsearch.watcher.support.http.auth.AuthModule;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -18,7 +19,7 @@ public class HttpClientModule extends AbstractModule implements SpawnModules {
|
|||
|
||||
@Override
|
||||
public Iterable<? extends Module> spawnModules() {
|
||||
return ImmutableList.of(new AuthModule());
|
||||
return Collections.singletonList(new AuthModule());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support.http;
|
||||
|
||||
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
|
@ -46,7 +45,7 @@ public enum HttpMethod implements ToXContent {
|
|||
case "DELETE":
|
||||
return DELETE;
|
||||
default:
|
||||
throw new ElasticsearchIllegalArgumentException("unsupported http method [" + value + "]");
|
||||
throw new IllegalArgumentException("unsupported http method [" + value + "]");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support.http;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
|
@ -206,13 +206,13 @@ public class HttpRequest implements ToXContent {
|
|||
builder.auth(httpAuthRegistry.parse(parser));
|
||||
} else if (Field.CONNECTION_TIMEOUT.match(currentFieldName)) {
|
||||
try {
|
||||
builder.connectionTimeout(WatcherDateTimeUtils.parseTimeValue(parser, null));
|
||||
builder.connectionTimeout(WatcherDateTimeUtils.parseTimeValue(parser, null, Field.CONNECTION_TIMEOUT.toString()));
|
||||
} catch (WatcherDateTimeUtils.ParseException pe) {
|
||||
throw new ParseException("could not parse http request. invalid time value for [{}] field", pe, currentFieldName);
|
||||
}
|
||||
} else if (Field.READ_TIMEOUT.match(currentFieldName)) {
|
||||
try {
|
||||
builder.readTimeout(WatcherDateTimeUtils.parseTimeValue(parser, null));
|
||||
builder.readTimeout(WatcherDateTimeUtils.parseTimeValue(parser, null, Field.READ_TIMEOUT.toString()));
|
||||
} catch (WatcherDateTimeUtils.ParseException pe) {
|
||||
throw new ParseException("could not parse http request. invalid time value for [{}] field", pe, currentFieldName);
|
||||
}
|
||||
|
|
|
@ -5,11 +5,10 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support.http;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.collect.MapBuilder;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.netty.handler.codec.http.HttpHeaders;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
@ -21,6 +20,7 @@ import org.elasticsearch.watcher.support.http.auth.HttpAuth;
|
|||
import org.elasticsearch.watcher.support.http.auth.HttpAuthRegistry;
|
||||
import org.elasticsearch.watcher.support.template.Template;
|
||||
import org.elasticsearch.watcher.support.template.TemplateEngine;
|
||||
import org.jboss.netty.handler.codec.http.HttpHeaders;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
@ -254,13 +254,13 @@ public class HttpRequestTemplate implements ToXContent {
|
|||
builder.body(parseFieldTemplate(currentFieldName, parser));
|
||||
} else if (Field.CONNECTION_TIMEOUT.match(currentFieldName)) {
|
||||
try {
|
||||
builder.connectionTimeout(WatcherDateTimeUtils.parseTimeValue(parser, null));
|
||||
builder.connectionTimeout(WatcherDateTimeUtils.parseTimeValue(parser, null, Field.CONNECTION_TIMEOUT.toString()));
|
||||
} catch (WatcherDateTimeUtils.ParseException pe) {
|
||||
throw new ParseException("could not parse http request template. invalid time value for [{}] field", pe, currentFieldName);
|
||||
}
|
||||
} else if (Field.READ_TIMEOUT.match(currentFieldName)) {
|
||||
try {
|
||||
builder.readTimeout(WatcherDateTimeUtils.parseTimeValue(parser, null));
|
||||
builder.readTimeout(WatcherDateTimeUtils.parseTimeValue(parser, null, Field.READ_TIMEOUT.toString()));
|
||||
} catch (WatcherDateTimeUtils.ParseException pe) {
|
||||
throw new ParseException("could not parse http request template. invalid time value for [{}] field", pe, currentFieldName);
|
||||
}
|
||||
|
@ -304,7 +304,7 @@ public class HttpRequestTemplate implements ToXContent {
|
|||
private static Template parseFieldTemplate(String field, XContentParser parser) throws IOException {
|
||||
try {
|
||||
return Template.parse(parser);
|
||||
} catch (Template.ParseException pe) {
|
||||
} catch (ParseException pe) {
|
||||
throw new ParseException("could not parse http request template. could not parse value for [{}] field", pe, field);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,16 +5,16 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support.http;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.netty.handler.codec.http.HttpHeaders;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.watcher.WatcherException;
|
||||
import org.jboss.netty.handler.codec.http.HttpHeaders;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support.http;
|
||||
|
||||
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
|
@ -35,7 +34,7 @@ public enum Scheme implements ToXContent {
|
|||
case "https":
|
||||
return HTTPS;
|
||||
default:
|
||||
throw new ElasticsearchIllegalArgumentException("unsupported http scheme [" + value + "]");
|
||||
throw new IllegalArgumentException("unsupported http scheme [" + value + "]");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support.http.auth;
|
||||
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
package org.elasticsearch.watcher.support.http.auth.basic;
|
||||
|
||||
import org.elasticsearch.common.Base64;
|
||||
import org.elasticsearch.common.base.Charsets;
|
||||
import org.elasticsearch.watcher.support.http.auth.ApplicableHttpAuth;
|
||||
import org.elasticsearch.watcher.support.secret.SecretService;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
*/
|
||||
|
@ -24,7 +24,7 @@ public class ApplicableBasicAuth extends ApplicableHttpAuth<BasicAuth> {
|
|||
}
|
||||
|
||||
public static String headerValue(String username, char[] password) {
|
||||
return "Basic " + Base64.encodeBytes((username + ":" + new String(password)).getBytes(Charsets.UTF_8));
|
||||
return "Basic " + Base64.encodeBytes((username + ":" + new String(password)).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public void apply(HttpURLConnection connection) {
|
||||
|
|
|
@ -71,17 +71,14 @@ public class ClientProxy implements InitializingService.Initializable {
|
|||
}
|
||||
|
||||
public BulkResponse bulk(BulkRequest request) {
|
||||
request.listenerThreaded(true);
|
||||
return client.bulk(preProcess(request)).actionGet();
|
||||
}
|
||||
|
||||
public void index(IndexRequest request, ActionListener<IndexResponse> listener) {
|
||||
request.listenerThreaded(true);
|
||||
client.index(preProcess(request), listener);
|
||||
}
|
||||
|
||||
public void bulk(BulkRequest request, ActionListener<BulkResponse> listener) {
|
||||
request.listenerThreaded(true);
|
||||
client.bulk(preProcess(request), listener);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,13 +5,8 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support.init.proxy;
|
||||
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.inject.Injector;
|
||||
import org.elasticsearch.script.CompiledScript;
|
||||
import org.elasticsearch.script.ExecutableScript;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.SearchScript;
|
||||
import org.elasticsearch.search.lookup.SearchLookup;
|
||||
import org.elasticsearch.script.*;
|
||||
import org.elasticsearch.watcher.support.Script;
|
||||
import org.elasticsearch.watcher.support.init.InitializingService;
|
||||
|
||||
|
@ -39,33 +34,30 @@ public class ScriptServiceProxy implements InitializingService.Initializable {
|
|||
this.service = injector.getInstance(ScriptService.class);
|
||||
}
|
||||
|
||||
public CompiledScript compile(String lang, String script, ScriptService.ScriptType scriptType) {
|
||||
return service.compile(lang, script, scriptType);
|
||||
public CompiledScript compile(Script script) {
|
||||
return compile(new org.elasticsearch.script.Script(script.script(), script.type(), script.lang(), script.params()));
|
||||
}
|
||||
|
||||
public CompiledScript compile(Script script) {
|
||||
return compile(script.lang(), script.script(), script.type());
|
||||
public CompiledScript compile(org.elasticsearch.script.Script script) {
|
||||
return service.compile(script, WatcherScriptContext.CTX);
|
||||
}
|
||||
|
||||
public ExecutableScript executable(CompiledScript compiledScript, Map<String, Object> vars) {
|
||||
return service.executable(compiledScript, vars);
|
||||
}
|
||||
|
||||
public ExecutableScript executable(Script script, Map<String, Object> vars) {
|
||||
if (script.params() != null && !script.params().isEmpty()) {
|
||||
vars = ImmutableMap.<String, Object>builder()
|
||||
.putAll(script.params())
|
||||
.putAll(vars)
|
||||
.build();
|
||||
|
||||
public ExecutableScript executable(org.elasticsearch.script.Script script) {
|
||||
return service.executable(script, WatcherScriptContext.CTX);
|
||||
}
|
||||
|
||||
public static final ScriptContext.Plugin INSTANCE = new ScriptContext.Plugin("elasticsearch-watcher", "watch");
|
||||
|
||||
private static class WatcherScriptContext implements ScriptContext {
|
||||
public static final ScriptContext CTX = new WatcherScriptContext();
|
||||
@Override
|
||||
public String getKey() {
|
||||
return INSTANCE.getKey();
|
||||
}
|
||||
return executable(script.lang(), script.script(), script.type(), vars);
|
||||
}
|
||||
|
||||
public ExecutableScript executable(String lang, String script, ScriptService.ScriptType scriptType, Map<String, Object> vars) {
|
||||
return service.executable(lang, script, scriptType, vars);
|
||||
}
|
||||
|
||||
public SearchScript search(SearchLookup lookup, String lang, String script, ScriptService.ScriptType scriptType, Map<String, Object> vars) {
|
||||
return service.search(lookup, lang, script, scriptType, vars);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ package org.elasticsearch.watcher.support.secret;
|
|||
|
||||
import org.apache.lucene.util.BytesRef;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.xcontent.XContentLocation;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
|
||||
|
@ -113,16 +114,6 @@ public class SensitiveXContentParser implements XContentParser {
|
|||
return parser.utf8Bytes();
|
||||
}
|
||||
|
||||
@Override @Deprecated
|
||||
public BytesRef bytesOrNull() throws IOException {
|
||||
return parser.bytesOrNull();
|
||||
}
|
||||
|
||||
@Override @Deprecated
|
||||
public BytesRef bytes() throws IOException {
|
||||
return parser.bytes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object objectText() throws IOException {
|
||||
return parser.objectText();
|
||||
|
@ -233,6 +224,11 @@ public class SensitiveXContentParser implements XContentParser {
|
|||
return parser.binaryValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentLocation getTokenLocation() {
|
||||
return parser.getTokenLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws ElasticsearchException {
|
||||
parser.close();
|
||||
|
|
|
@ -10,7 +10,6 @@ import org.elasticsearch.common.component.AbstractComponent;
|
|||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.script.ExecutableScript;
|
||||
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.watcher.support.template.xmustache.XMustacheScriptEngineService;
|
||||
|
||||
|
@ -35,9 +34,8 @@ public class MustacheTemplateEngine extends AbstractComponent implements Templat
|
|||
Map<String, Object> mergedModel = new HashMap<>();
|
||||
mergedModel.putAll(template.getParams());
|
||||
mergedModel.putAll(model);
|
||||
ExecutableScript executable = service.executable(MustacheScriptEngineService.NAME,
|
||||
XMustacheScriptEngineService.prepareTemplate(template.getTemplate(), template.getContentType()),
|
||||
template.getType(), mergedModel);
|
||||
String script = XMustacheScriptEngineService.prepareTemplate(template.getTemplate(), template.getContentType());
|
||||
ExecutableScript executable = service.executable(new org.elasticsearch.script.Template(script, template.getType(), XMustacheScriptEngineService.NAME , template.getContentType(), mergedModel));
|
||||
Object result = executable.run();
|
||||
if (result instanceof BytesReference) {
|
||||
return ((BytesReference) result).toUtf8();
|
||||
|
|
|
@ -8,12 +8,12 @@ package org.elasticsearch.watcher.support.template;
|
|||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.xcontent.*;
|
||||
import org.elasticsearch.script.ScriptService.ScriptType;
|
||||
import org.elasticsearch.watcher.WatcherException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -50,7 +50,7 @@ public class Template implements ToXContent {
|
|||
}
|
||||
|
||||
public Map<String, Object> getParams() {
|
||||
return params != null ? params : ImmutableMap.<String, Object>of();
|
||||
return params != null ? params : Collections.EMPTY_MAP;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,7 +8,9 @@ package org.elasticsearch.watcher.support.template;
|
|||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.Module;
|
||||
import org.elasticsearch.common.inject.PreProcessModule;
|
||||
import org.elasticsearch.script.ScriptContext;
|
||||
import org.elasticsearch.script.ScriptModule;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.watcher.support.template.xmustache.XMustacheScriptEngineService;
|
||||
import org.elasticsearch.watcher.support.template.xmustache.XMustacheTemplateEngine;
|
||||
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support.template.xmustache;
|
||||
|
||||
import org.elasticsearch.common.collect.Iterables;
|
||||
import org.elasticsearch.common.jackson.core.io.JsonStringEncoder;
|
||||
import org.elasticsearch.common.mustache.DefaultMustacheFactory;
|
||||
import org.elasticsearch.common.mustache.MustacheException;
|
||||
import org.elasticsearch.common.mustache.reflect.ReflectionObjectHandler;
|
||||
import com.fasterxml.jackson.core.io.JsonStringEncoder;
|
||||
import com.github.mustachejava.DefaultMustacheFactory;
|
||||
import com.github.mustachejava.MustacheException;
|
||||
import com.github.mustachejava.reflect.ReflectionObjectHandler;
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.watcher.support.ArrayObjectIterator;
|
||||
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support.template.xmustache;
|
||||
|
||||
import com.github.mustachejava.Mustache;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.component.AbstractComponent;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.io.FastStringReader;
|
||||
import org.elasticsearch.common.io.UTF8StreamWriter;
|
||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
import org.elasticsearch.common.mustache.Mustache;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.script.CompiledScript;
|
||||
|
|
|
@ -35,7 +35,7 @@ public class XMustacheTemplateEngine extends AbstractComponent implements Templa
|
|||
Map<String, Object> mergedModel = new HashMap<>();
|
||||
mergedModel.putAll(template.getParams());
|
||||
mergedModel.putAll(model);
|
||||
ExecutableScript executable = service.executable(XMustacheScriptEngineService.NAME, template.getTemplate(), template.getType(), mergedModel);
|
||||
ExecutableScript executable = service.executable(new org.elasticsearch.script.Template(template.getTemplate(), template.getType(), XMustacheScriptEngineService.NAME, template.getContentType(), mergedModel));
|
||||
Object result = executable.run();
|
||||
if (result instanceof BytesReference) {
|
||||
return ((BytesReference) result).toUtf8();
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support.xcontent;
|
||||
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
|
||||
/**
|
||||
|
@ -18,8 +18,6 @@ public class WatcherParams extends ToXContent.DelegatingMapParams {
|
|||
static final String HIDE_SECRETS_KEY = "hide_secrets";
|
||||
static final String COLLAPSE_ARRAYS_KEY = "collapse_arrays";
|
||||
|
||||
private ImmutableMap<String, String> params;
|
||||
|
||||
private WatcherParams(ImmutableMap<String, String> params, ToXContent.Params delegate) {
|
||||
super(params, delegate);
|
||||
}
|
||||
|
@ -42,10 +40,6 @@ public class WatcherParams extends ToXContent.DelegatingMapParams {
|
|||
return wrap(params).hideSecrets();
|
||||
}
|
||||
|
||||
public static boolean collapseArrays(ToXContent.Params params) {
|
||||
return wrap(params).collapseArrays();
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return builder(ToXContent.EMPTY_PARAMS);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,9 @@ import org.elasticsearch.common.collect.Tuple;
|
|||
import org.elasticsearch.common.compress.CompressedStreamInput;
|
||||
import org.elasticsearch.common.compress.Compressor;
|
||||
import org.elasticsearch.common.compress.CompressorFactory;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
|
||||
|
@ -29,19 +31,8 @@ public class WatcherXContentUtils {
|
|||
|
||||
public static Tuple<XContentType, Object> convertToObject(BytesReference bytes) throws ElasticsearchParseException {
|
||||
try {
|
||||
XContentParser parser;
|
||||
XContentType contentType;
|
||||
Compressor compressor = CompressorFactory.compressor(bytes);
|
||||
if (compressor != null) {
|
||||
CompressedStreamInput compressedStreamInput = compressor.streamInput(bytes.streamInput());
|
||||
contentType = XContentFactory.xContentType(compressedStreamInput);
|
||||
compressedStreamInput.resetToBufferStart();
|
||||
parser = XContentFactory.xContent(contentType).createParser(compressedStreamInput);
|
||||
} else {
|
||||
contentType = XContentFactory.xContentType(bytes);
|
||||
parser = XContentFactory.xContent(contentType).createParser(bytes.streamInput());
|
||||
}
|
||||
return Tuple.tuple(contentType, readValue(parser, parser.nextToken()));
|
||||
XContentParser parser = XContentHelper.createParser(bytes);
|
||||
return Tuple.tuple(parser.contentType(), readValue(parser, parser.nextToken()));
|
||||
} catch (IOException e) {
|
||||
throw new ElasticsearchParseException("Failed to parse content to map", e);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.support.xcontent;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
|
@ -22,15 +23,22 @@ import java.util.Map;
|
|||
public class XContentSource implements ToXContent {
|
||||
|
||||
private final BytesReference bytes;
|
||||
|
||||
private XContentType contentType;
|
||||
private final XContentType contentType;
|
||||
private Object data;
|
||||
|
||||
/**
|
||||
* Constructs a new XContentSource out of the given bytes reference.
|
||||
*/
|
||||
public XContentSource(BytesReference bytes) throws ElasticsearchParseException {
|
||||
public XContentSource(BytesReference bytes, XContentType xContentType) throws ElasticsearchParseException {
|
||||
if (xContentType == null) {
|
||||
throw new IllegalArgumentException("xContentType must not be null");
|
||||
}
|
||||
this.bytes = bytes;
|
||||
this.contentType = xContentType;
|
||||
}
|
||||
|
||||
public XContentSource(BytesReference bytes) {
|
||||
this(bytes, XContentFactory.xContentType(bytes));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,32 +88,33 @@ public class XContentSource implements ToXContent {
|
|||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
XContentParser parser = contentType().xContent().createParser(bytes);
|
||||
parser.nextToken();
|
||||
XContentHelper.copyCurrentStructure(builder.generator(), parser);
|
||||
return builder;
|
||||
try (XContentParser parser = parser()) {
|
||||
parser.nextToken();
|
||||
XContentHelper.copyCurrentStructure(builder.generator(), parser);
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
public XContentParser parser() throws IOException {
|
||||
return contentType.xContent().createParser(bytes);
|
||||
}
|
||||
|
||||
public static XContentSource readFrom(StreamInput in) throws IOException {
|
||||
return new XContentSource(in.readBytesReference());
|
||||
return new XContentSource(in.readBytesReference(), XContentType.readFrom(in));
|
||||
}
|
||||
|
||||
public static void writeTo(XContentSource source, StreamOutput out) throws IOException {
|
||||
out.writeBytesReference(source.bytes);
|
||||
}
|
||||
|
||||
private XContentType contentType() {
|
||||
if (contentType == null) {
|
||||
contentType = XContentFactory.xContentType(bytes);
|
||||
}
|
||||
return contentType;
|
||||
XContentType.writeTo(source.contentType, out);
|
||||
}
|
||||
|
||||
private Object data() {
|
||||
if (data == null) {
|
||||
Tuple<XContentType, Object> tuple = WatcherXContentUtils.convertToObject(bytes);
|
||||
this.contentType = tuple.v1();
|
||||
this.data = tuple.v2();
|
||||
try (XContentParser parser = parser()) {
|
||||
data = WatcherXContentUtils.readValue(parser, parser.nextToken());
|
||||
} catch (IOException ex) {
|
||||
throw new ElasticsearchException("failed to read value", ex);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.transform;
|
||||
|
||||
import org.elasticsearch.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
||||
|
@ -17,7 +17,7 @@ import java.util.Map;
|
|||
*/
|
||||
public class TransformRegistry {
|
||||
|
||||
private final ImmutableMap<String, TransformFactory> factories;
|
||||
private final Map<String, TransformFactory> factories;
|
||||
|
||||
@Inject
|
||||
public TransformRegistry(Map<String, TransformFactory> factories) {
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.transform.chain;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.collect.ImmutableList;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.watcher.transform.Transform;
|
||||
|
@ -14,6 +14,7 @@ import org.elasticsearch.watcher.transform.TransformRegistry;
|
|||
import org.elasticsearch.watcher.watch.Payload;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -33,7 +34,7 @@ public class ChainTransform implements Transform {
|
|||
return TYPE;
|
||||
}
|
||||
|
||||
public ImmutableList<Transform> getTransforms() {
|
||||
public List<Transform> getTransforms() {
|
||||
return transforms;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.transform.chain;
|
||||
|
||||
import org.elasticsearch.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.elasticsearch.common.inject.Injector;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.transform.chain;
|
||||
|
||||
import org.elasticsearch.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.watcher.execution.WatchExecutionContext;
|
||||
import org.elasticsearch.watcher.transform.ExecutableTransform;
|
||||
|
@ -13,6 +13,7 @@ import org.elasticsearch.watcher.transform.Transform;
|
|||
import org.elasticsearch.watcher.watch.Payload;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -26,7 +27,7 @@ public class ExecutableChainTransform extends ExecutableTransform<ChainTransform
|
|||
this.transforms = transforms;
|
||||
}
|
||||
|
||||
public ImmutableList<ExecutableTransform> executableTransforms() {
|
||||
public List<ExecutableTransform> executableTransforms() {
|
||||
return transforms;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ package org.elasticsearch.watcher.transport.actions;
|
|||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.ActionResponse;
|
||||
import org.elasticsearch.action.support.ActionFilters;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequest;
|
||||
import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction;
|
||||
import org.elasticsearch.action.support.master.MasterNodeRequest;
|
||||
import org.elasticsearch.action.support.master.TransportMasterNodeAction;
|
||||
import org.elasticsearch.cluster.ClusterService;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.license.plugin.core.LicenseExpiredException;
|
||||
|
@ -20,12 +20,12 @@ import org.elasticsearch.watcher.license.LicenseService;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public abstract class WatcherTransportAction<Request extends MasterNodeOperationRequest<Request>, Response extends ActionResponse> extends TransportMasterNodeOperationAction<Request, Response> {
|
||||
public abstract class WatcherTransportAction<Request extends MasterNodeRequest<Request>, Response extends ActionResponse> extends TransportMasterNodeAction<Request, Response> {
|
||||
|
||||
private final LicenseService licenseService;
|
||||
|
||||
public WatcherTransportAction(Settings settings, String actionName, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, LicenseService licenseService) {
|
||||
super(settings, actionName, transportService, clusterService, threadPool, actionFilters);
|
||||
public WatcherTransportAction(Settings settings, String actionName, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, LicenseService licenseService, Class<Request> request) {
|
||||
super(settings, actionName, transportService, clusterService, threadPool, actionFilters, request);
|
||||
this.licenseService = licenseService;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.transport.actions.ack;
|
||||
|
||||
import org.elasticsearch.watcher.client.WatcherAction;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.action.Action;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
|
||||
/**
|
||||
* This action acks a watch in memory, and the index
|
||||
*/
|
||||
public class AckWatchAction extends WatcherAction<AckWatchRequest, AckWatchResponse, AckWatchRequestBuilder> {
|
||||
public class AckWatchAction extends Action<AckWatchRequest, AckWatchResponse, AckWatchRequestBuilder> {
|
||||
|
||||
public static final AckWatchAction INSTANCE = new AckWatchAction();
|
||||
public static final String NAME = "cluster:admin/watcher/watch/ack";
|
||||
|
@ -26,8 +26,7 @@ public class AckWatchAction extends WatcherAction<AckWatchRequest, AckWatchRespo
|
|||
}
|
||||
|
||||
@Override
|
||||
public AckWatchRequestBuilder newRequestBuilder(Client client) {
|
||||
public AckWatchRequestBuilder newRequestBuilder(ElasticsearchClient client) {
|
||||
return new AckWatchRequestBuilder(client);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ package org.elasticsearch.watcher.transport.actions.ack;
|
|||
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.ValidateActions;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequest;
|
||||
import org.elasticsearch.action.support.master.MasterNodeRequest;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
|
@ -19,7 +19,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* A ack watch request to ack a watch by name (id)
|
||||
*/
|
||||
public class AckWatchRequest extends MasterNodeOperationRequest<AckWatchRequest> {
|
||||
public class AckWatchRequest extends MasterNodeRequest<AckWatchRequest> {
|
||||
|
||||
private static final TimeValue DEFAULT_TIMEOUT = TimeValue.timeValueSeconds(10);
|
||||
|
||||
|
|
|
@ -7,20 +7,21 @@ package org.elasticsearch.watcher.transport.actions.ack;
|
|||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
import org.elasticsearch.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
||||
/**
|
||||
* A ack watch action request builder.
|
||||
*/
|
||||
public class AckWatchRequestBuilder extends MasterNodeOperationRequestBuilder<AckWatchRequest, AckWatchResponse, AckWatchRequestBuilder, Client> {
|
||||
public class AckWatchRequestBuilder extends MasterNodeOperationRequestBuilder<AckWatchRequest, AckWatchResponse, AckWatchRequestBuilder> {
|
||||
|
||||
public AckWatchRequestBuilder(Client client) {
|
||||
super(client, new AckWatchRequest());
|
||||
public AckWatchRequestBuilder(ElasticsearchClient client) {
|
||||
super(client, AckWatchAction.INSTANCE, new AckWatchRequest());
|
||||
}
|
||||
|
||||
public AckWatchRequestBuilder(Client client, String id) {
|
||||
super(client, new AckWatchRequest(id));
|
||||
public AckWatchRequestBuilder(ElasticsearchClient client, String id) {
|
||||
super(client, AckWatchAction.INSTANCE, new AckWatchRequest(id));
|
||||
}
|
||||
|
||||
public AckWatchRequestBuilder setActionIds(String... actionIds) {
|
||||
|
@ -28,9 +29,5 @@ public class AckWatchRequestBuilder extends MasterNodeOperationRequestBuilder<Ac
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(final ActionListener<AckWatchResponse> listener) {
|
||||
new WatcherClient(client).ackWatch(request, listener);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public class TransportAckWatchAction extends WatcherTransportAction<AckWatchRequ
|
|||
@Inject
|
||||
public TransportAckWatchAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
||||
ThreadPool threadPool, ActionFilters actionFilters, WatcherService watcherService, LicenseService licenseService) {
|
||||
super(settings, AckWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, licenseService);
|
||||
super(settings, AckWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, licenseService, AckWatchRequest.class);
|
||||
this.watcherService = watcherService;
|
||||
}
|
||||
|
||||
|
@ -41,11 +41,6 @@ public class TransportAckWatchAction extends WatcherTransportAction<AckWatchRequ
|
|||
return ThreadPool.Names.MANAGEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AckWatchRequest newRequest() {
|
||||
return new AckWatchRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AckWatchResponse newResponse() {
|
||||
return new AckWatchResponse();
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.transport.actions.delete;
|
||||
|
||||
import org.elasticsearch.watcher.client.WatcherAction;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.action.Action;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
|
||||
/**
|
||||
* This action deletes an watch from in memory, the scheduler and the index
|
||||
*/
|
||||
public class DeleteWatchAction extends WatcherAction<DeleteWatchRequest, DeleteWatchResponse, DeleteWatchRequestBuilder> {
|
||||
public class DeleteWatchAction extends Action<DeleteWatchRequest, DeleteWatchResponse, DeleteWatchRequestBuilder> {
|
||||
|
||||
public static final DeleteWatchAction INSTANCE = new DeleteWatchAction();
|
||||
public static final String NAME = "cluster:admin/watcher/watch/delete";
|
||||
|
@ -26,7 +26,7 @@ public class DeleteWatchAction extends WatcherAction<DeleteWatchRequest, DeleteW
|
|||
}
|
||||
|
||||
@Override
|
||||
public DeleteWatchRequestBuilder newRequestBuilder(Client client) {
|
||||
public DeleteWatchRequestBuilder newRequestBuilder(ElasticsearchClient client) {
|
||||
return new DeleteWatchRequestBuilder(client);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ package org.elasticsearch.watcher.transport.actions.delete;
|
|||
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.ValidateActions;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequest;
|
||||
import org.elasticsearch.action.support.master.MasterNodeRequest;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.lucene.uid.Versions;
|
||||
|
@ -19,7 +19,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* A delete watch request to delete an watch by name (id)
|
||||
*/
|
||||
public class DeleteWatchRequest extends MasterNodeOperationRequest<DeleteWatchRequest> {
|
||||
public class DeleteWatchRequest extends MasterNodeRequest<DeleteWatchRequest> {
|
||||
|
||||
private static final TimeValue DEFAULT_TIMEOUT = TimeValue.timeValueSeconds(10);
|
||||
|
||||
|
@ -94,7 +94,7 @@ public class DeleteWatchRequest extends MasterNodeOperationRequest<DeleteWatchRe
|
|||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
id = in.readString();
|
||||
version = Versions.readVersion(in);
|
||||
version = in.readLong();
|
||||
force = in.readBoolean();
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ public class DeleteWatchRequest extends MasterNodeOperationRequest<DeleteWatchRe
|
|||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
out.writeString(id);
|
||||
Versions.writeVersion(version, out);
|
||||
out.writeLong(version);
|
||||
out.writeBoolean(force);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,20 +7,21 @@ package org.elasticsearch.watcher.transport.actions.delete;
|
|||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
import org.elasticsearch.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
||||
/**
|
||||
* A delete document action request builder.
|
||||
*/
|
||||
public class DeleteWatchRequestBuilder extends MasterNodeOperationRequestBuilder<DeleteWatchRequest, DeleteWatchResponse, DeleteWatchRequestBuilder, Client> {
|
||||
public class DeleteWatchRequestBuilder extends MasterNodeOperationRequestBuilder<DeleteWatchRequest, DeleteWatchResponse, DeleteWatchRequestBuilder> {
|
||||
|
||||
public DeleteWatchRequestBuilder(Client client) {
|
||||
super(client, new DeleteWatchRequest());
|
||||
public DeleteWatchRequestBuilder(ElasticsearchClient client) {
|
||||
super(client, DeleteWatchAction.INSTANCE, new DeleteWatchRequest());
|
||||
}
|
||||
|
||||
public DeleteWatchRequestBuilder(Client client, String id) {
|
||||
super(client, new DeleteWatchRequest(id));
|
||||
public DeleteWatchRequestBuilder(ElasticsearchClient client, String id) {
|
||||
super(client, DeleteWatchAction.INSTANCE, new DeleteWatchRequest(id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,9 +40,4 @@ public class DeleteWatchRequestBuilder extends MasterNodeOperationRequestBuilder
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(final ActionListener<DeleteWatchResponse> listener) {
|
||||
new WatcherClient(client).deleteWatch(request, listener);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public class TransportDeleteWatchAction extends WatcherTransportAction<DeleteWat
|
|||
@Inject
|
||||
public TransportDeleteWatchAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
||||
ThreadPool threadPool, ActionFilters actionFilters, WatcherService watcherService, LicenseService licenseService) {
|
||||
super(settings, DeleteWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, licenseService);
|
||||
super(settings, DeleteWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, licenseService, DeleteWatchRequest.class);
|
||||
this.watcherService = watcherService;
|
||||
}
|
||||
|
||||
|
@ -41,11 +41,6 @@ public class TransportDeleteWatchAction extends WatcherTransportAction<DeleteWat
|
|||
return ThreadPool.Names.MANAGEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DeleteWatchRequest newRequest() {
|
||||
return new DeleteWatchRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DeleteWatchResponse newResponse() {
|
||||
return new DeleteWatchResponse();
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.transport.actions.execute;
|
||||
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.watcher.client.WatcherAction;
|
||||
import org.elasticsearch.action.Action;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
|
||||
/**
|
||||
* This action executes a watch, either ignoring the schedule and condition or just the schedule and can execute a subset of the actions, optionally persisting the history entry
|
||||
*/
|
||||
public class ExecuteWatchAction extends WatcherAction<ExecuteWatchRequest, ExecuteWatchResponse, ExecuteWatchRequestBuilder> {
|
||||
public class ExecuteWatchAction extends Action<ExecuteWatchRequest, ExecuteWatchResponse, ExecuteWatchRequestBuilder> {
|
||||
|
||||
public static final ExecuteWatchAction INSTANCE = new ExecuteWatchAction();
|
||||
public static final String NAME = "cluster:admin/watcher/watch/execute";
|
||||
|
@ -26,7 +26,7 @@ public class ExecuteWatchAction extends WatcherAction<ExecuteWatchRequest, Execu
|
|||
}
|
||||
|
||||
@Override
|
||||
public ExecuteWatchRequestBuilder newRequestBuilder(Client client) {
|
||||
public ExecuteWatchRequestBuilder newRequestBuilder(ElasticsearchClient client) {
|
||||
return new ExecuteWatchRequestBuilder(client);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ package org.elasticsearch.watcher.transport.actions.execute;
|
|||
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.ValidateActions;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequest;
|
||||
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
|
@ -25,7 +25,7 @@ import java.util.Map;
|
|||
/**
|
||||
* An execute watch request to execute a watch by id
|
||||
*/
|
||||
public class ExecuteWatchRequest extends MasterNodeOperationRequest<ExecuteWatchRequest> {
|
||||
public class ExecuteWatchRequest extends MasterNodeReadRequest<ExecuteWatchRequest> {
|
||||
|
||||
public static final String INLINE_WATCH_ID = "_inlined_";
|
||||
|
||||
|
|
|
@ -5,12 +5,10 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.transport.actions.execute;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.watcher.client.WatchSourceBuilder;
|
||||
import org.elasticsearch.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.watcher.execution.ActionExecutionMode;
|
||||
import org.elasticsearch.watcher.trigger.TriggerEvent;
|
||||
|
||||
|
@ -20,14 +18,14 @@ import java.util.Map;
|
|||
/**
|
||||
* A execute watch action request builder.
|
||||
*/
|
||||
public class ExecuteWatchRequestBuilder extends MasterNodeOperationRequestBuilder<ExecuteWatchRequest, ExecuteWatchResponse, ExecuteWatchRequestBuilder, Client> {
|
||||
public class ExecuteWatchRequestBuilder extends MasterNodeOperationRequestBuilder<ExecuteWatchRequest, ExecuteWatchResponse, ExecuteWatchRequestBuilder> {
|
||||
|
||||
public ExecuteWatchRequestBuilder(Client client) {
|
||||
super(client, new ExecuteWatchRequest());
|
||||
public ExecuteWatchRequestBuilder(ElasticsearchClient client) {
|
||||
super(client, ExecuteWatchAction.INSTANCE, new ExecuteWatchRequest());
|
||||
}
|
||||
|
||||
public ExecuteWatchRequestBuilder(Client client, String watchName) {
|
||||
super(client, new ExecuteWatchRequest(watchName));
|
||||
public ExecuteWatchRequestBuilder(ElasticsearchClient client, String watchName) {
|
||||
super(client, ExecuteWatchAction.INSTANCE, new ExecuteWatchRequest(watchName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -103,9 +101,4 @@ public class ExecuteWatchRequestBuilder extends MasterNodeOperationRequestBuilde
|
|||
request.setActionMode(actionId, actionMode);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(final ActionListener<ExecuteWatchResponse> listener) {
|
||||
new WatcherClient(client).executeWatch(request, listener);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.elasticsearch.cluster.ClusterState;
|
|||
import org.elasticsearch.cluster.block.ClusterBlockException;
|
||||
import org.elasticsearch.cluster.block.ClusterBlockLevel;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.joda.time.DateTime;
|
||||
import org.joda.time.DateTime;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
|
@ -36,10 +36,10 @@ import org.elasticsearch.watcher.trigger.manual.ManualTriggerEvent;
|
|||
import org.elasticsearch.watcher.watch.Payload;
|
||||
import org.elasticsearch.watcher.watch.Watch;
|
||||
import org.elasticsearch.watcher.watch.WatchStore;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.common.joda.time.DateTimeZone.UTC;
|
||||
/**
|
||||
* Performs the watch execution operation.
|
||||
*/
|
||||
|
@ -56,7 +56,7 @@ public class TransportExecuteWatchAction extends WatcherTransportAction<ExecuteW
|
|||
ThreadPool threadPool, ActionFilters actionFilters, ExecutionService executionService,
|
||||
Clock clock, LicenseService licenseService, WatchStore watchStore, TriggerService triggerService,
|
||||
Watch.Parser watchParser) {
|
||||
super(settings, ExecuteWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, licenseService);
|
||||
super(settings, ExecuteWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, licenseService, ExecuteWatchRequest.class);
|
||||
this.executionService = executionService;
|
||||
this.watchStore = watchStore;
|
||||
this.clock = clock;
|
||||
|
@ -69,11 +69,6 @@ public class TransportExecuteWatchAction extends WatcherTransportAction<ExecuteW
|
|||
return ThreadPool.Names.MANAGEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ExecuteWatchRequest newRequest() {
|
||||
return new ExecuteWatchRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ExecuteWatchResponse newResponse() {
|
||||
return new ExecuteWatchResponse();
|
||||
|
@ -103,7 +98,7 @@ public class TransportExecuteWatchAction extends WatcherTransportAction<ExecuteW
|
|||
|
||||
ManualExecutionContext.Builder ctxBuilder = ManualExecutionContext.builder(watch, knownWatch, new ManualTriggerEvent(triggerEvent.jobName(), triggerEvent), executionService.defaultThrottlePeriod());
|
||||
|
||||
DateTime executionTime = clock.now(UTC);
|
||||
DateTime executionTime = clock.now(DateTimeZone.UTC);
|
||||
ctxBuilder.executionTime(executionTime);
|
||||
for (Map.Entry<String, ActionExecutionMode> entry : request.getActionModes().entrySet()) {
|
||||
ctxBuilder.actionMode(entry.getKey(), entry.getValue());
|
||||
|
|
|
@ -5,13 +5,12 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.transport.actions.get;
|
||||
|
||||
import org.elasticsearch.watcher.client.WatcherAction;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
|
||||
/**
|
||||
* This action gets an watch by name
|
||||
*/
|
||||
public class GetWatchAction extends WatcherAction<GetWatchRequest, GetWatchResponse, GetWatchRequestBuilder> {
|
||||
public class GetWatchAction extends org.elasticsearch.action.Action<GetWatchRequest, GetWatchResponse, GetWatchRequestBuilder> {
|
||||
|
||||
public static final GetWatchAction INSTANCE = new GetWatchAction();
|
||||
public static final String NAME = "cluster:monitor/watcher/watch/get";
|
||||
|
@ -26,7 +25,7 @@ public class GetWatchAction extends WatcherAction<GetWatchRequest, GetWatchRespo
|
|||
}
|
||||
|
||||
@Override
|
||||
public GetWatchRequestBuilder newRequestBuilder(Client client) {
|
||||
public GetWatchRequestBuilder newRequestBuilder(ElasticsearchClient client) {
|
||||
return new GetWatchRequestBuilder(client);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@ package org.elasticsearch.watcher.transport.actions.get;
|
|||
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.ValidateActions;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequest;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
||||
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.lucene.uid.Versions;
|
||||
|
@ -19,7 +20,7 @@ import java.io.IOException;
|
|||
/**
|
||||
* The request to get the watch by name (id)
|
||||
*/
|
||||
public class GetWatchRequest extends MasterNodeOperationRequest<GetWatchRequest> {
|
||||
public class GetWatchRequest extends MasterNodeReadRequest<GetWatchRequest> {
|
||||
|
||||
private String id;
|
||||
private long version = Versions.MATCH_ANY;
|
||||
|
@ -87,7 +88,7 @@ public class GetWatchRequest extends MasterNodeOperationRequest<GetWatchRequest>
|
|||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
super.readFrom(in);
|
||||
version = Versions.readVersion(in);
|
||||
version = in.readLong();
|
||||
versionType = VersionType.fromValue(in.readByte());
|
||||
id = in.readString();
|
||||
}
|
||||
|
@ -95,7 +96,7 @@ public class GetWatchRequest extends MasterNodeOperationRequest<GetWatchRequest>
|
|||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
super.writeTo(out);
|
||||
Versions.writeVersion(version, out);
|
||||
out.writeLong(version);
|
||||
out.writeByte(versionType.getValue());
|
||||
out.writeString(id);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,9 @@ package org.elasticsearch.watcher.transport.actions.get;
|
|||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.ActionRequestBuilder;
|
||||
import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder;
|
||||
import org.elasticsearch.bootstrap.Elasticsearch;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
import org.elasticsearch.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.index.VersionType;
|
||||
|
@ -14,15 +17,15 @@ import org.elasticsearch.index.VersionType;
|
|||
/**
|
||||
* A delete document action request builder.
|
||||
*/
|
||||
public class GetWatchRequestBuilder extends ActionRequestBuilder<GetWatchRequest, GetWatchResponse, GetWatchRequestBuilder, Client> {
|
||||
public class GetWatchRequestBuilder extends MasterNodeReadOperationRequestBuilder<GetWatchRequest, GetWatchResponse, GetWatchRequestBuilder> {
|
||||
|
||||
public GetWatchRequestBuilder(Client client, String id) {
|
||||
super(client, new GetWatchRequest(id));
|
||||
public GetWatchRequestBuilder(ElasticsearchClient client, String id) {
|
||||
super(client, GetWatchAction.INSTANCE, new GetWatchRequest(id));
|
||||
}
|
||||
|
||||
|
||||
public GetWatchRequestBuilder(Client client) {
|
||||
super(client, new GetWatchRequest());
|
||||
public GetWatchRequestBuilder(ElasticsearchClient client) {
|
||||
super(client, GetWatchAction.INSTANCE, new GetWatchRequest());
|
||||
}
|
||||
|
||||
public GetWatchRequestBuilder setId(String id) {
|
||||
|
@ -37,9 +40,4 @@ public class GetWatchRequestBuilder extends ActionRequestBuilder<GetWatchRequest
|
|||
request.setVersionType(versionType);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(final ActionListener<GetWatchResponse> listener) {
|
||||
new WatcherClient(client).getWatch(request, listener);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public class TransportGetWatchAction extends WatcherTransportAction<GetWatchRequ
|
|||
@Inject
|
||||
public TransportGetWatchAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
||||
ThreadPool threadPool, ActionFilters actionFilters, WatcherService watcherService, LicenseService licenseService) {
|
||||
super(settings, GetWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, licenseService);
|
||||
super(settings, GetWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, licenseService, GetWatchRequest.class);
|
||||
this.watcherService = watcherService;
|
||||
}
|
||||
|
||||
|
@ -47,11 +47,6 @@ public class TransportGetWatchAction extends WatcherTransportAction<GetWatchRequ
|
|||
return ThreadPool.Names.SAME; // Super lightweight operation, so don't fork
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GetWatchRequest newRequest() {
|
||||
return new GetWatchRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GetWatchResponse newResponse() {
|
||||
return new GetWatchResponse();
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.transport.actions.put;
|
||||
|
||||
import org.elasticsearch.watcher.client.WatcherAction;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.action.Action;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
|
||||
/**
|
||||
* This action puts an watch into the watch index and adds it to the scheduler
|
||||
*/
|
||||
public class PutWatchAction extends WatcherAction<PutWatchRequest, PutWatchResponse, PutWatchRequestBuilder> {
|
||||
public class PutWatchAction extends Action<PutWatchRequest, PutWatchResponse, PutWatchRequestBuilder> {
|
||||
|
||||
public static final PutWatchAction INSTANCE = new PutWatchAction();
|
||||
public static final String NAME = "cluster:admin/watcher/watch/put";
|
||||
|
@ -20,13 +20,13 @@ public class PutWatchAction extends WatcherAction<PutWatchRequest, PutWatchRespo
|
|||
super(NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PutWatchRequestBuilder newRequestBuilder(Client client) {
|
||||
return new PutWatchRequestBuilder(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PutWatchResponse newResponse() {
|
||||
return new PutWatchResponse();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PutWatchRequestBuilder newRequestBuilder(ElasticsearchClient client) {
|
||||
return new PutWatchRequestBuilder(client);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@ package org.elasticsearch.watcher.transport.actions.put;
|
|||
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.ValidateActions;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequest;
|
||||
import org.elasticsearch.action.support.master.MasterNodeReadRequest;
|
||||
import org.elasticsearch.action.support.master.MasterNodeRequest;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.watcher.client.WatchSourceBuilder;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
|
@ -23,7 +24,7 @@ import java.io.IOException;
|
|||
* This request class contains the data needed to create a watch along with the name of the watch.
|
||||
* The name of the watch will become the ID of the indexed document.
|
||||
*/
|
||||
public class PutWatchRequest extends MasterNodeOperationRequest<PutWatchRequest> {
|
||||
public class PutWatchRequest extends MasterNodeRequest<PutWatchRequest> {
|
||||
|
||||
private static final TimeValue DEFAULT_TIMEOUT = TimeValue.timeValueSeconds(10);
|
||||
|
||||
|
|
|
@ -7,19 +7,19 @@ package org.elasticsearch.watcher.transport.actions.put;
|
|||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
import org.elasticsearch.watcher.client.WatchSourceBuilder;
|
||||
import org.elasticsearch.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
|
||||
public class PutWatchRequestBuilder extends MasterNodeOperationRequestBuilder<PutWatchRequest, PutWatchResponse, PutWatchRequestBuilder, Client> {
|
||||
public class PutWatchRequestBuilder extends MasterNodeOperationRequestBuilder<PutWatchRequest, PutWatchResponse, PutWatchRequestBuilder> {
|
||||
|
||||
public PutWatchRequestBuilder(Client client) {
|
||||
super(client, new PutWatchRequest());
|
||||
public PutWatchRequestBuilder(ElasticsearchClient client) {
|
||||
super(client, PutWatchAction.INSTANCE, new PutWatchRequest());
|
||||
}
|
||||
|
||||
public PutWatchRequestBuilder(Client client, String id) {
|
||||
super(client, new PutWatchRequest());
|
||||
public PutWatchRequestBuilder(ElasticsearchClient client, String id) {
|
||||
super(client, PutWatchAction.INSTANCE, new PutWatchRequest());
|
||||
request.setId(id);
|
||||
}
|
||||
|
||||
|
@ -46,9 +46,4 @@ public class PutWatchRequestBuilder extends MasterNodeOperationRequestBuilder<Pu
|
|||
request.setSource(source);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doExecute(ActionListener<PutWatchResponse> listener) {
|
||||
new WatcherClient(client).putWatch(request, listener);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public class TransportPutWatchAction extends WatcherTransportAction<PutWatchRequ
|
|||
@Inject
|
||||
public TransportPutWatchAction(Settings settings, TransportService transportService, ClusterService clusterService,
|
||||
ThreadPool threadPool, ActionFilters actionFilters, WatcherService watcherService, LicenseService licenseService) {
|
||||
super(settings, PutWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, licenseService);
|
||||
super(settings, PutWatchAction.NAME, transportService, clusterService, threadPool, actionFilters, licenseService, PutWatchRequest.class);
|
||||
this.watcherService = watcherService;
|
||||
}
|
||||
|
||||
|
@ -40,11 +40,6 @@ public class TransportPutWatchAction extends WatcherTransportAction<PutWatchRequ
|
|||
return ThreadPool.Names.MANAGEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PutWatchRequest newRequest() {
|
||||
return new PutWatchRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PutWatchResponse newResponse() {
|
||||
return new PutWatchResponse();
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
package org.elasticsearch.watcher.transport.actions.service;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.ElasticsearchIllegalArgumentException;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.support.ActionFilters;
|
||||
import org.elasticsearch.cluster.ClusterService;
|
||||
|
@ -29,7 +28,7 @@ public class TransportWatcherServiceAction extends WatcherTransportAction<Watche
|
|||
|
||||
@Inject
|
||||
public TransportWatcherServiceAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, WatcherLifeCycleService lifeCycleService, LicenseService licenseService) {
|
||||
super(settings, WatcherServiceAction.NAME, transportService, clusterService, threadPool, actionFilters, licenseService);
|
||||
super(settings, WatcherServiceAction.NAME, transportService, clusterService, threadPool, actionFilters, licenseService, WatcherServiceRequest.class);
|
||||
this.lifeCycleService = lifeCycleService;
|
||||
}
|
||||
|
||||
|
@ -41,11 +40,6 @@ public class TransportWatcherServiceAction extends WatcherTransportAction<Watche
|
|||
return ThreadPool.Names.MANAGEMENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WatcherServiceRequest newRequest() {
|
||||
return new WatcherServiceRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WatcherServiceResponse newResponse() {
|
||||
return new WatcherServiceResponse();
|
||||
|
@ -65,7 +59,7 @@ public class TransportWatcherServiceAction extends WatcherTransportAction<Watche
|
|||
lifeCycleService.start();
|
||||
break;
|
||||
default:
|
||||
listener.onFailure(new ElasticsearchIllegalArgumentException("Command [" + request.getCommand() + "] is undefined"));
|
||||
listener.onFailure(new IllegalArgumentException("Command [" + request.getCommand() + "] is undefined"));
|
||||
return;
|
||||
}
|
||||
listener.onResponse(new WatcherServiceResponse(true));
|
||||
|
@ -73,6 +67,6 @@ public class TransportWatcherServiceAction extends WatcherTransportAction<Watche
|
|||
|
||||
@Override
|
||||
protected ClusterBlockException checkBlock(WatcherServiceRequest request, ClusterState state) {
|
||||
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA);
|
||||
return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,12 +5,13 @@
|
|||
*/
|
||||
package org.elasticsearch.watcher.transport.actions.service;
|
||||
|
||||
import org.elasticsearch.watcher.client.WatcherAction;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.action.Action;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class WatcherServiceAction extends WatcherAction<WatcherServiceRequest, WatcherServiceResponse, WatcherServiceRequestBuilder> {
|
||||
|
||||
public class WatcherServiceAction extends Action<WatcherServiceRequest, WatcherServiceResponse, WatcherServiceRequestBuilder> {
|
||||
|
||||
public static final WatcherServiceAction INSTANCE = new WatcherServiceAction();
|
||||
public static final String NAME = "cluster:admin/watcher/service";
|
||||
|
@ -25,8 +26,7 @@ public class WatcherServiceAction extends WatcherAction<WatcherServiceRequest, W
|
|||
}
|
||||
|
||||
@Override
|
||||
public WatcherServiceRequestBuilder newRequestBuilder(Client client) {
|
||||
public WatcherServiceRequestBuilder newRequestBuilder(ElasticsearchClient client) {
|
||||
return new WatcherServiceRequestBuilder(client);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue