Merge branch 'master' into feature/sql

Original commit: elastic/x-pack-elasticsearch@00ac1d607b
This commit is contained in:
javanna 2017-12-06 09:31:20 +01:00 committed by Luca Cavanna
commit 66c4962be9
4 changed files with 35 additions and 22 deletions

View File

@ -6,6 +6,7 @@
package org.elasticsearch.xpack.security; package org.elasticsearch.xpack.security;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
@ -220,8 +221,8 @@ public class SecurityLifecycleServiceTests extends ESTestCase {
IndexLifecycleManager.TEMPLATE_VERSION_PATTERN); IndexLifecycleManager.TEMPLATE_VERSION_PATTERN);
PutIndexTemplateRequest request = new PutIndexTemplateRequest(); PutIndexTemplateRequest request = new PutIndexTemplateRequest();
request.source(template, XContentType.JSON); request.source(template, XContentType.JSON);
IndexTemplateMetaData.Builder templateBuilder = IndexTemplateMetaData.Builder templateBuilder = IndexTemplateMetaData.builder(templateName)
IndexTemplateMetaData.builder(templateName); .patterns(Arrays.asList(generateRandomStringArray(10, 100, false, false)));
for (Map.Entry<String, String> entry : request.mappings().entrySet()) { for (Map.Entry<String, String> entry : request.mappings().entrySet()) {
templateBuilder.putMapping(entry.getKey(), entry.getValue()); templateBuilder.putMapping(entry.getKey(), entry.getValue());
} }

View File

@ -6,6 +6,7 @@
package org.elasticsearch.xpack.security.support; package org.elasticsearch.xpack.security.support;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
@ -304,7 +305,8 @@ public class IndexLifecycleManagerTests extends ESTestCase {
private static IndexTemplateMetaData.Builder getIndexTemplateMetaData(String templateName) throws IOException { private static IndexTemplateMetaData.Builder getIndexTemplateMetaData(String templateName) throws IOException {
final Map<String, String> mappings = getTemplateMappings(templateName); final Map<String, String> mappings = getTemplateMappings(templateName);
IndexTemplateMetaData.Builder templateBuilder = IndexTemplateMetaData.builder(TEMPLATE_NAME); IndexTemplateMetaData.Builder templateBuilder = IndexTemplateMetaData.builder(TEMPLATE_NAME)
.patterns(Arrays.asList(generateRandomStringArray(10, 100, false, false)));
for (Map.Entry<String, String> entry : mappings.entrySet()) { for (Map.Entry<String, String> entry : mappings.entrySet()) {
templateBuilder.putMapping(entry.getKey(), entry.getValue()); templateBuilder.putMapping(entry.getKey(), entry.getValue());
} }

View File

@ -37,7 +37,10 @@ import org.mockito.stubbing.Answer;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING; import static org.elasticsearch.cluster.routing.ShardRoutingState.RELOCATING;
@ -87,9 +90,9 @@ public class WatcherLifeCycleServiceTests extends ESTestCase {
IndexRoutingTable watchRoutingTable = IndexRoutingTable.builder(new Index(Watch.INDEX, "foo")).build(); IndexRoutingTable watchRoutingTable = IndexRoutingTable.builder(new Index(Watch.INDEX, "foo")).build();
ClusterState clusterState = ClusterState.builder(new ClusterName("my-cluster")) ClusterState clusterState = ClusterState.builder(new ClusterName("my-cluster"))
.metaData(MetaData.builder() .metaData(MetaData.builder()
.put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME)) .put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME).patterns(randomIndexPatterns()))
.put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME)) .put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME).patterns(randomIndexPatterns()))
.put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME)) .put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME).patterns(randomIndexPatterns()))
.build()) .build())
.nodes(new DiscoveryNodes.Builder().masterNodeId("node_1").localNodeId("node_1").add(newNode("node_1"))) .nodes(new DiscoveryNodes.Builder().masterNodeId("node_1").localNodeId("node_1").add(newNode("node_1")))
.routingTable(RoutingTable.builder().add(watchRoutingTable).build()) .routingTable(RoutingTable.builder().add(watchRoutingTable).build())
@ -124,9 +127,9 @@ public class WatcherLifeCycleServiceTests extends ESTestCase {
.nodes(new DiscoveryNodes.Builder().masterNodeId("node_1").localNodeId("node_1").add(newNode("node_1"))) .nodes(new DiscoveryNodes.Builder().masterNodeId("node_1").localNodeId("node_1").add(newNode("node_1")))
.routingTable(RoutingTable.builder().add(watchRoutingTable).build()) .routingTable(RoutingTable.builder().add(watchRoutingTable).build())
.metaData(MetaData.builder() .metaData(MetaData.builder()
.put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME)) .put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME).patterns(randomIndexPatterns()))
.put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME)) .put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME).patterns(randomIndexPatterns()))
.put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME)) .put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME).patterns(randomIndexPatterns()))
.build()) .build())
.build(); .build();
@ -153,9 +156,9 @@ public class WatcherLifeCycleServiceTests extends ESTestCase {
clusterState = ClusterState.builder(new ClusterName("my-cluster")) clusterState = ClusterState.builder(new ClusterName("my-cluster"))
.nodes(new DiscoveryNodes.Builder().masterNodeId("node_1").localNodeId("node_1").add(newNode("node_1"))) .nodes(new DiscoveryNodes.Builder().masterNodeId("node_1").localNodeId("node_1").add(newNode("node_1")))
.metaData(MetaData.builder() .metaData(MetaData.builder()
.put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME)) .put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME).patterns(randomIndexPatterns()))
.put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME)) .put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME).patterns(randomIndexPatterns()))
.put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME)) .put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME).patterns(randomIndexPatterns()))
.build()) .build())
.build(); .build();
when(watcherService.state()).thenReturn(WatcherState.STARTED); when(watcherService.state()).thenReturn(WatcherState.STARTED);
@ -166,9 +169,9 @@ public class WatcherLifeCycleServiceTests extends ESTestCase {
ClusterState previousClusterState = ClusterState.builder(new ClusterName("my-cluster")) ClusterState previousClusterState = ClusterState.builder(new ClusterName("my-cluster"))
.nodes(new DiscoveryNodes.Builder().masterNodeId("node_1").localNodeId("node_1").add(newNode("node_1"))) .nodes(new DiscoveryNodes.Builder().masterNodeId("node_1").localNodeId("node_1").add(newNode("node_1")))
.metaData(MetaData.builder() .metaData(MetaData.builder()
.put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME)) .put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME).patterns(randomIndexPatterns()))
.put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME)) .put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME).patterns(randomIndexPatterns()))
.put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME)) .put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME).patterns(randomIndexPatterns()))
.build()) .build())
.build(); .build();
when(watcherService.validate(clusterState)).thenReturn(true); when(watcherService.validate(clusterState)).thenReturn(true);
@ -440,9 +443,9 @@ public class WatcherLifeCycleServiceTests extends ESTestCase {
ClusterState state = ClusterState.builder(new ClusterName("my-cluster")) ClusterState state = ClusterState.builder(new ClusterName("my-cluster"))
.nodes(nodes) .nodes(nodes)
.metaData(MetaData.builder() .metaData(MetaData.builder()
.put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME)) .put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME).patterns(randomIndexPatterns()))
.put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME)) .put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME).patterns(randomIndexPatterns()))
.put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME)) .put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME).patterns(randomIndexPatterns()))
.build()) .build())
.build(); .build();
when(watcherService.validate(eq(state))).thenReturn(true); when(watcherService.validate(eq(state))).thenReturn(true);
@ -461,17 +464,17 @@ public class WatcherLifeCycleServiceTests extends ESTestCase {
MetaData.Builder metaDataBuilder = MetaData.builder(); MetaData.Builder metaDataBuilder = MetaData.builder();
boolean isHistoryTemplateAdded = randomBoolean(); boolean isHistoryTemplateAdded = randomBoolean();
if (isHistoryTemplateAdded) { if (isHistoryTemplateAdded) {
metaDataBuilder.put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME)); metaDataBuilder.put(IndexTemplateMetaData.builder(HISTORY_TEMPLATE_NAME).patterns(randomIndexPatterns()));
} }
boolean isTriggeredTemplateAdded = randomBoolean(); boolean isTriggeredTemplateAdded = randomBoolean();
if (isTriggeredTemplateAdded) { if (isTriggeredTemplateAdded) {
metaDataBuilder.put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME)); metaDataBuilder.put(IndexTemplateMetaData.builder(TRIGGERED_TEMPLATE_NAME).patterns(randomIndexPatterns()));
} }
boolean isWatchesTemplateAdded = randomBoolean(); boolean isWatchesTemplateAdded = randomBoolean();
if (isWatchesTemplateAdded) { if (isWatchesTemplateAdded) {
// ensure not all templates are added, otherwise life cycle service would start // ensure not all templates are added, otherwise life cycle service would start
if ((isHistoryTemplateAdded || isTriggeredTemplateAdded) == false) { if ((isHistoryTemplateAdded || isTriggeredTemplateAdded) == false) {
metaDataBuilder.put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME)); metaDataBuilder.put(IndexTemplateMetaData.builder(WATCHES_TEMPLATE_NAME).patterns(randomIndexPatterns()));
} }
} }
ClusterState state = ClusterState.builder(new ClusterName("my-cluster")).nodes(nodes).metaData(metaDataBuilder).build(); ClusterState state = ClusterState.builder(new ClusterName("my-cluster")).nodes(nodes).metaData(metaDataBuilder).build();
@ -482,6 +485,12 @@ public class WatcherLifeCycleServiceTests extends ESTestCase {
verify(watcherService, times(0)).start(any(ClusterState.class)); verify(watcherService, times(0)).start(any(ClusterState.class));
} }
private List<String> randomIndexPatterns() {
return IntStream.range(0, between(1, 10))
.mapToObj(n -> randomAlphaOfLengthBetween(1, 100))
.collect(Collectors.toList());
}
private static DiscoveryNode newNode(String nodeName) { private static DiscoveryNode newNode(String nodeName) {
return newNode(nodeName, Version.CURRENT); return newNode(nodeName, Version.CURRENT);
} }

View File

@ -154,7 +154,8 @@ public class WatcherIndexTemplateRegistryTests extends ESTestCase {
private ClusterState createClusterState(String ... existingTemplates) { private ClusterState createClusterState(String ... existingTemplates) {
MetaData.Builder metaDataBuilder = MetaData.builder(); MetaData.Builder metaDataBuilder = MetaData.builder();
for (String templateName : existingTemplates) { for (String templateName : existingTemplates) {
metaDataBuilder.put(IndexTemplateMetaData.builder(templateName)); metaDataBuilder.put(IndexTemplateMetaData.builder(templateName)
.patterns(Arrays.asList(generateRandomStringArray(10, 100, false, false))));
} }
return ClusterState.builder(new ClusterName("foo")).metaData(metaDataBuilder.build()).build(); return ClusterState.builder(new ClusterName("foo")).metaData(metaDataBuilder.build()).build();