use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project metacat by Netflix.
the class HiveConnectorPartitionService method getPartitions.
/**
* {@inheritDoc}.
*/
@Override
public List<PartitionInfo> getPartitions(final ConnectorRequestContext requestContext, final QualifiedName tableName, final PartitionListRequest partitionsRequest) {
try {
final List<Partition> partitions = getPartitions(tableName, partitionsRequest.getFilter(), partitionsRequest.getPartitionNames(), partitionsRequest.getSort(), partitionsRequest.getPageable());
final Table table = metacatHiveClient.getTableByName(tableName.getDatabaseName(), tableName.getTableName());
final TableInfo tableInfo = hiveMetacatConverters.toTableInfo(tableName, table);
final List<PartitionInfo> partitionInfos = new ArrayList<>();
for (Partition partition : partitions) {
partitionInfos.add(hiveMetacatConverters.toPartitionInfo(tableInfo, partition));
}
return partitionInfos;
} catch (NoSuchObjectException exception) {
throw new TableNotFoundException(tableName, exception);
} catch (MetaException | InvalidObjectException e) {
throw new InvalidMetaException("Invalid metadata for " + tableName, e);
} catch (TException e) {
throw new ConnectorException(String.format("Failed get partitions for hive table %s", tableName), e);
}
}
use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project metacat by Netflix.
the class MetacatHMSHandler method add_drop_partitions.
/**
* Adds and drops partitions in one transaction.
*
* @param databaseName database name
* @param tableName table name
* @param addParts list of partitions
* @param dropParts list of partition values
* @param deleteData if true, deletes the data
* @return true if successful
* @throws NoSuchObjectException Exception if table does not exists
* @throws MetaException Exception if
* @throws TException any internal exception
*/
@SuppressWarnings({ "checkstyle:methodname" })
public boolean add_drop_partitions(final String databaseName, final String tableName, final List<Partition> addParts, final List<List<String>> dropParts, final boolean deleteData) throws NoSuchObjectException, MetaException, TException {
startFunction("add_drop_partitions : db=" + databaseName + " tbl=" + tableName);
if (addParts.size() == 0 && dropParts.size() == 0) {
return true;
}
for (List<String> partVals : dropParts) {
LOG.info("Drop Partition values:" + partVals);
}
for (Partition part : addParts) {
LOG.info("Add Partition values:" + part);
}
boolean ret = false;
Exception ex = null;
try {
ret = addDropPartitionsCore(getMS(), databaseName, tableName, addParts, dropParts, false, null);
} catch (Exception e) {
ex = e;
if (e instanceof MetaException) {
throw (MetaException) e;
} else if (e instanceof InvalidObjectException) {
throw (InvalidObjectException) e;
} else if (e instanceof AlreadyExistsException) {
throw (AlreadyExistsException) e;
} else if (e instanceof NoSuchObjectException) {
throw (NoSuchObjectException) e;
} else {
throw newMetaException(e);
}
} finally {
endFunction("drop_partitions", ret, ex, tableName);
}
return ret;
}
use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project hive by apache.
the class TestMetaStoreAuthorization method testMetaStoreAuthorization.
public void testMetaStoreAuthorization() throws Exception {
setup();
MetaStoreTestUtils.startMetaStoreWithRetry(conf);
HiveMetaStoreClient client = new HiveMetaStoreClient(conf);
FileSystem fs = null;
String dbName = "simpdb";
Database db1 = null;
Path p = null;
try {
try {
db1 = client.getDatabase(dbName);
client.dropDatabase(dbName);
} catch (NoSuchObjectException noe) {
}
if (db1 != null) {
p = new Path(db1.getLocationUri());
fs = p.getFileSystem(conf);
fs.delete(p, true);
}
db1 = new Database();
db1.setName(dbName);
client.createDatabase(db1);
Database db = client.getDatabase(dbName);
assertTrue("Databases do not match", db1.getName().equals(db.getName()));
p = new Path(db.getLocationUri());
if (fs == null) {
fs = p.getFileSystem(conf);
}
fs.setPermission(p.getParent(), FsPermission.createImmutable((short) 0555));
try {
client.dropDatabase(dbName);
throw new Exception("Expected dropDatabase call to fail");
} catch (MetaException me) {
}
fs.setPermission(p.getParent(), FsPermission.createImmutable((short) 0755));
client.dropDatabase(dbName);
} finally {
if (p != null) {
fs.delete(p, true);
}
}
}
use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project hive by apache.
the class TestDBTokenStore method testDBTokenStore.
public void testDBTokenStore() throws TokenStoreException, MetaException, IOException {
DelegationTokenStore ts = new DBTokenStore();
ts.init(new HMSHandler("Test handler"), HadoopThriftAuthBridge.Server.ServerMode.METASTORE);
assertEquals(0, ts.getMasterKeys().length);
assertEquals(false, ts.removeMasterKey(-1));
try {
ts.updateMasterKey(-1, "non-existent-key");
fail("Updated non-existent key.");
} catch (TokenStoreException e) {
assertTrue(e.getCause() instanceof NoSuchObjectException);
}
int keySeq = ts.addMasterKey("key1Data");
int keySeq2 = ts.addMasterKey("key2Data");
int keySeq2same = ts.addMasterKey("key2Data");
assertEquals("keys sequential", keySeq + 1, keySeq2);
assertEquals("keys sequential", keySeq + 2, keySeq2same);
assertEquals("expected number of keys", 3, ts.getMasterKeys().length);
assertTrue(ts.removeMasterKey(keySeq));
assertTrue(ts.removeMasterKey(keySeq2same));
assertEquals("expected number of keys", 1, ts.getMasterKeys().length);
assertEquals("key2Data", ts.getMasterKeys()[0]);
ts.updateMasterKey(keySeq2, "updatedData");
assertEquals("updatedData", ts.getMasterKeys()[0]);
assertTrue(ts.removeMasterKey(keySeq2));
// tokens
assertEquals(0, ts.getAllDelegationTokenIdentifiers().size());
DelegationTokenIdentifier tokenId = new DelegationTokenIdentifier(new Text("owner"), new Text("renewer"), new Text("realUser"));
assertNull(ts.getToken(tokenId));
assertFalse(ts.removeToken(tokenId));
DelegationTokenInformation tokenInfo = new DelegationTokenInformation(99, "password".getBytes());
assertTrue(ts.addToken(tokenId, tokenInfo));
assertFalse(ts.addToken(tokenId, tokenInfo));
DelegationTokenInformation tokenInfoRead = ts.getToken(tokenId);
assertEquals(tokenInfo.getRenewDate(), tokenInfoRead.getRenewDate());
assertNotSame(tokenInfo, tokenInfoRead);
Assert.assertArrayEquals(HiveDelegationTokenSupport.encodeDelegationTokenInformation(tokenInfo), HiveDelegationTokenSupport.encodeDelegationTokenInformation(tokenInfoRead));
List<DelegationTokenIdentifier> allIds = ts.getAllDelegationTokenIdentifiers();
assertEquals(1, allIds.size());
Assert.assertEquals(TokenStoreDelegationTokenSecretManager.encodeWritable(tokenId), TokenStoreDelegationTokenSecretManager.encodeWritable(allIds.get(0)));
assertTrue(ts.removeToken(tokenId));
assertEquals(0, ts.getAllDelegationTokenIdentifiers().size());
assertNull(ts.getToken(tokenId));
ts.close();
}
use of org.apache.hadoop.hive.metastore.api.NoSuchObjectException in project hive by apache.
the class TestObjectStore method testDirectSqlErrorMetrics.
@Test
public void testDirectSqlErrorMetrics() throws Exception {
Configuration conf = MetastoreConf.newMetastoreConf();
MetastoreConf.setBoolVar(conf, MetastoreConf.ConfVars.METRICS_ENABLED, true);
Metrics.initialize(conf);
MetastoreConf.setVar(conf, MetastoreConf.ConfVars.HIVE_CODAHALE_METRICS_REPORTER_CLASSES, "org.apache.hadoop.hive.common.metrics.metrics2.JsonFileMetricsReporter, " + "org.apache.hadoop.hive.common.metrics.metrics2.JmxMetricsReporter");
// recall setup so that we get an object store with the metrics initalized
setUp();
Counter directSqlErrors = Metrics.getRegistry().getCounters().get(MetricsConstants.DIRECTSQL_ERRORS);
objectStore.new GetDbHelper("foo", true, true) {
@Override
protected Database getSqlResult(ObjectStore.GetHelper<Database> ctx) throws MetaException {
return null;
}
@Override
protected Database getJdoResult(ObjectStore.GetHelper<Database> ctx) throws MetaException, NoSuchObjectException {
return null;
}
}.run(false);
Assert.assertEquals(0, directSqlErrors.getCount());
objectStore.new GetDbHelper("foo", true, true) {
@Override
protected Database getSqlResult(ObjectStore.GetHelper<Database> ctx) throws MetaException {
throw new RuntimeException();
}
@Override
protected Database getJdoResult(ObjectStore.GetHelper<Database> ctx) throws MetaException, NoSuchObjectException {
return null;
}
}.run(false);
Assert.assertEquals(1, directSqlErrors.getCount());
}
Aggregations