use of org.komamitsu.fluency.NonRetryableException 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.NonRetryableException in project fluency by komamitsu.
the class TreasureDataSender method buildClient.
@VisibleForTesting
protected TDClient buildClient() {
URI uri;
try {
uri = new URI(config.getEndpoint());
} catch (URISyntaxException e) {
throw new NonRetryableException(String.format("Invalid endpoint. %s", config.getEndpoint()), e);
}
String host = uri.getHost() != null ? uri.getHost() : config.getEndpoint();
TDClientBuilder builder = new TDClientBuilder(false).setEndpoint(host).setApiKey(config.getApikey()).setRetryLimit(config.getRetryMax()).setRetryInitialIntervalMillis(config.getRetryIntervalMs()).setRetryMaxIntervalMillis(config.getMaxRetryIntervalMs()).setRetryMultiplier(config.getRetryFactor());
if (uri.getScheme() != null && uri.getScheme().equals("http")) {
builder.setUseSSL(false);
}
if (uri.getPort() > 0) {
builder.setPort(uri.getPort());
}
return builder.build();
}
use of org.komamitsu.fluency.NonRetryableException 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.NonRetryableException in project fluency by komamitsu.
the class TreasureDataSenderTest method sendWithLackOfPermissionOnDatabase.
@Test
public void sendWithLackOfPermissionOnDatabase() throws IOException {
doThrow(new TDClientHttpNotFoundException("Not Found!!!!")).when(client).importFile(anyString(), anyString(), any(File.class), anyString());
doThrow(new TDClientHttpNotFoundException("Not Found!!!!")).when(client).createTable(anyString(), anyString());
doThrow(new TDClientHttpConflictException("Conflict!!!!")).when(client).createDatabase(anyString());
doReturn(false).when(client).existsDatabase(anyString());
try {
sender.send(DB_AND_TABLE, ByteBuffer.wrap(DATA));
fail();
} catch (NonRetryableException e) {
assertTrue(true);
}
ArgumentCaptor<String> uniqueIdArgumentCaptor = ArgumentCaptor.forClass(String.class);
verify(client, times(1)).importFile(eq(DB), eq(TABLE), any(File.class), uniqueIdArgumentCaptor.capture());
verify(client, times(4)).createDatabase(eq(DB));
verify(client, times(4)).existsDatabase(eq(DB));
verify(client, times(1)).createTable(eq(DB), eq(TABLE));
UUID.fromString(uniqueIdArgumentCaptor.getValue());
}
use of org.komamitsu.fluency.NonRetryableException 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