Search in sources :

Example 11 with MTablePrivilege

use of org.apache.hadoop.hive.metastore.model.MTablePrivilege 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)

Example 12 with MTablePrivilege

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

the class ObjectStore method listPrincipalAllTableGrants.

@SuppressWarnings("unchecked")
private List<MTablePrivilege> listPrincipalAllTableGrants(String principalName, PrincipalType principalType, QueryWrapper queryWrapper) {
    boolean success = false;
    List<MTablePrivilege> mSecurityTabPartList = null;
    try {
        LOG.debug("Executing listPrincipalAllTableGrants");
        openTransaction();
        Query query = queryWrapper.query = pm.newQuery(MTablePrivilege.class, "principalName == t1 && principalType == t2");
        query.declareParameters("java.lang.String t1, java.lang.String t2");
        mSecurityTabPartList = (List<MTablePrivilege>) query.execute(principalName, principalType.toString());
        pm.retrieveAll(mSecurityTabPartList);
        success = commitTransaction();
        LOG.debug("Done retrieving all objects for listPrincipalAllTableGrants");
    } finally {
        if (!success) {
            rollbackTransaction();
        }
    }
    return mSecurityTabPartList;
}
Also used : Query(javax.jdo.Query) MTablePrivilege(org.apache.hadoop.hive.metastore.model.MTablePrivilege)

Example 13 with MTablePrivilege

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

the class ObjectStore method listPrincipalTableGrantsAll.

@Override
public List<HiveObjectPrivilege> listPrincipalTableGrantsAll(String principalName, PrincipalType principalType) {
    boolean success = false;
    Query query = null;
    try {
        openTransaction();
        LOG.debug("Executing listPrincipalAllTableGrants");
        List<MTablePrivilege> mSecurityTabPartList;
        if (principalName != null && principalType != null) {
            query = pm.newQuery(MTablePrivilege.class, "principalName == t1 && principalType == t2");
            query.declareParameters("java.lang.String t1, java.lang.String t2");
            mSecurityTabPartList = (List<MTablePrivilege>) query.execute(principalName, principalType.toString());
        } else {
            query = pm.newQuery(MTablePrivilege.class);
            mSecurityTabPartList = (List<MTablePrivilege>) query.execute();
        }
        LOG.debug("Done executing query for listPrincipalAllTableGrants");
        pm.retrieveAll(mSecurityTabPartList);
        List<HiveObjectPrivilege> result = convertTable(mSecurityTabPartList);
        success = commitTransaction();
        LOG.debug("Done retrieving all objects for listPrincipalAllTableGrants");
        return result;
    } finally {
        if (!success) {
            rollbackTransaction();
        }
        if (query != null) {
            query.closeAll();
        }
    }
}
Also used : HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) Query(javax.jdo.Query) MTablePrivilege(org.apache.hadoop.hive.metastore.model.MTablePrivilege)

Example 14 with MTablePrivilege

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

the class ObjectStore method listAllTableGrants.

@Override
public List<HiveObjectPrivilege> listAllTableGrants(String principalName, PrincipalType principalType, String dbName, String tableName) {
    List<MTablePrivilege> mTbls = listAllMTableGrants(principalName, principalType, dbName, tableName);
    if (mTbls.isEmpty()) {
        return Collections.<HiveObjectPrivilege>emptyList();
    }
    List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
    for (int i = 0; i < mTbls.size(); i++) {
        MTablePrivilege sTbl = mTbls.get(i);
        HiveObjectRef objectRef = new HiveObjectRef(HiveObjectType.TABLE, dbName, tableName, null, null);
        HiveObjectPrivilege secObj = new HiveObjectPrivilege(objectRef, sTbl.getPrincipalName(), principalType, new PrivilegeGrantInfo(sTbl.getPrivilege(), sTbl.getCreateTime(), sTbl.getGrantor(), PrincipalType.valueOf(sTbl.getGrantorType()), sTbl.getGrantOption()));
        result.add(secObj);
    }
    return result;
}
Also used : HiveObjectPrivilege(org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege) PrivilegeGrantInfo(org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo) HiveObjectRef(org.apache.hadoop.hive.metastore.api.HiveObjectRef) ArrayList(java.util.ArrayList) MTablePrivilege(org.apache.hadoop.hive.metastore.model.MTablePrivilege) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint)

Example 15 with MTablePrivilege

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

the class ObjectStore method dropTable.

@Override
public boolean dropTable(String dbName, String tableName) throws MetaException, NoSuchObjectException, InvalidObjectException, InvalidInputException {
    boolean success = false;
    try {
        openTransaction();
        MTable tbl = getMTable(dbName, tableName);
        pm.retrieve(tbl);
        if (tbl != null) {
            // first remove all the grants
            List<MTablePrivilege> tabGrants = listAllTableGrants(dbName, tableName);
            if (tabGrants != null && tabGrants.size() > 0) {
                pm.deletePersistentAll(tabGrants);
            }
            List<MTableColumnPrivilege> tblColGrants = listTableAllColumnGrants(dbName, tableName);
            if (tblColGrants != null && tblColGrants.size() > 0) {
                pm.deletePersistentAll(tblColGrants);
            }
            List<MPartitionPrivilege> partGrants = this.listTableAllPartitionGrants(dbName, tableName);
            if (partGrants != null && partGrants.size() > 0) {
                pm.deletePersistentAll(partGrants);
            }
            List<MPartitionColumnPrivilege> partColGrants = listTableAllPartitionColumnGrants(dbName, tableName);
            if (partColGrants != null && partColGrants.size() > 0) {
                pm.deletePersistentAll(partColGrants);
            }
            // delete column statistics if present
            try {
                deleteTableColumnStatistics(dbName, tableName, null);
            } catch (NoSuchObjectException e) {
                LOG.info("Found no table level column statistics associated with db " + dbName + " table " + tableName + " record to delete");
            }
            List<MConstraint> tabConstraints = listAllTableConstraintsWithOptionalConstraintName(dbName, tableName, null);
            if (tabConstraints != null && tabConstraints.size() > 0) {
                pm.deletePersistentAll(tabConstraints);
            }
            preDropStorageDescriptor(tbl.getSd());
            // then remove the table
            pm.deletePersistentAll(tbl);
        }
        success = commitTransaction();
    } finally {
        if (!success) {
            rollbackTransaction();
        }
    }
    return success;
}
Also used : MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint) MPartitionColumnPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege) MTable(org.apache.hadoop.hive.metastore.model.MTable) MPartitionPrivilege(org.apache.hadoop.hive.metastore.model.MPartitionPrivilege) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MTablePrivilege(org.apache.hadoop.hive.metastore.model.MTablePrivilege) MTableColumnPrivilege(org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege)

Aggregations

MTablePrivilege (org.apache.hadoop.hive.metastore.model.MTablePrivilege)16 ArrayList (java.util.ArrayList)11 MConstraint (org.apache.hadoop.hive.metastore.model.MConstraint)8 MPartitionColumnPrivilege (org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege)7 MPartitionPrivilege (org.apache.hadoop.hive.metastore.model.MPartitionPrivilege)7 MTableColumnPrivilege (org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege)7 LinkedList (java.util.LinkedList)6 List (java.util.List)6 HiveObjectPrivilege (org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege)6 MStringList (org.apache.hadoop.hive.metastore.model.MStringList)6 MTable (org.apache.hadoop.hive.metastore.model.MTable)6 Query (javax.jdo.Query)5 HiveObjectRef (org.apache.hadoop.hive.metastore.api.HiveObjectRef)4 PrivilegeGrantInfo (org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo)4 MPartition (org.apache.hadoop.hive.metastore.model.MPartition)4 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)3 PrincipalType (org.apache.hadoop.hive.metastore.api.PrincipalType)3 MDBPrivilege (org.apache.hadoop.hive.metastore.model.MDBPrivilege)3 MGlobalPrivilege (org.apache.hadoop.hive.metastore.model.MGlobalPrivilege)3 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)2