Search in sources :

Example 31 with Response

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

the class ReindexRestClientSslTests method testClientPassesClientCertificate.

public void testClientPassesClientCertificate() throws IOException {
    final List<Thread> threads = new ArrayList<>();
    final Path ca = getDataPath("ca.pem");
    final Path cert = getDataPath("client/client.crt");
    final Path key = getDataPath("client/client.key");
    final Settings settings = Settings.builder().put("path.home", createTempDir()).putList("reindex.ssl.certificate_authorities", ca.toString()).put("reindex.ssl.certificate", cert).put("reindex.ssl.key", key).put("reindex.ssl.key_passphrase", "client-password").put("reindex.ssl.supported_protocols", "TLSv1.2").build();
    AtomicReference<Certificate[]> clientCertificates = new AtomicReference<>();
    handler = https -> {
        try {
            clientCertificates.set(https.getSSLSession().getPeerCertificates());
        } catch (SSLPeerUnverifiedException e) {
            logger.warn("Client did not provide certificates", e);
            clientCertificates.set(null);
        }
    };
    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));
        final Certificate[] certs = clientCertificates.get();
        assertThat(certs, Matchers.notNullValue());
        assertThat(certs, Matchers.arrayWithSize(1));
        assertThat(certs[0], Matchers.instanceOf(X509Certificate.class));
        final X509Certificate clientCert = (X509Certificate) certs[0];
        assertThat(clientCert.getSubjectDN().getName(), Matchers.is("CN=client"));
        assertThat(clientCert.getIssuerDN().getName(), Matchers.is("CN=Elastic Certificate Tool Autogenerated CA"));
    }
}
Also used : Path(java.nio.file.Path) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) ArrayList(java.util.ArrayList) RestClient(org.opensearch.client.RestClient) Request(org.opensearch.client.Request) AtomicReference(java.util.concurrent.atomic.AtomicReference) X509Certificate(java.security.cert.X509Certificate) Response(org.opensearch.client.Response) TestEnvironment(org.opensearch.env.TestEnvironment) Environment(org.opensearch.env.Environment) ResourceWatcherService(org.opensearch.watcher.ResourceWatcherService) Settings(org.opensearch.common.settings.Settings) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 32 with Response

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

the class Netty4HeadBodyIsEmptyIT method headTestCase.

private void headTestCase(final String url, final Map<String, String> params, final int expectedStatusCode, final Matcher<Integer> matcher, final String... expectedWarnings) throws IOException {
    Request request = new Request("HEAD", url);
    for (Map.Entry<String, String> param : params.entrySet()) {
        request.addParameter(param.getKey(), param.getValue());
    }
    request.setOptions(expectWarnings(expectedWarnings));
    Response response = client().performRequest(request);
    assertEquals(expectedStatusCode, response.getStatusLine().getStatusCode());
    assertThat(Integer.valueOf(response.getHeader("Content-Length")), matcher);
    assertNull("HEAD requests shouldn't have a response body but " + url + " did", response.getEntity());
}
Also used : Response(org.opensearch.client.Response) Request(org.opensearch.client.Request) Collections.emptyMap(java.util.Collections.emptyMap) Map(java.util.Map) Collections.singletonMap(java.util.Collections.singletonMap)

Example 33 with Response

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

the class Zen2RestApiIT method testClearVotingTombstonesWaitingForRemoval.

public void testClearVotingTombstonesWaitingForRemoval() throws Exception {
    internalCluster().setBootstrapMasterNodeIndex(2);
    List<String> nodes = internalCluster().startNodes(3);
    ensureStableCluster(3);
    RestClient restClient = getRestClient();
    String nodeToWithdraw = nodes.get(randomIntBetween(0, 2));
    Response response = restClient.performRequest(new Request("POST", "/_cluster/voting_config_exclusions/" + nodeToWithdraw));
    assertThat(response.getStatusLine().getStatusCode(), is(200));
    assertThat(response.getEntity().getContentLength(), is(0L));
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodeToWithdraw));
    Response deleteResponse = restClient.performRequest(new Request("DELETE", "/_cluster/voting_config_exclusions"));
    assertThat(deleteResponse.getStatusLine().getStatusCode(), is(200));
    assertThat(deleteResponse.getEntity().getContentLength(), is(0L));
}
Also used : ClusterHealthResponse(org.opensearch.action.admin.cluster.health.ClusterHealthResponse) Response(org.opensearch.client.Response) RestClient(org.opensearch.client.RestClient) Request(org.opensearch.client.Request)

Example 34 with Response

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

the class Zen2RestApiIT method testClearVotingTombstonesNotWaitingForRemoval.

public void testClearVotingTombstonesNotWaitingForRemoval() throws Exception {
    internalCluster().setBootstrapMasterNodeIndex(2);
    List<String> nodes = internalCluster().startNodes(3);
    ensureStableCluster(3);
    RestClient restClient = getRestClient();
    Response response = restClient.performRequest(new Request("POST", "/_cluster/voting_config_exclusions/" + nodes.get(2)));
    assertThat(response.getStatusLine().getStatusCode(), is(200));
    assertThat(response.getEntity().getContentLength(), is(0L));
    Response deleteResponse = restClient.performRequest(new Request("DELETE", "/_cluster/voting_config_exclusions/?wait_for_removal=false"));
    assertThat(deleteResponse.getStatusLine().getStatusCode(), is(200));
    assertThat(deleteResponse.getEntity().getContentLength(), is(0L));
}
Also used : ClusterHealthResponse(org.opensearch.action.admin.cluster.health.ClusterHealthResponse) Response(org.opensearch.client.Response) RestClient(org.opensearch.client.RestClient) Request(org.opensearch.client.Request)

Example 35 with Response

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

the class Zen2RestApiIT method testRemoveTwoNodesAtOnce.

public void testRemoveTwoNodesAtOnce() throws Exception {
    internalCluster().setBootstrapMasterNodeIndex(2);
    List<String> nodes = internalCluster().startNodes(3);
    ensureStableCluster(3);
    RestClient restClient = getRestClient();
    Response response = restClient.performRequest(new Request("POST", "/_cluster/voting_config_exclusions/" + nodes.get(2) + "," + nodes.get(0)));
    assertThat(response.getStatusLine().getStatusCode(), is(200));
    assertThat(response.getEntity().getContentLength(), is(0L));
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodes.get(0)));
    internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodes.get(2)));
    ensureStableCluster(1);
}
Also used : ClusterHealthResponse(org.opensearch.action.admin.cluster.health.ClusterHealthResponse) Response(org.opensearch.client.Response) RestClient(org.opensearch.client.RestClient) Request(org.opensearch.client.Request)

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