use of com.amazonaws.services.s3.model.ObjectMetadata in project uPortal by Jasig.
the class AwsS3DynamicSkinService method saveContentToAwsS3Bucket.
private void saveContentToAwsS3Bucket(final String objectKey, final String content, final DynamicSkinInstanceData data) {
final InputStream inputStream = IOUtils.toInputStream(content);
final ObjectMetadata objectMetadata = this.createObjectMetadata(content, data);
final PutObjectRequest putObjectRequest = this.createPutObjectRequest(objectKey, inputStream, objectMetadata);
log.info(ATTEMPTING_TO_SAVE_FILE_TO_AWS_S3_LOG_MSG, this.awsS3BucketConfig.getBucketName(), objectKey);
this.saveContentToAwsS3Bucket(putObjectRequest);
log.info(FILE_SAVED_TO_AWS_S3_LOG_MSG, this.awsS3BucketConfig.getBucketName(), objectKey);
}
use of com.amazonaws.services.s3.model.ObjectMetadata in project hippo by NHS-digital-website.
the class S3ConnectorImpl method uploadFile.
public S3ObjectMetadata uploadFile(InputStream fileStream, String fileName, String contentType) {
String objectKey = s3ObjectKeyGenerator.generateObjectKey(fileName);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentType(contentType);
// initialise multipart upload
InitiateMultipartUploadResult initResult = s3.initiateMultipartUpload(new InitiateMultipartUploadRequest(bucketName, objectKey, metadata));
// loop parts
List<PartETag> partETags;
try {
partETags = uploadParts(fileStream, bucketName, objectKey, initResult.getUploadId());
} catch (Exception ex) {
final String errorMessage = "Failed to upload file " + objectKey;
log.error(errorMessage, ex);
s3.abortMultipartUpload(new AbortMultipartUploadRequest(bucketName, objectKey, initResult.getUploadId()));
throw new RuntimeException(errorMessage, ex);
}
// finalise multipart upload
s3.completeMultipartUpload(new CompleteMultipartUploadRequest(bucketName, objectKey, initResult.getUploadId(), partETags));
// The above put request returns metadata object but it's empty,
// hence the need for a separate call to fetch actual metadata.
ObjectMetadata resultMetadata = s3.getObjectMetadata(bucketName, objectKey);
return new S3ObjectMetadataImpl(resultMetadata, bucketName, objectKey);
}
use of com.amazonaws.services.s3.model.ObjectMetadata in project stocator by SparkTC.
the class COSAPIClient method getFileStatusKeyBased.
private FileStatus getFileStatusKeyBased(String key, Path path) throws AmazonS3Exception {
LOG.trace("internal method - get file status by key {}, path {}", key, path);
FileStatus cachedFS = memoryCache.getFileStatus(path.toString());
if (cachedFS != null) {
return cachedFS;
}
ObjectMetadata meta = mClient.getObjectMetadata(mBucket, key);
String sparkOrigin = meta.getUserMetaDataOf("data-origin");
boolean stocatorCreated = false;
if (sparkOrigin != null) {
String tmp = (String) sparkOrigin;
if (tmp.equals("stocator")) {
stocatorCreated = true;
}
}
mCachedSparkOriginated.put(key, Boolean.valueOf(stocatorCreated));
FileStatus fs = createFileStatus(meta.getContentLength(), key, meta.getLastModified(), path);
memoryCache.putFileStatus(path.toString(), fs);
return fs;
}
use of com.amazonaws.services.s3.model.ObjectMetadata in project stocator by SparkTC.
the class COSAPIClient method isSparkOrigin.
/**
* Checks if container/object exists and verifies that it contains
* Data-Origin=stocator metadata If so, object was created by Spark.
*
* @param objectKey the key of the object
* @param path the object path
* @return boolean if object was created by Spark
*/
private boolean isSparkOrigin(String objectKey, String path) {
LOG.debug("check spark origin for {}", objectKey);
if (!objectKey.endsWith("/")) {
LOG.debug("Key {} has no slash. Return false", objectKey);
return false;
} else {
objectKey = objectKey.substring(0, objectKey.length() - 1);
}
if (mCachedSparkOriginated.containsKey(objectKey)) {
boolean res = mCachedSparkOriginated.get(objectKey).booleanValue();
LOG.debug("found cached for spark origin for {}. Status {}", objectKey, res);
return res;
}
String key = getRealKey(objectKey);
Boolean sparkOriginated = Boolean.FALSE;
ObjectMetadata objMetadata = getObjectMetadata(key);
if (objMetadata != null) {
Object sparkOrigin = objMetadata.getUserMetaDataOf("data-origin");
if (sparkOrigin != null) {
String tmp = (String) sparkOrigin;
if (tmp.equals("stocator")) {
sparkOriginated = Boolean.TRUE;
}
}
}
mCachedSparkOriginated.put(key, sparkOriginated);
LOG.debug("spark origin for {} is {} non cached", objectKey, sparkOriginated.booleanValue());
return sparkOriginated.booleanValue();
}
use of com.amazonaws.services.s3.model.ObjectMetadata in project stocator by SparkTC.
the class COSAPIClient method isJobSuccessful.
/**
* Checks if container/object contains container/object/_SUCCESS If so, this
* object was created by successful Hadoop job
*
* @param objectKey
* @return boolean if job is successful
*/
private boolean isJobSuccessful(String objectKey) {
LOG.trace("isJobSuccessful: for {}", objectKey);
if (mCachedSparkJobsStatus.containsKey(objectKey)) {
LOG.trace("isJobSuccessful: {} found cached", objectKey);
return mCachedSparkJobsStatus.get(objectKey).booleanValue();
}
String key = getRealKey(objectKey);
Path p = new Path(key, HADOOP_SUCCESS);
ObjectMetadata statusMetadata = getObjectMetadata(p.toString());
Boolean isJobOK = Boolean.FALSE;
if (statusMetadata != null) {
isJobOK = Boolean.TRUE;
}
LOG.debug("isJobSuccessful: not cached {}. Status is {}", objectKey, isJobOK);
mCachedSparkJobsStatus.put(objectKey, isJobOK);
return isJobOK.booleanValue();
}
Aggregations