Search in sources :

Example 1 with AwsException

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);
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) AWSMediaConvert(com.amazonaws.services.mediaconvert.AWSMediaConvert) Input(com.amazonaws.services.mediaconvert.model.Input) CreateJobResult(com.amazonaws.services.mediaconvert.model.CreateJobResult) JobSettings(com.amazonaws.services.mediaconvert.model.JobSettings) MediaConvertProfile(org.craftercms.studio.api.v1.aws.mediaconvert.MediaConvertProfile) GetJobTemplateRequest(com.amazonaws.services.mediaconvert.model.GetJobTemplateRequest) JobTemplate(com.amazonaws.services.mediaconvert.model.JobTemplate) CreateJobRequest(com.amazonaws.services.mediaconvert.model.CreateJobRequest) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Example 2 with AwsException

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;
}
Also used : S3Item(org.craftercms.studio.model.aws.s3.S3Item) AwsUtils(org.craftercms.studio.impl.v1.service.aws.AwsUtils) S3Item(org.craftercms.studio.model.aws.s3.S3Item) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission) AbstractAwsService(org.craftercms.studio.api.v1.service.aws.AbstractAwsService) AwsS3Service(org.craftercms.studio.api.v2.service.aws.s3.AwsS3Service) S3Profile(org.craftercms.commons.config.profiles.aws.S3Profile) StringUtils.stripStart(org.apache.commons.lang3.StringUtils.stripStart) ProtectedResourceId(org.craftercms.commons.security.permissions.annotations.ProtectedResourceId) MimeTypeUtils(org.springframework.util.MimeTypeUtils) StringUtils.appendIfMissing(org.apache.commons.lang3.StringUtils.appendIfMissing) StringUtils(org.apache.commons.lang3.StringUtils) ListObjectsV2Result(com.amazonaws.services.s3.model.ListObjectsV2Result) MimeType(org.springframework.util.MimeType) ListObjectsV2Request(com.amazonaws.services.s3.model.ListObjectsV2Request) AwsException(org.craftercms.studio.api.v1.exception.AwsException) List(java.util.List) Mimetypes(com.amazonaws.services.s3.internal.Mimetypes) S3ClientCachingFactory(org.craftercms.commons.aws.S3ClientCachingFactory) AmazonS3(com.amazonaws.services.s3.AmazonS3) DefaultPermission(org.craftercms.commons.security.permissions.DefaultPermission) Required(org.springframework.beans.factory.annotation.Required) ValidateStringParam(org.craftercms.commons.validation.annotations.param.ValidateStringParam) LinkedList(java.util.LinkedList) InputStream(java.io.InputStream) AmazonS3(com.amazonaws.services.s3.AmazonS3) ListObjectsV2Request(com.amazonaws.services.s3.model.ListObjectsV2Request) ListObjectsV2Result(com.amazonaws.services.s3.model.ListObjectsV2Result) Mimetypes(com.amazonaws.services.s3.internal.Mimetypes) S3Profile(org.craftercms.commons.config.profiles.aws.S3Profile) LinkedList(java.util.LinkedList) MimeType(org.springframework.util.MimeType) HasPermission(org.craftercms.commons.security.permissions.annotations.HasPermission)

Example 3 with AwsException

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;
}
Also used : TranscoderProfile(org.craftercms.studio.api.v1.aws.elastictranscoder.TranscoderProfile) TranscoderJob(org.craftercms.studio.api.v1.aws.elastictranscoder.TranscoderJob) ValidateParams(org.craftercms.commons.validation.annotations.param.ValidateParams)

Example 4 with AwsException

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);
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) CreateJobResult(com.amazonaws.services.elastictranscoder.model.CreateJobResult) AmazonElasticTranscoder(com.amazonaws.services.elastictranscoder.AmazonElasticTranscoder) AwsException(org.craftercms.studio.api.v1.exception.AwsException) AwsException(org.craftercms.studio.api.v1.exception.AwsException) Pipeline(com.amazonaws.services.elastictranscoder.model.Pipeline)

Example 5 with AwsException

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;
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) S3Output(org.craftercms.studio.api.v1.aws.s3.S3Output) S3Profile(org.craftercms.commons.config.profiles.aws.S3Profile)

Aggregations

AmazonS3 (com.amazonaws.services.s3.AmazonS3)4 AwsException (org.craftercms.studio.api.v1.exception.AwsException)3 LinkedList (java.util.LinkedList)2 S3Profile (org.craftercms.commons.config.profiles.aws.S3Profile)2 HasPermission (org.craftercms.commons.security.permissions.annotations.HasPermission)2 AmazonElasticTranscoder (com.amazonaws.services.elastictranscoder.AmazonElasticTranscoder)1 CreateJobResult (com.amazonaws.services.elastictranscoder.model.CreateJobResult)1 Pipeline (com.amazonaws.services.elastictranscoder.model.Pipeline)1 AWSMediaConvert (com.amazonaws.services.mediaconvert.AWSMediaConvert)1 CreateJobRequest (com.amazonaws.services.mediaconvert.model.CreateJobRequest)1 CreateJobResult (com.amazonaws.services.mediaconvert.model.CreateJobResult)1 GetJobTemplateRequest (com.amazonaws.services.mediaconvert.model.GetJobTemplateRequest)1 Input (com.amazonaws.services.mediaconvert.model.Input)1 JobSettings (com.amazonaws.services.mediaconvert.model.JobSettings)1 JobTemplate (com.amazonaws.services.mediaconvert.model.JobTemplate)1 Mimetypes (com.amazonaws.services.s3.internal.Mimetypes)1 ListObjectsV2Request (com.amazonaws.services.s3.model.ListObjectsV2Request)1 ListObjectsV2Result (com.amazonaws.services.s3.model.ListObjectsV2Result)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1