Skip to content

Commit

Permalink
Fixing merge conflicts and build
Browse files Browse the repository at this point in the history
Signed-off-by: Vacha Shah <[email protected]>
  • Loading branch information
VachaShah committed Oct 11, 2023
1 parent 50e52cb commit eafcdbb
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.opensearch.client.documentation;

import org.apache.http.HttpHost;
import org.junit.Ignore;
import org.junit.Test;
import org.opensearch.client.RestClient;
Expand All @@ -41,7 +42,6 @@
import org.opensearch.client.opensearch.core.search.Hit;
import org.opensearch.client.transport.OpenSearchTransport;
import org.opensearch.client.transport.rest_client.RestClientTransport;
import org.apache.http.HttpHost;

public class ConnectingTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@

package org.opensearch.client.documentation;

import org.apache.http.HttpHost;
import org.junit.Test;
import org.opensearch.client.RestClient;
import org.opensearch.client.RestClientBuilder;
import org.opensearch.client.json.jackson.JacksonJsonpMapper;
import org.opensearch.client.opensearch.OpenSearchClient;
import org.opensearch.client.transport.OpenSearchTransport;
import org.opensearch.client.transport.rest_client.RestClientTransport;
import org.apache.http.HttpHost;

public class MigrateHlrcTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import static java.util.Collections.emptyMap;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -97,9 +98,8 @@ public void testClusterUpdateSettingNonExistent() throws IOException {
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"
e.getMessage(),
"Request failed: [illegal_argument_exception] " + "transient setting [no_idea_what_you_are_talking_about], not recognized"
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

package org.opensearch.client.opensearch.integTest;

import org.apache.http.client.methods.HttpGet;
import java.io.IOException;
import java.util.Map;
import org.apache.http.client.methods.HttpGet;
import org.opensearch.client.Request;
import org.opensearch.client.opensearch.OpenSearchClient;
import org.opensearch.client.opensearch.core.InfoResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@

package org.opensearch.client.opensearch.integTest;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.TreeSet;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.ssl.SSLContextBuilder;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.opensearch.Version;
import org.opensearch.client.RestClient;
import org.opensearch.client.RestClientBuilder;
Expand All @@ -19,25 +34,9 @@
import org.opensearch.client.opensearch.indices.DeleteIndexRequest;
import org.opensearch.client.opensearch.nodes.NodesInfoResponse;
import org.opensearch.client.opensearch.nodes.info.NodeInfo;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.ssl.SSLContextBuilder;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.opensearch.common.settings.Settings;
import org.opensearch.test.rest.OpenSearchRestTestCase;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.TreeSet;

public abstract class OpenSearchJavaClientTestCase extends OpenSearchRestTestCase implements OpenSearchTransportSupport {
private static final List<String> systemIndices = List.of(".opensearch-observability", ".opendistro_security", ".plugins-ml-config");
private static OpenSearchClient javaClient;
Expand Down Expand Up @@ -90,15 +89,12 @@ protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOE
String password = Optional.ofNullable(System.getProperty("password")).orElse("admin");

final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
for (final HttpHost host: hosts) {
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(userName, password));
for (final HttpHost host : hosts) {
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
}


try {
return httpClientBuilder
.setDefaultCredentialsProvider(credentialsProvider)
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)
// disable the certificate since our testing cluster just uses the default security configuration
.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.setSSLContext(SSLContextBuilder.create().loadTrustMaterial(null, (chains, authType) -> true).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import java.io.IOException;
import java.util.Optional;

import org.apache.http.HttpHost;
import org.opensearch.client.opensearch.OpenSearchClient;
import org.opensearch.client.transport.OpenSearchTransport;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
interface HttpClient5TransportSupport extends OpenSearchTransportSupport {
@Override
default OpenSearchTransport buildTransport(Settings settings, org.apache.http.HttpHost[] hosts) throws IOException {
final HttpHost[] converted = Arrays
.stream(hosts)
final HttpHost[] converted = Arrays.stream(hosts)
.map(h -> new HttpHost(h.getSchemeName(), h.getHostName(), h.getPort()))
.toArray(HttpHost[]::new);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package org.opensearch.client.opensearch.integTest.restclient;

import java.io.IOException;

import org.apache.http.HttpHost;
import org.opensearch.client.json.jackson.JacksonJsonpMapper;
import org.opensearch.client.opensearch.integTest.AbstractClusterClientIT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package org.opensearch.client.opensearch.integTest.restclient;

import java.io.IOException;

import org.apache.http.HttpHost;
import org.opensearch.client.json.jackson.JacksonJsonpMapper;
import org.opensearch.client.opensearch.integTest.AbstractCrudIT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package org.opensearch.client.opensearch.integTest.restclient;

import java.io.IOException;

import org.apache.http.HttpHost;
import org.opensearch.client.json.jackson.JacksonJsonpMapper;
import org.opensearch.client.opensearch.integTest.AbstractHighlightIT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package org.opensearch.client.opensearch.integTest.restclient;

import java.io.IOException;

import org.apache.http.HttpHost;
import org.opensearch.client.json.jackson.JacksonJsonpMapper;
import org.opensearch.client.opensearch.integTest.AbstractIndicesClientIT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package org.opensearch.client.opensearch.integTest.restclient;

import java.io.IOException;

import org.apache.http.HttpHost;
import org.opensearch.client.json.jackson.JacksonJsonpMapper;
import org.opensearch.client.opensearch.integTest.AbstractNodesIT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package org.opensearch.client.opensearch.integTest.restclient;

import java.io.IOException;

import org.apache.http.HttpHost;
import org.opensearch.client.json.jackson.JacksonJsonpMapper;
import org.opensearch.client.opensearch.integTest.AbstractPingAndInfoIT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import java.io.IOException;
import java.util.Optional;

import javax.net.ssl.SSLContext;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
Expand All @@ -35,10 +35,6 @@
import org.opensearch.client.transport.rest_client.RestClientTransport;
import org.opensearch.common.settings.Settings;

import javax.net.ssl.SSLContext;

import static org.hamcrest.CoreMatchers.equalTo;

public class RequestIT extends AbstractRequestIT {
@Override
public OpenSearchTransport buildTransport(Settings settings, HttpHost[] hosts) throws IOException {
Expand All @@ -54,23 +50,22 @@ public void testUnauthorized() throws Exception {
final String wrongPassword = Optional.ofNullable(System.getProperty("password")).orElse("admin") + "wrong";

final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(getClusterHosts().get(0)),
new UsernamePasswordCredentials(userName, wrongPassword));
credentialsProvider.setCredentials(
new AuthScope(getClusterHosts().get(0)),
new UsernamePasswordCredentials(userName, wrongPassword)
);

final RestClient restClient = RestClient
.builder(getClusterHosts().toArray(new HttpHost[0]))
.setHttpClientConfigCallback(httpClientBuilder -> {
try {
final TrustStrategy trustStrategy = new TrustAllStrategy();
final SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(
null, trustStrategy).build();
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)
.setSSLContext(sslContext);
} catch (Exception e) {
throw new RuntimeException(e);
}
})
.build();
final RestClient restClient = RestClient.builder(getClusterHosts().toArray(new HttpHost[0]))
.setHttpClientConfigCallback(httpClientBuilder -> {
try {
final TrustStrategy trustStrategy = new TrustAllStrategy();
final SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, trustStrategy).build();
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider).setSSLContext(sslContext);
} catch (Exception e) {
throw new RuntimeException(e);
}
})
.build();

final RestClientTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
final OpenSearchClient client = new OpenSearchClient(transport);
Expand Down

0 comments on commit eafcdbb

Please sign in to comment.