Search in sources :

Example 1 with MainResponse

use of org.opensearch.client.core.MainResponse in project OpenSearch by opensearch-project.

the class RestHighLevelClientTests method testInfo.

public void testInfo() throws IOException {
    MainResponse testInfo = new MainResponse("nodeName", new MainResponse.Version("number", "buildType", "buildHash", "buildDate", true, "luceneVersion", "minimumWireCompatibilityVersion", "minimumIndexCompatibilityVersion"), "clusterName", "clusterUuid");
    mockResponse((ToXContentFragment) (builder, params) -> {
        // taken from the server side MainResponse
        builder.field("name", testInfo.getNodeName());
        builder.field("cluster_name", testInfo.getClusterName());
        builder.field("cluster_uuid", testInfo.getClusterUuid());
        builder.startObject("version").field("number", testInfo.getVersion().getNumber()).field("build_type", testInfo.getVersion().getBuildType()).field("build_hash", testInfo.getVersion().getBuildHash()).field("build_date", testInfo.getVersion().getBuildDate()).field("build_snapshot", testInfo.getVersion().isSnapshot()).field("lucene_version", testInfo.getVersion().getLuceneVersion()).field("minimum_wire_compatibility_version", testInfo.getVersion().getMinimumWireCompatibilityVersion()).field("minimum_index_compatibility_version", testInfo.getVersion().getMinimumIndexCompatibilityVersion()).endObject();
        return builder;
    });
    MainResponse receivedInfo = restHighLevelClient.info(RequestOptions.DEFAULT);
    assertEquals(testInfo, receivedInfo);
}
Also used : InternalAggregationTestCase(org.opensearch.test.InternalAggregationTestCase) Arrays(java.util.Arrays) Aggregation(org.opensearch.search.aggregations.Aggregation) MainResponse(org.opensearch.client.core.MainResponse) ToXContentFragment(org.opensearch.common.xcontent.ToXContentFragment) CheckedFunction(org.opensearch.common.CheckedFunction) ToXContent(org.opensearch.common.xcontent.ToXContent) CoreMatchers.endsWith(org.hamcrest.CoreMatchers.endsWith) ChildrenAggregationBuilder(org.opensearch.join.aggregations.ChildrenAggregationBuilder) ActionRequest(org.opensearch.action.ActionRequest) OpenSearchException(org.opensearch.OpenSearchException) StatusLine(org.apache.http.StatusLine) NByteArrayEntity(org.apache.http.nio.entity.NByteArrayEntity) XContentParser(org.opensearch.common.xcontent.XContentParser) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) EvaluationMetric(org.opensearch.index.rankeval.EvaluationMetric) RequestLine(org.apache.http.RequestLine) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InternalAggregations(org.opensearch.search.aggregations.InternalAggregations) Map(java.util.Map) NStringEntity(org.apache.http.nio.entity.NStringEntity) ActionListener(org.opensearch.action.ActionListener) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Method(java.lang.reflect.Method) PrecisionAtK(org.opensearch.index.rankeval.PrecisionAtK) ClientYamlSuiteRestSpec(org.opensearch.test.rest.yaml.restspec.ClientYamlSuiteRestSpec) MetricDetail(org.opensearch.index.rankeval.MetricDetail) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) HttpEntity(org.apache.http.HttpEntity) ContentType(org.apache.http.entity.ContentType) Set(java.util.Set) RestStatus(org.opensearch.rest.RestStatus) Collectors(java.util.stream.Collectors) Tuple(org.opensearch.common.collect.Tuple) RecallAtK(org.opensearch.index.rankeval.RecallAtK) List(java.util.List) Stream(java.util.stream.Stream) HttpGet(org.apache.http.client.methods.HttpGet) Modifier(java.lang.reflect.Modifier) Optional(java.util.Optional) MeanReciprocalRank(org.opensearch.index.rankeval.MeanReciprocalRank) Mockito.any(org.mockito.Mockito.any) SmileXContent(org.opensearch.common.xcontent.smile.SmileXContent) Mockito.mock(org.mockito.Mockito.mock) BytesReference(org.opensearch.common.bytes.BytesReference) BasicStatusLine(org.apache.http.message.BasicStatusLine) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) CborXContent(org.opensearch.common.xcontent.cbor.CborXContent) ExpectedReciprocalRank(org.opensearch.index.rankeval.ExpectedReciprocalRank) HashMap(java.util.HashMap) SearchHits(org.opensearch.search.SearchHits) AtomicReference(java.util.concurrent.atomic.AtomicReference) ActionRequestValidationException(org.opensearch.action.ActionRequestValidationException) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) XContentHelper.toXContent(org.opensearch.common.xcontent.XContentHelper.toXContent) SearchScrollRequest(org.opensearch.action.search.SearchScrollRequest) SocketTimeoutException(java.net.SocketTimeoutException) ClearScrollResponse(org.opensearch.action.search.ClearScrollResponse) SearchResponse(org.opensearch.action.search.SearchResponse) ClientYamlSuiteRestApi(org.opensearch.test.rest.yaml.restspec.ClientYamlSuiteRestApi) MainRequest(org.opensearch.client.core.MainRequest) Before(org.junit.Before) MatrixStatsAggregationBuilder(org.opensearch.search.aggregations.matrix.stats.MatrixStatsAggregationBuilder) BasicRequestLine(org.apache.http.message.BasicRequestLine) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder) DiscountedCumulativeGain(org.opensearch.index.rankeval.DiscountedCumulativeGain) ProtocolVersion(org.apache.http.ProtocolVersion) Sets(org.opensearch.common.util.set.Sets) SearchResponseSections(org.opensearch.action.search.SearchResponseSections) Suggest(org.opensearch.search.suggest.Suggest) ClearScrollRequest(org.opensearch.action.search.ClearScrollRequest) ShardSearchFailure(org.opensearch.action.search.ShardSearchFailure) NamedXContentRegistry(org.opensearch.common.xcontent.NamedXContentRegistry) HttpResponse(org.apache.http.HttpResponse) HttpHost(org.apache.http.HttpHost) Collections(java.util.Collections) MainResponse(org.opensearch.client.core.MainResponse)

Example 2 with MainResponse

use of org.opensearch.client.core.MainResponse in project OpenSearch by opensearch-project.

the class PingAndInfoIT method testInfo.

public void testInfo() throws IOException {
    MainResponse info = highLevelClient().info(RequestOptions.DEFAULT);
    // compare with what the low level client outputs
    Map<String, Object> infoAsMap = entityAsMap(adminClient().performRequest(new Request(HttpGet.METHOD_NAME, "/")));
    assertEquals(infoAsMap.get("cluster_name"), info.getClusterName());
    assertEquals(infoAsMap.get("cluster_uuid"), info.getClusterUuid());
    // only check node name existence, might be a different one from what was hit by low level client in multi-node cluster
    assertNotNull(info.getNodeName());
    @SuppressWarnings("unchecked") Map<String, Object> versionMap = (Map<String, Object>) infoAsMap.get("version");
    assertEquals(versionMap.get("build_type"), info.getVersion().getBuildType());
    assertEquals(versionMap.get("build_hash"), info.getVersion().getBuildHash());
    assertEquals(versionMap.get("build_date"), info.getVersion().getBuildDate());
    assertEquals(versionMap.get("build_snapshot"), info.getVersion().isSnapshot());
    assertTrue(versionMap.get("number").toString().startsWith(info.getVersion().getNumber()));
    assertEquals(versionMap.get("lucene_version"), info.getVersion().getLuceneVersion());
}
Also used : MainResponse(org.opensearch.client.core.MainResponse) Map(java.util.Map)

Example 3 with MainResponse

use of org.opensearch.client.core.MainResponse in project OpenSearch by opensearch-project.

the class PingAndInfoIT method testInfo_overrideResponseVersion.

public void testInfo_overrideResponseVersion() throws IOException {
    Request overrideResponseVersionRequest = new Request("PUT", "/_cluster/settings");
    overrideResponseVersionRequest.setOptions(expectWarnings(TransportMainAction.OVERRIDE_MAIN_RESPONSE_VERSION_DEPRECATION_MESSAGE));
    overrideResponseVersionRequest.setJsonEntity("{\"persistent\":{\"compatibility\": {\"override_main_response_version\":true}}}");
    client().performRequest(overrideResponseVersionRequest);
    MainResponse info = highLevelClient().info(RequestOptions.DEFAULT);
    assertEquals("7.10.2", info.getVersion().getNumber());
    // Set back to default version.
    Request resetResponseVersionRequest = new Request("PUT", "/_cluster/settings");
    resetResponseVersionRequest.setJsonEntity("{\"persistent\":{\"compatibility\": {\"override_main_response_version\":null}}}");
    client().performRequest(resetResponseVersionRequest);
    Map<String, Object> infoAsMap = entityAsMap(adminClient().performRequest(new Request(HttpGet.METHOD_NAME, "/")));
    @SuppressWarnings("unchecked") Map<String, Object> versionMap = (Map<String, Object>) infoAsMap.get("version");
    info = highLevelClient().info(RequestOptions.DEFAULT);
    assertTrue(versionMap.get("number").toString().startsWith(info.getVersion().getNumber()));
}
Also used : MainResponse(org.opensearch.client.core.MainResponse) Map(java.util.Map)

Aggregations

Map (java.util.Map)3 MainResponse (org.opensearch.client.core.MainResponse)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 Modifier (java.lang.reflect.Modifier)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 HttpEntity (org.apache.http.HttpEntity)1