Search in sources :

Example 26 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class OpenSearchDashboardsSystemIndexIT method testIndexingAndUpdatingDocs.

public void testIndexingAndUpdatingDocs() throws IOException {
    Request request = new Request("PUT", "/_opensearch_dashboards/" + indexName + "/_doc/1");
    request.setJsonEntity("{ \"foo\" : \"bar\" }");
    Response response = client().performRequest(request);
    assertThat(response.getStatusLine().getStatusCode(), is(201));
    request = new Request("PUT", "/_opensearch_dashboards/" + indexName + "/_create/2");
    request.setJsonEntity("{ \"foo\" : \"bar\" }");
    response = client().performRequest(request);
    assertThat(response.getStatusLine().getStatusCode(), is(201));
    request = new Request("POST", "/_opensearch_dashboards/" + indexName + "/_doc");
    request.setJsonEntity("{ \"foo\" : \"bar\" }");
    response = client().performRequest(request);
    assertThat(response.getStatusLine().getStatusCode(), is(201));
    request = new Request("GET", "/_opensearch_dashboards/" + indexName + "/_refresh");
    response = client().performRequest(request);
    assertThat(response.getStatusLine().getStatusCode(), is(200));
    request = new Request("POST", "/_opensearch_dashboards/" + indexName + "/_update/1");
    request.setJsonEntity("{ \"doc\" : { \"foo\" : \"baz\" } }");
    response = client().performRequest(request);
    assertThat(response.getStatusLine().getStatusCode(), is(200));
}
Also used : Response(org.opensearch.client.Response) Request(org.opensearch.client.Request)

Example 27 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class OpenSearchDashboardsSystemIndexIT method testGetFromOpenSearchDashboardsIndex.

public void testGetFromOpenSearchDashboardsIndex() throws IOException {
    Request request = new Request("POST", "/_opensearch_dashboards/_bulk");
    request.setJsonEntity("{ \"index\" : { \"_index\" : \"" + indexName + "\", \"_id\" : \"1\" } }\n{ \"foo\" : \"bar\" }\n");
    request.addParameter("refresh", "true");
    Response response = client().performRequest(request);
    assertThat(response.getStatusLine().getStatusCode(), is(200));
    Request getRequest = new Request("GET", "/_opensearch_dashboards/" + indexName + "/_doc/1");
    Response getResponse = client().performRequest(getRequest);
    assertThat(getResponse.getStatusLine().getStatusCode(), is(200));
    String responseBody = EntityUtils.toString(getResponse.getEntity());
    assertThat(responseBody, containsString("foo"));
    assertThat(responseBody, containsString("bar"));
}
Also used : Response(org.opensearch.client.Response) Request(org.opensearch.client.Request) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 28 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class OpenSearchDashboardsSystemIndexIT method testMultiGetFromOpenSearchDashboardsIndex.

public void testMultiGetFromOpenSearchDashboardsIndex() throws IOException {
    Request request = new Request("POST", "/_opensearch_dashboards/_bulk");
    request.setJsonEntity("{ \"index\" : { \"_index\" : \"" + indexName + "\", \"_id\" : \"1\" } }\n{ \"foo\" : \"bar\" }\n" + "{ \"index\" : { \"_index\" : \"" + indexName + "\", \"_id\" : \"2\" } }\n{ \"baz\" : \"tag\" }\n");
    request.addParameter("refresh", "true");
    Response response = client().performRequest(request);
    assertThat(response.getStatusLine().getStatusCode(), is(200));
    Request getRequest = new Request("GET", "/_opensearch_dashboards/_mget");
    getRequest.setJsonEntity("{ \"docs\" : [ { \"_index\" : \"" + indexName + "\", \"_id\" : \"1\" }, " + "{ \"_index\" : \"" + indexName + "\", \"_id\" : \"2\" } ] }\n");
    Response getResponse = client().performRequest(getRequest);
    assertThat(getResponse.getStatusLine().getStatusCode(), is(200));
    String responseBody = EntityUtils.toString(getResponse.getEntity());
    assertThat(responseBody, containsString("foo"));
    assertThat(responseBody, containsString("bar"));
    assertThat(responseBody, containsString("baz"));
    assertThat(responseBody, containsString("tag"));
}
Also used : Response(org.opensearch.client.Response) Request(org.opensearch.client.Request) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 29 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class ReindexRestClientSslTests method testClientSucceedsWithCertificateAuthorities.

public void testClientSucceedsWithCertificateAuthorities() throws IOException {
    final List<Thread> threads = new ArrayList<>();
    final Path ca = getDataPath("ca.pem");
    final Settings settings = Settings.builder().put("path.home", createTempDir()).putList("reindex.ssl.certificate_authorities", ca.toString()).put("reindex.ssl.supported_protocols", "TLSv1.2").build();
    final Environment environment = TestEnvironment.newEnvironment(settings);
    final ReindexSslConfig ssl = new ReindexSslConfig(settings, environment, mock(ResourceWatcherService.class));
    try (RestClient client = Reindexer.buildRestClient(getRemoteInfo(), ssl, 1L, threads)) {
        final Response response = client.performRequest(new Request("GET", "/"));
        assertThat(response.getStatusLine().getStatusCode(), Matchers.is(200));
    }
}
Also used : Path(java.nio.file.Path) Response(org.opensearch.client.Response) ArrayList(java.util.ArrayList) RestClient(org.opensearch.client.RestClient) Request(org.opensearch.client.Request) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) ResourceWatcherService(org.opensearch.watcher.ResourceWatcherService) Settings(org.opensearch.common.settings.Settings)

Example 30 with Response

use of org.opensearch.client.Response in project OpenSearch by opensearch-project.

the class ReindexRestClientSslTests method testClientSucceedsWithVerificationDisabled.

public void testClientSucceedsWithVerificationDisabled() throws IOException {
    assumeFalse("Cannot disable verification in FIPS JVM", inFipsJvm());
    final List<Thread> threads = new ArrayList<>();
    final Settings settings = Settings.builder().put("path.home", createTempDir()).put("reindex.ssl.verification_mode", "NONE").put("reindex.ssl.supported_protocols", "TLSv1.2").build();
    final Environment environment = TestEnvironment.newEnvironment(settings);
    final ReindexSslConfig ssl = new ReindexSslConfig(settings, environment, mock(ResourceWatcherService.class));
    try (RestClient client = Reindexer.buildRestClient(getRemoteInfo(), ssl, 1L, threads)) {
        final Response response = client.performRequest(new Request("GET", "/"));
        assertThat(response.getStatusLine().getStatusCode(), Matchers.is(200));
    }
}
Also used : Response(org.opensearch.client.Response) ArrayList(java.util.ArrayList) RestClient(org.opensearch.client.RestClient) Request(org.opensearch.client.Request) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) ResourceWatcherService(org.opensearch.watcher.ResourceWatcherService) Settings(org.opensearch.common.settings.Settings)

Aggregations

Response (org.opensearch.client.Response)134 Request (org.opensearch.client.Request)113 ResponseException (org.opensearch.client.ResponseException)24 Map (java.util.Map)23 Matchers.containsString (org.hamcrest.Matchers.containsString)20 ArrayList (java.util.ArrayList)17 PutRepositoryRequest (org.opensearch.action.admin.cluster.repositories.put.PutRepositoryRequest)16 RestClient (org.opensearch.client.RestClient)15 HashMap (java.util.HashMap)14 RequestOptions (org.opensearch.client.RequestOptions)12 ObjectPath (org.opensearch.test.rest.yaml.ObjectPath)12 IndexRequest (org.opensearch.action.index.IndexRequest)11 IOException (java.io.IOException)10 List (java.util.List)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 Version (org.opensearch.Version)8 WriteRequest (org.opensearch.action.support.WriteRequest)8 ListTasksResponse (org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse)7 IndexResponse (org.opensearch.action.index.IndexResponse)7 CreateIndexRequest (org.opensearch.client.indices.CreateIndexRequest)7