Search in sources :

Example 1 with ClusterUpdateSettingsRequestBuilder

use of org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder in project OpenSearch by opensearch-project.

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().putNull(Metadata.SETTING_READ_ONLY_SETTING.getKey()).build();
        assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(settings).get());
    } finally {
        setClusterReadOnly(false);
    }
    // Cluster settings updates are blocked when the cluster is read only
    try {
        // 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_ALLOW_DELETE_SETTING.getKey(), true).build();
        assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(settings).get());
        assertBlocked(request, Metadata.CLUSTER_READ_ONLY_ALLOW_DELETE_BLOCK);
    } finally {
        // But it's possible to update the settings to update the "cluster.blocks.read_only" setting
        Settings s = Settings.builder().putNull(Metadata.SETTING_READ_ONLY_ALLOW_DELETE_SETTING.getKey()).build();
        assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(s).get());
    }
    // 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.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) ClusterUpdateSettingsResponse(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse) Settings(org.opensearch.common.settings.Settings) RecoverySettings(org.opensearch.indices.recovery.RecoverySettings)

Example 2 with ClusterUpdateSettingsRequestBuilder

use of org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder in project OpenSearch by opensearch-project.

the class UpgradeSettingsIT method runUpgradeSettingsOnUpdateTest.

private void runUpgradeSettingsOnUpdateTest(final BiConsumer<Settings, ClusterUpdateSettingsRequestBuilder> consumer, final Function<Metadata, Settings> settingsFunction) {
    final String value = randomAlphaOfLength(8);
    final ClusterUpdateSettingsRequestBuilder builder = client().admin().cluster().prepareUpdateSettings();
    consumer.accept(Settings.builder().put("foo.old", value).build(), builder);
    builder.get();
    final ClusterStateResponse response = client().admin().cluster().prepareState().clear().setMetadata(true).get();
    assertFalse(UpgradeSettingsPlugin.oldSetting.exists(settingsFunction.apply(response.getState().metadata())));
    assertTrue(UpgradeSettingsPlugin.newSetting.exists(settingsFunction.apply(response.getState().metadata())));
    assertThat(UpgradeSettingsPlugin.newSetting.get(settingsFunction.apply(response.getState().metadata())), equalTo("new." + value));
}
Also used : ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) ClusterUpdateSettingsRequestBuilder(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder)

Aggregations

ClusterUpdateSettingsRequestBuilder (org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1 ClusterUpdateSettingsResponse (org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse)1 ClusterStateResponse (org.opensearch.action.admin.cluster.state.ClusterStateResponse)1 Settings (org.opensearch.common.settings.Settings)1 RecoverySettings (org.opensearch.indices.recovery.RecoverySettings)1