use of org.apache.hadoop.hive.metastore.api.PrincipalType in project hive by apache.
the class ObjectStore method convertGlobal.
private List<HiveObjectPrivilege> convertGlobal(List<MGlobalPrivilege> privs) {
List<HiveObjectPrivilege> result = new ArrayList<>();
for (MGlobalPrivilege priv : privs) {
String pname = priv.getPrincipalName();
String authorizer = priv.getAuthorizer();
PrincipalType ptype = PrincipalType.valueOf(priv.getPrincipalType());
HiveObjectRef objectRef = new HiveObjectRef(HiveObjectType.GLOBAL, null, null, null, null);
PrivilegeGrantInfo grantor = new PrivilegeGrantInfo(priv.getPrivilege(), priv.getCreateTime(), priv.getGrantor(), PrincipalType.valueOf(priv.getGrantorType()), priv.getGrantOption());
result.add(new HiveObjectPrivilege(objectRef, pname, ptype, grantor, authorizer));
}
return result;
}
use of org.apache.hadoop.hive.metastore.api.PrincipalType in project hive by apache.
the class ObjectStore method getJDODatabase.
public Database getJDODatabase(String catName, String name) throws NoSuchObjectException {
MDatabase mdb = null;
boolean commited = false;
try {
openTransaction();
mdb = getMDatabase(catName, name);
commited = commitTransaction();
} finally {
if (!commited) {
rollbackTransaction();
}
}
Database db = new Database();
db.setName(mdb.getName());
db.setDescription(mdb.getDescription());
db.setParameters(convertMap(mdb.getParameters()));
db.setOwnerName(mdb.getOwnerName());
String type = org.apache.commons.lang3.StringUtils.defaultIfBlank(mdb.getOwnerType(), null);
PrincipalType principalType = (type == null) ? null : PrincipalType.valueOf(type);
db.setOwnerType(principalType);
if (mdb.getType().equalsIgnoreCase(DatabaseType.NATIVE.name())) {
db.setType(DatabaseType.NATIVE);
db.setLocationUri(mdb.getLocationUri());
db.setManagedLocationUri(org.apache.commons.lang3.StringUtils.defaultIfBlank(mdb.getManagedLocationUri(), null));
} else {
db.setType(DatabaseType.REMOTE);
db.setConnector_name(org.apache.commons.lang3.StringUtils.defaultIfBlank(mdb.getDataConnectorName(), null));
db.setRemote_dbname(org.apache.commons.lang3.StringUtils.defaultIfBlank(mdb.getRemoteDatabaseName(), null));
}
db.setCatalogName(catName);
db.setCreateTime(mdb.getCreateTime());
return db;
}
use of org.apache.hadoop.hive.metastore.api.PrincipalType in project hive by apache.
the class TestHiveMetaStore method testFunctionWithResources.
@Test
public void testFunctionWithResources() throws Exception {
String dbName = "test_db2";
String funcName = "test_func";
String className = "org.apache.hadoop.hive.ql.udf.generic.GenericUDFUpper";
String owner = "test_owner";
PrincipalType ownerType = PrincipalType.USER;
int createTime = (int) (System.currentTimeMillis() / 1000);
FunctionType funcType = FunctionType.JAVA;
List<ResourceUri> resList = new ArrayList<>();
resList.add(new ResourceUri(ResourceType.JAR, "hdfs:///tmp/jar1.jar"));
resList.add(new ResourceUri(ResourceType.FILE, "hdfs:///tmp/file1.txt"));
resList.add(new ResourceUri(ResourceType.ARCHIVE, "hdfs:///tmp/archive1.tgz"));
try {
cleanUp(dbName, null, null);
createDb(dbName);
createFunction(dbName, funcName, className, owner, ownerType, createTime, funcType, resList);
// Try the different getters
// getFunction()
Function func = client.getFunction(dbName, funcName);
assertEquals("function db name", dbName, func.getDbName());
assertEquals("function name", funcName, func.getFunctionName());
assertEquals("function class name", className, func.getClassName());
assertEquals("function owner name", owner, func.getOwnerName());
assertEquals("function owner type", PrincipalType.USER, func.getOwnerType());
assertEquals("function type", funcType, func.getFunctionType());
List<ResourceUri> resources = func.getResourceUris();
assertEquals("Resource list size", resList.size(), resources.size());
for (ResourceUri res : resources) {
assertTrue("Matching resource " + res.getResourceType() + " " + res.getUri(), resList.indexOf(res) >= 0);
}
client.dropFunction(dbName, funcName);
} catch (Exception e) {
System.err.println(StringUtils.stringifyException(e));
System.err.println("testConcurrentMetastores() failed.");
throw e;
} finally {
silentDropDatabase(dbName);
}
}
use of org.apache.hadoop.hive.metastore.api.PrincipalType in project hive by apache.
the class ObjectStore method convertToMTable.
private MTable convertToMTable(Table tbl) throws InvalidObjectException, MetaException {
// existing write ID against the caller's valid list.
if (tbl == null) {
return null;
}
MDatabase mdb = null;
String catName = tbl.isSetCatName() ? tbl.getCatName() : getDefaultCatalog(conf);
try {
mdb = getMDatabase(catName, tbl.getDbName());
} catch (NoSuchObjectException e) {
LOG.error("Could not convert to MTable", e);
throw new InvalidObjectException("Database " + DatabaseName.getQualified(catName, tbl.getDbName()) + " doesn't exist.");
}
// If the table has property EXTERNAL set, update table type
// accordingly
String tableType = tbl.getTableType();
boolean isExternal = Boolean.parseBoolean(tbl.getParameters().get("EXTERNAL"));
if (TableType.MANAGED_TABLE.toString().equals(tableType)) {
if (isExternal) {
tableType = TableType.EXTERNAL_TABLE.toString();
}
}
if (TableType.EXTERNAL_TABLE.toString().equals(tableType)) {
if (!isExternal) {
tableType = TableType.MANAGED_TABLE.toString();
}
}
PrincipalType ownerPrincipalType = tbl.getOwnerType();
String ownerType = (ownerPrincipalType == null) ? PrincipalType.USER.name() : ownerPrincipalType.name();
// A new table is always created with a new column descriptor
return new MTable(normalizeIdentifier(tbl.getTableName()), mdb, convertToMStorageDescriptor(tbl.getSd()), tbl.getOwner(), ownerType, tbl.getCreateTime(), tbl.getLastAccessTime(), tbl.getRetention(), convertToMFieldSchemas(tbl.getPartitionKeys()), tbl.getParameters(), tbl.getViewOriginalText(), tbl.getViewExpandedText(), tbl.isRewriteEnabled(), tableType);
}
use of org.apache.hadoop.hive.metastore.api.PrincipalType in project hive by apache.
the class ObjectStore method createDataConnector.
@Override
public void createDataConnector(DataConnector connector) throws InvalidObjectException, MetaException {
boolean commited = false;
MDataConnector mDataConnector = new MDataConnector();
mDataConnector.setName(connector.getName().toLowerCase());
mDataConnector.setType(connector.getType());
mDataConnector.setUrl(connector.getUrl());
mDataConnector.setDescription(connector.getDescription());
mDataConnector.setParameters(connector.getParameters());
mDataConnector.setOwnerName(connector.getOwnerName());
PrincipalType ownerType = connector.getOwnerType();
mDataConnector.setOwnerType((null == ownerType ? PrincipalType.USER.name() : ownerType.name()));
mDataConnector.setCreateTime(connector.getCreateTime());
try {
openTransaction();
pm.makePersistent(mDataConnector);
commited = commitTransaction();
} finally {
if (!commited) {
rollbackTransaction();
}
}
}
Aggregations