incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [6/8] git commit: Fixed BLUR-293
Date Tue, 05 Nov 2013 02:07:18 GMT
Fixed BLUR-293


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

Branch: refs/heads/master
Commit: 6e272a769eb0c4162d9b7c1a28af79addd256cdc
Parents: 292de85
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Sun Nov 3 10:05:46 2013 -0500
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Mon Nov 4 16:12:32 2013 -0500

----------------------------------------------------------------------
 .../blur/server/ControllerServerContext.java    |   19 +-
 .../apache/blur/server/ShardServerContext.java  |   13 +
 .../blur/thrift/BlurControllerServer.java       |    8 +
 .../org/apache/blur/thrift/BlurShardServer.java |    7 +
 .../java/org/apache/blur/utils/BlurUtil.java    |    2 +-
 .../java/org/apache/blur/thrift/BlurClient.java |   74 +-
 .../org/apache/blur/thrift/generated/Blur.java  | 1868 +++++++++++++-----
 .../org/apache/blur/thrift/generated/User.java  |  596 ++++++
 .../src/main/scripts/interface/Blur.thrift      |   19 +
 .../main/scripts/interface/gen-html/Blur.html   |   19 +-
 .../main/scripts/interface/gen-html/index.html  |    2 +
 .../org/apache/blur/thrift/generated/Blur.java  | 1868 +++++++++++++-----
 .../org/apache/blur/thrift/generated/User.java  |  596 ++++++
 .../src/main/scripts/interface/gen-js/Blur.js   |  730 ++++---
 .../main/scripts/interface/gen-js/Blur_types.js |   98 +
 .../scripts/interface/gen-perl/Blur/Blur.pm     |  584 ++++--
 .../scripts/interface/gen-perl/Blur/Types.pm    |  104 +
 .../src/main/scripts/interface/gen-rb/blur.rb   |   59 +
 .../main/scripts/interface/gen-rb/blur_types.rb |   22 +
 docs/Blur.html                                  |   19 +-
 20 files changed, 5159 insertions(+), 1548 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6e272a76/blur-core/src/main/java/org/apache/blur/server/ControllerServerContext.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/server/ControllerServerContext.java b/blur-core/src/main/java/org/apache/blur/server/ControllerServerContext.java
index 9fc3bcd..73c18bc 100644
--- a/blur-core/src/main/java/org/apache/blur/server/ControllerServerContext.java
+++ b/blur-core/src/main/java/org/apache/blur/server/ControllerServerContext.java
@@ -20,17 +20,23 @@ import java.net.SocketAddress;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import org.apache.blur.log.Log;
+import org.apache.blur.log.LogFactory;
 import org.apache.blur.thirdparty.thrift_0_9_0.server.ServerContext;
+import org.apache.blur.thrift.generated.User;
 
 /**
  * The thrift session that holds the connection string of the client.
  */
 public class ControllerServerContext implements ServerContext {
+  
+  private static final Log LOG = LogFactory.getLog(ControllerServerContext.class);
 
   private final static Map<Thread, ControllerServerContext> _threadsToContext = new
ConcurrentHashMap<Thread, ControllerServerContext>();
   private final SocketAddress _localSocketAddress;
   private final SocketAddress _remoteSocketAddress;
   private final String _connectionString;
+  private User _user;
 
   public ControllerServerContext(SocketAddress localSocketAddress, SocketAddress remoteSocketAddress)
{
     _localSocketAddress = localSocketAddress;
@@ -53,7 +59,7 @@ public class ControllerServerContext implements ServerContext {
    * 
    * @return the {@link ControllerServerContext}.
    */
-  public static ControllerServerContext getShardServerContext() {
+  public static ControllerServerContext getControllerServerContext() {
     return _threadsToContext.get(Thread.currentThread());
   }
 
@@ -68,4 +74,15 @@ public class ControllerServerContext implements ServerContext {
   public String getConnectionString() {
     return _connectionString;
   }
+
+  public void setUser(User user) {
+    LOG.info("User [{0}] for context [{1}]", user, this);
+    _user = user;
+  }
+
+  public User getUser() {
+    return _user;
+  }
+  
+  
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6e272a76/blur-core/src/main/java/org/apache/blur/server/ShardServerContext.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/server/ShardServerContext.java b/blur-core/src/main/java/org/apache/blur/server/ShardServerContext.java
index 2b80339..ee906e0 100644
--- a/blur-core/src/main/java/org/apache/blur/server/ShardServerContext.java
+++ b/blur-core/src/main/java/org/apache/blur/server/ShardServerContext.java
@@ -26,6 +26,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import org.apache.blur.log.Log;
 import org.apache.blur.log.LogFactory;
 import org.apache.blur.thirdparty.thrift_0_9_0.server.ServerContext;
+import org.apache.blur.thrift.generated.User;
 import org.apache.hadoop.io.IOUtils;
 
 /**
@@ -44,6 +45,8 @@ public class ShardServerContext implements ServerContext {
   private final SocketAddress _remoteSocketAddress;
   private final String _connectionString;
 
+  private User _user;
+
   public ShardServerContext(SocketAddress localSocketAddress, SocketAddress remoteSocketAddress)
{
     _localSocketAddress = localSocketAddress;
     _remoteSocketAddress = remoteSocketAddress;
@@ -151,4 +154,14 @@ public class ShardServerContext implements ServerContext {
   public String getConnectionString() {
     return _connectionString;
   }
+
+  public void setUser(User user) {
+    LOG.info("User [{0}] for context [{1}]", user, this);
+    _user = user;
+  }
+
+  public User getUser() {
+    return _user;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6e272a76/blur-core/src/main/java/org/apache/blur/thrift/BlurControllerServer.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/thrift/BlurControllerServer.java b/blur-core/src/main/java/org/apache/blur/thrift/BlurControllerServer.java
index 55da371..660b6d0 100644
--- a/blur-core/src/main/java/org/apache/blur/thrift/BlurControllerServer.java
+++ b/blur-core/src/main/java/org/apache/blur/thrift/BlurControllerServer.java
@@ -57,6 +57,7 @@ import org.apache.blur.manager.results.LazyBlurResult;
 import org.apache.blur.manager.results.MergerBlurResultIterable;
 import org.apache.blur.manager.stats.MergerTableStats;
 import org.apache.blur.manager.status.MergerQueryStatusSingle;
+import org.apache.blur.server.ControllerServerContext;
 import org.apache.blur.thirdparty.thrift_0_9_0.TException;
 import org.apache.blur.thrift.commands.BlurCommand;
 import org.apache.blur.thrift.generated.Blur.Client;
@@ -77,6 +78,7 @@ import org.apache.blur.thrift.generated.Selector;
 import org.apache.blur.thrift.generated.ShardState;
 import org.apache.blur.thrift.generated.TableDescriptor;
 import org.apache.blur.thrift.generated.TableStats;
+import org.apache.blur.thrift.generated.User;
 import org.apache.blur.utils.BlurConstants;
 import org.apache.blur.utils.BlurExecutorCompletionService;
 import org.apache.blur.utils.BlurIterator;
@@ -1171,4 +1173,10 @@ public class BlurControllerServer extends TableAdmin implements Iface
{
     return connections;
   }
 
+  @Override
+  public void setUser(User user) throws BlurException, TException {
+    ControllerServerContext context = ControllerServerContext.getControllerServerContext();
+    context.setUser(user);
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6e272a76/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java b/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
index 3189ec4..bda2482 100644
--- a/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
+++ b/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
@@ -56,6 +56,7 @@ import org.apache.blur.thrift.generated.Selector;
 import org.apache.blur.thrift.generated.ShardState;
 import org.apache.blur.thrift.generated.Status;
 import org.apache.blur.thrift.generated.TableStats;
+import org.apache.blur.thrift.generated.User;
 import org.apache.blur.utils.BlurConstants;
 import org.apache.blur.utils.BlurUtil;
 import org.apache.blur.utils.QueryCache;
@@ -481,5 +482,11 @@ public class BlurShardServer extends TableAdmin implements Iface {
   public void setConfiguration(BlurConfiguration conf) {
     _configuration = conf;
   }
+  
+  @Override
+  public void setUser(User user) throws BlurException, TException {
+    ShardServerContext context = ShardServerContext.getShardServerContext();
+    context.setUser(user);
+  }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6e272a76/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java b/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
index 0e440e0..631257b 100644
--- a/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
+++ b/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
@@ -161,7 +161,7 @@ public class BlurUtil {
         String requestId = prefix + "-" + requestNumber;
         String connectionString;
         if (controller) {
-          ControllerServerContext controllerServerContext = ControllerServerContext.getShardServerContext();
+          ControllerServerContext controllerServerContext = ControllerServerContext.getControllerServerContext();
           if (controllerServerContext == null) {
             connectionString = "unknown";
           } else {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/6e272a76/blur-thrift/src/main/java/org/apache/blur/thrift/BlurClient.java
----------------------------------------------------------------------
diff --git a/blur-thrift/src/main/java/org/apache/blur/thrift/BlurClient.java b/blur-thrift/src/main/java/org/apache/blur/thrift/BlurClient.java
index b294b89..0af883e 100644
--- a/blur-thrift/src/main/java/org/apache/blur/thrift/BlurClient.java
+++ b/blur-thrift/src/main/java/org/apache/blur/thrift/BlurClient.java
@@ -23,40 +23,63 @@ import java.lang.reflect.Proxy;
 import java.util.Arrays;
 import java.util.List;
 
+import org.apache.blur.log.Log;
+import org.apache.blur.log.LogFactory;
 import org.apache.blur.thirdparty.thrift_0_9_0.TException;
 import org.apache.blur.thrift.commands.BlurCommand;
 import org.apache.blur.thrift.generated.Blur.Client;
 import org.apache.blur.thrift.generated.Blur.Iface;
 import org.apache.blur.thrift.generated.BlurException;
+import org.apache.blur.thrift.generated.User;
 
 public class BlurClient {
 
+  private static final Log LOG = LogFactory.getLog(BlurClient.class);
+
   static class BlurClientInvocationHandler implements InvocationHandler {
 
-    private List<Connection> connections;
-    private int _maxRetries = BlurClientManager.MAX_RETRIES;
-    private long _backOffTime = BlurClientManager.BACK_OFF_TIME;
-    private long _maxBackOffTime = BlurClientManager.MAX_BACK_OFF_TIME;
+    private static final String SET_USER = "setUser";
+    private final List<Connection> _connections;
+    private final int _maxRetries;
+    private final long _backOffTime;
+    private final long _maxBackOffTime;
+    private final boolean _setUser;
+    private User user;
 
     public BlurClientInvocationHandler(List<Connection> connections) {
-      this.connections = connections;
+      this(connections, true);
     }
 
     public BlurClientInvocationHandler(List<Connection> connections, int maxRetries,
long backOffTime,
-        long maxBackOffTime) {
-      this(connections);
+        long maxBackOffTime, boolean setUser) {
+      _connections = connections;
       _maxRetries = maxRetries;
       _backOffTime = backOffTime;
       _maxBackOffTime = maxBackOffTime;
+      _setUser = setUser;
+    }
+
+    public BlurClientInvocationHandler(List<Connection> connections, boolean setUser)
{
+      this(connections, BlurClientManager.MAX_RETRIES, BlurClientManager.BACK_OFF_TIME,
+          BlurClientManager.MAX_BACK_OFF_TIME, setUser);
     }
 
     @Override
     public Object invoke(Object proxy, final Method method, final Object[] args) throws Throwable
{
-      return BlurClientManager.execute(connections, new BlurCommand<Object>() {
+      return BlurClientManager.execute(_connections, new BlurCommand<Object>() {
         @Override
         public Object call(Client client) throws BlurException, TException {
           try {
-            return method.invoke(client, args);
+            if (_setUser && method.getName().equals(SET_USER)) {
+              user = (User) args[0];
+              LOG.info("Setting the user [{0}] for this client.", user);
+              return null;
+            } else {
+              if (_setUser) {
+                client.setUser(user);
+              }
+              return method.invoke(client, args);
+            }
           } catch (IllegalArgumentException e) {
             throw new RuntimeException(e);
           } catch (IllegalAccessException e) {
@@ -105,6 +128,17 @@ public class BlurClient {
     return getClient(connections, maxRetries, backOffTime, maxBackOffTime);
   }
 
+  public static Iface getClient(String connectionStr, boolean setUser) {
+    List<Connection> connections = BlurClientManager.getConnections(connectionStr);
+    return getClient(connections, setUser);
+  }
+
+  public static Iface getClient(String connectionStr, int maxRetries, long backOffTime, long
maxBackOffTime,
+      boolean setUser) {
+    List<Connection> connections = BlurClientManager.getConnections(connectionStr);
+    return getClient(connections, maxRetries, backOffTime, maxBackOffTime, setUser);
+  }
+
   public static Iface getClient(Connection connection) {
     return getClient(Arrays.asList(connection));
   }
@@ -114,13 +148,33 @@ public class BlurClient {
         new BlurClientInvocationHandler(connections));
   }
 
+  public static Iface getClient(Connection connection, boolean setUser) {
+    return getClient(Arrays.asList(connection), setUser);
+  }
+
+  public static Iface getClient(List<Connection> connections, boolean setUser) {
+    return (Iface) Proxy.newProxyInstance(Iface.class.getClassLoader(), new Class[] { Iface.class
},
+        new BlurClientInvocationHandler(connections, setUser));
+  }
+
   public static Iface getClient(Connection connection, int maxRetries, long backOffTime,
long maxBackOffTime) {
     return getClient(Arrays.asList(connection), maxRetries, backOffTime, maxBackOffTime);
   }
 
   public static Iface getClient(List<Connection> connections, int maxRetries, long
backOffTime, long maxBackOffTime) {
     return (Iface) Proxy.newProxyInstance(Iface.class.getClassLoader(), new Class[] { Iface.class
},
-        new BlurClientInvocationHandler(connections, maxRetries, backOffTime, maxBackOffTime));
+        new BlurClientInvocationHandler(connections, maxRetries, backOffTime, maxBackOffTime,
true));
+  }
+
+  public static Iface getClient(Connection connection, int maxRetries, long backOffTime,
long maxBackOffTime,
+      boolean setUser) {
+    return getClient(Arrays.asList(connection), maxRetries, backOffTime, maxBackOffTime,
setUser);
+  }
+
+  public static Iface getClient(List<Connection> connections, int maxRetries, long
backOffTime, long maxBackOffTime,
+      boolean setUser) {
+    return (Iface) Proxy.newProxyInstance(Iface.class.getClassLoader(), new Class[] { Iface.class
},
+        new BlurClientInvocationHandler(connections, maxRetries, backOffTime, maxBackOffTime,
setUser));
   }
 
 }


Mime
View raw message