Search in sources :

Example 1 with ClusterUpdateSettingsResponse

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

the class ClusterSettingsIT method testUpdateSettings.

public void testUpdateSettings() {
    final Setting<Integer> INITIAL_RECOVERIES = CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES_SETTING;
    ClusterUpdateSettingsResponse response = client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().put(INITIAL_RECOVERIES.getKey(), 42).build()).get();
    assertAcked(response);
    assertThat(INITIAL_RECOVERIES.get(response.getTransientSettings()), equalTo(42));
    assertThat(clusterService().getClusterSettings().get(INITIAL_RECOVERIES), equalTo(42));
    try {
        client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().put(INITIAL_RECOVERIES.getKey(), "whatever").build()).get();
        fail("bogus value");
    } catch (IllegalArgumentException ex) {
        assertEquals(ex.getMessage(), "Failed to parse value [whatever] for setting [" + INITIAL_RECOVERIES.getKey() + "]");
    }
    assertThat(clusterService().getClusterSettings().get(INITIAL_RECOVERIES), equalTo(42));
    try {
        client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().put(INITIAL_RECOVERIES.getKey(), -1).build()).get();
        fail("bogus value");
    } catch (IllegalArgumentException ex) {
        assertEquals(ex.getMessage(), "Failed to parse value [-1] for setting [" + INITIAL_RECOVERIES.getKey() + "] must be >= 0");
    }
    assertThat(clusterService().getClusterSettings().get(INITIAL_RECOVERIES), equalTo(42));
}
Also used : ClusterUpdateSettingsResponse(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse)

Example 2 with ClusterUpdateSettingsResponse

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

the class ClusterSettingsIT method testDeleteIsAppliedFirst.

public void testDeleteIsAppliedFirst() {
    final Setting<Integer> INITIAL_RECOVERIES = CLUSTER_ROUTING_ALLOCATION_NODE_INITIAL_PRIMARIES_RECOVERIES_SETTING;
    final Setting<TimeValue> REROUTE_INTERVAL = CLUSTER_ROUTING_ALLOCATION_REROUTE_INTERVAL_SETTING;
    ClusterUpdateSettingsResponse response = client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().put(INITIAL_RECOVERIES.getKey(), 7).put(REROUTE_INTERVAL.getKey(), "42s").build()).get();
    assertAcked(response);
    assertThat(INITIAL_RECOVERIES.get(response.getTransientSettings()), equalTo(7));
    assertThat(clusterService().getClusterSettings().get(INITIAL_RECOVERIES), equalTo(7));
    assertThat(REROUTE_INTERVAL.get(response.getTransientSettings()), equalTo(TimeValue.timeValueSeconds(42)));
    assertThat(clusterService().getClusterSettings().get(REROUTE_INTERVAL), equalTo(TimeValue.timeValueSeconds(42)));
    response = client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder().putNull((randomBoolean() ? "cluster.routing.*" : "*")).put(REROUTE_INTERVAL.getKey(), "43s")).get();
    assertThat(INITIAL_RECOVERIES.get(response.getTransientSettings()), equalTo(INITIAL_RECOVERIES.get(Settings.EMPTY)));
    assertThat(clusterService().getClusterSettings().get(INITIAL_RECOVERIES), equalTo(INITIAL_RECOVERIES.get(Settings.EMPTY)));
    assertThat(REROUTE_INTERVAL.get(response.getTransientSettings()), equalTo(TimeValue.timeValueSeconds(43)));
    assertThat(clusterService().getClusterSettings().get(REROUTE_INTERVAL), equalTo(TimeValue.timeValueSeconds(43)));
}
Also used : ClusterUpdateSettingsResponse(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse) TimeValue(org.opensearch.common.unit.TimeValue)

Example 3 with ClusterUpdateSettingsResponse

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

the class ClusterClientDocumentationIT method testClusterPutSettings.

public void testClusterPutSettings() throws IOException {
    RestHighLevelClient client = highLevelClient();
    // tag::put-settings-request
    ClusterUpdateSettingsRequest request = new ClusterUpdateSettingsRequest();
    // end::put-settings-request
    // tag::put-settings-create-settings
    String transientSettingKey = RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey();
    int transientSettingValue = 10;
    Settings transientSettings = Settings.builder().put(transientSettingKey, transientSettingValue, ByteSizeUnit.BYTES).build();
    String persistentSettingKey = EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey();
    String persistentSettingValue = EnableAllocationDecider.Allocation.NONE.name();
    Settings persistentSettings = Settings.builder().put(persistentSettingKey, persistentSettingValue).build();
    // end::put-settings-create-settings
    // tag::put-settings-request-cluster-settings
    // <1>
    request.transientSettings(transientSettings);
    // <2>
    request.persistentSettings(persistentSettings);
    // end::put-settings-request-cluster-settings
    {
        // tag::put-settings-settings-builder
        Settings.Builder transientSettingsBuilder = Settings.builder().put(transientSettingKey, transientSettingValue, ByteSizeUnit.BYTES);
        // <1>
        request.transientSettings(transientSettingsBuilder);
    // end::put-settings-settings-builder
    }
    {
        // tag::put-settings-settings-map
        Map<String, Object> map = new HashMap<>();
        map.put(transientSettingKey, transientSettingValue + ByteSizeUnit.BYTES.getSuffix());
        // <1>
        request.transientSettings(map);
    // end::put-settings-settings-map
    }
    {
        // tag::put-settings-settings-source
        request.transientSettings("{\"indices.recovery.max_bytes_per_sec\": \"10b\"}", // <1>
        XContentType.JSON);
    // end::put-settings-settings-source
    }
    // tag::put-settings-request-timeout
    // <1>
    request.timeout(TimeValue.timeValueMinutes(2));
    // <2>
    request.timeout("2m");
    // end::put-settings-request-timeout
    // tag::put-settings-request-masterTimeout
    // <1>
    request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
    // <2>
    request.masterNodeTimeout("1m");
    // end::put-settings-request-masterTimeout
    // tag::put-settings-execute
    ClusterUpdateSettingsResponse response = client.cluster().putSettings(request, RequestOptions.DEFAULT);
    // end::put-settings-execute
    // tag::put-settings-response
    // <1>
    boolean acknowledged = response.isAcknowledged();
    // <2>
    Settings transientSettingsResponse = response.getTransientSettings();
    // <3>
    Settings persistentSettingsResponse = response.getPersistentSettings();
    // end::put-settings-response
    assertTrue(acknowledged);
    assertThat(transientSettingsResponse.get(transientSettingKey), equalTo(transientSettingValue + ByteSizeUnit.BYTES.getSuffix()));
    assertThat(persistentSettingsResponse.get(persistentSettingKey), equalTo(persistentSettingValue));
    // tag::put-settings-request-reset-transient
    // <1>
    request.transientSettings(Settings.builder().putNull(transientSettingKey).build());
    // tag::put-settings-request-reset-transient
    request.persistentSettings(Settings.builder().putNull(persistentSettingKey));
    ClusterUpdateSettingsResponse resetResponse = client.cluster().putSettings(request, RequestOptions.DEFAULT);
    assertTrue(resetResponse.isAcknowledged());
}
Also used : RestHighLevelClient(org.opensearch.client.RestHighLevelClient) ClusterUpdateSettingsResponse(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse) HashMap(java.util.HashMap) Map(java.util.Map) ClusterUpdateSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest) RecoverySettings(org.opensearch.indices.recovery.RecoverySettings) Settings(org.opensearch.common.settings.Settings)

Example 4 with ClusterUpdateSettingsResponse

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

the class OpenSearchRestHighLevelClientTestCase method setupRemoteClusterConfig.

protected static void setupRemoteClusterConfig(String remoteClusterName) throws Exception {
    // Configure local cluster as remote cluster:
    // TODO: replace with nodes info highlevel rest client code when it is available:
    final Request request = new Request("GET", "/_nodes");
    Map<?, ?> nodesResponse = (Map<?, ?>) toMap(client().performRequest(request)).get("nodes");
    // Select node info of first node (we don't know the node id):
    nodesResponse = (Map<?, ?>) nodesResponse.get(nodesResponse.keySet().iterator().next());
    String transportAddress = (String) nodesResponse.get("transport_address");
    ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
    updateSettingsRequest.transientSettings(singletonMap("cluster.remote." + remoteClusterName + ".seeds", transportAddress));
    ClusterUpdateSettingsResponse updateSettingsResponse = restHighLevelClient.cluster().putSettings(updateSettingsRequest, RequestOptions.DEFAULT);
    assertThat(updateSettingsResponse.isAcknowledged(), is(true));
    assertBusy(() -> {
        RemoteInfoResponse response = highLevelClient().cluster().remoteInfo(new RemoteInfoRequest(), RequestOptions.DEFAULT);
        assertThat(response, notNullValue());
        assertThat(response.getInfos().size(), greaterThan(0));
    });
}
Also used : PutPipelineRequest(org.opensearch.action.ingest.PutPipelineRequest) ListTasksRequest(org.opensearch.action.admin.cluster.node.tasks.list.ListTasksRequest) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) ClusterUpdateSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest) SearchRequest(org.opensearch.action.search.SearchRequest) RemoteInfoRequest(org.opensearch.client.cluster.RemoteInfoRequest) RemoteInfoResponse(org.opensearch.client.cluster.RemoteInfoResponse) ClusterUpdateSettingsResponse(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap) ClusterUpdateSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest) RemoteInfoRequest(org.opensearch.client.cluster.RemoteInfoRequest)

Example 5 with ClusterUpdateSettingsResponse

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

the class ClusterClientIT method testClusterPutSettings.

public void testClusterPutSettings() throws IOException {
    final String transientSettingKey = RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey();
    final int transientSettingValue = 10;
    final String persistentSettingKey = EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey();
    final String persistentSettingValue = EnableAllocationDecider.Allocation.NONE.name();
    Settings transientSettings = Settings.builder().put(transientSettingKey, transientSettingValue, ByteSizeUnit.BYTES).build();
    Map<String, Object> map = new HashMap<>();
    map.put(persistentSettingKey, persistentSettingValue);
    ClusterUpdateSettingsRequest setRequest = new ClusterUpdateSettingsRequest();
    setRequest.transientSettings(transientSettings);
    setRequest.persistentSettings(map);
    ClusterUpdateSettingsResponse setResponse = execute(setRequest, highLevelClient().cluster()::putSettings, highLevelClient().cluster()::putSettingsAsync);
    assertAcked(setResponse);
    assertThat(setResponse.getTransientSettings().get(transientSettingKey), notNullValue());
    assertThat(setResponse.getTransientSettings().get(persistentSettingKey), nullValue());
    assertThat(setResponse.getTransientSettings().get(transientSettingKey), equalTo(transientSettingValue + ByteSizeUnit.BYTES.getSuffix()));
    assertThat(setResponse.getPersistentSettings().get(transientSettingKey), nullValue());
    assertThat(setResponse.getPersistentSettings().get(persistentSettingKey), notNullValue());
    assertThat(setResponse.getPersistentSettings().get(persistentSettingKey), equalTo(persistentSettingValue));
    Map<String, Object> setMap = getAsMap("/_cluster/settings");
    String transientSetValue = (String) XContentMapValues.extractValue("transient." + transientSettingKey, setMap);
    assertThat(transientSetValue, equalTo(transientSettingValue + ByteSizeUnit.BYTES.getSuffix()));
    String persistentSetValue = (String) XContentMapValues.extractValue("persistent." + persistentSettingKey, setMap);
    assertThat(persistentSetValue, equalTo(persistentSettingValue));
    ClusterUpdateSettingsRequest resetRequest = new ClusterUpdateSettingsRequest();
    resetRequest.transientSettings(Settings.builder().putNull(transientSettingKey));
    resetRequest.persistentSettings("{\"" + persistentSettingKey + "\": null }", XContentType.JSON);
    ClusterUpdateSettingsResponse resetResponse = execute(resetRequest, highLevelClient().cluster()::putSettings, highLevelClient().cluster()::putSettingsAsync);
    assertThat(resetResponse.getTransientSettings().get(transientSettingKey), equalTo(null));
    assertThat(resetResponse.getPersistentSettings().get(persistentSettingKey), equalTo(null));
    assertThat(resetResponse.getTransientSettings(), equalTo(Settings.EMPTY));
    assertThat(resetResponse.getPersistentSettings(), equalTo(Settings.EMPTY));
    Map<String, Object> resetMap = getAsMap("/_cluster/settings");
    String transientResetValue = (String) XContentMapValues.extractValue("transient." + transientSettingKey, resetMap);
    assertThat(transientResetValue, equalTo(null));
    String persistentResetValue = (String) XContentMapValues.extractValue("persistent." + persistentSettingKey, resetMap);
    assertThat(persistentResetValue, equalTo(null));
}
Also used : HashMap(java.util.HashMap) ClusterUpdateSettingsResponse(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse) RecoverySettings(org.opensearch.indices.recovery.RecoverySettings) Settings(org.opensearch.common.settings.Settings) ClusterUpdateSettingsRequest(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest)

Aggregations

ClusterUpdateSettingsResponse (org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse)13 Settings (org.opensearch.common.settings.Settings)6 Matchers.containsString (org.hamcrest.Matchers.containsString)4 RecoverySettings (org.opensearch.indices.recovery.RecoverySettings)4 ClusterUpdateSettingsRequest (org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TimeValue (org.opensearch.common.unit.TimeValue)2 Collections.singletonMap (java.util.Collections.singletonMap)1 ListTasksRequest (org.opensearch.action.admin.cluster.node.tasks.list.ListTasksRequest)1 ClusterUpdateSettingsRequestBuilder (org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder)1 PutPipelineRequest (org.opensearch.action.ingest.PutPipelineRequest)1 SearchRequest (org.opensearch.action.search.SearchRequest)1 RestHighLevelClient (org.opensearch.client.RestHighLevelClient)1 RemoteInfoRequest (org.opensearch.client.cluster.RemoteInfoRequest)1 RemoteInfoResponse (org.opensearch.client.cluster.RemoteInfoResponse)1 CreateIndexRequest (org.opensearch.client.indices.CreateIndexRequest)1