Example usage for com.amazonaws.services.cloudfront.model GetDistributionConfigRequest GetDistributionConfigRequest

List of usage examples for com.amazonaws.services.cloudfront.model GetDistributionConfigRequest GetDistributionConfigRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.cloudfront.model GetDistributionConfigRequest GetDistributionConfigRequest.

Prototype

public GetDistributionConfigRequest(String id) 

Source Link

Document

Constructs a new GetDistributionConfigRequest object.

Usage

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

License:Open Source License

/**
 * Amazon CloudFront Extension used to enable or disable a distribution configuration and its CNAMESs
 *//*from   w  ww  .  ja va 2s .co  m*/
protected UpdateDistributionResult updateDownloadDistribution(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));
    }
    final AmazonCloudFront client = client(container);
    final GetDistributionConfigResult response = client
            .getDistributionConfig(new GetDistributionConfigRequest(distribution.getId()));
    final DistributionConfig config = response.getDistributionConfig().withEnabled(distribution.isEnabled())
            .withDefaultRootObject(distribution.getIndexDocument()).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 LoggingConfig().withEnabled(distribution.isLogging()).withIncludeCookies(true)
                .withBucket(loggingTarget).withPrefix(preferences.getProperty("cloudfront.logging.prefix")));
    }
    return client.updateDistribution(
            new UpdateDistributionRequest(config, distribution.getId(), response.getETag()));
}

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

License:Open Source License

protected UpdateDistributionResult updateCustomDistribution(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));/* www. j a va  2s.  co m*/
    }
    final AmazonCloudFront client = client(container);
    final GetDistributionConfigResult response = client
            .getDistributionConfig(new GetDistributionConfigRequest(distribution.getId()));
    final DistributionConfig config = response.getDistributionConfig().withEnabled(distribution.isEnabled())
            .withDefaultRootObject(distribution.getIndexDocument() != null ? distribution.getIndexDocument()
                    : StringUtils.EMPTY)
            .withAliases(new Aliases().withItems(distribution.getCNAMEs())
                    .withQuantity(distribution.getCNAMEs().length));
    // 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 LoggingConfig().withEnabled(distribution.isLogging()).withIncludeCookies(true)
            .withBucket(loggingTarget).withPrefix(preferences.getProperty("cloudfront.logging.prefix")));
    return client.updateDistribution(
            new UpdateDistributionRequest(config, distribution.getId(), response.getETag()));
}

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

License:Open Source License

private Distribution readDownloadDistribution(final AmazonCloudFront client, final DistributionSummary summary,
        final Path container, final Distribution.Method method) throws BackgroundException {
    // Retrieve distributions configuration to access current logging status settings.
    try {/*from www  .j  a  v a2s  .co  m*/
        final GetDistributionConfigResult response = client
                .getDistributionConfig(new GetDistributionConfigRequest(summary.getId()));
        final DistributionConfig configuration = response.getDistributionConfig();
        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 (StringUtils.isNotBlank(configuration.getDefaultRootObject())) {
            distribution.setIndexDocument(configuration.getDefaultRootObject());
        }
        if (this.getFeature(Purge.class, method) != null) {
            distribution.setInvalidationStatus(this.readInvalidationStatus(client, distribution));
        }
        if (this.getFeature(DistributionLogging.class, method) != null) {
            distribution.setContainers(new S3BucketListService(session).list(
                    new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory)),
                    new DisabledListProgressListener()).toList());
        }
        return distribution;
    } catch (AmazonClientException e) {
        throw new AmazonServiceExceptionMappingService().map("Cannot read CDN configuration", e);
    }
}

From source file:org.duracloud.s3task.streaminghls.BaseHlsTaskRunner.java

License:Apache License

/**
 * Enables or disables an existing distribution
 *
 * @param distId  the ID of the distribution
 * @param enabled true to enable, false to disable
 *//*from   www  .ja va2  s.c  o  m*/
protected void setDistributionState(String distId, boolean enabled) {
    GetDistributionConfigResult result = cfClient
            .getDistributionConfig(new GetDistributionConfigRequest(distId));

    DistributionConfig distConfig = result.getDistributionConfig();
    distConfig.setEnabled(enabled);

    cfClient.updateDistribution(new UpdateDistributionRequest().withDistributionConfig(distConfig)
            .withIfMatch(result.getETag()).withId(distId));
}

From source file:org.duracloud.s3task.streaminghls.DeleteHlsTaskRunner.java

License:Apache License

private void waitAndDelete(String distId) {
    // Wait for the distribution to be disabled
    waitForDisabled(distId);/*  ww w.  j  a  v a 2s  . c  om*/

    // Delete the distribution
    GetDistributionConfigResult result = cfClient
            .getDistributionConfig(new GetDistributionConfigRequest(distId));
    cfClient.deleteDistribution(new DeleteDistributionRequest().withId(distId).withIfMatch(result.getETag()));
}