Search in sources :

Example 1 with MRoleMap

use of org.apache.hadoop.hive.metastore.model.MRoleMap 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 2 with MRoleMap

use of org.apache.hadoop.hive.metastore.model.MRoleMap 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 3 with MRoleMap

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

the class ObjectStore method listMSecurityPrincipalMembershipRole.

private List<MRoleMap> listMSecurityPrincipalMembershipRole(final String roleName, final PrincipalType principalType) throws Exception {
    LOG.debug("Executing listMSecurityPrincipalMembershipRole");
    Preconditions.checkState(this.currentTransaction.isActive());
    try (Query query = pm.newQuery(MRoleMap.class, "principalName == t1 && principalType == t2")) {
        query.declareParameters("java.lang.String t1, java.lang.String t2");
        final List<MRoleMap> mRoleMemebership = (List<MRoleMap>) query.execute(roleName, principalType.toString());
        LOG.debug("Retrieving all objects for listMSecurityPrincipalMembershipRole");
        pm.retrieveAll(mRoleMemebership);
        LOG.debug("Done retrieving all objects for listMSecurityPrincipalMembershipRole: {}", mRoleMemebership);
        return Collections.unmodifiableList(new ArrayList<>(mRoleMemebership));
    }
}
Also used : ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) ValidWriteIdList(org.apache.hadoop.hive.common.ValidWriteIdList) ReplicationMetricList(org.apache.hadoop.hive.metastore.api.ReplicationMetricList) LinkedList(java.util.LinkedList) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) ValidReaderWriteIdList(org.apache.hadoop.hive.common.ValidReaderWriteIdList) List(java.util.List) MRoleMap(org.apache.hadoop.hive.metastore.model.MRoleMap)

Example 4 with MRoleMap

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

the class ObjectStore method listMRoleMembers.

public List<MRoleMap> listMRoleMembers(String roleName) {
    boolean success = false;
    Query query = null;
    List<MRoleMap> mRoleMemeberList = new ArrayList<>();
    try {
        LOG.debug("Executing listRoleMembers");
        openTransaction();
        query = pm.newQuery(MRoleMap.class, "role.roleName == t1");
        query.declareParameters("java.lang.String t1");
        query.setUnique(false);
        List<MRoleMap> mRoles = (List<MRoleMap>) query.execute(roleName);
        pm.retrieveAll(mRoles);
        success = commitTransaction();
        mRoleMemeberList.addAll(mRoles);
        LOG.debug("Done retrieving all objects for listRoleMembers");
    } finally {
        rollbackAndCleanup(success, query);
    }
    return mRoleMemeberList;
}
Also used : ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) ArrayList(java.util.ArrayList) ValidWriteIdList(org.apache.hadoop.hive.common.ValidWriteIdList) ReplicationMetricList(org.apache.hadoop.hive.metastore.api.ReplicationMetricList) LinkedList(java.util.LinkedList) MStringList(org.apache.hadoop.hive.metastore.model.MStringList) ArrayList(java.util.ArrayList) ValidReaderWriteIdList(org.apache.hadoop.hive.common.ValidReaderWriteIdList) List(java.util.List) MRoleMap(org.apache.hadoop.hive.metastore.model.MRoleMap)

Example 5 with MRoleMap

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

the class ObjectStore method getMSecurityUserRoleMap.

private MRoleMap getMSecurityUserRoleMap(String userName, PrincipalType principalType, String roleName) {
    MRoleMap mRoleMember = null;
    boolean commited = false;
    Query query = null;
    try {
        openTransaction();
        query = pm.newQuery(MRoleMap.class, "principalName == t1 && principalType == t2 && role.roleName == t3");
        query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3");
        query.setUnique(true);
        mRoleMember = (MRoleMap) query.executeWithArray(userName, principalType.toString(), roleName);
        pm.retrieve(mRoleMember);
        commited = commitTransaction();
    } finally {
        rollbackAndCleanup(commited, query);
    }
    return mRoleMember;
}
Also used : ScheduledQuery(org.apache.hadoop.hive.metastore.api.ScheduledQuery) Query(javax.jdo.Query) MScheduledQuery(org.apache.hadoop.hive.metastore.model.MScheduledQuery) MRoleMap(org.apache.hadoop.hive.metastore.model.MRoleMap)

Aggregations

MRoleMap (org.apache.hadoop.hive.metastore.model.MRoleMap)12 ArrayList (java.util.ArrayList)6 Query (javax.jdo.Query)5 ScheduledQuery (org.apache.hadoop.hive.metastore.api.ScheduledQuery)4 MRole (org.apache.hadoop.hive.metastore.model.MRole)4 MScheduledQuery (org.apache.hadoop.hive.metastore.model.MScheduledQuery)4 LinkedList (java.util.LinkedList)3 List (java.util.List)3 ValidReaderWriteIdList (org.apache.hadoop.hive.common.ValidReaderWriteIdList)3 ValidWriteIdList (org.apache.hadoop.hive.common.ValidWriteIdList)3 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)3 ReplicationMetricList (org.apache.hadoop.hive.metastore.api.ReplicationMetricList)3 MStringList (org.apache.hadoop.hive.metastore.model.MStringList)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)2 JDODataStoreException (javax.jdo.JDODataStoreException)2 JDOException (javax.jdo.JDOException)2 JDOObjectNotFoundException (javax.jdo.JDOObjectNotFoundException)2 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)2