Example usage for com.amazonaws.services.cloudfront AmazonCloudFront getStreamingDistributionConfig

List of usage examples for com.amazonaws.services.cloudfront AmazonCloudFront getStreamingDistributionConfig

Introduction

In this page you can find the example usage for com.amazonaws.services.cloudfront AmazonCloudFront getStreamingDistributionConfig.

Prototype

GetStreamingDistributionConfigResult getStreamingDistributionConfig(
        GetStreamingDistributionConfigRequest getStreamingDistributionConfigRequest);

Source Link

Document

Get the configuration information about a streaming distribution.

Usage

From source file:ch.cyberduck.core.cloudfront.CloudFrontDistributionConfiguration.java

License:Open Source License

protected UpdateStreamingDistributionResult updateStreamingDistribution(final Path container,
        final Distribution distribution) throws IOException, BackgroundException {
    final URI origin = this.getOrigin(container, distribution.getMethod());
    if (log.isDebugEnabled()) {
        log.debug(String.format("Update %s distribution with origin %s", distribution.getMethod().toString(),
                origin));// w ww  . j  av  a  2s.  c om
    }
    final AmazonCloudFront client = client(container);
    final GetStreamingDistributionConfigResult response = client
            .getStreamingDistributionConfig(new GetStreamingDistributionConfigRequest(distribution.getId()));
    final StreamingDistributionConfig config = response.getStreamingDistributionConfig()
            .withEnabled(distribution.isEnabled())
            .withS3Origin(new S3Origin(origin.getHost(), StringUtils.EMPTY)).withAliases(new Aliases()
                    .withItems(distribution.getCNAMEs()).withQuantity(distribution.getCNAMEs().length));
    if (distribution.isLogging()) {
        // Make bucket name fully qualified
        final String loggingTarget = ServiceUtils.generateS3HostnameForBucket(
                distribution.getLoggingContainer(), false, new S3Protocol().getDefaultHostname());
        if (log.isDebugEnabled()) {
            log.debug(String.format("Set logging target for %s to %s", distribution, loggingTarget));
        }
        config.setLogging(new StreamingLoggingConfig().withEnabled(distribution.isLogging())
                .withBucket(loggingTarget).withPrefix(preferences.getProperty("cloudfront.logging.prefix")));
    }
    return client.updateStreamingDistribution(
            new UpdateStreamingDistributionRequest(config, distribution.getId(), response.getETag()));
}

From source file:ch.cyberduck.core.cloudfront.CloudFrontDistributionConfiguration.java

License:Open Source License

private Distribution readStreamingDistribution(final AmazonCloudFront client,
        final StreamingDistributionSummary summary, final Path container, final Distribution.Method method)
        throws BackgroundException {
    // Retrieve distributions configuration to access current logging status settings.
    try {/* w  w w. j ava  2 s .  c  o  m*/
        final GetStreamingDistributionConfigResult response = client
                .getStreamingDistributionConfig(new GetStreamingDistributionConfigRequest(summary.getId()));
        final StreamingDistributionConfig configuration = response.getStreamingDistributionConfig();
        final Distribution distribution = new Distribution(this.getOrigin(container, method), method,
                summary.isEnabled());
        distribution.setId(summary.getId());
        distribution.setDeployed("Deployed".equals(summary.getStatus()));
        distribution.setUrl(URI.create(
                String.format("%s://%s%s", method.getScheme(), summary.getDomainName(), method.getContext())));
        distribution.setSslUrl(method.equals(Distribution.DOWNLOAD) || method.equals(Distribution.CUSTOM)
                ? URI.create(String.format("https://%s%s", summary.getDomainName(), method.getContext()))
                : null);
        distribution.setReference(configuration.getCallerReference());
        distribution.setEtag(response.getETag());
        distribution.setStatus(LocaleFactory.localizedString(summary.getStatus(), "S3"));
        distribution.setCNAMEs(configuration.getAliases().getItems()
                .toArray(new String[configuration.getAliases().getItems().size()]));
        distribution.setLogging(configuration.getLogging().isEnabled());
        distribution
                .setLoggingContainer(StringUtils.isNotBlank(configuration.getLogging().getBucket())
                        ? ServiceUtils.findBucketNameInHostname(configuration.getLogging().getBucket(),
                                new S3Protocol().getDefaultHostname())
                        : null);
        if (this.getFeature(Purge.class, method) != null) {
            distribution.setInvalidationStatus(this.readInvalidationStatus(client, distribution));
        }
        if (this.getFeature(DistributionLogging.class, method) != null) {
            try {
                distribution.setContainers(new S3BucketListService(session).list(
                        new Path(String.valueOf(Path.DELIMITER),
                                EnumSet.of(Path.Type.volume, Path.Type.directory)),
                        new DisabledListProgressListener()).toList());
            } catch (AccessDeniedException | InteroperabilityException e) {
                log.warn(String.format("Failure listing buckets. %s", e.getMessage()));
            }
        }
        return distribution;
    } catch (AmazonClientException e) {
        throw new AmazonServiceExceptionMappingService().map("Cannot read CDN configuration", e);
    }
}