Search in sources :

Example 11 with MRoleMap

use of org.apache.hadoop.hive.metastore.model.MRoleMap in project hive by apache.

the class ObjectStore method removeRole.

@Override
public boolean removeRole(String roleName) throws MetaException, NoSuchObjectException {
    boolean success = false;
    QueryWrapper queryWrapper = new QueryWrapper();
    try {
        openTransaction();
        MRole mRol = getMRole(roleName);
        pm.retrieve(mRol);
        if (mRol != null) {
            // first remove all the membership, the membership that this role has
            // been granted
            List<MRoleMap> roleMap = listMRoleMembers(mRol.getRoleName());
            if (roleMap.size() > 0) {
                pm.deletePersistentAll(roleMap);
            }
            List<MRoleMap> roleMember = listMSecurityPrincipalMembershipRole(mRol.getRoleName(), PrincipalType.ROLE, queryWrapper);
            if (roleMember.size() > 0) {
                pm.deletePersistentAll(roleMember);
            }
            queryWrapper.close();
            // then remove all the grants
            List<MGlobalPrivilege> userGrants = listPrincipalMGlobalGrants(mRol.getRoleName(), PrincipalType.ROLE);
            if (userGrants.size() > 0) {
                pm.deletePersistentAll(userGrants);
            }
            List<MDBPrivilege> dbGrants = listPrincipalAllDBGrant(mRol.getRoleName(), PrincipalType.ROLE, queryWrapper);
            if (dbGrants.size() > 0) {
                pm.deletePersistentAll(dbGrants);
            }
            queryWrapper.close();
            List<MTablePrivilege> tabPartGrants = listPrincipalAllTableGrants(mRol.getRoleName(), PrincipalType.ROLE, queryWrapper);
            if (tabPartGrants.size() > 0) {
                pm.deletePersistentAll(tabPartGrants);
            }
            queryWrapper.close();
            List<MPartitionPrivilege> partGrants = listPrincipalAllPartitionGrants(mRol.getRoleName(), PrincipalType.ROLE, queryWrapper);
            if (partGrants.size() > 0) {
                pm.deletePersistentAll(partGrants);
            }
            queryWrapper.close();
            List<MTableColumnPrivilege> tblColumnGrants = listPrincipalAllTableColumnGrants(mRol.getRoleName(), PrincipalType.ROLE, queryWrapper);
            if (tblColumnGrants.size() > 0) {
                pm.deletePersistentAll(tblColumnGrants);
            }
            queryWrapper.close();
            List<MPartitionColumnPrivilege> partColumnGrants = listPrincipalAllPartitionColumnGrants(mRol.getRoleName(), PrincipalType.ROLE, queryWrapper);
            if (partColumnGrants.size() > 0) {
                pm.deletePersistentAll(partColumnGrants);
            }
            queryWrapper.close();
            // finally remove the role
            pm.deletePersistent(mRol);
        }
        success = commitTransaction();
    } finally {
        if (!success) {
            rollbackTransaction();
        }
        queryWrapper.close();
    }
    return success;
}
Also used : MRole(org.apache.hadoop.hive.metastore.model.MRole) MPartitionColumnPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege) MDBPrivilege(org.apache.hadoop.hive.metastore.model.MDBPrivilege) MGlobalPrivilege(org.apache.hadoop.hive.metastore.model.MGlobalPrivilege) MPartitionPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionPrivilege) MRoleMap(org.apache.hadoop.hive.metastore.model.MRoleMap) MTablePrivilege(org.apache.hadoop.hive.metastore.model.MTablePrivilege) MTableColumnPrivilege(org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege)

Aggregations

MRoleMap (org.apache.hadoop.hive.metastore.model.MRoleMap)11 ArrayList (java.util.ArrayList)5 Query (javax.jdo.Query)4 MRole (org.apache.hadoop.hive.metastore.model.MRole)4 LinkedList (java.util.LinkedList)2 List (java.util.List)2 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 RolePrincipalGrant (org.apache.hadoop.hive.metastore.api.RolePrincipalGrant)2 MStringList (org.apache.hadoop.hive.metastore.model.MStringList)2 IOException (java.io.IOException)1 JDOCanRetryException (javax.jdo.JDOCanRetryException)1 JDODataStoreException (javax.jdo.JDODataStoreException)1 JDOException (javax.jdo.JDOException)1 JDOObjectNotFoundException (javax.jdo.JDOObjectNotFoundException)1 InvalidInputException (org.apache.hadoop.hive.metastore.api.InvalidInputException)1 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)1 InvalidPartitionException (org.apache.hadoop.hive.metastore.api.InvalidPartitionException)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 Role (org.apache.hadoop.hive.metastore.api.Role)1 UnknownDBException (org.apache.hadoop.hive.metastore.api.UnknownDBException)1