Search in sources :

Example 21 with IndexNameExpressionResolver

use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver in project elasticsearch by elastic.

the class ClusterModule method configure.

@Override
protected void configure() {
    bind(GatewayAllocator.class).asEagerSingleton();
    bind(AllocationService.class).asEagerSingleton();
    bind(ClusterService.class).toInstance(clusterService);
    bind(NodeConnectionsService.class).asEagerSingleton();
    bind(MetaDataCreateIndexService.class).asEagerSingleton();
    bind(MetaDataDeleteIndexService.class).asEagerSingleton();
    bind(MetaDataIndexStateService.class).asEagerSingleton();
    bind(MetaDataMappingService.class).asEagerSingleton();
    bind(MetaDataIndexAliasesService.class).asEagerSingleton();
    bind(MetaDataUpdateSettingsService.class).asEagerSingleton();
    bind(MetaDataIndexTemplateService.class).asEagerSingleton();
    bind(IndexNameExpressionResolver.class).toInstance(indexNameExpressionResolver);
    bind(RoutingService.class).asEagerSingleton();
    bind(DelayedAllocationService.class).asEagerSingleton();
    bind(ShardStateAction.class).asEagerSingleton();
    bind(NodeMappingRefreshAction.class).asEagerSingleton();
    bind(MappingUpdatedAction.class).asEagerSingleton();
    bind(TaskResultsService.class).asEagerSingleton();
    bind(AllocationDeciders.class).toInstance(new AllocationDeciders(settings, allocationDeciders));
    bind(ShardsAllocator.class).toInstance(shardsAllocator);
}
Also used : GatewayAllocator(org.elasticsearch.gateway.GatewayAllocator) MetaDataUpdateSettingsService(org.elasticsearch.cluster.metadata.MetaDataUpdateSettingsService) RoutingService(org.elasticsearch.cluster.routing.RoutingService) DelayedAllocationService(org.elasticsearch.cluster.routing.DelayedAllocationService) MetaDataCreateIndexService(org.elasticsearch.cluster.metadata.MetaDataCreateIndexService) ShardStateAction(org.elasticsearch.cluster.action.shard.ShardStateAction) NodeMappingRefreshAction(org.elasticsearch.cluster.action.index.NodeMappingRefreshAction) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) BalancedShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) ShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.ShardsAllocator) MetaDataIndexAliasesService(org.elasticsearch.cluster.metadata.MetaDataIndexAliasesService) TaskResultsService(org.elasticsearch.tasks.TaskResultsService) ClusterService(org.elasticsearch.cluster.service.ClusterService) MetaDataMappingService(org.elasticsearch.cluster.metadata.MetaDataMappingService) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) MappingUpdatedAction(org.elasticsearch.cluster.action.index.MappingUpdatedAction) MetaDataDeleteIndexService(org.elasticsearch.cluster.metadata.MetaDataDeleteIndexService) DelayedAllocationService(org.elasticsearch.cluster.routing.DelayedAllocationService) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) MetaDataIndexStateService(org.elasticsearch.cluster.metadata.MetaDataIndexStateService) MetaDataIndexTemplateService(org.elasticsearch.cluster.metadata.MetaDataIndexTemplateService)

Example 22 with IndexNameExpressionResolver

use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver in project elasticsearch by elastic.

the class TransportShrinkActionTests method testErrorCondition.

public void testErrorCondition() {
    ClusterState state = createClusterState("source", randomIntBetween(2, 42), randomIntBetween(0, 10), Settings.builder().put("index.blocks.write", true).build());
    assertTrue(expectThrows(IllegalStateException.class, () -> TransportShrinkAction.prepareCreateIndexRequest(new ShrinkRequest("target", "source"), state, (i) -> new DocsStats(Integer.MAX_VALUE, randomIntBetween(1, 1000)), new IndexNameExpressionResolver(Settings.EMPTY))).getMessage().startsWith("Can't merge index with more than [2147483519] docs - too many documents in shards "));
    assertTrue(expectThrows(IllegalStateException.class, () -> {
        ShrinkRequest req = new ShrinkRequest("target", "source");
        req.getShrinkIndexRequest().settings(Settings.builder().put("index.number_of_shards", 4));
        ClusterState clusterState = createClusterState("source", 8, 1, Settings.builder().put("index.blocks.write", true).build());
        TransportShrinkAction.prepareCreateIndexRequest(req, clusterState, (i) -> i == 2 || i == 3 ? new DocsStats(Integer.MAX_VALUE / 2, randomIntBetween(1, 1000)) : null, new IndexNameExpressionResolver(Settings.EMPTY));
    }).getMessage().startsWith("Can't merge index with more than [2147483519] docs - too many documents in shards "));
    // create one that won't fail
    ClusterState clusterState = ClusterState.builder(createClusterState("source", randomIntBetween(2, 10), 0, Settings.builder().put("index.blocks.write", true).build())).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
    AllocationService service = new AllocationService(Settings.builder().build(), new AllocationDeciders(Settings.EMPTY, Collections.singleton(new MaxRetryAllocationDecider(Settings.EMPTY))), new TestGatewayAllocator(), new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE);
    RoutingTable routingTable = service.reroute(clusterState, "reroute").routingTable();
    clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
    // now we start the shard
    routingTable = service.applyStartedShards(clusterState, routingTable.index("source").shardsWithState(ShardRoutingState.INITIALIZING)).routingTable();
    clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
    TransportShrinkAction.prepareCreateIndexRequest(new ShrinkRequest("target", "source"), clusterState, (i) -> new DocsStats(randomIntBetween(1, 1000), randomIntBetween(1, 1000)), new IndexNameExpressionResolver(Settings.EMPTY));
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) Arrays(java.util.Arrays) MaxRetryAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) ClusterBlocks(org.elasticsearch.cluster.block.ClusterBlocks) ShardRoutingState(org.elasticsearch.cluster.routing.ShardRoutingState) HashSet(java.util.HashSet) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) EmptyClusterInfoService(org.elasticsearch.cluster.EmptyClusterInfoService) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) ClusterName(org.elasticsearch.cluster.ClusterName) ESTestCase(org.elasticsearch.test.ESTestCase) CreateIndexClusterStateUpdateRequest(org.elasticsearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest) Collections.emptyMap(java.util.Collections.emptyMap) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) BalancedShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) TestGatewayAllocator(org.elasticsearch.test.gateway.TestGatewayAllocator) ActiveShardCount(org.elasticsearch.action.support.ActiveShardCount) IndexWriter(org.apache.lucene.index.IndexWriter) Version(org.elasticsearch.Version) DocsStats(org.elasticsearch.index.shard.DocsStats) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Collections(java.util.Collections) TestGatewayAllocator(org.elasticsearch.test.gateway.TestGatewayAllocator) ClusterState(org.elasticsearch.cluster.ClusterState) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) BalancedShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) DocsStats(org.elasticsearch.index.shard.DocsStats) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) MaxRetryAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService)

Example 23 with IndexNameExpressionResolver

use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver in project elasticsearch by elastic.

the class TransportShrinkActionTests method testShrinkIndexSettings.

public void testShrinkIndexSettings() {
    String indexName = randomAsciiOfLength(10);
    // create one that won't fail
    ClusterState clusterState = ClusterState.builder(createClusterState(indexName, randomIntBetween(2, 10), 0, Settings.builder().put("index.blocks.write", true).build())).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build();
    AllocationService service = new AllocationService(Settings.builder().build(), new AllocationDeciders(Settings.EMPTY, Collections.singleton(new MaxRetryAllocationDecider(Settings.EMPTY))), new TestGatewayAllocator(), new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE);
    RoutingTable routingTable = service.reroute(clusterState, "reroute").routingTable();
    clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
    // now we start the shard
    routingTable = service.applyStartedShards(clusterState, routingTable.index(indexName).shardsWithState(ShardRoutingState.INITIALIZING)).routingTable();
    clusterState = ClusterState.builder(clusterState).routingTable(routingTable).build();
    int numSourceShards = clusterState.metaData().index(indexName).getNumberOfShards();
    DocsStats stats = new DocsStats(randomIntBetween(0, (IndexWriter.MAX_DOCS) / numSourceShards), randomIntBetween(1, 1000));
    ShrinkRequest target = new ShrinkRequest("target", indexName);
    final ActiveShardCount activeShardCount = randomBoolean() ? ActiveShardCount.ALL : ActiveShardCount.ONE;
    target.setWaitForActiveShards(activeShardCount);
    CreateIndexClusterStateUpdateRequest request = TransportShrinkAction.prepareCreateIndexRequest(target, clusterState, (i) -> stats, new IndexNameExpressionResolver(Settings.EMPTY));
    assertNotNull(request.shrinkFrom());
    assertEquals(indexName, request.shrinkFrom().getName());
    assertEquals("1", request.settings().get("index.number_of_shards"));
    assertEquals("shrink_index", request.cause());
    assertEquals(request.waitForActiveShards(), activeShardCount);
}
Also used : TestGatewayAllocator(org.elasticsearch.test.gateway.TestGatewayAllocator) ClusterState(org.elasticsearch.cluster.ClusterState) BalancedShardsAllocator(org.elasticsearch.cluster.routing.allocation.allocator.BalancedShardsAllocator) AllocationDeciders(org.elasticsearch.cluster.routing.allocation.decider.AllocationDeciders) MaxRetryAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider) ActiveShardCount(org.elasticsearch.action.support.ActiveShardCount) CreateIndexClusterStateUpdateRequest(org.elasticsearch.action.admin.indices.create.CreateIndexClusterStateUpdateRequest) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) DocsStats(org.elasticsearch.index.shard.DocsStats) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService)

Example 24 with IndexNameExpressionResolver

use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver in project elasticsearch by elastic.

the class RestIndicesActionTests method testBuildTable.

public void testBuildTable() {
    final Settings settings = Settings.EMPTY;
    final RestController restController = new RestController(settings, Collections.emptySet(), null, null, null);
    final RestIndicesAction action = new RestIndicesAction(settings, restController, new IndexNameExpressionResolver(settings));
    // build a (semi-)random table
    final int numIndices = randomIntBetween(0, 5);
    Index[] indices = new Index[numIndices];
    for (int i = 0; i < numIndices; i++) {
        indices[i] = new Index(randomAsciiOfLength(5), UUIDs.randomBase64UUID());
    }
    final MetaData.Builder metaDataBuilder = MetaData.builder();
    for (final Index index : indices) {
        metaDataBuilder.put(IndexMetaData.builder(index.getName()).settings(Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID())).creationDate(System.currentTimeMillis()).numberOfShards(1).numberOfReplicas(1).state(IndexMetaData.State.OPEN));
    }
    final MetaData metaData = metaDataBuilder.build();
    final ClusterState clusterState = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).build();
    final String[] indicesStr = new String[indices.length];
    for (int i = 0; i < indices.length; i++) {
        indicesStr[i] = indices[i].getName();
    }
    final ClusterHealthResponse clusterHealth = new ClusterHealthResponse(clusterState.getClusterName().value(), indicesStr, clusterState, 0, 0, 0, TimeValue.timeValueMillis(1000L));
    final Table table = action.buildTable(new FakeRestRequest(), indices, clusterHealth, randomIndicesStatsResponse(indices), metaData);
    // now, verify the table is correct
    int count = 0;
    List<Table.Cell> headers = table.getHeaders();
    assertThat(headers.get(count++).value, equalTo("health"));
    assertThat(headers.get(count++).value, equalTo("status"));
    assertThat(headers.get(count++).value, equalTo("index"));
    assertThat(headers.get(count++).value, equalTo("uuid"));
    List<List<Table.Cell>> rows = table.getRows();
    assertThat(rows.size(), equalTo(indices.length));
    // TODO: more to verify (e.g. randomize cluster health, num primaries, num replicas, etc)
    for (int i = 0; i < rows.size(); i++) {
        count = 0;
        final List<Table.Cell> row = rows.get(i);
        // all are red because cluster state doesn't have routing entries
        assertThat(row.get(count++).value, equalTo("red*"));
        // all are OPEN for now
        assertThat(row.get(count++).value, equalTo("open"));
        assertThat(row.get(count++).value, equalTo(indices[i].getName()));
        assertThat(row.get(count++).value, equalTo(indices[i].getUUID()));
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) Table(org.elasticsearch.common.Table) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) RestController(org.elasticsearch.rest.RestController) Index(org.elasticsearch.index.Index) FakeRestRequest(org.elasticsearch.test.rest.FakeRestRequest) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Settings(org.elasticsearch.common.settings.Settings)

Example 25 with IndexNameExpressionResolver

use of org.elasticsearch.cluster.metadata.IndexNameExpressionResolver in project elasticsearch by elastic.

the class TransportBulkActionTookTests method createAction.

private TransportBulkAction createAction(boolean controlled, AtomicLong expected) {
    CapturingTransport capturingTransport = new CapturingTransport();
    TransportService transportService = new TransportService(clusterService.getSettings(), capturingTransport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundAddress -> clusterService.localNode(), null);
    transportService.start();
    transportService.acceptIncomingRequests();
    IndexNameExpressionResolver resolver = new Resolver(Settings.EMPTY);
    ActionFilters actionFilters = new ActionFilters(new HashSet<>());
    TransportCreateIndexAction createIndexAction = new TransportCreateIndexAction(Settings.EMPTY, transportService, clusterService, threadPool, null, actionFilters, resolver);
    if (controlled) {
        return new TestTransportBulkAction(Settings.EMPTY, threadPool, transportService, clusterService, null, createIndexAction, actionFilters, resolver, null, expected::get) {

            @Override
            void executeBulk(Task task, BulkRequest bulkRequest, long startTimeNanos, ActionListener<BulkResponse> listener, AtomicArray<BulkItemResponse> responses) {
                expected.set(1000000);
                super.executeBulk(task, bulkRequest, startTimeNanos, listener, responses);
            }
        };
    } else {
        return new TestTransportBulkAction(Settings.EMPTY, threadPool, transportService, clusterService, null, createIndexAction, actionFilters, resolver, null, System::nanoTime) {

            @Override
            void executeBulk(Task task, BulkRequest bulkRequest, long startTimeNanos, ActionListener<BulkResponse> listener, AtomicArray<BulkItemResponse> responses) {
                long elapsed = spinForAtLeastOneMillisecond();
                expected.set(elapsed);
                super.executeBulk(task, bulkRequest, startTimeNanos, listener, responses);
            }
        };
    }
}
Also used : Task(org.elasticsearch.tasks.Task) AtomicArray(org.elasticsearch.common.util.concurrent.AtomicArray) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) CapturingTransport(org.elasticsearch.test.transport.CapturingTransport) ActionFilters(org.elasticsearch.action.support.ActionFilters) TransportCreateIndexAction(org.elasticsearch.action.admin.indices.create.TransportCreateIndexAction) ActionListener(org.elasticsearch.action.ActionListener) TransportService(org.elasticsearch.transport.TransportService) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)

Aggregations

IndexNameExpressionResolver (org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)32 Settings (org.elasticsearch.common.settings.Settings)15 ThreadPool (org.elasticsearch.threadpool.ThreadPool)12 ClusterState (org.elasticsearch.cluster.ClusterState)10 ActionListener (org.elasticsearch.action.ActionListener)9 ActionFilters (org.elasticsearch.action.support.ActionFilters)9 Test (org.junit.Test)9 CrateUnitTest (io.crate.test.integration.CrateUnitTest)8 ClusterService (org.elasticsearch.cluster.ClusterService)7 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 TransportBulkCreateIndicesAction (org.elasticsearch.action.admin.indices.create.TransportBulkCreateIndicesAction)5 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)5 ShardId (org.elasticsearch.index.shard.ShardId)5 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)5 ShardUpsertRequest (io.crate.executor.transport.ShardUpsertRequest)4 TableIdent (io.crate.metadata.TableIdent)4 UUID (java.util.UUID)4 TransportService (org.elasticsearch.transport.TransportService)4 ShardResponse (io.crate.executor.transport.ShardResponse)3