当前位置: 首页>>代码示例>>Java>>正文


Java EmptyClusterInfoService类代码示例

本文整理汇总了Java中org.elasticsearch.cluster.EmptyClusterInfoService的典型用法代码示例。如果您正苦于以下问题:Java EmptyClusterInfoService类的具体用法?Java EmptyClusterInfoService怎么用?Java EmptyClusterInfoService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


EmptyClusterInfoService类属于org.elasticsearch.cluster包,在下文中一共展示了EmptyClusterInfoService类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRestoreDoesNotAllocateSnapshotOnOlderNodes

import org.elasticsearch.cluster.EmptyClusterInfoService; //导入依赖的package包/类
public void testRestoreDoesNotAllocateSnapshotOnOlderNodes() {
    final DiscoveryNode newNode = new DiscoveryNode("newNode", buildNewFakeTransportAddress(), emptyMap(),
            MASTER_DATA_ROLES, Version.CURRENT);
    final DiscoveryNode oldNode1 = new DiscoveryNode("oldNode1", buildNewFakeTransportAddress(), emptyMap(),
            MASTER_DATA_ROLES, VersionUtils.getPreviousVersion());
    final DiscoveryNode oldNode2 = new DiscoveryNode("oldNode2", buildNewFakeTransportAddress(), emptyMap(),
            MASTER_DATA_ROLES, VersionUtils.getPreviousVersion());

    int numberOfShards = randomIntBetween(1, 3);
    final IndexMetaData.Builder indexMetaData = IndexMetaData.builder("test").settings(settings(Version.CURRENT))
        .numberOfShards(numberOfShards).numberOfReplicas(randomIntBetween(0, 3));
    for (int i = 0; i < numberOfShards; i++) {
        indexMetaData.putInSyncAllocationIds(i, Collections.singleton("_test_"));
    }
    MetaData metaData = MetaData.builder().put(indexMetaData).build();

    ClusterState state = ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
        .metaData(metaData)
        .routingTable(RoutingTable.builder().addAsRestore(metaData.index("test"),
            new SnapshotRecoverySource(new Snapshot("rep1", new SnapshotId("snp1", UUIDs.randomBase64UUID())),
            Version.CURRENT, "test")).build())
        .nodes(DiscoveryNodes.builder().add(newNode).add(oldNode1).add(oldNode2)).build();
    AllocationDeciders allocationDeciders = new AllocationDeciders(Settings.EMPTY, Arrays.asList(
        new ReplicaAfterPrimaryActiveAllocationDecider(Settings.EMPTY),
        new NodeVersionAllocationDecider(Settings.EMPTY)));
    AllocationService strategy = new MockAllocationService(Settings.EMPTY,
        allocationDeciders,
        new TestGatewayAllocator(), new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE);
    state = strategy.reroute(state, new AllocationCommands(), true, false).getClusterState();

    // Make sure that primary shards are only allocated on the new node
    for (int i = 0; i < numberOfShards; i++) {
        assertEquals("newNode", state.routingTable().index("test").getShards().get(i).primaryShard().currentNodeId());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:36,代码来源:NodeVersionAllocationDeciderTests.java

示例2: setUp

import org.elasticsearch.cluster.EmptyClusterInfoService; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
    super.setUp();
    strategy = new AllocationService(Settings.builder().build(), new AllocationDeciders(Settings.EMPTY,
        Collections.singleton(new MaxRetryAllocationDecider(Settings.EMPTY))),
        new TestGatewayAllocator(), new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:MaxRetryAllocationDeciderTests.java

示例3: newAllocationService

import org.elasticsearch.cluster.EmptyClusterInfoService; //导入依赖的package包/类
private static AllocationService newAllocationService(Settings settings, Set<AllocationDecider> deciders) {
    return new AllocationService(settings,
                                 new AllocationDeciders(settings, deciders),
                                 new TestGatewayAllocator(),
                                 new BalancedShardsAllocator(settings),
                                 EmptyClusterInfoService.INSTANCE);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:DecisionsImpactOnClusterHealthTests.java

示例4: testShrinkIndexSettings

import org.elasticsearch.cluster.EmptyClusterInfoService; //导入依赖的package包/类
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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:33,代码来源:TransportShrinkActionTests.java

示例5: createAllocationService

import org.elasticsearch.cluster.EmptyClusterInfoService; //导入依赖的package包/类
public static AllocationService createAllocationService(Settings settings, ClusterSettings clusterSettings) throws
    InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
    return new AllocationService(settings,
        defaultAllocationDeciders(settings, clusterSettings),
        NoopGatewayAllocator.INSTANCE, new BalancedShardsAllocator(settings), EmptyClusterInfoService.INSTANCE);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:Allocators.java

示例6: testRebalanceDoesNotAllocatePrimaryAndReplicasOnDifferentVersionNodes

import org.elasticsearch.cluster.EmptyClusterInfoService; //导入依赖的package包/类
public void testRebalanceDoesNotAllocatePrimaryAndReplicasOnDifferentVersionNodes() {
    ShardId shard1 = new ShardId("test1", "_na_", 0);
    ShardId shard2 = new ShardId("test2", "_na_", 0);
    final DiscoveryNode newNode = new DiscoveryNode("newNode", buildNewFakeTransportAddress(), emptyMap(),
            MASTER_DATA_ROLES, Version.CURRENT);
    final DiscoveryNode oldNode1 = new DiscoveryNode("oldNode1", buildNewFakeTransportAddress(), emptyMap(),
            MASTER_DATA_ROLES, VersionUtils.getPreviousVersion());
    final DiscoveryNode oldNode2 = new DiscoveryNode("oldNode2", buildNewFakeTransportAddress(), emptyMap(),
            MASTER_DATA_ROLES, VersionUtils.getPreviousVersion());
    AllocationId allocationId1P = AllocationId.newInitializing();
    AllocationId allocationId1R = AllocationId.newInitializing();
    AllocationId allocationId2P = AllocationId.newInitializing();
    AllocationId allocationId2R = AllocationId.newInitializing();
    MetaData metaData = MetaData.builder()
        .put(IndexMetaData.builder(shard1.getIndexName()).settings(settings(Version.CURRENT).put(Settings.EMPTY)).numberOfShards(1).numberOfReplicas(1).putInSyncAllocationIds(0, Sets.newHashSet(allocationId1P.getId(), allocationId1R.getId())))
        .put(IndexMetaData.builder(shard2.getIndexName()).settings(settings(Version.CURRENT).put(Settings.EMPTY)).numberOfShards(1).numberOfReplicas(1).putInSyncAllocationIds(0, Sets.newHashSet(allocationId2P.getId(), allocationId2R.getId())))
        .build();
    RoutingTable routingTable = RoutingTable.builder()
        .add(IndexRoutingTable.builder(shard1.getIndex())
            .addIndexShard(new IndexShardRoutingTable.Builder(shard1)
                .addShard(TestShardRouting.newShardRouting(shard1.getIndexName(), shard1.getId(), newNode.getId(), null, true, ShardRoutingState.STARTED, allocationId1P))
                .addShard(TestShardRouting.newShardRouting(shard1.getIndexName(), shard1.getId(), oldNode1.getId(), null, false, ShardRoutingState.STARTED, allocationId1R))
                .build())
        )
        .add(IndexRoutingTable.builder(shard2.getIndex())
            .addIndexShard(new IndexShardRoutingTable.Builder(shard2)
                .addShard(TestShardRouting.newShardRouting(shard2.getIndexName(), shard2.getId(), newNode.getId(), null, true, ShardRoutingState.STARTED, allocationId2P))
                .addShard(TestShardRouting.newShardRouting(shard2.getIndexName(), shard2.getId(), oldNode1.getId(), null, false, ShardRoutingState.STARTED, allocationId2R))
                .build())
        )
        .build();
    ClusterState state = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY))
        .metaData(metaData)
        .routingTable(routingTable)
        .nodes(DiscoveryNodes.builder().add(newNode).add(oldNode1).add(oldNode2)).build();
    AllocationDeciders allocationDeciders = new AllocationDeciders(Settings.EMPTY, Collections.singleton(new NodeVersionAllocationDecider(Settings.EMPTY)));
    AllocationService strategy = new MockAllocationService(Settings.EMPTY,
        allocationDeciders,
        new TestGatewayAllocator(), new BalancedShardsAllocator(Settings.EMPTY), EmptyClusterInfoService.INSTANCE);
    state = strategy.reroute(state, new AllocationCommands(), true, false).getClusterState();
    // the two indices must stay as is, the replicas cannot move to oldNode2 because versions don't match
    assertThat(state.routingTable().index(shard2.getIndex()).shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(0));
    assertThat(state.routingTable().index(shard1.getIndex()).shardsWithState(ShardRoutingState.RELOCATING).size(), equalTo(0));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:45,代码来源:NodeVersionAllocationDeciderTests.java

示例7: testValidateShrinkIndex

import org.elasticsearch.cluster.EmptyClusterInfoService; //导入依赖的package包/类
public void testValidateShrinkIndex() {
    int numShards = randomIntBetween(2, 42);
    ClusterState state = createClusterState("source", numShards, randomIntBetween(0, 10),
        Settings.builder().put("index.blocks.write", true).build());

    assertEquals("index [source] already exists",
        expectThrows(ResourceAlreadyExistsException.class, () ->
            MetaDataCreateIndexService.validateShrinkIndex(state, "target", Collections.emptySet(), "source", Settings.EMPTY)
        ).getMessage());

    assertEquals("no such index",
        expectThrows(IndexNotFoundException.class, () ->
            MetaDataCreateIndexService.validateShrinkIndex(state, "no such index", Collections.emptySet(), "target", Settings.EMPTY)
        ).getMessage());

    assertEquals("can't shrink an index with only one shard",
        expectThrows(IllegalArgumentException.class, () -> MetaDataCreateIndexService.validateShrinkIndex(createClusterState("source",
            1, 0, Settings.builder().put("index.blocks.write", true).build()), "source", Collections.emptySet(),
                    "target", Settings.EMPTY)
        ).getMessage());

    assertEquals("the number of target shards must be less that the number of source shards",
        expectThrows(IllegalArgumentException.class, () -> MetaDataCreateIndexService.validateShrinkIndex(createClusterState("source",
            5, 0, Settings.builder().put("index.blocks.write", true).build()), "source", Collections.emptySet(),
            "target", Settings.builder().put("index.number_of_shards", 10).build())
        ).getMessage());


    assertEquals("index source must be read-only to shrink index. use \"index.blocks.write=true\"",
        expectThrows(IllegalStateException.class, () ->
                MetaDataCreateIndexService.validateShrinkIndex(
                    createClusterState("source", randomIntBetween(2, 100), randomIntBetween(0, 10), Settings.EMPTY)
                    , "source", Collections.emptySet(), "target", Settings.EMPTY)
        ).getMessage());

    assertEquals("index source must have all shards allocated on the same node to shrink index",
        expectThrows(IllegalStateException.class, () ->
            MetaDataCreateIndexService.validateShrinkIndex(state, "source", Collections.emptySet(), "target", Settings.EMPTY)

        ).getMessage());
    assertEquals("the number of source shards [8] must be a must be a multiple of [3]",
        expectThrows(IllegalArgumentException.class, () ->
                MetaDataCreateIndexService.validateShrinkIndex(createClusterState("source", 8, randomIntBetween(0, 10),
                    Settings.builder().put("index.blocks.write", true).build()), "source", Collections.emptySet(), "target",
                    Settings.builder().put("index.number_of_shards", 3).build())
        ).getMessage());

    assertEquals("mappings are not allowed when shrinking indices, all mappings are copied from the source index",
        expectThrows(IllegalArgumentException.class, () -> {
            MetaDataCreateIndexService.validateShrinkIndex(state, "source", Collections.singleton("foo"),
                "target", Settings.EMPTY);
            }
        ).getMessage());

    // create one that won't fail
    ClusterState clusterState = ClusterState.builder(createClusterState("source", numShards, 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();
    int targetShards;
    do {
        targetShards = randomIntBetween(1, numShards/2);
    } while (isShrinkable(numShards, targetShards) == false);
    MetaDataCreateIndexService.validateShrinkIndex(clusterState, "source", Collections.emptySet(), "target",
        Settings.builder().put("index.number_of_shards", targetShards).build());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:76,代码来源:MetaDataCreateIndexServiceTests.java

示例8: DiskThresholdDecider

import org.elasticsearch.cluster.EmptyClusterInfoService; //导入依赖的package包/类
public DiskThresholdDecider(Settings settings) {
    // It's okay the Client is null here, because the empty cluster info
    // service will never actually call the listener where the client is
    // needed. Also this constructor is only used for tests
    this(settings, new NodeSettingsService(settings), EmptyClusterInfoService.INSTANCE, null);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:7,代码来源:DiskThresholdDecider.java


注:本文中的org.elasticsearch.cluster.EmptyClusterInfoService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。