usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [04/50] git commit: Changed to use transport client
Date Thu, 06 Nov 2014 00:14:50 GMT
Changed to use transport client


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/a2f00166
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/a2f00166
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/a2f00166

Branch: refs/heads/two-dot-o
Commit: a2f001663d1310117f2dcf14526283837e8af2a9
Parents: 37d8598
Author: Todd Nine <tnine@apigee.com>
Authored: Fri Oct 31 10:43:20 2014 -0600
Committer: Todd Nine <tnine@apigee.com>
Committed: Fri Oct 31 10:43:20 2014 -0600

----------------------------------------------------------------------
 .../persistence/index/impl/EsProvider.java      | 90 +++++++++++++-------
 1 file changed, 59 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a2f00166/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java
index 0a06e8f..ea63ffc 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java
@@ -23,8 +23,10 @@ import java.net.InetAddress;
 import java.net.UnknownHostException;
 
 import org.elasticsearch.client.Client;
+import org.elasticsearch.client.transport.TransportClient;
 import org.elasticsearch.common.settings.ImmutableSettings;
 import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.transport.InetSocketTransportAddress;
 import org.elasticsearch.node.Node;
 import org.elasticsearch.node.NodeBuilder;
 import org.slf4j.Logger;
@@ -48,7 +50,7 @@ public class EsProvider {
 
     private final IndexFig indexFig;
     private static Client client;
-    private static Node node;
+//    private static Node node;
 
     public static String LOCAL_ES_PORT_PROPNAME = "EMBEDDED_ES_PORT";
 
@@ -76,9 +78,7 @@ public class EsProvider {
      */
     public void releaseClient() {
         //reset our static variables
-        if ( client != null && node != null ) {
-            node.stop();
-            node = null;
+        if ( client != null ) {
             client = null;
         }
     }
@@ -87,22 +87,29 @@ public class EsProvider {
     private synchronized void createClient( IndexFig fig ) {
 
 
-        if ( client != null && node != null) {
+        if ( client != null) {
             return;
         }
 
 
-        String allHosts = "";
+
+        final String clusterName = fig.getClusterName();
+        final int port = fig.getPort();
+
+
+        ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder()
+                 .put( "cluster.name", clusterName )
+                 .put( "client.transport.sniff", true );
+
+
+
+//        String allHosts = "";
+
 
 
-            // we will connect to ES on all configured hosts
-            String SEP = "";
-            for ( String host : fig.getHosts().split( "," ) ) {
-                allHosts = allHosts + SEP + host + ":" + fig.getPort();
-                SEP = ",";
-            }
 
         String nodeName = fig.getNodeName();
+
         if ( "default".equals( nodeName ) ) {
             // no nodeName was specified, use hostname
             try {
@@ -114,31 +121,52 @@ public class EsProvider {
             }
         }
 
-        Settings settings = ImmutableSettings.settingsBuilder()
-
-                .put( "cluster.name", fig.getClusterName() )
+        settings.put( "node.name", nodeName);
 
-                        // this assumes that we're using zen for host discovery.  Putting
an
-                        // explicit set of bootstrap hosts ensures we connect to a valid
cluster.
-                .put( "discovery.zen.ping.unicast.hosts", allHosts )
-                .put( "discovery.zen.ping.multicast.enabled", "false" ).put( "http.enabled",
false )
 
-                .put( "client.transport.ping_timeout", 2000 ) // milliseconds
-                .put( "client.transport.nodes_sampler_interval", 100 ).put( "network.tcp.blocking",
true )
-                .put( "node.client", true ).put( "node.name", nodeName )
 
-                .build();
+        TransportClient transportClient = new TransportClient( settings.build() );
+            // we will connect to ES on all configured hosts
+//            String SEP = "";
+            for ( String host : fig.getHosts().split( "," ) ) {
 
-        log.debug( "Creating ElasticSearch client with settings: " + settings.getAsMap()
);
+                transportClient.addTransportAddress( new InetSocketTransportAddress(host,
port));
 
-        // use this client when connecting via socket only,
-        // such as ssh tunnel or other firewall issues
-        // newClient  = new TransportClient(settings).addTransportAddress(
-        //                  new InetSocketTransportAddress("localhost", 9300) );
+//                allHosts = allHosts + SEP + host + ":" + fig.getPort();
+//                SEP = ",";
+            }
 
-        //use this client for quick connectivity
-        node = NodeBuilder.nodeBuilder().settings( settings ).client( true ).node();
-        client = node.client();
+//        Settings settings = ImmutableSettings.settingsBuilder()
+//
+//                .put( "cluster.name", fig.getClusterName() )
+//
+//                        // this assumes that we're using zen for host discovery.  Putting
an
+//                        // explicit set of bootstrap hosts ensures we connect to a valid
cluster.
+//                .put( "discovery.zen.ping.unicast.hosts", allHosts )
+//                .put( "discovery.zen.ping.multicast.enabled", "false" ).put( "http.enabled",
false )
+//                .put("transport.tcp.port", "9300-9400")
+//                .put( "client.transport.ping_timeout", 2000 ) // milliseconds
+//                .put( "client.transport.nodes_sampler_interval", 100 )
+////                .put( "network.tcp.blocking", true )
+//                .put( "node.client", true ).put( "node.name", nodeName+"Random test" )
+//
+//                .build();
+
+//        log.debug( "Creating ElasticSearch client with settings: " + settings.getAsMap()
);
+//
+//        // use this client when connecting via socket only,
+//        // such as ssh tunnel or other firewall issues
+//        // newClient  = new TransportClient(settings).addTransportAddress(
+//        //                  new InetSocketTransportAddress("localhost", 9300) );
+//
+//        //use this client for quick connectivity
+//        node = NodeBuilder.nodeBuilder().settings( settings ).client( true ).node();
+//        client = node.client();
+
+
+
+//                .build();
+       client =  transportClient;
     }
 
 


Mime
View raw message