Repository: sentry Updated Branches: refs/heads/sentry-ha-redesign e96151ad3 -> 049308d9e
SENTRY-1510: Add option to use non pool model for sentry client (Li Li, Reviewed by Hao Hao) Change-Id: I53fd629e402da4b4f4e3ef17a91fdcb14bc49394 Project: http://git-wip-us.apache.org/repos/asf/sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/049308d9 Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/049308d9 Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/049308d9 Branch: refs/heads/sentry-ha-redesign Commit: 049308d9ebef235e6a23e939969e7287a053ba5d Parents: e96151a Author: lili <[email protected]> Authored: Mon Oct 24 17:22:19 2016 -0700 Committer: lili <[email protected]> Committed: Wed Oct 26 10:31:42 2016 -0700 ---------------------------------------------------------------------- .../service/thrift/PoolClientInvocationHandler.java | 3 +++ .../service/thrift/SentryServiceClientFactory.java | 11 +++++++++-- .../db/service/thrift/TestSentryServiceFailureCase.java | 3 +-- .../sentry/tests/e2e/hive/TestPolicyImportExport.java | 4 +--- 4 files changed, 14 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/sentry/blob/049308d9/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/PoolClientInvocationHandler.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/PoolClientInvocationHandler.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/PoolClientInvocationHandler.java index 842d5ca..730bfec 100644 --- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/PoolClientInvocationHandler.java +++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/PoolClientInvocationHandler.java @@ -42,6 +42,9 @@ import org.slf4j.LoggerFactory; * get the instance and do the call again. For the thread safe, the commons-pool * will manage the connection pool, and every thread can get the connection by * borrowObject() and return the connection to the pool by returnObject(). + * + * TODO: Current pool model does not manage the opening connections very well, + * e.g. opening connections with failed servers should be closed promptly. */ public class PoolClientInvocationHandler extends SentryClientInvocationHandler { http://git-wip-us.apache.org/repos/asf/sentry/blob/049308d9/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryServiceClientFactory.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryServiceClientFactory.java b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryServiceClientFactory.java index 9e90af8..b7d2be1 100644 --- a/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryServiceClientFactory.java +++ b/sentry-provider/sentry-provider-db/src/main/java/org/apache/sentry/service/thrift/SentryServiceClientFactory.java @@ -24,6 +24,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.sentry.provider.db.service.thrift.SentryPolicyServiceClient; import org.apache.sentry.provider.db.service.thrift.SentryPolicyServiceClientDefaultImpl; +import org.apache.sentry.service.thrift.ServiceConstants.ClientConfig; public final class SentryServiceClientFactory { @@ -31,9 +32,15 @@ public final class SentryServiceClientFactory { } public static SentryPolicyServiceClient create(Configuration conf) throws Exception { + boolean pooled = conf.getBoolean( + ClientConfig.SENTRY_POOL_ENABLED, ClientConfig.SENTRY_POOL_ENABLED_DEFAULT); + if (pooled) { return (SentryPolicyServiceClient) Proxy .newProxyInstance(SentryPolicyServiceClientDefaultImpl.class.getClassLoader(), - SentryPolicyServiceClientDefaultImpl.class.getInterfaces(), - new PoolClientInvocationHandler(conf)); + SentryPolicyServiceClientDefaultImpl.class.getInterfaces(), + new PoolClientInvocationHandler(conf)); + } else { + return new SentryPolicyServiceClientDefaultImpl(conf); + } } } http://git-wip-us.apache.org/repos/asf/sentry/blob/049308d9/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceFailureCase.java ---------------------------------------------------------------------- diff --git a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceFailureCase.java b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceFailureCase.java index d1ac447..7c7ebab 100644 --- a/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceFailureCase.java +++ b/sentry-provider/sentry-provider-db/src/test/java/org/apache/sentry/provider/db/service/thrift/TestSentryServiceFailureCase.java @@ -63,8 +63,7 @@ public class TestSentryServiceFailureCase extends SentryServiceIntegrationBase { Assert.fail("Failed to receive Exception"); } catch(Exception e) { LOGGER.info("Excepted exception", e); - // peer callback exception is nested inside SentryUserException. - Throwable cause = e.getCause().getCause(); + Throwable cause = e.getCause(); if (cause == null) { throw e; } http://git-wip-us.apache.org/repos/asf/sentry/blob/049308d9/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPolicyImportExport.java ---------------------------------------------------------------------- diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPolicyImportExport.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPolicyImportExport.java index b45fc6d..3f57a00 100644 --- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPolicyImportExport.java +++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/hive/TestPolicyImportExport.java @@ -22,7 +22,6 @@ import static org.junit.Assert.fail; import java.io.File; import java.io.FileOutputStream; -import java.lang.reflect.UndeclaredThrowableException; import java.util.Map; import java.util.Set; @@ -173,8 +172,7 @@ public class TestPolicyImportExport extends AbstractTestWithStaticConfiguration try { configTool.importPolicy(); fail("IllegalArgumentException should be thrown for: Invalid key value: server [server]"); - } catch (UndeclaredThrowableException ex) { - assertTrue(ex.getUndeclaredThrowable().getCause() instanceof IllegalArgumentException); + } catch (IllegalArgumentException ex) { // ignore } }
