@Override public FindSchemasByColsResp get_schemas_by_cols(FindSchemasByColsRqst rqst) throws TException { startFunction("get_schemas_by_cols"); Exception ex = null; List<SchemaVersion> schemaVersions = Collections.emptyList(); try { schemaVersions = getMS().getSchemaVersionsByColumns(rqst.getColName(), rqst.getColNamespace(), rqst.getType()); firePreEvent(new PreReadhSchemaVersionEvent(this, schemaVersions)); final List<SchemaVersionDescriptor> entries = new ArrayList<>(schemaVersions.size()); schemaVersions.forEach(schemaVersion -> entries.add( new SchemaVersionDescriptor(schemaVersion.getSchema(), schemaVersion.getVersion()))); return new FindSchemasByColsResp(entries); } catch (MetaException e) { LOG.error("Caught exception doing schema version query", e); ex = e; throw e; } finally { endFunction("get_schemas_by_cols", !schemaVersions.isEmpty(), ex); } }
@Override public SchemaVersion get_schema_version(SchemaVersionDescriptor version) throws TException { startFunction("get_schema_version", ": " + version); Exception ex = null; SchemaVersion schemaVersion = null; try { schemaVersion = getMS().getSchemaVersion(version); if (schemaVersion == null) { throw new NoSuchObjectException("No schema version " + version + "exists"); } firePreEvent(new PreReadhSchemaVersionEvent(this, Collections.singletonList(schemaVersion))); return schemaVersion; } catch (MetaException e) { LOG.error("Caught exception getting schema version", e); ex = e; throw e; } finally { endFunction("get_schema_version", schemaVersion != null, ex); } }
@Override public SchemaVersion get_schema_latest_version(ISchemaName schemaName) throws TException { startFunction("get_latest_schema_version", ": " + schemaName); Exception ex = null; SchemaVersion schemaVersion = null; try { schemaVersion = getMS().getLatestSchemaVersion(schemaName); if (schemaVersion == null) { throw new NoSuchObjectException("No versions of schema " + schemaName + "exist"); } firePreEvent(new PreReadhSchemaVersionEvent(this, Collections.singletonList(schemaVersion))); return schemaVersion; } catch (MetaException e) { LOG.error("Caught exception getting latest schema version", e); ex = e; throw e; } finally { endFunction("get_latest_schema_version", schemaVersion != null, ex); } }
private Table getTableInternal(String catName, String dbname, String name, ClientCapabilities capabilities, String writeIdList, boolean getColumnStats) throws MetaException, NoSuchObjectException { if (isInTest) { assertClientHasCapability(capabilities, ClientCapability.TEST_CAPABILITY, "Hive tests", "get_table_req"); } Table t = null; startTableFunction("get_table", catName, dbname, name); Exception ex = null; try { t = get_table_core(catName, dbname, name, writeIdList, getColumnStats); if (MetaStoreUtils.isInsertOnlyTableParam(t.getParameters())) { assertClientHasCapability(capabilities, ClientCapability.INSERT_ONLY_TABLES, "insert-only tables", "get_table_req"); } firePreEvent(new PreReadTableEvent(t, this)); } catch (MetaException | NoSuchObjectException e) { ex = e; throw e; } finally { endFunction("get_table", t != null, ex, name); } return t; }
@Override public PrincipalPrivilegeSet get_privilege_set(HiveObjectRef hiveObject, String userName, List<String> groupNames) throws TException { firePreEvent(new PreAuthorizationCallEvent(this)); String catName = hiveObject.isSetCatName() ? hiveObject.getCatName() : getDefaultCatalog(conf); if (hiveObject.getObjectType() == HiveObjectType.COLUMN) { String partName = getPartName(hiveObject); return this.get_column_privilege_set(catName, hiveObject.getDbName(), hiveObject .getObjectName(), partName, hiveObject.getColumnName(), userName, groupNames); } else if (hiveObject.getObjectType() == HiveObjectType.PARTITION) { String partName = getPartName(hiveObject); return this.get_partition_privilege_set(catName, hiveObject.getDbName(), hiveObject.getObjectName(), partName, userName, groupNames); } else if (hiveObject.getObjectType() == HiveObjectType.DATABASE) { return this.get_db_privilege_set(catName, hiveObject.getDbName(), userName, groupNames); } else if (hiveObject.getObjectType() == HiveObjectType.TABLE) { return this.get_table_privilege_set(catName, hiveObject.getDbName(), hiveObject .getObjectName(), userName, groupNames); } else if (hiveObject.getObjectType() == HiveObjectType.GLOBAL) { return this.get_user_privilege_set(userName, groupNames); } return null; }
private boolean revoke_role(final String roleName, final String userName, final PrincipalType principalType, boolean grantOption) throws TException { incrementCounter("remove_role_member"); firePreEvent(new PreAuthorizationCallEvent(this)); if (PUBLIC.equals(roleName)) { throw new MetaException(PUBLIC + " role can't be revoked."); } Boolean ret; try { RawStore ms = getMS(); Role mRole = ms.getRole(roleName); ret = ms.revokeRole(mRole, userName, principalType, grantOption); } catch (MetaException e) { throw e; } catch (NoSuchObjectException e) { ret = false; MetaStoreUtils.logAndThrowMetaException(e); } catch (Exception e) { throw new TException(e); } return ret; }
@Override public List<SchemaVersion> get_schema_all_versions(ISchemaName schemaName) throws TException { startFunction("get_all_schema_versions", ": " + schemaName); Exception ex = null; List<SchemaVersion> schemaVersions = null; try { schemaVersions = getMS().getAllSchemaVersion(schemaName); if (schemaVersions == null) { throw new NoSuchObjectException("No versions of schema " + schemaName + "exist"); } firePreEvent(new PreReadhSchemaVersionEvent(this, schemaVersions)); return schemaVersions; } catch (MetaException e) { LOG.error("Caught exception getting all schema versions", e); ex = e; throw e; } finally { endFunction("get_all_schema_versions", schemaVersions != null, ex); } }
@Override public ISchema get_ischema(ISchemaName schemaName) throws TException { startFunction("get_ischema", ": " + schemaName); Exception ex = null; ISchema schema = null; try { schema = getMS().getISchema(schemaName); if (schema == null) { throw new NoSuchObjectException("No schema named " + schemaName + " exists"); } firePreEvent(new PreReadISchemaEvent(this, schema)); return schema; } catch (MetaException e) { LOG.error("Caught exception getting schema", e); ex = e; throw e; } finally { endFunction("get_ischema", schema != null, ex); } }
@Override public GetPrincipalsInRoleResponse get_principals_in_role(GetPrincipalsInRoleRequest request) throws TException { incrementCounter("get_principals_in_role"); firePreEvent(new PreAuthorizationCallEvent(this)); Exception ex = null; GetPrincipalsInRoleResponse response = null; try { response = new GetPrincipalsInRoleResponse(getMS().listRoleMembers(request.getRoleName())); } catch (MetaException e) { throw e; } catch (Exception e) { ex = e; rethrowException(e); } finally { endFunction("get_principals_in_role", ex == null, ex); } return response; }
@Override public GetRoleGrantsForPrincipalResponse get_role_grants_for_principal( GetRoleGrantsForPrincipalRequest request) throws TException { incrementCounter("get_role_grants_for_principal"); firePreEvent(new PreAuthorizationCallEvent(this)); Exception ex = null; List<RolePrincipalGrant> roleMaps = null; try { roleMaps = getMS().listRolesWithGrants(request.getPrincipal_name(), request.getPrincipal_type()); } catch (MetaException e) { throw e; } catch (Exception e) { ex = e; rethrowException(e); } finally { endFunction("get_role_grants_for_principal", ex == null, ex); } //List<RolePrincipalGrant> roleGrantsList = getRolePrincipalGrants(roleMaps); return new GetRoleGrantsForPrincipalResponse(roleMaps); }
@Override public boolean drop_role(final String roleName) throws TException { incrementCounter("drop_role"); firePreEvent(new PreAuthorizationCallEvent(this)); if (ADMIN.equals(roleName) || PUBLIC.equals(roleName)) { throw new MetaException(PUBLIC + "," + ADMIN + " roles can't be dropped."); } Boolean ret; try { ret = getMS().removeRole(roleName); } catch (MetaException e) { throw e; } catch (NoSuchObjectException e) { ret = false; MetaStoreUtils.logAndThrowMetaException(e); } catch (Exception e) { throw new TException(e); } return ret; }
@Override public boolean create_role(final Role role) throws TException { incrementCounter("create_role"); firePreEvent(new PreAuthorizationCallEvent(this)); if (PUBLIC.equals(role.getRoleName())) { throw new MetaException(PUBLIC + " role implicitly exists. It can't be created."); } Boolean ret; try { ret = getMS().addRole(role.getRoleName(), role.getOwnerName()); } catch (MetaException e) { throw e; } catch (InvalidObjectException | NoSuchObjectException e) { ret = false; MetaStoreUtils.logAndThrowMetaException(e); } catch (Exception e) { throw new TException(e); } return ret; }
@Override public GrantRevokePrivilegeResponse refresh_privileges(HiveObjectRef objToRefresh, String authorizer, GrantRevokePrivilegeRequest grantRequest) throws TException { incrementCounter("refresh_privileges"); firePreEvent(new PreAuthorizationCallEvent(this)); GrantRevokePrivilegeResponse response = new GrantRevokePrivilegeResponse(); try { boolean result = getMS().refreshPrivileges(objToRefresh, authorizer, grantRequest.getPrivileges()); response.setSuccess(result); } catch (MetaException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } return response; }
@Override public GetCatalogResponse get_catalog(GetCatalogRequest rqst) throws NoSuchObjectException, TException { String catName = rqst.getName(); startFunction("get_catalog", ": " + catName); Catalog cat = null; Exception ex = null; try { cat = getMS().getCatalog(catName); firePreEvent(new PreReadCatalogEvent(this, cat)); return new GetCatalogResponse(cat); } catch (MetaException|NoSuchObjectException e) { ex = e; throw e; } finally { endFunction("get_catalog", cat != null, ex); } }
@Override public boolean grant_privileges(final PrivilegeBag privileges) throws TException { incrementCounter("grant_privileges"); firePreEvent(new PreAuthorizationCallEvent(this)); Boolean ret; try { ret = getMS().grantPrivileges(privileges); } catch (MetaException e) { throw e; } catch (InvalidObjectException | NoSuchObjectException e) { ret = false; MetaStoreUtils.logAndThrowMetaException(e); } catch (Exception e) { throw new TException(e); } return ret; }
public boolean revoke_privileges(final PrivilegeBag privileges, boolean grantOption) throws TException { incrementCounter("revoke_privileges"); firePreEvent(new PreAuthorizationCallEvent(this)); Boolean ret; try { ret = getMS().revokePrivileges(privileges, grantOption); } catch (MetaException e) { throw e; } catch (InvalidObjectException | NoSuchObjectException e) { ret = false; MetaStoreUtils.logAndThrowMetaException(e); } catch (Exception e) { throw new TException(e); } return ret; }
/** * Fire a pre-event for read table operation, if there are any * pre-event listeners registered */ private void fireReadTablePreEvent(String catName, String dbName, String tblName) throws MetaException, NoSuchObjectException { if(preListeners.size() > 0) { // do this only if there is a pre event listener registered (avoid unnecessary // metastore api call) Table t = getMS().getTable(catName, dbName, tblName); if (t == null) { throw new NoSuchObjectException(TableName.getQualified(catName, dbName, tblName) + " table not found"); } firePreEvent(new PreReadTableEvent(t, this)); } }
@Override public Database get_database(final String name) throws NoSuchObjectException, MetaException { startFunction("get_database", ": " + name); Database db = null; Exception ex = null; try { String[] parsedDbName = parseDbName(name, conf); db = get_database_core(parsedDbName[CAT_NAME], parsedDbName[DB_NAME]); firePreEvent(new PreReadDatabaseEvent(db, this)); } catch (MetaException|NoSuchObjectException e) { ex = e; throw e; } finally { endFunction("get_database", db != null, ex); } return db; }
@Override public List<String> get_role_names() throws TException { incrementCounter("get_role_names"); firePreEvent(new PreAuthorizationCallEvent(this)); List<String> ret; try { ret = getMS().listRoleNames(); return ret; } catch (MetaException e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
@Override public List<Role> list_roles(final String principalName, final PrincipalType principalType) throws TException { incrementCounter("list_roles"); firePreEvent(new PreAuthorizationCallEvent(this)); return getMS().listRoles(principalName, principalType); }