Search in sources :

Example 1 with ExitException

use of org.apache.hive.hcatalog.ExitException in project hive by apache.

the class TestPermsGrp method testCustomPerms.

public void testCustomPerms() throws Exception {
    String dbName = Warehouse.DEFAULT_DATABASE_NAME;
    String tblName = "simptbl";
    String typeName = "Person";
    try {
        // Lets first test for default permissions, this is the case when user specified nothing.
        Table tbl = getTable(dbName, tblName, typeName);
        msc.createTable(tbl);
        Database db = Hive.get(hcatConf).getDatabase(dbName);
        Path dfsPath = clientWH.getDefaultTablePath(db, tblName);
        cleanupTbl(dbName, tblName, typeName);
        // Next user did specify perms.
        try {
            callHCatCli(new String[] { "-e", "create table simptbl (name string) stored as RCFILE", "-p", "rwx-wx---" });
            fail();
        } catch (Exception e) {
            assertTrue(e instanceof ExitException);
            assertEquals(((ExitException) e).getStatus(), 0);
        }
        dfsPath = clientWH.getDefaultTablePath(db, tblName);
        assertEquals(FsPermission.valueOf("drwx-wx---"), dfsPath.getFileSystem(hcatConf).getFileStatus(dfsPath).getPermission());
        cleanupTbl(dbName, tblName, typeName);
        // User specified perms in invalid format.
        hcatConf.set(HCatConstants.HCAT_PERMS, "rwx");
        // make sure create table fails.
        try {
            callHCatCli(new String[] { "-e", "create table simptbl (name string) stored as RCFILE", "-p", "rwx" });
            fail();
        } catch (Exception me) {
            assertTrue(me instanceof ExitException);
        }
        // No physical dir gets created.
        dfsPath = clientWH.getDefaultTablePath(db, tblName);
        try {
            dfsPath.getFileSystem(hcatConf).getFileStatus(dfsPath);
            fail();
        } catch (Exception fnfe) {
            assertTrue(fnfe instanceof FileNotFoundException);
        }
        // And no metadata gets created.
        try {
            msc.getTable(Warehouse.DEFAULT_DATABASE_NAME, tblName);
            fail();
        } catch (Exception e) {
            assertTrue(e instanceof NoSuchObjectException);
            assertEquals("default.simptbl table not found", e.getMessage());
        }
        // test for invalid group name
        hcatConf.set(HCatConstants.HCAT_PERMS, "drw-rw-rw-");
        hcatConf.set(HCatConstants.HCAT_GROUP, "THIS_CANNOT_BE_A_VALID_GRP_NAME_EVER");
        try {
            // create table must fail.
            callHCatCli(new String[] { "-e", "create table simptbl (name string) stored as RCFILE", "-p", "rw-rw-rw-", "-g", "THIS_CANNOT_BE_A_VALID_GRP_NAME_EVER" });
            fail();
        } catch (Exception me) {
            assertTrue(me instanceof SecurityException);
        }
        try {
            // no metadata should get created.
            msc.getTable(dbName, tblName);
            fail();
        } catch (Exception e) {
            assertTrue(e instanceof NoSuchObjectException);
            assertEquals("default.simptbl table not found", e.getMessage());
        }
        try {
            // neither dir should get created.
            dfsPath.getFileSystem(hcatConf).getFileStatus(dfsPath);
            fail();
        } catch (Exception e) {
            assertTrue(e instanceof FileNotFoundException);
        }
    } catch (Exception e) {
        LOG.error("testCustomPerms failed.", e);
        throw e;
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Table(org.apache.hadoop.hive.metastore.api.Table) Database(org.apache.hadoop.hive.metastore.api.Database) FileNotFoundException(java.io.FileNotFoundException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) ExitException(org.apache.hive.hcatalog.ExitException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) ExitException(org.apache.hive.hcatalog.ExitException) TException(org.apache.thrift.TException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) FileNotFoundException(java.io.FileNotFoundException) InvalidOperationException(org.apache.hadoop.hive.metastore.api.InvalidOperationException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 Path (org.apache.hadoop.fs.Path)1 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)1 Database (org.apache.hadoop.hive.metastore.api.Database)1 InvalidObjectException (org.apache.hadoop.hive.metastore.api.InvalidObjectException)1 InvalidOperationException (org.apache.hadoop.hive.metastore.api.InvalidOperationException)1 MetaException (org.apache.hadoop.hive.metastore.api.MetaException)1 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)1 Table (org.apache.hadoop.hive.metastore.api.Table)1 ExitException (org.apache.hive.hcatalog.ExitException)1 TException (org.apache.thrift.TException)1