Search in sources :

Example 1 with MASTER

use of org.elasticsearch.cluster.node.DiscoveryNode.Role.MASTER in project elasticsearch by elastic.

the class InternalTestClusterTests method testDifferentRolesMaintainPathOnRestart.

public void testDifferentRolesMaintainPathOnRestart() throws Exception {
    final Path baseDir = createTempDir();
    final int numNodes = 5;
    InternalTestCluster cluster = new InternalTestCluster(randomLong(), baseDir, true, true, 0, 0, "test", new NodeConfigurationSource() {

        @Override
        public Settings nodeSettings(int nodeOrdinal) {
            return Settings.builder().put(NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING.getKey(), numNodes).put(NetworkModule.HTTP_ENABLED.getKey(), false).put(NetworkModule.TRANSPORT_TYPE_KEY, MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME).put(DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey(), 0).build();
        }

        @Override
        public Settings transportClientSettings() {
            return Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME).build();
        }
    }, 0, randomBoolean(), "", Arrays.asList(MockTcpTransportPlugin.class, TestZenDiscovery.TestPlugin.class), Function.identity());
    cluster.beforeTest(random(), 0.0);
    try {
        Map<DiscoveryNode.Role, Set<String>> pathsPerRole = new HashMap<>();
        for (int i = 0; i < numNodes; i++) {
            final DiscoveryNode.Role role = i == numNodes - 1 && pathsPerRole.containsKey(MASTER) == false ? // last noe and still no master ofr the cluster
            MASTER : randomFrom(MASTER, DiscoveryNode.Role.DATA, DiscoveryNode.Role.INGEST);
            final String node;
            switch(role) {
                case MASTER:
                    node = cluster.startMasterOnlyNode(Settings.EMPTY);
                    break;
                case DATA:
                    node = cluster.startDataOnlyNode(Settings.EMPTY);
                    break;
                case INGEST:
                    node = cluster.startCoordinatingOnlyNode(Settings.EMPTY);
                    break;
                default:
                    throw new IllegalStateException("get your story straight");
            }
            Set<String> rolePaths = pathsPerRole.computeIfAbsent(role, k -> new HashSet<>());
            for (Path path : getNodePaths(cluster, node)) {
                assertTrue(rolePaths.add(path.toString()));
            }
        }
        cluster.fullRestart();
        Map<DiscoveryNode.Role, Set<String>> result = new HashMap<>();
        for (String name : cluster.getNodeNames()) {
            DiscoveryNode node = cluster.getInstance(ClusterService.class, name).localNode();
            List<String> paths = Arrays.stream(getNodePaths(cluster, name)).map(Path::toString).collect(Collectors.toList());
            if (node.isMasterNode()) {
                result.computeIfAbsent(MASTER, k -> new HashSet<>()).addAll(paths);
            } else if (node.isDataNode()) {
                result.computeIfAbsent(DATA, k -> new HashSet<>()).addAll(paths);
            } else {
                result.computeIfAbsent(INGEST, k -> new HashSet<>()).addAll(paths);
            }
        }
        assertThat(result.size(), equalTo(pathsPerRole.size()));
        for (DiscoveryNode.Role role : result.keySet()) {
            assertThat("path are not the same for " + role, result.get(role), equalTo(pathsPerRole.get(role)));
        }
    } finally {
        cluster.close();
    }
}
Also used : Path(java.nio.file.Path) InternalTestCluster(org.elasticsearch.test.InternalTestCluster) Arrays(java.util.Arrays) NetworkModule(org.elasticsearch.common.network.NetworkModule) ClusterService(org.elasticsearch.cluster.service.ClusterService) Matchers.not(org.hamcrest.Matchers.not) MockTcpTransportPlugin(org.elasticsearch.transport.MockTcpTransportPlugin) HashMap(java.util.HashMap) Random(java.util.Random) ElasticsearchAssertions.assertFileNotExists(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFileNotExists) Function(java.util.function.Function) HashSet(java.util.HashSet) INGEST(org.elasticsearch.cluster.node.DiscoveryNode.Role.INGEST) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) Map(java.util.Map) ClusterName(org.elasticsearch.cluster.ClusterName) ESTestCase(org.elasticsearch.test.ESTestCase) Path(java.nio.file.Path) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) DATA(org.elasticsearch.cluster.node.DiscoveryNode.Role.DATA) Iterator(java.util.Iterator) Files(java.nio.file.Files) Client(org.elasticsearch.client.Client) DiscoverySettings(org.elasticsearch.discovery.DiscoverySettings) IOUtils(org.apache.lucene.util.IOUtils) Plugin(org.elasticsearch.plugins.Plugin) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) List(java.util.List) ElasticsearchAssertions.assertFileExists(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFileExists) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) MASTER(org.elasticsearch.cluster.node.DiscoveryNode.Role.MASTER) TransportSettings(org.elasticsearch.transport.TransportSettings) Matchers.equalTo(org.hamcrest.Matchers.equalTo) NodeConfigurationSource(org.elasticsearch.test.NodeConfigurationSource) DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING(org.elasticsearch.discovery.zen.ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING) LuceneTestCase(org.apache.lucene.util.LuceneTestCase) Collections(java.util.Collections) TestZenDiscovery(org.elasticsearch.test.discovery.TestZenDiscovery) MockTcpTransportPlugin(org.elasticsearch.transport.MockTcpTransportPlugin) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) InternalTestCluster(org.elasticsearch.test.InternalTestCluster) NodeConfigurationSource(org.elasticsearch.test.NodeConfigurationSource) ClusterService(org.elasticsearch.cluster.service.ClusterService) Settings(org.elasticsearch.common.settings.Settings) DiscoverySettings(org.elasticsearch.discovery.DiscoverySettings) TransportSettings(org.elasticsearch.transport.TransportSettings) HashSet(java.util.HashSet)

Aggregations

IOException (java.io.IOException)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 IOUtils (org.apache.lucene.util.IOUtils)1 LuceneTestCase (org.apache.lucene.util.LuceneTestCase)1 Client (org.elasticsearch.client.Client)1 ClusterName (org.elasticsearch.cluster.ClusterName)1 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)1 DATA (org.elasticsearch.cluster.node.DiscoveryNode.Role.DATA)1