private long renewToken(Token token, String metaStoreURI, String hiveMetaStorePrincipal) { HCatClient hcatClient = null; if (UserGroupInformation.isSecurityEnabled()) { try { String tokenStr = token.encodeToUrlString(); HiveConf hcatConf = createHiveConf(metaStoreURI, hiveMetaStorePrincipal); LOG.debug("renewing delegation tokens for principal={}", hiveMetaStorePrincipal); hcatClient = HCatClient.create(hcatConf); Long expiryTime = hcatClient.renewDelegationToken(tokenStr); LOG.info("Renewed delegation token. new expiryTime={}", expiryTime); return expiryTime; } catch (Exception ex) { throw new RuntimeException("Failed to renew delegation tokens.", ex); } finally { if (hcatClient != null) try { hcatClient.close(); } catch (HCatException e) { LOG.error(" Exception", e); } } } else { throw new RuntimeException("Security is not enabled for Hadoop"); } }
private Token<DelegationTokenIdentifier> getDelegationToken(HiveConf hcatConf, String metaStoreServicePrincipal, String topologySubmitterUser) throws IOException { LOG.info("Creating delegation tokens for principal={}", metaStoreServicePrincipal); HCatClient hcatClient = null; try { hcatClient = HCatClient.create(hcatConf); String delegationToken = hcatClient.getDelegationToken(topologySubmitterUser, metaStoreServicePrincipal); Token<DelegationTokenIdentifier> delegationTokenId = new Token<DelegationTokenIdentifier>(); delegationTokenId.decodeFromUrlString(delegationToken); DelegationTokenIdentifier d = new DelegationTokenIdentifier(); d.readFields(new DataInputStream(new ByteArrayInputStream( delegationTokenId.getIdentifier()))); LOG.info("Created Delegation Token for : " + d.getUser()); return delegationTokenId; } finally { if (hcatClient != null) hcatClient.close(); } }
@Test public void testDropTableException() throws Exception { HCatClient client = HCatClient.create(new Configuration(hcatConf)); String tableName = "tableToBeDropped"; boolean isExceptionCaught = false; client.dropTable(null, tableName, true); try { client.dropTable(null, tableName, false); } catch (Exception exp) { isExceptionCaught = true; assertTrue(exp instanceof HCatException); LOG.info("Drop Table Exception: " + exp.getCause()); } finally { client.close(); assertTrue("The expected exception was never thrown.", isExceptionCaught); } }
@Test public void testCreateTableLike() throws Exception { HCatClient client = HCatClient.create(new Configuration(hcatConf)); String tableName = "tableone"; String cloneTable = "tabletwo"; client.dropTable(null, tableName, true); client.dropTable(null, cloneTable, true); ArrayList<HCatFieldSchema> cols = new ArrayList<HCatFieldSchema>(); cols.add(new HCatFieldSchema("id", Type.INT, "id columns")); cols.add(new HCatFieldSchema("value", Type.STRING, "id columns")); HCatCreateTableDesc tableDesc = HCatCreateTableDesc .create(null, tableName, cols).fileFormat("rcfile").build(); client.createTable(tableDesc); // create a new table similar to previous one. client.createTableLike(null, tableName, cloneTable, true, false, null); List<String> tables = client.listTableNamesByPattern(null, "table*"); assertTrue(tables.size() == 2); client.close(); }
@Test public void testDatabaseLocation() throws Exception { HCatClient client = HCatClient.create(new Configuration(hcatConf)); String dbName = "locationDB"; client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE); HCatCreateDBDesc dbDesc = HCatCreateDBDesc.create(dbName) .ifNotExists(true).location("/tmp/" + dbName).build(); client.createDatabase(dbDesc); HCatDatabase newDB = client.getDatabase(dbName); assertTrue(newDB.getLocation().matches(".*/tmp/" + dbName)); client.close(); }
@Test public void testGetMessageBusTopicName() throws Exception { try { HCatClient client = HCatClient.create(new Configuration(hcatConf)); String dbName = "testGetMessageBusTopicName_DBName"; String tableName = "testGetMessageBusTopicName_TableName"; client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE); client.createDatabase(HCatCreateDBDesc.create(dbName).build()); String messageBusTopicName = "MY.topic.name"; Map<String, String> tableProperties = new HashMap<String, String>(1); tableProperties.put(HCatConstants.HCAT_MSGBUS_TOPIC_NAME, messageBusTopicName); client.createTable(HCatCreateTableDesc.create(dbName, tableName, Arrays.asList(new HCatFieldSchema("foo", Type.STRING, ""))).tblProps(tableProperties).build()); assertEquals("MessageBus topic-name doesn't match!", messageBusTopicName, client.getMessageBusTopicName(dbName, tableName)); client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE); client.close(); } catch (Exception exception) { LOG.error("Unexpected exception.", exception); assertTrue("Unexpected exception:" + exception.getMessage(), false); } }
client.close(); assertTrue("The expected exception was never thrown.", isExceptionCaught);
@Test public void testRenameTable() throws Exception { HCatClient client = HCatClient.create(new Configuration(hcatConf)); String tableName = "temptable"; String newName = "mytable"; client.dropTable(null, tableName, true); client.dropTable(null, newName, true); ArrayList<HCatFieldSchema> cols = new ArrayList<HCatFieldSchema>(); cols.add(new HCatFieldSchema("id", Type.INT, "id columns")); cols.add(new HCatFieldSchema("value", Type.STRING, "id columns")); HCatCreateTableDesc tableDesc = HCatCreateTableDesc .create(null, tableName, cols).fileFormat("rcfile").build(); client.createTable(tableDesc); client.renameTable(null, tableName, newName); try { client.getTable(null, tableName); } catch (HCatException exp) { assertTrue("Unexpected exception message: " + exp.getMessage(), exp.getMessage().contains("NoSuchObjectException while fetching table")); } HCatTable newTable = client.getTable(null, newName); assertTrue(newTable != null); assertTrue(newTable.getTableName().equals(newName)); client.close(); }
assertTrue(table1.getCols().equals(cols)); client.close();
thirdPtn, PartitionEventType.LOAD_DONE); assertTrue(isMarked); client.close();
assertTrue(newTable.getTableName().equalsIgnoreCase(newName)); } finally { client.close(); assertTrue("The expected exception was never thrown.", isExceptionCaught);
private void closeQuietly(HCatClient client) { if (client != null) { try { client.close(); } catch (Exception ignore) { System.err.println("Error closing hcat client"); ignore.printStackTrace(System.err); } } }
private void closeQuietly(HCatClient client) { if (client != null) { try { client.close(); } catch (Exception ignore) { System.err.println("Error closing hcat client"); ignore.printStackTrace(System.err); } } }
private static HCatTable getHCatTable(String databaseName, String tableName, HiveConf conf) { HCatClient client = null; try { client = HCatClient.create(conf); return client.getTable(databaseName, tableName); } catch (HCatException e) { throw new RuntimeException("Unable to get table from the metastore.", e); } finally { if (client != null) { try { client.close(); } catch (HCatException e) { throw new RuntimeException("Unable close client.", e); } } } }
private static HCatTable getHCatTable(String databaseName, String tableName, HiveConf conf) { HCatClient client = null; try { client = HCatClient.create(conf); return client.getTable(databaseName, tableName); } catch (HCatException e) { throw new RuntimeException("Unable to get table from the metastore.", e); } finally { if (client != null) { try { client.close(); } catch (HCatException e) { throw new RuntimeException("Unable close client.", e); } } } }
private void closeQuietly(HCatClient client, String delegationToken, boolean close) { if (close && client != null) { try { if(delegationToken != null && !delegationToken.isEmpty()) { client.cancelDelegationToken(delegationToken); } client.close(); } catch (Exception ignore) { XLog.getLog(HCatURIHandler.class).warn("Error closing hcat client", ignore); } } }
private void closeQuietly(HCatClient client, String delegationToken, boolean close) { if (close && client != null) { try { if(delegationToken != null && !delegationToken.isEmpty()) { client.cancelDelegationToken(delegationToken); } client.close(); } catch (Exception ignore) { XLog.getLog(HCatURIHandler.class).warn("Error closing hcat client", ignore); } } }
public void shutdown() throws Exception { resetSystemProperties(); hcatClient.close(); if (mode.equals(RUNMODE.SERVER)) { // No clean way to stop hive metastore server. serverThread.stop(); } }
@Override public void destroy() { try { if (delegationToken != null && !delegationToken.isEmpty()) { hcatClient.cancelDelegationToken(delegationToken); } delegationToken = null; } catch (Exception ignore) { XLog.getLog(HCatContext.class).warn("Error cancelling delegation token", ignore); } try { hcatClient.close(); } catch (Exception ignore) { XLog.getLog(HCatContext.class).warn("Error closing hcat client", ignore); } }
@Override public void destroy() { try { if (delegationToken != null && !delegationToken.isEmpty()) { hcatClient.cancelDelegationToken(delegationToken); } delegationToken = null; } catch (Exception ignore) { XLog.getLog(HCatContext.class).warn("Error cancelling delegation token", ignore); } try { hcatClient.close(); } catch (Exception ignore) { XLog.getLog(HCatContext.class).warn("Error closing hcat client", ignore); } }