Search in sources :

Example 51 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project ice by Netflix.

the class BasicS3ApplicationGroupService method deleteApplicationGroup.

public boolean deleteApplicationGroup(String name) {
    Map<String, ApplicationGroup> appgroups = getApplicationGroups();
    ApplicationGroup appgroup = appgroups.remove(name);
    try {
        String json = getJson(appgroups);
        s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + "appgroups", new ByteArrayInputStream(json.getBytes()), new ObjectMetadata());
        BasicS3ApplicationGroupService.logger.info("delete appgroup " + name + " " + appgroup);
        return true;
    } catch (JSONException e) {
        logger.error("Error deleting appgroup " + appgroup, e);
        return false;
    }
}
Also used : ApplicationGroup(com.netflix.ice.reader.ApplicationGroup) ByteArrayInputStream(java.io.ByteArrayInputStream) JSONException(org.json.JSONException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 52 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project ice by Netflix.

the class AwsUtils method downloadFileIfChangedSince.

public static boolean downloadFileIfChangedSince(String bucketName, String bucketFilePrefix, File file, long milles, String accountId, String assumeRole, String externalId) {
    AmazonS3Client s3Client = AwsUtils.s3Client;
    try {
        if (!StringUtils.isEmpty(accountId) && !StringUtils.isEmpty(assumeRole)) {
            Credentials assumedCredentials = getAssumedCredentials(accountId, assumeRole, externalId);
            s3Client = new AmazonS3Client(new BasicSessionCredentials(assumedCredentials.getAccessKeyId(), assumedCredentials.getSecretAccessKey(), assumedCredentials.getSessionToken()), clientConfig);
        }
        ObjectMetadata metadata = s3Client.getObjectMetadata(bucketName, bucketFilePrefix + file.getName());
        boolean download = !file.exists() || metadata.getLastModified().getTime() > milles;
        if (download) {
            return download(s3Client, bucketName, bucketFilePrefix + file.getName(), file);
        } else
            return download;
    } finally {
        if (s3Client != AwsUtils.s3Client)
            s3Client.shutdown();
    }
}
Also used : AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) Credentials(com.amazonaws.services.securitytoken.model.Credentials)

Example 53 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project exhibitor by soabase.

the class S3Utils method simpleUploadFile.

public static ObjectMetadata simpleUploadFile(S3Client client, byte[] bytes, String bucket, String key) throws Exception {
    byte[] md5 = md5(bytes, bytes.length);
    ObjectMetadata metadata = new ObjectMetadata();
    metadata.setContentLength(bytes.length);
    metadata.setLastModified(new Date());
    metadata.setContentMD5(S3Utils.toBase64(md5));
    PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, new ByteArrayInputStream(bytes), metadata);
    PutObjectResult putObjectResult = client.putObject(putObjectRequest);
    if (!putObjectResult.getETag().equals(S3Utils.toHex(md5))) {
        throw new Exception("Unable to match MD5 for config");
    }
    return metadata;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PutObjectResult(com.amazonaws.services.s3.model.PutObjectResult) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Date(java.util.Date) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Example 54 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project exhibitor by soabase.

the class S3ClientImpl method getObjectMetadata.

@Override
public ObjectMetadata getObjectMetadata(String bucket, String key) throws Exception {
    RefCountedClient holder = client.get();
    AmazonS3Client amazonS3Client = holder.useClient();
    try {
        return amazonS3Client.getObjectMetadata(bucket, key);
    } finally {
        holder.release();
    }
}
Also used : AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client)

Example 55 with ObjectMetadata

use of com.amazonaws.services.s3.model.ObjectMetadata in project uPortal by Jasig.

the class AwsS3DynamicSkinService method innerSkinCssFileExists.

@Override
protected boolean innerSkinCssFileExists(DynamicSkinInstanceData data) {
    final String objectKey = this.getCssObjectKey(data);
    log.info(ATTEMPTING_TO_GET_FILE_METADATA_FROM_AWS_S3_LOG_MSG, this.awsS3BucketConfig.getBucketName(), objectKey);
    final ObjectMetadata metadata = this.getMetadataFromAwsS3Bucket(objectKey);
    log.info(FILE_METADATA_RETRIEVED_FROM_AWS_S3_LOG_MSG, this.awsS3BucketConfig.getBucketName(), objectKey);
    if (metadata == null) {
        return false;
    } else {
        final String uniqueTokenFromS3 = metadata.getUserMetaDataOf(SKIN_UNIQUE_TOKEN_METADATA_KEY);
        return this.getUniqueToken(data).equals(uniqueTokenFromS3);
    }
}
Also used : ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Aggregations

ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)75 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)26 IOException (java.io.IOException)19 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)18 AmazonClientException (com.amazonaws.AmazonClientException)17 AmazonServiceException (com.amazonaws.AmazonServiceException)17 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)10 Upload (com.amazonaws.services.s3.transfer.Upload)10 ByteArrayInputStream (java.io.ByteArrayInputStream)10 InputStream (java.io.InputStream)9 Copy (com.amazonaws.services.s3.transfer.Copy)8 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)7 File (java.io.File)5 InterruptedIOException (java.io.InterruptedIOException)5 Date (java.util.Date)5 Path (org.apache.hadoop.fs.Path)5 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)4 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)3 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)3 InitiateMultipartUploadRequest (com.amazonaws.services.s3.model.InitiateMultipartUploadRequest)3