Search in sources :

Example 16 with Role

use of org.apache.hadoop.hive.metastore.api.Role in project hive by apache.

the class HBaseUtils method deserializeRole.

/**
   * Deserialize a role.  This method should be used when the rolename is already known as it
   * doesn't have to re-deserialize it.
   * @param roleName name of the role
   * @param value value fetched from hbase
   * @return A role
   * @throws InvalidProtocolBufferException
   */
static Role deserializeRole(String roleName, byte[] value) throws InvalidProtocolBufferException {
    Role role = new Role();
    role.setRoleName(roleName);
    HbaseMetastoreProto.Role protoRole = HbaseMetastoreProto.Role.parseFrom(value);
    role.setCreateTime((int) protoRole.getCreateTime());
    if (protoRole.hasOwnerName())
        role.setOwnerName(protoRole.getOwnerName());
    return role;
}
Also used : Role(org.apache.hadoop.hive.metastore.api.Role)

Example 17 with Role

use of org.apache.hadoop.hive.metastore.api.Role in project hive by apache.

the class HBaseStore method getRole.

@Override
public Role getRole(String roleName) throws NoSuchObjectException {
    boolean commit = false;
    openTransaction();
    try {
        Role role = getHBase().getRole(roleName);
        if (role == null) {
            throw new NoSuchObjectException("Unable to find role " + roleName);
        }
        commit = true;
        return role;
    } catch (IOException e) {
        LOG.error("Unable to get role", e);
        throw new NoSuchObjectException("Error reading table " + e.getMessage());
    } finally {
        commitOrRoleBack(commit);
    }
}
Also used : Role(org.apache.hadoop.hive.metastore.api.Role) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) IOException(java.io.IOException)

Example 18 with Role

use of org.apache.hadoop.hive.metastore.api.Role in project hive by apache.

the class HBaseStore method listRoleNames.

@Override
public List<String> listRoleNames() {
    boolean commit = false;
    openTransaction();
    try {
        List<Role> roles = getHBase().scanRoles();
        List<String> roleNames = new ArrayList<String>(roles.size());
        for (Role role : roles) roleNames.add(role.getRoleName());
        commit = true;
        return roleNames;
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        commitOrRoleBack(commit);
    }
}
Also used : Role(org.apache.hadoop.hive.metastore.api.Role) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 19 with Role

use of org.apache.hadoop.hive.metastore.api.Role in project hive by apache.

the class HBaseReadWrite method getPrincipalDirectRoles.

/**
   * Find all roles directly participated in by a given principal.  This builds the role cache
   * because it assumes that subsequent calls may be made to find roles participated in indirectly.
   * @param name username or role name
   * @param type user or role
   * @return map of role name to grant info for all roles directly participated in.
   */
List<Role> getPrincipalDirectRoles(String name, PrincipalType type) throws IOException {
    buildRoleCache();
    Set<String> rolesFound = new HashSet<>();
    for (Map.Entry<String, HbaseMetastoreProto.RoleGrantInfoList> e : roleCache.entrySet()) {
        for (HbaseMetastoreProto.RoleGrantInfo giw : e.getValue().getGrantInfoList()) {
            if (HBaseUtils.convertPrincipalTypes(giw.getPrincipalType()) == type && giw.getPrincipalName().equals(name)) {
                rolesFound.add(e.getKey());
                break;
            }
        }
    }
    List<Role> directRoles = new ArrayList<>(rolesFound.size());
    List<Get> gets = new ArrayList<>();
    HTableInterface htab = conn.getHBaseTable(ROLE_TABLE);
    for (String roleFound : rolesFound) {
        byte[] key = HBaseUtils.buildKey(roleFound);
        Get g = new Get(key);
        g.addColumn(CATALOG_CF, CATALOG_COL);
        gets.add(g);
    }
    Result[] results = htab.get(gets);
    for (int i = 0; i < results.length; i++) {
        byte[] serialized = results[i].getValue(CATALOG_CF, CATALOG_COL);
        if (serialized != null) {
            directRoles.add(HBaseUtils.deserializeRole(results[i].getRow(), serialized));
        }
    }
    return directRoles;
}
Also used : ArrayList(java.util.ArrayList) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface) Result(org.apache.hadoop.hbase.client.Result) Role(org.apache.hadoop.hive.metastore.api.Role) Get(org.apache.hadoop.hbase.client.Get) Map(java.util.Map) NavigableMap(java.util.NavigableMap) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 20 with Role

use of org.apache.hadoop.hive.metastore.api.Role in project hive by apache.

the class HBaseStore method listRoles.

@Override
public List<Role> listRoles(String principalName, PrincipalType principalType) {
    List<Role> roles = new ArrayList<Role>();
    boolean commit = false;
    openTransaction();
    try {
        try {
            roles.addAll(getHBase().getPrincipalDirectRoles(principalName, principalType));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        // Add the public role if this is a user
        if (principalType == PrincipalType.USER) {
            roles.add(new Role(HiveMetaStore.PUBLIC, 0, null));
        }
        commit = true;
        return roles;
    } finally {
        commitOrRoleBack(commit);
    }
}
Also used : Role(org.apache.hadoop.hive.metastore.api.Role) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

Role (org.apache.hadoop.hive.metastore.api.Role)30 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)12 IOException (java.io.IOException)5 HiveObjectPrivilege (org.apache.hadoop.hive.metastore.api.HiveObjectPrivilege)5 HiveObjectRef (org.apache.hadoop.hive.metastore.api.HiveObjectRef)5 PrivilegeBag (org.apache.hadoop.hive.metastore.api.PrivilegeBag)5 PrivilegeGrantInfo (org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo)5 Database (org.apache.hadoop.hive.metastore.api.Database)4 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)3 Table (org.apache.hadoop.hive.metastore.api.Table)3 HashSet (java.util.HashSet)2 Result (org.apache.hadoop.hbase.client.Result)2 ObjectStore (org.apache.hadoop.hive.metastore.ObjectStore)2 RawStore (org.apache.hadoop.hive.metastore.RawStore)2 TestObjectStore (org.apache.hadoop.hive.metastore.TestObjectStore)2 MetastoreUnitTest (org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest)2 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)2 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)2 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)2