Search in sources :

Example 11 with Role

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

the class HBaseReadWrite method scanRoles.

private List<Role> scanRoles(String regex) throws IOException {
    Filter filter = null;
    if (regex != null) {
        filter = new RowFilter(CompareFilter.CompareOp.EQUAL, new RegexStringComparator(regex));
    }
    Iterator<Result> iter = scan(ROLE_TABLE, null, null, CATALOG_CF, CATALOG_COL, filter);
    List<Role> roles = new ArrayList<>();
    while (iter.hasNext()) {
        Result result = iter.next();
        roles.add(HBaseUtils.deserializeRole(result.getRow(), result.getValue(CATALOG_CF, CATALOG_COL)));
    }
    return roles;
}
Also used : RegexStringComparator(org.apache.hadoop.hbase.filter.RegexStringComparator) Role(org.apache.hadoop.hive.metastore.api.Role) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) FirstKeyOnlyFilter(org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter) Filter(org.apache.hadoop.hbase.filter.Filter) CompareFilter(org.apache.hadoop.hbase.filter.CompareFilter) BloomFilter(org.apache.hive.common.util.BloomFilter) ArrayList(java.util.ArrayList) Result(org.apache.hadoop.hbase.client.Result)

Example 12 with Role

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

the class TestAdminUser method testCreateAdminNAddUser.

public void testCreateAdminNAddUser() throws IOException, Throwable {
    HiveConf conf = new HiveConf();
    conf.setVar(ConfVars.USERS_IN_ADMIN_ROLE, "adminuser");
    conf.setVar(ConfVars.HIVE_AUTHORIZATION_MANAGER, SQLStdHiveAuthorizerFactory.class.getName());
    RawStore rawStore = new HMSHandler("testcreateroot", conf).getMS();
    Role adminRole = rawStore.getRole(HiveMetaStore.ADMIN);
    assertTrue(adminRole.getOwnerName().equals(HiveMetaStore.ADMIN));
    assertEquals(rawStore.listPrincipalGlobalGrants(HiveMetaStore.ADMIN, PrincipalType.ROLE).get(0).getGrantInfo().getPrivilege(), "All");
    assertEquals(rawStore.listRoles("adminuser", PrincipalType.USER).get(0).getRoleName(), HiveMetaStore.ADMIN);
}
Also used : Role(org.apache.hadoop.hive.metastore.api.Role) SQLStdHiveAuthorizerFactory(org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory) HiveConf(org.apache.hadoop.hive.conf.HiveConf) HMSHandler(org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler)

Example 13 with Role

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

the class AbstractTestAuthorizationApiAuthorizer method testCreateRole.

@Test
public void testCreateRole() throws Exception {
    FunctionInvoker invoker = new FunctionInvoker() {

        @Override
        public void invoke() throws Exception {
            msc.create_role(new Role("role1", 0, "owner"));
        }
    };
    testFunction(invoker);
}
Also used : Role(org.apache.hadoop.hive.metastore.api.Role) Test(org.junit.Test)

Example 14 with Role

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

the class HBaseStore method addRole.

@Override
public boolean addRole(String roleName, String ownerName) throws InvalidObjectException, MetaException, NoSuchObjectException {
    int now = (int) (System.currentTimeMillis() / 1000);
    Role role = new Role(roleName, now, ownerName);
    boolean commit = false;
    openTransaction();
    try {
        if (getHBase().getRole(roleName) != null) {
            throw new InvalidObjectException("Role " + roleName + " already exists");
        }
        getHBase().putRole(role);
        commit = true;
        return true;
    } catch (IOException e) {
        LOG.error("Unable to create role ", e);
        throw new MetaException("Unable to read from or write to hbase " + e.getMessage());
    } finally {
        commitOrRoleBack(commit);
    }
}
Also used : Role(org.apache.hadoop.hive.metastore.api.Role) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) IOException(java.io.IOException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

Example 15 with Role

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

the class HBaseImport method copyRoles.

private void copyRoles() throws NoSuchObjectException, InvalidObjectException, MetaException {
    screen("Copying roles");
    List<String> toCopy = doAll ? rdbmsStore.get().listRoleNames() : rolesToImport;
    for (String roleName : toCopy) {
        Role role = rdbmsStore.get().getRole(roleName);
        screen("Copying role " + roleName);
        hbaseStore.get().addRole(roleName, role.getOwnerName());
    }
}
Also used : Role(org.apache.hadoop.hive.metastore.api.Role)

Aggregations

Role (org.apache.hadoop.hive.metastore.api.Role)30 Test (org.junit.Test)15 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 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 Partition (org.apache.hadoop.hive.metastore.api.Partition)2