Search in sources :

Example 16 with ServiceException

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

Example 17 with ServiceException

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

Example 18 with ServiceException

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

Example 19 with ServiceException

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

Example 20 with ServiceException

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

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