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


Java ClusterSettings.applySettings方法代码示例

本文整理汇总了Java中org.elasticsearch.common.settings.ClusterSettings.applySettings方法的典型用法代码示例。如果您正苦于以下问题:Java ClusterSettings.applySettings方法的具体用法?Java ClusterSettings.applySettings怎么用?Java ClusterSettings.applySettings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.common.settings.ClusterSettings的用法示例。


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

示例1: testUpdate

import org.elasticsearch.common.settings.ClusterSettings; //导入方法依赖的package包/类
public void testUpdate() {
    ClusterSettings nss = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    DiskThresholdSettings diskThresholdSettings = new DiskThresholdSettings(Settings.EMPTY, nss);

    Settings newSettings = Settings.builder()
        .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_DISK_THRESHOLD_ENABLED_SETTING.getKey(), false)
        .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_INCLUDE_RELOCATIONS_SETTING.getKey(), false)
        .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_HIGH_DISK_WATERMARK_SETTING.getKey(), "70%")
        .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_LOW_DISK_WATERMARK_SETTING.getKey(), "500mb")
        .put(DiskThresholdSettings.CLUSTER_ROUTING_ALLOCATION_REROUTE_INTERVAL_SETTING.getKey(), "30s")
        .build();
    nss.applySettings(newSettings);

    assertEquals(ByteSizeValue.parseBytesSizeValue("0b", "test"), diskThresholdSettings.getFreeBytesThresholdHigh());
    assertEquals(30.0D, diskThresholdSettings.getFreeDiskThresholdHigh(), 0.0D);
    assertEquals(ByteSizeValue.parseBytesSizeValue("500mb", "test"), diskThresholdSettings.getFreeBytesThresholdLow());
    assertEquals(0.0D, diskThresholdSettings.getFreeDiskThresholdLow(), 0.0D);
    assertEquals(30L, diskThresholdSettings.getRerouteInterval().seconds());
    assertFalse(diskThresholdSettings.isEnabled());
    assertFalse(diskThresholdSettings.includeRelocations());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:DiskThresholdSettingsTests.java

示例2: testUpdate

import org.elasticsearch.common.settings.ClusterSettings; //导入方法依赖的package包/类
public void testUpdate() {
    boolean value = randomBoolean();
    Settings settings;
    if (value && randomBoolean()) {
        settings = Settings.EMPTY;
    } else {
        settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), value).build();
    }

    ClusterSettings clusterSettings = new ClusterSettings(settings,
            ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    AutoCreateIndex  autoCreateIndex = new AutoCreateIndex(settings, clusterSettings, new IndexNameExpressionResolver(settings));
    assertThat(autoCreateIndex.getAutoCreate().isAutoCreateIndex(), equalTo(value));

    Settings newSettings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), !value).build();
    clusterSettings.applySettings(newSettings);
    assertThat(autoCreateIndex.getAutoCreate().isAutoCreateIndex(), equalTo(!value));

    newSettings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), "logs-*").build();
    clusterSettings.applySettings(newSettings);
    assertThat(autoCreateIndex.getAutoCreate().isAutoCreateIndex(), equalTo(true));
    assertThat(autoCreateIndex.getAutoCreate().getExpressions().size(), equalTo(1));
    assertThat(autoCreateIndex.getAutoCreate().getExpressions().get(0).v1(), equalTo("logs-*"));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:AutoCreateIndexTests.java

示例3: testPersistedSettings

import org.elasticsearch.common.settings.ClusterSettings; //导入方法依赖的package包/类
public void testPersistedSettings() {
    Settings.Builder settings = Settings.builder();
    settings.put(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING.getKey(), 0.2);
    settings.put(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING.getKey(), 0.3);
    settings.put(BalancedShardsAllocator.THRESHOLD_SETTING.getKey(), 2.0);
    ClusterSettings service = new ClusterSettings(Settings.builder().build(), ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    BalancedShardsAllocator allocator = new BalancedShardsAllocator(settings.build(), service);
    assertThat(allocator.getIndexBalance(), Matchers.equalTo(0.2f));
    assertThat(allocator.getShardBalance(), Matchers.equalTo(0.3f));
    assertThat(allocator.getThreshold(), Matchers.equalTo(2.0f));

    settings = Settings.builder();
    settings.put(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING.getKey(), 0.2);
    settings.put(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING.getKey(), 0.3);
    settings.put(BalancedShardsAllocator.THRESHOLD_SETTING.getKey(), 2.0);
    settings.put(ClusterRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ALLOW_REBALANCE_SETTING.getKey(), ClusterRebalanceAllocationDecider.ClusterRebalanceType.ALWAYS.toString());
    service.applySettings(settings.build());
    assertThat(allocator.getIndexBalance(), Matchers.equalTo(0.2f));
    assertThat(allocator.getShardBalance(), Matchers.equalTo(0.3f));
    assertThat(allocator.getThreshold(), Matchers.equalTo(2.0f));

    settings = Settings.builder();
    settings.put(BalancedShardsAllocator.INDEX_BALANCE_FACTOR_SETTING.getKey(), 0.5);
    settings.put(BalancedShardsAllocator.SHARD_BALANCE_FACTOR_SETTING.getKey(), 0.1);
    settings.put(BalancedShardsAllocator.THRESHOLD_SETTING.getKey(), 3.0);
    service.applySettings(settings.build());
    assertThat(allocator.getIndexBalance(), Matchers.equalTo(0.5f));
    assertThat(allocator.getShardBalance(), Matchers.equalTo(0.1f));
    assertThat(allocator.getThreshold(), Matchers.equalTo(3.0f));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:31,代码来源:BalanceConfigurationTests.java

示例4: testEnableClusterBalanceNoReplicas

import org.elasticsearch.common.settings.ClusterSettings; //导入方法依赖的package包/类
public void testEnableClusterBalanceNoReplicas() {
    final boolean useClusterSetting = randomBoolean();
    Settings build = Settings.builder()
            .put(CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), useClusterSetting ? Rebalance.NONE: RandomPicks.randomFrom(random(), Rebalance.values())) // index settings override cluster settings
            .put(ConcurrentRebalanceAllocationDecider.CLUSTER_ROUTING_ALLOCATION_CLUSTER_CONCURRENT_REBALANCE_SETTING.getKey(), 3)
            .build();
    ClusterSettings clusterSettings = new ClusterSettings(build, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    AllocationService strategy = createAllocationService(build, clusterSettings, random());
    Settings indexSettings = useClusterSetting ? Settings.EMPTY : Settings.builder().put(EnableAllocationDecider.INDEX_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), Rebalance.NONE).build();

    logger.info("Building initial routing table");
    MetaData metaData = MetaData.builder()
            .put(IndexMetaData.builder("test").settings(settings(Version.CURRENT).put(indexSettings)).numberOfShards(6).numberOfReplicas(0))
            .build();

    RoutingTable initialRoutingTable = RoutingTable.builder()
            .addAsNew(metaData.index("test"))
            .build();

    ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(initialRoutingTable).build();

    logger.info("--> adding one nodes and do rerouting");
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
            .add(newNode("node1"))
            .add(newNode("node2"))
    ).build();
    clusterState = strategy.reroute(clusterState, "reroute");
    assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(6));
    logger.info("--> start the shards (primaries)");
    clusterState = strategy.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(6));
    assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(0));

    logger.info("--> adding one nodes and do rerouting");
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder()
            .add(newNode("node1"))
            .add(newNode("node2"))
            .add(newNode("node3"))
    ).build();
    clusterState = strategy.reroute(clusterState, "reroute");
    assertThat(clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(6));
    assertThat(clusterState.getRoutingNodes().shardsWithState(RELOCATING).size(), equalTo(0));
    metaData = clusterState.metaData();
    if (useClusterSetting) {
        clusterState = ClusterState.builder(clusterState).metaData(MetaData.builder(metaData).transientSettings(Settings.builder()
                .put(CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), randomBoolean() ? Rebalance.PRIMARIES : Rebalance.ALL)
                .build())).build();
    } else {
        IndexMetaData meta = clusterState.getMetaData().index("test");
        clusterState = ClusterState.builder(clusterState).metaData(MetaData.builder(metaData).removeAllIndices()
                .put(IndexMetaData.builder(meta).settings(Settings.builder().put(meta.getSettings()).put(EnableAllocationDecider.INDEX_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), randomBoolean() ? Rebalance.PRIMARIES : Rebalance.ALL).build()))).build();
    }
    clusterSettings.applySettings(clusterState.metaData().settings());
    clusterState = strategy.reroute(clusterState, "reroute");
    assertThat("expected 4 primaries to be started and 2 to relocate useClusterSettings: " + useClusterSetting, clusterState.getRoutingNodes().shardsWithState(STARTED).size(), equalTo(4));
    assertThat("expected 2 primaries to relocate useClusterSettings: " + useClusterSetting, clusterState.getRoutingNodes().shardsWithState(RELOCATING).size(), equalTo(2));

}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:59,代码来源:EnableAllocationTests.java


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