use of org.craftercms.studio.api.v1.exception.AwsException in project studio by craftercms.
the class AwsMediaConvertServiceImpl method uploadVideo.
/**
* {@inheritDoc}
*/
@Override
@HasPermission(type = DefaultPermission.class, action = "s3 write")
public MediaConvertResult uploadVideo(@ValidateStringParam @ProtectedResourceId("siteId") final String site, @ValidateStringParam final String inputProfileId, @ValidateStringParam final String outputProfileId, @ValidateStringParam final String filename, final InputStream content) throws AwsException {
MediaConvertProfile profile = getProfile(site, inputProfileId);
AmazonS3 s3Client = getS3Client(profile);
AWSMediaConvert mediaConvertClient = getMediaConvertClient(profile);
logger.info("Starting upload of file {0} for site {1}", filename, site);
AwsUtils.uploadStream(profile.getInputPath(), filename, s3Client, partSize, filename, content);
logger.info("Upload of file {0} for site {1} complete", filename, site);
String originalName = FilenameUtils.getBaseName(filename);
JobTemplate jobTemplate = mediaConvertClient.getJobTemplate(new GetJobTemplateRequest().withName(profile.getTemplate())).getJobTemplate();
JobSettings jobSettings = new JobSettings().withInputs(new Input().withFileInput(AwsUtils.getS3Url(profile.getInputPath(), filename)));
CreateJobRequest createJobRequest = new CreateJobRequest().withJobTemplate(profile.getTemplate()).withSettings(jobSettings).withRole(profile.getRole()).withQueue(profile.getQueue());
logger.info("Starting transcode job of file {0} for site {1}", filename, site);
CreateJobResult createJobResult = mediaConvertClient.createJob(createJobRequest);
logger.debug("Job {0} started", createJobResult.getJob().getArn());
return buildResult(jobTemplate, createJobResult, outputProfileId, originalName);
}
use of org.craftercms.studio.api.v1.exception.AwsException in project studio by craftercms.
the class AwsS3ServiceImpl method listItems.
/**
* {@inheritDoc}
*/
@Override
@HasPermission(type = DefaultPermission.class, action = "s3 read")
public List<S3Item> listItems(@ValidateStringParam(name = "siteId") @ProtectedResourceId("siteId") String siteId, @ValidateStringParam(name = "profileId") String profileId, @ValidateStringParam(name = "path") String path, @ValidateStringParam(name = "type") String type) throws AwsException {
S3Profile profile = getProfile(siteId, profileId);
AmazonS3 client = getS3Client(profile);
List<S3Item> items = new LinkedList<>();
Mimetypes mimetypes = Mimetypes.getInstance();
MimeType filerType = StringUtils.isEmpty(type) || StringUtils.equals(type, ITEM_FILTER) ? MimeTypeUtils.ALL : new MimeType(type);
String prefix = StringUtils.isEmpty(path) ? path : normalizePrefix(path);
ListObjectsV2Request request = new ListObjectsV2Request().withBucketName(profile.getBucketName()).withPrefix(prefix).withDelimiter(delimiter);
ListObjectsV2Result result;
do {
result = client.listObjectsV2(request);
result.getCommonPrefixes().stream().map(p -> new S3Item(StringUtils.removeEnd(StringUtils.removeStart(p, prefix), delimiter), p, true)).forEach(items::add);
result.getObjectSummaries().stream().filter(o -> !StringUtils.equals(o.getKey(), prefix) && MimeType.valueOf(mimetypes.getMimetype(o.getKey())).isCompatibleWith(filerType)).map(o -> new S3Item(StringUtils.removeStart(o.getKey(), prefix), createUrl(profileId, o.getKey()), false)).forEach(items::add);
request.setContinuationToken(result.getNextContinuationToken());
} while (result.isTruncated());
return items;
}
use of org.craftercms.studio.api.v1.exception.AwsException in project studio by craftercms.
the class ElasticTranscoderServiceImpl method transcodeFile.
@Override
@ValidateParams
public TranscoderJob transcodeFile(@ValidateStringParam(name = "site") String site, @ValidateStringParam(name = "profileId") String profileId, @ValidateStringParam(name = "filename") String filename, InputStream content) throws AwsException {
TranscoderProfile profile = getProfile(site, profileId);
TranscoderJob job = transcoder.startJob(filename, content, profile);
return job;
}
use of org.craftercms.studio.api.v1.exception.AwsException in project studio by craftercms.
the class ElasticTranscoderImpl method startJob.
@Override
public TranscoderJob startJob(String filename, InputStream content, TranscoderProfile profile) throws AwsException {
try {
AmazonS3 s3Client = getS3Client(profile);
AmazonElasticTranscoder transcoderClient = getTranscoderClient(profile);
Pipeline pipeline = getPipeline(profile.getPipelineId(), transcoderClient);
String baseKey = FilenameUtils.removeExtension(filename) + "/" + UUID.randomUUID().toString();
String inputKey = baseKey + "." + FilenameUtils.getExtension(filename);
uploadInput(inputKey, filename, content, pipeline, s3Client);
CreateJobResult jobResult = createJob(inputKey, baseKey, profile, transcoderClient);
return createResult(baseKey, jobResult, pipeline);
} catch (Exception e) {
throw new AwsException("Error while attempting to start an AWS Elastic Transcoder job for file " + filename, e);
}
}
use of org.craftercms.studio.api.v1.exception.AwsException in project studio by craftercms.
the class S3ServiceImpl method uploadFile.
@Override
public S3Output uploadFile(@ValidateStringParam(name = "site") String site, @ValidateStringParam(name = "profileId") String profileId, @ValidateStringParam(name = "filename") String filename, InputStream content) throws AwsException {
S3Profile profile = getProfile(site, profileId);
AmazonS3 s3Client = getS3Client(profile);
String inputBucket = profile.getBucketName();
String inputKey = filename;
AwsUtils.uploadStream(inputBucket, inputKey, s3Client, partSize, filename, content);
S3Output output = new S3Output();
output.setBucket(inputBucket);
output.setKey(inputKey);
return output;
}
Aggregations