Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wildfly tests use rest high level client #42186

Merged
merged 1 commit into from
May 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions qa/wildfly/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ dependencies {
compile "com.fasterxml.jackson.module:jackson-module-jaxb-annotations:${versions.jackson}"
compile "org.apache.logging.log4j:log4j-api:${versions.log4j}"
compile "org.apache.logging.log4j:log4j-core:${versions.log4j}"
compile project(path: ':client:transport', configuration: 'runtime')
compile project(path: ':client:rest-high-level')
wildfly "org.jboss:wildfly:${wildflyVersion}@zip"
testCompile "org.elasticsearch.test:framework:${VersionProperties.elasticsearch}"
}
Expand All @@ -93,8 +93,7 @@ task writeElasticsearchProperties {
final File elasticsearchProperties = file("${wildflyInstall}/standalone/configuration/elasticsearch.properties")
elasticsearchProperties.write(
[
"transport.uri=${-> integTest.getNodes().get(0).transportUri()}",
"cluster.name=${-> integTest.getNodes().get(0).clusterName}"
"http.uri=${-> integTest.getNodes().get(0).httpUri()}"
].join("\n"))
}
}
Expand Down Expand Up @@ -167,7 +166,7 @@ task startWildfly {
}
}

task configureTransportClient(type: LoggedExec) {
task configureClient(type: LoggedExec) {
dependsOn startWildfly
// we skip these tests on Windows so we do not need to worry about compatibility here
commandLine "${wildflyInstall}/bin/jboss-cli.sh",
Expand All @@ -182,7 +181,7 @@ task stopWildfly(type: LoggedExec) {
}

if (!Os.isFamily(Os.FAMILY_WINDOWS)) {
integTestRunner.dependsOn(configureTransportClient)
integTestRunner.dependsOn(configureClient)
final TaskExecutionAdapter logDumpListener = new TaskExecutionAdapter() {
@Override
void afterExecute(final Task task, final TaskState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import java.util.Set;

@ApplicationPath("/transport")
public class TransportClientActivator extends Application {
public class RestHighLevelClientActivator extends Application {

@Override
public Set<Class<?>> getClasses() {
return Collections.singleton(TransportClientEmployeeResource.class);
return Collections.singleton(RestHighLevelClientEmployeeResource.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@

package org.elasticsearch.wildfly.transport;

import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.wildfly.model.Employee;

Expand All @@ -33,7 +36,6 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
Expand All @@ -44,17 +46,17 @@
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;

@Path("/employees")
public class TransportClientEmployeeResource {
public class RestHighLevelClientEmployeeResource {

@Inject
private TransportClient client;
private RestHighLevelClient client;

@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response getEmployeeById(final @PathParam("id") Long id) {
public Response getEmployeeById(final @PathParam("id") Long id) throws IOException {
Objects.requireNonNull(id);
final GetResponse response = client.prepareGet("megacorp", "employee", Long.toString(id)).get();
final GetResponse response = client.get(new GetRequest("megacorp", Long.toString(id)), RequestOptions.DEFAULT);
if (response.isExists()) {
final Map<String, Object> source = response.getSource();
final Employee employee = new Employee();
Expand Down Expand Up @@ -94,7 +96,10 @@ public Response putEmployeeById(final @PathParam("id") Long id, final Employee e
}
}
builder.endObject();
final IndexResponse response = client.prepareIndex("megacorp", "employee", Long.toString(id)).setSource(builder).get();
final IndexRequest request = new IndexRequest("megacorp");
request.id(Long.toString(id));
request.source(builder);
final IndexResponse response = client.index(request, RequestOptions.DEFAULT);
if (response.status().getStatus() == 201) {
return Response.created(new URI("/employees/" + id)).build();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,34 @@

package org.elasticsearch.wildfly.transport;

import org.elasticsearch.client.transport.TransportClient;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

import javax.enterprise.inject.Produces;

import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Properties;

@SuppressWarnings("unused")
public final class TransportClientProducer {
public final class RestHighLevelClientProducer {

@Produces
public TransportClient createTransportClient() throws IOException {
public RestHighLevelClient createRestHighLevelClient() throws IOException {
final String elasticsearchProperties = System.getProperty("elasticsearch.properties");
final Properties properties = new Properties();

final String transportUri;
final String clusterName;
final String httpUri;
try (InputStream is = Files.newInputStream(getPath(elasticsearchProperties))) {
properties.load(is);
transportUri = properties.getProperty("transport.uri");
clusterName = properties.getProperty("cluster.name");
httpUri = properties.getProperty("http.uri");
}

final int lastColon = transportUri.lastIndexOf(':');
final String host = transportUri.substring(0, lastColon);
final int port = Integer.parseInt(transportUri.substring(lastColon + 1));
final Settings settings = Settings.builder().put("cluster.name", clusterName).build();
final TransportClient transportClient = new PreBuiltTransportClient(settings, Collections.emptyList());
transportClient.addTransportAddress(new TransportAddress(InetAddress.getByName(host), port));
return transportClient;
return new RestHighLevelClient(RestClient.builder(HttpHost.create(httpUri)));
}

@SuppressForbidden(reason = "get path not configured in environment")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
import javax.ws.rs.ext.Provider;

@Provider
public class TransportJacksonJsonProvider extends ResteasyJackson2Provider {
public class RestHighLevelJacksonJsonProvider extends ResteasyJackson2Provider {
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
@TestRuleLimitSysouts.Limit(bytes = 14000)
public class WildflyIT extends LuceneTestCase {

Logger logger = Logger.getLogger(WildflyIT.class);
private Logger logger = Logger.getLogger(WildflyIT.class);

public void testTransportClient() throws URISyntaxException, IOException {
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
Expand Down