tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject tajo git commit: TAJO-1268: tajo-client module should not use UserGroupInformation.
Date Wed, 24 Dec 2014 08:59:52 GMT
Repository: tajo
Updated Branches:
  refs/heads/master 09cad22ee -> db5496550


TAJO-1268: tajo-client module should not use UserGroupInformation.

Closes #318


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

Branch: refs/heads/master
Commit: db549655034c1eb79d8f5785bc00aeecfc53a593
Parents: 09cad22
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Wed Dec 24 17:58:25 2014 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Wed Dec 24 17:58:25 2014 +0900

----------------------------------------------------------------------
 CHANGES                                         |  3 +
 .../org/apache/tajo/cli/tools/TajoDump.java     |  8 +-
 .../org/apache/tajo/client/QueryClient.java     |  4 +-
 .../org/apache/tajo/client/QueryClientImpl.java |  4 +-
 .../apache/tajo/client/SessionConnection.java   | 10 +--
 .../java/org/apache/tajo/auth/UserRoleInfo.java | 80 ++++++++++++++++++++
 .../java/org/apache/tajo/util/PlatformUtil.java | 65 ++++++++++++++++
 .../org/apache/tajo/cli/tools/TestTajoDump.java |  5 +-
 8 files changed, 163 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/db549655/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 23d34d4..2ee58a2 100644
--- a/CHANGES
+++ b/CHANGES
@@ -24,6 +24,9 @@ Release 0.9.1 - unreleased
 
   IMPROVEMENT
 
+    TAJO-1268: tajo-client module should not use UserGroupInformation. 
+    (hyunsik)
+
     TAJO-1259: Change tsql history behavior. (Jaewoong Jung via hyunsik)
 
     TAJO-1261: Separate query and ddl execution codes from GlobalEngine. 

http://git-wip-us.apache.org/repos/asf/tajo/blob/db549655/tajo-client/src/main/java/org/apache/tajo/cli/tools/TajoDump.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/tools/TajoDump.java b/tajo-client/src/main/java/org/apache/tajo/cli/tools/TajoDump.java
index d05564a..750ead0 100644
--- a/tajo-client/src/main/java/org/apache/tajo/cli/tools/TajoDump.java
+++ b/tajo-client/src/main/java/org/apache/tajo/cli/tools/TajoDump.java
@@ -20,7 +20,7 @@ package org.apache.tajo.cli.tools;
 
 import com.google.protobuf.ServiceException;
 import org.apache.commons.cli.*;
-import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.tajo.auth.UserRoleInfo;
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.DDLBuilder;
 import org.apache.tajo.catalog.TableDesc;
@@ -85,7 +85,7 @@ public class TajoDump {
     final Pair<String, Integer> hostAndPort = getConnectionAddr(conf, cmd);
     final String hostName = hostAndPort.getFirst();
     final Integer port = hostAndPort.getSecond();
-    final UserGroupInformation userInfo = UserGroupInformation.getCurrentUser();
+    final UserRoleInfo userInfo = UserRoleInfo.getCurrentUser();
 
     String baseDatabaseName = null;
     if (cmd.getArgList().size() > 0) {
@@ -117,7 +117,7 @@ public class TajoDump {
     System.exit(0);
   }
 
-  public static void dump(TajoClient client, UserGroupInformation userInfo, String baseDatabaseName,
+  public static void dump(TajoClient client, UserRoleInfo userInfo, String baseDatabaseName,
                    boolean isDumpingAllDatabases, boolean includeUserName, boolean includeDate,
PrintWriter out)
       throws SQLException, ServiceException {
     printHeader(out, userInfo, includeUserName, includeDate);
@@ -136,7 +136,7 @@ public class TajoDump {
     out.flush();
   }
 
-  private static void printHeader(PrintWriter writer, UserGroupInformation userInfo, boolean
includeUSerName,
+  private static void printHeader(PrintWriter writer, UserRoleInfo userInfo, boolean includeUSerName,
                                   boolean includeDate) {
     writer.write("--\n");
     writer.write("-- Tajo database dump\n");

http://git-wip-us.apache.org/repos/asf/tajo/blob/db549655/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java b/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java
index 73a4d35..7c7db33 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/QueryClient.java
@@ -19,8 +19,8 @@
 package org.apache.tajo.client;
 
 import com.google.protobuf.ServiceException;
-import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.tajo.QueryId;
+import org.apache.tajo.auth.UserRoleInfo;
 import org.apache.tajo.ipc.ClientProtos;
 import org.apache.tajo.ipc.ClientProtos.QueryHistoryProto;
 import org.apache.tajo.ipc.ClientProtos.QueryInfoProto;
@@ -49,7 +49,7 @@ public interface QueryClient extends Closeable {
   @Override
   public void close();
 
-  public UserGroupInformation getUserInfo();
+  public UserRoleInfo getUserInfo();
 
   /**
    * Call to QueryMaster closing query resources

http://git-wip-us.apache.org/repos/asf/tajo/blob/db549655/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java b/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
index dc35968..f923965 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/QueryClientImpl.java
@@ -21,11 +21,11 @@ package org.apache.tajo.client;
 import com.google.protobuf.ServiceException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.tajo.QueryId;
 import org.apache.tajo.QueryIdFactory;
 import org.apache.tajo.TajoIdProtos;
 import org.apache.tajo.TajoProtos;
+import org.apache.tajo.auth.UserRoleInfo;
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.Schema;
 import org.apache.tajo.catalog.TableDesc;
@@ -89,7 +89,7 @@ public class QueryClientImpl implements QueryClient {
   }
 
   @Override
-  public UserGroupInformation getUserInfo() {
+  public UserRoleInfo getUserInfo() {
     return connection.getUserInfo();
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/db549655/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java b/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java
index db2bd2a..c849f2d 100644
--- a/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java
+++ b/tajo-client/src/main/java/org/apache/tajo/client/SessionConnection.java
@@ -21,11 +21,12 @@ package org.apache.tajo.client;
 import com.google.protobuf.ServiceException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.tajo.QueryId;
 import org.apache.tajo.TajoIdProtos;
 import org.apache.tajo.annotation.Nullable;
+import org.apache.tajo.auth.UserRoleInfo;
 import org.apache.tajo.conf.TajoConf;
+import org.apache.tajo.ha.HAServiceUtil;
 import org.apache.tajo.ipc.ClientProtos;
 import org.apache.tajo.ipc.ClientProtos.ResultCode;
 import org.apache.tajo.ipc.ClientProtos.SessionUpdateResponse;
@@ -33,7 +34,6 @@ import org.apache.tajo.ipc.TajoMasterClientProtocol;
 import org.apache.tajo.rpc.NettyClientBase;
 import org.apache.tajo.rpc.RpcConnectionPool;
 import org.apache.tajo.rpc.ServerCallable;
-import org.apache.tajo.ha.HAServiceUtil;
 import org.apache.tajo.util.KeyValueSet;
 import org.apache.tajo.util.NetUtils;
 import org.apache.tajo.util.ProtoUtil;
@@ -67,7 +67,7 @@ public class SessionConnection implements Closeable {
 
   private final String baseDatabase;
 
-  private final UserGroupInformation userInfo;
+  private final UserRoleInfo userInfo;
 
   volatile TajoIdProtos.SessionIdProto sessionId;
 
@@ -109,7 +109,7 @@ public class SessionConnection implements Closeable {
     int workerNum = conf.getIntVar(TajoConf.ConfVars.RPC_CLIENT_WORKER_THREAD_NUM);
     // Don't share connection pool per client
     connPool = RpcConnectionPool.newPool(conf, getClass().getSimpleName(), workerNum);
-    userInfo = UserGroupInformation.getCurrentUser();
+    userInfo = UserRoleInfo.getCurrentUser();
     this.baseDatabase = baseDatabase != null ? baseDatabase : null;
   }
 
@@ -167,7 +167,7 @@ public class SessionConnection implements Closeable {
     return conf;
   }
 
-  public UserGroupInformation getUserInfo() {
+  public UserRoleInfo getUserInfo() {
     return userInfo;
   }
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/db549655/tajo-common/src/main/java/org/apache/tajo/auth/UserRoleInfo.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/auth/UserRoleInfo.java b/tajo-common/src/main/java/org/apache/tajo/auth/UserRoleInfo.java
new file mode 100644
index 0000000..54c438c
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/auth/UserRoleInfo.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.auth;
+
+import org.apache.tajo.util.PlatformUtil;
+
+import java.lang.reflect.Method;
+
+public class UserRoleInfo {
+  private final String username;
+
+  public UserRoleInfo(String username) {
+    this.username = username;
+  }
+
+  public String getUserName() {
+    return username;
+  }
+
+  @Override
+  public String toString() {
+    return "user=" + username;
+  }
+
+  public synchronized static UserRoleInfo getCurrentUser() {
+    Class<?> c;
+    Object   o = null;
+    Method method = null;
+    String userName;
+
+    PlatformUtil.OsType osType = PlatformUtil.getOsType();
+
+    try {
+      switch (osType) {
+      case WINDOWS:
+        c = Class.forName("com.sun.security.auth.module.NTSystem");
+        o = Class.forName("com.sun.security.auth.module.NTSystem").newInstance();
+        method = c.getDeclaredMethod("getName");
+        break;
+      case LINUX_OR_UNIX:
+      case MAC:
+        c = Class.forName("com.sun.security.auth.module.UnixSystem");
+        o = Class.forName("com.sun.security.auth.module.UnixSystem").newInstance();
+        method = c.getDeclaredMethod("getUsername");
+        break;
+      case SOLARIS:
+        c = Class.forName("com.sun.security.auth.module.SolarisSystem");
+        o = Class.forName("com.sun.security.auth.module.SolarisSystem").newInstance();
+        method = c.getDeclaredMethod("getUsername");
+        break;
+
+      default:
+        throw new IllegalStateException("Unknown Operating System: " + PlatformUtil.getOsName());
+      }
+
+      userName = (String) method.invoke(o);
+    } catch (Throwable t) {
+      throw new RuntimeException(t);
+    }
+
+    return new UserRoleInfo(userName);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/db549655/tajo-common/src/main/java/org/apache/tajo/util/PlatformUtil.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/util/PlatformUtil.java b/tajo-common/src/main/java/org/apache/tajo/util/PlatformUtil.java
new file mode 100644
index 0000000..dabcdba
--- /dev/null
+++ b/tajo-common/src/main/java/org/apache/tajo/util/PlatformUtil.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tajo.util;
+
+public class PlatformUtil {
+  public static enum OsType {
+    WINDOWS,
+    MAC,
+    LINUX_OR_UNIX,
+    SOLARIS,
+    UNKNOWN
+  }
+
+  public static String getOsName() {
+    return System.getProperty("os.name").toLowerCase();
+  }
+
+  public static OsType getOsType() {
+    String osName = System.getProperty("os.name").toLowerCase();
+
+    if (PlatformUtil.isWindows(osName)) {
+      return OsType.WINDOWS;
+    } else if (isMac(osName)) {
+      return OsType.MAC;
+    } else if (isUnix(osName)) {
+      return OsType.LINUX_OR_UNIX;
+    } else if (isSolaris(osName)) {
+      return OsType.SOLARIS;
+    } else {
+      throw new RuntimeException("Unknown OS Type: " + osName);
+    }
+  }
+
+  private static boolean isWindows(String osName) {
+    return (osName.indexOf("win") >= 0);
+  }
+
+  private static boolean isMac(String osName) {
+    return (osName.indexOf("mac") >= 0);
+  }
+
+  private static boolean isUnix(String osName) {
+    return (osName.indexOf("nix") >= 0 || osName.indexOf("nux") >= 0 || osName.indexOf("aix")
> 0 );
+  }
+
+  private static boolean isSolaris(String osName) {
+    return (osName.indexOf("sunos") >= 0) || (osName.indexOf("solaris") >= 0);
+  }
+}

http://git-wip-us.apache.org/repos/asf/tajo/blob/db549655/tajo-core/src/test/java/org/apache/tajo/cli/tools/TestTajoDump.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/cli/tools/TestTajoDump.java b/tajo-core/src/test/java/org/apache/tajo/cli/tools/TestTajoDump.java
index 29b7d3b..d6631f6 100644
--- a/tajo-core/src/test/java/org/apache/tajo/cli/tools/TestTajoDump.java
+++ b/tajo-core/src/test/java/org/apache/tajo/cli/tools/TestTajoDump.java
@@ -18,9 +18,8 @@
 
 package org.apache.tajo.cli.tools;
 
-import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.tajo.QueryTestCaseBase;
-import org.apache.tajo.cli.tools.TajoDump;
+import org.apache.tajo.auth.UserRoleInfo;
 import org.junit.Test;
 
 import java.io.ByteArrayOutputStream;
@@ -34,7 +33,7 @@ public class TestTajoDump extends QueryTestCaseBase {
       executeString("CREATE TABLE \"" + getCurrentDatabase() +
           "\".\"TableName1\" (\"Age\" int, \"FirstName\" TEXT, lastname TEXT)");
 
-      UserGroupInformation userInfo = UserGroupInformation.getCurrentUser();
+      UserRoleInfo userInfo = UserRoleInfo.getCurrentUser();
       ByteArrayOutputStream bos = new ByteArrayOutputStream();
       PrintWriter printWriter = new PrintWriter(bos);
       TajoDump.dump(client, userInfo, getCurrentDatabase(), false, false, false, printWriter);


Mime
View raw message