Search in sources :

Example 6 with OpenSearchClient

use of org.opensearch.client.opensearch.OpenSearchClient 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);
}
Also used : HashMap(java.util.HashMap) PutClusterSettingsRequest(org.opensearch.client.opensearch.cluster.PutClusterSettingsRequest) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) PutClusterSettingsResponse(org.opensearch.client.opensearch.cluster.PutClusterSettingsResponse) JsonData(org.opensearch.client.json.JsonData)

Example 7 with OpenSearchClient

use of org.opensearch.client.opensearch.OpenSearchClient in project opensearch-java by opensearch-project.

the class ClusterClientIT method testClusterHealthNotFoundIndex.

public void testClusterHealthNotFoundIndex() throws IOException {
    OpenSearchClient openSearchClient = highLevelClient();
    createIndex("index", Settings.EMPTY);
    HealthRequest request = new HealthRequest.Builder().index("notexisted-index").timeout(t -> t.time("5s")).level(Level.Indices).build();
    try {
        HealthResponse response = openSearchClient.cluster().health(request);
        assertNotNull(response);
        assertTrue(response.timedOut());
        assertEquals(response.status(), HealthStatus.Red);
        assertNoIndices(response);
    } catch (ResponseException e) {
        assertNotNull(e);
    }
}
Also used : HealthRequest(org.opensearch.client.opensearch.cluster.HealthRequest) ResponseException(org.opensearch.client.ResponseException) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) HealthResponse(org.opensearch.client.opensearch.cluster.HealthResponse)

Example 8 with OpenSearchClient

use of org.opensearch.client.opensearch.OpenSearchClient 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");
    }
}
Also used : HashMap(java.util.HashMap) PutClusterSettingsRequest(org.opensearch.client.opensearch.cluster.PutClusterSettingsRequest) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) OpenSearchException(org.opensearch.client.opensearch._types.OpenSearchException) JsonData(org.opensearch.client.json.JsonData)

Example 9 with OpenSearchClient

use of org.opensearch.client.opensearch.OpenSearchClient 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);
}
Also used : GetClusterSettingsResponse(org.opensearch.client.opensearch.cluster.GetClusterSettingsResponse) HashMap(java.util.HashMap) GetClusterSettingsRequest(org.opensearch.client.opensearch.cluster.GetClusterSettingsRequest) PutClusterSettingsRequest(org.opensearch.client.opensearch.cluster.PutClusterSettingsRequest) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) JsonData(org.opensearch.client.json.JsonData)

Example 10 with OpenSearchClient

use of org.opensearch.client.opensearch.OpenSearchClient in project opensearch-java by opensearch-project.

the class ClusterClientIT method testClusterHealthYellowSpecificIndex.

public void testClusterHealthYellowSpecificIndex() throws IOException {
    OpenSearchClient openSearchClient = highLevelClient();
    createIndex("index", Settings.EMPTY);
    createIndex("index2", Settings.EMPTY);
    HealthRequest request = new HealthRequest.Builder().index("index").timeout(t -> t.time("5s")).level(Level.Shards).build();
    HealthResponse response = openSearchClient.cluster().health(request);
    assertNotNull(response);
    assertFalse(response.timedOut());
    assertEquals(response.status(), HealthStatus.Yellow);
    assertEquals(response.activePrimaryShards(), 1);
    assertEquals(response.numberOfDataNodes(), 1);
    assertEquals(response.numberOfNodes(), 1);
    assertEquals(response.activeShards(), 1);
    assertEquals(response.delayedUnassignedShards(), 0);
    assertEquals(response.initializingShards(), 0);
    assertEquals(response.unassignedShards(), 1);
    assertEquals(response.indices().size(), 1);
    Map.Entry<String, IndexHealthStats> index = response.indices().entrySet().iterator().next();
    assertYellowIndex(index.getKey(), index.getValue(), false);
}
Also used : HealthRequest(org.opensearch.client.opensearch.cluster.HealthRequest) IndexHealthStats(org.opensearch.client.opensearch.cluster.health.IndexHealthStats) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) Collections.emptyMap(java.util.Collections.emptyMap) HashMap(java.util.HashMap) Map(java.util.Map) HealthResponse(org.opensearch.client.opensearch.cluster.HealthResponse)

Aggregations

OpenSearchClient (org.opensearch.client.opensearch.OpenSearchClient)19 HashMap (java.util.HashMap)11 Map (java.util.Map)9 Test (org.junit.Test)8 OpenSearchTransport (org.opensearch.client.transport.OpenSearchTransport)7 List (java.util.List)5 Assert (org.junit.Assert)5 JsonData (org.opensearch.client.json.JsonData)5 PutClusterSettingsRequest (org.opensearch.client.opensearch.cluster.PutClusterSettingsRequest)5 SearchResponse (org.opensearch.client.opensearch.core.SearchResponse)5 Alias (org.opensearch.client.opensearch.indices.Alias)5 CreateIndexResponse (org.opensearch.client.opensearch.indices.CreateIndexResponse)5 Arrays (java.util.Arrays)4 LogManager (java.util.logging.LogManager)4 Logger (java.util.logging.Logger)4 OpenSearchAsyncClient (org.opensearch.client.opensearch.OpenSearchAsyncClient)4 NodeStatistics (org.opensearch.client.opensearch._types.NodeStatistics)4 SortOrder (org.opensearch.client.opensearch._types.SortOrder)4 Aggregation (org.opensearch.client.opensearch._types.aggregations.Aggregation)4 Query (org.opensearch.client.opensearch._types.query_dsl.Query)4