Search in sources :

Example 11 with ServiceException

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));
}
Also used : ServiceException(org.jets3t.service.ServiceException) IOException(java.io.IOException) AlluxioURI(alluxio.AlluxioURI)

Example 12 with ServiceException

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;
}
Also used : ServiceException(org.jets3t.service.ServiceException) BufferedInputStream(java.io.BufferedInputStream) IOException(java.io.IOException)

Example 13 with ServiceException

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;
}
Also used : ServiceException(org.jets3t.service.ServiceException) S3Object(org.jets3t.service.model.S3Object)

Example 14 with ServiceException

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;
    }
}
Also used : ServiceException(org.jets3t.service.ServiceException) ByteArrayInputStream(java.io.ByteArrayInputStream) S3Object(org.jets3t.service.model.S3Object)

Example 15 with ServiceException

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;
}
Also used : ServiceException(org.jets3t.service.ServiceException) BufferedInputStream(java.io.BufferedInputStream) IOException(java.io.IOException)

Aggregations

ServiceException (org.jets3t.service.ServiceException)24 S3ServiceException (org.jets3t.service.S3ServiceException)11 IOException (java.io.IOException)10 S3Object (org.jets3t.service.model.S3Object)10 SegmentLoadingException (io.druid.segment.loading.SegmentLoadingException)4 StorageObject (org.jets3t.service.model.StorageObject)4 BufferedInputStream (java.io.BufferedInputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 GSObject (org.jets3t.service.model.GSObject)3 AlluxioURI (alluxio.AlluxioURI)2 DataSegment (io.druid.timeline.DataSegment)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 Predicate (com.google.common.base.Predicate)1 ByteSource (com.google.common.io.ByteSource)1 FileUtils (io.druid.java.util.common.FileUtils)1 IAE (io.druid.java.util.common.IAE)1 UOE (io.druid.java.util.common.UOE)1 EOFException (java.io.EOFException)1