Watcher: Make watch history use doc type instead of watch_record (elastic/x-pack-elasticsearch#1311)

As this does not require any reindexing this is easy to fix by just
changing the watch history template.

In addition the old templates are deleted on start up and the new ones
are instantiated.

Original commit: elastic/x-pack-elasticsearch@7e1ad495ad
This commit is contained in:
Alexander Reelsen 2017-05-12 16:52:57 +02:00 committed by GitHub
parent de1d98b135
commit 50e9e413da
16 changed files with 203 additions and 141 deletions

View File

@ -166,5 +166,4 @@ public class WatcherLifeCycleService extends AbstractComponent implements Cluste
public WatcherMetaData watcherMetaData() {
return watcherMetaData;
}
}

View File

@ -36,18 +36,6 @@ public class QueuedWatch implements Streamable, ToXContent {
return watchId;
}
public void WatchId(String watchId) {
this.watchId = watchId;
}
public String watchRecordId() {
return watchRecordId;
}
public void watchRecordId(String watchRecordId) {
this.watchRecordId = watchRecordId;
}
public DateTime triggeredTime() {
return triggeredTime;
}

View File

@ -38,7 +38,7 @@ public class HistoryStore extends AbstractComponent {
public static final String INDEX_PREFIX = ".watcher-history-";
public static final String INDEX_PREFIX_WITH_TEMPLATE = INDEX_PREFIX + WatcherIndexTemplateRegistry.INDEX_TEMPLATE_VERSION + "-";
public static final String DOC_TYPE = "watch_record";
public static final String DOC_TYPE = "doc";
static final DateTimeFormatter indexTimeFormat = DateTimeFormat.forPattern("YYYY.MM.dd");

View File

@ -5,9 +5,11 @@
*/
package org.elasticsearch.xpack.watcher.support;
import com.carrotsearch.hppc.cursors.ObjectCursor;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.logging.log4j.util.Supplier;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse;
import org.elasticsearch.cluster.ClusterChangedEvent;
@ -37,11 +39,11 @@ import static java.util.Collections.unmodifiableMap;
public class WatcherIndexTemplateRegistry extends AbstractComponent implements ClusterStateListener {
private static final String FORBIDDEN_INDEX_SETTING = "index.mapper.dynamic";
public static final String INDEX_TEMPLATE_VERSION = "5";
public static final String INDEX_TEMPLATE_VERSION = "6";
public static final String HISTORY_TEMPLATE_NAME = "watch_history_" + INDEX_TEMPLATE_VERSION;
public static final String TRIGGERED_TEMPLATE_NAME = "triggered_watches";
public static final String WATCHES_TEMPLATE_NAME = "watches";
public static final String HISTORY_TEMPLATE_NAME = ".watch-history-" + INDEX_TEMPLATE_VERSION;
public static final String TRIGGERED_TEMPLATE_NAME = ".triggered_watches";
public static final String WATCHES_TEMPLATE_NAME = ".watches";
public static final Setting<Settings> HISTORY_TEMPLATE_SETTING = Setting.groupSetting("xpack.watcher.history.index.",
Setting.Property.Dynamic, Setting.Property.NodeScope);
@ -50,9 +52,9 @@ public class WatcherIndexTemplateRegistry extends AbstractComponent implements C
public static final Setting<Settings> WATCHES_TEMPLATE_SETTING = Setting.groupSetting("xpack.watcher.watches.index.",
Setting.Property.Dynamic, Setting.Property.NodeScope);
public static final TemplateConfig[] TEMPLATE_CONFIGS = new TemplateConfig[]{
new TemplateConfig(TRIGGERED_TEMPLATE_NAME, TRIGGERED_TEMPLATE_SETTING),
new TemplateConfig(HISTORY_TEMPLATE_NAME, "watch_history", HISTORY_TEMPLATE_SETTING),
new TemplateConfig(WATCHES_TEMPLATE_NAME, WATCHES_TEMPLATE_SETTING)
new TemplateConfig(TRIGGERED_TEMPLATE_NAME, "triggered-watches", TRIGGERED_TEMPLATE_SETTING),
new TemplateConfig(HISTORY_TEMPLATE_NAME, "watch-history", HISTORY_TEMPLATE_SETTING),
new TemplateConfig(WATCHES_TEMPLATE_NAME, "watches", WATCHES_TEMPLATE_SETTING)
};
private final WatcherClientProxy client;
@ -96,6 +98,22 @@ public class WatcherIndexTemplateRegistry extends AbstractComponent implements C
}
addTemplatesIfMissing(state);
deleteDeprecatedTemplates(state);
}
/**
* This methods deletes the 5.x watcher index templates
* @param state The current cluster state
*/
private void deleteDeprecatedTemplates(ClusterState state) {
for (ObjectCursor<String> cursor : state.metaData().getTemplates().keys()) {
String name = cursor.value;
if ("watches".equals(name) || "triggered_watches".equals(name) || name.startsWith("watcher_history_")) {
client.deleteTemplate(new DeleteIndexTemplateRequest(name), ActionListener.wrap(
r -> logger.debug("Deleted old index template [{}]", name),
e -> logger.debug("Could not delete watcher template [{}]: [{}]", name, e.getMessage())));
}
}
}
void addTemplatesIfMissing(ClusterState state) {
@ -189,10 +207,6 @@ public class WatcherIndexTemplateRegistry extends AbstractComponent implements C
private String fileName;
private final Setting<Settings> setting;
public TemplateConfig(String templateName, Setting<Settings> setting) {
this(templateName, templateName, setting);
}
public TemplateConfig(String templateName, String fileName, Setting<Settings> setting) {
this.templateName = templateName;
this.fileName = fileName;

View File

@ -8,6 +8,8 @@ package org.elasticsearch.xpack.watcher.support.init.proxy;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest;
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse;
import org.elasticsearch.action.bulk.BulkRequest;
@ -128,8 +130,11 @@ public class WatcherClientProxy extends ClientProxy {
}
public void putTemplate(PutIndexTemplateRequest request, ActionListener<PutIndexTemplateResponse> listener) {
preProcess(request);
client.admin().indices().putTemplate(request, listener);
client.admin().indices().putTemplate(preProcess(request), listener);
}
public void deleteTemplate(DeleteIndexTemplateRequest request, ActionListener<DeleteIndexTemplateResponse> listener) {
client.admin().indices().deleteTemplate(preProcess(request), listener);
}
public GetResponse getWatch(String id) {

View File

@ -7,7 +7,7 @@
"index.mapper.dynamic": false
},
"mappings": {
"watch_record": {
"doc": {
"dynamic_templates": [
{
"disabled_payload_fields": {

View File

@ -41,15 +41,12 @@ public class HistoryStoreSettingsTests extends AbstractWatcherIntegrationTestCas
);
// use assertBusy(...) because we update the index template in an async manner
assertBusy(new Runnable() {
@Override
public void run() {
GetIndexTemplatesResponse response = client().admin().indices()
assertBusy(() -> {
GetIndexTemplatesResponse response1 = client().admin().indices()
.prepareGetTemplates(WatcherIndexTemplateRegistry.HISTORY_TEMPLATE_NAME).get();
assertThat(response.getIndexTemplates().get(0).getSettings().get("index.number_of_shards"), equalTo("2"));
assertThat(response.getIndexTemplates().get(0).getSettings().get("index.number_of_replicas"), equalTo("2"));
assertThat(response.getIndexTemplates().get(0).getSettings().get("index.refresh_interval"), equalTo("5m"));
}
assertThat(response1.getIndexTemplates().get(0).getSettings().get("index.number_of_shards"), equalTo("2"));
assertThat(response1.getIndexTemplates().get(0).getSettings().get("index.number_of_replicas"), equalTo("2"));
assertThat(response1.getIndexTemplates().get(0).getSettings().get("index.refresh_interval"), equalTo("5m"));
});
}
@ -68,15 +65,11 @@ public class HistoryStoreSettingsTests extends AbstractWatcherIntegrationTestCas
);
// use assertBusy(...) because we update the index template in an async manner
assertBusy(new Runnable() {
@Override
public void run() {
GetIndexTemplatesResponse response = client().admin().indices()
assertBusy(() -> {
GetIndexTemplatesResponse response1 = client().admin().indices()
.prepareGetTemplates(WatcherIndexTemplateRegistry.HISTORY_TEMPLATE_NAME).get();
assertThat(response.getIndexTemplates().get(0).getSettings().get("index.number_of_shards"), equalTo("2"));
assertThat(response.getIndexTemplates().get(0).getSettings().getAsBoolean("index.mapper.dynamic", null), is(false));
}
assertThat(response1.getIndexTemplates().get(0).getSettings().get("index.number_of_shards"), equalTo("2"));
assertThat(response1.getIndexTemplates().get(0).getSettings().getAsBoolean("index.mapper.dynamic", null), is(false));
});
}
}

View File

@ -60,7 +60,7 @@ public class HistoryTemplateTimeMappingsTests extends AbstractWatcherIntegration
if (!metadatas.key.startsWith(HistoryStore.INDEX_PREFIX)) {
continue;
}
MappingMetaData metadata = metadatas.value.get("watch_record");
MappingMetaData metadata = metadatas.value.get("doc");
assertThat(metadata, notNullValue());
try {
Map<String, Object> source = metadata.getSourceAsMap();

View File

@ -116,12 +116,12 @@ public class HistoryTemplateTransformMappingsTests extends AbstractWatcherIntegr
GetFieldMappingsResponse response = client().admin().indices()
.prepareGetFieldMappings(".watcher-history*")
.setFields("result.actions.transform.payload")
.setTypes("watch_record")
.setTypes("doc")
.includeDefaults(true)
.get();
for (Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetaData>> map : response.mappings().values()) {
Map<String, GetFieldMappingsResponse.FieldMappingMetaData> watchRecord = map.get("watch_record");
Map<String, GetFieldMappingsResponse.FieldMappingMetaData> watchRecord = map.get("doc");
assertThat(watchRecord, hasKey("result.actions.transform.payload"));
GetFieldMappingsResponse.FieldMappingMetaData fieldMappingMetaData = watchRecord.get("result.actions.transform.payload");
assertThat(fieldMappingMetaData.isNull(), is(true));

View File

@ -5,80 +5,153 @@
*/
package org.elasticsearch.xpack.watcher.support;
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
import org.elasticsearch.client.AdminClient;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.cluster.ClusterChangedEvent;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.block.ClusterBlocks;
import org.elasticsearch.cluster.metadata.IndexTemplateMetaData;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.gateway.GatewayService;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.security.InternalClient;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.function.Function;
import java.util.Set;
import java.util.stream.Collectors;
import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.core.Is.is;
import static org.elasticsearch.mock.orig.Mockito.verify;
import static org.elasticsearch.mock.orig.Mockito.when;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.startsWith;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@ESIntegTestCase.ClusterScope(scope = TEST, numClientNodes = 0, transportClientRatio = 0, randomDynamicTemplates = false,
supportsDedicatedMasters = false, numDataNodes = 1)
public class WatcherIndexTemplateRegistryTests extends AbstractWatcherIntegrationTestCase {
public class WatcherIndexTemplateRegistryTests extends ESTestCase {
@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
ArrayList<Class<? extends Plugin>> plugins = new ArrayList<>(super.nodePlugins());
plugins.add(SettingTestPlugin.class);
return plugins;
private WatcherIndexTemplateRegistry registry;
private Client client;
@Before
public void createRegistryAndClient() {
Set<Setting<?>> registeredSettings = new HashSet<>();
registeredSettings.add(WatcherIndexTemplateRegistry.HISTORY_TEMPLATE_SETTING);
registeredSettings.add(WatcherIndexTemplateRegistry.TRIGGERED_TEMPLATE_SETTING);
registeredSettings.add(WatcherIndexTemplateRegistry.WATCHES_TEMPLATE_SETTING);
ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, registeredSettings);
ThreadPool threadPool = mock(ThreadPool.class);
when(threadPool.getThreadContext()).thenReturn(new ThreadContext(Settings.EMPTY));
when(threadPool.generic()).thenReturn(EsExecutors.newDirectExecutorService());
client = mock(Client.class);
InternalClient internalClient = new InternalClient(Settings.EMPTY, threadPool, client);
AdminClient adminClient = mock(AdminClient.class);
IndicesAdminClient indicesAdminClient = mock(IndicesAdminClient.class);
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(client.admin()).thenReturn(adminClient);
ClusterService clusterService = mock(ClusterService.class);
registry = new WatcherIndexTemplateRegistry(Settings.EMPTY, clusterSettings, clusterService, threadPool, internalClient);
}
public void testTemplates() throws Exception {
assertAcked(
client().admin().cluster().prepareUpdateSettings()
.setTransientSettings(Settings.builder()
.put("xpack.watcher.history.index.key1", "value"))
.get()
);
private ClusterChangedEvent createClusterChangedEvent(List<String> existingTemplateNames) {
ClusterChangedEvent event = mock(ClusterChangedEvent.class);
when(event.localNodeMaster()).thenReturn(true);
ClusterState cs = mock(ClusterState.class);
ClusterBlocks clusterBlocks = mock(ClusterBlocks.class);
when(clusterBlocks.hasGlobalBlock(eq(GatewayService.STATE_NOT_RECOVERED_BLOCK))).thenReturn(false);
when(cs.blocks()).thenReturn(clusterBlocks);
when(event.state()).thenReturn(cs);
assertBusy(new Runnable() {
@Override
public void run() {
GetIndexTemplatesResponse response = client().admin().indices()
.prepareGetTemplates(WatcherIndexTemplateRegistry.HISTORY_TEMPLATE_NAME).get();
assertThat(response.getIndexTemplates().size(), equalTo(1));
// setting from the file on the classpath:
assertThat(response.getIndexTemplates().get(0).getSettings().getAsBoolean("index.mapper.dynamic", null), is(false));
// additional setting defined in the node settings:
assertThat(response.getIndexTemplates().get(0).getSettings().get("index.key1"), equalTo("value"));
}
});
// Now delete the index template and verify the index template gets added back:
assertAcked(client().admin().indices().prepareDeleteTemplate(WatcherIndexTemplateRegistry.HISTORY_TEMPLATE_NAME).get());
assertBusy(new Runnable() {
@Override
public void run() {
GetIndexTemplatesResponse response = client().admin().indices()
.prepareGetTemplates(WatcherIndexTemplateRegistry.HISTORY_TEMPLATE_NAME).get();
assertThat(response.getIndexTemplates().size(), equalTo(1));
// setting from the file on the classpath:
assertThat(response.getIndexTemplates().get(0).getSettings().getAsBoolean("index.mapper.dynamic", null), is(false));
// additional setting defined in the node settings:
assertThat(response.getIndexTemplates().get(0).getSettings().get("index.key1"), equalTo("value"));
}
});
MetaData metaData = mock(MetaData.class);
ImmutableOpenMap.Builder<String, IndexTemplateMetaData> indexTemplates = ImmutableOpenMap.builder();
for (String name : existingTemplateNames) {
indexTemplates.put(name, mock(IndexTemplateMetaData.class));
}
public static class SettingTestPlugin extends Plugin {
when(metaData.getTemplates()).thenReturn(indexTemplates.build());
when(cs.metaData()).thenReturn(metaData);
public static final Setting<String> KEY_1 = new Setting<>("index.key1", "", Function.identity(), Setting.Property.IndexScope);
return event;
}
@Override
public List<Setting<?>> getSettings() {
return Collections.singletonList(KEY_1);
}
public void testThatDeprecatedTemplatesAreRemovedOnce() throws Exception {
List<String> templateNames = new ArrayList<>();
// old index templates to be deleted
boolean containsWatchesTemplate = randomBoolean();
if (containsWatchesTemplate) {
templateNames.add("watches");
}
boolean containsTriggeredWatchesTemplates = randomBoolean();
if (containsTriggeredWatchesTemplates) {
templateNames.add("triggered_watches");
}
boolean containsVersionedWatchHistoryTemplate = randomBoolean();
if (containsVersionedWatchHistoryTemplate) {
templateNames.add("watcher_history_" + randomIntBetween(0, 100));
}
List<String> templatesInClusterState = new ArrayList<>();
templatesInClusterState.addAll(Arrays.asList(WatcherIndexTemplateRegistry.HISTORY_TEMPLATE_NAME,
WatcherIndexTemplateRegistry.TRIGGERED_TEMPLATE_NAME, WatcherIndexTemplateRegistry.WATCHES_TEMPLATE_NAME));
templatesInClusterState.addAll(templateNames);
ClusterChangedEvent event = createClusterChangedEvent(templatesInClusterState);
registry.clusterChanged(event);
ArgumentCaptor<DeleteIndexTemplateRequest> requestArgumentCaptor = ArgumentCaptor.forClass(DeleteIndexTemplateRequest.class);
verify(client, times(templateNames.size())).execute(anyObject(), requestArgumentCaptor.capture(), anyObject());
assertThat(requestArgumentCaptor.getAllValues(), hasSize(templateNames.size()));
List<String> deletedTemplateNames = requestArgumentCaptor.getAllValues().stream().map(DeleteIndexTemplateRequest::name)
.collect(Collectors.toList());
if (containsWatchesTemplate) {
assertThat(deletedTemplateNames, hasItem("watches"));
}
if (containsTriggeredWatchesTemplates) {
assertThat(deletedTemplateNames, hasItem("triggered_watches"));
}
if (containsVersionedWatchHistoryTemplate) {
assertThat(deletedTemplateNames, hasItem(startsWith("watcher_history_")));
}
// a second event with removed templates should not trigger any further requests, so the invocation count stays the same
ClusterChangedEvent newEvent = createClusterChangedEvent(Arrays.asList(WatcherIndexTemplateRegistry.HISTORY_TEMPLATE_NAME,
WatcherIndexTemplateRegistry.TRIGGERED_TEMPLATE_NAME, WatcherIndexTemplateRegistry.WATCHES_TEMPLATE_NAME));
registry.clusterChanged(newEvent);
verify(client, times(templateNames.size())).execute(anyObject(), anyObject(), anyObject());
}
public void testThatNonExistingTemplatesAreAddedImmediately() {
ClusterChangedEvent event = createClusterChangedEvent(Collections.emptyList());
registry.clusterChanged(event);
ArgumentCaptor<PutIndexTemplateRequest> argumentCaptor = ArgumentCaptor.forClass(PutIndexTemplateRequest.class);
verify(client, times(3)).execute(anyObject(), argumentCaptor.capture(), anyObject());
// now delete one template from the cluster state and lets retry
ClusterChangedEvent newEvent = createClusterChangedEvent(Arrays.asList(WatcherIndexTemplateRegistry.HISTORY_TEMPLATE_NAME,
WatcherIndexTemplateRegistry.TRIGGERED_TEMPLATE_NAME));
registry.clusterChanged(newEvent);
verify(client, times(4)).execute(anyObject(), argumentCaptor.capture(), anyObject());
}
}

View File

@ -334,7 +334,7 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase
// alias for .triggered-watches, ensuring the index template is set appropriately
if (rarely()) {
String newIndex = ".triggered-watches-alias-index";
BytesReference bytesReference = TemplateUtils.load("/triggered_watches.json");
BytesReference bytesReference = TemplateUtils.load("/triggered-watches.json");
try (XContentParser parser = createParser(JsonXContent.jsonXContent, bytesReference.toBytesRef().bytes)) {
Map<String, Object> parserMap = parser.map();
Map<String, Object> allMappings = (Map<String, Object>) parserMap.get("mappings");
@ -484,16 +484,6 @@ public abstract class AbstractWatcherIntegrationTestCase extends ESIntegTestCase
return builder.get();
}
protected long historyRecordsCount(String watchName) {
refresh();
SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*")
.setIndicesOptions(IndicesOptions.lenientExpandOpen())
.setSize(0)
.setQuery(matchQuery("watch_id", watchName))
.get();
return searchResponse.getHits().getTotalHits();
}
protected long findNumberOfPerformedActions(String watchName) {
refresh();
SearchResponse searchResponse = client().prepareSearch(HistoryStore.INDEX_PREFIX_WITH_TEMPLATE + "*")

View File

@ -104,17 +104,17 @@ public class HistoryIntegrationTests extends AbstractWatcherIntegrationTestCase
assertHitCount(searchResponse, 1);
// as fields with dots are allowed in 5.0 again, the mapping must be checked in addition
GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*").addTypes("watch_record").get();
byte[] bytes = response.getMappings().values().iterator().next().value.get("watch_record").source().uncompressed();
GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*").addTypes("doc").get();
byte[] bytes = response.getMappings().values().iterator().next().value.get("doc").source().uncompressed();
XContentSource source = new XContentSource(new BytesArray(bytes), XContentType.JSON);
// lets make sure the body fields are disabled
if (useChained) {
String chainedPath = "watch_record.properties.result.properties.input.properties.chain.properties.chained.properties.search" +
String chainedPath = "doc.properties.result.properties.input.properties.chain.properties.chained.properties.search" +
".properties.request.properties.body.enabled";
assertThat(source.getValue(chainedPath), is(false));
} else {
String path =
"watch_record.properties.result.properties.input.properties.search.properties.request.properties.body.enabled";
"doc.properties.result.properties.input.properties.search.properties.request.properties.body.enabled";
assertThat(source.getValue(path), is(false));
}
}
@ -143,16 +143,16 @@ public class HistoryIntegrationTests extends AbstractWatcherIntegrationTestCase
assertHitCount(searchResponse, 1);
// as fields with dots are allowed in 5.0 again, the mapping must be checked in addition
GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*").addTypes("watch_record").get();
byte[] bytes = response.getMappings().values().iterator().next().value.get("watch_record").source().uncompressed();
GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*").addTypes("doc").get();
byte[] bytes = response.getMappings().values().iterator().next().value.get("doc").source().uncompressed();
XContentSource source = new XContentSource(new BytesArray(bytes), XContentType.JSON);
// lets make sure the body fields are disabled
if (useChained) {
String path = "watch_record.properties.result.properties.input.properties.chain.properties.chained.properties.payload.enabled";
String path = "doc.properties.result.properties.input.properties.chain.properties.chained.properties.payload.enabled";
assertThat(source.getValue(path), is(false));
} else {
String path = "watch_record.properties.result.properties.input.properties.payload.enabled";
String path = "doc.properties.result.properties.input.properties.payload.enabled";
assertThat(source.getValue(path), is(false));
}
}
@ -197,11 +197,11 @@ public class HistoryIntegrationTests extends AbstractWatcherIntegrationTestCase
assertThat(lastExecutionSuccesful, is(actionStatus.lastExecution().successful()));
// also ensure that the status field is disabled in the watch history
GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*").addTypes("watch_record").get();
byte[] bytes = response.getMappings().values().iterator().next().value.get("watch_record").source().uncompressed();
GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*").addTypes("doc").get();
byte[] bytes = response.getMappings().values().iterator().next().value.get("doc").source().uncompressed();
XContentSource mappingSource = new XContentSource(new BytesArray(bytes), XContentType.JSON);
assertThat(mappingSource.getValue("watch_record.properties.status.enabled"), is(false));
assertThat(mappingSource.getValue("watch_record.properties.status.properties.status"), is(nullValue()));
assertThat(mappingSource.getValue("watch_record.properties.status.properties.status.properties.active"), is(nullValue()));
assertThat(mappingSource.getValue("doc.properties.status.enabled"), is(false));
assertThat(mappingSource.getValue("doc.properties.status.properties.status"), is(nullValue()));
assertThat(mappingSource.getValue("doc.properties.status.properties.status.properties.active"), is(nullValue()));
}
}

View File

@ -90,13 +90,13 @@ public class ActivateWatchTests extends AbstractWatcherIntegrationTestCase {
logger.info("Ensured no more watches are being executed");
refresh();
long count1 = docCount(".watcher-history*", "watch_record", matchAllQuery());
long count1 = docCount(".watcher-history*", "doc", matchAllQuery());
logger.info("Sleeping for 5 seconds, watch history count [{}]", count1);
Thread.sleep(5000);
refresh();
long count2 = docCount(".watcher-history*", "watch_record", matchAllQuery());
long count2 = docCount(".watcher-history*", "doc", matchAllQuery());
assertThat(count2, is(count1));
@ -114,7 +114,7 @@ public class ActivateWatchTests extends AbstractWatcherIntegrationTestCase {
logger.info("Sleeping for another five seconds, ensuring that watch is executed");
Thread.sleep(5000);
refresh();
long count3 = docCount(".watcher-history*", "watch_record", matchAllQuery());
long count3 = docCount(".watcher-history*", "doc", matchAllQuery());
assertThat(count3, greaterThan(count1));
}

View File

@ -75,7 +75,7 @@
index: ".watcher-history-*"
- match: { hits.total: 1 }
- match: { hits.hits.0._type: "watch_record" }
- match: { hits.hits.0._type: "doc" }
- match: { hits.hits.0._source.watch_id: "jira_watch" }
- match: { hits.hits.0._source.state: "executed" }
@ -195,7 +195,7 @@
- match: { hits.total: 1 }
- match: { hits.hits.0._type: "watch_record" }
- match: { hits.hits.0._type: "doc" }
- match: { hits.hits.0._source.watch_id: "wrong_jira_watch" }
- match: { hits.hits.0._source.state: "executed" }