use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project herd by FINRAOS.
the class JobServiceTest method putParameterIntoS3.
/**
* Puts a Java properties file content into S3. The Properties contains a single key-value defined by the given parameter object.
*
* @param s3BucketName the S3 bucket name
* @param s3ObjectKey the S3 object key
* @param parameter the parameter
*/
private void putParameterIntoS3(String s3BucketName, String s3ObjectKey, Parameter parameter) {
String content = parameter.getName() + "=" + parameter.getValue();
byte[] bytes = content.getBytes();
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(content.length());
PutObjectRequest putObjectRequest = new PutObjectRequest(s3BucketName, s3ObjectKey, inputStream, metadata);
s3Operations.putObject(putObjectRequest, null);
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project herd by FINRAOS.
the class FileUploadCleanupServiceTest method testDeleteBusinessObjectDataS3FileExists.
@Test
public void testDeleteBusinessObjectDataS3FileExists() throws Exception {
// Prepare database entries required for testing.
BusinessObjectDataKey testBusinessObjectKey = new BusinessObjectDataKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
createTestDatabaseEntities(testBusinessObjectKey, STORAGE_NAME, s3BucketName, TARGET_S3_KEY, 15);
// Put a file in S3.
PutObjectRequest putObjectRequest = new PutObjectRequest(s3BucketName, TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), new ObjectMetadata());
s3Operations.putObject(putObjectRequest, null);
// Delete the business object data.
List<BusinessObjectDataKey> resultBusinessObjectDataKeys = fileUploadCleanupService.deleteBusinessObjectData(STORAGE_NAME, 10);
// Validate the results.
assertNotNull(resultBusinessObjectDataKeys);
assertTrue(resultBusinessObjectDataKeys.isEmpty());
validateBusinessObjectDataStatus(testBusinessObjectKey, BDATA_STATUS);
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project herd by FINRAOS.
the class JdbcServiceTest method putS3Object.
/**
* Puts an S3 object with the given parameters directly into S3.
*
* @param s3BucketName the S3 bucket name
* @param s3ObjectKey the S3 object key
* @param content the content of the S3 object
*/
private void putS3Object(String s3BucketName, String s3ObjectKey, String content) {
PutObjectRequest putObjectRequest = new PutObjectRequest(s3BucketName, s3ObjectKey, new ByteArrayInputStream(content.getBytes()), new ObjectMetadata());
s3Operations.putObject(putObjectRequest, null);
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project herd by FINRAOS.
the class BusinessObjectDataServiceTestHelper method createS3Object.
/**
* Creates an object in S3 with the prefix constructed from the given parameters. The object's full path will be {prefix}/{UUID}
*
* @param businessObjectFormatEntity business object format
* @param request request with partition values and storage
* @param businessObjectDataVersion business object data version to put
*/
public void createS3Object(BusinessObjectFormatEntity businessObjectFormatEntity, BusinessObjectDataInvalidateUnregisteredRequest request, int businessObjectDataVersion) {
StorageEntity storageEntity = storageDao.getStorageByName(request.getStorageName());
String s3BucketName = storageHelper.getS3BucketAccessParams(storageEntity).getS3BucketName();
BusinessObjectDataKey businessObjectDataKey = getBusinessObjectDataKey(request);
businessObjectDataKey.setBusinessObjectDataVersion(businessObjectDataVersion);
String s3KeyPrefix = s3KeyPrefixHelper.buildS3KeyPrefix(AbstractServiceTest.S3_KEY_PREFIX_VELOCITY_TEMPLATE, businessObjectFormatEntity, businessObjectDataKey, storageEntity.getName());
String s3ObjectKey = s3KeyPrefix + "/test";
PutObjectRequest putObjectRequest = new PutObjectRequest(s3BucketName, s3ObjectKey, new ByteArrayInputStream(new byte[1]), new ObjectMetadata());
s3Operations.putObject(putObjectRequest, null);
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project herd by FINRAOS.
the class S3DaoImpl method createDirectory.
@Override
public void createDirectory(final S3FileTransferRequestParamsDto params) {
// Create metadata for the directory marker and set content-length to 0 bytes.
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(0);
prepareMetadata(params, metadata);
// Create empty content.
InputStream emptyContent = new ByteArrayInputStream(new byte[0]);
// Create a PutObjectRequest passing the folder name suffixed by '/'.
String directoryName = StringUtils.appendIfMissing(params.getS3KeyPrefix(), "/");
PutObjectRequest putObjectRequest = new PutObjectRequest(params.getS3BucketName(), directoryName, emptyContent, metadata);
// KMS key ID is being set through prepareMetadata()
AmazonS3Client s3Client = getAmazonS3(params);
try {
s3Operations.putObject(putObjectRequest, s3Client);
} catch (AmazonServiceException e) {
throw new IllegalStateException(String.format("Failed to create 0 byte S3 object with \"%s\" key in bucket \"%s\". Reason: %s", directoryName, params.getS3BucketName(), e.getMessage()), e);
} finally {
// Shutdown the AmazonS3Client instance to release resources.
s3Client.shutdown();
}
}
Aggregations