Merge pull request elastic/elasticsearch#2388 from areek/extract_scheduler_engine_to_xpack

[refactor] extract trigger package and scheduler engine to top-level x-pack directory

Original commit: elastic/x-pack-elasticsearch@0a89cf2ca3
This commit is contained in:
Areek Zillur 2016-06-01 15:27:24 -04:00
commit 6ff8124640
175 changed files with 722 additions and 631 deletions

View File

@ -25,8 +25,8 @@ import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBu
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.scriptCondition;
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
import static org.elasticsearch.xpack.watcher.transform.TransformBuilders.scriptTransform;
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.cron;
import static org.elasticsearch.xpack.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.trigger.schedule.Schedules.cron;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.is;

View File

@ -20,8 +20,8 @@ import org.elasticsearch.xpack.watcher.transport.actions.delete.DeleteWatchRespo
import org.elasticsearch.xpack.watcher.transport.actions.get.GetWatchRequest;
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchRequest;
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse;
import org.elasticsearch.xpack.watcher.trigger.manual.ManualTriggerEvent;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleTriggerEvent;
import org.elasticsearch.xpack.trigger.manual.ManualTriggerEvent;
import org.elasticsearch.xpack.trigger.schedule.ScheduleTriggerEvent;
import org.elasticsearch.xpack.watcher.watch.Watch;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@ -34,8 +34,8 @@ import java.util.concurrent.TimeUnit;
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.cron;
import static org.elasticsearch.xpack.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.trigger.schedule.Schedules.cron;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;

View File

@ -21,8 +21,8 @@ import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBu
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
import static org.elasticsearch.xpack.watcher.transform.TransformBuilders.scriptTransform;
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
import static org.elasticsearch.xpack.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.trigger.schedule.Schedules.interval;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.is;

View File

@ -14,11 +14,11 @@ import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.xpack.watcher.history.HistoryStore;
import org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils;
import org.elasticsearch.xpack.support.DateTimeUtils;
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
import org.elasticsearch.xpack.watcher.transport.actions.execute.ExecuteWatchResponse;
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleTriggerEvent;
import org.elasticsearch.xpack.trigger.schedule.ScheduleTriggerEvent;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@ -33,8 +33,8 @@ import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBu
import static org.elasticsearch.xpack.watcher.input.InputBuilders.searchInput;
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
import static org.elasticsearch.xpack.watcher.transform.TransformBuilders.scriptTransform;
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.cron;
import static org.elasticsearch.xpack.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.trigger.schedule.Schedules.cron;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.is;
@ -75,10 +75,10 @@ public class IndexActionIT extends AbstractWatcherIntegrationTestCase {
assertThat(searchResponse.getHits().totalHits(), is(1L));
SearchHit hit = searchResponse.getHits().getAt(0);
if (timeWarped()) {
assertThat(hit.getSource(), hasEntry("@timestamp", (Object) WatcherDateTimeUtils.formatDate(now)));
assertThat(hit.getSource(), hasEntry("@timestamp", (Object) DateTimeUtils.formatDate(now)));
} else {
assertThat(hit.getSource(), hasKey("@timestamp"));
DateTime timestamp = WatcherDateTimeUtils.parseDate((String) hit.getSource().get("@timestamp"));
DateTime timestamp = DateTimeUtils.parseDate((String) hit.getSource().get("@timestamp"));
assertThat(timestamp.isEqual(now) || timestamp.isAfter(now), is(true));
}
assertThat(hit.getSource(), hasEntry("foo", (Object) "bar"));
@ -111,10 +111,10 @@ public class IndexActionIT extends AbstractWatcherIntegrationTestCase {
assertThat(searchResponse.getHits().totalHits(), is(1L));
SearchHit hit = searchResponse.getHits().getAt(0);
if (timeWarped()) {
assertThat(hit.getSource(), hasEntry("@timestamp", (Object) WatcherDateTimeUtils.formatDate(now)));
assertThat(hit.getSource(), hasEntry("@timestamp", (Object) DateTimeUtils.formatDate(now)));
} else {
assertThat(hit.getSource(), hasKey("@timestamp"));
DateTime timestamp = WatcherDateTimeUtils.parseDate((String) hit.getSource().get("@timestamp"));
DateTime timestamp = DateTimeUtils.parseDate((String) hit.getSource().get("@timestamp"));
assertThat(timestamp.isEqual(now) || timestamp.isAfter(now), is(true));
}
assertThat(hit.getSource(), hasEntry("foo", (Object) "bar"));
@ -202,10 +202,10 @@ public class IndexActionIT extends AbstractWatcherIntegrationTestCase {
int i = 0;
for (SearchHit hit : searchResponse.getHits()) {
if (timeWarped()) {
assertThat(hit.getSource(), hasEntry("@timestamp", (Object) WatcherDateTimeUtils.formatDate(now)));
assertThat(hit.getSource(), hasEntry("@timestamp", (Object) DateTimeUtils.formatDate(now)));
} else {
assertThat(hit.getSource(), hasKey("@timestamp"));
DateTime timestamp = WatcherDateTimeUtils.parseDate((String) hit.getSource().get("@timestamp"));
DateTime timestamp = DateTimeUtils.parseDate((String) hit.getSource().get("@timestamp"));
assertThat(timestamp.isEqual(now) || timestamp.isAfter(now), is(true));
}
assertThat(hit.getSource(), hasEntry("key", (Object) key.getMillis()));

View File

@ -36,7 +36,7 @@ import java.io.IOException;
import static java.util.Collections.singletonMap;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.messy.tests.MessyTestUtils.getScriptServiceProxy;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.mockExecutionContext;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;

View File

@ -36,8 +36,8 @@ import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
import static org.elasticsearch.xpack.watcher.transform.TransformBuilders.chainTransform;
import static org.elasticsearch.xpack.watcher.transform.TransformBuilders.scriptTransform;
import static org.elasticsearch.xpack.watcher.transform.TransformBuilders.searchTransform;
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
import static org.elasticsearch.xpack.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.trigger.schedule.Schedules.interval;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;

View File

@ -30,8 +30,8 @@ import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.hipchatActi
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
import static org.elasticsearch.xpack.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.trigger.schedule.Schedules.interval;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.notNullValue;

View File

@ -51,9 +51,9 @@ import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.always
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.compareCondition;
import static org.elasticsearch.xpack.watcher.input.InputBuilders.searchInput;
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.cron;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
import static org.elasticsearch.xpack.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.trigger.schedule.Schedules.cron;
import static org.elasticsearch.xpack.trigger.schedule.Schedules.interval;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.core.Is.is;

View File

@ -32,8 +32,8 @@ import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.pagerDutyAc
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
import static org.elasticsearch.xpack.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.trigger.schedule.Schedules.interval;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.notNullValue;

View File

@ -37,9 +37,9 @@ import org.elasticsearch.xpack.watcher.input.search.SearchInputFactory;
import org.elasticsearch.xpack.watcher.input.simple.ExecutableSimpleInput;
import org.elasticsearch.xpack.watcher.input.simple.SimpleInput;
import org.elasticsearch.xpack.watcher.support.init.proxy.WatcherClientProxy;
import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleTrigger;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleTriggerEvent;
import org.elasticsearch.xpack.trigger.schedule.IntervalSchedule;
import org.elasticsearch.xpack.trigger.schedule.ScheduleTrigger;
import org.elasticsearch.xpack.trigger.schedule.ScheduleTriggerEvent;
import org.elasticsearch.xpack.watcher.watch.Payload;
import org.elasticsearch.xpack.watcher.watch.Watch;
import org.elasticsearch.xpack.watcher.watch.WatchStatus;

View File

@ -43,9 +43,9 @@ import org.elasticsearch.xpack.watcher.transform.TransformBuilders;
import org.elasticsearch.xpack.watcher.transform.search.ExecutableSearchTransform;
import org.elasticsearch.xpack.watcher.transform.search.SearchTransform;
import org.elasticsearch.xpack.watcher.transform.search.SearchTransformFactory;
import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleTrigger;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleTriggerEvent;
import org.elasticsearch.xpack.trigger.schedule.IntervalSchedule;
import org.elasticsearch.xpack.trigger.schedule.ScheduleTrigger;
import org.elasticsearch.xpack.trigger.schedule.ScheduleTriggerEvent;
import org.elasticsearch.xpack.watcher.watch.Payload;
import org.elasticsearch.xpack.watcher.watch.Watch;
import org.elasticsearch.xpack.watcher.watch.WatchStatus;
@ -74,7 +74,7 @@ import static org.elasticsearch.index.query.QueryBuilders.rangeQuery;
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
import static org.elasticsearch.test.ESIntegTestCase.Scope.SUITE;
import static org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils.parseDate;
import static org.elasticsearch.xpack.support.DateTimeUtils.parseDate;
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.EMPTY_PAYLOAD;
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.getRandomSupportedSearchType;
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.mockExecutionContext;

View File

@ -30,8 +30,8 @@ import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.slackAction
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
import static org.elasticsearch.xpack.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.trigger.schedule.Schedules.interval;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.notNullValue;

View File

@ -46,8 +46,8 @@ import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.compar
import static org.elasticsearch.xpack.watcher.input.InputBuilders.searchInput;
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.matchAllRequest;
import static org.elasticsearch.xpack.watcher.transform.TransformBuilders.searchTransform;
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.cron;
import static org.elasticsearch.xpack.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.trigger.schedule.Schedules.cron;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;

View File

@ -12,7 +12,7 @@ import org.elasticsearch.common.xcontent.XContentType;
import java.io.IOException;
import java.util.Locale;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.support.Exceptions.illegalArgument;
/**
*/

View File

@ -19,7 +19,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.rest.support.RestUtils;
import org.elasticsearch.xpack.common.http.auth.HttpAuthRegistry;
import org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils;
import org.elasticsearch.xpack.support.DateTimeUtils;
import org.elasticsearch.xpack.watcher.support.WatcherUtils;
import org.elasticsearch.xpack.common.http.auth.HttpAuth;
@ -272,14 +272,14 @@ public class HttpRequest implements ToXContent {
builder.auth(httpAuthRegistry.parse(parser));
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.CONNECTION_TIMEOUT)) {
try {
builder.connectionTimeout(WatcherDateTimeUtils.parseTimeValue(parser, Field.CONNECTION_TIMEOUT.toString()));
builder.connectionTimeout(DateTimeUtils.parseTimeValue(parser, Field.CONNECTION_TIMEOUT.toString()));
} catch (ElasticsearchParseException pe) {
throw new ElasticsearchParseException("could not parse http request. invalid time value for [{}] field", pe,
currentFieldName);
}
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.READ_TIMEOUT)) {
try {
builder.readTimeout(WatcherDateTimeUtils.parseTimeValue(parser, Field.READ_TIMEOUT.toString()));
builder.readTimeout(DateTimeUtils.parseTimeValue(parser, Field.READ_TIMEOUT.toString()));
} catch (ElasticsearchParseException pe) {
throw new ElasticsearchParseException("could not parse http request. invalid time value for [{}] field", pe,
currentFieldName);

View File

@ -18,7 +18,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.rest.support.RestUtils;
import org.elasticsearch.xpack.common.http.auth.HttpAuth;
import org.elasticsearch.xpack.common.http.auth.HttpAuthRegistry;
import org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils;
import org.elasticsearch.xpack.support.DateTimeUtils;
import org.elasticsearch.xpack.common.text.TextTemplate;
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
import org.jboss.netty.handler.codec.http.HttpHeaders;
@ -283,7 +283,7 @@ public class HttpRequestTemplate implements ToXContent {
builder.fromUrl(parser.text());
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, HttpRequest.Field.CONNECTION_TIMEOUT)) {
try {
builder.connectionTimeout(WatcherDateTimeUtils.parseTimeValue(parser,
builder.connectionTimeout(DateTimeUtils.parseTimeValue(parser,
HttpRequest.Field.CONNECTION_TIMEOUT.toString()));
} catch (ElasticsearchParseException pe) {
throw new ElasticsearchParseException("could not parse http request template. invalid time value for [{}] field",
@ -291,7 +291,7 @@ public class HttpRequestTemplate implements ToXContent {
}
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, HttpRequest.Field.READ_TIMEOUT)) {
try {
builder.readTimeout(WatcherDateTimeUtils.parseTimeValue(parser, HttpRequest.Field.READ_TIMEOUT.toString()));
builder.readTimeout(DateTimeUtils.parseTimeValue(parser, HttpRequest.Field.READ_TIMEOUT.toString()));
} catch (ElasticsearchParseException pe) {
throw new ElasticsearchParseException("could not parse http request template. invalid time value for [{}] field",
pe, currentFieldName);

View File

@ -12,7 +12,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
import java.io.IOException;
import java.util.Map;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.support.Exceptions.illegalArgument;
/**
*

View File

@ -18,7 +18,7 @@ import java.io.IOException;
import java.util.Locale;
import java.util.Map;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.support.Exceptions.illegalArgument;
/**
*

View File

@ -3,85 +3,132 @@
* 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.xpack.watcher.trigger.schedule.engine;
package org.elasticsearch.xpack.scheduler;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.common.util.concurrent.FutureUtils;
import org.elasticsearch.xpack.support.clock.Clock;
import org.elasticsearch.xpack.watcher.trigger.TriggerEvent;
import org.elasticsearch.xpack.watcher.trigger.schedule.Schedule;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleRegistry;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleTrigger;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleTriggerEngine;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleTriggerEvent;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static java.util.Collections.unmodifiableMap;
/**
*
*/
public class SchedulerScheduleTriggerEngine extends ScheduleTriggerEngine {
public class SchedulerEngine {
public static class Job {
private final String id;
private final Schedule schedule;
public Job(String id, Schedule schedule) {
this.id = id;
this.schedule = schedule;
}
public String getId() {
return id;
}
public Schedule getSchedule() {
return schedule;
}
}
public static class Event {
private final String jobName;
private final long triggeredTime;
private final long scheduledTime;
public Event(String jobName, long triggeredTime, long scheduledTime) {
this.jobName = jobName;
this.triggeredTime = triggeredTime;
this.scheduledTime = scheduledTime;
}
public String getJobName() {
return jobName;
}
public long getTriggeredTime() {
return triggeredTime;
}
public long getScheduledTime() {
return scheduledTime;
}
}
public interface Listener {
void triggered(Event event);
}
public interface Schedule {
/**
* Returns the next scheduled time after the given time, according to this schedule. If the given schedule
* cannot resolve the next scheduled time, then {@code -1} is returned. It really depends on the type of
* schedule to determine when {@code -1} is returned. Some schedules (e.g. IntervalSchedule) will never return
* {@code -1} as they can always compute the next scheduled time. {@code Cron} based schedules are good example
* of schedules that may return {@code -1}, for example, when the schedule only points to times that are all
* before the given time (in which case, there is no next scheduled time for the given time).
*
* Example:
*
* cron 0 0 0 * 1 ? 2013 (only points to days in January 2013)
*
* time 2015-01-01 12:00:00 (this time is in 2015)
*
*/
long nextScheduledTimeAfter(long startTime, long now);
}
private volatile Schedules schedules;
private ScheduledExecutorService scheduler;
private final Clock clock;
private List<Listener> listeners = new CopyOnWriteArrayList<>();
@Inject
public SchedulerScheduleTriggerEngine(Settings settings, ScheduleRegistry scheduleRegistry, Clock clock) {
super(settings, scheduleRegistry, clock);
public SchedulerEngine(Clock clock) {
this.clock = clock;
}
public void register(Listener listener) {
listeners.add(listener);
}
@Override
public void start(Collection<Job> jobs) {
logger.debug("starting schedule engine...");
this.scheduler = Executors.newScheduledThreadPool(1, EsExecutors.daemonThreadFactory("trigger_engine_scheduler"));
long starTime = clock.millis();
List<ActiveSchedule> schedules = new ArrayList<>();
for (Job job : jobs) {
if (job.trigger() instanceof ScheduleTrigger) {
ScheduleTrigger trigger = (ScheduleTrigger) job.trigger();
schedules.add(new ActiveSchedule(job.id(), trigger.getSchedule(), starTime));
}
}
List<ActiveSchedule> schedules = jobs.stream()
.map(job -> new ActiveSchedule(job.getId(), job.getSchedule(), starTime))
.collect(Collectors.toList());
this.schedules = new Schedules(schedules);
logger.debug("schedule engine started at [{}]", clock.nowUTC());
}
@Override
public void stop() {
logger.debug("stopping schedule engine...");
scheduler.shutdownNow();
try {
scheduler.awaitTermination(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
logger.debug("schedule engine stopped");
}
@Override
public void add(Job job) {
assert job.trigger() instanceof ScheduleTrigger;
ScheduleTrigger trigger = (ScheduleTrigger) job.trigger();
ActiveSchedule schedule = new ActiveSchedule(job.id(), trigger.getSchedule(), clock.millis());
ActiveSchedule schedule = new ActiveSchedule(job.getId(), job.getSchedule(), clock.millis());
schedules = schedules.add(schedule);
}
@Override
public boolean remove(String jobId) {
Schedules newSchedules = schedules.remove(jobId);
if (newSchedules == null) {
@ -92,12 +139,9 @@ 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, DateTimeZone.UTC),
new DateTime(scheduledTime, DateTimeZone.UTC));
final ScheduleTriggerEvent event = new ScheduleTriggerEvent(name, new DateTime(triggeredTime, DateTimeZone.UTC),
new DateTime(scheduledTime, DateTimeZone.UTC));
final Event event = new Event(name, triggeredTime, scheduledTime);
for (Listener listener : listeners) {
listener.triggered(Arrays.<TriggerEvent>asList(event));
listener.triggered(event);
}
}
@ -139,68 +183,56 @@ public class SchedulerScheduleTriggerEngine extends ScheduleTriggerEngine {
static class Schedules {
private final ActiveSchedule[] schedules;
private final Map<String, ActiveSchedule> scheduleByName;
Schedules(Collection<ActiveSchedule> schedules) {
Map<String, ActiveSchedule> builder = new HashMap<>();
this.schedules = new ActiveSchedule[schedules.size()];
int i = 0;
for (ActiveSchedule schedule : schedules) {
builder.put(schedule.name, schedule);
this.schedules[i++] = schedule;
}
this.scheduleByName = unmodifiableMap(builder);
}
public Schedules(ActiveSchedule[] schedules, Map<String, ActiveSchedule> scheduleByName) {
this.schedules = schedules;
public Schedules(Map<String, ActiveSchedule> scheduleByName) {
this.scheduleByName = scheduleByName;
}
public Schedules add(ActiveSchedule schedule) {
boolean replacing = scheduleByName.containsKey(schedule.name);
if (!replacing) {
ActiveSchedule[] newSchedules = new ActiveSchedule[schedules.length + 1];
System.arraycopy(schedules, 0, newSchedules, 0, schedules.length);
newSchedules[schedules.length] = schedule;
Map<String, ActiveSchedule> newScheduleByName = new HashMap<>(scheduleByName);
newScheduleByName.put(schedule.name, schedule);
return new Schedules(newSchedules, unmodifiableMap(newScheduleByName));
return new Schedules(unmodifiableMap(newScheduleByName));
}
ActiveSchedule[] newSchedules = new ActiveSchedule[schedules.length];
Map<String, ActiveSchedule> builder = new HashMap<>();
for (int i = 0; i < schedules.length; i++) {
final ActiveSchedule sched;
if (schedules[i].name.equals(schedule.name)) {
sched = schedule;
schedules[i].cancel();
Map<String, ActiveSchedule> builder = new HashMap<>(scheduleByName.size());
for (Map.Entry<String, ActiveSchedule> scheduleEntry : scheduleByName.entrySet()) {
final String existingScheduleName = scheduleEntry.getKey();
final ActiveSchedule existingSchedule = scheduleEntry.getValue();
if (existingScheduleName.equals(schedule.name)) {
existingSchedule.cancel();
builder.put(schedule.name, schedule);
} else {
sched = schedules[i];
builder.put(existingScheduleName, existingSchedule);
}
newSchedules[i] = sched;
builder.put(sched.name, sched);
}
return new Schedules(newSchedules, unmodifiableMap(builder));
return new Schedules(unmodifiableMap(builder));
}
public Schedules remove(String name) {
if (!scheduleByName.containsKey(name)) {
return null;
}
Map<String, ActiveSchedule> builder = new HashMap<>();
ActiveSchedule[] newSchedules = new ActiveSchedule[schedules.length - 1];
int i = 0;
for (ActiveSchedule schedule : schedules) {
if (!schedule.name.equals(name)) {
newSchedules[i++] = schedule;
builder.put(schedule.name, schedule);
Map<String, ActiveSchedule> builder = new HashMap<>(scheduleByName.size() - 1);
for (Map.Entry<String, ActiveSchedule> scheduleEntry : scheduleByName.entrySet()) {
final String existingScheduleName = scheduleEntry.getKey();
final ActiveSchedule existingSchedule = scheduleEntry.getValue();
if (existingScheduleName.equals(name)) {
existingSchedule.cancel();
} else {
schedule.cancel();
builder.put(existingScheduleName, existingSchedule);
}
}
return new Schedules(newSchedules, unmodifiableMap(builder));
return new Schedules(unmodifiableMap(builder));
}
}
}

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.support;
package org.elasticsearch.xpack.support;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.io.stream.StreamInput;
@ -23,12 +23,12 @@ import java.util.concurrent.Callable;
/**
*
*/
public class WatcherDateTimeUtils {
public class DateTimeUtils {
public static final FormatDateTimeFormatter dateTimeFormatter = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER;
public static final DateMathParser dateMathParser = new DateMathParser(dateTimeFormatter);
private WatcherDateTimeUtils() {
private DateTimeUtils() {
}
public static DateTime convertToDate(Object value, Clock clock) {

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.support;
package org.elasticsearch.xpack.support;
import org.elasticsearch.common.settings.SettingsException;
import org.elasticsearch.script.GeneralScriptException;

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.support;
package org.elasticsearch.xpack.support;
import java.util.Objects;

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger;
package org.elasticsearch.xpack.trigger;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.settings.Settings;

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger;
package org.elasticsearch.xpack.trigger;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentParser;

View File

@ -3,10 +3,10 @@
* 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.xpack.watcher.trigger;
package org.elasticsearch.xpack.trigger;
import org.elasticsearch.xpack.watcher.trigger.schedule.Schedule;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleTrigger;
import org.elasticsearch.xpack.trigger.schedule.ScheduleTrigger;
import org.elasticsearch.xpack.trigger.schedule.Schedule;
/**
*

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger;
package org.elasticsearch.xpack.trigger;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.xcontent.XContentParser;
@ -43,7 +43,7 @@ public interface TriggerEngine<T extends Trigger, E extends TriggerEvent> {
T parseTrigger(String context, XContentParser parser) throws IOException;
E parseTriggerEvent(TriggerService service, String watchId, String context, XContentParser parser) throws IOException;
E parseTriggerEvent(TriggerService service, String id, String context, XContentParser parser) throws IOException;
interface Listener {

View File

@ -3,12 +3,12 @@
* 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.xpack.watcher.trigger;
package org.elasticsearch.xpack.trigger;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils;
import org.elasticsearch.xpack.support.DateTimeUtils;
import org.joda.time.DateTime;
import java.io.IOException;
@ -58,7 +58,7 @@ public abstract class TriggerEvent implements ToXContent {
public void recordXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
builder.field(Field.TYPE.getPreferredName(), type());
WatcherDateTimeUtils.writeDate(Field.TRIGGERED_TIME.getPreferredName(), builder, triggeredTime);
DateTimeUtils.writeDate(Field.TRIGGERED_TIME.getPreferredName(), builder, triggeredTime);
recordDataXContent(builder, params);
builder.endObject();
}

View File

@ -3,13 +3,13 @@
* 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.xpack.watcher.trigger;
package org.elasticsearch.xpack.trigger;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.multibindings.Multibinder;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.watcher.trigger.manual.ManualTriggerEngine;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleModule;
import org.elasticsearch.xpack.trigger.manual.ManualTriggerEngine;
import org.elasticsearch.xpack.trigger.schedule.ScheduleModule;
import java.util.HashSet;
import java.util.Set;

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger;
package org.elasticsearch.xpack.trigger;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.component.AbstractComponent;
@ -20,7 +20,7 @@ import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import static java.util.Collections.unmodifiableMap;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.support.Exceptions.illegalArgument;
/**
*

View File

@ -3,12 +3,12 @@
* 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.xpack.watcher.trigger.manual;
package org.elasticsearch.xpack.trigger.manual;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.watcher.trigger.Trigger;
import org.elasticsearch.xpack.trigger.Trigger;
import java.io.IOException;

View File

@ -3,19 +3,19 @@
* 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.xpack.watcher.trigger.manual;
package org.elasticsearch.xpack.trigger.manual;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.watcher.trigger.TriggerEngine;
import org.elasticsearch.xpack.watcher.trigger.TriggerService;
import org.elasticsearch.xpack.trigger.TriggerEngine;
import org.elasticsearch.xpack.trigger.TriggerService;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.support.Exceptions.illegalArgument;
/**
*/
@ -79,8 +79,8 @@ public class ManualTriggerEngine implements TriggerEngine<ManualTrigger, ManualT
}
@Override
public ManualTriggerEvent parseTriggerEvent(TriggerService service, String watchId, String context, XContentParser parser) throws
public ManualTriggerEvent parseTriggerEvent(TriggerService service, String id, String context, XContentParser parser) throws
IOException {
return ManualTriggerEvent.parse(service, watchId, context, parser);
return ManualTriggerEvent.parse(service, id, context, parser);
}
}

View File

@ -3,12 +3,12 @@
* 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.xpack.watcher.trigger.manual;
package org.elasticsearch.xpack.trigger.manual;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.watcher.trigger.TriggerEvent;
import org.elasticsearch.xpack.watcher.trigger.TriggerService;
import org.elasticsearch.xpack.trigger.TriggerEvent;
import org.elasticsearch.xpack.trigger.TriggerService;
import java.io.IOException;
@ -43,9 +43,9 @@ public class ManualTriggerEvent extends TriggerEvent {
builder.endObject();
}
public static ManualTriggerEvent parse(TriggerService triggerService, String watchId, String context, XContentParser parser) throws
public static ManualTriggerEvent parse(TriggerService triggerService, String id, String context, XContentParser parser) throws
IOException {
TriggerEvent parsedTriggerEvent = triggerService.parseTriggerEvent(watchId, context, parser);
TriggerEvent parsedTriggerEvent = triggerService.parseTriggerEvent(id, context, parser);
return new ManualTriggerEvent(context, parsedTriggerEvent);
}

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.ElasticsearchParseException;
import org.joda.time.DateTimeZone;
@ -21,7 +21,7 @@ import java.util.StringTokenizer;
import java.util.TimeZone;
import java.util.TreeSet;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.support.Exceptions.illegalArgument;
/**

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.xcontent.XContentBuilder;

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import java.util.Arrays;
import java.util.Comparator;

View File

@ -3,14 +3,14 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.DayTimes;
import org.elasticsearch.xpack.trigger.schedule.support.DayTimes;
import java.io.IOException;
import java.util.ArrayList;

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseField;
@ -11,7 +11,7 @@ import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.DayTimes;
import org.elasticsearch.xpack.trigger.schedule.support.DayTimes;
import java.io.IOException;
import java.util.ArrayList;
@ -19,7 +19,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.support.Exceptions.illegalArgument;
/**
*

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.xcontent.ToXContent;
@ -14,7 +14,7 @@ import java.io.IOException;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.support.Exceptions.illegalArgument;
/**
*

View File

@ -3,12 +3,12 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.MonthTimes;
import org.elasticsearch.xpack.trigger.schedule.support.MonthTimes;
import java.io.IOException;
import java.util.ArrayList;

View File

@ -0,0 +1,27 @@
/*
* 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.xpack.trigger.schedule;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.scheduler.SchedulerEngine;
import java.io.IOException;
/**
*
*/
public interface Schedule extends SchedulerEngine.Schedule, ToXContent {
String type();
interface Parser<S extends Schedule> {
String type();
S parse(XContentParser parser) throws IOException;
}
}

View File

@ -3,15 +3,15 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.multibindings.MapBinder;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.watcher.trigger.TriggerEngine;
import org.elasticsearch.xpack.watcher.trigger.schedule.engine.SchedulerScheduleTriggerEngine;
import org.elasticsearch.xpack.watcher.trigger.schedule.engine.TickerScheduleTriggerEngine;
import org.elasticsearch.xpack.trigger.schedule.engine.TickerScheduleTriggerEngine;
import org.elasticsearch.xpack.trigger.TriggerEngine;
import org.elasticsearch.xpack.trigger.schedule.engine.SchedulerScheduleTriggerEngine;
import java.util.HashMap;
import java.util.Locale;

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.inject.Inject;

View File

@ -3,10 +3,10 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.xpack.watcher.trigger.Trigger;
import org.elasticsearch.xpack.trigger.Trigger;
import java.io.IOException;

View File

@ -3,21 +3,21 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils;
import org.elasticsearch.xpack.trigger.AbstractTriggerEngine;
import org.elasticsearch.xpack.trigger.TriggerService;
import org.elasticsearch.xpack.support.DateTimeUtils;
import org.elasticsearch.xpack.support.clock.Clock;
import org.elasticsearch.xpack.watcher.trigger.AbstractTriggerEngine;
import org.elasticsearch.xpack.watcher.trigger.TriggerService;
import org.joda.time.DateTime;
import java.io.IOException;
import java.util.Map;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.support.Exceptions.illegalArgument;
/**
*
@ -48,13 +48,13 @@ public abstract class ScheduleTriggerEngine extends AbstractTriggerEngine<Schedu
}
Object value = data.get(ScheduleTriggerEvent.Field.TRIGGERED_TIME.getPreferredName());
DateTime triggeredTime = value != null ? WatcherDateTimeUtils.convertToDate(value, clock) : now;
DateTime triggeredTime = value != null ? DateTimeUtils.convertToDate(value, clock) : now;
if (triggeredTime == null) {
throw illegalArgument("could not simulate schedule event. could not convert provided triggered time [{}] to date/time", value);
}
value = data.get(ScheduleTriggerEvent.Field.SCHEDULED_TIME.getPreferredName());
DateTime scheduledTime = value != null ? WatcherDateTimeUtils.convertToDate(value, clock) : triggeredTime;
DateTime scheduledTime = value != null ? DateTimeUtils.convertToDate(value, clock) : triggeredTime;
if (scheduledTime == null) {
throw illegalArgument("could not simulate schedule event. could not convert provided scheduled time [{}] to date/time", value);
}
@ -69,8 +69,8 @@ public abstract class ScheduleTriggerEngine extends AbstractTriggerEngine<Schedu
}
@Override
public ScheduleTriggerEvent parseTriggerEvent(TriggerService service, String watchId, String context, XContentParser parser) throws
public ScheduleTriggerEvent parseTriggerEvent(TriggerService service, String id, String context, XContentParser parser) throws
IOException {
return ScheduleTriggerEvent.parse(parser, watchId, context, clock);
return ScheduleTriggerEvent.parse(parser, id, context, clock);
}
}

View File

@ -3,16 +3,16 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils;
import org.elasticsearch.xpack.support.DateTimeUtils;
import org.elasticsearch.xpack.support.clock.Clock;
import org.elasticsearch.xpack.watcher.trigger.TriggerEvent;
import org.elasticsearch.xpack.trigger.TriggerEvent;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@ -47,15 +47,15 @@ public class ScheduleTriggerEvent extends TriggerEvent {
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
WatcherDateTimeUtils.writeDate(Field.TRIGGERED_TIME.getPreferredName(), builder, triggeredTime);
WatcherDateTimeUtils.writeDate(Field.SCHEDULED_TIME.getPreferredName(), builder, scheduledTime);
DateTimeUtils.writeDate(Field.TRIGGERED_TIME.getPreferredName(), builder, triggeredTime);
DateTimeUtils.writeDate(Field.SCHEDULED_TIME.getPreferredName(), builder, scheduledTime);
return builder.endObject();
}
@Override
public void recordDataXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(ScheduleTrigger.TYPE);
WatcherDateTimeUtils.writeDate(Field.SCHEDULED_TIME.getPreferredName(), builder, scheduledTime);
DateTimeUtils.writeDate(Field.SCHEDULED_TIME.getPreferredName(), builder, scheduledTime);
builder.endObject();
}
@ -70,7 +70,7 @@ public class ScheduleTriggerEvent extends TriggerEvent {
currentFieldName = parser.currentName();
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.TRIGGERED_TIME)) {
try {
triggeredTime = WatcherDateTimeUtils.parseDateMath(currentFieldName, parser, DateTimeZone.UTC, clock);
triggeredTime = DateTimeUtils.parseDateMath(currentFieldName, parser, DateTimeZone.UTC, clock);
} catch (ElasticsearchParseException pe) {
//Failed to parse as a date try datemath parsing
throw new ElasticsearchParseException("could not parse [{}] trigger event for [{}] for watch [{}]. failed to parse " +
@ -78,7 +78,7 @@ public class ScheduleTriggerEvent extends TriggerEvent {
}
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.SCHEDULED_TIME)) {
try {
scheduledTime = WatcherDateTimeUtils.parseDateMath(currentFieldName, parser, DateTimeZone.UTC, clock);
scheduledTime = DateTimeUtils.parseDateMath(currentFieldName, parser, DateTimeZone.UTC, clock);
} catch (ElasticsearchParseException pe) {
throw new ElasticsearchParseException("could not parse [{}] trigger event for [{}] for watch [{}]. failed to parse " +
"date field [{}]", pe, ScheduleTriggerEngine.TYPE, context, watchId, currentFieldName);

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
/**
* A static factory for all available schedules.

View File

@ -3,12 +3,12 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.WeekTimes;
import org.elasticsearch.xpack.trigger.schedule.support.WeekTimes;
import java.io.IOException;
import java.util.ArrayList;

View File

@ -3,12 +3,12 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.YearTimes;
import org.elasticsearch.xpack.trigger.schedule.support.YearTimes;
import java.io.IOException;
import java.util.ArrayList;

View File

@ -0,0 +1,82 @@
/*
* 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.xpack.trigger.schedule.engine;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.scheduler.SchedulerEngine;
import org.elasticsearch.xpack.support.clock.Clock;
import org.elasticsearch.xpack.trigger.TriggerEvent;
import org.elasticsearch.xpack.trigger.schedule.ScheduleRegistry;
import org.elasticsearch.xpack.trigger.schedule.ScheduleTrigger;
import org.elasticsearch.xpack.trigger.schedule.ScheduleTriggerEvent;
import org.elasticsearch.xpack.trigger.schedule.ScheduleTriggerEngine;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
*
*/
public class SchedulerScheduleTriggerEngine extends ScheduleTriggerEngine {
private final SchedulerEngine schedulerEngine;
@Inject
public SchedulerScheduleTriggerEngine(Settings settings, ScheduleRegistry scheduleRegistry, Clock clock) {
super(settings, scheduleRegistry, clock);
this.schedulerEngine = new SchedulerEngine(clock);
this.schedulerEngine.register(event ->
notifyListeners(event.getJobName(), event.getTriggeredTime(), event.getScheduledTime()));
}
@Override
public void start(Collection<Job> jobs) {
logger.debug("starting schedule engine...");
final List<SchedulerEngine.Job> schedulerJobs = new ArrayList<>();
jobs.stream()
.filter(job -> job.trigger() instanceof ScheduleTrigger)
.forEach(job -> {
ScheduleTrigger trigger = (ScheduleTrigger) job.trigger();
schedulerJobs.add(new SchedulerEngine.Job(job.id(), trigger.getSchedule()));
});
schedulerEngine.start(schedulerJobs);
logger.debug("schedule engine started at [{}]", clock.nowUTC());
}
@Override
public void stop() {
logger.debug("stopping schedule engine...");
schedulerEngine.stop();
logger.debug("schedule engine stopped");
}
@Override
public void add(Job job) {
assert job.trigger() instanceof ScheduleTrigger;
ScheduleTrigger trigger = (ScheduleTrigger) job.trigger();
schedulerEngine.add(new SchedulerEngine.Job(job.id(), trigger.getSchedule()));
}
@Override
public boolean remove(String jobId) {
return schedulerEngine.remove(jobId);
}
protected void notifyListeners(String name, long triggeredTime, long scheduledTime) {
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(Collections.<TriggerEvent>singletonList(event));
}
}
}

View File

@ -3,18 +3,18 @@
* 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.xpack.watcher.trigger.schedule.engine;
package org.elasticsearch.xpack.trigger.schedule.engine;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.xpack.support.clock.Clock;
import org.elasticsearch.xpack.watcher.trigger.TriggerEvent;
import org.elasticsearch.xpack.watcher.trigger.schedule.Schedule;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleRegistry;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleTrigger;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleTriggerEngine;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleTriggerEvent;
import org.elasticsearch.xpack.trigger.schedule.ScheduleRegistry;
import org.elasticsearch.xpack.trigger.schedule.ScheduleTrigger;
import org.elasticsearch.xpack.trigger.schedule.ScheduleTriggerEvent;
import org.elasticsearch.xpack.trigger.TriggerEvent;
import org.elasticsearch.xpack.trigger.schedule.Schedule;
import org.elasticsearch.xpack.trigger.schedule.ScheduleTriggerEngine;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule.support;
package org.elasticsearch.xpack.trigger.schedule.support;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.xcontent.ToXContent;

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule.support;
package org.elasticsearch.xpack.trigger.schedule.support;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseFieldMatcher;
@ -16,8 +16,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.watcher.support.Strings.join;
import static org.elasticsearch.xpack.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.support.Strings.join;
/**
*

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule.support;
package org.elasticsearch.xpack.trigger.schedule.support;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.xcontent.ToXContent;

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule.support;
package org.elasticsearch.xpack.trigger.schedule.support;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseFieldMatcher;
@ -19,8 +19,8 @@ import java.util.Locale;
import java.util.Set;
import static org.elasticsearch.common.util.set.Sets.newHashSet;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.watcher.support.Strings.join;
import static org.elasticsearch.xpack.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.support.Strings.join;
/**
*

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule.support;
package org.elasticsearch.xpack.trigger.schedule.support;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.xcontent.ToXContent;

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule.support;
package org.elasticsearch.xpack.trigger.schedule.support;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseFieldMatcher;
@ -18,7 +18,7 @@ import java.util.HashSet;
import java.util.Set;
import static org.elasticsearch.common.util.set.Sets.newHashSet;
import static org.elasticsearch.xpack.watcher.support.Strings.join;
import static org.elasticsearch.xpack.support.Strings.join;
/**
*

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule.support;
package org.elasticsearch.xpack.trigger.schedule.support;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.ParseFieldMatcher;
@ -21,8 +21,8 @@ import java.util.Locale;
import java.util.Set;
import static org.elasticsearch.common.util.set.Sets.newHashSet;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.watcher.support.Strings.join;
import static org.elasticsearch.xpack.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.support.Strings.join;
/**
*

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule.tool;
package org.elasticsearch.xpack.trigger.schedule.tool;
import java.util.Arrays;
import java.util.List;
@ -14,7 +14,7 @@ import org.elasticsearch.cli.Command;
import org.elasticsearch.cli.ExitCodes;
import org.elasticsearch.cli.UserError;
import org.elasticsearch.cli.Terminal;
import org.elasticsearch.xpack.watcher.trigger.schedule.Cron;
import org.elasticsearch.xpack.trigger.schedule.Cron;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;

View File

@ -27,7 +27,7 @@ import java.util.Map;
import static java.util.Collections.singletonMap;
import static java.util.Collections.unmodifiableMap;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.support.Exceptions.illegalArgument;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;

View File

@ -15,8 +15,8 @@ import org.elasticsearch.xpack.watcher.support.xcontent.XContentSource;
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
import org.elasticsearch.xpack.watcher.transport.actions.execute.ExecuteWatchResponse;
import org.elasticsearch.xpack.watcher.transport.actions.get.GetWatchResponse;
import org.elasticsearch.xpack.watcher.trigger.TriggerEvent;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleTriggerEvent;
import org.elasticsearch.xpack.trigger.TriggerEvent;
import org.elasticsearch.xpack.trigger.schedule.ScheduleTriggerEvent;
import org.elasticsearch.xpack.watcher.watch.WatchStore;
import org.elasticsearch.xpack.notification.email.support.EmailServer;
import org.joda.time.DateTime;
@ -32,8 +32,8 @@ import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.emailAction
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.cron;
import static org.elasticsearch.xpack.trigger.TriggerBuilders.schedule;
import static org.elasticsearch.xpack.trigger.schedule.Schedules.cron;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.support;
package org.elasticsearch.xpack.support;
import org.elasticsearch.ElasticsearchParseException;
@ -22,7 +22,6 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.xContentParser;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.either;
import static org.hamcrest.Matchers.is;
@ -31,7 +30,7 @@ import static org.hamcrest.Matchers.notNullValue;
/**
*
*/
public class WatcherDateTimeUtilsTests extends ESTestCase {
public class DateTimeUtilsTests extends ESTestCase {
public void testParseTimeValueNumeric() throws Exception {
TimeValue value = new TimeValue(randomInt(100), randomFrom(TimeUnit.values()));
long millis = value.getMillis();
@ -41,13 +40,14 @@ public class WatcherDateTimeUtilsTests extends ESTestCase {
} else {
xContentBuilder.field("value", Long.toString(millis));
}
XContentParser parser = xContentParser(xContentBuilder.endObject());
final XContentBuilder builder = xContentBuilder.endObject();
XContentParser parser = builder.contentType().xContent().createParser(builder.bytes());
parser.nextToken(); // start object
parser.nextToken(); // field name
parser.nextToken(); // value
try {
WatcherDateTimeUtils.parseTimeValue(parser, "test");
DateTimeUtils.parseTimeValue(parser, "test");
fail("Expected ElasticsearchParseException");
} catch (ElasticsearchParseException e) {
assertThat(e.getMessage(), either(is("failed to parse time unit"))
@ -58,13 +58,14 @@ public class WatcherDateTimeUtilsTests extends ESTestCase {
public void testParseTimeValueNumericNegative() throws Exception {
TimeValue value = new TimeValue(randomIntBetween(1, 100), randomFrom(MILLISECONDS, SECONDS, MINUTES, HOURS, DAYS));
XContentParser parser = xContentParser(jsonBuilder().startObject().field("value", -1 * value.getMillis()).endObject());
final XContentBuilder builder = jsonBuilder().startObject().field("value", -1 * value.getMillis()).endObject();
XContentParser parser = builder.contentType().xContent().createParser(builder.bytes());
parser.nextToken(); // start object
parser.nextToken(); // field name
parser.nextToken(); // value
try {
WatcherDateTimeUtils.parseTimeValue(parser, "test");
DateTimeUtils.parseTimeValue(parser, "test");
fail("Expected ElasticsearchParseException");
} catch (ElasticsearchParseException e) {
assertThat(e.getMessage(),
@ -81,12 +82,13 @@ public class WatcherDateTimeUtilsTests extends ESTestCase {
String key = randomFrom(values.keySet().toArray(new String[values.size()]));
XContentParser parser = xContentParser(jsonBuilder().startObject().field("value", key).endObject());
final XContentBuilder builder = jsonBuilder().startObject().field("value", key).endObject();
XContentParser parser = builder.contentType().xContent().createParser(builder.bytes());
parser.nextToken(); // start object
parser.nextToken(); // field name
parser.nextToken(); // value
TimeValue parsed = WatcherDateTimeUtils.parseTimeValue(parser, "test");
TimeValue parsed = DateTimeUtils.parseTimeValue(parser, "test");
assertThat(parsed, notNullValue());
assertThat(parsed.millis(), is(values.get(key).millis()));
}
@ -100,13 +102,14 @@ public class WatcherDateTimeUtilsTests extends ESTestCase {
String key = randomFrom(values.keySet().toArray(new String[values.size()]));
XContentParser parser = xContentParser(jsonBuilder().startObject().field("value", key).endObject());
final XContentBuilder builder = jsonBuilder().startObject().field("value", key).endObject();
XContentParser parser = builder.contentType().xContent().createParser(builder.bytes());
parser.nextToken(); // start object
parser.nextToken(); // field name
parser.nextToken(); // value
try {
WatcherDateTimeUtils.parseTimeValue(parser, "test");
DateTimeUtils.parseTimeValue(parser, "test");
fail("Expected ElasticsearchParseException");
} catch (ElasticsearchParseException e) {
assertThat(e.getMessage(), is("failed to parse time unit"));
@ -114,12 +117,13 @@ public class WatcherDateTimeUtilsTests extends ESTestCase {
}
public void testParseTimeValueNull() throws Exception {
XContentParser parser = xContentParser(jsonBuilder().startObject().nullField("value").endObject());
final XContentBuilder builder = jsonBuilder().startObject().nullField("value").endObject();
XContentParser parser = builder.contentType().xContent().createParser(builder.bytes());
parser.nextToken(); // start object
parser.nextToken(); // field name
parser.nextToken(); // value
TimeValue parsed = WatcherDateTimeUtils.parseTimeValue(parser, "test");
TimeValue parsed = DateTimeUtils.parseTimeValue(parser, "test");
assertThat(parsed, nullValue());
}
}

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger;
package org.elasticsearch.xpack.trigger;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.logging.ESLogger;
@ -13,10 +13,10 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.support.clock.Clock;
import org.elasticsearch.xpack.support.clock.ClockMock;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleRegistry;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleTrigger;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleTriggerEngine;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleTriggerEvent;
import org.elasticsearch.xpack.trigger.schedule.ScheduleRegistry;
import org.elasticsearch.xpack.trigger.schedule.ScheduleTrigger;
import org.elasticsearch.xpack.trigger.schedule.ScheduleTriggerEngine;
import org.elasticsearch.xpack.trigger.schedule.ScheduleTriggerEvent;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@ -48,9 +48,9 @@ public class ScheduleTriggerEngineMock extends ScheduleTriggerEngine {
}
@Override
public ScheduleTriggerEvent parseTriggerEvent(TriggerService service, String watchId, String context,
public ScheduleTriggerEvent parseTriggerEvent(TriggerService service, String id, String context,
XContentParser parser) throws IOException {
return ScheduleTriggerEvent.parse(parser, watchId, context, clock);
return ScheduleTriggerEvent.parse(parser, id, context, clock);
}
@Override

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.bytes.BytesReference;

View File

@ -3,17 +3,17 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.DayTimes;
import org.elasticsearch.xpack.trigger.schedule.support.DayTimes;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.xpack.watcher.support.Strings.join;
import static org.elasticsearch.xpack.support.Strings.join;
import static org.hamcrest.Matchers.arrayContaining;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.containsString;

View File

@ -3,14 +3,14 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.xpack.watcher.support.Strings;
import org.elasticsearch.xpack.support.Strings;
import java.util.Arrays;
import java.util.stream.Collectors;

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.bytes.BytesReference;

View File

@ -3,18 +3,18 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.DayTimes;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.MonthTimes;
import org.elasticsearch.xpack.trigger.schedule.support.DayTimes;
import org.elasticsearch.xpack.trigger.schedule.support.MonthTimes;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.xpack.watcher.support.Strings.join;
import static org.elasticsearch.xpack.support.Strings.join;
import static org.hamcrest.Matchers.arrayContaining;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.hasItemInArray;

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.common.bytes.BytesReference;

View File

@ -3,29 +3,26 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.DayOfWeek;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.DayTimes;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.Month;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.MonthTimes;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.WeekTimes;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.YearTimes;
import org.elasticsearch.xpack.trigger.schedule.support.DayOfWeek;
import org.elasticsearch.xpack.trigger.schedule.support.DayTimes;
import org.elasticsearch.xpack.trigger.schedule.support.Month;
import org.elasticsearch.xpack.trigger.schedule.support.MonthTimes;
import org.elasticsearch.xpack.trigger.schedule.support.WeekTimes;
import org.elasticsearch.xpack.trigger.schedule.support.YearTimes;
import java.io.IOException;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.daily;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.hourly;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.monthly;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.weekly;
import static org.elasticsearch.xpack.trigger.schedule.Schedules.hourly;
import static org.elasticsearch.xpack.trigger.schedule.Schedules.interval;
/**
*
@ -46,44 +43,44 @@ public abstract class ScheduleTestCase extends ESTestCase {
protected static MonthlySchedule randomMonthlySchedule() {
switch (randomIntBetween(1, 4)) {
case 1: return monthly().build();
case 2: return monthly().time(MonthTimes.builder().atMidnight()).build();
case 3: return monthly().time(MonthTimes.builder().on(randomIntBetween(1, 31)).atMidnight()).build();
case 1: return Schedules.monthly().build();
case 2: return Schedules.monthly().time(MonthTimes.builder().atMidnight()).build();
case 3: return Schedules.monthly().time(MonthTimes.builder().on(randomIntBetween(1, 31)).atMidnight()).build();
default: return new MonthlySchedule(validMonthTimes());
}
}
protected static WeeklySchedule randomWeeklySchedule() {
switch (randomIntBetween(1, 4)) {
case 1: return weekly().build();
case 2: return weekly().time(WeekTimes.builder().atMidnight()).build();
case 3: return weekly().time(WeekTimes.builder().on(DayOfWeek.THURSDAY).atMidnight()).build();
case 1: return Schedules.weekly().build();
case 2: return Schedules.weekly().time(WeekTimes.builder().atMidnight()).build();
case 3: return Schedules.weekly().time(WeekTimes.builder().on(DayOfWeek.THURSDAY).atMidnight()).build();
default: return new WeeklySchedule(validWeekTimes());
}
}
protected static DailySchedule randomDailySchedule() {
switch (randomIntBetween(1, 4)) {
case 1: return daily().build();
case 2: return daily().atMidnight().build();
case 3: return daily().atNoon().build();
case 1: return Schedules.daily().build();
case 2: return Schedules.daily().atMidnight().build();
case 3: return Schedules.daily().atNoon().build();
default: return new DailySchedule(validDayTimes());
}
}
protected static HourlySchedule randomHourlySchedule() {
switch (randomIntBetween(1, 4)) {
case 1: return hourly().build();
case 2: return hourly().minutes(randomIntBetween(0, 59)).build();
case 3: return hourly(randomIntBetween(0, 59));
default: return hourly().minutes(validMinutes()).build();
case 1: return Schedules.hourly().build();
case 2: return Schedules.hourly().minutes(randomIntBetween(0, 59)).build();
case 3: return Schedules.hourly(randomIntBetween(0, 59));
default: return Schedules.hourly().minutes(validMinutes()).build();
}
}
protected static IntervalSchedule randomIntervalSchedule() {
switch (randomIntBetween(1, 3)) {
case 1: return interval(randomInterval().toString());
case 2: return interval(randomIntBetween(1, 100), randomIntervalUnit());
case 1: return Schedules.interval(randomInterval().toString());
case 2: return Schedules.interval(randomIntBetween(1, 100), randomIntervalUnit());
default: return new IntervalSchedule(randomInterval());
}
}

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.common.xcontent.XContentBuilder;

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.ElasticsearchParseException;
@ -12,12 +12,12 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.DayOfWeek;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.DayTimes;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.WeekTimes;
import org.elasticsearch.xpack.trigger.schedule.support.DayOfWeek;
import org.elasticsearch.xpack.trigger.schedule.support.DayTimes;
import org.elasticsearch.xpack.trigger.schedule.support.WeekTimes;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.xpack.watcher.support.Strings.join;
import static org.elasticsearch.xpack.support.Strings.join;
import static org.hamcrest.Matchers.arrayContaining;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.contains;

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule;
package org.elasticsearch.xpack.trigger.schedule;
import org.elasticsearch.ElasticsearchParseException;
@ -12,11 +12,11 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.DayTimes;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.YearTimes;
import org.elasticsearch.xpack.trigger.schedule.support.DayTimes;
import org.elasticsearch.xpack.trigger.schedule.support.YearTimes;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.xpack.watcher.support.Strings.join;
import static org.elasticsearch.xpack.support.Strings.join;
import static org.hamcrest.Matchers.arrayContaining;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.hasItemInArray;

View File

@ -3,17 +3,18 @@
* 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.xpack.watcher.trigger.schedule.engine;
package org.elasticsearch.xpack.trigger.schedule.engine;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.support.clock.SystemClock;
import org.elasticsearch.xpack.watcher.trigger.Trigger;
import org.elasticsearch.xpack.watcher.trigger.TriggerEngine;
import org.elasticsearch.xpack.watcher.trigger.TriggerEvent;
import org.elasticsearch.xpack.watcher.trigger.schedule.Schedule;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleTrigger;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.DayOfWeek;
import org.elasticsearch.xpack.watcher.trigger.schedule.support.WeekTimes;
import org.elasticsearch.xpack.trigger.Trigger;
import org.elasticsearch.xpack.trigger.schedule.ScheduleTrigger;
import org.elasticsearch.xpack.trigger.schedule.Schedules;
import org.elasticsearch.xpack.trigger.TriggerEngine;
import org.elasticsearch.xpack.trigger.TriggerEvent;
import org.elasticsearch.xpack.trigger.schedule.Schedule;
import org.elasticsearch.xpack.trigger.schedule.support.DayOfWeek;
import org.elasticsearch.xpack.trigger.schedule.support.WeekTimes;
import org.joda.time.DateTime;
import org.junit.After;
import org.junit.Before;
@ -25,10 +26,6 @@ import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.daily;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.hourly;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.weekly;
import static org.hamcrest.Matchers.is;
import static org.joda.time.DateTimeZone.UTC;
@ -52,7 +49,7 @@ public abstract class BaseTriggerEngineTestCase extends ESTestCase {
final CountDownLatch latch = new CountDownLatch(count);
List<TriggerEngine.Job> jobs = new ArrayList<>();
for (int i = 0; i < count; i++) {
jobs.add(new SimpleJob(String.valueOf(i), interval("1s")));
jobs.add(new SimpleJob(String.valueOf(i), Schedules.interval("1s")));
}
final BitSet bits = new BitSet(count);
engine.register(new TriggerEngine.Listener() {
@ -104,7 +101,7 @@ public abstract class BaseTriggerEngineTestCase extends ESTestCase {
int minute = minOfHour.value;
logger.info("scheduling hourly job [{}]", minute);
logger.info("current date [{}]", now);
engine.add(new SimpleJob(name, hourly(minute)));
engine.add(new SimpleJob(name, Schedules.hourly(minute)));
long secondsToWait = now.getSecondOfMinute() < 29 ? 62 - now.getSecondOfMinute() : 122 - now.getSecondOfMinute();
logger.info("waiting at least [{}] seconds for response", secondsToWait);
if (!latch.await(secondsToWait, TimeUnit.SECONDS)) {
@ -138,7 +135,7 @@ public abstract class BaseTriggerEngineTestCase extends ESTestCase {
int hour = hourOfDay.value;
logger.info("scheduling hourly job [{}:{}]", hour, minute);
logger.info("current date [{}]", now);
engine.add(new SimpleJob(name, daily().at(hour, minute).build()));
engine.add(new SimpleJob(name, Schedules.daily().at(hour, minute).build()));
// 30 sec is the default idle time for the scheduler
long secondsToWait = now.getSecondOfMinute() < 29 ? 62 - now.getSecondOfMinute() : 122 - now.getSecondOfMinute();
logger.info("waiting at least [{}] seconds for response", secondsToWait);
@ -175,7 +172,7 @@ public abstract class BaseTriggerEngineTestCase extends ESTestCase {
DayOfWeek day = dayOfWeek.day();
logger.info("scheduling hourly job [{} {}:{}]", day, hour, minute);
logger.info("current date [{}]", now);
engine.add(new SimpleJob(name, weekly().time(WeekTimes.builder().on(day).at(hour, minute).build()).build()));
engine.add(new SimpleJob(name, Schedules.weekly().time(WeekTimes.builder().on(day).at(hour, minute).build()).build()));
// 30 sec is the default idle time for the scheduler
long secondsToWait = now.getSecondOfMinute() < 29 ? 62 - now.getSecondOfMinute() : 122 - now.getSecondOfMinute();
logger.info("waiting at least [{}] seconds for response", secondsToWait);
@ -196,7 +193,7 @@ public abstract class BaseTriggerEngineTestCase extends ESTestCase {
int times = scaledRandomIntBetween(3, 30);
for (int i = 0; i < times; i++) {
engine.add(new SimpleJob("_id", interval("10s")));
engine.add(new SimpleJob("_id", Schedules.interval("10s")));
}
}

View File

@ -3,13 +3,13 @@
* 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.xpack.watcher.trigger.schedule.engine;
package org.elasticsearch.xpack.trigger.schedule.engine;
import org.apache.lucene.util.LuceneTestCase.BadApple;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.support.clock.SystemClock;
import org.elasticsearch.xpack.watcher.trigger.TriggerEngine;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleRegistry;
import org.elasticsearch.xpack.trigger.TriggerEngine;
import org.elasticsearch.xpack.trigger.schedule.ScheduleRegistry;
import static org.mockito.Mockito.mock;

View File

@ -3,13 +3,13 @@
* 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.xpack.watcher.trigger.schedule.engine;
package org.elasticsearch.xpack.trigger.schedule.engine;
import org.apache.lucene.util.LuceneTestCase.BadApple;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.support.clock.SystemClock;
import org.elasticsearch.xpack.watcher.trigger.TriggerEngine;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleRegistry;
import org.elasticsearch.xpack.trigger.schedule.ScheduleRegistry;
import org.elasticsearch.xpack.trigger.TriggerEngine;
import static org.mockito.Mockito.mock;

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule.tool;
package org.elasticsearch.xpack.trigger.schedule.tool;
import org.elasticsearch.cli.Command;
import org.elasticsearch.cli.CommandTestCase;

View File

@ -3,7 +3,7 @@
* 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.xpack.watcher.trigger.schedule.tool;
package org.elasticsearch.xpack.trigger.schedule.tool;
import org.elasticsearch.cli.Terminal;

View File

@ -63,8 +63,8 @@ import org.elasticsearch.xpack.watcher.transport.actions.service.TransportWatche
import org.elasticsearch.xpack.watcher.transport.actions.service.WatcherServiceAction;
import org.elasticsearch.xpack.watcher.transport.actions.stats.TransportWatcherStatsAction;
import org.elasticsearch.xpack.watcher.transport.actions.stats.WatcherStatsAction;
import org.elasticsearch.xpack.watcher.trigger.TriggerModule;
import org.elasticsearch.xpack.watcher.trigger.schedule.ScheduleModule;
import org.elasticsearch.xpack.trigger.TriggerModule;
import org.elasticsearch.xpack.trigger.schedule.ScheduleModule;
import org.elasticsearch.xpack.watcher.watch.WatchModule;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

View File

@ -18,7 +18,7 @@ import org.elasticsearch.index.engine.VersionConflictEngineException;
import org.elasticsearch.xpack.watcher.execution.ExecutionService;
import org.elasticsearch.xpack.watcher.support.WatcherIndexTemplateRegistry;
import org.elasticsearch.xpack.support.clock.Clock;
import org.elasticsearch.xpack.watcher.trigger.TriggerService;
import org.elasticsearch.xpack.trigger.TriggerService;
import org.elasticsearch.xpack.watcher.watch.Watch;
import org.elasticsearch.xpack.watcher.watch.WatchLockService;
import org.elasticsearch.xpack.watcher.watch.WatchStatus;
@ -30,9 +30,9 @@ import org.joda.time.PeriodType;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalState;
import static org.elasticsearch.xpack.watcher.support.Exceptions.ioException;
import static org.elasticsearch.xpack.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.support.Exceptions.illegalState;
import static org.elasticsearch.xpack.support.Exceptions.ioException;
public class WatcherService extends AbstractComponent {

View File

@ -21,8 +21,8 @@ import java.io.IOException;
import java.util.Locale;
import java.util.Objects;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils.dateTimeFormatter;
import static org.elasticsearch.xpack.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.support.DateTimeUtils.dateTimeFormatter;
/**
*

View File

@ -18,7 +18,7 @@ import org.elasticsearch.xpack.watcher.actions.throttler.ActionThrottler;
import org.elasticsearch.xpack.watcher.actions.throttler.Throttler;
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
import org.elasticsearch.xpack.watcher.WatcherLicensee;
import org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils;
import org.elasticsearch.xpack.support.DateTimeUtils;
import org.elasticsearch.xpack.support.clock.Clock;
import org.elasticsearch.xpack.watcher.transform.ExecutableTransform;
import org.elasticsearch.xpack.watcher.transform.Transform;
@ -158,7 +158,7 @@ public class ActionWrapper implements ToXContent {
transform = transformRegistry.parse(watchId, parser);
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Throttler.Field.THROTTLE_PERIOD)) {
try {
throttlePeriod = WatcherDateTimeUtils.parseTimeValue(parser, Throttler.Field.THROTTLE_PERIOD.toString());
throttlePeriod = DateTimeUtils.parseTimeValue(parser, Throttler.Field.THROTTLE_PERIOD.toString());
} catch (ElasticsearchParseException pe) {
throw new ElasticsearchParseException("could not parse action [{}/{}]. failed to parse field [{}] as time value",
pe, watchId, actionId, currentFieldName);

View File

@ -20,7 +20,7 @@ import org.elasticsearch.xpack.watcher.actions.Action;
import org.elasticsearch.xpack.watcher.actions.ExecutableAction;
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
import org.elasticsearch.xpack.watcher.support.ArrayObjectIterator;
import org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils;
import org.elasticsearch.xpack.support.DateTimeUtils;
import org.elasticsearch.xpack.watcher.support.init.proxy.WatcherClientProxy;
import org.elasticsearch.xpack.watcher.support.xcontent.XContentSource;
import org.elasticsearch.xpack.watcher.watch.Payload;
@ -30,7 +30,7 @@ import java.util.HashMap;
import java.util.Map;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalState;
import static org.elasticsearch.xpack.support.Exceptions.illegalState;
public class ExecutableIndexAction extends ExecutableAction<IndexAction> {
@ -71,9 +71,9 @@ public class ExecutableIndexAction extends ExecutableAction<IndexAction> {
if (!(data instanceof HashMap)) {
data = new HashMap<>(data); // ensuring mutability
}
data.put(action.executionTimeField, WatcherDateTimeUtils.formatDate(ctx.executionTime()));
data.put(action.executionTimeField, DateTimeUtils.formatDate(ctx.executionTime()));
} else {
indexRequest.timestamp(WatcherDateTimeUtils.formatDate(ctx.executionTime()));
indexRequest.timestamp(DateTimeUtils.formatDate(ctx.executionTime()));
}
indexRequest.source(jsonBuilder().prettyPrint().map(data));
@ -104,9 +104,9 @@ public class ExecutableIndexAction extends ExecutableAction<IndexAction> {
if (!(doc instanceof HashMap)) {
doc = new HashMap<>(doc); // ensuring mutability
}
doc.put(action.executionTimeField, WatcherDateTimeUtils.formatDate(ctx.executionTime()));
doc.put(action.executionTimeField, DateTimeUtils.formatDate(ctx.executionTime()));
} else {
indexRequest.timestamp(WatcherDateTimeUtils.formatDate(ctx.executionTime()));
indexRequest.timestamp(DateTimeUtils.formatDate(ctx.executionTime()));
}
indexRequest.source(jsonBuilder().prettyPrint().map(doc));
bulkRequest.add(indexRequest);

View File

@ -13,7 +13,7 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.watcher.actions.Action;
import org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils;
import org.elasticsearch.xpack.support.DateTimeUtils;
import org.elasticsearch.xpack.watcher.support.xcontent.XContentSource;
import org.joda.time.DateTimeZone;
@ -129,7 +129,7 @@ public class IndexAction implements Action {
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.EXECUTION_TIME_FIELD)) {
executionTimeField = parser.text();
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.TIMEOUT)) {
timeout = WatcherDateTimeUtils.parseTimeValue(parser, Field.TIMEOUT.toString());
timeout = DateTimeUtils.parseTimeValue(parser, Field.TIMEOUT.toString());
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.DYNAMIC_NAME_TIMEZONE)) {
if (token == XContentParser.Token.VALUE_STRING) {
dynamicNameTimeZone = DateTimeZone.forID(parser.text());

View File

@ -9,7 +9,7 @@ import org.elasticsearch.xpack.watcher.actions.ActionStatus;
import org.elasticsearch.xpack.watcher.actions.ActionStatus.AckStatus;
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
import static org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils.formatDate;
import static org.elasticsearch.xpack.support.DateTimeUtils.formatDate;
/**
*

View File

@ -19,10 +19,10 @@ import org.elasticsearch.xpack.watcher.condition.Condition;
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
import org.elasticsearch.xpack.watcher.input.Input;
import org.elasticsearch.xpack.watcher.input.none.NoneInput;
import org.elasticsearch.xpack.watcher.support.Exceptions;
import org.elasticsearch.xpack.support.Exceptions;
import org.elasticsearch.xpack.watcher.support.xcontent.XContentSource;
import org.elasticsearch.xpack.watcher.transform.Transform;
import org.elasticsearch.xpack.watcher.trigger.Trigger;
import org.elasticsearch.xpack.trigger.Trigger;
import org.elasticsearch.xpack.watcher.watch.Watch;
import java.io.IOException;

View File

@ -10,7 +10,7 @@ import org.elasticsearch.xpack.watcher.condition.Condition;
import org.elasticsearch.xpack.watcher.condition.ExecutableCondition;
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
import org.elasticsearch.xpack.watcher.support.Variables;
import org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils;
import org.elasticsearch.xpack.support.DateTimeUtils;
import org.elasticsearch.xpack.support.clock.Clock;
import org.elasticsearch.xpack.watcher.support.xcontent.ObjectPath;
import org.joda.time.DateTime;
@ -55,8 +55,8 @@ public abstract class AbstractExecutableCompareCondition<C extends Condition, R
Matcher matcher = DATE_MATH_PATTERN.matcher((String) configuredValue);
if (matcher.matches()) {
String dateMath = matcher.group(1);
configuredValue = WatcherDateTimeUtils.parseDateMath(dateMath, DateTimeZone.UTC, clock);
resolvedValues.put(dateMath, WatcherDateTimeUtils.formatDate((DateTime) configuredValue));
configuredValue = DateTimeUtils.parseDateMath(dateMath, DateTimeZone.UTC, clock);
resolvedValues.put(dateMath, DateTimeUtils.formatDate((DateTime) configuredValue));
} else {
// checking if the given value is a path expression
matcher = PATH_PATTERN.matcher((String) configuredValue);

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.watcher.condition.compare;
import org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils;
import org.elasticsearch.xpack.support.DateTimeUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@ -55,7 +55,7 @@ public class LenientCompare {
}
if (v1 instanceof String) {
try {
v1 = WatcherDateTimeUtils.parseDate((String) v1);
v1 = DateTimeUtils.parseDate((String) v1);
} catch (Exception e) {
return null;
}

View File

@ -15,7 +15,7 @@ import org.elasticsearch.xpack.common.ScriptServiceProxy;
import java.util.Map;
import static org.elasticsearch.xpack.watcher.support.Exceptions.invalidScript;
import static org.elasticsearch.xpack.support.Exceptions.invalidScript;
/**
* This class executes a script against the ctx payload and returns a boolean

View File

@ -7,7 +7,7 @@ package org.elasticsearch.xpack.watcher.execution;
import java.util.Locale;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalArgument;
import static org.elasticsearch.xpack.support.Exceptions.illegalArgument;
/**
*

View File

@ -9,9 +9,9 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.watcher.trigger.TriggerEngine;
import org.elasticsearch.xpack.watcher.trigger.TriggerEvent;
import org.elasticsearch.xpack.watcher.trigger.TriggerService;
import org.elasticsearch.xpack.trigger.TriggerEngine;
import org.elasticsearch.xpack.trigger.TriggerEvent;
import org.elasticsearch.xpack.trigger.TriggerService;
import java.util.stream.StreamSupport;

View File

@ -14,7 +14,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalState;
import static org.elasticsearch.xpack.support.Exceptions.illegalState;
public class CurrentExecutions implements Iterable<ExecutionService.WatchExecution> {

View File

@ -6,7 +6,7 @@
package org.elasticsearch.xpack.watcher.execution;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.xpack.watcher.trigger.TriggerEngine;
import org.elasticsearch.xpack.trigger.TriggerEngine;
/**
*/

View File

@ -21,7 +21,7 @@ import org.elasticsearch.xpack.watcher.input.Input;
import org.elasticsearch.xpack.support.clock.Clock;
import org.elasticsearch.xpack.watcher.support.validation.WatcherSettingsValidation;
import org.elasticsearch.xpack.watcher.transform.Transform;
import org.elasticsearch.xpack.watcher.trigger.TriggerEvent;
import org.elasticsearch.xpack.trigger.TriggerEvent;
import org.elasticsearch.xpack.watcher.watch.Watch;
import org.elasticsearch.xpack.watcher.watch.WatchLockService;
import org.elasticsearch.xpack.watcher.watch.WatchStore;

View File

@ -10,7 +10,7 @@ import org.elasticsearch.xpack.watcher.actions.Action;
import org.elasticsearch.xpack.watcher.actions.ActionWrapper;
import org.elasticsearch.xpack.watcher.condition.Condition;
import org.elasticsearch.xpack.watcher.input.Input;
import org.elasticsearch.xpack.watcher.trigger.manual.ManualTriggerEvent;
import org.elasticsearch.xpack.trigger.manual.ManualTriggerEvent;
import org.elasticsearch.xpack.watcher.watch.Watch;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;

View File

@ -9,9 +9,9 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.watcher.trigger.TriggerEngine;
import org.elasticsearch.xpack.watcher.trigger.TriggerEvent;
import org.elasticsearch.xpack.watcher.trigger.TriggerService;
import org.elasticsearch.xpack.trigger.TriggerEngine;
import org.elasticsearch.xpack.trigger.TriggerEvent;
import org.elasticsearch.xpack.trigger.TriggerService;
import java.util.stream.StreamSupport;

View File

@ -6,7 +6,7 @@
package org.elasticsearch.xpack.watcher.execution;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.xpack.watcher.trigger.TriggerEvent;
import org.elasticsearch.xpack.trigger.TriggerEvent;
import org.elasticsearch.xpack.watcher.watch.Watch;
import org.joda.time.DateTime;

View File

@ -16,8 +16,8 @@ import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.watcher.trigger.TriggerEvent;
import org.elasticsearch.xpack.watcher.trigger.TriggerService;
import org.elasticsearch.xpack.trigger.TriggerEvent;
import org.elasticsearch.xpack.trigger.TriggerService;
import java.io.IOException;

View File

@ -38,8 +38,8 @@ import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import static org.elasticsearch.xpack.watcher.support.Exceptions.illegalState;
import static org.elasticsearch.xpack.watcher.support.Exceptions.ioException;
import static org.elasticsearch.xpack.support.Exceptions.illegalState;
import static org.elasticsearch.xpack.support.Exceptions.ioException;
public class TriggeredWatchStore extends AbstractComponent {

View File

@ -13,7 +13,7 @@ import org.elasticsearch.xpack.watcher.condition.Condition;
import org.elasticsearch.xpack.watcher.history.WatchRecord;
import org.elasticsearch.xpack.watcher.input.Input;
import org.elasticsearch.xpack.watcher.transform.Transform;
import org.elasticsearch.xpack.watcher.trigger.TriggerEvent;
import org.elasticsearch.xpack.trigger.TriggerEvent;
import org.elasticsearch.xpack.watcher.watch.Payload;
import org.elasticsearch.xpack.watcher.watch.Watch;
import org.joda.time.DateTime;

View File

@ -12,7 +12,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.xpack.watcher.actions.ExecutableActions;
import org.elasticsearch.xpack.watcher.condition.Condition;
import org.elasticsearch.xpack.watcher.input.Input;
import org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils;
import org.elasticsearch.xpack.support.DateTimeUtils;
import org.elasticsearch.xpack.watcher.transform.Transform;
import org.joda.time.DateTime;
@ -73,7 +73,7 @@ public class WatchExecutionResult implements ToXContent {
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
WatcherDateTimeUtils.writeDate(Field.EXECUTION_TIME.getPreferredName(), builder, executionTime);
DateTimeUtils.writeDate(Field.EXECUTION_TIME.getPreferredName(), builder, executionTime);
builder.field(Field.EXECUTION_DURATION.getPreferredName(), executionDurationMs);
if (inputResult != null) {

Some files were not shown because too many files have changed in this diff Show More