Search in sources :

Example 1 with TStatus

use of org.apache.hive.service.rpc.thrift.TStatus in project hive by apache.

the class HiveSQLException method toTStatus.

/**
   * Converts current object to a {@link TStatus} object
   * @return	a {@link TStatus} object
   */
public TStatus toTStatus() {
    // TODO: convert sqlState, etc.
    TStatus tStatus = new TStatus(TStatusCode.ERROR_STATUS);
    tStatus.setSqlState(getSQLState());
    tStatus.setErrorCode(getErrorCode());
    tStatus.setErrorMessage(getMessage());
    tStatus.setInfoMessages(toString(this));
    return tStatus;
}
Also used : TStatus(org.apache.hive.service.rpc.thrift.TStatus)

Example 2 with TStatus

use of org.apache.hive.service.rpc.thrift.TStatus in project hive by apache.

the class HiveSQLException method toTStatus.

/**
   * Converts the specified {@link Exception} object into a {@link TStatus} object
   * @param e	a {@link Exception} object
   * @return	a {@link TStatus} object
   */
public static TStatus toTStatus(Exception e) {
    if (e instanceof HiveSQLException) {
        return ((HiveSQLException) e).toTStatus();
    }
    TStatus tStatus = new TStatus(TStatusCode.ERROR_STATUS);
    tStatus.setErrorMessage(e.getMessage());
    tStatus.setInfoMessages(toString(e));
    return tStatus;
}
Also used : TStatus(org.apache.hive.service.rpc.thrift.TStatus)

Example 3 with TStatus

use of org.apache.hive.service.rpc.thrift.TStatus in project hive by apache.

the class ThriftCLIService method unsecureTokenErrorStatus.

private TStatus unsecureTokenErrorStatus() {
    TStatus errorStatus = new TStatus(TStatusCode.ERROR_STATUS);
    errorStatus.setErrorMessage("Delegation token only supported over remote " + "client with kerberos authentication");
    return errorStatus;
}
Also used : TStatus(org.apache.hive.service.rpc.thrift.TStatus)

Example 4 with TStatus

use of org.apache.hive.service.rpc.thrift.TStatus in project hive by apache.

the class ThriftCLIService method GetDelegationToken.

@Override
public TGetDelegationTokenResp GetDelegationToken(TGetDelegationTokenReq req) throws TException {
    TGetDelegationTokenResp resp = new TGetDelegationTokenResp();
    if (hiveAuthFactory == null || !hiveAuthFactory.isSASLKerberosUser()) {
        resp.setStatus(unsecureTokenErrorStatus());
    } else {
        try {
            String token = cliService.getDelegationToken(new SessionHandle(req.getSessionHandle()), hiveAuthFactory, req.getOwner(), req.getRenewer());
            resp.setDelegationToken(token);
            resp.setStatus(OK_STATUS);
        } catch (HiveSQLException e) {
            LOG.error("Error obtaining delegation token", e);
            TStatus tokenErrorStatus = HiveSQLException.toTStatus(e);
            tokenErrorStatus.setSqlState("42000");
            resp.setStatus(tokenErrorStatus);
        }
    }
    return resp;
}
Also used : HiveSQLException(org.apache.hive.service.cli.HiveSQLException) TStatus(org.apache.hive.service.rpc.thrift.TStatus) TGetDelegationTokenResp(org.apache.hive.service.rpc.thrift.TGetDelegationTokenResp) SessionHandle(org.apache.hive.service.cli.SessionHandle)

Example 5 with TStatus

use of org.apache.hive.service.rpc.thrift.TStatus in project hive by apache.

the class TestHiveSQLException method testHiveSQLExceptionToTStatus.

/**
   * Tests the conversion from a HiveSQLException exception to the TStatus object
   */
@Test
public void testHiveSQLExceptionToTStatus() {
    String expectedMessage = "reason";
    String expectedSqlState = "sqlState";
    int expectedVendorCode = 10;
    Exception ex1 = new HiveSQLException(expectedMessage, expectedSqlState, expectedVendorCode, createSimpleCause());
    TStatus status = HiveSQLException.toTStatus(ex1);
    Assert.assertEquals(TStatusCode.ERROR_STATUS, status.getStatusCode());
    Assert.assertEquals(expectedSqlState, status.getSqlState());
    Assert.assertEquals(expectedMessage, status.getErrorMessage());
    Assert.assertEquals(HiveSQLException.toString(ex1), status.getInfoMessages());
}
Also used : TStatus(org.apache.hive.service.rpc.thrift.TStatus) Test(org.junit.Test)

Aggregations

TStatus (org.apache.hive.service.rpc.thrift.TStatus)6 Test (org.junit.Test)2 HiveSQLException (org.apache.hive.service.cli.HiveSQLException)1 SessionHandle (org.apache.hive.service.cli.SessionHandle)1 TGetDelegationTokenResp (org.apache.hive.service.rpc.thrift.TGetDelegationTokenResp)1