use of org.opensearch.action.admin.cluster.settings.ClusterGetSettingsRequest in project OpenSearch by opensearch-project.
the class ClusterRequestConvertersTests method testClusterGetSettings.
public void testClusterGetSettings() throws IOException {
ClusterGetSettingsRequest request = new ClusterGetSettingsRequest();
Map<String, String> expectedParams = new HashMap<>();
RequestConvertersTests.setRandomMasterTimeout(request, expectedParams);
request.includeDefaults(OpenSearchTestCase.randomBoolean());
if (request.includeDefaults()) {
expectedParams.put("include_defaults", String.valueOf(true));
}
Request expectedRequest = ClusterRequestConverters.clusterGetSettings(request);
Assert.assertEquals("/_cluster/settings", expectedRequest.getEndpoint());
Assert.assertEquals(HttpGet.METHOD_NAME, expectedRequest.getMethod());
Assert.assertEquals(expectedParams, expectedRequest.getParameters());
}
use of org.opensearch.action.admin.cluster.settings.ClusterGetSettingsRequest in project OpenSearch by opensearch-project.
the class ClusterClientIT method testClusterGetSettings.
public void testClusterGetSettings() 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();
Settings persistentSettings = Settings.builder().put(persistentSettingKey, persistentSettingValue).build();
clusterUpdateSettings(persistentSettings, transientSettings);
ClusterGetSettingsRequest request = new ClusterGetSettingsRequest();
ClusterGetSettingsResponse response = execute(request, highLevelClient().cluster()::getSettings, highLevelClient().cluster()::getSettingsAsync);
assertEquals(persistentSettings, response.getPersistentSettings());
assertEquals(transientSettings, response.getTransientSettings());
assertEquals(0, response.getDefaultSettings().size());
}
use of org.opensearch.action.admin.cluster.settings.ClusterGetSettingsRequest in project OpenSearch by opensearch-project.
the class ClusterClientDocumentationIT method testClusterGetSettings.
@SuppressWarnings("unused")
public void testClusterGetSettings() throws IOException {
RestHighLevelClient client = highLevelClient();
// tag::get-settings-request
ClusterGetSettingsRequest request = new ClusterGetSettingsRequest();
// end::get-settings-request
// tag::get-settings-request-includeDefaults
// <1>
request.includeDefaults(true);
// end::get-settings-request-includeDefaults
// tag::get-settings-request-local
// <1>
request.local(true);
// end::get-settings-request-local
// tag::get-settings-request-masterTimeout
// <1>
request.masterNodeTimeout(TimeValue.timeValueMinutes(1));
// <2>
request.masterNodeTimeout("1m");
// end::get-settings-request-masterTimeout
// tag::get-settings-execute
// <1>
ClusterGetSettingsResponse response = client.cluster().getSettings(request, RequestOptions.DEFAULT);
// end::get-settings-execute
// tag::get-settings-response
// <1>
Settings persistentSettings = response.getPersistentSettings();
// <2>
Settings transientSettings = response.getTransientSettings();
// <3>
Settings defaultSettings = response.getDefaultSettings();
// <4>
String settingValue = response.getSetting("cluster.routing.allocation.enable");
// end::get-settings-response
assertThat(defaultSettings.size(), greaterThan(0));
}
use of org.opensearch.action.admin.cluster.settings.ClusterGetSettingsRequest in project OpenSearch by opensearch-project.
the class ClusterClientDocumentationIT method testClusterGetSettingsAsync.
public void testClusterGetSettingsAsync() throws InterruptedException {
RestHighLevelClient client = highLevelClient();
ClusterGetSettingsRequest request = new ClusterGetSettingsRequest();
// tag::get-settings-execute-listener
ActionListener<ClusterGetSettingsResponse> listener = new ActionListener<ClusterGetSettingsResponse>() {
@Override
public void onResponse(ClusterGetSettingsResponse response) {
// <1>
}
@Override
public void onFailure(Exception e) {
// <2>
}
};
// end::get-settings-execute-listener
// Replace the empty listener by a blocking listener in test
final CountDownLatch latch = new CountDownLatch(1);
listener = new LatchedActionListener<>(listener, latch);
// tag::get-settings-execute-async
// <1>
client.cluster().getSettingsAsync(request, RequestOptions.DEFAULT, listener);
// end::get-settings-execute-async
assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
use of org.opensearch.action.admin.cluster.settings.ClusterGetSettingsRequest in project OpenSearch by opensearch-project.
the class ClusterClientIT method testRemoteInfo.
public void testRemoteInfo() throws Exception {
String clusterAlias = "local_cluster";
setupRemoteClusterConfig(clusterAlias);
ClusterGetSettingsRequest settingsRequest = new ClusterGetSettingsRequest();
settingsRequest.includeDefaults(true);
ClusterGetSettingsResponse settingsResponse = highLevelClient().cluster().getSettings(settingsRequest, RequestOptions.DEFAULT);
List<String> seeds = SniffConnectionStrategy.REMOTE_CLUSTER_SEEDS.getConcreteSettingForNamespace(clusterAlias).get(settingsResponse.getTransientSettings());
int connectionsPerCluster = SniffConnectionStrategy.REMOTE_CONNECTIONS_PER_CLUSTER.get(settingsResponse.getTransientSettings());
TimeValue initialConnectionTimeout = RemoteClusterService.REMOTE_INITIAL_CONNECTION_TIMEOUT_SETTING.get(settingsResponse.getTransientSettings());
boolean skipUnavailable = RemoteClusterService.REMOTE_CLUSTER_SKIP_UNAVAILABLE.getConcreteSettingForNamespace(clusterAlias).get(settingsResponse.getTransientSettings());
RemoteInfoRequest request = new RemoteInfoRequest();
RemoteInfoResponse response = execute(request, highLevelClient().cluster()::remoteInfo, highLevelClient().cluster()::remoteInfoAsync);
assertThat(response, notNullValue());
assertThat(response.getInfos().size(), equalTo(1));
RemoteConnectionInfo info = response.getInfos().get(0);
assertThat(info.getClusterAlias(), equalTo(clusterAlias));
assertThat(info.getInitialConnectionTimeoutString(), equalTo(initialConnectionTimeout.toString()));
assertThat(info.isSkipUnavailable(), equalTo(skipUnavailable));
assertThat(info.getModeInfo().modeName(), equalTo(SniffModeInfo.NAME));
assertThat(info.getModeInfo().isConnected(), equalTo(true));
SniffModeInfo sniffModeInfo = (SniffModeInfo) info.getModeInfo();
assertThat(sniffModeInfo.getMaxConnectionsPerCluster(), equalTo(connectionsPerCluster));
assertThat(sniffModeInfo.getNumNodesConnected(), equalTo(1));
assertThat(sniffModeInfo.getSeedNodes(), equalTo(seeds));
}
Aggregations