Search in sources :

Example 11 with UserRemoteException

use of org.apache.drill.common.exceptions.UserRemoteException in project drill by apache.

the class TestImpersonationMetadata method testCreateTableInWSWithNoPermissionsForQueryUser.

@Test
public void testCreateTableInWSWithNoPermissionsForQueryUser() throws Exception {
    // Workspace dir owned by "processUser", workspace group is "group0" and "user2" is not part of "group0"
    final String tableWS = "drillTestGrp0_755";
    final String tableName = "table1";
    UserRemoteException ex = null;
    try {
        updateClient(user2);
        test("USE " + Joiner.on(".").join(MINIDFS_STORAGE_PLUGIN_NAME, tableWS));
        test("CREATE TABLE " + tableName + " AS SELECT " + "c_custkey, c_nationkey FROM cp.`tpch/customer.parquet` ORDER BY c_custkey;");
    } catch (UserRemoteException e) {
        ex = e;
    }
    assertNotNull("UserRemoteException is expected", ex);
    assertThat(ex.getMessage(), containsString("SYSTEM ERROR: RemoteException: Permission denied: user=drillTestUser2, access=WRITE, inode=\"/drillTestGrp0_755/"));
}
Also used : UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) StringContains.containsString(org.hamcrest.core.StringContains.containsString) Test(org.junit.Test)

Example 12 with UserRemoteException

use of org.apache.drill.common.exceptions.UserRemoteException in project drill by apache.

the class TestImpersonationQueries method testDirectImpersonation_NoReadPermissions.

@Test
public void testDirectImpersonation_NoReadPermissions() throws Exception {
    UserRemoteException ex = null;
    try {
        // Table lineitem is owned by "user0_1:group0_1" with permissions 750. Now try to read the table as "user2_1". We
        // should expect a permission denied error as "user2_1" is not part of the "group0_1"
        updateClient(org1Users[2]);
        test(String.format("SELECT * FROM %s.lineitem ORDER BY l_orderkey LIMIT 1", getWSSchema(org1Users[0])));
    } catch (UserRemoteException e) {
        ex = e;
    }
    assertNotNull("UserRemoteException is expected", ex);
    assertThat(ex.getMessage(), containsString("PERMISSION ERROR: " + String.format("Not authorized to read table [lineitem] in schema [%s.user0_1]", MINIDFS_STORAGE_PLUGIN_NAME)));
}
Also used : UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) Test(org.junit.Test)

Example 13 with UserRemoteException

use of org.apache.drill.common.exceptions.UserRemoteException in project drill by apache.

the class TestDynamicUDFSupport method testDisableDynamicSupport.

@Test
public void testDisableDynamicSupport() throws Exception {
    try {
        test("alter system set `exec.udf.enable_dynamic_support` = false");
        String[] actions = new String[] { "create", "drop" };
        String query = "%s function using jar 'jar_name.jar'";
        for (String action : actions) {
            try {
                test(query, action);
            } catch (UserRemoteException e) {
                assertThat(e.getMessage(), containsString("Dynamic UDFs support is disabled."));
            }
        }
    } finally {
        test("alter system reset `exec.udf.enable_dynamic_support`");
    }
}
Also used : UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) Matchers.anyString(org.mockito.Matchers.anyString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 14 with UserRemoteException

use of org.apache.drill.common.exceptions.UserRemoteException in project drill by apache.

the class TestDynamicUDFSupport method testLazyInit.

@Test
public void testLazyInit() throws Exception {
    try {
        test("select custom_lower('A') from (values(1))");
    } catch (UserRemoteException e) {
        assertThat(e.getMessage(), containsString("No match found for function signature custom_lower(<CHARACTER>)"));
    }
    copyDefaultJarsToStagingArea();
    test("create function using jar '%s'", default_binary_name);
    testBuilder().sqlQuery("select custom_lower('A') as res from (values(1))").unOrdered().baselineColumns("res").baselineValues("a").go();
    Path localUdfDirPath = Deencapsulation.getField(getDrillbitContext().getFunctionImplementationRegistry(), "localUdfDir");
    File localUdfDir = new File(localUdfDirPath.toUri().getPath());
    assertTrue("Binary should exist in local udf directory", new File(localUdfDir, default_binary_name).exists());
    assertTrue("Source should exist in local udf directory", new File(localUdfDir, default_source_name).exists());
}
Also used : Path(org.apache.hadoop.fs.Path) UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) File(java.io.File) Test(org.junit.Test)

Example 15 with UserRemoteException

use of org.apache.drill.common.exceptions.UserRemoteException in project drill by apache.

the class QueryResultHandler method resultArrived.

/**
   * Maps internal low-level API protocol to {@link UserResultsListener}-level API protocol.
   * handles data result messages
   */
public void resultArrived(ByteBuf pBody) throws RpcException {
    final QueryResult queryResult = RpcBus.get(pBody, QueryResult.PARSER);
    final QueryId queryId = queryResult.getQueryId();
    final QueryState queryState = queryResult.getQueryState();
    if (logger.isDebugEnabled()) {
        logger.debug("resultArrived: queryState: {}, queryId = {}", queryState, QueryIdHelper.getQueryId(queryId));
    }
    assert queryResult.hasQueryState() : "received query result without QueryState";
    final boolean isFailureResult = QueryState.FAILED == queryState;
    // CANCELED queries are handled the same way as COMPLETED
    final boolean isTerminalResult;
    switch(queryState) {
        case FAILED:
        case CANCELED:
        case COMPLETED:
            isTerminalResult = true;
            break;
        default:
            logger.error("Unexpected/unhandled QueryState " + queryState + " (for query " + queryId + ")");
            isTerminalResult = false;
            break;
    }
    assert isFailureResult || queryResult.getErrorCount() == 0 : "Error count for the query batch is non-zero but QueryState != FAILED";
    UserResultsListener resultsListener = newUserResultsListener(queryId);
    try {
        if (isFailureResult) {
            // Failure case--pass on via submissionFailed(...).
            resultsListener.submissionFailed(new UserRemoteException(queryResult.getError(0)));
        // Note: Listener is removed in finally below.
        } else if (isTerminalResult) {
            try {
                resultsListener.queryCompleted(queryState);
            } catch (Exception e) {
                resultsListener.submissionFailed(UserException.systemError(e).build(logger));
            }
        } else {
            logger.warn("queryState {} was ignored", queryState);
        }
    } finally {
        if (isTerminalResult) {
            // for it?
            if ((!(resultsListener instanceof BufferingResultsListener) || ((BufferingResultsListener) resultsListener).output != null)) {
                queryIdToResultsListenersMap.remove(queryId, resultsListener);
            }
        }
    }
}
Also used : QueryResult(org.apache.drill.exec.proto.UserBitShared.QueryResult) UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException) QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) QueryState(org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState) UserException(org.apache.drill.common.exceptions.UserException) RpcException(org.apache.drill.exec.rpc.RpcException) UserRemoteException(org.apache.drill.common.exceptions.UserRemoteException)

Aggregations

UserRemoteException (org.apache.drill.common.exceptions.UserRemoteException)25 Test (org.junit.Test)22 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)15 File (java.io.File)2 QueryId (org.apache.drill.exec.proto.UserBitShared.QueryId)2 QueryState (org.apache.drill.exec.proto.UserBitShared.QueryResult.QueryState)2 Path (org.apache.hadoop.fs.Path)2 Matchers.anyString (org.mockito.Matchers.anyString)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 UserException (org.apache.drill.common.exceptions.UserException)1 FunctionImplementationRegistry (org.apache.drill.exec.expr.fn.FunctionImplementationRegistry)1 LocalFunctionRegistry (org.apache.drill.exec.expr.fn.registry.LocalFunctionRegistry)1 RemoteFunctionRegistry (org.apache.drill.exec.expr.fn.registry.RemoteFunctionRegistry)1 QueryResult (org.apache.drill.exec.proto.UserBitShared.QueryResult)1 RpcException (org.apache.drill.exec.rpc.RpcException)1 DataChangeVersion (org.apache.drill.exec.store.sys.store.DataChangeVersion)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1