@Override public SentryPolicyServiceClient create() throws Exception { LOGGER.debug("Creating Sentry Service Client..."); boolean haEnabled = conf.getBoolean(ClientConfig.SERVER_HA_ENABLED, false); if (haEnabled) { return (SentryPolicyServiceClient) Proxy .newProxyInstance(SentryPolicyServiceClientDefaultImpl.class.getClassLoader(), SentryPolicyServiceClientDefaultImpl.class.getInterfaces(), new HAClientInvocationHandler(conf)); } else { return new SentryPolicyServiceClientDefaultImpl(conf); } }
public static SentryPolicyServiceClient create(Configuration conf) throws Exception { boolean haEnabled = conf.getBoolean(ClientConfig.SERVER_HA_ENABLED, false); boolean pooled = conf.getBoolean(ClientConfig.SENTRY_POOL_ENABLED, false); if (pooled) { return (SentryPolicyServiceClient) Proxy .newProxyInstance(SentryPolicyServiceClientDefaultImpl.class.getClassLoader(), SentryPolicyServiceClientDefaultImpl.class.getInterfaces(), new PoolClientInvocationHandler(conf)); } else if (haEnabled) { return (SentryPolicyServiceClient) Proxy .newProxyInstance(SentryPolicyServiceClientDefaultImpl.class.getClassLoader(), SentryPolicyServiceClientDefaultImpl.class.getInterfaces(), new HAClientInvocationHandler(conf)); } else { return new SentryPolicyServiceClientDefaultImpl(conf); } }
private void renewSentryClient() throws IOException { try { manager = new ServiceManager(HAContext.getHAContext(conf)); } catch (Exception e1) { throw new IOException("Failed to extract Sentry node info from zookeeper", e1); } try { while (true) { currentServiceInstance = manager.getServiceInstance(); if (currentServiceInstance == null) { throw new IOException(SENTRY_HA_ERROR_MESSAGE); } InetSocketAddress serverAddress = ServiceManager.convertServiceInstance(currentServiceInstance); conf.set(ServiceConstants.ClientConfig.SERVER_RPC_ADDRESS, serverAddress.getHostName()); conf.setInt(ServiceConstants.ClientConfig.SERVER_RPC_PORT, serverAddress.getPort()); try { client = new SentryPolicyServiceClientDefaultImpl(conf); LOGGER.info("Sentry Client using server " + serverAddress.getHostName() + ":" + serverAddress.getPort()); break; } catch (IOException e) { manager.reportError(currentServiceInstance); LOGGER.info("Transport exception while opening transport:", e, e.getMessage()); } } } finally { manager.close(); } }