Esempio n. 1
0
    def test_get_exec_summary(self):
        statement = "SELECT COUNT(1) FROM functional.alltypes"
        execute_statement_resp = self.execute_statement(statement)

        exec_summary_req = ImpalaHiveServer2Service.TGetExecSummaryReq()
        exec_summary_req.operationHandle = execute_statement_resp.operationHandle
        exec_summary_req.sessionHandle = self.session_handle
        exec_summary_resp = self.hs2_client.GetExecSummary(exec_summary_req)

        # Test getting the summary while query is running. We can't verify anything
        # about the summary (depends how much progress query has made) but the call
        # should work.
        TestHS2.check_response(exec_summary_resp)

        # Wait for query to start running so we can get a non-empty ExecSummary.
        self.wait_for_admission_control(execute_statement_resp.operationHandle)
        exec_summary_resp = self.hs2_client.GetExecSummary(exec_summary_req)
        TestHS2.check_response(exec_summary_resp)
        assert len(exec_summary_resp.summary.nodes) > 0

        # Test that session secret is validated. Note that operation secret does not need to
        # be validated in addition if the session secret is valid and the operation belongs
        # to the session, because the user has full access to the session.
        TestHS2.check_invalid_session(
            self.hs2_client.GetExecSummary(
                ImpalaHiveServer2Service.TGetExecSummaryReq(
                    execute_statement_resp.operationHandle,
                    create_session_handle_without_secret(
                        self.session_handle))))

        # Attempt to access query with different user should fail.
        evil_user = getuser() + "_evil_twin"
        with ScopedSession(self.hs2_client, username=evil_user) as session:
            session_handle2 = session.sessionHandle
            TestHS2.check_profile_access_denied(self.hs2_client.GetExecSummary(
                ImpalaHiveServer2Service.TGetExecSummaryReq(
                    execute_statement_resp.operationHandle, session_handle2)),
                                                user=evil_user)

            # Now close the query and verify the exec summary is available.
            close_operation_req = TCLIService.TCloseOperationReq()
            close_operation_req.operationHandle = execute_statement_resp.operationHandle
            TestHS2.check_response(
                self.hs2_client.CloseOperation(close_operation_req))

            # Attempt to access query with different user from log should fail.
            TestHS2.check_profile_access_denied(
                self.hs2_client.GetRuntimeProfile(
                    ImpalaHiveServer2Service.TGetRuntimeProfileReq(
                        execute_statement_resp.operationHandle,
                        session_handle2)),
                user=evil_user)

        exec_summary_resp = self.hs2_client.GetExecSummary(exec_summary_req)
        TestHS2.check_response(exec_summary_resp)
        assert len(exec_summary_resp.summary.nodes) > 0
Esempio n. 2
0
    def test_get_exec_summary(self):
        execute_statement_req = TCLIService.TExecuteStatementReq()
        execute_statement_req.sessionHandle = self.session_handle
        execute_statement_req.statement = "SELECT COUNT(1) FROM functional.alltypes"
        execute_statement_resp = self.hs2_client.ExecuteStatement(
            execute_statement_req)
        TestHS2.check_response(execute_statement_resp)

        exec_summary_req = ImpalaHiveServer2Service.TGetExecSummaryReq()
        exec_summary_req.operationHandle = execute_statement_resp.operationHandle
        exec_summary_req.sessionHandle = self.session_handle
        exec_summary_resp = self.hs2_client.GetExecSummary(exec_summary_req)

        # Test getting the summary while query is running. We can't verify anything
        # about the summary (depends how much progress query has made) but the call
        # should work.
        TestHS2.check_response(exec_summary_resp)

        close_operation_req = TCLIService.TCloseOperationReq()
        close_operation_req.operationHandle = execute_statement_resp.operationHandle
        TestHS2.check_response(
            self.hs2_client.CloseOperation(close_operation_req))

        exec_summary_resp = self.hs2_client.GetExecSummary(exec_summary_req)
        TestHS2.check_response(exec_summary_resp)
        assert len(exec_summary_resp.summary.nodes) > 0
Esempio n. 3
0
    def test_get_exec_summary(self):
        statement = "SELECT COUNT(1) FROM functional.alltypes"
        execute_statement_resp = self.execute_statement(statement)

        exec_summary_req = ImpalaHiveServer2Service.TGetExecSummaryReq()
        exec_summary_req.operationHandle = execute_statement_resp.operationHandle
        exec_summary_req.sessionHandle = self.session_handle
        exec_summary_resp = self.hs2_client.GetExecSummary(exec_summary_req)

        # Test getting the summary while query is running. We can't verify anything
        # about the summary (depends how much progress query has made) but the call
        # should work.
        TestHS2.check_response(exec_summary_resp)

        # Wait for query to start running so we can get a non-empty ExecSummary.
        self.wait_for_admission_control(execute_statement_resp.operationHandle)
        exec_summary_resp = self.hs2_client.GetExecSummary(exec_summary_req)
        TestHS2.check_response(exec_summary_resp)
        assert len(exec_summary_resp.summary.nodes) > 0

        # Now close the query and verify the exec summary is available.
        close_operation_req = TCLIService.TCloseOperationReq()
        close_operation_req.operationHandle = execute_statement_resp.operationHandle
        TestHS2.check_response(
            self.hs2_client.CloseOperation(close_operation_req))

        exec_summary_resp = self.hs2_client.GetExecSummary(exec_summary_req)
        TestHS2.check_response(exec_summary_resp)
        assert len(exec_summary_resp.summary.nodes) > 0
Esempio n. 4
0
  def __run_stmt_and_verify_profile_access(self, stmt, has_access, close_operation):
    """Runs 'stmt' and retrieves the runtime profile and exec summary. If
      'has_access' is true, it verifies that no runtime profile or exec summary are
      returned. If 'close_operation' is true, make sure the operation is closed before
      retrieving the profile and exec summary."""
    from tests.hs2.test_hs2 import TestHS2
    execute_statement_resp = self.__execute_hs2_stmt(stmt, False)

    if close_operation:
      close_operation_req = TCLIService.TCloseOperationReq()
      close_operation_req.operationHandle = execute_statement_resp.operationHandle
      TestHS2.check_response(self.hs2_client.CloseOperation(close_operation_req))

    get_profile_req = ImpalaHiveServer2Service.TGetRuntimeProfileReq()
    get_profile_req.operationHandle = execute_statement_resp.operationHandle
    get_profile_req.sessionHandle = self.session_handle
    get_profile_resp = self.hs2_client.GetRuntimeProfile(get_profile_req)

    if has_access:
      TestHS2.check_response(get_profile_resp)
      assert "Plan: " in get_profile_resp.profile
    else:
      assert "User %s is not authorized to access the runtime profile or "\
          "execution summary." % (getuser()) in str(get_profile_resp)

    exec_summary_req = ImpalaHiveServer2Service.TGetExecSummaryReq()
    exec_summary_req.operationHandle = execute_statement_resp.operationHandle
    exec_summary_req.sessionHandle = self.session_handle
    exec_summary_resp = self.hs2_client.GetExecSummary(exec_summary_req)

    if has_access:
      TestHS2.check_response(exec_summary_resp)
    else:
      assert "User %s is not authorized to access the runtime profile or "\
          "execution summary." % (getuser()) in str(exec_summary_resp)
Esempio n. 5
0
    def test_get_exec_summary(self):
        execute_statement_req = TCLIService.TExecuteStatementReq()
        execute_statement_req.sessionHandle = self.session_handle
        execute_statement_req.statement = "SELECT COUNT(1) FROM functional.alltypes"
        execute_statement_resp = self.hs2_client.ExecuteStatement(
            execute_statement_req)
        TestHS2.check_response(execute_statement_resp)

        exec_summary_req = ImpalaHiveServer2Service.TGetExecSummaryReq()
        exec_summary_req.operationHandle = execute_statement_resp.operationHandle
        exec_summary_req.sessionHandle = self.session_handle
        exec_summary_resp = self.hs2_client.GetExecSummary(exec_summary_req)

        # GetExecSummary() only works for closed queries
        TestHS2.check_response(exec_summary_resp,
                               TCLIService.TStatusCode.ERROR_STATUS)

        close_operation_req = TCLIService.TCloseOperationReq()
        close_operation_req.operationHandle = execute_statement_resp.operationHandle
        TestHS2.check_response(
            self.hs2_client.CloseOperation(close_operation_req))

        exec_summary_resp = self.hs2_client.GetExecSummary(exec_summary_req)
        TestHS2.check_response(exec_summary_resp)
        assert len(exec_summary_resp.summary.nodes) > 0
Esempio n. 6
0
  def get_exec_summary(self, operation_handle, session_handle):
    """
    Calls Impala HS2 API's GetExecSummary method on the given query handle
    :return: TExecSummary object serialized as a dict
    """
    req = ImpalaHiveServer2Service.TGetExecSummaryReq(operationHandle=operation_handle, sessionHandle=session_handle)

    # GetExecSummary() only works for closed queries
    try:
      self.close_operation(operation_handle)
    except QueryServerException, e:
      LOG.warn('Failed to close operation for query handle, query may be invalid or already closed.')