@Override public void close() { if (client != null) { client.close(); } } }
@Override public void destroyObject(PooledObject<SentryPolicyServiceClient> pooledObject) { SentryPolicyServiceClient client = pooledObject.getObject(); LOGGER.debug("Destroying Sentry Service Client: " + client); if (client != null) { // The close() of TSocket or TSaslClientTransport is called actually, and there has no // exception even there has some problems, eg, the client is closed already. // The close here is just try to close the socket and the client will be destroyed soon. client.close(); } } }
private void dropSentryPrivileges( List<? extends Authorizable> authorizableTable) throws SentryUserException, IOException, MetaException { String requestorUserName = UserGroupInformation.getCurrentUser() .getShortUserName(); SentryPolicyServiceClient sentryClient = getSentryServiceClient(); sentryClient.dropPrivileges(requestorUserName, authorizableTable); // Close the connection after dropping privileges is done. sentryClient.close(); }
policyServiceClient.close();
" service, will retry other service.", e); if (client != null) { client.close(); client = null;
sentryClient.close();
@Override public void runTestAsSubject() throws Exception { if (client != null) { Set<TSentryRole> tRoles = client.listRoles(ADMIN_USER); if (tRoles != null) { for (TSentryRole tRole : tRoles) { client.dropRole(ADMIN_USER, tRole.getRoleName()); } } client.close(); } } });
} finally { if (sentryClient != null) { sentryClient.close();
@Override public void runTestAsSubject() throws Exception { Configuration confWithSmallMaxMsgSize = new Configuration(conf); confWithSmallMaxMsgSize.setLong(ServiceConstants.ClientConfig.SENTRY_POLICY_CLIENT_THRIFT_MAX_MESSAGE_SIZE, 20); // create a client with a small thrift max message size SentryPolicyServiceClient clientWithSmallMaxMsgSize = SentryServiceClientFactory.create(confWithSmallMaxMsgSize); setLocalGroupMapping(ADMIN_USER, REQUESTER_USER_GROUP_NAMES); writePolicyFile(); boolean exceptionThrown = false; try { // client throws exception when message size is larger than the client's thrift max message size. clientWithSmallMaxMsgSize.listRoles(ADMIN_USER); } catch (SentryUserException e) { exceptionThrown = true; Assert.assertTrue(e.getMessage().contains("Thrift exception occurred")); Assert.assertTrue(e.getCause().getMessage().contains("Length exceeded max allowed")); } finally { Assert.assertEquals(true, exceptionThrown); clientWithSmallMaxMsgSize.close(); } // client can still talk with sentry server when message size is smaller. client.dropRoleIfExists(ADMIN_USER, ROLE_NAME); client.listRoles(ADMIN_USER); client.createRole(ADMIN_USER, ROLE_NAME); client.listRoles(ADMIN_USER); } });