Search in sources :

Example 1 with ClusterUpdateSettingsRequestBuilder

use of org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder in project elasticsearch by elastic.

the class ClusterSettingsIT method testClusterUpdateSettingsWithBlocks.

public void testClusterUpdateSettingsWithBlocks() {
    String key1 = "cluster.routing.allocation.enable";
    Settings transientSettings = Settings.builder().put(key1, EnableAllocationDecider.Allocation.NONE.name()).build();
    String key2 = "cluster.routing.allocation.node_concurrent_recoveries";
    Settings persistentSettings = Settings.builder().put(key2, "5").build();
    ClusterUpdateSettingsRequestBuilder request = client().admin().cluster().prepareUpdateSettings().setTransientSettings(transientSettings).setPersistentSettings(persistentSettings);
    // Cluster settings updates are blocked when the cluster is read only
    try {
        setClusterReadOnly(true);
        assertBlocked(request, MetaData.CLUSTER_READ_ONLY_BLOCK);
        // But it's possible to update the settings to update the "cluster.blocks.read_only" setting
        Settings settings = Settings.builder().put(MetaData.SETTING_READ_ONLY_SETTING.getKey(), false).build();
        assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(settings).get());
    } finally {
        setClusterReadOnly(false);
    }
    // It should work now
    ClusterUpdateSettingsResponse response = request.execute().actionGet();
    assertAcked(response);
    assertThat(response.getTransientSettings().get(key1), notNullValue());
    assertThat(response.getTransientSettings().get(key2), nullValue());
    assertThat(response.getPersistentSettings().get(key1), nullValue());
    assertThat(response.getPersistentSettings().get(key2), notNullValue());
}
Also used : ClusterUpdateSettingsRequestBuilder(org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) ClusterUpdateSettingsResponse(org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse) DiscoverySettings(org.elasticsearch.discovery.DiscoverySettings) RecoverySettings(org.elasticsearch.indices.recovery.RecoverySettings) Settings(org.elasticsearch.common.settings.Settings)

Aggregations

ClusterUpdateSettingsRequestBuilder (org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder)1 ClusterUpdateSettingsResponse (org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse)1 Settings (org.elasticsearch.common.settings.Settings)1 DiscoverySettings (org.elasticsearch.discovery.DiscoverySettings)1 RecoverySettings (org.elasticsearch.indices.recovery.RecoverySettings)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1