Search in sources :

Example 1 with MRole

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

the class ObjectStore method getRole.

@Override
public Role getRole(String roleName) throws NoSuchObjectException {
    MRole mRole = this.getMRole(roleName);
    if (mRole == null) {
        throw new NoSuchObjectException(roleName + " role can not be found.");
    }
    Role ret = new Role(mRole.getRoleName(), mRole.getCreateTime(), mRole.getOwnerName());
    return ret;
}
Also used : Role(org.apache.hadoop.hive.metastore.api.Role) MRole(org.apache.hadoop.hive.metastore.model.MRole) MRole(org.apache.hadoop.hive.metastore.model.MRole) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Example 2 with MRole

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

the class ObjectStore method listRoles.

@Override
public List<Role> listRoles(String principalName, PrincipalType principalType) {
    List<Role> result = new ArrayList<>();
    List<MRoleMap> roleMaps = listMRoles(principalName, principalType);
    if (roleMaps != null) {
        for (MRoleMap roleMap : roleMaps) {
            MRole mrole = roleMap.getRole();
            Role role = new Role(mrole.getRoleName(), mrole.getCreateTime(), mrole.getOwnerName());
            result.add(role);
        }
    }
    return result;
}
Also used : Role(org.apache.hadoop.hive.metastore.api.Role) MRole(org.apache.hadoop.hive.metastore.model.MRole) MRole(org.apache.hadoop.hive.metastore.model.MRole) ArrayList(java.util.ArrayList) MRoleMap(org.apache.hadoop.hive.metastore.model.MRoleMap)

Example 3 with MRole

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

the class ObjectStore method addRole.

@Override
public boolean addRole(String roleName, String ownerName) throws InvalidObjectException, MetaException, NoSuchObjectException {
    boolean success = false;
    boolean commited = false;
    try {
        openTransaction();
        MRole nameCheck = this.getMRole(roleName);
        if (nameCheck != null) {
            throw new InvalidObjectException("Role " + roleName + " already exists.");
        }
        int now = (int) (System.currentTimeMillis() / 1000);
        MRole mRole = new MRole(roleName, now, ownerName);
        pm.makePersistent(mRole);
        commited = commitTransaction();
        success = true;
    } finally {
        if (!commited) {
            rollbackTransaction();
        }
    }
    return success;
}
Also used : MRole(org.apache.hadoop.hive.metastore.model.MRole) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) MConstraint(org.apache.hadoop.hive.metastore.model.MConstraint) SQLUniqueConstraint(org.apache.hadoop.hive.metastore.api.SQLUniqueConstraint) SQLCheckConstraint(org.apache.hadoop.hive.metastore.api.SQLCheckConstraint) SQLDefaultConstraint(org.apache.hadoop.hive.metastore.api.SQLDefaultConstraint) SQLNotNullConstraint(org.apache.hadoop.hive.metastore.api.SQLNotNullConstraint)

Example 4 with MRole

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

the class ObjectStore method grantRole.

@Override
public boolean grantRole(Role role, String userName, PrincipalType principalType, String grantor, PrincipalType grantorType, boolean grantOption) throws MetaException, NoSuchObjectException, InvalidObjectException {
    boolean success = false;
    boolean commited = false;
    try {
        openTransaction();
        MRoleMap roleMap = null;
        try {
            roleMap = this.getMSecurityUserRoleMap(userName, principalType, role.getRoleName());
        } catch (Exception e) {
        }
        if (roleMap != null) {
            throw new InvalidObjectException("Principal " + userName + " already has the role " + role.getRoleName());
        }
        if (principalType == PrincipalType.ROLE) {
            validateRole(userName);
        }
        MRole mRole = getMRole(role.getRoleName());
        long now = System.currentTimeMillis() / 1000;
        MRoleMap roleMember = new MRoleMap(userName, principalType.toString(), mRole, (int) now, grantor, grantorType.toString(), grantOption);
        pm.makePersistent(roleMember);
        commited = commitTransaction();
        success = true;
    } finally {
        if (!commited) {
            rollbackTransaction();
        }
    }
    return success;
}
Also used : MRole(org.apache.hadoop.hive.metastore.model.MRole) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) MRoleMap(org.apache.hadoop.hive.metastore.model.MRoleMap) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) IOException(java.io.IOException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) InvalidPartitionException(org.apache.hadoop.hive.metastore.api.InvalidPartitionException) UnknownPartitionException(org.apache.hadoop.hive.metastore.api.UnknownPartitionException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) JDOException(javax.jdo.JDOException) MissingTableException(org.datanucleus.store.rdbms.exceptions.MissingTableException) SQLException(java.sql.SQLException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) TException(org.apache.thrift.TException) JDODataStoreException(javax.jdo.JDODataStoreException) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException)

Example 5 with MRole

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

the class ObjectStore method removeRole.

@Override
public boolean removeRole(String roleName) throws MetaException, NoSuchObjectException {
    boolean success = false;
    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 (CollectionUtils.isNotEmpty(roleMap)) {
                pm.deletePersistentAll(roleMap);
            }
            List<MRoleMap> roleMember = listMSecurityPrincipalMembershipRole(mRol.getRoleName(), PrincipalType.ROLE);
            if (CollectionUtils.isNotEmpty(roleMember)) {
                pm.deletePersistentAll(roleMember);
            }
            // then remove all the grants
            List<MGlobalPrivilege> userGrants = listPrincipalMGlobalGrants(mRol.getRoleName(), PrincipalType.ROLE);
            if (CollectionUtils.isNotEmpty(userGrants)) {
                pm.deletePersistentAll(userGrants);
            }
            List<MDBPrivilege> dbGrants = listPrincipalAllDBGrant(mRol.getRoleName(), PrincipalType.ROLE);
            if (CollectionUtils.isNotEmpty(dbGrants)) {
                pm.deletePersistentAll(dbGrants);
            }
            List<MDCPrivilege> dcGrants = listPrincipalAllDCGrant(mRol.getRoleName(), PrincipalType.ROLE);
            if (CollectionUtils.isNotEmpty(dcGrants)) {
                pm.deletePersistentAll(dcGrants);
            }
            List<MTablePrivilege> tabPartGrants = listPrincipalAllTableGrants(mRol.getRoleName(), PrincipalType.ROLE);
            if (CollectionUtils.isNotEmpty(tabPartGrants)) {
                pm.deletePersistentAll(tabPartGrants);
            }
            List<MPartitionPrivilege> partGrants = listPrincipalAllPartitionGrants(mRol.getRoleName(), PrincipalType.ROLE);
            if (CollectionUtils.isNotEmpty(partGrants)) {
                pm.deletePersistentAll(partGrants);
            }
            List<MTableColumnPrivilege> tblColumnGrants = listPrincipalAllTableColumnGrants(mRol.getRoleName(), PrincipalType.ROLE);
            if (CollectionUtils.isNotEmpty(tblColumnGrants)) {
                pm.deletePersistentAll(tblColumnGrants);
            }
            List<MPartitionColumnPrivilege> partColumnGrants = listPrincipalAllPartitionColumnGrants(mRol.getRoleName(), PrincipalType.ROLE);
            if (CollectionUtils.isNotEmpty(partColumnGrants)) {
                pm.deletePersistentAll(partColumnGrants);
            }
            // finally remove the role
            pm.deletePersistent(mRol);
        }
        success = commitTransaction();
    } catch (Exception e) {
        throw new MetaException(e.getMessage());
    } finally {
        rollbackAndCleanup(success, null);
    }
    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) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) InvalidInputException(org.apache.hadoop.hive.metastore.api.InvalidInputException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) IOException(java.io.IOException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) InvalidPartitionException(org.apache.hadoop.hive.metastore.api.InvalidPartitionException) UnknownPartitionException(org.apache.hadoop.hive.metastore.api.UnknownPartitionException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) JDOException(javax.jdo.JDOException) MissingTableException(org.datanucleus.store.rdbms.exceptions.MissingTableException) SQLException(java.sql.SQLException) UnknownDBException(org.apache.hadoop.hive.metastore.api.UnknownDBException) TException(org.apache.thrift.TException) JDODataStoreException(javax.jdo.JDODataStoreException) JDOObjectNotFoundException(javax.jdo.JDOObjectNotFoundException) UnknownTableException(org.apache.hadoop.hive.metastore.api.UnknownTableException) MDCPrivilege(org.apache.hadoop.hive.metastore.model.MDCPrivilege) 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) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Aggregations

MRole (org.apache.hadoop.hive.metastore.model.MRole)7 MRoleMap (org.apache.hadoop.hive.metastore.model.MRoleMap)4 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)3 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)2 ArrayList (java.util.ArrayList)2 JDODataStoreException (javax.jdo.JDODataStoreException)2 JDOException (javax.jdo.JDOException)2 JDOObjectNotFoundException (javax.jdo.JDOObjectNotFoundException)2 Query (javax.jdo.Query)2 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)2 InvalidInputException (org.apache.hadoop.hive.metastore.api.InvalidInputException)2 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)2 InvalidPartitionException (org.apache.hadoop.hive.metastore.api.InvalidPartitionException)2 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2 Role (org.apache.hadoop.hive.metastore.api.Role)2 ScheduledQuery (org.apache.hadoop.hive.metastore.api.ScheduledQuery)2 UnknownDBException (org.apache.hadoop.hive.metastore.api.UnknownDBException)2