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());
public static Method forName(final String name) { if(DOWNLOAD.toString().equals(name)) { return DOWNLOAD; } if(STREAMING.toString().equals(name)) { return STREAMING; } if(CUSTOM.toString().equals(name)) { return CUSTOM; } if(WEBSITE.toString().equals(name)) { return WEBSITE; } if(WEBSITE_CDN.toString().equals(name)) { return WEBSITE_CDN; } throw new FactoryException(name); } }
final Path file = this.getSelected(); final Distribution.Method method = Distribution.Method.forName(distributionDeliveryPopup.selectedItem().representedObject()); controller.background(new WorkerBackgroundAction<Distribution>(controller, session, new ReadDistributionWorker(files, prompt, method) { @Override
distributionAnalyticsSetupUrlField.setAttributedStringValue( HyperlinkAttributedStringFactory.create(analyticsFeature.getSetup(cdn.getHostname(), distribution.getMethod().getScheme(), file, credentials)) );
Distribution.Method method = Distribution.Method.forName(distributionDeliveryPopup.selectedItem().representedObject()); distributionEnableButton.setEnabled(stop && enable); distributionDeliveryPopup.setEnabled(stop && enable);
protected com.amazonaws.services.cloudfront.model.Distribution createDownloadDistribution(final Path container, final Distribution distribution) throws BackgroundException { if(log.isDebugEnabled()) { log.debug(String.format("Create new %s distribution", distribution.getMethod().toString()));
distributionDeliveryPopup.removeItemWithTitle(LocaleFactory.localizedString("None")); for(Distribution.Method method : cdn.getMethods(file)) { distributionDeliveryPopup.addItemWithTitle(method.toString()); distributionDeliveryPopup.itemWithTitle(method.toString()).setRepresentedObject(method.toString()); distributionDeliveryPopup.selectItemWithTitle(method.toString());
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));
throws BackgroundException { if(log.isDebugEnabled()) { log.debug(String.format("Create new %s distribution", distribution.getMethod().toString()));
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());
protected UpdateStreamingDistributionResult updateStreamingDistribution(final Path container, final Distribution distribution) throws 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 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())); }
@Override public Distribution read(final Path container, final Distribution.Method method, final LoginCallback prompt) throws BackgroundException { if(method.equals(Distribution.WEBSITE)) { try { final WebsiteConfig configuration = session.getClient().getWebsiteConfig(container.getName()); final Distribution distribution = new Distribution(this.getOrigin(container, method), method, configuration.isWebsiteConfigActive()); distribution.setStatus(LocaleFactory.localizedString("Deployed", "S3")); // http://example-bucket.s3-website-us-east-1.amazonaws.com/ distribution.setUrl(URI.create(String.format("%s://%s", method.getScheme(), this.getWebsiteHostname(container)))); distribution.setIndexDocument(configuration.getIndexDocumentSuffix()); distribution.setContainers(new S3BucketListService(session, new S3LocationFeature.S3Region(session.getHost().getRegion())).list( new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory)), new DisabledListProgressListener()).toList()); return distribution; } catch(ServiceException e) { // Not found. Website configuration not enabled. final Distribution distribution = new Distribution(this.getOrigin(container, method), method, false); distribution.setStatus(e.getErrorMessage()); distribution.setUrl(URI.create(String.format("%s://%s", method.getScheme(), this.getWebsiteHostname(container)))); return distribution; } } else { return super.read(container, method, prompt); } }
protected UpdateDistributionResult updateCustomDistribution(final Path container, final Distribution distribution) throws 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() != 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())); }
@Override public Distribution read(final Path file, final Distribution.Method method, final LoginCallback prompt) throws BackgroundException { final Path container = containerService.getContainer(file); final URI origin = URI.create(String.format("%s://%s.%s", method.getScheme(), container.getName(), this.getHostname())); try { final WebsiteConfig configuration = session.getClient().getWebsiteConfigImpl(container.getName()); final Distribution distribution = new Distribution( origin, method, configuration.isWebsiteConfigActive()); distribution.setUrl(URI.create(String.format("%s://%s.%s", method.getScheme(), container.getName(), this.getHostname()))); distribution.setStatus(LocaleFactory.localizedString("Deployed", "S3")); distribution.setIndexDocument(configuration.getIndexDocumentSuffix()); final DistributionLogging logging = this.getFeature(DistributionLogging.class, method); if(logging != null) { final LoggingConfiguration c = new GoogleStorageLoggingFeature(session).getConfiguration(container); distribution.setLogging(c.isEnabled()); distribution.setLoggingContainer(c.getLoggingTarget()); 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(ServiceException e) { // Not found. Website configuration is disabled. final Distribution distribution = new Distribution(origin, method, false); distribution.setStatus(e.getErrorMessage()); distribution.setUrl(URI.create(String.format("%s://%s.%s", method.getScheme(), container.getName(), this.getHostname()))); return distribution; } }
@Override public DescriptiveUrlBag toUrl(final Path file) { final DescriptiveUrlBag list = new DescriptiveUrlBag(); list.add(new DescriptiveUrl(this.toUrl(file, distribution.getOrigin()), DescriptiveUrl.Type.origin, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString("Origin", "Info")))); if(distribution.getUrl() != null) { list.add(new DescriptiveUrl(this.toUrl(file, distribution.getUrl()), DescriptiveUrl.Type.cdn, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString(distribution.getMethod().toString(), "S3")))); } if(distribution.getSslUrl() != null) { list.add(new DescriptiveUrl(this.toUrl(file, distribution.getSslUrl()), DescriptiveUrl.Type.cdn, String.format("%s (SSL)", MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString(distribution.getMethod().toString(), "S3"))))); } if(distribution.getStreamingUrl() != null) { list.add(new DescriptiveUrl(this.toUrl(file, distribution.getStreamingUrl()), DescriptiveUrl.Type.cdn, String.format("%s (Streaming)", MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString(distribution.getMethod().toString(), "S3"))))); } if(distribution.getiOSstreamingUrl() != null) { list.add(new DescriptiveUrl(this.toUrl(file, distribution.getiOSstreamingUrl()), DescriptiveUrl.Type.cdn, String.format("%s (iOS Streaming)", MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString(distribution.getMethod().toString(), "S3"))))); } list.addAll(this.toCnameUrl(file)); return list; }
@Action public void distributionApplyButtonClicked(final ID sender) { if(this.toggleDistributionSettings(false)) { final Distribution.Method method = Distribution.Method.forName(distributionDeliveryPopup.selectedItem().representedObject()); final Distribution configuration = new Distribution(method, distributionEnableButton.state() == NSCell.NSOnState); configuration.setIndexDocument(distributionDefaultRootPopup.selectedItem().representedObject()); configuration.setLogging(distributionLoggingButton.state() == NSCell.NSOnState); configuration.setLoggingContainer(distributionLoggingPopup.selectedItem().representedObject()); configuration.setCNAMEs(StringUtils.split(distributionCnameField.stringValue())); controller.background(new WorkerBackgroundAction<Boolean>(controller, session, new WriteDistributionWorker(files, prompt, configuration) { @Override public void cleanup(final Boolean result) { // Refresh the current distribution status distributionStatusButtonClicked(sender); } })); } }
/** * @param file File in origin container * @return CNAME to distribution */ private List<DescriptiveUrl> toCnameUrl(final Path file) { final List<DescriptiveUrl> urls = new ArrayList<DescriptiveUrl>(); for(String cname : distribution.getCNAMEs()) { final StringBuilder b = new StringBuilder(); b.append(String.format("%s://%s", distribution.getMethod().getScheme(), cname)).append(distribution.getMethod().getContext()); if(StringUtils.isNotEmpty(containerService.getKey(file))) { b.append(Path.DELIMITER).append(URIEncoder.encode(containerService.getKey(file))); } urls.add(new DescriptiveUrl(URI.create(b.toString()).normalize(), DescriptiveUrl.Type.cname, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), LocaleFactory.localizedString(distribution.getMethod().toString(), "S3")))); } return urls; } }
public int getDefaultPort() { return this.getScheme().getPort(); }
@Action public void distributionInvalidateObjectsButtonClicked(final ID sender) { if(this.toggleDistributionSettings(false)) { final Distribution.Method method = Distribution.Method.forName(distributionDeliveryPopup.selectedItem().representedObject()); controller.background(new WorkerBackgroundAction<Boolean>(controller, session, new DistributionPurgeWorker(files, prompt, method) { @Override public void cleanup(final Boolean result) { // Refresh the current distribution status distributionStatusButtonClicked(sender); } })); } }
protected void deleteDownloadDistribution(final Path container, final Distribution distribution) throws 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); client.deleteDistribution(new DeleteDistributionRequest(distribution.getId(), distribution.getEtag())); }