-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A simple app to verify TransportClient access to an Elasticsearch
cluster
- Loading branch information
Jeff Tharp
committed
Mar 4, 2015
0 parents
commit 0cbc530
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## elasticsearch-test-client | ||
|
||
Simple application to verify TransportClient connectivity to an Elasticsearch cluster. | ||
Uses Elasticsearch 1.4.3 by default, adjust pom.xml to specify other versions | ||
|
||
### Usage | ||
|
||
`java -jar esTestTransportClient.jar ClusterName host1:port,host2:port,host3:port` | ||
|
||
### Example Output | ||
|
||
``` | ||
Connecting to eaf1fe49e76ea1b2782ac45879ce5952... | ||
Mar 03, 2015 10:38:53 PM org.elasticsearch.plugins.PluginsService <init> | ||
INFO: [Cybelle] loaded [], sites [] | ||
Last status: GREEN | ||
``` | ||
|
||
This shows that a connection was made and the cluster status was GREEN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.objectrocket</groupId> | ||
<artifactId>esTestClient</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>Elasticsearch Test Client</name> | ||
<description>A client to test native connectivity</description> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.elasticsearch</groupId> | ||
<artifactId>elasticsearch</artifactId> | ||
<version>1.4.3</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus; | ||
import org.elasticsearch.common.settings.ImmutableSettings; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.transport.InetSocketTransportAddress; | ||
import org.elasticsearch.client.transport.TransportClient; | ||
|
||
|
||
public class esTestTransportClient { | ||
private String cluster_name; | ||
private String[] host_list; | ||
|
||
public esTestTransportClient(String cname, String hlist) { | ||
cluster_name = cname; | ||
host_list = hlist.split(",", -1); | ||
} | ||
|
||
private void connect() { | ||
System.out.println("Connecting to " + cluster_name + "..."); | ||
Settings settings = ImmutableSettings.settingsBuilder() | ||
.put("cluster.name", cluster_name).build(); | ||
|
||
TransportClient client = new TransportClient(settings); | ||
for(String host: host_list) { | ||
int port = 9300; | ||
|
||
//Parse port from host string | ||
String[] parsedHost = host.split(":", 2); | ||
if(parsedHost.length == 2) { | ||
host = parsedHost[0]; | ||
port = Integer.parseInt(parsedHost[1]); | ||
} | ||
|
||
client.addTransportAddress(new InetSocketTransportAddress(host, port)); | ||
} | ||
|
||
final ClusterHealthStatus status = client.admin().cluster().prepareHealth().get().getStatus(); | ||
System.out.println("Last status: " + status.name()); | ||
client.close(); | ||
} | ||
|
||
public static void main(String[] args) { | ||
String cname; | ||
String hlist; | ||
|
||
if(args.length != 0) { | ||
cname = args[0]; | ||
hlist = args[1]; | ||
|
||
try { | ||
esTestTransportClient esclient = new esTestTransportClient(cname, hlist); | ||
esclient.connect(); | ||
} | ||
catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
System.exit(0); | ||
} | ||
} | ||
} |