use of org.opensearch.client.opensearch.cluster.PutClusterSettingsRequest in project opensearch-java by opensearch-project.
the class ClusterClientIT method testClusterGetSettings.
public void testClusterGetSettings() throws IOException {
OpenSearchClient openSearchClient = highLevelClient();
final String transientSettingKey = RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey();
final String transientSettingValue = "10b";
final String persistentSettingKey = EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey();
final String persistentSettingValue = EnableAllocationDecider.Allocation.NONE.name();
Map<String, JsonData> transientSettingsMap = new HashMap<>();
Map<String, JsonData> persistentSettingsMap = new HashMap<>();
transientSettingsMap.put(transientSettingKey, JsonData.of(transientSettingValue));
persistentSettingsMap.put(persistentSettingKey, JsonData.of(persistentSettingValue));
PutClusterSettingsRequest request = new PutClusterSettingsRequest.Builder().persistent(persistentSettingsMap).transient_(transientSettingsMap).build();
openSearchClient.cluster().putSettings(request);
GetClusterSettingsResponse getSettingsResponse = openSearchClient.cluster().getSettings(new GetClusterSettingsRequest.Builder().build());
assertEquals(1, getSettingsResponse.persistent().size());
assertEquals(1, getSettingsResponse.transient_().size());
assertEquals(0, getSettingsResponse.defaults().size());
}
use of org.opensearch.client.opensearch.cluster.PutClusterSettingsRequest in project opensearch-java by opensearch-project.
the class ClusterClientIT method testClusterPutSettings.
public void testClusterPutSettings() throws IOException {
OpenSearchClient openSearchClient = highLevelClient();
final String transientSettingKey = RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey();
String[] transientSettingKeySplit = transientSettingKey.split("\\.");
final String transientSettingValue = "10b";
final String persistentSettingKey = EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey();
String[] persistentSettingKeySplit = persistentSettingKey.split("\\.");
final String persistentSettingValue = EnableAllocationDecider.Allocation.NONE.name();
Map<String, JsonData> transientSettingsMap = new HashMap<>();
Map<String, JsonData> persistentSettingsMap = new HashMap<>();
transientSettingsMap.put(transientSettingKey, JsonData.of(transientSettingValue));
persistentSettingsMap.put(persistentSettingKey, JsonData.of(persistentSettingValue));
PutClusterSettingsRequest request = new PutClusterSettingsRequest.Builder().persistent(persistentSettingsMap).transient_(transientSettingsMap).build();
PutClusterSettingsResponse response = openSearchClient.cluster().putSettings(request);
assertTrue(response.acknowledged());
assertThat(response.transient_().get(transientSettingKeySplit[0]), notNullValue());
assertThat(response.transient_().get(persistentSettingKeySplit[0]), nullValue());
assertEquals(response.transient_().get(transientSettingKeySplit[0]).toJson().asJsonObject().getJsonObject("recovery").getString("max_bytes_per_sec"), transientSettingValue);
assertThat(response.persistent().get(transientSettingKeySplit[0]), nullValue());
assertThat(response.persistent().get(persistentSettingKeySplit[0]), notNullValue());
assertEquals(response.persistent().get(persistentSettingKeySplit[0]).toJson().asJsonObject().getJsonObject("routing").getJsonObject("allocation").getString("enable"), persistentSettingValue);
}
use of org.opensearch.client.opensearch.cluster.PutClusterSettingsRequest in project opensearch-java by opensearch-project.
the class ClusterClientIT method testClusterUpdateSettingNonExistent.
public void testClusterUpdateSettingNonExistent() throws IOException {
OpenSearchClient openSearchClient = highLevelClient();
String setting = "no_idea_what_you_are_talking_about";
int value = 10;
Map<String, JsonData> transientSettingsMap = new HashMap<>();
transientSettingsMap.put(setting, JsonData.of(value));
PutClusterSettingsRequest request = new PutClusterSettingsRequest.Builder().transient_(transientSettingsMap).build();
try {
openSearchClient.cluster().putSettings(request);
fail();
} catch (OpenSearchException e) {
assertNotNull(e);
assertEquals(e.response().status(), 400);
assertEquals(e.getMessage(), "Request failed: [illegal_argument_exception] " + "transient setting [no_idea_what_you_are_talking_about], not recognized");
}
}
use of org.opensearch.client.opensearch.cluster.PutClusterSettingsRequest in project opensearch-java by opensearch-project.
the class ClusterClientIT method testClusterGetSettingsWithDefault.
public void testClusterGetSettingsWithDefault() throws IOException {
OpenSearchClient openSearchClient = highLevelClient();
final String transientSettingKey = RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey();
final String transientSettingValue = "10b";
final String persistentSettingKey = EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey();
final String persistentSettingValue = EnableAllocationDecider.Allocation.NONE.name();
Map<String, JsonData> transientSettingsMap = new HashMap<>();
Map<String, JsonData> persistentSettingsMap = new HashMap<>();
transientSettingsMap.put(transientSettingKey, JsonData.of(transientSettingValue));
persistentSettingsMap.put(persistentSettingKey, JsonData.of(persistentSettingValue));
PutClusterSettingsRequest request = new PutClusterSettingsRequest.Builder().persistent(persistentSettingsMap).transient_(transientSettingsMap).build();
openSearchClient.cluster().putSettings(request);
GetClusterSettingsResponse getSettingsResponse = openSearchClient.cluster().getSettings(new GetClusterSettingsRequest.Builder().includeDefaults(true).build());
assertEquals(1, getSettingsResponse.persistent().size());
assertEquals(1, getSettingsResponse.transient_().size());
assertTrue(getSettingsResponse.defaults().size() > 0);
}
Aggregations