Search in sources :

Example 1 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project crate by crate.

the class DefaultTemplateServiceTest method testAddDefaultTemplate.

@Test
public void testAddDefaultTemplate() throws Exception {
    ClusterState state = ClusterState.builder(new ClusterName("foo")).build();
    ClusterState newState = DefaultTemplateService.addDefaultTemplate(state);
    assertThat(newState.getMetaData().templates().containsKey(DefaultTemplateService.TEMPLATE_NAME), is(true));
    // verify that it doesn't fail it the template already exists
    newState = DefaultTemplateService.addDefaultTemplate(newState);
    assertThat(newState.getMetaData().templates().containsKey(DefaultTemplateService.TEMPLATE_NAME), is(true));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterName(org.elasticsearch.cluster.ClusterName) Test(org.junit.Test)

Example 2 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project crate by crate.

the class SnapshotRestoreAnalyzerTest method before.

@Before
public void before() throws Exception {
    RepositoriesMetaData repositoriesMetaData = new RepositoriesMetaData(new RepositoryMetaData("my_repo", "fs", Settings.builder().put("location", "/tmp/my_repo").build()));
    ClusterState clusterState = ClusterState.builder(new ClusterName("testing")).metaData(MetaData.builder().putCustom(RepositoriesMetaData.TYPE, repositoriesMetaData)).build();
    NoopClusterService clusterService = new NoopClusterService(clusterState);
    executor = SQLExecutor.builder(clusterService).addDocTable(USER_TABLE_INFO).addDocTable(TEST_DOC_LOCATIONS_TABLE_INFO).addDocTable(TEST_PARTITIONED_TABLE_INFO).build();
}
Also used : RepositoriesMetaData(org.elasticsearch.cluster.metadata.RepositoriesMetaData) ClusterState(org.elasticsearch.cluster.ClusterState) RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) ClusterName(org.elasticsearch.cluster.ClusterName) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) Before(org.junit.Before)

Example 3 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class ScriptContextTests method makeScriptService.

ScriptService makeScriptService() throws Exception {
    Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), "false").put("script." + PLUGIN_NAME + "_custom_globally_disabled_op", "false").put("script.engine." + MockScriptEngine.NAME + ".inline." + PLUGIN_NAME + "_custom_exp_disabled_op", "false").build();
    MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME, Collections.singletonMap("1", script -> "1"));
    ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(scriptEngine));
    List<ScriptContext.Plugin> customContexts = Arrays.asList(new ScriptContext.Plugin(PLUGIN_NAME, "custom_op"), new ScriptContext.Plugin(PLUGIN_NAME, "custom_exp_disabled_op"), new ScriptContext.Plugin(PLUGIN_NAME, "custom_globally_disabled_op"));
    ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customContexts);
    ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
    ScriptService scriptService = new ScriptService(settings, new Environment(settings), null, scriptEngineRegistry, scriptContextRegistry, scriptSettings);
    ClusterState empty = ClusterState.builder(new ClusterName("_name")).build();
    ScriptMetaData smd = empty.metaData().custom(ScriptMetaData.TYPE);
    smd = ScriptMetaData.putStoredScript(smd, "1", new StoredScriptSource(MockScriptEngine.NAME, "1", Collections.emptyMap()));
    MetaData.Builder mdb = MetaData.builder(empty.getMetaData()).putCustom(ScriptMetaData.TYPE, smd);
    ClusterState stored = ClusterState.builder(empty).metaData(mdb).build();
    scriptService.clusterChanged(new ClusterChangedEvent("test", stored, empty));
    return scriptService;
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) ClusterState(org.elasticsearch.cluster.ClusterState) Arrays(java.util.Arrays) List(java.util.List) Settings(org.elasticsearch.common.settings.Settings) Environment(org.elasticsearch.env.Environment) ClusterName(org.elasticsearch.cluster.ClusterName) ESTestCase(org.elasticsearch.test.ESTestCase) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) Collections(java.util.Collections) Matchers.containsString(org.hamcrest.Matchers.containsString) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) MetaData(org.elasticsearch.cluster.metadata.MetaData) Environment(org.elasticsearch.env.Environment) ClusterName(org.elasticsearch.cluster.ClusterName) Settings(org.elasticsearch.common.settings.Settings)

Example 4 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class NodeRemovalClusterStateTaskExecutorTests method testNotEnoughMasterNodesAfterRemove.

public void testNotEnoughMasterNodesAfterRemove() throws Exception {
    final ElectMasterService electMasterService = mock(ElectMasterService.class);
    when(electMasterService.hasEnoughMasterNodes(any(Iterable.class))).thenReturn(false);
    final AllocationService allocationService = mock(AllocationService.class);
    final AtomicBoolean rejoinCalled = new AtomicBoolean();
    final Consumer<String> submitRejoin = source -> rejoinCalled.set(true);
    final AtomicReference<ClusterState> remainingNodesClusterState = new AtomicReference<>();
    final ZenDiscovery.NodeRemovalClusterStateTaskExecutor executor = new ZenDiscovery.NodeRemovalClusterStateTaskExecutor(allocationService, electMasterService, submitRejoin, logger) {

        @Override
        ClusterState remainingNodesClusterState(ClusterState currentState, DiscoveryNodes.Builder remainingNodesBuilder) {
            remainingNodesClusterState.set(super.remainingNodesClusterState(currentState, remainingNodesBuilder));
            return remainingNodesClusterState.get();
        }
    };
    final DiscoveryNodes.Builder builder = DiscoveryNodes.builder();
    final int nodes = randomIntBetween(2, 16);
    final List<ZenDiscovery.NodeRemovalClusterStateTaskExecutor.Task> tasks = new ArrayList<>();
    // to ensure there is at least one removal
    boolean first = true;
    for (int i = 0; i < nodes; i++) {
        final DiscoveryNode node = node(i);
        builder.add(node);
        if (first || randomBoolean()) {
            tasks.add(new ZenDiscovery.NodeRemovalClusterStateTaskExecutor.Task(node, randomBoolean() ? "left" : "failed"));
        }
        first = false;
    }
    final ClusterState clusterState = ClusterState.builder(new ClusterName("test")).nodes(builder).build();
    final ClusterStateTaskExecutor.ClusterTasksResult<ZenDiscovery.NodeRemovalClusterStateTaskExecutor.Task> result = executor.execute(clusterState, tasks);
    verify(electMasterService).hasEnoughMasterNodes(eq(remainingNodesClusterState.get().nodes()));
    verifyNoMoreInteractions(electMasterService);
    // ensure that we did not reroute
    verifyNoMoreInteractions(allocationService);
    assertTrue(rejoinCalled.get());
    assertThat(result.resultingState, equalTo(clusterState));
    for (final ZenDiscovery.NodeRemovalClusterStateTaskExecutor.Task task : tasks) {
        assertNotNull(result.resultingState.nodes().get(task.node().getId()));
    }
}
Also used : DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterStateTaskExecutor(org.elasticsearch.cluster.ClusterStateTaskExecutor) Mockito.when(org.mockito.Mockito.when) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) Consumer(java.util.function.Consumer) Matchers.any(org.mockito.Matchers.any) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) List(java.util.List) Version(org.elasticsearch.Version) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Matchers.eq(org.mockito.Matchers.eq) StreamSupport(java.util.stream.StreamSupport) ClusterName(org.elasticsearch.cluster.ClusterName) ESTestCase(org.elasticsearch.test.ESTestCase) Mockito.mock(org.mockito.Mockito.mock) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ArrayList(java.util.ArrayList) ClusterName(org.elasticsearch.cluster.ClusterName) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) ClusterState(org.elasticsearch.cluster.ClusterState) AtomicReference(java.util.concurrent.atomic.AtomicReference) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ClusterStateTaskExecutor(org.elasticsearch.cluster.ClusterStateTaskExecutor)

Example 5 with ClusterName

use of org.elasticsearch.cluster.ClusterName in project elasticsearch by elastic.

the class ZenDiscoveryUnitTests method testPendingCSQueueIsClearedWhenClusterStatePublished.

public void testPendingCSQueueIsClearedWhenClusterStatePublished() throws Exception {
    ThreadPool threadPool = new TestThreadPool(getClass().getName());
    // randomly make minimum_master_nodes a value higher than we have nodes for, so it will force failure
    int minMasterNodes = randomBoolean() ? 3 : 1;
    Settings settings = Settings.builder().put(DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey(), Integer.toString(minMasterNodes)).build();
    ArrayDeque<Closeable> toClose = new ArrayDeque<>();
    try {
        final MockTransportService masterTransport = MockTransportService.createNewService(settings, Version.CURRENT, threadPool, null);
        masterTransport.start();
        DiscoveryNode masterNode = masterTransport.getLocalNode();
        toClose.addFirst(masterTransport);
        ClusterState state = ClusterStateCreationUtils.state(masterNode, null, masterNode);
        // build the zen discovery and cluster service
        ClusterService masterClusterService = createClusterService(threadPool, masterNode);
        toClose.addFirst(masterClusterService);
        state = ClusterState.builder(masterClusterService.getClusterName()).nodes(state.nodes()).build();
        setState(masterClusterService, state);
        ZenDiscovery masterZen = buildZenDiscovery(settings, masterTransport, masterClusterService, threadPool);
        toClose.addFirst(masterZen);
        masterTransport.acceptIncomingRequests();
        // inject a pending cluster state
        masterZen.pendingClusterStatesQueue().addPending(ClusterState.builder(new ClusterName("foreign")).build());
        // a new cluster state with a new discovery node (we will test if the cluster state
        // was updated by the presence of this node in NodesFaultDetection)
        ClusterState newState = ClusterState.builder(masterClusterService.state()).incrementVersion().nodes(DiscoveryNodes.builder(masterClusterService.state().nodes()).masterNodeId(masterNode.getId())).build();
        try {
            // publishing a new cluster state
            ClusterChangedEvent clusterChangedEvent = new ClusterChangedEvent("testing", newState, state);
            AssertingAckListener listener = new AssertingAckListener(newState.nodes().getSize() - 1);
            masterZen.publish(clusterChangedEvent, listener);
            listener.await(1, TimeUnit.HOURS);
            // publish was a success, check that queue as cleared
            assertThat(masterZen.pendingClusterStates(), emptyArray());
        } catch (Discovery.FailedToCommitClusterStateException e) {
            // not successful, so the pending queue should stay
            assertThat(masterZen.pendingClusterStates(), arrayWithSize(1));
            assertThat(masterZen.pendingClusterStates()[0].getClusterName().value(), equalTo("foreign"));
        }
    } finally {
        IOUtils.close(toClose);
        terminate(threadPool);
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ZenDiscovery.shouldIgnoreOrRejectNewClusterState(org.elasticsearch.discovery.zen.ZenDiscovery.shouldIgnoreOrRejectNewClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MockTransportService(org.elasticsearch.test.transport.MockTransportService) Closeable(java.io.Closeable) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Discovery(org.elasticsearch.discovery.Discovery) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) ArrayDeque(java.util.ArrayDeque) ClusterServiceUtils.createClusterService(org.elasticsearch.test.ClusterServiceUtils.createClusterService) ClusterService(org.elasticsearch.cluster.service.ClusterService) AssertingAckListener(org.elasticsearch.discovery.zen.PublishClusterStateActionTests.AssertingAckListener) ClusterName(org.elasticsearch.cluster.ClusterName) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

ClusterName (org.elasticsearch.cluster.ClusterName)95 ClusterState (org.elasticsearch.cluster.ClusterState)76 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)22 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)20 Settings (org.elasticsearch.common.settings.Settings)20 Matchers.containsString (org.hamcrest.Matchers.containsString)17 Version (org.elasticsearch.Version)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)12 MetaData (org.elasticsearch.cluster.metadata.MetaData)12 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)12 ArrayList (java.util.ArrayList)11 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)10 List (java.util.List)9 IndexShardRoutingTable (org.elasticsearch.cluster.routing.IndexShardRoutingTable)9 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 Collectors (java.util.stream.Collectors)8 BytesArray (org.elasticsearch.common.bytes.BytesArray)8 ESTestCase (org.elasticsearch.test.ESTestCase)8