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));
}
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)));
}
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());
}
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));
});
}
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));
}
Aggregations