Search in sources :

Example 41 with ClusterName

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

the class ClusterSerializationTests method testClusterStateSerialization.

public void testClusterStateSerialization() throws Exception {
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(10).numberOfReplicas(1)).build();
    RoutingTable routingTable = RoutingTable.builder().addAsNew(metaData.index("test")).build();
    DiscoveryNodes nodes = DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).add(newNode("node3")).localNodeId("node1").masterNodeId("node2").build();
    ClusterState clusterState = ClusterState.builder(new ClusterName("clusterName1")).nodes(nodes).metaData(metaData).routingTable(routingTable).build();
    AllocationService strategy = createAllocationService();
    clusterState = ClusterState.builder(clusterState).routingTable(strategy.reroute(clusterState, "reroute").routingTable()).build();
    ClusterState serializedClusterState = ClusterState.Builder.fromBytes(ClusterState.Builder.toBytes(clusterState), newNode("node1"), new NamedWriteableRegistry(ClusterModule.getNamedWriteables()));
    assertThat(serializedClusterState.getClusterName().value(), equalTo(clusterState.getClusterName().value()));
    assertThat(serializedClusterState.routingTable().toString(), equalTo(clusterState.routingTable().toString()));
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) ClusterState(org.elasticsearch.cluster.ClusterState) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ClusterName(org.elasticsearch.cluster.ClusterName) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService)

Example 42 with ClusterName

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

the class DecisionsImpactOnClusterHealthTests method runAllocationTest.

private ClusterState runAllocationTest(final Settings settings, final String indexName, final Set<AllocationDecider> allocationDeciders, final ClusterHealthStatus expectedStatus) throws IOException {
    final String clusterName = "test-cluster";
    final AllocationService allocationService = newAllocationService(settings, allocationDeciders);
    logger.info("Building initial routing table");
    final int numShards = randomIntBetween(1, 5);
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder(indexName).settings(settings(Version.CURRENT)).numberOfShards(numShards).numberOfReplicas(1)).build();
    RoutingTable routingTable = RoutingTable.builder().addAsNew(metaData.index(indexName)).build();
    ClusterState clusterState = ClusterState.builder(new ClusterName(clusterName)).metaData(metaData).routingTable(routingTable).build();
    logger.info("--> adding nodes");
    // we need at least as many nodes as shards for the THROTTLE case, because
    // once a shard has been throttled on a node, that node no longer accepts
    // any allocations on it
    final DiscoveryNodes.Builder discoveryNodes = DiscoveryNodes.builder();
    for (int i = 0; i < numShards; i++) {
        discoveryNodes.add(newNode("node" + i));
    }
    clusterState = ClusterState.builder(clusterState).nodes(discoveryNodes).build();
    logger.info("--> do the reroute");
    routingTable = allocationService.reroute(clusterState, "reroute").routingTable();
    clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
    logger.info("--> assert cluster health");
    ClusterStateHealth health = new ClusterStateHealth(clusterState);
    assertThat(health.getStatus(), equalTo(expectedStatus));
    return clusterState;
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterStateHealth(org.elasticsearch.cluster.health.ClusterStateHealth) IndexShardRoutingTable(org.elasticsearch.cluster.routing.IndexShardRoutingTable) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ClusterName(org.elasticsearch.cluster.ClusterName) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes)

Example 43 with ClusterName

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

the class RepositoryServiceTest method testRepositoryIsDroppedOnFailure.

@Test
public void testRepositoryIsDroppedOnFailure() throws Throwable {
    expectedException.expect(RepositoryException.class);
    // add repo to cluster service so that it exists..
    RepositoriesMetaData repos = new RepositoriesMetaData(new RepositoryMetaData("repo1", "fs", Settings.EMPTY));
    ClusterState state = ClusterState.builder(new ClusterName("dummy")).metaData(MetaData.builder().putCustom(RepositoriesMetaData.TYPE, repos)).build();
    ClusterService clusterService = new NoopClusterService(state);
    final ActionFilters actionFilters = mock(ActionFilters.class, Answers.RETURNS_MOCKS.get());
    IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(Settings.EMPTY);
    final AtomicBoolean deleteRepoCalled = new AtomicBoolean(false);
    TransportDeleteRepositoryAction deleteRepositoryAction = new TransportDeleteRepositoryAction(Settings.EMPTY, mock(TransportService.class, Answers.RETURNS_MOCKS.get()), clusterService, mock(RepositoriesService.class), threadPool, actionFilters, indexNameExpressionResolver) {

        @Override
        protected void doExecute(Task task, DeleteRepositoryRequest request, ActionListener<DeleteRepositoryResponse> listener) {
            deleteRepoCalled.set(true);
            listener.onResponse(mock(DeleteRepositoryResponse.class));
        }
    };
    TransportPutRepositoryAction putRepo = new TransportPutRepositoryAction(Settings.EMPTY, mock(TransportService.class, Answers.RETURNS_MOCKS.get()), clusterService, mock(RepositoriesService.class), threadPool, actionFilters, indexNameExpressionResolver) {

        @Override
        protected void doExecute(Task task, PutRepositoryRequest request, ActionListener<PutRepositoryResponse> listener) {
            listener.onFailure(new RepositoryException(request.name(), "failure"));
        }
    };
    RepositoryService repositoryService = new RepositoryService(clusterService, deleteRepositoryAction, putRepo);
    try {
        repositoryService.execute(new CreateRepositoryAnalyzedStatement("repo1", "fs", Settings.EMPTY)).get(10, TimeUnit.SECONDS);
    } catch (ExecutionException e) {
        assertThat(deleteRepoCalled.get(), is(true));
        throw e.getCause();
    }
}
Also used : RepositoriesMetaData(org.elasticsearch.cluster.metadata.RepositoriesMetaData) ClusterState(org.elasticsearch.cluster.ClusterState) Task(org.elasticsearch.tasks.Task) TransportDeleteRepositoryAction(org.elasticsearch.action.admin.cluster.repositories.delete.TransportDeleteRepositoryAction) DeleteRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest) RepositoryException(org.elasticsearch.repositories.RepositoryException) ActionFilters(org.elasticsearch.action.support.ActionFilters) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CreateRepositoryAnalyzedStatement(io.crate.analyze.CreateRepositoryAnalyzedStatement) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ClusterService(org.elasticsearch.cluster.ClusterService) DeleteRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryResponse) ActionListener(org.elasticsearch.action.ActionListener) TransportService(org.elasticsearch.transport.TransportService) RepositoriesService(org.elasticsearch.repositories.RepositoriesService) RepositoryMetaData(org.elasticsearch.cluster.metadata.RepositoryMetaData) ClusterName(org.elasticsearch.cluster.ClusterName) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) TransportPutRepositoryAction(org.elasticsearch.action.admin.cluster.repositories.put.TransportPutRepositoryAction) ExecutionException(java.util.concurrent.ExecutionException) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) PutRepositoryRequest(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 44 with ClusterName

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

the class TestGlobalSysExpressions method prepare.

@Before
public void prepare() throws Exception {
    Injector injector = new ModulesBuilder().add(new SysClusterExpressionModule()).add((Module) binder -> {
        binder.bind(ClusterService.class).toInstance(new NoopClusterService());
        binder.bind(Settings.class).toInstance(Settings.EMPTY);
        binder.bind(ClusterName.class).toInstance(new ClusterName("cluster"));
        binder.bind(ClusterReferenceResolver.class).asEagerSingleton();
    }).createInjector();
    resolver = injector.getInstance(ClusterReferenceResolver.class);
}
Also used : NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) ClusterService(org.elasticsearch.cluster.ClusterService) SysClusterExpressionModule(io.crate.operation.reference.sys.cluster.SysClusterExpressionModule) Injector(org.elasticsearch.common.inject.Injector) ClusterName(org.elasticsearch.cluster.ClusterName) ModulesBuilder(org.elasticsearch.common.inject.ModulesBuilder) ClusterReferenceResolver(io.crate.metadata.ClusterReferenceResolver) Module(org.elasticsearch.common.inject.Module) SysClusterExpressionModule(io.crate.operation.reference.sys.cluster.SysClusterExpressionModule) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) CrateSettings(io.crate.metadata.settings.CrateSettings) Settings(org.elasticsearch.common.settings.Settings) Before(org.junit.Before)

Example 45 with ClusterName

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

the class CreateDropRepositoryAnalyzerTest method init.

@Before
public void init() 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);
    e = SQLExecutor.builder(clusterService).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)

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