diff --git a/pom.xml b/pom.xml index 72360baf34a..99f8711c4ee 100644 --- a/pom.xml +++ b/pom.xml @@ -16,30 +16,17 @@ - org.sonatype.oss - oss-parent - 7 + org.elasticsearch + elasticsearch-plugin + 2.0.0-SNAPSHOT - - 1.5.0 - 4.10.4 - 4.10.4 - 1.2.1 - 1.0.0 - - auto - true - onerror - - ${project.basedir}/backwards - INFO - 512m - 5 - .local-${project.version}-execution-hints.log - true - false - true + dev-tools/elasticsearch_license_header.txt + dev-tools/license_header_definition.xml + 2.0.0-SNAPSHOT + 2.0.0-SNAPSHOT + false + false @@ -151,14 +138,14 @@ org.elasticsearch elasticsearch-license-plugin - ${license.version} + ${license.plugin.version} true org.elasticsearch elasticsearch-shield - ${shield.version} + ${shield.plugin.version} true @@ -168,12 +155,6 @@ r239 - - com.google.guava - guava - r05 - - org.apache.lucene lucene-core @@ -191,6 +172,12 @@ activation 1.1.1 + + com.github.spullara.mustache.java + compiler + 0.8.13 + true + @@ -199,7 +186,7 @@ org.elasticsearch elasticsearch-shield - ${shield.version} + ${shield.plugin.version} org.elasticsearch @@ -210,7 +197,7 @@ org.elasticsearch elasticsearch-license-plugin - ${license.version} + ${license.plugin.version} org.elasticsearch @@ -254,6 +241,11 @@ http://download.java.net/maven/2/ default + + oss-snapshots + Sonatype OSS Snapshots + https://oss.sonatype.org/content/repositories/snapshots/ + @@ -283,22 +275,10 @@ org.apache.maven.plugins maven-enforcer-plugin - 1.3.1 - - - enforce-versions - - enforce - - - - - [1.7,) - - - - - + + + org.codehaus.mojo + buildnumber-maven-plugin org.apache.maven.plugins @@ -318,7 +298,7 @@ true - com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer + com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer com.google.guava:guava @@ -367,245 +347,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.7 - 1.7 - true - 512m - - false - - -XDignore.symbol.file - - - - - com.carrotsearch.randomizedtesting - junit4-maven-plugin - 2.1.2 - - - tests - test - - junit4 - - - 20 - pipe,warn - true - - - - - - - - - - - ${tests.jvms} - - - - - - - **/*Tests.class - **/*Test.class - **/Test*.class - - - **/Abstract*.class - **/*StressTest.class - - - -Xmx${tests.heap.size} - -Xms${tests.heap.size} - -Xss256k - -XX:MaxDirectMemorySize=512m - -Des.logger.prefix= - - ${tests.shuffle} - ${tests.verbose} - ${tests.seed} - ${tests.failfast} - false - - . - - - ${tests.bwc} - ${tests.bwc.path} - ${tests.bwc.version} - ${tests.jvm.argline} - ${tests.processors} - ${tests.appendseed} - ${tests.iters} - ${tests.maxfailures} - ${tests.failfast} - ${tests.class} - ${tests.method} - ${tests.nightly} - ${tests.verbose} - ${tests.badapples} - ${tests.weekly} - ${tests.slow} - ${tests.awaitsfix} - ${tests.slow} - ${tests.timeoutSuite} - ${tests.showSuccess} - ${tests.integration} - ${tests.client.ratio} - ${tests.enable_mock_modules} - ${tests.assertion.disabled} - ${tests.rest} - ${tests.rest.suite} - ${tests.rest.blacklist} - ${tests.rest.spec} - ${tests.network} - ${tests.cluster} - ${tests.heap.size} - ${tests.filter} - ${tests.timewarp} - ${env.ES_TEST_LOCAL} - ${es.node.mode} - ${es.logger.level} - ${tests.security.manager} - ${tests.compatibility} - true - - ${project.build.directory} - ${basedir}/tests.policy - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.16 - - true - - - - org.codehaus.mojo - buildnumber-maven-plugin - 1.3 - - - validate - - create - - - - - false - false - - - - de.thetaphi - forbiddenapis - 1.6.1 - - - - check-forbidden-apis - - 1.7 - - true - - false - - jsr166e/** - - org/elasticsearch/common/lucene/search/Queries$QueryWrapperFilterFactory.class - - - - org/elasticsearch/common/util/UnsafeUtils.class - - - org/elasticsearch/common/util/MathUtils.class - org/elasticsearch/common/math/UnboxedMathUtils.class - org/elasticsearch/cluster/routing/operation/plain/PlainOperationRouting.class - - - - org/elasticsearch/common/lucene/search/XFilteredQuery.class - - - org/elasticsearch/common/io/Channels.class - - - - - jdk-unsafe - jdk-deprecated - jdk-system-out - - - core-signatures.txt - all-signatures.txt - - - - compile - - check - - - - check-forbidden-test-apis - - 1.7 - - true - - false - - - jdk-unsafe - jdk-deprecated - - - test-signatures.txt - all-signatures.txt - - - - test-compile - - testCheck - - - - diff --git a/src/main/assemblies/plugin.xml b/src/main/assemblies/plugin.xml index 5d42636284e..ac763fa7273 100644 --- a/src/main/assemblies/plugin.xml +++ b/src/main/assemblies/plugin.xml @@ -22,12 +22,12 @@ - / - false - - javax.mail:mail - javax.activation:activation - + / + false + + javax.mail:mail + javax.activation:activation + diff --git a/src/main/java/org/elasticsearch/watcher/TransportClientWatcherModule.java b/src/main/java/org/elasticsearch/watcher/TransportClientWatcherModule.java index 62b025bb0d3..ae4d7dd5b94 100644 --- a/src/main/java/org/elasticsearch/watcher/TransportClientWatcherModule.java +++ b/src/main/java/org/elasticsearch/watcher/TransportClientWatcherModule.java @@ -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 spawnModules() { - return ImmutableList.of(new WatcherTransportModule()); + return Collections.singleton(new WatcherTransportModule()); } @Override diff --git a/src/main/java/org/elasticsearch/watcher/WatcherBuild.java b/src/main/java/org/elasticsearch/watcher/WatcherBuild.java index a6b47802853..0289260d733 100644 --- a/src/main/java/org/elasticsearch/watcher/WatcherBuild.java +++ b/src/main/java/org/elasticsearch/watcher/WatcherBuild.java @@ -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) { diff --git a/src/main/java/org/elasticsearch/watcher/WatcherModule.java b/src/main/java/org/elasticsearch/watcher/WatcherModule.java index f22db9af117..409baa766bd 100644 --- a/src/main/java/org/elasticsearch/watcher/WatcherModule.java +++ b/src/main/java/org/elasticsearch/watcher/WatcherModule.java @@ -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 spawnModules() { - return ImmutableList.of( + return Arrays.asList( new InitializingModule(), new LicenseModule(), new WatchModule(), diff --git a/src/main/java/org/elasticsearch/watcher/WatcherPlugin.java b/src/main/java/org/elasticsearch/watcher/WatcherPlugin.java index 1fa9d4760c6..75e3725cba0 100644 --- a/src/main/java/org/elasticsearch/watcher/WatcherPlugin.java +++ b/src/main/java/org/elasticsearch/watcher/WatcherPlugin.java @@ -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.>of(WatcherModule.class); } + @Override public Collection> 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); } diff --git a/src/main/java/org/elasticsearch/watcher/WatcherService.java b/src/main/java/org/elasticsearch/watcher/WatcherService.java index b2d2d5831c0..c5834e2bde2 100644 --- a/src/main/java/org/elasticsearch/watcher/WatcherService.java +++ b/src/main/java/org/elasticsearch/watcher/WatcherService.java @@ -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"); } } diff --git a/src/main/java/org/elasticsearch/watcher/actions/ActionRegistry.java b/src/main/java/org/elasticsearch/watcher/actions/ActionRegistry.java index 39e1285fa21..9fe92cd9cbc 100644 --- a/src/main/java/org/elasticsearch/watcher/actions/ActionRegistry.java +++ b/src/main/java/org/elasticsearch/watcher/actions/ActionRegistry.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/actions/ActionStatus.java b/src/main/java/org/elasticsearch/watcher/actions/ActionStatus.java index e3dbb91de83..60cc19f4c89 100644 --- a/src/main/java/org/elasticsearch/watcher/actions/ActionStatus.java +++ b/src/main/java/org/elasticsearch/watcher/actions/ActionStatus.java @@ -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()); } } diff --git a/src/main/java/org/elasticsearch/watcher/actions/ActionWrapper.java b/src/main/java/org/elasticsearch/watcher/actions/ActionWrapper.java index a1f247c3a76..3dc5a2c5d5c 100644 --- a/src/main/java/org/elasticsearch/watcher/actions/ActionWrapper.java +++ b/src/main/java/org/elasticsearch/watcher/actions/ActionWrapper.java @@ -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); } diff --git a/src/main/java/org/elasticsearch/watcher/actions/email/service/Account.java b/src/main/java/org/elasticsearch/watcher/actions/email/service/Account.java index c4699ca1837..2f4a730af43 100644 --- a/src/main/java/org/elasticsearch/watcher/actions/email/service/Account.java +++ b/src/main/java/org/elasticsearch/watcher/actions/email/service/Account.java @@ -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); diff --git a/src/main/java/org/elasticsearch/watcher/actions/email/service/Attachment.java b/src/main/java/org/elasticsearch/watcher/actions/email/service/Attachment.java index d0993c85764..ddd6db526eb 100644 --- a/src/main/java/org/elasticsearch/watcher/actions/email/service/Attachment.java +++ b/src/main/java/org/elasticsearch/watcher/actions/email/service/Attachment.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/actions/email/service/Email.java b/src/main/java/org/elasticsearch/watcher/actions/email/service/Email.java index 06b784d00bd..71533db3ded 100644 --- a/src/main/java/org/elasticsearch/watcher/actions/email/service/Email.java +++ b/src/main/java/org/elasticsearch/watcher/actions/email/service/Email.java @@ -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 diff --git a/src/main/java/org/elasticsearch/watcher/actions/email/service/Inline.java b/src/main/java/org/elasticsearch/watcher/actions/email/service/Inline.java index 0812d6bd71f..f13c9865de6 100644 --- a/src/main/java/org/elasticsearch/watcher/actions/email/service/Inline.java +++ b/src/main/java/org/elasticsearch/watcher/actions/email/service/Inline.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/actions/email/service/InternalEmailService.java b/src/main/java/org/elasticsearch/watcher/actions/email/service/InternalEmailService.java index 85465472800..7bdd387a407 100644 --- a/src/main/java/org/elasticsearch/watcher/actions/email/service/InternalEmailService.java +++ b/src/main/java/org/elasticsearch/watcher/actions/email/service/InternalEmailService.java @@ -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 { 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 { diff --git a/src/main/java/org/elasticsearch/watcher/actions/index/IndexAction.java b/src/main/java/org/elasticsearch/watcher/actions/index/IndexAction.java index 0e98b5ecd02..269cf1c80ce 100644 --- a/src/main/java/org/elasticsearch/watcher/actions/index/IndexAction.java +++ b/src/main/java/org/elasticsearch/watcher/actions/index/IndexAction.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/actions/throttler/PeriodThrottler.java b/src/main/java/org/elasticsearch/watcher/actions/throttler/PeriodThrottler.java index 8a2fcac6179..56d87b0e5cd 100644 --- a/src/main/java/org/elasticsearch/watcher/actions/throttler/PeriodThrottler.java +++ b/src/main/java/org/elasticsearch/watcher/actions/throttler/PeriodThrottler.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/client/WatcherAction.java b/src/main/java/org/elasticsearch/watcher/client/WatcherAction.java deleted file mode 100644 index 9831442cc74..00000000000 --- a/src/main/java/org/elasticsearch/watcher/client/WatcherAction.java +++ /dev/null @@ -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> extends ClientAction { - - protected WatcherAction(String name) { - super(name); - } - -} \ No newline at end of file diff --git a/src/main/java/org/elasticsearch/watcher/client/WatcherClient.java b/src/main/java/org/elasticsearch/watcher/client/WatcherClient.java index 9a45e0a828e..6d0638cdf82 100644 --- a/src/main/java/org/elasticsearch/watcher/client/WatcherClient.java +++ b/src/main/java/org/elasticsearch/watcher/client/WatcherClient.java @@ -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) { diff --git a/src/main/java/org/elasticsearch/watcher/condition/ConditionRegistry.java b/src/main/java/org/elasticsearch/watcher/condition/ConditionRegistry.java index 83e02e34727..8a7f0943316 100644 --- a/src/main/java/org/elasticsearch/watcher/condition/ConditionRegistry.java +++ b/src/main/java/org/elasticsearch/watcher/condition/ConditionRegistry.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/condition/compare/CompareCondition.java b/src/main/java/org/elasticsearch/watcher/condition/compare/CompareCondition.java index 8022b853fbc..4bf1fb74831 100644 --- a/src/main/java/org/elasticsearch/watcher/condition/compare/CompareCondition.java +++ b/src/main/java/org/elasticsearch/watcher/condition/compare/CompareCondition.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/condition/compare/ExecutableCompareCondition.java b/src/main/java/org/elasticsearch/watcher/condition/compare/ExecutableCompareCondition.java index 6d411f67505..06eb243601d 100644 --- a/src/main/java/org/elasticsearch/watcher/condition/compare/ExecutableCompareCondition.java +++ b/src/main/java/org/elasticsearch/watcher/condition/compare/ExecutableCompareCondition.java @@ -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 events) throws WatcherException { if (!started.get()) { - throw new ElasticsearchIllegalStateException("not started"); + throw new IllegalStateException("not started"); } final LinkedList triggeredWatches = new LinkedList<>(); final LinkedList 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 events) throws WatcherException { if (!started.get()) { - throw new ElasticsearchIllegalStateException("not started"); + throw new IllegalStateException("not started"); } final LinkedList triggeredWatches = new LinkedList<>(); final LinkedList 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++; } diff --git a/src/main/java/org/elasticsearch/watcher/execution/InternalWatchExecutor.java b/src/main/java/org/elasticsearch/watcher/execution/InternalWatchExecutor.java index 7b017f17f38..73858f681d5 100644 --- a/src/main/java/org/elasticsearch/watcher/execution/InternalWatchExecutor.java +++ b/src/main/java/org/elasticsearch/watcher/execution/InternalWatchExecutor.java @@ -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) diff --git a/src/main/java/org/elasticsearch/watcher/execution/ManualExecutionContext.java b/src/main/java/org/elasticsearch/watcher/execution/ManualExecutionContext.java index 732bd63feab..b4614b6e51f 100644 --- a/src/main/java/org/elasticsearch/watcher/execution/ManualExecutionContext.java +++ b/src/main/java/org/elasticsearch/watcher/execution/ManualExecutionContext.java @@ -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); } diff --git a/src/main/java/org/elasticsearch/watcher/execution/QueuedWatch.java b/src/main/java/org/elasticsearch/watcher/execution/QueuedWatch.java index 81c4da2d2f2..4614188e86a 100644 --- a/src/main/java/org/elasticsearch/watcher/execution/QueuedWatch.java +++ b/src/main/java/org/elasticsearch/watcher/execution/QueuedWatch.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/execution/TriggeredExecutionContext.java b/src/main/java/org/elasticsearch/watcher/execution/TriggeredExecutionContext.java index d679fcc6baa..9464cf866c5 100644 --- a/src/main/java/org/elasticsearch/watcher/execution/TriggeredExecutionContext.java +++ b/src/main/java/org/elasticsearch/watcher/execution/TriggeredExecutionContext.java @@ -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; /** */ diff --git a/src/main/java/org/elasticsearch/watcher/execution/TriggeredWatchStore.java b/src/main/java/org/elasticsearch/watcher/execution/TriggeredWatchStore.java index f4552f456d0..4d4ea904b28 100644 --- a/src/main/java/org/elasticsearch/watcher/execution/TriggeredWatchStore.java +++ b/src/main/java/org/elasticsearch/watcher/execution/TriggeredWatchStore.java @@ -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 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 triggeredWatches, final ActionListener> listener) throws TriggeredWatchException { if (triggeredWatches.isEmpty()) { - listener.onResponse(ImmutableList.of()); + listener.onResponse(Collections.EMPTY_LIST); return; } @@ -169,7 +167,7 @@ public class TriggeredWatchStore extends AbstractComponent { put(triggeredWatches.get(0), new ActionListener() { @Override public void onResponse(Boolean success) { - listener.onResponse(ImmutableList.of(0)); + listener.onResponse(Collections.singletonList(0)); } @Override diff --git a/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionContext.java b/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionContext.java index 59fe767d58e..ed039e707ac 100644 --- a/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionContext.java +++ b/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionContext.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionResult.java b/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionResult.java index ec96a700967..67b26b4b357 100644 --- a/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionResult.java +++ b/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionResult.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionSnapshot.java b/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionSnapshot.java index 88cb043630c..01d3d60fd48 100644 --- a/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionSnapshot.java +++ b/src/main/java/org/elasticsearch/watcher/execution/WatchExecutionSnapshot.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/execution/Wid.java b/src/main/java/org/elasticsearch/watcher/execution/Wid.java index cd146b4910b..32edb38a8d8 100644 --- a/src/main/java/org/elasticsearch/watcher/execution/Wid.java +++ b/src/main/java/org/elasticsearch/watcher/execution/Wid.java @@ -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; /** * diff --git a/src/main/java/org/elasticsearch/watcher/history/HistoryStore.java b/src/main/java/org/elasticsearch/watcher/history/HistoryStore.java index 1b7335fdaac..e44a7d92a6b 100644 --- a/src/main/java/org/elasticsearch/watcher/history/HistoryStore.java +++ b/src/main/java/org/elasticsearch/watcher/history/HistoryStore.java @@ -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 entry : newSettings.getAsMap().entrySet()) { String name = "index." + entry.getKey(); diff --git a/src/main/java/org/elasticsearch/watcher/input/InputBuilders.java b/src/main/java/org/elasticsearch/watcher/input/InputBuilders.java index 6530b608fb0..31ddc1d5508 100644 --- a/src/main/java/org/elasticsearch/watcher/input/InputBuilders.java +++ b/src/main/java/org/elasticsearch/watcher/input/InputBuilders.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/input/InputRegistry.java b/src/main/java/org/elasticsearch/watcher/input/InputRegistry.java index 2f20568c03d..cd08981492e 100644 --- a/src/main/java/org/elasticsearch/watcher/input/InputRegistry.java +++ b/src/main/java/org/elasticsearch/watcher/input/InputRegistry.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/input/http/HttpInput.java b/src/main/java/org/elasticsearch/watcher/input/http/HttpInput.java index 67cfc8ab394..4145434a716 100644 --- a/src/main/java/org/elasticsearch/watcher/input/http/HttpInput.java +++ b/src/main/java/org/elasticsearch/watcher/input/http/HttpInput.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/input/search/SearchInput.java b/src/main/java/org/elasticsearch/watcher/input/search/SearchInput.java index 8b89b62bfd6..90b57f450fc 100644 --- a/src/main/java/org/elasticsearch/watcher/input/search/SearchInput.java +++ b/src/main/java/org/elasticsearch/watcher/input/search/SearchInput.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/license/LicenseModule.java b/src/main/java/org/elasticsearch/watcher/license/LicenseModule.java index b6268faae41..148e53c0a15 100644 --- a/src/main/java/org/elasticsearch/watcher/license/LicenseModule.java +++ b/src/main/java/org/elasticsearch/watcher/license/LicenseModule.java @@ -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 + "]"); } diff --git a/src/main/java/org/elasticsearch/watcher/license/LicenseService.java b/src/main/java/org/elasticsearch/watcher/license/LicenseService.java index 239395b749b..2744c67099b 100644 --- a/src/main/java/org/elasticsearch/watcher/license/LicenseService.java +++ b/src/main/java/org/elasticsearch/watcher/license/LicenseService.java @@ -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 { 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) { diff --git a/src/main/java/org/elasticsearch/watcher/shield/ShieldIntegration.java b/src/main/java/org/elasticsearch/watcher/shield/ShieldIntegration.java index 97389daffe0..be14f2ece49 100644 --- a/src/main/java/org/elasticsearch/watcher/shield/ShieldIntegration.java +++ b/src/main/java/org/elasticsearch/watcher/shield/ShieldIntegration.java @@ -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 + "]"); } diff --git a/src/main/java/org/elasticsearch/watcher/shield/ShieldSecretService.java b/src/main/java/org/elasticsearch/watcher/shield/ShieldSecretService.java index 72766d19071..880db47d5fc 100644 --- a/src/main/java/org/elasticsearch/watcher/shield/ShieldSecretService.java +++ b/src/main/java/org/elasticsearch/watcher/shield/ShieldSecretService.java @@ -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; } diff --git a/src/main/java/org/elasticsearch/watcher/support/Script.java b/src/main/java/org/elasticsearch/watcher/support/Script.java index 77e621b49fa..6d39af1769c 100644 --- a/src/main/java/org/elasticsearch/watcher/support/Script.java +++ b/src/main/java/org/elasticsearch/watcher/support/Script.java @@ -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 params() { - return params != null ? params : ImmutableMap.of(); + return params != null ? params : Collections.EMPTY_MAP; } @Override diff --git a/src/main/java/org/elasticsearch/watcher/support/SearchRequestEquivalence.java b/src/main/java/org/elasticsearch/watcher/support/SearchRequestEquivalence.java index 6c70ce09c0f..f1ee9523be8 100644 --- a/src/main/java/org/elasticsearch/watcher/support/SearchRequestEquivalence.java +++ b/src/main/java/org/elasticsearch/watcher/support/SearchRequestEquivalence.java @@ -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 diff --git a/src/main/java/org/elasticsearch/watcher/support/TemplateUtils.java b/src/main/java/org/elasticsearch/watcher/support/TemplateUtils.java index 9fd587ccf5d..784b050d8b4 100644 --- a/src/main/java/org/elasticsearch/watcher/support/TemplateUtils.java +++ b/src/main/java/org/elasticsearch/watcher/support/TemplateUtils.java @@ -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(); diff --git a/src/main/java/org/elasticsearch/watcher/support/ThreadPoolSettingsBuilder.java b/src/main/java/org/elasticsearch/watcher/support/ThreadPoolSettingsBuilder.java index a21c5b3dd79..0a2f22e6a49 100644 --- a/src/main/java/org/elasticsearch/watcher/support/ThreadPoolSettingsBuilder.java +++ b/src/main/java/org/elasticsearch/watcher/support/ThreadPoolSettingsBuilder.java @@ -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 { 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 { 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 { 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 { 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); diff --git a/src/main/java/org/elasticsearch/watcher/support/http/HttpClient.java b/src/main/java/org/elasticsearch/watcher/support/http/HttpClient.java index 7e471b080a0..6b220f20517 100644 --- a/src/main/java/org/elasticsearch/watcher/support/http/HttpClient.java +++ b/src/main/java/org/elasticsearch/watcher/support/http/HttpClient.java @@ -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 { 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 { 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 { } 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 { 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 { 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 { } } - 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); } diff --git a/src/main/java/org/elasticsearch/watcher/support/http/HttpClientModule.java b/src/main/java/org/elasticsearch/watcher/support/http/HttpClientModule.java index 440ca2a2b79..5441f423878 100644 --- a/src/main/java/org/elasticsearch/watcher/support/http/HttpClientModule.java +++ b/src/main/java/org/elasticsearch/watcher/support/http/HttpClientModule.java @@ -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 spawnModules() { - return ImmutableList.of(new AuthModule()); + return Collections.singletonList(new AuthModule()); } @Override diff --git a/src/main/java/org/elasticsearch/watcher/support/http/HttpMethod.java b/src/main/java/org/elasticsearch/watcher/support/http/HttpMethod.java index d8765edd99e..c31957878c6 100644 --- a/src/main/java/org/elasticsearch/watcher/support/http/HttpMethod.java +++ b/src/main/java/org/elasticsearch/watcher/support/http/HttpMethod.java @@ -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 + "]"); } } diff --git a/src/main/java/org/elasticsearch/watcher/support/http/HttpRequest.java b/src/main/java/org/elasticsearch/watcher/support/http/HttpRequest.java index feb881b3de2..8543bcbbc74 100644 --- a/src/main/java/org/elasticsearch/watcher/support/http/HttpRequest.java +++ b/src/main/java/org/elasticsearch/watcher/support/http/HttpRequest.java @@ -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); } diff --git a/src/main/java/org/elasticsearch/watcher/support/http/HttpRequestTemplate.java b/src/main/java/org/elasticsearch/watcher/support/http/HttpRequestTemplate.java index 4cd516e77bd..caa11c4fc7c 100644 --- a/src/main/java/org/elasticsearch/watcher/support/http/HttpRequestTemplate.java +++ b/src/main/java/org/elasticsearch/watcher/support/http/HttpRequestTemplate.java @@ -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); } } diff --git a/src/main/java/org/elasticsearch/watcher/support/http/HttpResponse.java b/src/main/java/org/elasticsearch/watcher/support/http/HttpResponse.java index d6a85d3679e..6fe81a09a6c 100644 --- a/src/main/java/org/elasticsearch/watcher/support/http/HttpResponse.java +++ b/src/main/java/org/elasticsearch/watcher/support/http/HttpResponse.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/support/http/Scheme.java b/src/main/java/org/elasticsearch/watcher/support/http/Scheme.java index 3b8e1746616..4f0631bc39d 100644 --- a/src/main/java/org/elasticsearch/watcher/support/http/Scheme.java +++ b/src/main/java/org/elasticsearch/watcher/support/http/Scheme.java @@ -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 + "]"); } } diff --git a/src/main/java/org/elasticsearch/watcher/support/http/auth/HttpAuthRegistry.java b/src/main/java/org/elasticsearch/watcher/support/http/auth/HttpAuthRegistry.java index 66a6abbc474..cd9d2de7a56 100644 --- a/src/main/java/org/elasticsearch/watcher/support/http/auth/HttpAuthRegistry.java +++ b/src/main/java/org/elasticsearch/watcher/support/http/auth/HttpAuthRegistry.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/support/http/auth/basic/ApplicableBasicAuth.java b/src/main/java/org/elasticsearch/watcher/support/http/auth/basic/ApplicableBasicAuth.java index 038e2b4ca65..fea32976f5a 100644 --- a/src/main/java/org/elasticsearch/watcher/support/http/auth/basic/ApplicableBasicAuth.java +++ b/src/main/java/org/elasticsearch/watcher/support/http/auth/basic/ApplicableBasicAuth.java @@ -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 { } 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) { diff --git a/src/main/java/org/elasticsearch/watcher/support/init/proxy/ClientProxy.java b/src/main/java/org/elasticsearch/watcher/support/init/proxy/ClientProxy.java index 0db5a030c2b..7be03fdf4ff 100644 --- a/src/main/java/org/elasticsearch/watcher/support/init/proxy/ClientProxy.java +++ b/src/main/java/org/elasticsearch/watcher/support/init/proxy/ClientProxy.java @@ -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 listener) { - request.listenerThreaded(true); client.index(preProcess(request), listener); } public void bulk(BulkRequest request, ActionListener listener) { - request.listenerThreaded(true); client.bulk(preProcess(request), listener); } diff --git a/src/main/java/org/elasticsearch/watcher/support/init/proxy/ScriptServiceProxy.java b/src/main/java/org/elasticsearch/watcher/support/init/proxy/ScriptServiceProxy.java index 09300c9d977..edafbfbb6b7 100644 --- a/src/main/java/org/elasticsearch/watcher/support/init/proxy/ScriptServiceProxy.java +++ b/src/main/java/org/elasticsearch/watcher/support/init/proxy/ScriptServiceProxy.java @@ -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 vars) { return service.executable(compiledScript, vars); } - public ExecutableScript executable(Script script, Map vars) { - if (script.params() != null && !script.params().isEmpty()) { - vars = ImmutableMap.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 vars) { - return service.executable(lang, script, scriptType, vars); - } - - public SearchScript search(SearchLookup lookup, String lang, String script, ScriptService.ScriptType scriptType, Map vars) { - return service.search(lookup, lang, script, scriptType, vars); } } diff --git a/src/main/java/org/elasticsearch/watcher/support/secret/SensitiveXContentParser.java b/src/main/java/org/elasticsearch/watcher/support/secret/SensitiveXContentParser.java index cc200620b01..729f00c6ce2 100644 --- a/src/main/java/org/elasticsearch/watcher/support/secret/SensitiveXContentParser.java +++ b/src/main/java/org/elasticsearch/watcher/support/secret/SensitiveXContentParser.java @@ -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(); diff --git a/src/main/java/org/elasticsearch/watcher/support/template/MustacheTemplateEngine.java b/src/main/java/org/elasticsearch/watcher/support/template/MustacheTemplateEngine.java index c1a8f91c3ad..4fc439db42e 100644 --- a/src/main/java/org/elasticsearch/watcher/support/template/MustacheTemplateEngine.java +++ b/src/main/java/org/elasticsearch/watcher/support/template/MustacheTemplateEngine.java @@ -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 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(); diff --git a/src/main/java/org/elasticsearch/watcher/support/template/Template.java b/src/main/java/org/elasticsearch/watcher/support/template/Template.java index 335a673d296..485c46335c8 100644 --- a/src/main/java/org/elasticsearch/watcher/support/template/Template.java +++ b/src/main/java/org/elasticsearch/watcher/support/template/Template.java @@ -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 getParams() { - return params != null ? params : ImmutableMap.of(); + return params != null ? params : Collections.EMPTY_MAP; } @Override diff --git a/src/main/java/org/elasticsearch/watcher/support/template/TemplateModule.java b/src/main/java/org/elasticsearch/watcher/support/template/TemplateModule.java index dc23a07fbf0..773a2feeef9 100644 --- a/src/main/java/org/elasticsearch/watcher/support/template/TemplateModule.java +++ b/src/main/java/org/elasticsearch/watcher/support/template/TemplateModule.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/support/template/xmustache/XMustacheFactory.java b/src/main/java/org/elasticsearch/watcher/support/template/xmustache/XMustacheFactory.java index 8d4f4ae9aa9..19b223e04b8 100644 --- a/src/main/java/org/elasticsearch/watcher/support/template/xmustache/XMustacheFactory.java +++ b/src/main/java/org/elasticsearch/watcher/support/template/xmustache/XMustacheFactory.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/support/template/xmustache/XMustacheScriptEngineService.java b/src/main/java/org/elasticsearch/watcher/support/template/xmustache/XMustacheScriptEngineService.java index a1dc983029e..e41b8804e77 100644 --- a/src/main/java/org/elasticsearch/watcher/support/template/xmustache/XMustacheScriptEngineService.java +++ b/src/main/java/org/elasticsearch/watcher/support/template/xmustache/XMustacheScriptEngineService.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/support/template/xmustache/XMustacheTemplateEngine.java b/src/main/java/org/elasticsearch/watcher/support/template/xmustache/XMustacheTemplateEngine.java index 099ccc5b686..9bc88192b8e 100644 --- a/src/main/java/org/elasticsearch/watcher/support/template/xmustache/XMustacheTemplateEngine.java +++ b/src/main/java/org/elasticsearch/watcher/support/template/xmustache/XMustacheTemplateEngine.java @@ -35,7 +35,7 @@ public class XMustacheTemplateEngine extends AbstractComponent implements Templa Map 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(); diff --git a/src/main/java/org/elasticsearch/watcher/support/xcontent/WatcherParams.java b/src/main/java/org/elasticsearch/watcher/support/xcontent/WatcherParams.java index 734fd4dd981..e42d0519320 100644 --- a/src/main/java/org/elasticsearch/watcher/support/xcontent/WatcherParams.java +++ b/src/main/java/org/elasticsearch/watcher/support/xcontent/WatcherParams.java @@ -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 params; - private WatcherParams(ImmutableMap 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); } diff --git a/src/main/java/org/elasticsearch/watcher/support/xcontent/WatcherXContentUtils.java b/src/main/java/org/elasticsearch/watcher/support/xcontent/WatcherXContentUtils.java index b737c14bbcb..5899d39f5cc 100644 --- a/src/main/java/org/elasticsearch/watcher/support/xcontent/WatcherXContentUtils.java +++ b/src/main/java/org/elasticsearch/watcher/support/xcontent/WatcherXContentUtils.java @@ -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 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); } diff --git a/src/main/java/org/elasticsearch/watcher/support/xcontent/XContentSource.java b/src/main/java/org/elasticsearch/watcher/support/xcontent/XContentSource.java index d81bb006804..d614ee71be0 100644 --- a/src/main/java/org/elasticsearch/watcher/support/xcontent/XContentSource.java +++ b/src/main/java/org/elasticsearch/watcher/support/xcontent/XContentSource.java @@ -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 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; } diff --git a/src/main/java/org/elasticsearch/watcher/transform/TransformRegistry.java b/src/main/java/org/elasticsearch/watcher/transform/TransformRegistry.java index 650b1eb7e3b..20876444a61 100644 --- a/src/main/java/org/elasticsearch/watcher/transform/TransformRegistry.java +++ b/src/main/java/org/elasticsearch/watcher/transform/TransformRegistry.java @@ -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 factories; + private final Map factories; @Inject public TransformRegistry(Map factories) { diff --git a/src/main/java/org/elasticsearch/watcher/transform/chain/ChainTransform.java b/src/main/java/org/elasticsearch/watcher/transform/chain/ChainTransform.java index d2f92bf5ba4..3bc19b0deb3 100644 --- a/src/main/java/org/elasticsearch/watcher/transform/chain/ChainTransform.java +++ b/src/main/java/org/elasticsearch/watcher/transform/chain/ChainTransform.java @@ -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 getTransforms() { + public List getTransforms() { return transforms; } diff --git a/src/main/java/org/elasticsearch/watcher/transform/chain/ChainTransformFactory.java b/src/main/java/org/elasticsearch/watcher/transform/chain/ChainTransformFactory.java index 60dcfcf5220..4f3b4947450 100644 --- a/src/main/java/org/elasticsearch/watcher/transform/chain/ChainTransformFactory.java +++ b/src/main/java/org/elasticsearch/watcher/transform/chain/ChainTransformFactory.java @@ -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; diff --git a/src/main/java/org/elasticsearch/watcher/transform/chain/ExecutableChainTransform.java b/src/main/java/org/elasticsearch/watcher/transform/chain/ExecutableChainTransform.java index 94d7244c180..4ee6cc65b21 100644 --- a/src/main/java/org/elasticsearch/watcher/transform/chain/ExecutableChainTransform.java +++ b/src/main/java/org/elasticsearch/watcher/transform/chain/ExecutableChainTransform.java @@ -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 executableTransforms() { + public List executableTransforms() { return transforms; } diff --git a/src/main/java/org/elasticsearch/watcher/transport/actions/WatcherTransportAction.java b/src/main/java/org/elasticsearch/watcher/transport/actions/WatcherTransportAction.java index 4d9b3461cea..3740474e46f 100644 --- a/src/main/java/org/elasticsearch/watcher/transport/actions/WatcherTransportAction.java +++ b/src/main/java/org/elasticsearch/watcher/transport/actions/WatcherTransportAction.java @@ -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, Response extends ActionResponse> extends TransportMasterNodeOperationAction { +public abstract class WatcherTransportAction, Response extends ActionResponse> extends TransportMasterNodeAction { 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) { + super(settings, actionName, transportService, clusterService, threadPool, actionFilters, request); this.licenseService = licenseService; } diff --git a/src/main/java/org/elasticsearch/watcher/transport/actions/ack/AckWatchAction.java b/src/main/java/org/elasticsearch/watcher/transport/actions/ack/AckWatchAction.java index 3570e15ffe3..010872e11ee 100644 --- a/src/main/java/org/elasticsearch/watcher/transport/actions/ack/AckWatchAction.java +++ b/src/main/java/org/elasticsearch/watcher/transport/actions/ack/AckWatchAction.java @@ -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 { +public class AckWatchAction extends Action { 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 { +public class AckWatchRequest extends MasterNodeRequest { private static final TimeValue DEFAULT_TIMEOUT = TimeValue.timeValueSeconds(10); diff --git a/src/main/java/org/elasticsearch/watcher/transport/actions/ack/AckWatchRequestBuilder.java b/src/main/java/org/elasticsearch/watcher/transport/actions/ack/AckWatchRequestBuilder.java index b4506338f51..37d36e25de0 100644 --- a/src/main/java/org/elasticsearch/watcher/transport/actions/ack/AckWatchRequestBuilder.java +++ b/src/main/java/org/elasticsearch/watcher/transport/actions/ack/AckWatchRequestBuilder.java @@ -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 { +public class AckWatchRequestBuilder extends MasterNodeOperationRequestBuilder { - 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 listener) { - new WatcherClient(client).ackWatch(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/watcher/transport/actions/ack/TransportAckWatchAction.java b/src/main/java/org/elasticsearch/watcher/transport/actions/ack/TransportAckWatchAction.java index dcce5f77642..14e2c9605d3 100644 --- a/src/main/java/org/elasticsearch/watcher/transport/actions/ack/TransportAckWatchAction.java +++ b/src/main/java/org/elasticsearch/watcher/transport/actions/ack/TransportAckWatchAction.java @@ -32,7 +32,7 @@ public class TransportAckWatchAction extends WatcherTransportAction { +public class DeleteWatchAction extends Action { 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 { +public class DeleteWatchRequest extends MasterNodeRequest { private static final TimeValue DEFAULT_TIMEOUT = TimeValue.timeValueSeconds(10); @@ -94,7 +94,7 @@ public class DeleteWatchRequest extends MasterNodeOperationRequest { +public class DeleteWatchRequestBuilder extends MasterNodeOperationRequestBuilder { - 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 listener) { - new WatcherClient(client).deleteWatch(request, listener); - } - } diff --git a/src/main/java/org/elasticsearch/watcher/transport/actions/delete/TransportDeleteWatchAction.java b/src/main/java/org/elasticsearch/watcher/transport/actions/delete/TransportDeleteWatchAction.java index 784f717fb92..ea9e42c23bf 100644 --- a/src/main/java/org/elasticsearch/watcher/transport/actions/delete/TransportDeleteWatchAction.java +++ b/src/main/java/org/elasticsearch/watcher/transport/actions/delete/TransportDeleteWatchAction.java @@ -32,7 +32,7 @@ public class TransportDeleteWatchAction extends WatcherTransportAction { +public class ExecuteWatchAction extends Action { 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 { +public class ExecuteWatchRequest extends MasterNodeReadRequest { public static final String INLINE_WATCH_ID = "_inlined_"; diff --git a/src/main/java/org/elasticsearch/watcher/transport/actions/execute/ExecuteWatchRequestBuilder.java b/src/main/java/org/elasticsearch/watcher/transport/actions/execute/ExecuteWatchRequestBuilder.java index 95589d7d233..68b3cf688f1 100644 --- a/src/main/java/org/elasticsearch/watcher/transport/actions/execute/ExecuteWatchRequestBuilder.java +++ b/src/main/java/org/elasticsearch/watcher/transport/actions/execute/ExecuteWatchRequestBuilder.java @@ -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 { +public class ExecuteWatchRequestBuilder extends MasterNodeOperationRequestBuilder { - 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 listener) { - new WatcherClient(client).executeWatch(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/watcher/transport/actions/execute/TransportExecuteWatchAction.java b/src/main/java/org/elasticsearch/watcher/transport/actions/execute/TransportExecuteWatchAction.java index d7f6ded09de..558c85e44aa 100644 --- a/src/main/java/org/elasticsearch/watcher/transport/actions/execute/TransportExecuteWatchAction.java +++ b/src/main/java/org/elasticsearch/watcher/transport/actions/execute/TransportExecuteWatchAction.java @@ -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 entry : request.getActionModes().entrySet()) { ctxBuilder.actionMode(entry.getKey(), entry.getValue()); diff --git a/src/main/java/org/elasticsearch/watcher/transport/actions/get/GetWatchAction.java b/src/main/java/org/elasticsearch/watcher/transport/actions/get/GetWatchAction.java index 499ea0bf9fa..710dbbc1eff 100644 --- a/src/main/java/org/elasticsearch/watcher/transport/actions/get/GetWatchAction.java +++ b/src/main/java/org/elasticsearch/watcher/transport/actions/get/GetWatchAction.java @@ -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 { +public class GetWatchAction extends org.elasticsearch.action.Action { 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 { +public class GetWatchRequest extends MasterNodeReadRequest { private String id; private long version = Versions.MATCH_ANY; @@ -87,7 +88,7 @@ public class GetWatchRequest extends MasterNodeOperationRequest @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 @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); } diff --git a/src/main/java/org/elasticsearch/watcher/transport/actions/get/GetWatchRequestBuilder.java b/src/main/java/org/elasticsearch/watcher/transport/actions/get/GetWatchRequestBuilder.java index 3a5fe88e46c..a28d82c7eba 100644 --- a/src/main/java/org/elasticsearch/watcher/transport/actions/get/GetWatchRequestBuilder.java +++ b/src/main/java/org/elasticsearch/watcher/transport/actions/get/GetWatchRequestBuilder.java @@ -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 { +public class GetWatchRequestBuilder extends MasterNodeReadOperationRequestBuilder { - 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 listener) { - new WatcherClient(client).getWatch(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/watcher/transport/actions/get/TransportGetWatchAction.java b/src/main/java/org/elasticsearch/watcher/transport/actions/get/TransportGetWatchAction.java index d403418da04..3c07fc03be7 100644 --- a/src/main/java/org/elasticsearch/watcher/transport/actions/get/TransportGetWatchAction.java +++ b/src/main/java/org/elasticsearch/watcher/transport/actions/get/TransportGetWatchAction.java @@ -38,7 +38,7 @@ public class TransportGetWatchAction extends WatcherTransportAction { +public class PutWatchAction extends Action { 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 { +public class PutWatchRequest extends MasterNodeRequest { private static final TimeValue DEFAULT_TIMEOUT = TimeValue.timeValueSeconds(10); diff --git a/src/main/java/org/elasticsearch/watcher/transport/actions/put/PutWatchRequestBuilder.java b/src/main/java/org/elasticsearch/watcher/transport/actions/put/PutWatchRequestBuilder.java index 1c08f4db762..6cf607a5b3e 100644 --- a/src/main/java/org/elasticsearch/watcher/transport/actions/put/PutWatchRequestBuilder.java +++ b/src/main/java/org/elasticsearch/watcher/transport/actions/put/PutWatchRequestBuilder.java @@ -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 { +public class PutWatchRequestBuilder extends MasterNodeOperationRequestBuilder { - 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 listener) { - new WatcherClient(client).putWatch(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/watcher/transport/actions/put/TransportPutWatchAction.java b/src/main/java/org/elasticsearch/watcher/transport/actions/put/TransportPutWatchAction.java index 7bbf005c554..d43627cbf48 100644 --- a/src/main/java/org/elasticsearch/watcher/transport/actions/put/TransportPutWatchAction.java +++ b/src/main/java/org/elasticsearch/watcher/transport/actions/put/TransportPutWatchAction.java @@ -31,7 +31,7 @@ public class TransportPutWatchAction extends WatcherTransportAction { + +public class WatcherServiceAction extends Action { 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 { +public class WatcherServiceRequest extends MasterNodeRequest { enum Command { START, STOP, RESTART } diff --git a/src/main/java/org/elasticsearch/watcher/transport/actions/service/WatcherServiceRequestBuilder.java b/src/main/java/org/elasticsearch/watcher/transport/actions/service/WatcherServiceRequestBuilder.java index d984c4b42d2..80f7ad263b5 100644 --- a/src/main/java/org/elasticsearch/watcher/transport/actions/service/WatcherServiceRequestBuilder.java +++ b/src/main/java/org/elasticsearch/watcher/transport/actions/service/WatcherServiceRequestBuilder.java @@ -7,15 +7,16 @@ package org.elasticsearch.watcher.transport.actions.service; 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; /** */ -public class WatcherServiceRequestBuilder extends MasterNodeOperationRequestBuilder { +public class WatcherServiceRequestBuilder extends MasterNodeOperationRequestBuilder { - public WatcherServiceRequestBuilder(Client client) { - super(client, new WatcherServiceRequest()); + public WatcherServiceRequestBuilder(ElasticsearchClient client) { + super(client, WatcherServiceAction.INSTANCE, new WatcherServiceRequest()); } /** @@ -41,9 +42,4 @@ public class WatcherServiceRequestBuilder extends MasterNodeOperationRequestBuil request.restart(); return this; } - - @Override - protected void doExecute(ActionListener listener) { - new WatcherClient(client).watcherService(request, listener); - } } diff --git a/src/main/java/org/elasticsearch/watcher/transport/actions/stats/TransportWatcherStatsAction.java b/src/main/java/org/elasticsearch/watcher/transport/actions/stats/TransportWatcherStatsAction.java index 6c0b8550769..9fd1fb29a3a 100644 --- a/src/main/java/org/elasticsearch/watcher/transport/actions/stats/TransportWatcherStatsAction.java +++ b/src/main/java/org/elasticsearch/watcher/transport/actions/stats/TransportWatcherStatsAction.java @@ -35,7 +35,7 @@ public class TransportWatcherStatsAction extends WatcherTransportAction { +public class WatcherStatsAction extends Action { public static final WatcherStatsAction INSTANCE = new WatcherStatsAction(); public static final String NAME = "cluster:monitor/watcher/stats"; @@ -26,7 +26,7 @@ public class WatcherStatsAction extends WatcherAction { +public class WatcherStatsRequest extends MasterNodeReadRequest { private boolean includeCurrentWatches; private boolean includeQueuedWatches; diff --git a/src/main/java/org/elasticsearch/watcher/transport/actions/stats/WatcherStatsRequestBuilder.java b/src/main/java/org/elasticsearch/watcher/transport/actions/stats/WatcherStatsRequestBuilder.java index 541345f0421..9bfeadaf296 100644 --- a/src/main/java/org/elasticsearch/watcher/transport/actions/stats/WatcherStatsRequestBuilder.java +++ b/src/main/java/org/elasticsearch/watcher/transport/actions/stats/WatcherStatsRequestBuilder.java @@ -7,16 +7,18 @@ package org.elasticsearch.watcher.transport.actions.stats; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.master.MasterNodeOperationRequestBuilder; +import org.elasticsearch.action.support.master.MasterNodeReadOperationRequestBuilder; +import org.elasticsearch.client.ElasticsearchClient; import org.elasticsearch.watcher.client.WatcherClient; import org.elasticsearch.client.Client; /** * Watcher stats request builder. */ -public class WatcherStatsRequestBuilder extends MasterNodeOperationRequestBuilder { +public class WatcherStatsRequestBuilder extends MasterNodeReadOperationRequestBuilder { - public WatcherStatsRequestBuilder(Client client) { - super(client, new WatcherStatsRequest()); + public WatcherStatsRequestBuilder(ElasticsearchClient client) { + super(client, WatcherStatsAction.INSTANCE, new WatcherStatsRequest()); } public WatcherStatsRequestBuilder setIncludeCurrentWatches(boolean includeCurrentWatches) { @@ -27,10 +29,4 @@ public class WatcherStatsRequestBuilder extends MasterNodeOperationRequestBuilde request().includeQueuedWatches(includeQueuedWatches); return this; } - - @Override - protected void doExecute(final ActionListener listener) { - new WatcherClient(client).watcherStats(request, listener); - } - } diff --git a/src/main/java/org/elasticsearch/watcher/trigger/TriggerEvent.java b/src/main/java/org/elasticsearch/watcher/trigger/TriggerEvent.java index e75343db470..80689b53f48 100644 --- a/src/main/java/org/elasticsearch/watcher/trigger/TriggerEvent.java +++ b/src/main/java/org/elasticsearch/watcher/trigger/TriggerEvent.java @@ -6,10 +6,10 @@ package org.elasticsearch.watcher.trigger; 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.support.WatcherDateTimeUtils; +import org.joda.time.DateTime; import java.io.IOException; import java.util.HashMap; diff --git a/src/main/java/org/elasticsearch/watcher/trigger/TriggerModule.java b/src/main/java/org/elasticsearch/watcher/trigger/TriggerModule.java index 5a46dfeb41b..a9f0b080603 100644 --- a/src/main/java/org/elasticsearch/watcher/trigger/TriggerModule.java +++ b/src/main/java/org/elasticsearch/watcher/trigger/TriggerModule.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.watcher.trigger; -import org.elasticsearch.common.collect.ImmutableSet; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.SpawnModules; @@ -14,6 +13,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.watcher.trigger.manual.ManualTriggerEngine; import org.elasticsearch.watcher.trigger.schedule.ScheduleModule; +import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -41,7 +41,7 @@ public class TriggerModule extends AbstractModule implements SpawnModules { @Override public Iterable spawnModules() { - return ImmutableSet.of(new ScheduleModule()); + return Collections.singleton(new ScheduleModule()); } @Override diff --git a/src/main/java/org/elasticsearch/watcher/trigger/TriggerService.java b/src/main/java/org/elasticsearch/watcher/trigger/TriggerService.java index b33be545c36..4394c42e164 100644 --- a/src/main/java/org/elasticsearch/watcher/trigger/TriggerService.java +++ b/src/main/java/org/elasticsearch/watcher/trigger/TriggerService.java @@ -5,8 +5,8 @@ */ package org.elasticsearch.watcher.trigger; +import com.google.common.collect.ImmutableMap; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.collect.ImmutableMap; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; diff --git a/src/main/java/org/elasticsearch/watcher/trigger/schedule/Cron.java b/src/main/java/org/elasticsearch/watcher/trigger/schedule/Cron.java index a505eaa871a..1bf18250b6f 100644 --- a/src/main/java/org/elasticsearch/watcher/trigger/schedule/Cron.java +++ b/src/main/java/org/elasticsearch/watcher/trigger/schedule/Cron.java @@ -5,9 +5,9 @@ */ package org.elasticsearch.watcher.trigger.schedule; -import org.elasticsearch.common.joda.time.DateTimeZone; -import org.elasticsearch.common.joda.time.format.DateTimeFormat; -import org.elasticsearch.common.joda.time.format.DateTimeFormatter; +import org.joda.time.DateTimeZone; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; import org.elasticsearch.watcher.trigger.TriggerException; import java.util.*; diff --git a/src/main/java/org/elasticsearch/watcher/trigger/schedule/HourlySchedule.java b/src/main/java/org/elasticsearch/watcher/trigger/schedule/HourlySchedule.java index cc61e0a85d3..e0320fb1e77 100644 --- a/src/main/java/org/elasticsearch/watcher/trigger/schedule/HourlySchedule.java +++ b/src/main/java/org/elasticsearch/watcher/trigger/schedule/HourlySchedule.java @@ -5,8 +5,8 @@ */ package org.elasticsearch.watcher.trigger.schedule; +import com.google.common.primitives.Ints; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.primitives.Ints; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.watcher.trigger.schedule.support.DayTimes; diff --git a/src/main/java/org/elasticsearch/watcher/trigger/schedule/ScheduleModule.java b/src/main/java/org/elasticsearch/watcher/trigger/schedule/ScheduleModule.java index 0220b2b5283..080629a3f33 100644 --- a/src/main/java/org/elasticsearch/watcher/trigger/schedule/ScheduleModule.java +++ b/src/main/java/org/elasticsearch/watcher/trigger/schedule/ScheduleModule.java @@ -75,7 +75,7 @@ public class ScheduleModule extends AbstractModule { protected abstract Class engineType(); public static Engine resolve(Settings settings) { - String engine = settings.getComponentSettings(ScheduleModule.class).get("engine", "ticker"); + String engine = settings.get("watcher.trigger.schedule.engine", "ticker"); switch (engine.toLowerCase(Locale.ROOT)) { case "ticker" : return TICKER; case "scheduler" : return SCHEDULER; diff --git a/src/main/java/org/elasticsearch/watcher/trigger/schedule/ScheduleRegistry.java b/src/main/java/org/elasticsearch/watcher/trigger/schedule/ScheduleRegistry.java index 177a3e3b646..d83232bb333 100644 --- a/src/main/java/org/elasticsearch/watcher/trigger/schedule/ScheduleRegistry.java +++ b/src/main/java/org/elasticsearch/watcher/trigger/schedule/ScheduleRegistry.java @@ -5,7 +5,7 @@ */ package org.elasticsearch.watcher.trigger.schedule; -import org.elasticsearch.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.xcontent.XContentParser; diff --git a/src/main/java/org/elasticsearch/watcher/trigger/schedule/ScheduleTriggerEngine.java b/src/main/java/org/elasticsearch/watcher/trigger/schedule/ScheduleTriggerEngine.java index f79cf26c3e9..9965a6a894e 100644 --- a/src/main/java/org/elasticsearch/watcher/trigger/schedule/ScheduleTriggerEngine.java +++ b/src/main/java/org/elasticsearch/watcher/trigger/schedule/ScheduleTriggerEngine.java @@ -5,7 +5,7 @@ */ package org.elasticsearch.watcher.trigger.schedule; -import org.elasticsearch.common.joda.time.DateTime; +import org.joda.time.DateTime; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.watcher.support.WatcherDateTimeUtils; diff --git a/src/main/java/org/elasticsearch/watcher/trigger/schedule/ScheduleTriggerEvent.java b/src/main/java/org/elasticsearch/watcher/trigger/schedule/ScheduleTriggerEvent.java index a763377b745..323ee1d23b0 100644 --- a/src/main/java/org/elasticsearch/watcher/trigger/schedule/ScheduleTriggerEvent.java +++ b/src/main/java/org/elasticsearch/watcher/trigger/schedule/ScheduleTriggerEvent.java @@ -6,18 +6,17 @@ package org.elasticsearch.watcher.trigger.schedule; 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.WatcherException; import org.elasticsearch.watcher.support.WatcherDateTimeUtils; import org.elasticsearch.watcher.support.clock.Clock; import org.elasticsearch.watcher.trigger.TriggerEvent; +import org.joda.time.DateTimeZone; import java.io.IOException; -import static org.elasticsearch.common.joda.time.DateTimeZone.UTC; - /** * */ @@ -70,14 +69,14 @@ public class ScheduleTriggerEvent extends TriggerEvent { currentFieldName = parser.currentName(); } else if (Field.TRIGGERED_TIME.match(currentFieldName)) { try { - triggeredTime = WatcherDateTimeUtils.parseDateMath(currentFieldName, parser, UTC, clock); + triggeredTime = WatcherDateTimeUtils.parseDateMath(currentFieldName, parser, DateTimeZone.UTC, clock); } catch (WatcherDateTimeUtils.ParseException pe) { //Failed to parse as a date try datemath parsing throw new ParseException("could not parse [{}] trigger event for [{}] for watch [{}]. failed to parse date field [{}]", pe, ScheduleTriggerEngine.TYPE, context, watchId, currentFieldName); } } else if (Field.SCHEDULED_TIME.match(currentFieldName)) { try { - scheduledTime = WatcherDateTimeUtils.parseDateMath(currentFieldName, parser, UTC, clock); + scheduledTime = WatcherDateTimeUtils.parseDateMath(currentFieldName, parser, DateTimeZone.UTC, clock); } catch (WatcherDateTimeUtils.ParseException pe) { throw new ParseException("could not parse [{}] trigger event for [{}] for watch [{}]. failed to parse date field [{}]", pe, ScheduleTriggerEngine.TYPE, context, watchId, currentFieldName); } diff --git a/src/main/java/org/elasticsearch/watcher/trigger/schedule/engine/SchedulerScheduleTriggerEngine.java b/src/main/java/org/elasticsearch/watcher/trigger/schedule/engine/SchedulerScheduleTriggerEngine.java index 9877502fc67..4239f34d777 100644 --- a/src/main/java/org/elasticsearch/watcher/trigger/schedule/engine/SchedulerScheduleTriggerEngine.java +++ b/src/main/java/org/elasticsearch/watcher/trigger/schedule/engine/SchedulerScheduleTriggerEngine.java @@ -5,15 +5,17 @@ */ package org.elasticsearch.watcher.trigger.schedule.engine; -import org.elasticsearch.common.collect.ImmutableList; -import org.elasticsearch.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.joda.time.DateTime; +import org.elasticsearch.common.util.concurrent.FutureUtils; +import org.joda.time.DateTime; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.watcher.support.clock.Clock; import org.elasticsearch.watcher.trigger.TriggerEvent; import org.elasticsearch.watcher.trigger.schedule.*; +import org.joda.time.DateTimeZone; import java.util.ArrayList; import java.util.Collection; @@ -23,7 +25,6 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import static org.elasticsearch.common.joda.time.DateTimeZone.UTC; /** * */ @@ -84,8 +85,8 @@ public class SchedulerScheduleTriggerEngine extends ScheduleTriggerEngine { } protected void notifyListeners(String name, long triggeredTime, long scheduledTime) { - logger.trace("triggered job [{}] at [{}] (scheduled time was [{}])", name, new DateTime(triggeredTime, UTC), new DateTime(scheduledTime, UTC)); - final ScheduleTriggerEvent event = new ScheduleTriggerEvent(name, new DateTime(triggeredTime, UTC), new DateTime(scheduledTime, UTC)); + logger.trace("triggered job [{}] at [{}] (scheduled time was [{}])", name, new DateTime(triggeredTime, DateTimeZone.UTC), new DateTime(scheduledTime, DateTimeZone.UTC)); + final ScheduleTriggerEvent event = new ScheduleTriggerEvent(name, new DateTime(triggeredTime, DateTimeZone.UTC), new DateTime(scheduledTime, DateTimeZone.UTC)); for (Listener listener : listeners) { listener.triggered(ImmutableList.of(event)); } @@ -123,9 +124,7 @@ public class SchedulerScheduleTriggerEngine extends ScheduleTriggerEngine { } public void cancel() { - if (future != null) { - future.cancel(true); - } + FutureUtils.cancel(future); } } diff --git a/src/main/java/org/elasticsearch/watcher/trigger/schedule/engine/TickerScheduleTriggerEngine.java b/src/main/java/org/elasticsearch/watcher/trigger/schedule/engine/TickerScheduleTriggerEngine.java index 203235b29fe..4b551f15212 100644 --- a/src/main/java/org/elasticsearch/watcher/trigger/schedule/engine/TickerScheduleTriggerEngine.java +++ b/src/main/java/org/elasticsearch/watcher/trigger/schedule/engine/TickerScheduleTriggerEngine.java @@ -5,14 +5,15 @@ */ package org.elasticsearch.watcher.trigger.schedule.engine; -import org.elasticsearch.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList; 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.unit.TimeValue; import org.elasticsearch.watcher.support.clock.Clock; import org.elasticsearch.watcher.trigger.TriggerEvent; import org.elasticsearch.watcher.trigger.schedule.*; +import org.joda.time.DateTimeZone; import java.util.ArrayList; import java.util.Collection; @@ -21,7 +22,6 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CountDownLatch; -import static org.elasticsearch.common.joda.time.DateTimeZone.UTC; /** * */ @@ -75,8 +75,8 @@ public class TickerScheduleTriggerEngine extends ScheduleTriggerEngine { for (ActiveSchedule schedule : schedules.values()) { long scheduledTime = schedule.check(triggeredTime); if (scheduledTime > 0) { - logger.trace("triggered job [{}] at [{}] (scheduled time was [{}])", schedule.name, new DateTime(triggeredTime, UTC), new DateTime(scheduledTime, UTC)); - events.add(new ScheduleTriggerEvent(schedule.name, new DateTime(triggeredTime, UTC), new DateTime(scheduledTime, UTC))); + logger.trace("triggered job [{}] at [{}] (scheduled time was [{}])", schedule.name, new DateTime(triggeredTime, DateTimeZone.UTC), new DateTime(scheduledTime, DateTimeZone.UTC)); + events.add(new ScheduleTriggerEvent(schedule.name, new DateTime(triggeredTime, DateTimeZone.UTC), new DateTime(scheduledTime, DateTimeZone.UTC))); if (events.size() >= 1000) { notifyListeners(ImmutableList.copyOf(events)); events.clear(); diff --git a/src/main/java/org/elasticsearch/watcher/trigger/schedule/support/DayTimes.java b/src/main/java/org/elasticsearch/watcher/trigger/schedule/support/DayTimes.java index 16dcdf68f1e..a7dd3baca75 100644 --- a/src/main/java/org/elasticsearch/watcher/trigger/schedule/support/DayTimes.java +++ b/src/main/java/org/elasticsearch/watcher/trigger/schedule/support/DayTimes.java @@ -5,7 +5,7 @@ */ package org.elasticsearch.watcher.trigger.schedule.support; -import org.elasticsearch.common.primitives.Ints; +import com.google.common.primitives.Ints; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.watcher.WatcherException; diff --git a/src/main/java/org/elasticsearch/watcher/trigger/schedule/support/MonthTimes.java b/src/main/java/org/elasticsearch/watcher/trigger/schedule/support/MonthTimes.java index ae5ab1f7800..3f63be2707a 100644 --- a/src/main/java/org/elasticsearch/watcher/trigger/schedule/support/MonthTimes.java +++ b/src/main/java/org/elasticsearch/watcher/trigger/schedule/support/MonthTimes.java @@ -5,9 +5,9 @@ */ package org.elasticsearch.watcher.trigger.schedule.support; -import org.elasticsearch.common.base.Joiner; -import org.elasticsearch.common.collect.ImmutableSet; -import org.elasticsearch.common.primitives.Ints; +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableSet; +import com.google.common.primitives.Ints; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.watcher.WatcherException; diff --git a/src/main/java/org/elasticsearch/watcher/trigger/schedule/support/WeekTimes.java b/src/main/java/org/elasticsearch/watcher/trigger/schedule/support/WeekTimes.java index 0d8f34a854e..70a555d54fb 100644 --- a/src/main/java/org/elasticsearch/watcher/trigger/schedule/support/WeekTimes.java +++ b/src/main/java/org/elasticsearch/watcher/trigger/schedule/support/WeekTimes.java @@ -5,8 +5,8 @@ */ package org.elasticsearch.watcher.trigger.schedule.support; -import org.elasticsearch.common.collect.ImmutableSet; -import org.elasticsearch.common.primitives.Ints; +import com.google.common.collect.ImmutableSet; +import com.google.common.primitives.Ints; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.watcher.WatcherException; diff --git a/src/main/java/org/elasticsearch/watcher/trigger/schedule/support/YearTimes.java b/src/main/java/org/elasticsearch/watcher/trigger/schedule/support/YearTimes.java index 21aad23c901..8fa203c24c6 100644 --- a/src/main/java/org/elasticsearch/watcher/trigger/schedule/support/YearTimes.java +++ b/src/main/java/org/elasticsearch/watcher/trigger/schedule/support/YearTimes.java @@ -5,9 +5,9 @@ */ package org.elasticsearch.watcher.trigger.schedule.support; -import org.elasticsearch.common.base.Joiner; -import org.elasticsearch.common.collect.ImmutableSet; -import org.elasticsearch.common.primitives.Ints; +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableSet; +import com.google.common.primitives.Ints; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.watcher.WatcherException; diff --git a/src/main/java/org/elasticsearch/watcher/trigger/schedule/tool/CronEvalTool.java b/src/main/java/org/elasticsearch/watcher/trigger/schedule/tool/CronEvalTool.java index 6bbdc32796b..736f94dbdfb 100644 --- a/src/main/java/org/elasticsearch/watcher/trigger/schedule/tool/CronEvalTool.java +++ b/src/main/java/org/elasticsearch/watcher/trigger/schedule/tool/CronEvalTool.java @@ -5,14 +5,14 @@ */ package org.elasticsearch.watcher.trigger.schedule.tool; +import org.apache.commons.cli.CommandLine; import org.elasticsearch.common.cli.CliTool; import org.elasticsearch.common.cli.CliToolConfig; import org.elasticsearch.common.cli.Terminal; -import org.elasticsearch.common.cli.commons.CommandLine; -import org.elasticsearch.common.joda.time.DateTime; -import org.elasticsearch.common.joda.time.DateTimeZone; -import org.elasticsearch.common.joda.time.format.DateTimeFormat; -import org.elasticsearch.common.joda.time.format.DateTimeFormatter; +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.watcher.trigger.schedule.Cron; diff --git a/src/main/java/org/elasticsearch/watcher/watch/Watch.java b/src/main/java/org/elasticsearch/watcher/watch/Watch.java index 192246ab0d0..54b3bf34e76 100644 --- a/src/main/java/org/elasticsearch/watcher/watch/Watch.java +++ b/src/main/java/org/elasticsearch/watcher/watch/Watch.java @@ -6,14 +6,15 @@ package org.elasticsearch.watcher.watch; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.collect.ImmutableMap; 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.PeriodType; +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; +import org.joda.time.PeriodType; import org.elasticsearch.common.lucene.uid.Versions; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -46,7 +47,6 @@ import java.io.IOException; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; -import static org.elasticsearch.common.joda.time.DateTimeZone.UTC; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; public class Watch implements TriggerEngine.Job, ToXContent { @@ -292,7 +292,7 @@ public class Watch implements TriggerEngine.Job, ToXContent { transform = transformRegistry.parse(id, parser); } else if (Field.THROTTLE_PERIOD.match(currentFieldName)) { try { - throttlePeriod = WatcherDateTimeUtils.parseTimeValue(parser, null); + throttlePeriod = WatcherDateTimeUtils.parseTimeValue(parser, null, Field.THROTTLE_PERIOD.toString()); } catch (WatcherDateTimeUtils.ParseException pe) { throw new ParseException("could not parse watch [{}]. failed to parse time value for field [{}]", pe, id, currentFieldName); } @@ -324,7 +324,7 @@ public class Watch implements TriggerEngine.Job, ToXContent { } else { // we need to create the initial statuses for the actions ImmutableMap.Builder actionsStatuses = ImmutableMap.builder(); - DateTime now = clock.now(UTC); + DateTime now = clock.now(DateTimeZone.UTC); for (ActionWrapper action : actions) { actionsStatuses.put(action.id(), new ActionStatus(now)); } diff --git a/src/main/java/org/elasticsearch/watcher/watch/WatchLockService.java b/src/main/java/org/elasticsearch/watcher/watch/WatchLockService.java index c255602f48c..12090fa6bb9 100644 --- a/src/main/java/org/elasticsearch/watcher/watch/WatchLockService.java +++ b/src/main/java/org/elasticsearch/watcher/watch/WatchLockService.java @@ -7,8 +7,7 @@ package org.elasticsearch.watcher.watch; import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.joda.time.PeriodType; -import org.elasticsearch.common.settings.ImmutableSettings; +import org.joda.time.PeriodType; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.watcher.WatcherException; @@ -37,7 +36,7 @@ public class WatchLockService extends AbstractComponent { } WatchLockService(TimeValue maxStopTimeout){ - super(ImmutableSettings.EMPTY); + super(Settings.EMPTY); this.maxStopTimeout = maxStopTimeout; } diff --git a/src/main/java/org/elasticsearch/watcher/watch/WatchStatus.java b/src/main/java/org/elasticsearch/watcher/watch/WatchStatus.java index 80cc09a93dd..4b26b61b1bb 100644 --- a/src/main/java/org/elasticsearch/watcher/watch/WatchStatus.java +++ b/src/main/java/org/elasticsearch/watcher/watch/WatchStatus.java @@ -5,14 +5,13 @@ */ package org.elasticsearch.watcher.watch; +import com.google.common.collect.ImmutableMap; +import org.apache.commons.lang3.ArrayUtils; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.collect.ImmutableMap; 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.lang3.ArrayUtils; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; @@ -20,11 +19,12 @@ import org.elasticsearch.watcher.WatcherException; import org.elasticsearch.watcher.actions.Action; import org.elasticsearch.watcher.actions.ActionStatus; import org.elasticsearch.watcher.actions.throttler.AckThrottler; +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; import java.io.IOException; import java.util.Map; -import static org.elasticsearch.common.joda.time.DateTimeZone.UTC; import static org.elasticsearch.watcher.support.WatcherDateTimeUtils.*; /** @@ -192,8 +192,8 @@ public class WatchStatus implements ToXContent, Streamable { @Override public void readFrom(StreamInput in) throws IOException { version = in.readLong(); - lastChecked = readOptionalDate(in, UTC); - lastMetCondition = readOptionalDate(in, UTC); + lastChecked = readOptionalDate(in, DateTimeZone.UTC); + lastMetCondition = readOptionalDate(in, DateTimeZone.UTC); ImmutableMap.Builder builder = ImmutableMap.builder(); int count = in.readInt(); for (int i = 0; i < count; i++) { @@ -240,13 +240,13 @@ public class WatchStatus implements ToXContent, Streamable { currentFieldName = parser.currentName(); } else if (Field.LAST_CHECKED.match(currentFieldName)) { if (token.isValue()) { - lastChecked = parseDate(currentFieldName, parser, UTC); + lastChecked = parseDate(currentFieldName, parser, DateTimeZone.UTC); } else { throw new WatcherException("could not parse watch status for [{}]. expecting field [{}] to hold a date value, found [{}] instead", watchId, currentFieldName, token); } } else if (Field.LAST_MET_CONDITION.match(currentFieldName)) { if (token.isValue()) { - lastMetCondition = parseDate(currentFieldName, parser, UTC); + lastMetCondition = parseDate(currentFieldName, parser, DateTimeZone.UTC); } else { throw new WatcherException("could not parse watch status for [{}]. expecting field [{}] to hold a date value, found [{}] instead", watchId, currentFieldName, token); } diff --git a/src/main/java/org/elasticsearch/watcher/watch/WatchStore.java b/src/main/java/org/elasticsearch/watcher/watch/WatchStore.java index 9e25083be5b..7a9e53b382b 100644 --- a/src/main/java/org/elasticsearch/watcher/watch/WatchStore.java +++ b/src/main/java/org/elasticsearch/watcher/watch/WatchStore.java @@ -6,7 +6,6 @@ package org.elasticsearch.watcher.watch; import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.ElasticsearchIllegalStateException; import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; import org.elasticsearch.action.delete.DeleteRequest; @@ -67,8 +66,8 @@ public class WatchStore extends AbstractComponent { this.watchParser = watchParser; this.watches = ConcurrentCollections.newConcurrentMap(); - this.scrollTimeout = componentSettings.getAsTime("scroll.timeout", TimeValue.timeValueSeconds(30)); - this.scrollSize = componentSettings.getAsInt("scroll.size", 100); + this.scrollTimeout = settings.getAsTime("watcher.watch.scroll.timeout", TimeValue.timeValueSeconds(30)); + this.scrollSize = settings.getAsInt("watcher.watch.scroll.size", 100); } public void start(ClusterState state) { @@ -157,7 +156,6 @@ public class WatchStore extends AbstractComponent { .field(Watch.Field.STATUS.getPreferredName(), watch.status(), ToXContent.EMPTY_PARAMS) .endObject(); UpdateRequest updateRequest = new UpdateRequest(INDEX, DOC_TYPE, watch.id()); - updateRequest.listenerThreaded(false); updateRequest.doc(source); updateRequest.version(watch.version()); try { @@ -197,7 +195,6 @@ public class WatchStore extends AbstractComponent { IndexRequest createIndexRequest(String id, BytesReference source, long version) { IndexRequest indexRequest = new IndexRequest(INDEX, DOC_TYPE, id); - indexRequest.listenerThreaded(false); // TODO (2.0 upgrade): move back to BytesReference instead of dealing with the array directly if (source.hasArray()) { indexRequest.source(source.array(), source.arrayOffset(), source.length()); @@ -260,7 +257,7 @@ public class WatchStore extends AbstractComponent { private void ensureStarted() { if (!started.get()) { - throw new ElasticsearchIllegalStateException("watch store not started"); + throw new IllegalStateException("watch store not started"); } } diff --git a/src/test/java/org/elasticsearch/watcher/WatcherLifeCycleServiceTests.java b/src/test/java/org/elasticsearch/watcher/WatcherLifeCycleServiceTests.java index 03199ca7e91..4b935f40482 100644 --- a/src/test/java/org/elasticsearch/watcher/WatcherLifeCycleServiceTests.java +++ b/src/test/java/org/elasticsearch/watcher/WatcherLifeCycleServiceTests.java @@ -5,14 +5,14 @@ */ package org.elasticsearch.watcher; +import com.google.common.util.concurrent.MoreExecutors; import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.common.settings.ImmutableSettings; -import org.elasticsearch.common.util.concurrent.MoreExecutors; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.threadpool.ThreadPool; @@ -35,7 +35,7 @@ public class WatcherLifeCycleServiceTests extends ElasticsearchTestCase { when(threadPool.executor(anyString())).thenReturn(MoreExecutors.newDirectExecutorService()); watcherService = mock(WatcherService.class); ClusterService clusterService = mock(ClusterService.class); - lifeCycleService = new WatcherLifeCycleService(ImmutableSettings.EMPTY, clusterService, threadPool, watcherService); + lifeCycleService = new WatcherLifeCycleService(Settings.EMPTY, clusterService, threadPool, watcherService); } @Test diff --git a/src/test/java/org/elasticsearch/watcher/WatcherPluginDisableTests.java b/src/test/java/org/elasticsearch/watcher/WatcherPluginDisableTests.java index 1c1a4e6ab26..9efdeeffc8c 100644 --- a/src/test/java/org/elasticsearch/watcher/WatcherPluginDisableTests.java +++ b/src/test/java/org/elasticsearch/watcher/WatcherPluginDisableTests.java @@ -10,11 +10,11 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.elasticsearch.action.admin.cluster.node.info.NodeInfo; import org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse; -import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.http.HttpServerTransport; import org.elasticsearch.license.plugin.LicensePlugin; -import org.elasticsearch.node.internal.InternalNode; +import org.elasticsearch.node.Node; +import org.elasticsearch.plugins.PluginsService; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope; import org.elasticsearch.test.rest.client.http.HttpRequestBuilder; @@ -36,11 +36,20 @@ public class WatcherPluginDisableTests extends ElasticsearchIntegrationTest { @Override protected Settings nodeSettings(int nodeOrdinal) { - return ImmutableSettings.settingsBuilder() + return Settings.settingsBuilder() .put(super.nodeSettings(nodeOrdinal)) .put("plugin.types", WatcherPlugin.class.getName() + "," + LicensePlugin.class.getName()) + .put(PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false) .put(WatcherPlugin.ENABLED_SETTING, false) - .put(InternalNode.HTTP_ENABLED, true) + .put(Node.HTTP_ENABLED, true) + .build(); + } + + @Override + protected Settings transportClientSettings() { + return Settings.builder() + .put(super.transportClientSettings()) + .put(PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, false) .build(); } diff --git a/src/test/java/org/elasticsearch/watcher/actions/ActionErrorIntegrationTests.java b/src/test/java/org/elasticsearch/watcher/actions/ActionErrorIntegrationTests.java index ccb2936af90..bdfd41c8387 100644 --- a/src/test/java/org/elasticsearch/watcher/actions/ActionErrorIntegrationTests.java +++ b/src/test/java/org/elasticsearch/watcher/actions/ActionErrorIntegrationTests.java @@ -5,7 +5,7 @@ */ package org.elasticsearch.watcher.actions; -import org.elasticsearch.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; @@ -13,6 +13,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.plugins.AbstractPlugin; import org.elasticsearch.watcher.WatcherException; import org.elasticsearch.watcher.execution.WatchExecutionContext; @@ -26,10 +27,8 @@ import org.junit.Test; import java.io.IOException; import java.util.List; -import static org.elasticsearch.index.query.FilterBuilders.boolFilter; -import static org.elasticsearch.index.query.FilterBuilders.termFilter; -import static org.elasticsearch.index.query.QueryBuilders.filteredQuery; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; +import static org.elasticsearch.index.query.QueryBuilders.termsQuery; import static org.elasticsearch.watcher.client.WatchSourceBuilders.watchBuilder; import static org.elasticsearch.watcher.trigger.TriggerBuilders.schedule; import static org.elasticsearch.watcher.trigger.schedule.Schedules.interval; @@ -81,9 +80,9 @@ public class ActionErrorIntegrationTests extends AbstractWatcherIntegrationTests assertBusy(new Runnable() { @Override public void run() { - long count = watchRecordCount(filteredQuery(matchAllQuery(), boolFilter() - .must(termFilter("result.actions.id", "_action")) - .must(termFilter("result.actions.status", "failure")))); + long count = watchRecordCount(QueryBuilders.boolQuery() + .must(termsQuery("result.actions.id", "_action")) + .must(termsQuery("result.actions.status", "failure"))); assertThat(count, is(1L)); } }); @@ -101,9 +100,9 @@ public class ActionErrorIntegrationTests extends AbstractWatcherIntegrationTests assertBusy(new Runnable() { @Override public void run() { - long count = watchRecordCount(filteredQuery(matchAllQuery(), boolFilter() - .must(termFilter("result.actions.id", "_action")) - .must(termFilter("result.actions.status", "failure")))); + long count = watchRecordCount(QueryBuilders.boolQuery() + .must(termsQuery("result.actions.id", "_action")) + .must(termsQuery("result.actions.status", "failure"))); assertThat(count, is(2L)); } }); diff --git a/src/test/java/org/elasticsearch/watcher/actions/TimeThrottleIntegrationTests.java b/src/test/java/org/elasticsearch/watcher/actions/TimeThrottleIntegrationTests.java index 20f6191a0a9..0804300ae4c 100644 --- a/src/test/java/org/elasticsearch/watcher/actions/TimeThrottleIntegrationTests.java +++ b/src/test/java/org/elasticsearch/watcher/actions/TimeThrottleIntegrationTests.java @@ -5,9 +5,9 @@ */ package org.elasticsearch.watcher.actions; -import com.carrotsearch.randomizedtesting.annotations.Repeat; + import org.elasticsearch.action.index.IndexResponse; -import org.elasticsearch.common.joda.time.DateTime; +import org.joda.time.DateTime; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.watcher.client.WatcherClient; import org.elasticsearch.watcher.execution.ExecutionState; @@ -15,11 +15,11 @@ import org.elasticsearch.watcher.history.HistoryStore; import org.elasticsearch.watcher.history.WatchRecord; import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTests; import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse; +import org.joda.time.DateTimeZone; import org.junit.Test; import java.util.concurrent.TimeUnit; -import static org.elasticsearch.common.joda.time.DateTimeZone.UTC; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; import static org.elasticsearch.watcher.actions.ActionBuilders.indexAction; @@ -51,7 +51,7 @@ public class TimeThrottleIntegrationTests extends AbstractWatcherIntegrationTest @Test - @Repeat(iterations = 10) + public void testTimeThrottle() throws Exception { WatcherClient watcherClient = watcherClient(); indexTestDoc(); @@ -69,7 +69,7 @@ public class TimeThrottleIntegrationTests extends AbstractWatcherIntegrationTest assertThat(putWatchResponse.isCreated(), is(true)); if (timeWarped()) { - timeWarp().clock().setTime(DateTime.now(UTC)); + timeWarp().clock().setTime(DateTime.now(DateTimeZone.UTC)); timeWarp().scheduler().trigger("_name"); refresh(); @@ -126,7 +126,7 @@ public class TimeThrottleIntegrationTests extends AbstractWatcherIntegrationTest } } - @Test @Repeat(iterations = 10) + @Test public void testTimeThrottle_Defaults() throws Exception { WatcherClient watcherClient = watcherClient(); indexTestDoc(); @@ -143,7 +143,7 @@ public class TimeThrottleIntegrationTests extends AbstractWatcherIntegrationTest assertThat(putWatchResponse.isCreated(), is(true)); if (timeWarped()) { - timeWarp().clock().setTime(DateTime.now(UTC)); + timeWarp().clock().setTime(DateTime.now(DateTimeZone.UTC)); timeWarp().scheduler().trigger("_name"); refresh(); diff --git a/src/test/java/org/elasticsearch/watcher/actions/email/DataAttachmentTests.java b/src/test/java/org/elasticsearch/watcher/actions/email/DataAttachmentTests.java index 133643c967e..a839b2cd618 100644 --- a/src/test/java/org/elasticsearch/watcher/actions/email/DataAttachmentTests.java +++ b/src/test/java/org/elasticsearch/watcher/actions/email/DataAttachmentTests.java @@ -5,8 +5,7 @@ */ package org.elasticsearch.watcher.actions.email; -import org.elasticsearch.common.base.Charsets; -import org.elasticsearch.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap; import org.elasticsearch.common.io.Streams; import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.watcher.actions.email.service.Attachment; @@ -14,6 +13,7 @@ import org.junit.Test; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; import java.util.Map; import static org.hamcrest.Matchers.is; @@ -28,7 +28,7 @@ public class DataAttachmentTests extends ElasticsearchTestCase { Map data = ImmutableMap.of("key", "value"); Attachment attachment = DataAttachment.JSON.create(data); InputStream input = attachment.bodyPart().getDataHandler().getInputStream(); - String content = Streams.copyToString(new InputStreamReader(input, Charsets.UTF_8)); + String content = Streams.copyToString(new InputStreamReader(input, StandardCharsets.UTF_8)); assertThat(content, is("{" + System.lineSeparator() + " \"key\" : \"value\"" + System.lineSeparator() + "}")); } @@ -37,7 +37,7 @@ public class DataAttachmentTests extends ElasticsearchTestCase { Map data = ImmutableMap.of("key", "value"); Attachment attachment = DataAttachment.YAML.create(data); InputStream input = attachment.bodyPart().getDataHandler().getInputStream(); - String content = Streams.copyToString(new InputStreamReader(input, Charsets.UTF_8)); + String content = Streams.copyToString(new InputStreamReader(input, StandardCharsets.UTF_8)); // the yaml factory in es always emits unix line breaks // this seems to be a bug in jackson yaml factory that doesn't default to the platform line break assertThat(content, is("---\nkey: \"value\"\n")); diff --git a/src/test/java/org/elasticsearch/watcher/actions/email/EmailActionIntegrationTests.java b/src/test/java/org/elasticsearch/watcher/actions/email/EmailActionIntegrationTests.java index d4fba3a111b..072ba34a597 100644 --- a/src/test/java/org/elasticsearch/watcher/actions/email/EmailActionIntegrationTests.java +++ b/src/test/java/org/elasticsearch/watcher/actions/email/EmailActionIntegrationTests.java @@ -6,7 +6,7 @@ package org.elasticsearch.watcher.actions.email; import org.elasticsearch.action.search.SearchRequest; -import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.watcher.actions.email.service.EmailTemplate; import org.elasticsearch.watcher.actions.email.service.support.EmailServer; @@ -52,7 +52,7 @@ public class EmailActionIntegrationTests extends AbstractWatcherIntegrationTests //Need to construct the Email Server here as this happens before init() server = EmailServer.localhost("2500-2600", USERNAME, PASSWORD, logger); } - return ImmutableSettings.builder() + return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) .put("watcher.actions.email.service.account.test.smtp.auth", true) .put("watcher.actions.email.service.account.test.smtp.user", USERNAME) diff --git a/src/test/java/org/elasticsearch/watcher/actions/email/EmailActionTests.java b/src/test/java/org/elasticsearch/watcher/actions/email/EmailActionTests.java index 39f0ce320b1..b028619b6d1 100644 --- a/src/test/java/org/elasticsearch/watcher/actions/email/EmailActionTests.java +++ b/src/test/java/org/elasticsearch/watcher/actions/email/EmailActionTests.java @@ -5,12 +5,11 @@ */ package org.elasticsearch.watcher.actions.email; -import com.carrotsearch.randomizedtesting.annotations.Repeat; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap; import org.elasticsearch.common.collect.MapBuilder; -import org.elasticsearch.common.joda.time.DateTime; -import org.elasticsearch.common.settings.ImmutableSettings; +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; @@ -25,12 +24,12 @@ import org.elasticsearch.watcher.support.template.Template; import org.elasticsearch.watcher.support.template.TemplateEngine; import org.elasticsearch.watcher.support.xcontent.WatcherParams; import org.elasticsearch.watcher.watch.Payload; +import org.joda.time.DateTimeZone; import org.junit.Test; import java.util.HashMap; import java.util.Map; -import static org.elasticsearch.common.joda.time.DateTimeZone.UTC; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.watcher.test.WatcherTestUtils.mockExecutionContextBuilder; import static org.hamcrest.Matchers.*; @@ -42,7 +41,7 @@ import static org.mockito.Mockito.when; */ public class EmailActionTests extends ElasticsearchTestCase { - @Test @Repeat(iterations = 20) + @Test public void testExecute() throws Exception { final String account = "account1"; EmailService service = new EmailService() { @@ -90,7 +89,7 @@ public class EmailActionTests extends ElasticsearchTestCase { Map metadata = MapBuilder.newMapBuilder().put("_key", "_val").map(); - DateTime now = DateTime.now(UTC); + DateTime now = DateTime.now(DateTimeZone.UTC); Wid wid = new Wid(randomAsciiOfLength(5), randomLong(), now); WatchExecutionContext ctx = mockExecutionContextBuilder("watch1") @@ -141,7 +140,7 @@ public class EmailActionTests extends ElasticsearchTestCase { } } - @Test @Repeat(iterations = 20) + @Test public void testParser() throws Exception { TemplateEngine engine = mock(TemplateEngine.class); HtmlSanitizer htmlSanitizer = mock(HtmlSanitizer.class); @@ -244,7 +243,7 @@ public class EmailActionTests extends ElasticsearchTestCase { XContentParser parser = JsonXContent.jsonXContent.createParser(bytes); parser.nextToken(); - ExecutableEmailAction executable = new EmailActionFactory(ImmutableSettings.EMPTY, emailService, engine, htmlSanitizer) + ExecutableEmailAction executable = new EmailActionFactory(Settings.EMPTY, emailService, engine, htmlSanitizer) .parseExecutable(randomAsciiOfLength(8), randomAsciiOfLength(3), parser); assertThat(executable, notNullValue()); @@ -288,7 +287,7 @@ public class EmailActionTests extends ElasticsearchTestCase { return templates; } - @Test @Repeat(iterations = 20) + @Test public void testParser_SelfGenerated() throws Exception { EmailService service = mock(EmailService.class); TemplateEngine engine = mock(TemplateEngine.class); @@ -336,7 +335,7 @@ public class EmailActionTests extends ElasticsearchTestCase { logger.info(bytes.toUtf8()); XContentParser parser = JsonXContent.jsonXContent.createParser(bytes); parser.nextToken(); - ExecutableEmailAction parsed = new EmailActionFactory(ImmutableSettings.EMPTY, service, engine, htmlSanitizer) + ExecutableEmailAction parsed = new EmailActionFactory(Settings.EMPTY, service, engine, htmlSanitizer) .parseExecutable(randomAsciiOfLength(4), randomAsciiOfLength(10), parser); if (!hideSecrets) { @@ -357,7 +356,7 @@ public class EmailActionTests extends ElasticsearchTestCase { } } - @Test(expected = EmailActionException.class) @Repeat(iterations = 100) + @Test(expected = EmailActionException.class) public void testParser_Invalid() throws Exception { EmailService emailService = mock(EmailService.class); TemplateEngine engine = mock(TemplateEngine.class); @@ -365,7 +364,7 @@ public class EmailActionTests extends ElasticsearchTestCase { XContentBuilder builder = jsonBuilder().startObject().field("unknown_field", "value"); XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes()); parser.nextToken(); - new EmailActionFactory(ImmutableSettings.EMPTY, emailService, engine, htmlSanitizer) + new EmailActionFactory(Settings.EMPTY, emailService, engine, htmlSanitizer) .parseExecutable(randomAsciiOfLength(3), randomAsciiOfLength(7), parser); } diff --git a/src/test/java/org/elasticsearch/watcher/actions/email/EmailSecretsIntegrationTests.java b/src/test/java/org/elasticsearch/watcher/actions/email/EmailSecretsIntegrationTests.java index 77bd25282aa..c9949213464 100644 --- a/src/test/java/org/elasticsearch/watcher/actions/email/EmailSecretsIntegrationTests.java +++ b/src/test/java/org/elasticsearch/watcher/actions/email/EmailSecretsIntegrationTests.java @@ -6,8 +6,8 @@ package org.elasticsearch.watcher.actions.email; import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.common.joda.time.DateTime; -import org.elasticsearch.common.settings.ImmutableSettings; +import org.joda.time.DateTime; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.support.XContentMapValues; import org.elasticsearch.watcher.actions.email.service.EmailTemplate; @@ -23,6 +23,7 @@ import org.elasticsearch.watcher.transport.actions.get.GetWatchResponse; import org.elasticsearch.watcher.trigger.TriggerEvent; import org.elasticsearch.watcher.trigger.schedule.ScheduleTriggerEvent; import org.elasticsearch.watcher.watch.WatchStore; +import org.joda.time.DateTimeZone; import org.junit.After; import org.junit.Test; @@ -31,7 +32,6 @@ import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import static org.elasticsearch.common.joda.time.DateTimeZone.UTC; import static org.elasticsearch.watcher.actions.ActionBuilders.emailAction; import static org.elasticsearch.watcher.client.WatchSourceBuilders.watchBuilder; import static org.elasticsearch.watcher.condition.ConditionBuilders.alwaysCondition; @@ -65,7 +65,7 @@ public class EmailSecretsIntegrationTests extends AbstractWatcherIntegrationTest if (encryptSensitiveData == null) { encryptSensitiveData = shieldEnabled() && randomBoolean(); } - return ImmutableSettings.builder() + return Settings.builder() .put(super.nodeSettings(nodeOrdinal)) .put("watcher.actions.email.service.account.test.smtp.auth", true) .put("watcher.actions.email.service.account.test.smtp.port", server.port()) @@ -136,7 +136,7 @@ public class EmailSecretsIntegrationTests extends AbstractWatcherIntegrationTest } }); - TriggerEvent triggerEvent = new ScheduleTriggerEvent(new DateTime(UTC), new DateTime(UTC)); + TriggerEvent triggerEvent = new ScheduleTriggerEvent(new DateTime(DateTimeZone.UTC), new DateTime(DateTimeZone.UTC)); ExecuteWatchResponse executeResponse = watcherClient.prepareExecuteWatch("_id") .setRecordExecution(false) .setTriggerEvent(triggerEvent) diff --git a/src/test/java/org/elasticsearch/watcher/actions/email/service/AccountTests.java b/src/test/java/org/elasticsearch/watcher/actions/email/service/AccountTests.java index c27a5caad37..b95f2a59d22 100644 --- a/src/test/java/org/elasticsearch/watcher/actions/email/service/AccountTests.java +++ b/src/test/java/org/elasticsearch/watcher/actions/email/service/AccountTests.java @@ -5,7 +5,7 @@ */ package org.elasticsearch.watcher.actions.email.service; -import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.watcher.actions.email.service.support.EmailServer; @@ -48,7 +48,7 @@ public class AccountTests extends ElasticsearchTestCase { @Test public void testConfig() throws Exception { - ImmutableSettings.Builder builder = ImmutableSettings.builder(); + Settings.Builder builder = Settings.builder(); Profile profile = rarely() ? Profile.STANDARD : randomFrom(Profile.values()); if (profile != Profile.STANDARD) { @@ -57,7 +57,7 @@ public class AccountTests extends ElasticsearchTestCase { Account.Config.EmailDefaults emailDefaults; if (randomBoolean()) { - ImmutableSettings.Builder sb = ImmutableSettings.builder(); + Settings.Builder sb = Settings.builder(); if (randomBoolean()) { sb.put(Email.Field.FROM.getPreferredName(), "from@domain"); } @@ -85,11 +85,11 @@ public class AccountTests extends ElasticsearchTestCase { builder.put("email_defaults." + name, settings.get(name)); } } else { - emailDefaults = new Account.Config.EmailDefaults(ImmutableSettings.EMPTY); + emailDefaults = new Account.Config.EmailDefaults(Settings.EMPTY); } Properties smtpProps = new Properties(); - ImmutableSettings.Builder smtpBuilder = ImmutableSettings.builder(); + Settings.Builder smtpBuilder = Settings.builder(); String host = "somehost"; String setting = randomFrom("host", "localaddress", "local_address"); smtpBuilder.put(setting, host); @@ -154,7 +154,7 @@ public class AccountTests extends ElasticsearchTestCase { @Test public void testSend() throws Exception { - Account account = new Account(new Account.Config("default", ImmutableSettings.builder() + Account account = new Account(new Account.Config("default", Settings.builder() .put("smtp.host", "localhost") .put("smtp.port", server.port()) .put("smtp.user", USERNAME) @@ -194,7 +194,7 @@ public class AccountTests extends ElasticsearchTestCase { @Test public void testSend_CC_BCC() throws Exception { - Account account = new Account(new Account.Config("default", ImmutableSettings.builder() + Account account = new Account(new Account.Config("default", Settings.builder() .put("smtp.host", "localhost") .put("smtp.port", server.port()) .put("smtp.user", USERNAME) @@ -239,7 +239,7 @@ public class AccountTests extends ElasticsearchTestCase { @Test public void testSend_Authentication() throws Exception { - Account account = new Account(new Account.Config("default", ImmutableSettings.builder() + Account account = new Account(new Account.Config("default", Settings.builder() .put("smtp.host", "localhost") .put("smtp.port", server.port()) .build()), new SecretService.PlainText(), logger); diff --git a/src/test/java/org/elasticsearch/watcher/actions/email/service/AccountsTests.java b/src/test/java/org/elasticsearch/watcher/actions/email/service/AccountsTests.java index e87c0a24c2d..8546aaa8bad 100644 --- a/src/test/java/org/elasticsearch/watcher/actions/email/service/AccountsTests.java +++ b/src/test/java/org/elasticsearch/watcher/actions/email/service/AccountsTests.java @@ -5,7 +5,7 @@ */ package org.elasticsearch.watcher.actions.email.service; -import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ElasticsearchTestCase; import org.elasticsearch.watcher.support.secret.SecretService; import org.junit.Test; @@ -19,7 +19,7 @@ public class AccountsTests extends ElasticsearchTestCase { @Test public void testSingleAccount() throws Exception { - ImmutableSettings.Builder builder = ImmutableSettings.builder() + Settings.Builder builder = Settings.builder() .put("default_account", "account1"); addAccountSettings("account1", builder); @@ -34,7 +34,7 @@ public class AccountsTests extends ElasticsearchTestCase { @Test public void testSingleAccount_NoExplicitDefault() throws Exception { - ImmutableSettings.Builder builder = ImmutableSettings.builder(); + Settings.Builder builder = Settings.builder(); addAccountSettings("account1", builder); Accounts accounts = new Accounts(builder.build(), new SecretService.PlainText(), logger); @@ -48,7 +48,7 @@ public class AccountsTests extends ElasticsearchTestCase { @Test public void testMultipleAccounts() throws Exception { - ImmutableSettings.Builder builder = ImmutableSettings.builder() + Settings.Builder builder = Settings.builder() .put("default_account", "account1"); addAccountSettings("account1", builder); addAccountSettings("account2", builder); @@ -67,7 +67,7 @@ public class AccountsTests extends ElasticsearchTestCase { @Test public void testMultipleAccounts_NoExplicitDefault() throws Exception { - ImmutableSettings.Builder builder = ImmutableSettings.builder() + Settings.Builder builder = Settings.builder() .put("default_account", "account1"); addAccountSettings("account1", builder); addAccountSettings("account2", builder); @@ -86,7 +86,7 @@ public class AccountsTests extends ElasticsearchTestCase { @Test(expected = EmailSettingsException.class) public void testMultipleAccounts_UnknownDefault() throws Exception { - ImmutableSettings.Builder builder = ImmutableSettings.builder() + Settings.Builder builder = Settings.builder() .put("default_account", "unknown"); addAccountSettings("account1", builder); addAccountSettings("account2", builder); @@ -95,7 +95,7 @@ public class AccountsTests extends ElasticsearchTestCase { @Test(expected = EmailSettingsException.class) public void testNoAccount() throws Exception { - ImmutableSettings.Builder builder = ImmutableSettings.builder(); + Settings.Builder builder = Settings.builder(); Accounts accounts = new Accounts(builder.build(), new SecretService.PlainText(), logger); accounts.account(null); fail("no accounts are configured so trying to get the default account should throw an EmailSettingsException"); @@ -103,12 +103,12 @@ public class AccountsTests extends ElasticsearchTestCase { @Test(expected = EmailSettingsException.class) public void testNoAccount_WithDefaultAccount() throws Exception { - ImmutableSettings.Builder builder = ImmutableSettings.builder() + Settings.Builder builder = Settings.builder() .put("default_account", "unknown"); new Accounts(builder.build(), new SecretService.PlainText(), logger); } - private void addAccountSettings(String name, ImmutableSettings.Builder builder) { + private void addAccountSettings(String name, Settings.Builder builder) { builder.put("account." + name + ".smtp.host", "_host"); } } diff --git a/src/test/java/org/elasticsearch/watcher/actions/email/service/EmailTemplateTests.java b/src/test/java/org/elasticsearch/watcher/actions/email/service/EmailTemplateTests.java index 7b6f9d41b97..4bcef5b868c 100644 --- a/src/test/java/org/elasticsearch/watcher/actions/email/service/EmailTemplateTests.java +++ b/src/test/java/org/elasticsearch/watcher/actions/email/service/EmailTemplateTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.watcher.actions.email.service; -import com.carrotsearch.randomizedtesting.annotations.Repeat; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; @@ -30,7 +29,7 @@ import static org.mockito.Mockito.when; */ public class EmailTemplateTests extends ElasticsearchTestCase { - @Test @Repeat(iterations = 100) + @Test public void testEmailTemplate_Parser_SelfGenerated() throws Exception { Template from = randomFrom(Template.inline("from@from.com").build(), null); List