/** * Connect to HMS in unsecure mode or in Kerberos mode according to config. * * @return HMS connection * @throws IOException if could not establish connection * @throws InterruptedException if connection was interrupted * @throws MetaException if other errors happened */ public HMSClient connect() throws IOException, InterruptedException, MetaException { UserGroupInformation clientUGI; if (insecure) { clientUGI = UserGroupInformation.getCurrentUser(); } else { clientUGI = UserGroupInformation.getUGIFromSubject(kerberosContext.getSubject()); } return new HMSClient(clientUGI.doAs(new PrivilegedExceptionAction<HiveMetaStoreClient>() { @Override public HiveMetaStoreClient run() throws MetaException { return new HiveMetaStoreClient(hiveConf); } })); }
@Override public String call() throws Exception { SentryKerberosContext kerberosContext = null; try { status = Status.STARTED; if (kerberos) { kerberosContext = new SentryKerberosContext(principal, keytab, true); Subject.doAs(kerberosContext.getSubject(), new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { runServer(); return null; } }); } else { runServer(); } } catch (Exception t) { LOGGER.error("Error starting server", t); throw new Exception("Error starting server", t); } finally { if (kerberosContext != null) { kerberosContext.shutDown(); } status = Status.NOT_STARTED; } return null; }
@Override public String call() throws Exception { SentryKerberosContext kerberosContext = null; try { status = Status.STARTED; if (kerberos) { kerberosContext = new SentryKerberosContext(principal, keytab, true); Subject.doAs(kerberosContext.getSubject(), new PrivilegedExceptionAction<Void>() { @Override public Void run() throws Exception { runServer(); return null; } }); } else { runServer(); } } catch (Exception t) { LOGGER.error("Error starting server", t); throw new Exception("Error starting server", t); } finally { if (kerberosContext != null) { kerberosContext.shutDown(); } status = Status.NOT_STARTED; } return null; }