use of org.jets3t.service.ServiceException in project alluxio by Alluxio.
the class S3UnderFileSystemFactory method create.
@Override
public UnderFileSystem create(String path, Object unusedConf) {
Preconditions.checkNotNull(path);
if (checkAWSCredentials()) {
try {
return S3UnderFileSystem.createInstance(new AlluxioURI(path));
} catch (ServiceException e) {
throw Throwables.propagate(e);
}
}
String err = "AWS Credentials not available, cannot create S3 Under File System.";
throw Throwables.propagate(new IOException(err));
}
use of org.jets3t.service.ServiceException in project alluxio by Alluxio.
the class S3InputStream method skip.
/**
* This method leverages the ability to open a stream from S3 from a given offset. When the
* underlying stream has fewer bytes buffered than the skip request, the stream is closed, and
* a new stream is opened starting at the requested offset.
*
* @param n number of bytes to skip
* @return the number of bytes skipped
* @throws IOException if an error occurs when requesting from S3
*/
@Override
public long skip(long n) throws IOException {
if (mInputStream.available() >= n) {
return mInputStream.skip(n);
}
// The number of bytes to skip is possibly large, open a new stream from S3.
mInputStream.close();
mPos += n;
try {
mObject = mClient.getObject(mBucketName, mKey, null, null, null, null, mPos, null);
mInputStream = new BufferedInputStream(mObject.getDataInputStream());
} catch (ServiceException e) {
throw new IOException(e);
}
return n;
}
use of org.jets3t.service.ServiceException in project alluxio by Alluxio.
the class S3UnderFileSystem method copyObject.
@Override
protected boolean copyObject(String src, String dst) {
LOG.debug("Copying {} to {}", src, dst);
S3Object obj = new S3Object(dst);
// Retry copy for a few times, in case some Jets3t or AWS 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;
}
use of org.jets3t.service.ServiceException in project alluxio by Alluxio.
the class S3UnderFileSystem method createEmptyObject.
@Override
protected boolean createEmptyObject(String key) {
try {
S3Object obj = new S3Object(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 object: {}", key, e);
return false;
}
}
use of org.jets3t.service.ServiceException in project alluxio by Alluxio.
the class GCSInputStream method skip.
/**
* This method leverages the ability to open a stream from GCS from a given offset. When the
* underlying stream has fewer bytes buffered than the skip request, the stream is closed, and
* a new stream is opened starting at the requested offset.
*
* @param n number of bytes to skip
* @return the number of bytes skipped
* @throws IOException if an error occurs when requesting from GCS
*/
@Override
public long skip(long n) throws IOException {
if (mInputStream.available() >= n) {
return mInputStream.skip(n);
}
// The number of bytes to skip is possibly large, open a new stream from GCS.
mInputStream.close();
mPos += n;
try {
mObject = mClient.getObject(mBucketName, mKey, null, /* ignore ModifiedSince */
null, /* ignore UnmodifiedSince */
null, /* ignore MatchTags */
null, /* ignore NoneMatchTags */
mPos, /* byteRangeStart */
null);
mInputStream = new BufferedInputStream(mObject.getDataInputStream());
} catch (ServiceException e) {
throw new IOException(e);
}
return n;
}
Aggregations