use of org.komamitsu.fluency.RetryableException 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));
}
use of org.komamitsu.fluency.RetryableException 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);
}
}
}
use of org.komamitsu.fluency.RetryableException in project fluency by komamitsu.
the class AwsS3Sender method uploadData.
private void uploadData(String bucket, String key, File file) {
LOG.debug("Upload data to S3: bucket={}, key={}, fileSize={}", bucket, key, file.length());
try {
PutObjectRequest.Builder builder = PutObjectRequest.builder().bucket(bucket).key(key);
client.putObject(builder.build(), RequestBody.fromFile(file));
} catch (NonRetryableException e) {
throw e;
} catch (Throwable e) {
throw new RetryableException(String.format("Failed to upload data. bucket=%s, key=%s", bucket, key), e);
}
}
Aggregations