Search in sources :

Example 1 with TDClientHttpException

use of com.treasuredata.client.TDClientHttpException in project fluency by komamitsu.

the class TreasureDataSender method createDatabase.

private void createDatabase(String database) {
    for (int i = 0; i < RETRY_COUNT_FOR_DB_CREATE_DELETE_CONFLICT; i++) {
        try {
            client.createDatabase(database);
            LOG.info("Created database. database={}", database);
            return;
        } catch (TDClientHttpException e) {
            switch(e.getStatusCode()) {
                case 409:
                    LOG.info("The database already exists. database={}", database);
                    if (checkDatabaseAndWaitIfNeeded(database)) {
                        return;
                    }
                    // Retrying...
                    break;
                case 401:
                case 403:
                case 404:
                    throw new NonRetryableException(String.format("Failed to create database. database=%s", database), e);
            }
        } catch (NonRetryableException e) {
            throw e;
        } catch (Throwable e) {
            throw new RetryableException(String.format("Failed to create database. database=%s", database), e);
        }
    }
    // Retry over
    throw new NonRetryableException(String.format("It seems you don't have a proper permission on the database. database=%s", database));
}
Also used : TDClientHttpException(com.treasuredata.client.TDClientHttpException) NonRetryableException(org.komamitsu.fluency.NonRetryableException) NonRetryableException(org.komamitsu.fluency.NonRetryableException) RetryableException(org.komamitsu.fluency.RetryableException)

Example 2 with TDClientHttpException

use of com.treasuredata.client.TDClientHttpException in project fluency by komamitsu.

the class TreasureDataSender method createTable.

private void createTable(String database, String table) {
    while (true) {
        try {
            client.createTable(database, table);
            LOG.info("Created table. database={}, table={}", database, table);
            return;
        } catch (TDClientHttpException e) {
            switch(e.getStatusCode()) {
                case 409:
                    LOG.info("The table already exists. database={}, table={}", database, table);
                    return;
                case 401:
                case 403:
                    throw new NonRetryableException(String.format("Failed to create table. database=%s, table=%s", database, table), e);
                case 404:
                    createDatabase(database);
                    // Retry to create the table
                    break;
                default:
                    throw new RetryableException(String.format("Failed to create table. database=%s, table=%s", database, table), e);
            }
        } catch (NonRetryableException e) {
            throw e;
        } catch (Throwable e) {
            throw new RetryableException(String.format("Failed to create table. database=%s, table=%s", database, table), e);
        }
    }
}
Also used : TDClientHttpException(com.treasuredata.client.TDClientHttpException) NonRetryableException(org.komamitsu.fluency.NonRetryableException) NonRetryableException(org.komamitsu.fluency.NonRetryableException) RetryableException(org.komamitsu.fluency.RetryableException)

Example 3 with TDClientHttpException

use of com.treasuredata.client.TDClientHttpException in project td-client-java by treasure-data.

the class ProxyAuthenticator method authenticate.

@Override
public Request authenticate(Route route, Response response) throws IOException {
    if (response.request().header(PROXY_AUTHORIZATION) != null) {
        // If Proxy-Authrization is set, it means OkHttp client has already tried the authentication and failed
        throw new IOException(new TDClientHttpException(TDClientException.ErrorType.PROXY_AUTHENTICATION_FAILURE, "Proxy authentication failure", 407, null));
    }
    // Proxy authentication is required
    if (!proxyAuthCache.isPresent()) {
        logger.debug("Proxy authorization requested for " + route.address());
        proxyAuthCache = Optional.of(Credentials.basic(proxyConfig.getUser().or(""), proxyConfig.getPassword().or("")));
    }
    return response.request().newBuilder().addHeader(PROXY_AUTHORIZATION, proxyAuthCache.get()).build();
}
Also used : TDClientHttpException(com.treasuredata.client.TDClientHttpException) IOException(java.io.IOException)

Aggregations

TDClientHttpException (com.treasuredata.client.TDClientHttpException)3 NonRetryableException (org.komamitsu.fluency.NonRetryableException)2 RetryableException (org.komamitsu.fluency.RetryableException)2 IOException (java.io.IOException)1