Merge branch 'master' into cli-parsing
Original commit: elastic/x-pack-elasticsearch@bfe0cdc477
This commit is contained in:
commit
64419c0856
|
@ -34,7 +34,7 @@ import org.elasticsearch.watcher.input.search.SearchInput;
|
|||
import org.elasticsearch.watcher.input.search.SearchInputFactory;
|
||||
import org.elasticsearch.watcher.input.simple.ExecutableSimpleInput;
|
||||
import org.elasticsearch.watcher.input.simple.SimpleInput;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
import org.elasticsearch.watcher.support.text.TextTemplate;
|
||||
import org.elasticsearch.watcher.trigger.schedule.IntervalSchedule;
|
||||
import org.elasticsearch.watcher.trigger.schedule.ScheduleTrigger;
|
||||
|
@ -132,7 +132,7 @@ public class SearchInputIT extends ESIntegTestCase {
|
|||
.source(searchSourceBuilder);
|
||||
|
||||
ExecutableSearchInput searchInput = new ExecutableSearchInput(new SearchInput(request, null, null, null), logger,
|
||||
ClientProxy.of(client()), null);
|
||||
WatcherClientProxy.of(client()), null);
|
||||
WatchExecutionContext ctx = new TriggeredExecutionContext(
|
||||
new Watch("test-watch",
|
||||
new ScheduleTrigger(new IntervalSchedule(new IntervalSchedule.Interval(1, IntervalSchedule.Interval.Unit.MINUTES))),
|
||||
|
@ -244,7 +244,7 @@ public class SearchInputIT extends ESIntegTestCase {
|
|||
.source(searchSourceBuilder);
|
||||
|
||||
ExecutableSearchInput searchInput = new ExecutableSearchInput(new SearchInput(request, null, null, null), logger,
|
||||
ClientProxy.of(client()), null);
|
||||
WatcherClientProxy.of(client()), null);
|
||||
WatchExecutionContext ctx = new TriggeredExecutionContext(
|
||||
new Watch("test-watch",
|
||||
new ScheduleTrigger(new IntervalSchedule(new IntervalSchedule.Interval(1, IntervalSchedule.Interval.Unit.MINUTES))),
|
||||
|
@ -281,7 +281,7 @@ public class SearchInputIT extends ESIntegTestCase {
|
|||
parser.nextToken();
|
||||
|
||||
IndicesQueriesRegistry indicesQueryRegistry = internalCluster().getInstance(IndicesQueriesRegistry.class);
|
||||
SearchInputFactory factory = new SearchInputFactory(Settings.EMPTY, ClientProxy.of(client()), indicesQueryRegistry, null);
|
||||
SearchInputFactory factory = new SearchInputFactory(Settings.EMPTY, WatcherClientProxy.of(client()), indicesQueryRegistry, null);
|
||||
|
||||
SearchInput searchInput = factory.parseInput("_id", parser);
|
||||
assertEquals(SearchInput.TYPE, searchInput.type());
|
||||
|
@ -311,7 +311,7 @@ public class SearchInputIT extends ESIntegTestCase {
|
|||
|
||||
SearchInput si = siBuilder.build();
|
||||
|
||||
ExecutableSearchInput searchInput = new ExecutableSearchInput(si, logger, ClientProxy.of(client()), null);
|
||||
ExecutableSearchInput searchInput = new ExecutableSearchInput(si, logger, WatcherClientProxy.of(client()), null);
|
||||
return searchInput.execute(ctx, new Payload.Simple());
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.elasticsearch.watcher.execution.TriggeredExecutionContext;
|
|||
import org.elasticsearch.watcher.execution.WatchExecutionContext;
|
||||
import org.elasticsearch.watcher.input.simple.ExecutableSimpleInput;
|
||||
import org.elasticsearch.watcher.input.simple.SimpleInput;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
import org.elasticsearch.watcher.support.text.TextTemplate;
|
||||
import org.elasticsearch.watcher.transform.Transform;
|
||||
import org.elasticsearch.watcher.transform.TransformBuilders;
|
||||
|
@ -154,7 +154,7 @@ public class SearchTransformIT extends ESIntegTestCase {
|
|||
|
||||
SearchRequest request = Requests.searchRequest("idx").source(new SearchSourceBuilder().query(QueryBuilders.matchAllQuery()));
|
||||
SearchTransform searchTransform = TransformBuilders.searchTransform(request).build();
|
||||
ExecutableSearchTransform transform = new ExecutableSearchTransform(searchTransform, logger, ClientProxy.of(client()), null);
|
||||
ExecutableSearchTransform transform = new ExecutableSearchTransform(searchTransform, logger, WatcherClientProxy.of(client()), null);
|
||||
|
||||
WatchExecutionContext ctx = mockExecutionContext("_name", EMPTY_PAYLOAD);
|
||||
|
||||
|
@ -188,7 +188,7 @@ public class SearchTransformIT extends ESIntegTestCase {
|
|||
new SearchSourceBuilder().query(QueryBuilders.wrapperQuery(jsonBuilder().startObject()
|
||||
.startObject("_unknown_query_").endObject().endObject().bytes())));
|
||||
SearchTransform searchTransform = TransformBuilders.searchTransform(request).build();
|
||||
ExecutableSearchTransform transform = new ExecutableSearchTransform(searchTransform, logger, ClientProxy.of(client()), null);
|
||||
ExecutableSearchTransform transform = new ExecutableSearchTransform(searchTransform, logger, WatcherClientProxy.of(client()), null);
|
||||
|
||||
WatchExecutionContext ctx = mockExecutionContext("_name", EMPTY_PAYLOAD);
|
||||
|
||||
|
@ -252,7 +252,7 @@ public class SearchTransformIT extends ESIntegTestCase {
|
|||
.must(termQuery("value", "{{ctx.payload.value}}"))));
|
||||
|
||||
SearchTransform searchTransform = TransformBuilders.searchTransform(request).build();
|
||||
ExecutableSearchTransform transform = new ExecutableSearchTransform(searchTransform, logger, ClientProxy.of(client()), null);
|
||||
ExecutableSearchTransform transform = new ExecutableSearchTransform(searchTransform, logger, WatcherClientProxy.of(client()), null);
|
||||
|
||||
ScheduleTriggerEvent event = new ScheduleTriggerEvent("_name", parseDate("2015-01-04T00:00:00", UTC),
|
||||
parseDate("2015-01-01T00:00:00", UTC));
|
||||
|
@ -318,7 +318,7 @@ public class SearchTransformIT extends ESIntegTestCase {
|
|||
parser.nextToken();
|
||||
|
||||
IndicesQueriesRegistry indicesQueryRegistry = internalCluster().getInstance(IndicesQueriesRegistry.class);
|
||||
SearchTransformFactory transformFactory = new SearchTransformFactory(Settings.EMPTY, ClientProxy.of(client()),
|
||||
SearchTransformFactory transformFactory = new SearchTransformFactory(Settings.EMPTY, WatcherClientProxy.of(client()),
|
||||
indicesQueryRegistry,
|
||||
null);
|
||||
ExecutableSearchTransform executable = transformFactory.parseExecutable("_id", parser);
|
||||
|
@ -482,7 +482,7 @@ public class SearchTransformIT extends ESIntegTestCase {
|
|||
|
||||
SearchTransform searchTransform = TransformBuilders.searchTransform(request).build();
|
||||
ExecutableSearchTransform executableSearchTransform = new ExecutableSearchTransform(searchTransform, logger,
|
||||
ClientProxy.of(client()), null);
|
||||
WatcherClientProxy.of(client()), null);
|
||||
|
||||
return executableSearchTransform.execute(ctx, Payload.Simple.EMPTY);
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@ integTest {
|
|||
'indices.shard_stores/10_basic/no indices test',
|
||||
'cat.nodeattrs/10_basic/Test cat nodes attrs output',
|
||||
'bulk/40_fields/Fields',
|
||||
'indices.get_alias/10_basic/Get alias against closed indices'].join(',')
|
||||
'indices.get_alias/10_basic/Get alias against closed indices',
|
||||
'ingest/10_crud/Check availability of default processors'].join(',')
|
||||
|
||||
cluster {
|
||||
plugin 'x-pack', project(':x-plugins:elasticsearch:x-pack')
|
||||
|
|
|
@ -292,7 +292,8 @@ public class HttpExporterTests extends MarvelIntegTestCase {
|
|||
logger.info("--> starting node");
|
||||
|
||||
// returning an unsupported cluster version
|
||||
enqueueGetClusterVersionResponse(randomFrom(Version.V_0_18_0, Version.V_1_0_0, Version.V_1_4_0));
|
||||
enqueueGetClusterVersionResponse(randomFrom(Version.fromString("0.18.0"), Version.fromString("1.0.0"),
|
||||
Version.fromString("1.4.0")));
|
||||
|
||||
String agentNode = internalCluster().startNode(builder);
|
||||
|
||||
|
@ -431,8 +432,8 @@ public class HttpExporterTests extends MarvelIntegTestCase {
|
|||
Version resolved = exporter.loadRemoteClusterVersion(host);
|
||||
assertTrue(resolved.equals(Version.CURRENT));
|
||||
|
||||
final Version expected = randomFrom(Version.CURRENT, Version.V_0_18_0, Version.V_1_1_0, Version.V_1_2_4,
|
||||
Version.V_1_4_5, Version.V_1_6_0);
|
||||
final Version expected = randomFrom(Version.CURRENT, Version.V_2_0_0_beta1, Version.V_2_0_0_beta2, Version.V_2_0_0_rc1,
|
||||
Version.V_2_0_0, Version.V_2_1_0, Version.V_2_2_0, Version.V_2_3_0);
|
||||
enqueueGetClusterVersionResponse(expected);
|
||||
resolved = exporter.loadRemoteClusterVersion(host);
|
||||
assertTrue(resolved.equals(expected));
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.elasticsearch.index.fielddata.FieldDataStats;
|
|||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.index.shard.ShardPath;
|
||||
import org.elasticsearch.indices.NodeIndicesStats;
|
||||
import org.elasticsearch.ingest.core.IngestInfo;
|
||||
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStatsMonitoringDoc;
|
||||
import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils;
|
||||
import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolverTestCase;
|
||||
|
@ -112,7 +113,7 @@ public class ClusterStatsResolverTests extends MonitoringIndexNameResolverTestCa
|
|||
Settings.EMPTY, DummyOsInfo.INSTANCE, new ProcessInfo(randomInt(), randomBoolean()), JvmInfo.jvmInfo(),
|
||||
new ThreadPoolInfo(Collections.singletonList(new ThreadPool.Info("test_threadpool", ThreadPool.ThreadPoolType.FIXED, 5))),
|
||||
new TransportInfo(transportAddress, Collections.emptyMap()), new HttpInfo(transportAddress, randomLong()),
|
||||
new PluginsAndModules());
|
||||
new PluginsAndModules(), new IngestInfo());
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,9 @@ import static org.hamcrest.Matchers.equalTo;
|
|||
public class VersionUtilsTests extends ESTestCase {
|
||||
|
||||
public void testParseVersion() {
|
||||
List<Version> versions = randomSubsetOf(9, Version.V_0_18_0, Version.V_0_19_0, Version.V_1_0_1, Version.V_1_2_3, Version.V_1_3_2,
|
||||
Version.V_1_4_5, Version.V_1_6_2, Version.V_1_7_2, Version.V_2_0_0);
|
||||
List<Version> versions = randomSubsetOf(9, Version.V_2_0_0_beta1, Version.V_2_0_0_beta2, Version.V_2_0_0_rc1, Version.V_2_0_0,
|
||||
Version.V_2_0_1, Version.V_2_0_2, Version.V_2_1_0, Version.V_2_1_1, Version.V_2_1_2, Version.V_2_2_0, Version.V_2_3_0,
|
||||
Version.V_5_0_0);
|
||||
for (Version version : versions) {
|
||||
String output = createOutput(VersionUtils.VERSION_NUMBER_FIELD, version.toString());
|
||||
assertThat(VersionUtils.parseVersion(output.getBytes(StandardCharsets.UTF_8)), equalTo(version));
|
||||
|
|
|
@ -125,6 +125,14 @@ export HOSTNAME=`hostname -s`
|
|||
# include shield jars in classpath
|
||||
ES_CLASSPATH="$ES_CLASSPATH:$ES_HOME/plugins/xpack/*"
|
||||
|
||||
# don't let JAVA_TOOL_OPTIONS slip in (e.g. crazy agents in ubuntu)
|
||||
# works around https://bugs.launchpad.net/ubuntu/+source/jayatana/+bug/1441487
|
||||
if [ "x$JAVA_TOOL_OPTIONS" != "x" ]; then
|
||||
echo "Warning: Ignoring JAVA_TOOL_OPTIONS=$JAVA_TOOL_OPTIONS"
|
||||
echo "Please pass JVM parameters via ES_JAVA_OPTS instead"
|
||||
unset JAVA_TOOL_OPTIONS
|
||||
fi
|
||||
|
||||
cd "$ES_HOME" > /dev/null
|
||||
"$JAVA" $ES_JAVA_OPTS -cp "$ES_CLASSPATH" -Des.path.home="$ES_HOME" $properties org.elasticsearch.shield.authc.esusers.tool.ESUsersTool "$@"
|
||||
status=$?
|
||||
|
|
|
@ -125,8 +125,16 @@ export HOSTNAME=`hostname -s`
|
|||
# include shield jars in classpath
|
||||
ES_CLASSPATH="$ES_CLASSPATH:$ES_HOME/plugins/xpack/*"
|
||||
|
||||
# don't let JAVA_TOOL_OPTIONS slip in (e.g. crazy agents in ubuntu)
|
||||
# works around https://bugs.launchpad.net/ubuntu/+source/jayatana/+bug/1441487
|
||||
if [ "x$JAVA_TOOL_OPTIONS" != "x" ]; then
|
||||
echo "Warning: Ignoring JAVA_TOOL_OPTIONS=$JAVA_TOOL_OPTIONS"
|
||||
echo "Please pass JVM parameters via ES_JAVA_OPTS instead"
|
||||
unset JAVA_TOOL_OPTIONS
|
||||
fi
|
||||
|
||||
cd "$ES_HOME" > /dev/null
|
||||
$JAVA $ES_JAVA_OPTS -cp "$ES_CLASSPATH" -Des.path.home="$ES_HOME" $properties org.elasticsearch.shield.crypto.tool.SystemKeyTool "$@"
|
||||
"$JAVA" $ES_JAVA_OPTS -cp "$ES_CLASSPATH" -Des.path.home="$ES_HOME" $properties org.elasticsearch.shield.crypto.tool.SystemKeyTool "$@"
|
||||
status=$?
|
||||
cd - > /dev/null
|
||||
exit $status
|
||||
|
|
|
@ -325,6 +325,7 @@ public class Shield {
|
|||
return;
|
||||
}
|
||||
|
||||
final Map<String, String> settingsMap = settings.getAsMap();
|
||||
for (Map.Entry<String, Settings> tribeSettings : tribesSettings.entrySet()) {
|
||||
String tribePrefix = "tribe." + tribeSettings.getKey() + ".";
|
||||
|
||||
|
@ -352,6 +353,14 @@ public class Shield {
|
|||
//shield must be enabled on every tribe if it's enabled on the tribe node
|
||||
settingsBuilder.put(tribeEnabledSetting, true);
|
||||
}
|
||||
|
||||
// we passed all the checks now we need to copy in all of the shield settings
|
||||
for (Map.Entry<String, String> entry : settingsMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
if (key.startsWith("shield.")) {
|
||||
settingsBuilder.put(tribePrefix + key, entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,13 +5,16 @@
|
|||
*/
|
||||
package org.elasticsearch.shield;
|
||||
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.XPackPlugin;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.Matchers.arrayContaining;
|
||||
|
||||
public class ShieldPluginSettingsTests extends ESTestCase {
|
||||
|
@ -106,4 +109,27 @@ public class ShieldPluginSettingsTests extends ESTestCase {
|
|||
assertThat(e.getMessage(), containsString(TRIBE_T1_SHIELD_ENABLED));
|
||||
}
|
||||
}
|
||||
|
||||
public void testShieldSettingsCopiedForTribeNodes() {
|
||||
Settings settings = Settings.builder()
|
||||
.put("tribe.t1.cluster.name", "non_existing")
|
||||
.put("tribe.t2.cluster.name", "non_existing")
|
||||
.put("shield.foo", "bar")
|
||||
.put("shield.bar", "foo")
|
||||
.putArray("shield.something.else.here", new String[] { "foo", "bar" })
|
||||
.build();
|
||||
|
||||
Shield shield = new Shield(settings);
|
||||
Settings additionalSettings = shield.additionalSettings();
|
||||
|
||||
assertThat(additionalSettings.get("shield.foo"), nullValue());
|
||||
assertThat(additionalSettings.get("shield.bar"), nullValue());
|
||||
assertThat(additionalSettings.getAsArray("shield.something.else.here"), is(Strings.EMPTY_ARRAY));
|
||||
assertThat(additionalSettings.get("tribe.t1.shield.foo"), is("bar"));
|
||||
assertThat(additionalSettings.get("tribe.t1.shield.bar"), is("foo"));
|
||||
assertThat(additionalSettings.getAsArray("tribe.t1.shield.something.else.here"), arrayContaining("foo", "bar"));
|
||||
assertThat(additionalSettings.get("tribe.t2.shield.foo"), is("bar"));
|
||||
assertThat(additionalSettings.get("tribe.t2.shield.bar"), is("foo"));
|
||||
assertThat(additionalSettings.getAsArray("tribe.t2.shield.something.else.here"), arrayContaining("foo", "bar"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -207,7 +207,7 @@ public class DocumentSubsetReaderTests extends ESTestCase {
|
|||
iw.addDocument(doc);
|
||||
|
||||
// open reader
|
||||
DirectoryReader ir = DocumentSubsetReader.wrap(DirectoryReader.open(iw, true), bitsetFilterCache, new MatchAllDocsQuery());
|
||||
DirectoryReader ir = DocumentSubsetReader.wrap(DirectoryReader.open(iw), bitsetFilterCache, new MatchAllDocsQuery());
|
||||
assertEquals(2, ir.numDocs());
|
||||
assertEquals(1, ir.leaves().size());
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
|
||||
// open reader
|
||||
Set<String> fields = Collections.singleton("fieldA");
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only one field
|
||||
LeafReader segmentReader = ir.leaves().get(0).reader();
|
||||
|
@ -96,7 +96,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
|
||||
// open reader
|
||||
Set<String> fields = Collections.singleton("fieldA");
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only one field
|
||||
Document d2 = ir.document(0);
|
||||
|
@ -123,7 +123,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
|
||||
// open reader
|
||||
Set<String> fields = Collections.singleton("fieldA");
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only one field
|
||||
Document d2 = ir.document(0);
|
||||
|
@ -150,7 +150,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
|
||||
// open reader
|
||||
Set<String> fields = Collections.singleton("fieldA");
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only one field
|
||||
Document d2 = ir.document(0);
|
||||
|
@ -177,7 +177,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
|
||||
// open reader
|
||||
Set<String> fields = Collections.singleton("fieldA");
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only one field
|
||||
Document d2 = ir.document(0);
|
||||
|
@ -204,7 +204,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
|
||||
// open reader
|
||||
Set<String> fields = Collections.singleton("fieldA");
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only one field
|
||||
Document d2 = ir.document(0);
|
||||
|
@ -231,7 +231,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
|
||||
// open reader
|
||||
Set<String> fields = Collections.singleton("fieldA");
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only one field
|
||||
Document d2 = ir.document(0);
|
||||
|
@ -260,7 +260,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
|
||||
// open reader
|
||||
Set<String> fields = Collections.singleton("fieldA");
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only one field
|
||||
Fields vectors = ir.getTermVectors(0);
|
||||
|
@ -290,7 +290,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
|
||||
// open reader
|
||||
Set<String> fields = Collections.singleton("fieldA");
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only one field
|
||||
LeafReader segmentReader = ir.leaves().get(0).reader();
|
||||
|
@ -317,7 +317,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
|
||||
// open reader
|
||||
Set<String> fields = Collections.singleton("fieldA");
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only one field
|
||||
LeafReader segmentReader = ir.leaves().get(0).reader();
|
||||
|
@ -349,7 +349,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
|
||||
// open reader
|
||||
Set<String> fields = Collections.singleton("fieldA");
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only one field
|
||||
LeafReader segmentReader = ir.leaves().get(0).reader();
|
||||
|
@ -381,7 +381,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
|
||||
// open reader
|
||||
Set<String> fields = Collections.singleton("fieldA");
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only one field
|
||||
LeafReader segmentReader = ir.leaves().get(0).reader();
|
||||
|
@ -413,7 +413,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
|
||||
// open reader
|
||||
Set<String> fields = Collections.singleton("fieldA");
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only one field
|
||||
LeafReader segmentReader = ir.leaves().get(0).reader();
|
||||
|
@ -449,7 +449,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
|
||||
// open reader
|
||||
Set<String> fields = Collections.singleton("fieldA");
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only one field
|
||||
LeafReader segmentReader = ir.leaves().get(0).reader();
|
||||
|
@ -484,7 +484,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
|
||||
// open reader
|
||||
Set<String> fields = Collections.singleton("fieldA");
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only one field
|
||||
LeafReader segmentReader = ir.leaves().get(0).reader();
|
||||
|
@ -517,7 +517,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
Set<String> fields = new HashSet<>();
|
||||
fields.add("fieldA");
|
||||
fields.add(SourceFieldMapper.NAME);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only one field
|
||||
Document d2 = ir.document(0);
|
||||
|
@ -548,7 +548,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
Set<String> fields = new HashSet<>();
|
||||
fields.add("fieldA");
|
||||
fields.add(FieldNamesFieldMapper.NAME);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only one field
|
||||
LeafReader segmentReader = ir.leaves().get(0).reader();
|
||||
|
@ -597,7 +597,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
fields.add("fieldA");
|
||||
fields.add("fieldC");
|
||||
fields.add(FieldNamesFieldMapper.NAME);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only two fields
|
||||
LeafReader segmentReader = ir.leaves().get(0).reader();
|
||||
|
@ -645,7 +645,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
fields.add("fieldA");
|
||||
fields.add("fieldC");
|
||||
fields.add(FieldNamesFieldMapper.NAME);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only one field
|
||||
LeafReader segmentReader = ir.leaves().get(0).reader();
|
||||
|
@ -681,7 +681,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
Set<String> fields = new HashSet<>();
|
||||
fields.add("fieldA");
|
||||
fields.add(FieldNamesFieldMapper.NAME);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see only one field
|
||||
LeafReader segmentReader = ir.leaves().get(0).reader();
|
||||
|
@ -710,7 +710,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
|
||||
// open reader
|
||||
Set<String> fields = Collections.singleton("id");
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
assertEquals(2, ir.numDocs());
|
||||
assertEquals(1, ir.leaves().size());
|
||||
|
||||
|
@ -745,7 +745,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
|
||||
// open reader
|
||||
Set<String> fields = Collections.singleton("fieldB");
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// sees no fields
|
||||
assertNull(ir.getTermVectors(0));
|
||||
|
@ -765,7 +765,7 @@ public class FieldSubsetReaderTests extends ESTestCase {
|
|||
|
||||
// open reader
|
||||
Set<String> fields = Collections.singleton("fieldA");
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw, true), fields);
|
||||
DirectoryReader ir = FieldSubsetReader.wrap(DirectoryReader.open(iw), fields);
|
||||
|
||||
// see no fields
|
||||
LeafReader segmentReader = ir.leaves().get(0).reader();
|
||||
|
|
|
@ -22,6 +22,8 @@ import org.elasticsearch.plugins.Plugin;
|
|||
import org.elasticsearch.script.ScriptModule;
|
||||
import org.elasticsearch.shield.Shield;
|
||||
import org.elasticsearch.watcher.Watcher;
|
||||
import org.elasticsearch.xpack.common.init.LazyInitializationModule;
|
||||
import org.elasticsearch.xpack.common.init.LazyInitializationService;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.security.AccessController;
|
||||
|
@ -89,6 +91,7 @@ public class XPackPlugin extends Plugin {
|
|||
@Override
|
||||
public Collection<Module> nodeModules() {
|
||||
ArrayList<Module> modules = new ArrayList<>();
|
||||
modules.add(new LazyInitializationModule());
|
||||
modules.addAll(licensing.nodeModules());
|
||||
modules.addAll(shield.nodeModules());
|
||||
modules.addAll(watcher.nodeModules());
|
||||
|
@ -99,6 +102,10 @@ public class XPackPlugin extends Plugin {
|
|||
@Override
|
||||
public Collection<Class<? extends LifecycleComponent>> nodeServices() {
|
||||
ArrayList<Class<? extends LifecycleComponent>> services = new ArrayList<>();
|
||||
// the initialization service must be first in the list
|
||||
// as other services may depend on one of the initialized
|
||||
// constructs
|
||||
services.add(LazyInitializationService.class);
|
||||
services.addAll(licensing.nodeServices());
|
||||
services.addAll(shield.nodeServices());
|
||||
services.addAll(watcher.nodeServices());
|
||||
|
@ -145,6 +152,10 @@ public class XPackPlugin extends Plugin {
|
|||
shield.onIndexModule(module);
|
||||
}
|
||||
|
||||
public void onModule(LazyInitializationModule module) {
|
||||
watcher.onModule(module);
|
||||
}
|
||||
|
||||
public static boolean transportClientMode(Settings settings) {
|
||||
return !"node".equals(settings.get(Client.CLIENT_TYPE_SETTING_S.getKey()));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* 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.common.init;
|
||||
|
||||
import org.elasticsearch.common.inject.Injector;
|
||||
|
||||
public interface LazyInitializable {
|
||||
|
||||
/**
|
||||
* This method is called once all objects have been constructed and
|
||||
* the @{link LazyInitializationService} has been started.
|
||||
*/
|
||||
void init(Injector injector);
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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.common.init;
|
||||
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.multibindings.Multibinder;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A module to lazy initialize objects and avoid circular dependency injection issues.
|
||||
*
|
||||
* Objects that use the {@link org.elasticsearch.client.ElasticsearchClient} and that are also injected in transport actions provoke
|
||||
* a circular dependency injection issues with Guice. Using proxies with lazy initialization is a way to solve this issue.
|
||||
*
|
||||
* The proxies are initialized by {@link LazyInitializationService}.
|
||||
*/
|
||||
public class LazyInitializationModule extends AbstractModule {
|
||||
|
||||
private final Set<Class<? extends LazyInitializable>> initializables = new HashSet<>();
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
Multibinder<LazyInitializable> mbinder = Multibinder.newSetBinder(binder(), LazyInitializable.class);
|
||||
for (Class<? extends LazyInitializable> initializable : initializables) {
|
||||
bind(initializable).asEagerSingleton();
|
||||
mbinder.addBinding().to(initializable);
|
||||
}
|
||||
bind(LazyInitializationService.class).asEagerSingleton();
|
||||
}
|
||||
|
||||
public void registerLazyInitializable(Class<? extends LazyInitializable> lazyTypeClass) {
|
||||
initializables.add(lazyTypeClass);
|
||||
}
|
||||
}
|
|
@ -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.watcher.support.init;
|
||||
package org.elasticsearch.xpack.common.init;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
||||
|
@ -14,15 +14,15 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A service to lazy initialize {@link InitializingService.Initializable} constructs.
|
||||
* A service to lazy initialize {@link LazyInitializable} constructs.
|
||||
*/
|
||||
public class InitializingService extends AbstractLifecycleComponent {
|
||||
public class LazyInitializationService extends AbstractLifecycleComponent {
|
||||
|
||||
private final Injector injector;
|
||||
private final Set<Initializable> initializables;
|
||||
private final Set<LazyInitializable> initializables;
|
||||
|
||||
@Inject
|
||||
public InitializingService(Settings settings, Injector injector, Set<Initializable> initializables) {
|
||||
public LazyInitializationService(Settings settings, Injector injector, Set<LazyInitializable> initializables) {
|
||||
super(settings);
|
||||
this.injector = injector;
|
||||
this.initializables = initializables;
|
||||
|
@ -30,7 +30,8 @@ public class InitializingService extends AbstractLifecycleComponent {
|
|||
|
||||
@Override
|
||||
protected void doStart() throws ElasticsearchException {
|
||||
for (Initializable initializable : initializables) {
|
||||
for (LazyInitializable initializable : initializables) {
|
||||
logger.trace("lazy initialization of [{}]", initializable);
|
||||
initializable.init(injector);
|
||||
}
|
||||
}
|
||||
|
@ -42,9 +43,4 @@ public class InitializingService extends AbstractLifecycleComponent {
|
|||
@Override
|
||||
protected void doClose() throws ElasticsearchException {
|
||||
}
|
||||
|
||||
public interface Initializable {
|
||||
|
||||
void init(Injector injector);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* 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.common.init.proxy;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.bulk.BulkRequest;
|
||||
import org.elasticsearch.action.bulk.BulkResponse;
|
||||
import org.elasticsearch.client.AdminClient;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.inject.Injector;
|
||||
import org.elasticsearch.shield.InternalClient;
|
||||
import org.elasticsearch.transport.TransportMessage;
|
||||
import org.elasticsearch.xpack.common.init.LazyInitializable;
|
||||
|
||||
/**
|
||||
* A lazily initialized proxy to an elasticsearch {@link Client}. Inject this proxy whenever a client
|
||||
* needs to injected to be avoid circular dependencies issues.
|
||||
*/
|
||||
public class ClientProxy implements LazyInitializable {
|
||||
|
||||
protected InternalClient client;
|
||||
|
||||
@Override
|
||||
public void init(Injector injector) {
|
||||
this.client = injector.getInstance(InternalClient.class);
|
||||
}
|
||||
|
||||
public AdminClient admin() {
|
||||
return client.admin();
|
||||
}
|
||||
|
||||
public void bulk(BulkRequest request, ActionListener<BulkResponse> listener) {
|
||||
client.bulk(preProcess(request), listener);
|
||||
}
|
||||
|
||||
protected <M extends TransportMessage> M preProcess(M message) {
|
||||
return message;
|
||||
}
|
||||
}
|
|
@ -116,8 +116,16 @@ export HOSTNAME=`hostname -s`
|
|||
# include watcher jars in classpath
|
||||
ES_CLASSPATH="$ES_CLASSPATH:$ES_HOME/plugins/xpack/*"
|
||||
|
||||
# don't let JAVA_TOOL_OPTIONS slip in (e.g. crazy agents in ubuntu)
|
||||
# works around https://bugs.launchpad.net/ubuntu/+source/jayatana/+bug/1441487
|
||||
if [ "x$JAVA_TOOL_OPTIONS" != "x" ]; then
|
||||
echo "Warning: Ignoring JAVA_TOOL_OPTIONS=$JAVA_TOOL_OPTIONS"
|
||||
echo "Please pass JVM parameters via ES_JAVA_OPTS instead"
|
||||
unset JAVA_TOOL_OPTIONS
|
||||
fi
|
||||
|
||||
cd "$ES_HOME" > /dev/null
|
||||
$JAVA $ES_JAVA_OPTS -cp "$ES_CLASSPATH" org.elasticsearch.watcher.trigger.schedule.tool.CronEvalTool "$@" $properties
|
||||
"$JAVA" $ES_JAVA_OPTS -cp "$ES_CLASSPATH" -Des.path.home="$ES_HOME" org.elasticsearch.watcher.trigger.schedule.tool.CronEvalTool "$@" $properties
|
||||
status=$?
|
||||
cd - > /dev/null
|
||||
exit $status
|
||||
exit $status
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.elasticsearch.watcher.execution.ExecutionModule;
|
|||
import org.elasticsearch.watcher.history.HistoryModule;
|
||||
import org.elasticsearch.watcher.history.HistoryStore;
|
||||
import org.elasticsearch.watcher.input.InputModule;
|
||||
import org.elasticsearch.watcher.input.chain.ChainInputFactory;
|
||||
import org.elasticsearch.watcher.license.LicenseModule;
|
||||
import org.elasticsearch.watcher.license.WatcherLicensee;
|
||||
import org.elasticsearch.watcher.rest.action.RestAckWatchAction;
|
||||
|
@ -54,14 +55,14 @@ import org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry.TemplateCo
|
|||
import org.elasticsearch.watcher.support.clock.ClockModule;
|
||||
import org.elasticsearch.watcher.support.http.HttpClient;
|
||||
import org.elasticsearch.watcher.support.http.HttpClientModule;
|
||||
import org.elasticsearch.watcher.support.init.InitializingModule;
|
||||
import org.elasticsearch.watcher.support.init.InitializingService;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
import org.elasticsearch.watcher.support.secret.SecretModule;
|
||||
import org.elasticsearch.watcher.support.secret.SecretService;
|
||||
import org.elasticsearch.watcher.support.text.TextTemplateModule;
|
||||
import org.elasticsearch.watcher.support.validation.WatcherSettingsValidation;
|
||||
import org.elasticsearch.watcher.transform.TransformModule;
|
||||
import org.elasticsearch.watcher.transform.chain.ChainTransformFactory;
|
||||
import org.elasticsearch.watcher.transport.actions.ack.AckWatchAction;
|
||||
import org.elasticsearch.watcher.transport.actions.ack.TransportAckWatchAction;
|
||||
import org.elasticsearch.watcher.transport.actions.activate.ActivateWatchAction;
|
||||
|
@ -82,6 +83,7 @@ import org.elasticsearch.watcher.trigger.TriggerModule;
|
|||
import org.elasticsearch.watcher.trigger.schedule.ScheduleModule;
|
||||
import org.elasticsearch.watcher.watch.WatchModule;
|
||||
import org.elasticsearch.xpack.XPackPlugin;
|
||||
import org.elasticsearch.xpack.common.init.LazyInitializationModule;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
|
@ -133,7 +135,6 @@ public class Watcher {
|
|||
}
|
||||
return Arrays.<Module>asList(
|
||||
new WatcherModule(settings),
|
||||
new InitializingModule(),
|
||||
new LicenseModule(),
|
||||
new WatchModule(),
|
||||
new TextTemplateModule(),
|
||||
|
@ -156,10 +157,6 @@ public class Watcher {
|
|||
return Collections.emptyList();
|
||||
}
|
||||
return Arrays.<Class<? extends LifecycleComponent>>asList(
|
||||
// the initialization service must be first in the list
|
||||
// as other services may depend on one of the initialized
|
||||
// constructs
|
||||
InitializingService.class,
|
||||
WatcherLicensee.class,
|
||||
EmailService.class,
|
||||
HipChatService.class,
|
||||
|
@ -254,6 +251,15 @@ public class Watcher {
|
|||
}
|
||||
}
|
||||
|
||||
public void onModule(LazyInitializationModule module) {
|
||||
if (enabled) {
|
||||
module.registerLazyInitializable(WatcherClientProxy.class);
|
||||
module.registerLazyInitializable(ScriptServiceProxy.class);
|
||||
module.registerLazyInitializable(ChainTransformFactory.class);
|
||||
module.registerLazyInitializable(ChainInputFactory.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean enabled(Settings settings) {
|
||||
return XPackPlugin.featureEnabled(settings, NAME, true);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public enum DataAttachment implements ToXContent {
|
|||
|
||||
@Override
|
||||
public Attachment create(String id, Map<String, Object> data) {
|
||||
return new Attachment.XContent.Yaml(id, "data.yml", new Payload.Simple(data));
|
||||
return new Attachment.XContent.Yaml(id, id, new Payload.Simple(data));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,7 +51,7 @@ public enum DataAttachment implements ToXContent {
|
|||
|
||||
@Override
|
||||
public Attachment create(String id, Map<String, Object> data) {
|
||||
return new Attachment.XContent.Json(id, "data.json", new Payload.Simple(data));
|
||||
return new Attachment.XContent.Json(id, id, new Payload.Simple(data));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,7 +32,6 @@ public class DataAttachment implements EmailAttachmentParser.EmailAttachment {
|
|||
} else {
|
||||
builder.field("format", "json");
|
||||
}
|
||||
|
||||
return builder.endObject().endObject();
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,11 @@ public interface EmailAttachmentParser<T extends EmailAttachmentParser.EmailAtta
|
|||
* @return A type to identify the email attachment, same as the parser identifier
|
||||
*/
|
||||
String type();
|
||||
|
||||
/**
|
||||
* @return The id of this attachment
|
||||
*/
|
||||
String id();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,8 +10,8 @@ import org.elasticsearch.common.xcontent.ToXContent;
|
|||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class EmailAttachments implements ToXContent {
|
||||
|
@ -23,13 +23,13 @@ public class EmailAttachments implements ToXContent {
|
|||
ParseField ATTACHMENTS = new ParseField("attachments");
|
||||
}
|
||||
|
||||
private final List<EmailAttachmentParser.EmailAttachment> attachments;
|
||||
private final Collection<EmailAttachmentParser.EmailAttachment> attachments;
|
||||
|
||||
public EmailAttachments(List<EmailAttachmentParser.EmailAttachment> attachments) {
|
||||
public EmailAttachments(Collection<EmailAttachmentParser.EmailAttachment> attachments) {
|
||||
this.attachments = attachments;
|
||||
}
|
||||
|
||||
public List<EmailAttachmentParser.EmailAttachment> getAttachments() {
|
||||
public Collection<EmailAttachmentParser.EmailAttachment> getAttachments() {
|
||||
return attachments;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class EmailAttachmentsParser {
|
||||
|
@ -25,7 +25,7 @@ public class EmailAttachmentsParser {
|
|||
}
|
||||
|
||||
public EmailAttachments parse(XContentParser parser) throws IOException {
|
||||
List<EmailAttachmentParser.EmailAttachment> attachments = new ArrayList<>();
|
||||
Map<String, EmailAttachmentParser.EmailAttachment> attachments = new LinkedHashMap<>();
|
||||
String currentFieldName = null;
|
||||
XContentParser.Token token;
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
|
@ -41,17 +41,21 @@ public class EmailAttachmentsParser {
|
|||
|
||||
EmailAttachmentParser emailAttachmentParser = parsers.get(currentAttachmentType);
|
||||
if (emailAttachmentParser == null) {
|
||||
throw new ElasticsearchParseException("Cannot parse attachment of type " + currentAttachmentType);
|
||||
throw new ElasticsearchParseException("Cannot parse attachment of type [{}]", currentAttachmentType);
|
||||
}
|
||||
EmailAttachmentParser.EmailAttachment emailAttachment = emailAttachmentParser.parse(currentFieldName, parser);
|
||||
attachments.add(emailAttachment);
|
||||
if (attachments.containsKey(emailAttachment.id())) {
|
||||
throw new ElasticsearchParseException("Attachment with id [{}] has already been created, must be renamed",
|
||||
emailAttachment.id());
|
||||
}
|
||||
attachments.put(emailAttachment.id(), emailAttachment);
|
||||
// one further to skip the end_object from the attachment
|
||||
parser.nextToken();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new EmailAttachments(attachments);
|
||||
return new EmailAttachments(new ArrayList<>(attachments.values()));
|
||||
}
|
||||
|
||||
public Map<String, EmailAttachmentParser> getParsers() {
|
||||
|
|
|
@ -94,7 +94,7 @@ public class HttpEmailAttachementParser implements EmailAttachmentParser<HttpReq
|
|||
if (response.hasContent()) {
|
||||
String contentType = attachment.getContentType();
|
||||
String attachmentContentType = Strings.hasLength(contentType) ? contentType : response.contentType();
|
||||
return new Attachment.Bytes(attachment.getId(), response.body().toBytes(), attachmentContentType);
|
||||
return new Attachment.Bytes(attachment.id(), response.body().toBytes(), attachmentContentType);
|
||||
} else {
|
||||
logger.error("Empty response body: [host[{}], port[{}], method[{}], path[{}]: response status [{}]", httpRequest.host(),
|
||||
httpRequest.port(), httpRequest.method(), httpRequest.path(), response.status());
|
||||
|
@ -109,6 +109,6 @@ public class HttpEmailAttachementParser implements EmailAttachmentParser<HttpReq
|
|||
}
|
||||
|
||||
throw new ElasticsearchException("Unable to get attachment of type [{}] with id [{}] in watch [{}] aborting watch execution",
|
||||
type(), attachment.getId(), context.watch().id());
|
||||
type(), attachment.id(), context.watch().id());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public class HttpRequestAttachment implements EmailAttachmentParser.EmailAttachm
|
|||
|
||||
private final HttpRequestTemplate requestTemplate;
|
||||
private final String contentType;
|
||||
private String id;
|
||||
private final String id;
|
||||
|
||||
public HttpRequestAttachment(String id, HttpRequestTemplate requestTemplate, @Nullable String contentType) {
|
||||
this.id = id;
|
||||
|
@ -33,7 +33,8 @@ public class HttpRequestAttachment implements EmailAttachmentParser.EmailAttachm
|
|||
return contentType;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
@Override
|
||||
public String id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import org.elasticsearch.watcher.actions.ExecutableAction;
|
|||
import org.elasticsearch.watcher.execution.WatchExecutionContext;
|
||||
import org.elasticsearch.watcher.support.ArrayObjectIterator;
|
||||
import org.elasticsearch.watcher.support.WatcherDateTimeUtils;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
import org.elasticsearch.watcher.support.xcontent.XContentSource;
|
||||
import org.elasticsearch.watcher.watch.Payload;
|
||||
|
||||
|
@ -34,10 +34,10 @@ import static org.elasticsearch.watcher.support.Exceptions.illegalState;
|
|||
|
||||
public class ExecutableIndexAction extends ExecutableAction<IndexAction> {
|
||||
|
||||
private final ClientProxy client;
|
||||
private final WatcherClientProxy client;
|
||||
private final TimeValue timeout;
|
||||
|
||||
public ExecutableIndexAction(IndexAction action, ESLogger logger, ClientProxy client, @Nullable TimeValue defaultTimeout) {
|
||||
public ExecutableIndexAction(IndexAction action, ESLogger logger, WatcherClientProxy client, @Nullable TimeValue defaultTimeout) {
|
||||
super(action, logger);
|
||||
this.client = client;
|
||||
this.timeout = action.timeout != null ? action.timeout : defaultTimeout;
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.elasticsearch.common.unit.TimeValue;
|
|||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.watcher.actions.ActionFactory;
|
||||
import org.elasticsearch.watcher.actions.email.ExecutableEmailAction;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -21,11 +21,11 @@ import java.io.IOException;
|
|||
*/
|
||||
public class IndexActionFactory extends ActionFactory<IndexAction, ExecutableIndexAction> {
|
||||
|
||||
private final ClientProxy client;
|
||||
private final WatcherClientProxy client;
|
||||
private final TimeValue defaultTimeout;
|
||||
|
||||
@Inject
|
||||
public IndexActionFactory(Settings settings, ClientProxy client) {
|
||||
public IndexActionFactory(Settings settings, WatcherClientProxy client) {
|
||||
super(Loggers.getLogger(ExecutableEmailAction.class, settings));
|
||||
this.client = client;
|
||||
this.defaultTimeout = settings.getAsTime("watcher.actions.index.default_timeout", null);
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
|||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.search.sort.SortBuilders;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -47,7 +47,7 @@ public class TriggeredWatchStore extends AbstractComponent {
|
|||
public static final String DOC_TYPE = "triggered_watch";
|
||||
|
||||
private final int scrollSize;
|
||||
private final ClientProxy client;
|
||||
private final WatcherClientProxy client;
|
||||
private final TimeValue scrollTimeout;
|
||||
private final TriggeredWatch.Parser triggeredWatchParser;
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class TriggeredWatchStore extends AbstractComponent {
|
|||
private final AtomicBoolean started = new AtomicBoolean(false);
|
||||
|
||||
@Inject
|
||||
public TriggeredWatchStore(Settings settings, ClientProxy client, TriggeredWatch.Parser triggeredWatchParser) {
|
||||
public TriggeredWatchStore(Settings settings, WatcherClientProxy client, TriggeredWatch.Parser triggeredWatchParser) {
|
||||
super(settings);
|
||||
this.scrollSize = settings.getAsInt("watcher.execution.scroll.size", 100);
|
||||
this.client = client;
|
||||
|
|
|
@ -14,7 +14,7 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
|||
import org.elasticsearch.index.engine.VersionConflictEngineException;
|
||||
import org.elasticsearch.watcher.WatcherModule;
|
||||
import org.elasticsearch.watcher.execution.ExecutionState;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
@ -36,7 +36,7 @@ public class HistoryStore extends AbstractComponent {
|
|||
|
||||
static final DateTimeFormatter indexTimeFormat = DateTimeFormat.forPattern("YYYY.MM.dd");
|
||||
|
||||
private final ClientProxy client;
|
||||
private final WatcherClientProxy client;
|
||||
|
||||
private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
|
||||
private final Lock putUpdateLock = readWriteLock.readLock();
|
||||
|
@ -44,7 +44,7 @@ public class HistoryStore extends AbstractComponent {
|
|||
private final AtomicBoolean started = new AtomicBoolean(false);
|
||||
|
||||
@Inject
|
||||
public HistoryStore(Settings settings, ClientProxy client) {
|
||||
public HistoryStore(Settings settings, WatcherClientProxy client) {
|
||||
super(settings);
|
||||
this.client = client;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public class InputModule extends AbstractModule {
|
|||
bind(NoneInputFactory.class).asEagerSingleton();
|
||||
parsersBinder.addBinding(NoneInput.TYPE).to(NoneInputFactory.class);
|
||||
|
||||
// no bind() needed, done in InitializingModule
|
||||
// no bind() needed, done using the LazyInitializationModule
|
||||
parsersBinder.addBinding(ChainInput.TYPE).to(ChainInputFactory.class);
|
||||
|
||||
for (Map.Entry<String, Class<? extends InputFactory>> entry : parsers.entrySet()) {
|
||||
|
|
|
@ -15,14 +15,14 @@ import org.elasticsearch.watcher.input.ExecutableInput;
|
|||
import org.elasticsearch.watcher.input.Input;
|
||||
import org.elasticsearch.watcher.input.InputFactory;
|
||||
import org.elasticsearch.watcher.input.InputRegistry;
|
||||
import org.elasticsearch.watcher.support.init.InitializingService;
|
||||
import org.elasticsearch.xpack.common.init.LazyInitializable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ChainInputFactory extends InputFactory<ChainInput, ChainInput.Result, ExecutableChainInput>
|
||||
implements InitializingService.Initializable {
|
||||
implements LazyInitializable {
|
||||
|
||||
private InputRegistry inputRegistry;
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.elasticsearch.watcher.execution.WatchExecutionContext;
|
|||
import org.elasticsearch.watcher.input.ExecutableInput;
|
||||
import org.elasticsearch.watcher.support.WatcherUtils;
|
||||
import org.elasticsearch.watcher.support.XContentFilterKeysUtils;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
import org.elasticsearch.watcher.watch.Payload;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -34,10 +34,10 @@ public class ExecutableSearchInput extends ExecutableInput<SearchInput, SearchIn
|
|||
|
||||
public static final SearchType DEFAULT_SEARCH_TYPE = SearchType.QUERY_THEN_FETCH;
|
||||
|
||||
private final ClientProxy client;
|
||||
private final WatcherClientProxy client;
|
||||
private final @Nullable TimeValue timeout;
|
||||
|
||||
public ExecutableSearchInput(SearchInput input, ESLogger logger, ClientProxy client, @Nullable TimeValue defaultTimeout) {
|
||||
public ExecutableSearchInput(SearchInput input, ESLogger logger, WatcherClientProxy client, @Nullable TimeValue defaultTimeout) {
|
||||
super(input, logger);
|
||||
this.client = client;
|
||||
this.timeout = input.getTimeout() != null ? input.getTimeout() : defaultTimeout;
|
||||
|
|
|
@ -15,7 +15,7 @@ import org.elasticsearch.indices.query.IndicesQueriesRegistry;
|
|||
import org.elasticsearch.search.aggregations.AggregatorParsers;
|
||||
import org.elasticsearch.watcher.input.InputFactory;
|
||||
import org.elasticsearch.watcher.input.simple.ExecutableSimpleInput;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -24,13 +24,14 @@ import java.io.IOException;
|
|||
*/
|
||||
public class SearchInputFactory extends InputFactory<SearchInput, SearchInput.Result, ExecutableSearchInput> {
|
||||
|
||||
private final ClientProxy client;
|
||||
private final WatcherClientProxy client;
|
||||
private final TimeValue defaultTimeout;
|
||||
private IndicesQueriesRegistry queryRegistry;
|
||||
private AggregatorParsers aggParsers;
|
||||
|
||||
@Inject
|
||||
public SearchInputFactory(Settings settings, ClientProxy client, IndicesQueriesRegistry queryRegistry, AggregatorParsers aggParsers) {
|
||||
public SearchInputFactory(Settings settings, WatcherClientProxy client, IndicesQueriesRegistry queryRegistry,
|
||||
AggregatorParsers aggParsers) {
|
||||
super(Loggers.getLogger(ExecutableSimpleInput.class, settings));
|
||||
this.client = client;
|
||||
this.queryRegistry = queryRegistry;
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.elasticsearch.common.settings.Setting;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.gateway.GatewayService;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
import org.elasticsearch.watcher.watch.WatchStore;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
@ -38,7 +38,7 @@ import static java.util.Collections.unmodifiableSet;
|
|||
public class WatcherIndexTemplateRegistry extends AbstractComponent implements ClusterStateListener {
|
||||
private static final String FORBIDDEN_INDEX_SETTING = "index.mapper.dynamic";
|
||||
|
||||
private final ClientProxy client;
|
||||
private final WatcherClientProxy client;
|
||||
private final ThreadPool threadPool;
|
||||
private final ClusterService clusterService;
|
||||
private final Set<TemplateConfig> indexTemplates;
|
||||
|
@ -47,7 +47,7 @@ public class WatcherIndexTemplateRegistry extends AbstractComponent implements C
|
|||
|
||||
@Inject
|
||||
public WatcherIndexTemplateRegistry(Settings settings, ClusterSettings clusterSettings, ClusterService clusterService,
|
||||
ThreadPool threadPool, ClientProxy client, Set<TemplateConfig> configs) {
|
||||
ThreadPool threadPool, WatcherClientProxy client, Set<TemplateConfig> configs) {
|
||||
super(settings);
|
||||
this.client = client;
|
||||
this.threadPool = threadPool;
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.watcher.support.init;
|
||||
|
||||
import org.elasticsearch.common.inject.AbstractModule;
|
||||
import org.elasticsearch.common.inject.multibindings.Multibinder;
|
||||
import org.elasticsearch.watcher.input.chain.ChainInputFactory;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.watcher.transform.chain.ChainTransformFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class InitializingModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
|
||||
bind(ClientProxy.class).asEagerSingleton();
|
||||
bind(ScriptServiceProxy.class).asEagerSingleton();
|
||||
bind(ChainInputFactory.class).asEagerSingleton();
|
||||
|
||||
Multibinder<InitializingService.Initializable> mbinder = Multibinder.newSetBinder(binder(),
|
||||
InitializingService.Initializable.class);
|
||||
mbinder.addBinding().to(ClientProxy.class);
|
||||
mbinder.addBinding().to(ScriptServiceProxy.class);
|
||||
mbinder.addBinding().to(ChainTransformFactory.class);
|
||||
mbinder.addBinding().to(ChainInputFactory.class);
|
||||
bind(InitializingService.class).asEagerSingleton();
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ import org.elasticsearch.script.ScriptService;
|
|||
import org.elasticsearch.shield.SecurityContext;
|
||||
import org.elasticsearch.shield.XPackUser;
|
||||
import org.elasticsearch.watcher.support.Script;
|
||||
import org.elasticsearch.watcher.support.init.InitializingService;
|
||||
import org.elasticsearch.xpack.common.init.LazyInitializable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -23,7 +23,7 @@ import static java.util.Collections.emptyMap;
|
|||
*A lazily initialized proxy to the elasticsearch {@link ScriptService}. Inject this proxy whenever the script
|
||||
* service needs to be injected to avoid circular dependencies issues.
|
||||
*/
|
||||
public class ScriptServiceProxy implements InitializingService.Initializable {
|
||||
public class ScriptServiceProxy implements LazyInitializable {
|
||||
|
||||
private ScriptService service;
|
||||
private SecurityContext securityContext;
|
||||
|
@ -65,7 +65,7 @@ public class ScriptServiceProxy implements InitializingService.Initializable {
|
|||
service.executable(script, WatcherScriptContext.CTX, emptyMap()));
|
||||
}
|
||||
|
||||
public static final ScriptContext.Plugin INSTANCE = new ScriptContext.Plugin("elasticsearch-watcher", "watch");
|
||||
public static final ScriptContext.Plugin INSTANCE = new ScriptContext.Plugin("xpack", "watch");
|
||||
|
||||
private static class WatcherScriptContext implements ScriptContext {
|
||||
|
||||
|
|
|
@ -23,29 +23,25 @@ import org.elasticsearch.action.search.SearchResponse;
|
|||
import org.elasticsearch.action.search.SearchScrollRequest;
|
||||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.action.update.UpdateResponse;
|
||||
import org.elasticsearch.client.AdminClient;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.inject.Injector;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.shield.InternalClient;
|
||||
import org.elasticsearch.transport.TransportMessage;
|
||||
import org.elasticsearch.watcher.support.init.InitializingService;
|
||||
import org.elasticsearch.xpack.common.init.proxy.ClientProxy;
|
||||
|
||||
/**
|
||||
* A lazily initialized proxy to an elasticsearch {@link Client}. Inject this proxy whenever a client
|
||||
* needs to injected to be avoid circular dependencies issues.
|
||||
*/
|
||||
public class ClientProxy implements InitializingService.Initializable {
|
||||
public class WatcherClientProxy extends ClientProxy {
|
||||
|
||||
private final TimeValue defaultSearchTimeout;
|
||||
private final TimeValue defaultIndexTimeout;
|
||||
private final TimeValue defaultBulkTimeout;
|
||||
private InternalClient client;
|
||||
|
||||
@Inject
|
||||
public ClientProxy(Settings settings) {
|
||||
public WatcherClientProxy(Settings settings) {
|
||||
defaultSearchTimeout = settings.getAsTime("watcher.internal.ops.search.default_timeout", TimeValue.timeValueSeconds(30));
|
||||
defaultIndexTimeout = settings.getAsTime("watcher.internal.ops.index.default_timeout", TimeValue.timeValueSeconds(60));
|
||||
defaultBulkTimeout = settings.getAsTime("watcher.internal.ops.bulk.default_timeout", TimeValue.timeValueSeconds(120));
|
||||
|
@ -54,21 +50,12 @@ public class ClientProxy implements InitializingService.Initializable {
|
|||
/**
|
||||
* Creates a proxy to the given internal client (can be used for testing)
|
||||
*/
|
||||
public static ClientProxy of(Client client) {
|
||||
ClientProxy proxy = new ClientProxy(Settings.EMPTY);
|
||||
public static WatcherClientProxy of(Client client) {
|
||||
WatcherClientProxy proxy = new WatcherClientProxy(Settings.EMPTY);
|
||||
proxy.client = client instanceof InternalClient ? (InternalClient) client : new InternalClient.Insecure(client);
|
||||
return proxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(Injector injector) {
|
||||
this.client = injector.getInstance(InternalClient.class);
|
||||
}
|
||||
|
||||
public AdminClient admin() {
|
||||
return client.admin();
|
||||
}
|
||||
|
||||
public IndexResponse index(IndexRequest request, TimeValue timeout) {
|
||||
if (timeout == null) {
|
||||
timeout = defaultIndexTimeout;
|
||||
|
@ -125,8 +112,4 @@ public class ClientProxy implements InitializingService.Initializable {
|
|||
preProcess(request);
|
||||
return client.admin().indices().putTemplate(request).actionGet(defaultIndexTimeout);
|
||||
}
|
||||
|
||||
<M extends TransportMessage> M preProcess(M message) {
|
||||
return message;
|
||||
}
|
||||
}
|
|
@ -38,7 +38,7 @@ public class TransformModule extends AbstractModule {
|
|||
bind(ScriptTransformFactory.class).asEagerSingleton();
|
||||
mbinder.addBinding(ScriptTransform.TYPE).to(ScriptTransformFactory.class);
|
||||
|
||||
bind(ChainTransformFactory.class).asEagerSingleton();
|
||||
// no bind() needed, done using the LazyInitializationModule
|
||||
mbinder.addBinding(ChainTransform.TYPE).to(ChainTransformFactory.class);
|
||||
|
||||
for (Map.Entry<String, Class<? extends TransformFactory>> entry : factories.entrySet()) {
|
||||
|
|
|
@ -9,11 +9,11 @@ import org.elasticsearch.common.inject.Injector;
|
|||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.watcher.support.init.InitializingService;
|
||||
import org.elasticsearch.watcher.transform.ExecutableTransform;
|
||||
import org.elasticsearch.watcher.transform.Transform;
|
||||
import org.elasticsearch.watcher.transform.TransformFactory;
|
||||
import org.elasticsearch.watcher.transform.TransformRegistry;
|
||||
import org.elasticsearch.xpack.common.init.LazyInitializable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -22,7 +22,7 @@ import java.util.ArrayList;
|
|||
*
|
||||
*/
|
||||
public class ChainTransformFactory extends TransformFactory<ChainTransform, ChainTransform.Result, ExecutableChainTransform> implements
|
||||
InitializingService.Initializable {
|
||||
LazyInitializable {
|
||||
|
||||
private TransformRegistry registry;
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.elasticsearch.common.logging.ESLogger;
|
|||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.watcher.execution.WatchExecutionContext;
|
||||
import org.elasticsearch.watcher.support.WatcherUtils;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
import org.elasticsearch.watcher.transform.ExecutableTransform;
|
||||
import org.elasticsearch.watcher.watch.Payload;
|
||||
|
||||
|
@ -24,10 +24,11 @@ public class ExecutableSearchTransform extends ExecutableTransform<SearchTransfo
|
|||
|
||||
public static final SearchType DEFAULT_SEARCH_TYPE = SearchType.QUERY_THEN_FETCH;
|
||||
|
||||
protected final ClientProxy client;
|
||||
protected final WatcherClientProxy client;
|
||||
protected final @Nullable TimeValue timeout;
|
||||
|
||||
public ExecutableSearchTransform(SearchTransform transform, ESLogger logger, ClientProxy client, @Nullable TimeValue defaultTimeout) {
|
||||
public ExecutableSearchTransform(SearchTransform transform, ESLogger logger, WatcherClientProxy client,
|
||||
@Nullable TimeValue defaultTimeout) {
|
||||
super(transform, logger);
|
||||
this.client = client;
|
||||
this.timeout = transform.getTimeout() != null ? transform.getTimeout() : defaultTimeout;
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
|||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
|
||||
import org.elasticsearch.search.aggregations.AggregatorParsers;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
import org.elasticsearch.watcher.transform.TransformFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -23,14 +23,14 @@ import java.io.IOException;
|
|||
*/
|
||||
public class SearchTransformFactory extends TransformFactory<SearchTransform, SearchTransform.Result, ExecutableSearchTransform> {
|
||||
|
||||
protected final ClientProxy client;
|
||||
protected final WatcherClientProxy client;
|
||||
private final TimeValue defaultTimeout;
|
||||
private IndicesQueriesRegistry queryRegistry;
|
||||
private AggregatorParsers aggParsers;
|
||||
|
||||
@Inject
|
||||
public SearchTransformFactory(Settings settings, ClientProxy client, IndicesQueriesRegistry queryRegistry,
|
||||
AggregatorParsers aggParsers) {
|
||||
public SearchTransformFactory(Settings settings, WatcherClientProxy client, IndicesQueriesRegistry queryRegistry,
|
||||
AggregatorParsers aggParsers) {
|
||||
super(Loggers.getLogger(ExecutableSearchTransform.class, settings));
|
||||
this.client = client;
|
||||
this.queryRegistry = queryRegistry;
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.elasticsearch.common.xcontent.json.JsonXContent;
|
|||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.search.sort.SortBuilders;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
@ -49,7 +49,7 @@ public class WatchStore extends AbstractComponent {
|
|||
public static final String INDEX = ".watches";
|
||||
public static final String DOC_TYPE = "watch";
|
||||
|
||||
private final ClientProxy client;
|
||||
private final WatcherClientProxy client;
|
||||
private final Watch.Parser watchParser;
|
||||
|
||||
private final ConcurrentMap<String, Watch> watches;
|
||||
|
@ -59,7 +59,7 @@ public class WatchStore extends AbstractComponent {
|
|||
private final TimeValue scrollTimeout;
|
||||
|
||||
@Inject
|
||||
public WatchStore(Settings settings, ClientProxy client, Watch.Parser watchParser) {
|
||||
public WatchStore(Settings settings, WatcherClientProxy client, Watch.Parser watchParser) {
|
||||
super(settings);
|
||||
this.client = client;
|
||||
this.watchParser = watchParser;
|
||||
|
|
|
@ -17,10 +17,8 @@ import java.util.Map;
|
|||
import static java.util.Collections.singletonMap;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class DataAttachmentTests extends ESTestCase {
|
||||
|
||||
public void testCreateJson() throws Exception {
|
||||
Map<String, Object> data = singletonMap("key", "value");
|
||||
Attachment attachment = DataAttachment.JSON.create("data", data);
|
||||
|
|
|
@ -481,7 +481,7 @@ public class EmailActionTests extends ESTestCase {
|
|||
}
|
||||
|
||||
public void testThatDataAttachmentGetsAttachedWithId() throws Exception {
|
||||
String attachmentId = "my_attachment";
|
||||
String attachmentId = randomAsciiOfLength(10) + ".yml";
|
||||
|
||||
XContentBuilder builder = jsonBuilder().startObject()
|
||||
.startObject("attachments")
|
||||
|
@ -506,9 +506,9 @@ public class EmailActionTests extends ESTestCase {
|
|||
EmailAction.Result.Success successResult = (EmailAction.Result.Success) result;
|
||||
Map<String, Attachment> attachments = successResult.email().attachments();
|
||||
|
||||
assertThat(attachments, hasKey("my_attachment"));
|
||||
Attachment dataAttachment = attachments.get("my_attachment");
|
||||
assertThat(dataAttachment.name(), is("data.yml"));
|
||||
assertThat(attachments, hasKey(attachmentId));
|
||||
Attachment dataAttachment = attachments.get(attachmentId);
|
||||
assertThat(dataAttachment.name(), is(attachmentId));
|
||||
assertThat(dataAttachment.type(), is("yaml"));
|
||||
assertThat(dataAttachment.contentType(), is("application/yaml"));
|
||||
}
|
||||
|
|
|
@ -11,7 +11,9 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
|||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
|
@ -36,7 +38,8 @@ public class DataAttachmentParserTests extends ESTestCase {
|
|||
assertThat(emailAttachments.getAttachments(), hasSize(1));
|
||||
|
||||
XContentBuilder toXcontentBuilder = jsonBuilder().startObject();
|
||||
emailAttachments.getAttachments().get(0).toXContent(toXcontentBuilder, ToXContent.EMPTY_PARAMS);
|
||||
List<EmailAttachmentParser.EmailAttachment> attachments = new ArrayList<>(emailAttachments.getAttachments());
|
||||
attachments.get(0).toXContent(toXcontentBuilder, ToXContent.EMPTY_PARAMS);
|
||||
toXcontentBuilder.endObject();
|
||||
assertThat(toXcontentBuilder.string(), is(builder.string()));
|
||||
}
|
||||
|
|
|
@ -61,15 +61,15 @@ public class EmailAttachmentParsersTests extends ESTestCase {
|
|||
EmailAttachments attachments = parser.parse(xContentParser);
|
||||
assertThat(attachments.getAttachments(), hasSize(2));
|
||||
|
||||
EmailAttachmentParser.EmailAttachment emailAttachment = attachments.getAttachments().get(0);
|
||||
List<EmailAttachmentParser.EmailAttachment> emailAttachments = new ArrayList<>(attachments.getAttachments());
|
||||
EmailAttachmentParser.EmailAttachment emailAttachment = emailAttachments.get(0);
|
||||
assertThat(emailAttachment, instanceOf(TestEmailAttachment.class));
|
||||
|
||||
Attachment attachment = parsers.get("test").toAttachment(ctx, new Payload.Simple(), emailAttachment);
|
||||
assertThat(attachment.name(), is("my-id"));
|
||||
assertThat(attachment.contentType(), is("personalContentType"));
|
||||
|
||||
assertThat(parsers.get("test").toAttachment(ctx, new Payload.Simple(),
|
||||
attachments.getAttachments().get(1)).id(), is("my-other-id"));
|
||||
assertThat(parsers.get("test").toAttachment(ctx, new Payload.Simple(), emailAttachments.get(1)).id(), is("my-other-id"));
|
||||
}
|
||||
|
||||
public void testThatUnknownParserThrowsException() throws IOException {
|
||||
|
@ -84,13 +84,13 @@ public class EmailAttachmentParsersTests extends ESTestCase {
|
|||
parser.parse(xContentParser);
|
||||
fail("Expected random parser of type [" + type + "] to throw an exception");
|
||||
} catch (ElasticsearchParseException e) {
|
||||
assertThat(e.getMessage(), containsString("Cannot parse attachment of type " + type));
|
||||
assertThat(e.getMessage(), containsString("Cannot parse attachment of type [" + type + "]"));
|
||||
}
|
||||
}
|
||||
|
||||
public void testThatToXContentSerializationWorks() throws Exception {
|
||||
List<EmailAttachmentParser.EmailAttachment> attachments = new ArrayList<>();
|
||||
attachments.add(new DataAttachment("my-id", org.elasticsearch.watcher.actions.email.DataAttachment.JSON));
|
||||
attachments.add(new DataAttachment("my-name.json", org.elasticsearch.watcher.actions.email.DataAttachment.JSON));
|
||||
|
||||
HttpRequestTemplate requestTemplate = HttpRequestTemplate.builder("localhost", 80).scheme(Scheme.HTTP).path("/").build();
|
||||
HttpRequestAttachment httpRequestAttachment = new HttpRequestAttachment("other-id", requestTemplate, null);
|
||||
|
@ -100,13 +100,36 @@ public class EmailAttachmentParsersTests extends ESTestCase {
|
|||
XContentBuilder builder = jsonBuilder();
|
||||
emailAttachments.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
logger.info("JSON is: " + builder.string());
|
||||
assertThat(builder.string(), containsString("my-id"));
|
||||
assertThat(builder.string(), containsString("my-name.json"));
|
||||
assertThat(builder.string(), containsString("json"));
|
||||
assertThat(builder.string(), containsString("other-id"));
|
||||
assertThat(builder.string(), containsString("localhost"));
|
||||
assertThat(builder.string(), containsString("/"));
|
||||
}
|
||||
|
||||
public void testThatTwoAttachmentsWithTheSameIdThrowError() throws Exception {
|
||||
Map<String, EmailAttachmentParser> parsers = new HashMap<>();
|
||||
parsers.put("test", new TestEmailAttachmentParser());
|
||||
EmailAttachmentsParser parser = new EmailAttachmentsParser(parsers);
|
||||
|
||||
List<EmailAttachmentParser.EmailAttachment> attachments = new ArrayList<>();
|
||||
attachments.add(new TestEmailAttachment("my-name.json", "value"));
|
||||
attachments.add(new TestEmailAttachment("my-name.json", "value"));
|
||||
|
||||
EmailAttachments emailAttachments = new EmailAttachments(attachments);
|
||||
XContentBuilder builder = jsonBuilder();
|
||||
emailAttachments.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
logger.info("JSON is: " + builder.string());
|
||||
|
||||
XContentParser xContentParser = JsonXContent.jsonXContent.createParser(builder.bytes());
|
||||
try {
|
||||
parser.parse(xContentParser);
|
||||
fail("Expected parser to fail but did not happen");
|
||||
} catch (ElasticsearchParseException e) {
|
||||
assertThat(e.getMessage(), is("Attachment with id [my-name.json] has already been created, must be renamed"));
|
||||
}
|
||||
}
|
||||
|
||||
public class TestEmailAttachmentParser implements EmailAttachmentParser<TestEmailAttachment> {
|
||||
|
||||
@Override
|
||||
|
@ -138,7 +161,7 @@ public class EmailAttachmentParsersTests extends ESTestCase {
|
|||
|
||||
@Override
|
||||
public Attachment toAttachment(WatchExecutionContext ctx, Payload payload, TestEmailAttachment attachment) {
|
||||
return new Attachment.Bytes(attachment.getId(), attachment.getValue().getBytes(Charsets.UTF_8), "personalContentType");
|
||||
return new Attachment.Bytes(attachment.id(), attachment.getValue().getBytes(Charsets.UTF_8), "personalContentType");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,7 +188,8 @@ public class EmailAttachmentParsersTests extends ESTestCase {
|
|||
return value;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
@Override
|
||||
public String id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,9 @@ import org.elasticsearch.watcher.support.secret.SecretService;
|
|||
import org.elasticsearch.watcher.test.MockTextTemplateEngine;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
@ -83,7 +85,8 @@ public class HttpEmailAttachementParserTests extends ESTestCase {
|
|||
assertThat(emailAttachments.getAttachments(), hasSize(1));
|
||||
|
||||
XContentBuilder toXcontentBuilder = jsonBuilder().startObject();
|
||||
emailAttachments.getAttachments().get(0).toXContent(toXcontentBuilder, ToXContent.EMPTY_PARAMS);
|
||||
List<EmailAttachmentParser.EmailAttachment> attachments = new ArrayList<>(emailAttachments.getAttachments());
|
||||
attachments.get(0).toXContent(toXcontentBuilder, ToXContent.EMPTY_PARAMS);
|
||||
toXcontentBuilder.endObject();
|
||||
assertThat(toXcontentBuilder.string(), is(builder.string()));
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.elasticsearch.watcher.actions.Action;
|
|||
import org.elasticsearch.watcher.actions.Action.Result.Status;
|
||||
import org.elasticsearch.watcher.execution.WatchExecutionContext;
|
||||
import org.elasticsearch.watcher.support.WatcherDateTimeUtils;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
import org.elasticsearch.watcher.support.xcontent.XContentSource;
|
||||
import org.elasticsearch.watcher.test.WatcherTestUtils;
|
||||
import org.elasticsearch.watcher.watch.Payload;
|
||||
|
@ -72,7 +72,7 @@ public class IndexActionTests extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
IndexAction action = new IndexAction("test-index", "test-type", timestampField, null, null);
|
||||
ExecutableIndexAction executable = new ExecutableIndexAction(action, logger, ClientProxy.of(client()), null);
|
||||
ExecutableIndexAction executable = new ExecutableIndexAction(action, logger, WatcherClientProxy.of(client()), null);
|
||||
DateTime executionTime = DateTime.now(UTC);
|
||||
Payload payload = randomBoolean() ? new Payload.Simple("foo", "bar") : new Payload.Simple("_doc", singletonMap("foo", "bar"));
|
||||
WatchExecutionContext ctx = WatcherTestUtils.mockExecutionContext("_id", executionTime, payload);
|
||||
|
@ -132,7 +132,7 @@ public class IndexActionTests extends ESIntegTestCase {
|
|||
);
|
||||
|
||||
IndexAction action = new IndexAction("test-index", "test-type", timestampField, null, null);
|
||||
ExecutableIndexAction executable = new ExecutableIndexAction(action, logger, ClientProxy.of(client()), null);
|
||||
ExecutableIndexAction executable = new ExecutableIndexAction(action, logger, WatcherClientProxy.of(client()), null);
|
||||
DateTime executionTime = DateTime.now(UTC);
|
||||
WatchExecutionContext ctx = WatcherTestUtils.mockExecutionContext("_id", executionTime, new Payload.Simple("_doc", list));
|
||||
|
||||
|
@ -196,7 +196,7 @@ public class IndexActionTests extends ESIntegTestCase {
|
|||
}
|
||||
builder.endObject();
|
||||
|
||||
IndexActionFactory actionParser = new IndexActionFactory(Settings.EMPTY, ClientProxy.of(client()));
|
||||
IndexActionFactory actionParser = new IndexActionFactory(Settings.EMPTY, WatcherClientProxy.of(client()));
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
|
||||
parser.nextToken();
|
||||
|
||||
|
@ -224,7 +224,7 @@ public class IndexActionTests extends ESIntegTestCase {
|
|||
}
|
||||
}
|
||||
builder.endObject();
|
||||
IndexActionFactory actionParser = new IndexActionFactory(Settings.EMPTY, ClientProxy.of(client()));
|
||||
IndexActionFactory actionParser = new IndexActionFactory(Settings.EMPTY, WatcherClientProxy.of(client()));
|
||||
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());
|
||||
parser.nextToken();
|
||||
try {
|
||||
|
|
|
@ -15,7 +15,6 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
|||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.threadpool.ThreadPool;
|
||||
import org.elasticsearch.watcher.actions.Action;
|
||||
import org.elasticsearch.watcher.actions.Action.Result.Status;
|
||||
import org.elasticsearch.watcher.actions.email.service.Attachment;
|
||||
|
@ -32,12 +31,10 @@ import org.elasticsearch.watcher.support.http.HttpRequestTemplate;
|
|||
import org.elasticsearch.watcher.support.http.HttpResponse;
|
||||
import org.elasticsearch.watcher.support.http.auth.HttpAuthRegistry;
|
||||
import org.elasticsearch.watcher.support.http.auth.basic.BasicAuthFactory;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
import org.elasticsearch.watcher.support.secret.SecretService;
|
||||
import org.elasticsearch.watcher.support.text.TextTemplate;
|
||||
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
|
||||
import org.elasticsearch.watcher.support.text.DefaultTextTemplateEngine;
|
||||
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.watcher.test.MockTextTemplateEngine;
|
||||
import org.elasticsearch.watcher.test.WatcherTestUtils;
|
||||
|
@ -46,7 +43,6 @@ import org.elasticsearch.watcher.watch.Payload;
|
|||
import org.elasticsearch.watcher.watch.Watch;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
import javax.mail.internet.AddressException;
|
||||
|
@ -242,7 +238,7 @@ public class WebhookActionTests extends ESTestCase {
|
|||
|
||||
ExecutableWebhookAction executable = new ExecutableWebhookAction(action, logger, httpClient, templateEngine);
|
||||
String watchId = "test_url_encode" + randomAsciiOfLength(10);
|
||||
Watch watch = createWatch(watchId, mock(ClientProxy.class), "account1");
|
||||
Watch watch = createWatch(watchId, mock(WatcherClientProxy.class), "account1");
|
||||
WatchExecutionContext ctx = new TriggeredExecutionContext(watch, new DateTime(UTC),
|
||||
new ScheduleTriggerEvent(watchId, new DateTime(UTC), new DateTime(UTC)), timeValueSeconds(5));
|
||||
executable.execute("_id", ctx, new Payload.Simple());
|
||||
|
@ -268,14 +264,14 @@ public class WebhookActionTests extends ESTestCase {
|
|||
|
||||
ExecutableWebhookAction executable = new ExecutableWebhookAction(action, logger, client, templateEngine);
|
||||
|
||||
Watch watch = createWatch(watchId, mock(ClientProxy.class), "account1");
|
||||
Watch watch = createWatch(watchId, mock(WatcherClientProxy.class), "account1");
|
||||
WatchExecutionContext ctx = new TriggeredExecutionContext(watch, new DateTime(UTC),
|
||||
new ScheduleTriggerEvent(watchId, new DateTime(UTC), new DateTime(UTC)), timeValueSeconds(5));
|
||||
Action.Result result = executable.execute("_id", ctx, new Payload.Simple());
|
||||
assertThat(result, Matchers.instanceOf(WebhookAction.Result.Success.class));
|
||||
}
|
||||
|
||||
private Watch createWatch(String watchId, ClientProxy client, final String account) throws AddressException, IOException {
|
||||
private Watch createWatch(String watchId, WatcherClientProxy client, final String account) throws AddressException, IOException {
|
||||
return WatcherTestUtils.createTestWatch(watchId,
|
||||
client,
|
||||
ExecuteScenario.Success.client(),
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.elasticsearch.search.internal.InternalSearchHit;
|
|||
import org.elasticsearch.search.internal.InternalSearchHits;
|
||||
import org.elasticsearch.search.internal.InternalSearchResponse;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
import org.hamcrest.core.IsNull;
|
||||
import org.junit.Before;
|
||||
|
||||
|
@ -53,13 +53,13 @@ import static org.mockito.Mockito.verifyZeroInteractions;
|
|||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class TriggeredWatchStoreTests extends ESTestCase {
|
||||
private ClientProxy clientProxy;
|
||||
private WatcherClientProxy clientProxy;
|
||||
private TriggeredWatch.Parser parser;
|
||||
private TriggeredWatchStore triggeredWatchStore;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
clientProxy = mock(ClientProxy.class);
|
||||
clientProxy = mock(WatcherClientProxy.class);
|
||||
parser = mock(TriggeredWatch.Parser.class);
|
||||
triggeredWatchStore = new TriggeredWatchStore(Settings.EMPTY, clientProxy, parser);
|
||||
triggeredWatchStore.start();
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.elasticsearch.test.ESTestCase;
|
|||
import org.elasticsearch.watcher.WatcherModule;
|
||||
import org.elasticsearch.watcher.execution.ExecutionState;
|
||||
import org.elasticsearch.watcher.execution.Wid;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
import org.elasticsearch.watcher.trigger.schedule.ScheduleTriggerEvent;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Before;
|
||||
|
@ -31,11 +31,11 @@ import static org.mockito.Mockito.when;
|
|||
*/
|
||||
public class HistoryStoreTests extends ESTestCase {
|
||||
private HistoryStore historyStore;
|
||||
private ClientProxy clientProxy;
|
||||
private WatcherClientProxy clientProxy;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
clientProxy = mock(ClientProxy.class);
|
||||
clientProxy = mock(WatcherClientProxy.class);
|
||||
historyStore = new HistoryStore(Settings.EMPTY, clientProxy);
|
||||
historyStore.start();
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ import org.elasticsearch.watcher.support.WatcherUtils;
|
|||
import org.elasticsearch.watcher.support.http.HttpClient;
|
||||
import org.elasticsearch.watcher.support.http.HttpMethod;
|
||||
import org.elasticsearch.watcher.support.http.HttpRequestTemplate;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.watcher.support.secret.Secret;
|
||||
import org.elasticsearch.watcher.support.text.TextTemplate;
|
||||
|
@ -172,11 +172,11 @@ public final class WatcherTestUtils {
|
|||
|
||||
public static Watch createTestWatch(String watchName, HttpClient httpClient, EmailService emailService,
|
||||
ESLogger logger) throws AddressException {
|
||||
return createTestWatch(watchName, ClientProxy.of(ESIntegTestCase.client()), httpClient, emailService, logger);
|
||||
return createTestWatch(watchName, WatcherClientProxy.of(ESIntegTestCase.client()), httpClient, emailService, logger);
|
||||
}
|
||||
|
||||
|
||||
public static Watch createTestWatch(String watchName, ClientProxy client, HttpClient httpClient, EmailService emailService,
|
||||
public static Watch createTestWatch(String watchName, WatcherClientProxy client, HttpClient httpClient, EmailService emailService,
|
||||
ESLogger logger) throws AddressException {
|
||||
|
||||
SearchRequest conditionRequest = newInputSearchRequest("my-condition-index").source(searchSource().query(matchAllQuery()));
|
||||
|
|
|
@ -32,7 +32,7 @@ import org.elasticsearch.search.SearchHitField;
|
|||
import org.elasticsearch.search.internal.InternalSearchHit;
|
||||
import org.elasticsearch.search.internal.InternalSearchHits;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.util.Collections;
|
||||
|
@ -52,12 +52,12 @@ import static org.mockito.Mockito.when;
|
|||
*/
|
||||
public class WatchStoreTests extends ESTestCase {
|
||||
private WatchStore watchStore;
|
||||
private ClientProxy clientProxy;
|
||||
private WatcherClientProxy clientProxy;
|
||||
private Watch.Parser parser;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
clientProxy = mock(ClientProxy.class);
|
||||
clientProxy = mock(WatcherClientProxy.class);
|
||||
parser = mock(Watch.Parser.class);
|
||||
watchStore = new WatchStore(Settings.EMPTY, clientProxy, parser);
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ import org.elasticsearch.watcher.support.http.HttpMethod;
|
|||
import org.elasticsearch.watcher.support.http.HttpRequestTemplate;
|
||||
import org.elasticsearch.watcher.support.http.auth.HttpAuthRegistry;
|
||||
import org.elasticsearch.watcher.support.http.auth.basic.BasicAuthFactory;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.WatcherClientProxy;
|
||||
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
|
||||
import org.elasticsearch.watcher.support.secret.SecretService;
|
||||
import org.elasticsearch.watcher.support.text.TextTemplate;
|
||||
|
@ -141,7 +141,7 @@ import static org.mockito.Mockito.mock;
|
|||
|
||||
public class WatchTests extends ESTestCase {
|
||||
private ScriptServiceProxy scriptService;
|
||||
private ClientProxy client;
|
||||
private WatcherClientProxy client;
|
||||
private HttpClient httpClient;
|
||||
private EmailService emailService;
|
||||
private TextTemplateEngine templateEngine;
|
||||
|
@ -155,7 +155,7 @@ public class WatchTests extends ESTestCase {
|
|||
@Before
|
||||
public void init() throws Exception {
|
||||
scriptService = mock(ScriptServiceProxy.class);
|
||||
client = mock(ClientProxy.class);
|
||||
client = mock(WatcherClientProxy.class);
|
||||
httpClient = mock(HttpClient.class);
|
||||
emailService = mock(EmailService.class);
|
||||
templateEngine = mock(TextTemplateEngine.class);
|
||||
|
|
Loading…
Reference in New Issue