You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ga...@apache.org on 2015/03/05 05:09:32 UTC
svn commit: r1664226 [1/2] - in /hive/branches/hbase-metastore:
itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/
itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/
metastore/src/java/org/apache/hadoop/hive/metastore/...
Author: gates
Date: Thu Mar 5 04:09:31 2015
New Revision: 1664226
URL: http://svn.apache.org/r1664226
Log:
HIVE-9763 Remove M* classes from RawStore interface (Alan Gates)
Modified:
hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestAdminUser.java
hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseStoreIntegration.java
hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/RawStore.java
hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseReadWrite.java
hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseStore.java
hive/branches/hbase-metastore/metastore/src/test/org/apache/hadoop/hive/metastore/DummyRawStoreControlledCommit.java
hive/branches/hbase-metastore/metastore/src/test/org/apache/hadoop/hive/metastore/DummyRawStoreForJdoConnection.java
Modified: hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestAdminUser.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestAdminUser.java?rev=1664226&r1=1664225&r2=1664226&view=diff
==============================================================================
--- hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestAdminUser.java (original)
+++ hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestAdminUser.java Thu Mar 5 04:09:31 2015
@@ -38,8 +38,8 @@ public class TestAdminUser extends TestC
Role adminRole = rawStore.getRole(HiveMetaStore.ADMIN);
assertTrue(adminRole.getOwnerName().equals(HiveMetaStore.ADMIN));
assertEquals(rawStore.listPrincipalGlobalGrants(HiveMetaStore.ADMIN, PrincipalType.ROLE)
- .get(0).getPrivilege(),"All");
- assertEquals(rawStore.listRoles("adminuser", PrincipalType.USER).get(0).getRole().
+ .get(0).getGrantInfo().getPrivilege(),"All");
+ assertEquals(rawStore.listRoles("adminuser", PrincipalType.USER).get(0).
getRoleName(),HiveMetaStore.ADMIN);
}
}
\ No newline at end of file
Modified: hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseStoreIntegration.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseStoreIntegration.java?rev=1664226&r1=1664225&r2=1664226&view=diff
==============================================================================
--- hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseStoreIntegration.java (original)
+++ hive/branches/hbase-metastore/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/hbase/TestHBaseStoreIntegration.java Thu Mar 5 04:09:31 2015
@@ -49,6 +49,7 @@ import org.apache.hadoop.hive.metastore.
import org.apache.hadoop.hive.metastore.api.PrivilegeBag;
import org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo;
import org.apache.hadoop.hive.metastore.api.Role;
+import org.apache.hadoop.hive.metastore.api.RolePrincipalGrant;
import org.apache.hadoop.hive.metastore.api.SerDeInfo;
import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
import org.apache.hadoop.hive.metastore.api.StringColumnStatsData;
@@ -669,67 +670,45 @@ public class TestHBaseStoreIntegration {
store.grantRole(role2, roleName1, PrincipalType.ROLE, "admin", PrincipalType.ROLE, true);
store.grantRole(role2, "fred", PrincipalType.USER, "admin", PrincipalType.ROLE, false);
- List<MRoleMap> maps = store.listRoles("fred", PrincipalType.USER);
- Assert.assertEquals(3, maps.size());
+ List<Role> roles = store.listRoles("fred", PrincipalType.USER);
+ Assert.assertEquals(3, roles.size());
boolean sawRole1 = false, sawRole2 = false, sawPublic = false;
- for (MRoleMap map : maps) {
- if (map.getRole().getRoleName().equals(roleName1)) {
+ for (Role role : roles) {
+ if (role.getRoleName().equals(roleName1)) {
sawRole1 = true;
- Assert.assertEquals("fred", map.getPrincipalName());
- Assert.assertEquals(PrincipalType.USER.toString(), map.getPrincipalType());
- Assert.assertTrue(map.getAddTime() >= now);
- Assert.assertEquals("bob", map.getGrantor());
- Assert.assertEquals(PrincipalType.USER.toString(), map.getGrantorType());
- Assert.assertFalse(map.getGrantOption());
- } else if (map.getRole().getRoleName().equals(roleName2)) {
+ } else if (role.getRoleName().equals(roleName2)) {
sawRole2 = true;
- Assert.assertEquals("fred", map.getPrincipalName());
- Assert.assertEquals(PrincipalType.USER.toString(), map.getPrincipalType());
- LOG.debug("now " + now + " add time " + map.getAddTime());
- Assert.assertTrue(map.getAddTime() >= now);
- Assert.assertEquals("admin", map.getGrantor());
- Assert.assertEquals(PrincipalType.ROLE.toString(), map.getGrantorType());
- Assert.assertFalse(map.getGrantOption());
- } else if (map.getRole().getRoleName().equals(HiveMetaStore.PUBLIC)) {
+ } else if (role.getRoleName().equals(HiveMetaStore.PUBLIC)) {
sawPublic = true;
- Assert.assertEquals("fred", map.getPrincipalName());
- Assert.assertEquals(PrincipalType.USER.toString(), map.getPrincipalType());
- Assert.assertFalse(map.getGrantOption());
} else {
- Assert.fail("Unknown role name " + map.getRole().getRoleName());
+ Assert.fail("Unknown role name " + role.getRoleName());
}
}
Assert.assertTrue(sawRole1 && sawRole2 && sawPublic);
- maps = store.listRoles("fred", PrincipalType.ROLE);
- Assert.assertEquals(0, maps.size());
+ roles = store.listRoles("fred", PrincipalType.ROLE);
+ Assert.assertEquals(0, roles.size());
- maps = store.listRoles(roleName1, PrincipalType.ROLE);
- Assert.assertEquals(1, maps.size());
- MRoleMap map = maps.get(0);
- Assert.assertEquals(roleName1, map.getPrincipalName());
- Assert.assertEquals(PrincipalType.ROLE.toString(), map.getPrincipalType());
- Assert.assertEquals(roleName2, map.getRole().getRoleName());
- Assert.assertTrue(map.getAddTime() <= now);
- Assert.assertEquals("admin", map.getGrantor());
- Assert.assertEquals(PrincipalType.ROLE.toString(), map.getGrantorType());
- Assert.assertTrue(map.getGrantOption());
+ roles = store.listRoles(roleName1, PrincipalType.ROLE);
+ Assert.assertEquals(1, roles.size());
+ Role role = roles.get(0);
+ Assert.assertEquals(roleName2, role.getRoleName());
// Test listing all members in a role
- maps = store.listRoleMembers(roleName1);
- Assert.assertEquals(1, maps.size());
- Assert.assertEquals("fred", maps.get(0).getPrincipalName());
- Assert.assertEquals(PrincipalType.USER.toString(), maps.get(0).getPrincipalType());
- Assert.assertTrue(maps.get(0).getAddTime() >= now);
- Assert.assertEquals("bob", maps.get(0).getGrantor());
- Assert.assertEquals(PrincipalType.USER.toString(), maps.get(0).getGrantorType());
- Assert.assertFalse(maps.get(0).getGrantOption());
+ List<RolePrincipalGrant> grants = store.listRoleMembers(roleName1);
+ Assert.assertEquals(1, grants.size());
+ Assert.assertEquals("fred", grants.get(0).getPrincipalName());
+ Assert.assertEquals(PrincipalType.USER, grants.get(0).getPrincipalType());
+ Assert.assertTrue(grants.get(0).getGrantTime() >= now);
+ Assert.assertEquals("bob", grants.get(0).getGrantorName());
+ Assert.assertEquals(PrincipalType.USER, grants.get(0).getGrantorPrincipalType());
+ Assert.assertFalse(grants.get(0).isGrantOption());
- maps = store.listRoleMembers(roleName2);
- Assert.assertEquals(2, maps.size());
+ grants = store.listRoleMembers(roleName2);
+ Assert.assertEquals(2, grants.size());
boolean sawFred = false;
sawRole1 = false;
- for (MRoleMap m : maps) {
+ for (RolePrincipalGrant m : grants) {
if ("fred".equals(m.getPrincipalName())) sawFred = true;
else if (roleName1.equals(m.getPrincipalName())) sawRole1 = true;
else Assert.fail("Unexpected principal " + m.getPrincipalName());
@@ -738,30 +717,32 @@ public class TestHBaseStoreIntegration {
// Revoke a role with grant option, make sure it just goes to no grant option
store.revokeRole(role2, roleName1, PrincipalType.ROLE, true);
- maps = store.listRoles(roleName1, PrincipalType.ROLE);
- Assert.assertEquals(1, maps.size());
- Assert.assertEquals(roleName2, maps.get(0).getRole().getRoleName());
- Assert.assertFalse(maps.get(0).getGrantOption());
+ roles = store.listRoles(roleName1, PrincipalType.ROLE);
+ Assert.assertEquals(1, roles.size());
+ Assert.assertEquals(roleName2, roles.get(0).getRoleName());
+
+ grants = store.listRoleMembers(roleName1);
+ Assert.assertFalse(grants.get(0).isGrantOption());
// Drop a role, make sure it is properly removed from the map
store.removeRole(roleName1);
- maps = store.listRoles("fred", PrincipalType.USER);
- Assert.assertEquals(2, maps.size());
+ roles = store.listRoles("fred", PrincipalType.USER);
+ Assert.assertEquals(2, roles.size());
sawRole2 = sawPublic = false;
- for (MRoleMap m : maps) {
- if (m.getRole().getRoleName().equals(roleName2)) sawRole2 = true;
- else if (m.getRole().getRoleName().equals(HiveMetaStore.PUBLIC)) sawPublic = true;
- else Assert.fail("Unknown role " + m.getRole().getRoleName());
+ for (Role m : roles) {
+ if (m.getRoleName().equals(roleName2)) sawRole2 = true;
+ else if (m.getRoleName().equals(HiveMetaStore.PUBLIC)) sawPublic = true;
+ else Assert.fail("Unknown role " + m.getRoleName());
}
Assert.assertTrue(sawRole2 && sawPublic);
- maps = store.listRoles(roleName1, PrincipalType.ROLE);
- Assert.assertEquals(0, maps.size());
+ roles = store.listRoles(roleName1, PrincipalType.ROLE);
+ Assert.assertEquals(0, roles.size());
// Revoke a role without grant option, make sure it goes away
store.revokeRole(role2, "fred", PrincipalType.USER, false);
- maps = store.listRoles("fred", PrincipalType.USER);
- Assert.assertEquals(1, maps.size());
- Assert.assertEquals(HiveMetaStore.PUBLIC, maps.get(0).getRole().getRoleName());
+ roles = store.listRoles("fred", PrincipalType.USER);
+ Assert.assertEquals(1, roles.size());
+ Assert.assertEquals(HiveMetaStore.PUBLIC, roles.get(0).getRoleName());
}
@Test
@@ -1080,9 +1061,290 @@ public class TestHBaseStoreIntegration {
Assert.assertNull("Expected null for role " + roleName + " for type " + objectType.toString()
+ " with db " + dbName + " and table " + tableName, pgi);
+ }
+
+ @Test
+ public void listDbGrants() throws Exception {
+ String dbNames[] = new String[] {"ldbg_db1", "ldbg_db2"};
+ try {
+ Database db = new Database(dbNames[0], "no description", "file:///tmp", emptyParameters);
+ store.createDatabase(db);
+ db = new Database(dbNames[1], "no description", "file:///tmp", emptyParameters);
+ store.createDatabase(db);
+ String[] roleNames = new String[]{"ldbg_role1", "ldbg_role2"};
+ String[] userNames = new String[]{"frodo", "sam"};
+ store.addRole(roleNames[0], "me");
+ store.addRole(roleNames[1], "me");
+ int now = (int)(System.currentTimeMillis() / 1000);
+
+ Role role1 = store.getRole(roleNames[0]);
+ Role role2 = store.getRole(roleNames[1]);
+ store.grantRole(role1, userNames[0], PrincipalType.USER, "bob", PrincipalType.USER, false);
+ store.grantRole(role1, roleNames[1], PrincipalType.ROLE, "admin", PrincipalType.ROLE, true);
+ store.grantRole(role2, userNames[1], PrincipalType.USER, "bob", PrincipalType.USER, false);
+
+ List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
+ HiveObjectRef hiveObjRef =
+ new HiveObjectRef(HiveObjectType.DATABASE, dbNames[0], null, null, null);
+ PrivilegeGrantInfo grantInfo =
+ new PrivilegeGrantInfo("read", now, "me", PrincipalType.USER, false);
+ HiveObjectPrivilege hop = new HiveObjectPrivilege(hiveObjRef, userNames[0], PrincipalType.USER,
+ grantInfo);
+ privileges.add(hop);
+
+ grantInfo = new PrivilegeGrantInfo("write", now, "me", PrincipalType.USER, true);
+ hop = new HiveObjectPrivilege(hiveObjRef, roleNames[0], PrincipalType.ROLE, grantInfo);
+ privileges.add(hop);
+
+ PrivilegeBag pBag = new PrivilegeBag(privileges);
+ store.grantPrivileges(pBag);
+
+ List<HiveObjectPrivilege> hops =
+ store.listPrincipalDBGrants(roleNames[0], PrincipalType.ROLE, dbNames[0]);
+ Assert.assertEquals(1, hops.size());
+ Assert.assertEquals(PrincipalType.ROLE, hops.get(0).getPrincipalType());
+ Assert.assertEquals(HiveObjectType.DATABASE, hops.get(0).getHiveObject().getObjectType());
+ Assert.assertEquals("write", hops.get(0).getGrantInfo().getPrivilege());
+
+ hops = store.listPrincipalDBGrants(userNames[0], PrincipalType.USER, dbNames[0]);
+ Assert.assertEquals(1, hops.size());
+ Assert.assertEquals(PrincipalType.USER, hops.get(0).getPrincipalType());
+ Assert.assertEquals(HiveObjectType.DATABASE, hops.get(0).getHiveObject().getObjectType());
+ Assert.assertEquals("read", hops.get(0).getGrantInfo().getPrivilege());
+
+ hops = store.listPrincipalDBGrants(roleNames[1], PrincipalType.ROLE, dbNames[0]);
+ Assert.assertEquals(0, hops.size());
+ hops = store.listPrincipalDBGrants(userNames[1], PrincipalType.USER, dbNames[0]);
+ Assert.assertEquals(0, hops.size());
+
+ hops = store.listPrincipalDBGrants(roleNames[0], PrincipalType.ROLE, dbNames[1]);
+ Assert.assertEquals(0, hops.size());
+ hops = store.listPrincipalDBGrants(userNames[0], PrincipalType.USER, dbNames[1]);
+ Assert.assertEquals(0, hops.size());
+
+ hops = store.listDBGrantsAll(dbNames[0]);
+ Assert.assertEquals(2, hops.size());
+ boolean sawUser = false, sawRole = false;
+ for (HiveObjectPrivilege h : hops) {
+ if (h.getPrincipalName().equals(userNames[0])) {
+ Assert.assertEquals(PrincipalType.USER, h.getPrincipalType());
+ Assert.assertEquals(HiveObjectType.DATABASE, h.getHiveObject().getObjectType());
+ Assert.assertEquals("read", h.getGrantInfo().getPrivilege());
+ sawUser = true;
+ } else if (h.getPrincipalName().equals(roleNames[0])) {
+ Assert.assertEquals(PrincipalType.ROLE, h.getPrincipalType());
+ Assert.assertEquals(HiveObjectType.DATABASE, h.getHiveObject().getObjectType());
+ Assert.assertEquals("write", h.getGrantInfo().getPrivilege());
+ sawRole = true;
+ }
+ }
+ Assert.assertTrue(sawUser && sawRole);
+ hops = store.listPrincipalDBGrantsAll(roleNames[0], PrincipalType.ROLE);
+ Assert.assertEquals(1, hops.size());
+ Assert.assertEquals(PrincipalType.ROLE, hops.get(0).getPrincipalType());
+ Assert.assertEquals(HiveObjectType.DATABASE, hops.get(0).getHiveObject().getObjectType());
+ Assert.assertEquals("write", hops.get(0).getGrantInfo().getPrivilege());
+
+ hops = store.listPrincipalDBGrantsAll(userNames[0], PrincipalType.USER);
+ Assert.assertEquals(1, hops.size());
+ Assert.assertEquals(PrincipalType.USER, hops.get(0).getPrincipalType());
+ Assert.assertEquals(HiveObjectType.DATABASE, hops.get(0).getHiveObject().getObjectType());
+ Assert.assertEquals("read", hops.get(0).getGrantInfo().getPrivilege());
+
+ hops = store.listPrincipalDBGrantsAll(roleNames[1], PrincipalType.ROLE);
+ Assert.assertEquals(0, hops.size());
+ hops = store.listPrincipalDBGrantsAll(userNames[1], PrincipalType.USER);
+ Assert.assertEquals(0, hops.size());
+
+ } finally {
+ store.dropDatabase(dbNames[0]);
+ store.dropDatabase(dbNames[1]);
+ }
+ }
+
+ @Test
+ public void listGlobalGrants() throws Exception {
+ String[] roleNames = new String[]{"lgg_role1", "lgg_role2"};
+ String[] userNames = new String[]{"merry", "pippen"};
+
+ store.addRole(roleNames[0], "me");
+ store.addRole(roleNames[1], "me");
+ int now = (int)(System.currentTimeMillis() / 1000);
+
+ Role role1 = store.getRole(roleNames[0]);
+ Role role2 = store.getRole(roleNames[1]);
+ store.grantRole(role1, userNames[0], PrincipalType.USER, "bob", PrincipalType.USER, false);
+ store.grantRole(role1, roleNames[1], PrincipalType.ROLE, "admin", PrincipalType.ROLE, true);
+ store.grantRole(role2, userNames[1], PrincipalType.USER, "bob", PrincipalType.USER, false);
+
+ List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
+ HiveObjectRef hiveObjRef =
+ new HiveObjectRef(HiveObjectType.GLOBAL, null, null, null, null);
+ PrivilegeGrantInfo grantInfo =
+ new PrivilegeGrantInfo("read", now, "me", PrincipalType.USER, false);
+ HiveObjectPrivilege hop = new HiveObjectPrivilege(hiveObjRef, userNames[0], PrincipalType.USER,
+ grantInfo);
+ privileges.add(hop);
+
+ grantInfo = new PrivilegeGrantInfo("write", now, "me", PrincipalType.USER, true);
+ hop = new HiveObjectPrivilege(hiveObjRef, roleNames[0], PrincipalType.ROLE, grantInfo);
+ privileges.add(hop);
+
+ PrivilegeBag pBag = new PrivilegeBag(privileges);
+ store.grantPrivileges(pBag);
+
+ List<HiveObjectPrivilege> hops =
+ store.listPrincipalGlobalGrants(roleNames[0], PrincipalType.ROLE);
+ Assert.assertEquals(1, hops.size());
+ Assert.assertEquals(PrincipalType.ROLE, hops.get(0).getPrincipalType());
+ Assert.assertEquals(HiveObjectType.GLOBAL, hops.get(0).getHiveObject().getObjectType());
+ Assert.assertEquals("write", hops.get(0).getGrantInfo().getPrivilege());
+
+ hops = store.listPrincipalGlobalGrants(userNames[0], PrincipalType.USER);
+ Assert.assertEquals(1, hops.size());
+ Assert.assertEquals(PrincipalType.USER, hops.get(0).getPrincipalType());
+ Assert.assertEquals(HiveObjectType.GLOBAL, hops.get(0).getHiveObject().getObjectType());
+ Assert.assertEquals("read", hops.get(0).getGrantInfo().getPrivilege());
+
+ hops = store.listPrincipalGlobalGrants(roleNames[1], PrincipalType.ROLE);
+ Assert.assertEquals(0, hops.size());
+ hops = store.listPrincipalGlobalGrants(userNames[1], PrincipalType.USER);
+ Assert.assertEquals(0, hops.size());
+
+ hops = store.listGlobalGrantsAll();
+ Assert.assertEquals(2, hops.size());
+ boolean sawUser = false, sawRole = false;
+ for (HiveObjectPrivilege h : hops) {
+ if (h.getPrincipalName().equals(userNames[0])) {
+ Assert.assertEquals(PrincipalType.USER, h.getPrincipalType());
+ Assert.assertEquals(HiveObjectType.GLOBAL, h.getHiveObject().getObjectType());
+ Assert.assertEquals("read", h.getGrantInfo().getPrivilege());
+ sawUser = true;
+ } else if (h.getPrincipalName().equals(roleNames[0])) {
+ Assert.assertEquals(PrincipalType.ROLE, h.getPrincipalType());
+ Assert.assertEquals(HiveObjectType.GLOBAL, h.getHiveObject().getObjectType());
+ Assert.assertEquals("write", h.getGrantInfo().getPrivilege());
+ sawRole = true;
+ }
+ }
+ Assert.assertTrue(sawUser && sawRole);
+ }
+
+ @Test
+ public void listTableGrants() throws Exception {
+ String dbName = "ltg_db";
+ String[] tableNames = new String[] {"ltg_t1", "ltg_t2"};
+ try {
+ Database db = new Database(dbName, "no description", "file:///tmp", emptyParameters);
+ store.createDatabase(db);
+ int startTime = (int)(System.currentTimeMillis() / 1000);
+ List<FieldSchema> cols = new ArrayList<FieldSchema>();
+ cols.add(new FieldSchema("col1", "int", "nocomment"));
+ SerDeInfo serde = new SerDeInfo("serde", "seriallib", null);
+ StorageDescriptor sd = new StorageDescriptor(cols, "file:/tmp", "input", "output", false, 0,
+ serde, null, null, emptyParameters);
+ Table table = new Table(tableNames[0], dbName, "me", startTime, startTime, 0, sd, null,
+ emptyParameters, null, null, null);
+ store.createTable(table);
+ table = new Table(tableNames[1], dbName, "me", startTime, startTime, 0, sd, null,
+ emptyParameters, null, null, null);
+ store.createTable(table);
+ String[] roleNames = new String[]{"ltg_role1", "ltg_role2"};
+ String[] userNames = new String[]{"gandalf", "radagast"};
+
+ store.addRole(roleNames[0], "me");
+ store.addRole(roleNames[1], "me");
+ int now = (int)(System.currentTimeMillis() / 1000);
+
+ Role role1 = store.getRole(roleNames[0]);
+ Role role2 = store.getRole(roleNames[1]);
+ store.grantRole(role1, userNames[0], PrincipalType.USER, "bob", PrincipalType.USER, false);
+ store.grantRole(role1, roleNames[1], PrincipalType.ROLE, "admin", PrincipalType.ROLE, true);
+ store.grantRole(role2, userNames[1], PrincipalType.USER, "bob", PrincipalType.USER, false);
+
+ List<HiveObjectPrivilege> privileges = new ArrayList<HiveObjectPrivilege>();
+ HiveObjectRef hiveObjRef =
+ new HiveObjectRef(HiveObjectType.TABLE, dbName, tableNames[0], null, null);
+ PrivilegeGrantInfo grantInfo =
+ new PrivilegeGrantInfo("read", now, "me", PrincipalType.USER, false);
+ HiveObjectPrivilege hop = new HiveObjectPrivilege(hiveObjRef, userNames[0], PrincipalType.USER,
+ grantInfo);
+ privileges.add(hop);
+
+ grantInfo = new PrivilegeGrantInfo("write", now, "me", PrincipalType.USER, true);
+ hop = new HiveObjectPrivilege(hiveObjRef, roleNames[0], PrincipalType.ROLE, grantInfo);
+ privileges.add(hop);
+
+ PrivilegeBag pBag = new PrivilegeBag(privileges);
+ store.grantPrivileges(pBag);
+
+ List<HiveObjectPrivilege> hops =
+ store.listAllTableGrants(roleNames[0], PrincipalType.ROLE, dbName, tableNames[0]);
+ Assert.assertEquals(1, hops.size());
+ Assert.assertEquals(PrincipalType.ROLE, hops.get(0).getPrincipalType());
+ Assert.assertEquals(HiveObjectType.TABLE, hops.get(0).getHiveObject().getObjectType());
+ Assert.assertEquals("write", hops.get(0).getGrantInfo().getPrivilege());
+
+ hops = store.listAllTableGrants(userNames[0], PrincipalType.USER, dbName, tableNames[0]);
+ Assert.assertEquals(1, hops.size());
+ Assert.assertEquals(PrincipalType.USER, hops.get(0).getPrincipalType());
+ Assert.assertEquals(HiveObjectType.TABLE, hops.get(0).getHiveObject().getObjectType());
+ Assert.assertEquals("read", hops.get(0).getGrantInfo().getPrivilege());
+
+ hops = store.listAllTableGrants(roleNames[1], PrincipalType.ROLE, dbName, tableNames[0]);
+ Assert.assertEquals(0, hops.size());
+ hops = store.listAllTableGrants(userNames[1], PrincipalType.USER, dbName, tableNames[0]);
+ Assert.assertEquals(0, hops.size());
+
+ hops = store.listAllTableGrants(roleNames[0], PrincipalType.ROLE, dbName, tableNames[1]);
+ Assert.assertEquals(0, hops.size());
+ hops = store.listAllTableGrants(userNames[0], PrincipalType.USER, dbName, tableNames[1]);
+ Assert.assertEquals(0, hops.size());
+
+ hops = store.listTableGrantsAll(dbName, tableNames[0]);
+ Assert.assertEquals(2, hops.size());
+ boolean sawUser = false, sawRole = false;
+ for (HiveObjectPrivilege h : hops) {
+ if (h.getPrincipalName().equals(userNames[0])) {
+ Assert.assertEquals(PrincipalType.USER, h.getPrincipalType());
+ Assert.assertEquals(HiveObjectType.TABLE, h.getHiveObject().getObjectType());
+ Assert.assertEquals("read", h.getGrantInfo().getPrivilege());
+ sawUser = true;
+ } else if (h.getPrincipalName().equals(roleNames[0])) {
+ Assert.assertEquals(PrincipalType.ROLE, h.getPrincipalType());
+ Assert.assertEquals(HiveObjectType.TABLE, h.getHiveObject().getObjectType());
+ Assert.assertEquals("write", h.getGrantInfo().getPrivilege());
+ sawRole = true;
+ }
+ }
+ Assert.assertTrue(sawUser && sawRole);
+
+ hops = store.listPrincipalTableGrantsAll(roleNames[0], PrincipalType.ROLE);
+ Assert.assertEquals(1, hops.size());
+ Assert.assertEquals(PrincipalType.ROLE, hops.get(0).getPrincipalType());
+ Assert.assertEquals(HiveObjectType.TABLE, hops.get(0).getHiveObject().getObjectType());
+ Assert.assertEquals("write", hops.get(0).getGrantInfo().getPrivilege());
+
+ hops = store.listPrincipalTableGrantsAll(userNames[0], PrincipalType.USER);
+ Assert.assertEquals(1, hops.size());
+ Assert.assertEquals(PrincipalType.USER, hops.get(0).getPrincipalType());
+ Assert.assertEquals(HiveObjectType.TABLE, hops.get(0).getHiveObject().getObjectType());
+ Assert.assertEquals("read", hops.get(0).getGrantInfo().getPrivilege());
+
+ hops = store.listPrincipalDBGrantsAll(roleNames[1], PrincipalType.ROLE);
+ Assert.assertEquals(0, hops.size());
+ hops = store.listPrincipalDBGrantsAll(userNames[1], PrincipalType.USER);
+ Assert.assertEquals(0, hops.size());
+
+
+ } finally {
+ store.dropTable(dbName, tableNames[0]);
+ store.dropTable(dbName, tableNames[1]);
+ store.dropDatabase(dbName);
+ }
}
@Test
Modified: hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java?rev=1664226&r1=1664225&r2=1664226&view=diff
==============================================================================
--- hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java (original)
+++ hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java Thu Mar 5 04:09:31 2015
@@ -2817,8 +2817,8 @@ public class HiveMetaStore extends Thrif
* Fire a pre-event for read table operation, if there are any
* pre-event listeners registered
*
- * @param db_name
- * @param tbl_name
+ * @param dbName
+ * @param tblName
* @throws MetaException
* @throws NoSuchObjectException
*/
@@ -4555,9 +4555,9 @@ public class HiveMetaStore extends Thrif
return true;
}
//do this check recursively on all the parent roles of curRole
- List<MRoleMap> parentRoleMaps = getMS().listRoles(curRole, PrincipalType.ROLE);
- for(MRoleMap parentRole : parentRoleMaps){
- if(isNewRoleAParent(newRole, parentRole.getRole().getRoleName())){
+ List<Role> parentRoleMaps = getMS().listRoles(curRole, PrincipalType.ROLE);
+ for(Role parentRole : parentRoleMaps){
+ if(isNewRoleAParent(newRole, parentRole.getRoleName())){
return true;
}
}
@@ -4569,26 +4569,9 @@ public class HiveMetaStore extends Thrif
final PrincipalType principalType) throws MetaException, TException {
incrementCounter("list_roles");
firePreEvent(new PreAuthorizationCallEvent(this));
- List<Role> result = new ArrayList<Role>();
- try {
- List<MRoleMap> roleMaps = getMS().listRoles(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;
- } catch (MetaException e) {
- throw e;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
+ return getMS().listRoles(principalName, principalType);
}
-
-
@Override
public boolean create_role(final Role role)
throws MetaException, TException {
@@ -4836,25 +4819,9 @@ public class HiveMetaStore extends Thrif
if (principalName == null) {
return getMS().listTableColumnGrantsAll(dbName, tableName, columnName);
}
- List<MTableColumnPrivilege> mTableCols = getMS()
+ List<HiveObjectPrivilege> result = getMS()
.listPrincipalTableColumnGrants(principalName, principalType,
dbName, tableName, columnName);
- if (mTableCols.isEmpty()) {
- return Collections.emptyList();
- }
- List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
- for (int i = 0; i < mTableCols.size(); i++) {
- MTableColumnPrivilege sCol = mTableCols.get(i);
- HiveObjectRef objectRef = new HiveObjectRef(
- HiveObjectType.COLUMN, dbName, tableName, null, sCol.getColumnName());
- HiveObjectPrivilege secObj = new HiveObjectPrivilege(
- objectRef, sCol.getPrincipalName(), principalType,
- new PrivilegeGrantInfo(sCol.getPrivilege(), sCol
- .getCreateTime(), sCol.getGrantor(), PrincipalType
- .valueOf(sCol.getGrantorType()), sCol
- .getGrantOption()));
- result.add(secObj);
- }
return result;
} catch (MetaException e) {
throw e;
@@ -4878,24 +4845,11 @@ public class HiveMetaStore extends Thrif
if (principalName == null) {
return getMS().listPartitionColumnGrantsAll(dbName, tableName, partName, columnName);
}
- List<MPartitionColumnPrivilege> mPartitionCols = getMS().listPrincipalPartitionColumnGrants(
- principalName,
- principalType, dbName, tableName, partName, columnName);
- if (mPartitionCols.isEmpty()) {
- return Collections.emptyList();
- }
- List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
- for (int i = 0; i < mPartitionCols.size(); i++) {
- MPartitionColumnPrivilege sCol = mPartitionCols.get(i);
- HiveObjectRef objectRef = new HiveObjectRef(
- HiveObjectType.COLUMN, dbName, tableName, partValues, sCol.getColumnName());
- HiveObjectPrivilege secObj = new HiveObjectPrivilege(objectRef,
- sCol.getPrincipalName(), principalType,
- new PrivilegeGrantInfo(sCol.getPrivilege(), sCol
- .getCreateTime(), sCol.getGrantor(), PrincipalType
- .valueOf(sCol.getGrantorType()), sCol.getGrantOption()));
- result.add(secObj);
- }
+
+ List<HiveObjectPrivilege> result =
+ getMS().listPrincipalPartitionColumnGrants(principalName, principalType, dbName,
+ tableName, partValues, partName, columnName);
+
return result;
} catch (MetaException e) {
throw e;
@@ -4915,25 +4869,9 @@ public class HiveMetaStore extends Thrif
}
if (principalName == null) {
return getMS().listDBGrantsAll(dbName);
+ } else {
+ return getMS().listPrincipalDBGrants(principalName, principalType, dbName);
}
- List<MDBPrivilege> mDbs = getMS().listPrincipalDBGrants(
- principalName, principalType, dbName);
- if (mDbs.isEmpty()) {
- return Collections.<HiveObjectPrivilege>emptyList();
- }
- List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
- for (int i = 0; i < mDbs.size(); i++) {
- MDBPrivilege sDB = mDbs.get(i);
- HiveObjectRef objectRef = new HiveObjectRef(
- HiveObjectType.DATABASE, dbName, null, null, null);
- HiveObjectPrivilege secObj = new HiveObjectPrivilege(objectRef,
- sDB.getPrincipalName(), principalType,
- new PrivilegeGrantInfo(sDB.getPrivilege(), sDB
- .getCreateTime(), sDB.getGrantor(), PrincipalType
- .valueOf(sDB.getGrantorType()), sDB.getGrantOption()));
- result.add(secObj);
- }
- return result;
} catch (MetaException e) {
throw e;
} catch (Exception e) {
@@ -4956,25 +4894,9 @@ public class HiveMetaStore extends Thrif
if (principalName == null) {
return getMS().listPartitionGrantsAll(dbName, tableName, partName);
}
- List<MPartitionPrivilege> mParts = getMS().listPrincipalPartitionGrants(
- principalName, principalType, dbName, tableName, partName);
- if (mParts.isEmpty()) {
- return Collections.<HiveObjectPrivilege> emptyList();
- }
- List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
- for (int i = 0; i < mParts.size(); i++) {
- MPartitionPrivilege sPart = mParts.get(i);
- HiveObjectRef objectRef = new HiveObjectRef(
- HiveObjectType.PARTITION, dbName, tableName, partValues, null);
- HiveObjectPrivilege secObj = new HiveObjectPrivilege(objectRef,
- sPart.getPrincipalName(), principalType,
- new PrivilegeGrantInfo(sPart.getPrivilege(), sPart
- .getCreateTime(), sPart.getGrantor(), PrincipalType
- .valueOf(sPart.getGrantorType()), sPart
- .getGrantOption()));
+ List<HiveObjectPrivilege> result = getMS().listPrincipalPartitionGrants(
+ principalName, principalType, dbName, tableName, partValues, partName);
- result.add(secObj);
- }
return result;
} catch (MetaException e) {
throw e;
@@ -4996,23 +4918,9 @@ public class HiveMetaStore extends Thrif
if (principalName == null) {
return getMS().listTableGrantsAll(dbName, tableName);
}
- List<MTablePrivilege> mTbls = getMS()
+ List<HiveObjectPrivilege> result = getMS()
.listAllTableGrants(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;
} catch (MetaException e) {
throw e;
@@ -5030,23 +4938,9 @@ public class HiveMetaStore extends Thrif
if (principalName == null) {
return getMS().listGlobalGrantsAll();
}
- List<MGlobalPrivilege> mUsers = getMS().listPrincipalGlobalGrants(
+ List<HiveObjectPrivilege> result = getMS().listPrincipalGlobalGrants(
principalName, principalType);
- if (mUsers.isEmpty()) {
- return Collections.<HiveObjectPrivilege> emptyList();
- }
- List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
- for (int i = 0; i < mUsers.size(); i++) {
- MGlobalPrivilege sUsr = mUsers.get(i);
- HiveObjectRef objectRef = new HiveObjectRef(
- HiveObjectType.GLOBAL, null, null, null, null);
- HiveObjectPrivilege secUser = new HiveObjectPrivilege(
- objectRef, sUsr.getPrincipalName(), principalType,
- new PrivilegeGrantInfo(sUsr.getPrivilege(), sUsr
- .getCreateTime(), sUsr.getGrantor(), PrincipalType
- .valueOf(sUsr.getGrantorType()), sUsr.getGrantOption()));
- result.add(secUser);
- }
+
return result;
} catch (MetaException e) {
throw e;
@@ -5472,9 +5366,9 @@ public class HiveMetaStore extends Thrif
incrementCounter("get_principals_in_role");
firePreEvent(new PreAuthorizationCallEvent(this));
Exception ex = null;
- List<MRoleMap> roleMaps = null;
+ GetPrincipalsInRoleResponse response = null;
try {
- roleMaps = getMS().listRoleMembers(request.getRoleName());
+ response = new GetPrincipalsInRoleResponse(getMS().listRoleMembers(request.getRoleName()));
} catch (MetaException e) {
throw e;
} catch (Exception e) {
@@ -5483,7 +5377,7 @@ public class HiveMetaStore extends Thrif
} finally {
endFunction("get_principals_in_role", ex == null, ex);
}
- return new GetPrincipalsInRoleResponse(getRolePrincipalGrants(roleMaps));
+ return response;
}
@Override
@@ -5493,9 +5387,9 @@ public class HiveMetaStore extends Thrif
incrementCounter("get_role_grants_for_principal");
firePreEvent(new PreAuthorizationCallEvent(this));
Exception ex = null;
- List<MRoleMap> roleMaps = null;
+ List<RolePrincipalGrant> roleMaps = null;
try {
- roleMaps = getMS().listRoles(request.getPrincipal_name(), request.getPrincipal_type());
+ roleMaps = getMS().listRolesWithGrants(request.getPrincipal_name(), request.getPrincipal_type());
} catch (MetaException e) {
throw e;
} catch (Exception e) {
@@ -5505,31 +5399,20 @@ public class HiveMetaStore extends Thrif
endFunction("get_role_grants_for_principal", ex == null, ex);
}
- List<RolePrincipalGrant> roleGrantsList = getRolePrincipalGrants(roleMaps);
- return new GetRoleGrantsForPrincipalResponse(roleGrantsList);
+ //List<RolePrincipalGrant> roleGrantsList = getRolePrincipalGrants(roleMaps);
+ return new GetRoleGrantsForPrincipalResponse(roleMaps);
}
/**
* Convert each MRoleMap object into a thrift RolePrincipalGrant object
- * @param roleMaps
+ * @param roles
* @return
*/
- private List<RolePrincipalGrant> getRolePrincipalGrants(List<MRoleMap> roleMaps) {
+ private List<RolePrincipalGrant> getRolePrincipalGrants(List<Role> roles) throws MetaException {
List<RolePrincipalGrant> rolePrinGrantList = new ArrayList<RolePrincipalGrant>();
- if (roleMaps != null) {
- for (MRoleMap roleMap : roleMaps) {
- RolePrincipalGrant rolePrinGrant = new RolePrincipalGrant(
- roleMap.getRole().getRoleName(),
- roleMap.getPrincipalName(),
- PrincipalType.valueOf(roleMap.getPrincipalType()),
- roleMap.getGrantOption(),
- roleMap.getAddTime(),
- roleMap.getGrantor(),
- // no grantor type for public role, hence the null check
- roleMap.getGrantorType() == null ? null
- : PrincipalType.valueOf(roleMap.getGrantorType())
- );
- rolePrinGrantList.add(rolePrinGrant);
+ if (roles != null) {
+ for (Role role : roles) {
+ rolePrinGrantList.addAll(getMS().listRoleMembers(role.getRoleName()));
}
}
return rolePrinGrantList;
Modified: hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java?rev=1664226&r1=1664225&r2=1664226&view=diff
==============================================================================
--- hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java (original)
+++ hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java Thu Mar 5 04:09:31 2015
@@ -94,6 +94,7 @@ import org.apache.hadoop.hive.metastore.
import org.apache.hadoop.hive.metastore.api.ResourceType;
import org.apache.hadoop.hive.metastore.api.ResourceUri;
import org.apache.hadoop.hive.metastore.api.Role;
+import org.apache.hadoop.hive.metastore.api.RolePrincipalGrant;
import org.apache.hadoop.hive.metastore.api.SerDeInfo;
import org.apache.hadoop.hive.metastore.api.SkewedInfo;
import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
@@ -3329,7 +3330,7 @@ public class ObjectStore implements RawS
if (mRol != null) {
// first remove all the membership, the membership that this role has
// been granted
- List<MRoleMap> roleMap = listRoleMembers(mRol.getRoleName());
+ List<MRoleMap> roleMap = listMRoleMembers(mRol.getRoleName());
if (roleMap.size() > 0) {
pm.deletePersistentAll(roleMap);
}
@@ -3339,7 +3340,7 @@ public class ObjectStore implements RawS
pm.deletePersistentAll(roleMember);
}
// then remove all the grants
- List<MGlobalPrivilege> userGrants = listPrincipalGlobalGrants(
+ List<MGlobalPrivilege> userGrants = listPrincipalMGlobalGrants(
mRol.getRoleName(), PrincipalType.ROLE);
if (userGrants.size() > 0) {
pm.deletePersistentAll(userGrants);
@@ -3391,11 +3392,11 @@ public class ObjectStore implements RawS
List<String> groupNames) {
List<MRoleMap> ret = new ArrayList<MRoleMap>();
if(userName != null) {
- ret.addAll(listRoles(userName, PrincipalType.USER));
+ ret.addAll(listMRoles(userName, PrincipalType.USER));
}
if (groupNames != null) {
for (String groupName: groupNames) {
- ret.addAll(listRoles(groupName, PrincipalType.GROUP));
+ ret.addAll(listMRoles(groupName, PrincipalType.GROUP));
}
}
// get names of these roles and its ancestors
@@ -3416,7 +3417,7 @@ public class ObjectStore implements RawS
if (!processedRoleNames.contains(parentRoleName)) {
// unprocessed role: get its parents, add it to processed, and call this
// function recursively
- List<MRoleMap> nextParentRoles = listRoles(parentRoleName, PrincipalType.ROLE);
+ List<MRoleMap> nextParentRoles = listMRoles(parentRoleName, PrincipalType.ROLE);
processedRoleNames.add(parentRoleName);
getAllRoleAncestors(processedRoleNames, nextParentRoles);
}
@@ -3424,8 +3425,7 @@ public class ObjectStore implements RawS
}
@SuppressWarnings("unchecked")
- @Override
- public List<MRoleMap> listRoles(String principalName,
+ public List<MRoleMap> listMRoles(String principalName,
PrincipalType principalType) {
boolean success = false;
List<MRoleMap> mRoleMember = null;
@@ -3466,6 +3466,44 @@ public class ObjectStore implements RawS
}
+ @Override
+ public List<Role> listRoles(String principalName, PrincipalType principalType) {
+ List<Role> result = new ArrayList<Role>();
+ 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;
+ }
+
+ @Override
+ public List<RolePrincipalGrant> listRolesWithGrants(String principalName,
+ PrincipalType principalType) {
+ List<RolePrincipalGrant> result = new ArrayList<RolePrincipalGrant>();
+ List<MRoleMap> roleMaps = listMRoles(principalName, principalType);
+ if (roleMaps != null) {
+ for (MRoleMap roleMap : roleMaps) {
+ RolePrincipalGrant rolePrinGrant = new RolePrincipalGrant(
+ roleMap.getRole().getRoleName(),
+ roleMap.getPrincipalName(),
+ PrincipalType.valueOf(roleMap.getPrincipalType()),
+ roleMap.getGrantOption(),
+ roleMap.getAddTime(),
+ roleMap.getGrantor(),
+ // no grantor type for public role, hence the null check
+ roleMap.getGrantorType() == null ? null
+ : PrincipalType.valueOf(roleMap.getGrantorType())
+ );
+ result.add(rolePrinGrant);
+ }
+ }
+ return result;
+ }
+
@SuppressWarnings("unchecked")
private List<MRoleMap> listMSecurityPrincipalMembershipRole(final String roleName,
final PrincipalType principalType) {
@@ -3553,7 +3591,7 @@ public class ObjectStore implements RawS
try {
openTransaction();
if (userName != null) {
- List<MGlobalPrivilege> user = this.listPrincipalGlobalGrants(userName, PrincipalType.USER);
+ List<MGlobalPrivilege> user = this.listPrincipalMGlobalGrants(userName, PrincipalType.USER);
if(user.size()>0) {
Map<String, List<PrivilegeGrantInfo>> userPriv = new HashMap<String, List<PrivilegeGrantInfo>>();
List<PrivilegeGrantInfo> grantInfos = new ArrayList<PrivilegeGrantInfo>(user.size());
@@ -3570,7 +3608,8 @@ public class ObjectStore implements RawS
if (groupNames != null && groupNames.size() > 0) {
Map<String, List<PrivilegeGrantInfo>> groupPriv = new HashMap<String, List<PrivilegeGrantInfo>>();
for(String groupName: groupNames) {
- List<MGlobalPrivilege> group = this.listPrincipalGlobalGrants(groupName, PrincipalType.GROUP);
+ List<MGlobalPrivilege> group =
+ this.listPrincipalMGlobalGrants(groupName, PrincipalType.GROUP);
if(group.size()>0) {
List<PrivilegeGrantInfo> grantInfos = new ArrayList<PrivilegeGrantInfo>(group.size());
for (int i = 0; i < group.size(); i++) {
@@ -3599,7 +3638,7 @@ public class ObjectStore implements RawS
dbName = HiveStringUtils.normalizeIdentifier(dbName);
if (principalName != null) {
- List<MDBPrivilege> userNameDbPriv = this.listPrincipalDBGrants(
+ List<MDBPrivilege> userNameDbPriv = this.listPrincipalMDBGrants(
principalName, principalType, dbName);
if (userNameDbPriv != null && userNameDbPriv.size() > 0) {
List<PrivilegeGrantInfo> grantInfos = new ArrayList<PrivilegeGrantInfo>(
@@ -3799,7 +3838,7 @@ public class ObjectStore implements RawS
if (principalName != null) {
List<MPartitionPrivilege> userNameTabPartPriv = this
- .listPrincipalPartitionGrants(principalName, principalType,
+ .listPrincipalMPartitionGrants(principalName, principalType,
dbName, tableName, partName);
if (userNameTabPartPriv != null && userNameTabPartPriv.size() > 0) {
List<PrivilegeGrantInfo> grantInfos = new ArrayList<PrivilegeGrantInfo>(
@@ -3828,7 +3867,7 @@ public class ObjectStore implements RawS
if (principalName != null) {
List<MTablePrivilege> userNameTabPartPriv = this
- .listAllTableGrants(principalName, principalType,
+ .listAllMTableGrants(principalName, principalType,
dbName, tableName);
if (userNameTabPartPriv != null && userNameTabPartPriv.size() > 0) {
List<PrivilegeGrantInfo> grantInfos = new ArrayList<PrivilegeGrantInfo>(
@@ -3855,7 +3894,7 @@ public class ObjectStore implements RawS
if (partitionName == null) {
List<MTableColumnPrivilege> userNameColumnPriv = this
- .listPrincipalTableColumnGrants(principalName, principalType,
+ .listPrincipalMTableColumnGrants(principalName, principalType,
dbName, tableName, columnName);
if (userNameColumnPriv != null && userNameColumnPriv.size() > 0) {
List<PrivilegeGrantInfo> grantInfos = new ArrayList<PrivilegeGrantInfo>(
@@ -3870,7 +3909,7 @@ public class ObjectStore implements RawS
}
} else {
List<MPartitionColumnPrivilege> userNameColumnPriv = this
- .listPrincipalPartitionColumnGrants(principalName,
+ .listPrincipalMPartitionColumnGrants(principalName,
principalType, dbName, tableName, partitionName, columnName);
if (userNameColumnPriv != null && userNameColumnPriv.size() > 0) {
List<PrivilegeGrantInfo> grantInfos = new ArrayList<PrivilegeGrantInfo>(
@@ -3919,7 +3958,7 @@ public class ObjectStore implements RawS
if (hiveObject.getObjectType() == HiveObjectType.GLOBAL) {
List<MGlobalPrivilege> globalPrivs = this
- .listPrincipalGlobalGrants(userName, principalType);
+ .listPrincipalMGlobalGrants(userName, principalType);
if (globalPrivs != null) {
for (MGlobalPrivilege priv : globalPrivs) {
if (priv.getGrantor().equalsIgnoreCase(grantor)) {
@@ -3939,7 +3978,7 @@ public class ObjectStore implements RawS
} else if (hiveObject.getObjectType() == HiveObjectType.DATABASE) {
MDatabase dbObj = getMDatabase(hiveObject.getDbName());
if (dbObj != null) {
- List<MDBPrivilege> dbPrivs = this.listPrincipalDBGrants(
+ List<MDBPrivilege> dbPrivs = this.listPrincipalMDBGrants(
userName, principalType, hiveObject.getDbName());
if (dbPrivs != null) {
for (MDBPrivilege priv : dbPrivs) {
@@ -3964,7 +4003,7 @@ public class ObjectStore implements RawS
.getObjectName());
if (tblObj != null) {
List<MTablePrivilege> tablePrivs = this
- .listAllTableGrants(userName, principalType,
+ .listAllMTableGrants(userName, principalType,
hiveObject.getDbName(), hiveObject.getObjectName());
if (tablePrivs != null) {
for (MTablePrivilege priv : tablePrivs) {
@@ -3994,7 +4033,7 @@ public class ObjectStore implements RawS
if (partObj != null) {
partName = partObj.getPartitionName();
List<MPartitionPrivilege> partPrivs = this
- .listPrincipalPartitionGrants(userName,
+ .listPrincipalMPartitionGrants(userName,
principalType, hiveObject.getDbName(), hiveObject
.getObjectName(), partObj.getPartitionName());
if (partPrivs != null) {
@@ -4030,7 +4069,7 @@ public class ObjectStore implements RawS
if (partObj == null) {
continue;
}
- colPrivs = this.listPrincipalPartitionColumnGrants(
+ colPrivs = this.listPrincipalMPartitionColumnGrants(
userName, principalType, hiveObject.getDbName(), hiveObject
.getObjectName(), partObj.getPartitionName(),
hiveObject.getColumnName());
@@ -4060,7 +4099,7 @@ public class ObjectStore implements RawS
} else {
List<MTableColumnPrivilege> colPrivs = null;
- colPrivs = this.listPrincipalTableColumnGrants(
+ colPrivs = this.listPrincipalMTableColumnGrants(
userName, principalType, hiveObject.getDbName(), hiveObject
.getObjectName(), hiveObject.getColumnName());
@@ -4128,7 +4167,7 @@ public class ObjectStore implements RawS
PrincipalType principalType = privDef.getPrincipalType();
if (hiveObject.getObjectType() == HiveObjectType.GLOBAL) {
- List<MGlobalPrivilege> mSecUser = this.listPrincipalGlobalGrants(
+ List<MGlobalPrivilege> mSecUser = this.listPrincipalMGlobalGrants(
userName, principalType);
boolean found = false;
if (mSecUser != null) {
@@ -4161,7 +4200,7 @@ public class ObjectStore implements RawS
if (dbObj != null) {
String db = hiveObject.getDbName();
boolean found = false;
- List<MDBPrivilege> dbGrants = this.listPrincipalDBGrants(
+ List<MDBPrivilege> dbGrants = this.listPrincipalMDBGrants(
userName, principalType, db);
for (String privilege : privs) {
for (MDBPrivilege dbGrant : dbGrants) {
@@ -4190,7 +4229,7 @@ public class ObjectStore implements RawS
} else if (hiveObject.getObjectType() == HiveObjectType.TABLE) {
boolean found = false;
List<MTablePrivilege> tableGrants = this
- .listAllTableGrants(userName, principalType,
+ .listAllMTableGrants(userName, principalType,
hiveObject.getDbName(), hiveObject.getObjectName());
for (String privilege : privs) {
for (MTablePrivilege tabGrant : tableGrants) {
@@ -4224,7 +4263,7 @@ public class ObjectStore implements RawS
partName = Warehouse.makePartName(tabObj.getPartitionKeys(), hiveObject.getPartValues());
}
List<MPartitionPrivilege> partitionGrants = this
- .listPrincipalPartitionGrants(userName, principalType,
+ .listPrincipalMPartitionGrants(userName, principalType,
hiveObject.getDbName(), hiveObject.getObjectName(), partName);
for (String privilege : privs) {
for (MPartitionPrivilege partGrant : partitionGrants) {
@@ -4260,7 +4299,7 @@ public class ObjectStore implements RawS
}
if (partName != null) {
- List<MPartitionColumnPrivilege> mSecCol = listPrincipalPartitionColumnGrants(
+ List<MPartitionColumnPrivilege> mSecCol = listPrincipalMPartitionColumnGrants(
userName, principalType, hiveObject.getDbName(), hiveObject
.getObjectName(), partName, hiveObject.getColumnName());
boolean found = false;
@@ -4292,7 +4331,7 @@ public class ObjectStore implements RawS
}
}
} else {
- List<MTableColumnPrivilege> mSecCol = listPrincipalTableColumnGrants(
+ List<MTableColumnPrivilege> mSecCol = listPrincipalMTableColumnGrants(
userName, principalType, hiveObject.getDbName(), hiveObject
.getObjectName(), hiveObject.getColumnName());
boolean found = false;
@@ -4347,8 +4386,7 @@ public class ObjectStore implements RawS
}
@SuppressWarnings("unchecked")
- @Override
- public List<MRoleMap> listRoleMembers(String roleName) {
+ public List<MRoleMap> listMRoleMembers(String roleName) {
boolean success = false;
List<MRoleMap> mRoleMemeberList = null;
try {
@@ -4372,9 +4410,34 @@ public class ObjectStore implements RawS
return mRoleMemeberList;
}
- @SuppressWarnings("unchecked")
@Override
- public List<MGlobalPrivilege> listPrincipalGlobalGrants(String principalName, PrincipalType principalType) {
+ public List<RolePrincipalGrant> listRoleMembers(String roleName) {
+ List<MRoleMap> roleMaps = listMRoleMembers(roleName);
+ List<RolePrincipalGrant> rolePrinGrantList = new ArrayList<RolePrincipalGrant>();
+
+ if (roleMaps != null) {
+ for (MRoleMap roleMap : roleMaps) {
+ RolePrincipalGrant rolePrinGrant = new RolePrincipalGrant(
+ roleMap.getRole().getRoleName(),
+ roleMap.getPrincipalName(),
+ PrincipalType.valueOf(roleMap.getPrincipalType()),
+ roleMap.getGrantOption(),
+ roleMap.getAddTime(),
+ roleMap.getGrantor(),
+ // no grantor type for public role, hence the null check
+ roleMap.getGrantorType() == null ? null
+ : PrincipalType.valueOf(roleMap.getGrantorType())
+ );
+ rolePrinGrantList.add(rolePrinGrant);
+
+ }
+ }
+ return rolePrinGrantList;
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<MGlobalPrivilege> listPrincipalMGlobalGrants(String principalName,
+ PrincipalType principalType) {
boolean commited = false;
List<MGlobalPrivilege> userNameDbPriv = null;
try {
@@ -4398,6 +4461,29 @@ public class ObjectStore implements RawS
}
@Override
+ public List<HiveObjectPrivilege> listPrincipalGlobalGrants(String principalName,
+ PrincipalType principalType) {
+ List<MGlobalPrivilege> mUsers =
+ listPrincipalMGlobalGrants(principalName, principalType);
+ if (mUsers.isEmpty()) {
+ return Collections.<HiveObjectPrivilege> emptyList();
+ }
+ List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
+ for (int i = 0; i < mUsers.size(); i++) {
+ MGlobalPrivilege sUsr = mUsers.get(i);
+ HiveObjectRef objectRef = new HiveObjectRef(
+ HiveObjectType.GLOBAL, null, null, null, null);
+ HiveObjectPrivilege secUser = new HiveObjectPrivilege(
+ objectRef, sUsr.getPrincipalName(), principalType,
+ new PrivilegeGrantInfo(sUsr.getPrivilege(), sUsr
+ .getCreateTime(), sUsr.getGrantor(), PrincipalType
+ .valueOf(sUsr.getGrantorType()), sUsr.getGrantOption()));
+ result.add(secUser);
+ }
+ return result;
+ }
+
+ @Override
public List<HiveObjectPrivilege> listGlobalGrantsAll() {
boolean commited = false;
try {
@@ -4430,8 +4516,7 @@ public class ObjectStore implements RawS
}
@SuppressWarnings("unchecked")
- @Override
- public List<MDBPrivilege> listPrincipalDBGrants(String principalName,
+ public List<MDBPrivilege> listPrincipalMDBGrants(String principalName,
PrincipalType principalType, String dbName) {
boolean success = false;
List<MDBPrivilege> mSecurityDBList = null;
@@ -4458,6 +4543,29 @@ public class ObjectStore implements RawS
}
@Override
+ public List<HiveObjectPrivilege> listPrincipalDBGrants(String principalName,
+ PrincipalType principalType,
+ String dbName) {
+ List<MDBPrivilege> mDbs = listPrincipalMDBGrants(principalName, principalType, dbName);
+ if (mDbs.isEmpty()) {
+ return Collections.<HiveObjectPrivilege>emptyList();
+ }
+ List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
+ for (int i = 0; i < mDbs.size(); i++) {
+ MDBPrivilege sDB = mDbs.get(i);
+ HiveObjectRef objectRef = new HiveObjectRef(
+ HiveObjectType.DATABASE, dbName, null, null, null);
+ HiveObjectPrivilege secObj = new HiveObjectPrivilege(objectRef,
+ sDB.getPrincipalName(), principalType,
+ new PrivilegeGrantInfo(sDB.getPrivilege(), sDB
+ .getCreateTime(), sDB.getGrantor(), PrincipalType
+ .valueOf(sDB.getGrantorType()), sDB.getGrantOption()));
+ result.add(secObj);
+ }
+ return result;
+ }
+
+ @Override
public List<HiveObjectPrivilege> listPrincipalDBGrantsAll(
String principalName, PrincipalType principalType) {
return convertDB(listPrincipalAllDBGrant(principalName, principalType));
@@ -4754,9 +4862,8 @@ public class ObjectStore implements RawS
return new ObjectPair<Query, Object[]>(query, params);
}
- @Override
@SuppressWarnings("unchecked")
- public List<MTablePrivilege> listAllTableGrants(
+ public List<MTablePrivilege> listAllMTableGrants(
String principalName, PrincipalType principalType, String dbName,
String tableName) {
tableName = HiveStringUtils.normalizeIdentifier(tableName);
@@ -4787,9 +4894,33 @@ public class ObjectStore implements RawS
return mSecurityTabPartList;
}
- @SuppressWarnings("unchecked")
@Override
- public List<MPartitionPrivilege> listPrincipalPartitionGrants(
+ 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;
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<MPartitionPrivilege> listPrincipalMPartitionGrants(
String principalName, PrincipalType principalType, String dbName,
String tableName, String partName) {
boolean success = false;
@@ -4822,9 +4953,37 @@ public class ObjectStore implements RawS
return mSecurityTabPartList;
}
- @SuppressWarnings("unchecked")
@Override
- public List<MTableColumnPrivilege> listPrincipalTableColumnGrants(
+ public List<HiveObjectPrivilege> listPrincipalPartitionGrants(String principalName,
+ PrincipalType principalType,
+ String dbName,
+ String tableName,
+ List<String> partValues,
+ String partName) {
+ List<MPartitionPrivilege> mParts = listPrincipalMPartitionGrants(principalName,
+ principalType, dbName, tableName, partName);
+ if (mParts.isEmpty()) {
+ return Collections.<HiveObjectPrivilege> emptyList();
+ }
+ List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
+ for (int i = 0; i < mParts.size(); i++) {
+ MPartitionPrivilege sPart = mParts.get(i);
+ HiveObjectRef objectRef = new HiveObjectRef(
+ HiveObjectType.PARTITION, dbName, tableName, partValues, null);
+ HiveObjectPrivilege secObj = new HiveObjectPrivilege(objectRef,
+ sPart.getPrincipalName(), principalType,
+ new PrivilegeGrantInfo(sPart.getPrivilege(), sPart
+ .getCreateTime(), sPart.getGrantor(), PrincipalType
+ .valueOf(sPart.getGrantorType()), sPart
+ .getGrantOption()));
+
+ result.add(secObj);
+ }
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<MTableColumnPrivilege> listPrincipalMTableColumnGrants(
String principalName, PrincipalType principalType, String dbName,
String tableName, String columnName) {
boolean success = false;
@@ -4857,8 +5016,34 @@ public class ObjectStore implements RawS
}
@Override
+ public List<HiveObjectPrivilege> listPrincipalTableColumnGrants(String principalName,
+ PrincipalType principalType,
+ String dbName,
+ String tableName,
+ String columnName) {
+ List<MTableColumnPrivilege> mTableCols =
+ listPrincipalMTableColumnGrants(principalName, principalType, dbName, tableName, columnName);
+ if (mTableCols.isEmpty()) {
+ return Collections.emptyList();
+ }
+ List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
+ for (int i = 0; i < mTableCols.size(); i++) {
+ MTableColumnPrivilege sCol = mTableCols.get(i);
+ HiveObjectRef objectRef = new HiveObjectRef(
+ HiveObjectType.COLUMN, dbName, tableName, null, sCol.getColumnName());
+ HiveObjectPrivilege secObj = new HiveObjectPrivilege(
+ objectRef, sCol.getPrincipalName(), principalType,
+ new PrivilegeGrantInfo(sCol.getPrivilege(), sCol
+ .getCreateTime(), sCol.getGrantor(), PrincipalType
+ .valueOf(sCol.getGrantorType()), sCol
+ .getGrantOption()));
+ result.add(secObj);
+ }
+ return result;
+ }
+
@SuppressWarnings("unchecked")
- public List<MPartitionColumnPrivilege> listPrincipalPartitionColumnGrants(
+ public List<MPartitionColumnPrivilege> listPrincipalMPartitionColumnGrants(
String principalName, PrincipalType principalType, String dbName,
String tableName, String partitionName, String columnName) {
boolean success = false;
@@ -4897,6 +5082,35 @@ public class ObjectStore implements RawS
}
@Override
+ public List<HiveObjectPrivilege> listPrincipalPartitionColumnGrants(String principalName,
+ PrincipalType principalType,
+ String dbName,
+ String tableName,
+ List<String> partValues,
+ String partitionName,
+ String columnName) {
+ List<MPartitionColumnPrivilege> mPartitionCols =
+ listPrincipalMPartitionColumnGrants(principalName, principalType, dbName, tableName,
+ partitionName, columnName);
+ if (mPartitionCols.isEmpty()) {
+ return Collections.emptyList();
+ }
+ List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
+ for (int i = 0; i < mPartitionCols.size(); i++) {
+ MPartitionColumnPrivilege sCol = mPartitionCols.get(i);
+ HiveObjectRef objectRef = new HiveObjectRef(
+ HiveObjectType.COLUMN, dbName, tableName, partValues, sCol.getColumnName());
+ HiveObjectPrivilege secObj = new HiveObjectPrivilege(objectRef,
+ sCol.getPrincipalName(), principalType,
+ new PrivilegeGrantInfo(sCol.getPrivilege(), sCol
+ .getCreateTime(), sCol.getGrantor(), PrincipalType
+ .valueOf(sCol.getGrantorType()), sCol.getGrantOption()));
+ result.add(secObj);
+ }
+ return result;
+ }
+
+ @Override
public List<HiveObjectPrivilege> listPrincipalPartitionColumnGrantsAll(
String principalName, PrincipalType principalType) {
boolean success = false;
Modified: hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/RawStore.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/RawStore.java?rev=1664226&r1=1664225&r2=1664226&view=diff
==============================================================================
--- hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/RawStore.java (original)
+++ hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/RawStore.java Thu Mar 5 04:09:31 2015
@@ -24,12 +24,10 @@ import java.lang.annotation.RetentionPol
import java.lang.annotation.Target;
import java.util.List;
import java.util.Map;
-import java.util.SortedSet;
import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.hive.metastore.api.AggrStats;
import org.apache.hadoop.hive.metastore.api.ColumnStatistics;
-import org.apache.hadoop.hive.metastore.api.ColumnStatisticsObj;
import org.apache.hadoop.hive.metastore.api.CurrentNotificationEventId;
import org.apache.hadoop.hive.metastore.api.Database;
import org.apache.hadoop.hive.metastore.api.Function;
@@ -49,19 +47,12 @@ import org.apache.hadoop.hive.metastore.
import org.apache.hadoop.hive.metastore.api.PrincipalType;
import org.apache.hadoop.hive.metastore.api.PrivilegeBag;
import org.apache.hadoop.hive.metastore.api.Role;
-import org.apache.hadoop.hive.metastore.api.SetPartitionsStatsRequest;
+import org.apache.hadoop.hive.metastore.api.RolePrincipalGrant;
import org.apache.hadoop.hive.metastore.api.Table;
import org.apache.hadoop.hive.metastore.api.Type;
import org.apache.hadoop.hive.metastore.api.UnknownDBException;
import org.apache.hadoop.hive.metastore.api.UnknownPartitionException;
import org.apache.hadoop.hive.metastore.api.UnknownTableException;
-import org.apache.hadoop.hive.metastore.model.MDBPrivilege;
-import org.apache.hadoop.hive.metastore.model.MGlobalPrivilege;
-import org.apache.hadoop.hive.metastore.model.MPartitionColumnPrivilege;
-import org.apache.hadoop.hive.metastore.model.MPartitionPrivilege;
-import org.apache.hadoop.hive.metastore.model.MRoleMap;
-import org.apache.hadoop.hive.metastore.model.MTableColumnPrivilege;
-import org.apache.hadoop.hive.metastore.model.MTablePrivilege;
import org.apache.hadoop.hive.metastore.partition.spec.PartitionSpecProxy;
import org.apache.thrift.TException;
@@ -260,27 +251,27 @@ public interface RawStore extends Config
public abstract PrincipalPrivilegeSet getColumnPrivilegeSet (String dbName, String tableName, String partitionName,
String columnName, String userName, List<String> groupNames) throws InvalidObjectException, MetaException;
- public abstract List<MGlobalPrivilege> listPrincipalGlobalGrants(String principalName,
+ public abstract List<HiveObjectPrivilege> listPrincipalGlobalGrants(String principalName,
PrincipalType principalType);
- public abstract List<MDBPrivilege> listPrincipalDBGrants(String principalName,
+ public abstract List<HiveObjectPrivilege> listPrincipalDBGrants(String principalName,
PrincipalType principalType, String dbName);
- public abstract List<MTablePrivilege> listAllTableGrants(
+ public abstract List<HiveObjectPrivilege> listAllTableGrants(
String principalName, PrincipalType principalType, String dbName,
String tableName);
- public abstract List<MPartitionPrivilege> listPrincipalPartitionGrants(
+ public abstract List<HiveObjectPrivilege> listPrincipalPartitionGrants(
String principalName, PrincipalType principalType, String dbName,
- String tableName, String partName);
+ String tableName, List<String> partValues, String partName);
- public abstract List<MTableColumnPrivilege> listPrincipalTableColumnGrants(
+ public abstract List<HiveObjectPrivilege> listPrincipalTableColumnGrants(
String principalName, PrincipalType principalType, String dbName,
String tableName, String columnName);
- public abstract List<MPartitionColumnPrivilege> listPrincipalPartitionColumnGrants(
+ public abstract List<HiveObjectPrivilege> listPrincipalPartitionColumnGrants(
String principalName, PrincipalType principalType, String dbName,
- String tableName, String partName, String columnName);
+ String tableName, List<String> partValues, String partName, String columnName);
public abstract boolean grantPrivileges (PrivilegeBag privileges)
throws InvalidObjectException, MetaException, NoSuchObjectException;
@@ -293,16 +284,19 @@ public interface RawStore extends Config
public List<String> listRoleNames();
- public List<MRoleMap> listRoles(String principalName,
+ public List<Role> listRoles(String principalName,
PrincipalType principalType);
+ public List<RolePrincipalGrant> listRolesWithGrants(String principalName,
+ PrincipalType principalType);
+
/**
* Get the role to principal grant mapping for given role
* @param roleName
* @return
*/
- public List<MRoleMap> listRoleMembers(String roleName);
+ public List<RolePrincipalGrant> listRoleMembers(String roleName);
public abstract Partition getPartitionWithAuth(String dbName, String tblName,
@@ -358,10 +352,7 @@ public interface RawStore extends Config
throws MetaException, InvalidObjectException, NoSuchObjectException;
/** Persists the given column statistics object to the metastore
- * @param partVals
- *
- * @param ColumnStats object to persist
- * @param List of partVals
+ * @param colStats object to persist
* @return Boolean indicating the outcome of the operation
* @throws NoSuchObjectException
* @throws MetaException
@@ -374,8 +365,7 @@ public interface RawStore extends Config
/** Persists the given column statistics object to the metastore
* @param partVals
*
- * @param ColumnStats object to persist
- * @param List of partVals
+ * @param statsObj object to persist
* @return Boolean indicating the outcome of the operation
* @throws NoSuchObjectException
* @throws MetaException
@@ -390,9 +380,9 @@ public interface RawStore extends Config
* Returns the relevant column statistics for a given column in a given table in a given database
* if such statistics exist.
*
- * @param The name of the database, defaults to current database
- * @param The name of the table
- * @param The name of the column for which statistics is requested
+ * @param dbName name of the database, defaults to current database
+ * @param tableName name of the table
+ * @param colName names of the columns for which statistics is requested
* @return Relevant column statistics for the column for the given table
* @throws NoSuchObjectException
* @throws MetaException
@@ -520,7 +510,7 @@ public interface RawStore extends Config
/**
* Alter function based on new function specs.
* @param dbName
- * @param name
+ * @param funcName
* @param newFunction
* @throws InvalidObjectException
* @throws MetaException
@@ -531,7 +521,7 @@ public interface RawStore extends Config
/**
* Drop a function definition.
* @param dbName
- * @param functionName
+ * @param funcName
* @return
* @throws MetaException
* @throws NoSuchObjectException
@@ -544,7 +534,7 @@ public interface RawStore extends Config
/**
* Retrieve function by name.
* @param dbName
- * @param functionName
+ * @param funcName
* @return
* @throws MetaException
*/
Modified: hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseReadWrite.java
URL: http://svn.apache.org/viewvc/hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseReadWrite.java?rev=1664226&r1=1664225&r2=1664226&view=diff
==============================================================================
--- hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseReadWrite.java (original)
+++ hive/branches/hbase-metastore/metastore/src/java/org/apache/hadoop/hive/metastore/hbase/HBaseReadWrite.java Thu Mar 5 04:09:31 2015
@@ -612,19 +612,39 @@ class HBaseReadWrite {
* @param type user or role
* @return map of role name to grant info for all roles directly participated in.
*/
- Map<String, GrantInfoWritable> getPrincipalDirectRoles(String name, PrincipalType type)
+ List<Role> getPrincipalDirectRoles(String name, PrincipalType type)
throws IOException {
buildRoleCache();
- Map<String, GrantInfoWritable> directRoles = new HashMap<String, GrantInfoWritable>();
+ Set<String> rolesFound = new HashSet<String>();
for (Map.Entry<String, GrantInfoList> e : roleCache.entrySet()) {
for (GrantInfoWritable giw : e.getValue().grantInfos) {
if (giw.principalType == type && giw.principalName.equals(name)) {
- directRoles.put(e.getKey(), giw);
+ rolesFound.add(e.getKey());
break;
}
}
}
+ List<Role> directRoles = new ArrayList<Role>(rolesFound.size());
+ List<Get> gets = new ArrayList<Get>();
+ HTableInterface htab = getHTable(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) {
+ RoleWritable role = new RoleWritable();
+ HBaseUtils.deserialize(role, serialized);
+ directRoles.add(role.role);
+ }
+ }
+
return directRoles;
}
@@ -1031,11 +1051,14 @@ class HBaseReadWrite {
// There's no way to know whether all the tables we are looking for are
// in the cache, so we would need to scan one way or another. Thus there's no value in hitting
// the cache for this function.
+ byte[] keyPrefix = null;
+ if (dbName != null) {
+ keyPrefix = HBaseUtils.buildKeyWithTrailingSeparator(dbName);
+ }
Filter filter = null;
if (regex != null) {
filter = new RowFilter(CompareFilter.CompareOp.EQUAL, new RegexStringComparator(regex));
}
- byte[] keyPrefix = HBaseUtils.buildKeyWithTrailingSeparator(dbName);
Iterator<Result> iter =
scanWithFilter(TABLE_TABLE, keyPrefix, CATALOG_CF, CATALOG_COL, filter);
List<Table> tables = new ArrayList<Table>();