use of org.jets3t.service.ServiceException in project alluxio by Alluxio.
the class GCSUnderFileSystem method createEmptyObject.
@Override
protected boolean createEmptyObject(String key) {
try {
GSObject obj = new GSObject(key);
obj.setDataInputStream(new ByteArrayInputStream(new byte[0]));
obj.setContentLength(0);
obj.setMd5Hash(DIR_HASH);
obj.setContentType(Mimetypes.MIMETYPE_BINARY_OCTET_STREAM);
mClient.putObject(mBucketName, obj);
return true;
} catch (ServiceException e) {
LOG.error("Failed to create directory: {}", key, e);
return false;
}
}
use of org.jets3t.service.ServiceException in project alluxio by Alluxio.
the class GCSUnderFileSystemFactory method create.
@Override
public UnderFileSystem create(String path, Object unusedConf) {
Preconditions.checkNotNull(path);
if (addAndCheckGoogleCredentials()) {
try {
return GCSUnderFileSystem.createInstance(new AlluxioURI(path));
} catch (ServiceException e) {
LOG.error("Failed to create GCSUnderFileSystem.", e);
throw Throwables.propagate(e);
}
}
String err = "Google Credentials not available, cannot create GCS Under File System.";
throw Throwables.propagate(new IOException(err));
}
use of org.jets3t.service.ServiceException in project druid by druid-io.
the class S3DataSegmentPusher method push.
@Override
public DataSegment push(final File indexFilesDir, final DataSegment inSegment) throws IOException {
final String s3Path = S3Utils.constructSegmentPath(config.getBaseKey(), inSegment);
log.info("Copying segment[%s] to S3 at location[%s]", inSegment.getIdentifier(), s3Path);
final File zipOutFile = File.createTempFile("druid", "index.zip");
final long indexSize = CompressionUtils.zip(indexFilesDir, zipOutFile);
try {
return S3Utils.retryS3Operation(new Callable<DataSegment>() {
@Override
public DataSegment call() throws Exception {
S3Object toPush = new S3Object(zipOutFile);
final String outputBucket = config.getBucket();
final String s3DescriptorPath = S3Utils.descriptorPathForSegmentPath(s3Path);
toPush.setBucketName(outputBucket);
toPush.setKey(s3Path);
if (!config.getDisableAcl()) {
toPush.setAcl(GSAccessControlList.REST_CANNED_BUCKET_OWNER_FULL_CONTROL);
}
log.info("Pushing %s.", toPush);
s3Client.putObject(outputBucket, toPush);
final DataSegment outSegment = inSegment.withSize(indexSize).withLoadSpec(ImmutableMap.<String, Object>of("type", "s3_zip", "bucket", outputBucket, "key", toPush.getKey())).withBinaryVersion(SegmentUtils.getVersionFromDir(indexFilesDir));
File descriptorFile = File.createTempFile("druid", "descriptor.json");
Files.copy(ByteStreams.newInputStreamSupplier(jsonMapper.writeValueAsBytes(inSegment)), descriptorFile);
S3Object descriptorObject = new S3Object(descriptorFile);
descriptorObject.setBucketName(outputBucket);
descriptorObject.setKey(s3DescriptorPath);
if (!config.getDisableAcl()) {
descriptorObject.setAcl(GSAccessControlList.REST_CANNED_BUCKET_OWNER_FULL_CONTROL);
}
log.info("Pushing %s", descriptorObject);
s3Client.putObject(outputBucket, descriptorObject);
log.info("Deleting zipped index File[%s]", zipOutFile);
zipOutFile.delete();
log.info("Deleting descriptor file[%s]", descriptorFile);
descriptorFile.delete();
return outSegment;
}
});
} catch (ServiceException e) {
throw new IOException(e);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of org.jets3t.service.ServiceException in project alluxio by Alluxio.
the class GCSOutputStream method close.
@Override
public void close() throws IOException {
if (mClosed.getAndSet(true)) {
return;
}
mLocalOutputStream.close();
try {
GSObject obj = new GSObject(mKey);
obj.setBucketName(mBucketName);
obj.setDataInputFile(mFile);
obj.setContentLength(mFile.length());
obj.setContentEncoding(Mimetypes.MIMETYPE_BINARY_OCTET_STREAM);
if (mHash != null) {
obj.setMd5Hash(mHash.digest());
} else {
LOG.warn("MD5 was not computed for: {}", mKey);
}
mClient.putObject(mBucketName, obj);
if (!mFile.delete()) {
LOG.error("Failed to delete temporary file @ {}", mFile.getPath());
}
} catch (ServiceException e) {
LOG.error("Failed to upload {}. Temporary file @ {}", mKey, mFile.getPath());
throw new IOException(e);
}
}
use of org.jets3t.service.ServiceException in project alluxio by Alluxio.
the class GCSUnderFileSystem method copyObject.
@Override
protected boolean copyObject(String src, String dst) {
LOG.debug("Copying {} to {}", src, dst);
GSObject obj = new GSObject(dst);
// Retry copy for a few times, in case some Jets3t or GCS internal errors happened during copy.
int retries = 3;
for (int i = 0; i < retries; i++) {
try {
mClient.copyObject(mBucketName, src, mBucketName, obj, false);
return true;
} catch (ServiceException e) {
LOG.error("Failed to copy file {} to {}", src, dst, e);
if (i != retries - 1) {
LOG.error("Retrying copying file {} to {}", src, dst);
}
}
}
LOG.error("Failed to copy file {} to {}, after {} retries", src, dst, retries);
return false;
}
Aggregations