private void write(final DistributionConfiguration feature, final Path file) throws BackgroundException { feature.write(file, configuration, prompt); }
@Override public String getName(Distribution.Method method) { return method.toString(); }
@Override public Distribution initialize() { return new Distribution(method, false); }
@Override public DescriptiveUrlBag toUrl(final Path file) { final Distribution distribution = new Distribution(URI.create(String.format("%s://%s.%s", Distribution.DOWNLOAD.getScheme(), containerService.getContainer(file).getName(), this.getHostname())), Distribution.DOWNLOAD, false); distribution.setUrl(URI.create(String.format("%s://%s.%s", Distribution.DOWNLOAD.getScheme(), containerService.getContainer(file).getName(), this.getHostname()))); return new DistributionUrlProvider(distribution).toUrl(file); }
@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); } })); } }
@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; }
/** * @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; } }
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())); }
@Override public Distribution run(final Session<?> session) throws BackgroundException { final DistributionConfiguration cdn = session.getFeature(DistributionConfiguration.class); for(Path file : this.getContainers(files)) { if(this.isCanceled()) { throw new ConnectionCanceledException(); } final Distribution distribution = cdn.read(file, method, prompt); if(cdn.getFeature(Index.class, distribution.getMethod()) != null) { // Make sure container items are cached for default root object. distribution.setRootDocuments(session.getFeature(ListService.class).list(containerService.getContainer(file), new DisabledListProgressListener()).toList()); } return distribution; } return this.initialize(); }
@Override protected Map<Path, Distribution> operate(final PasswordCallback callback, final Path file) throws BackgroundException { final DistributionConfiguration feature = session.getFeature(DistributionConfiguration.class); if(null == feature) { return Collections.emptyMap(); } final AttributedList<Path> containers = new S3BucketListService(session, new S3LocationFeature.S3Region(session.getHost().getRegion())).list(file, new DisabledListProgressListener()); final Map<Path, Distribution> distributions = new ConcurrentHashMap<>(); for(Path container : containers) { for(Distribution.Method method : feature.getMethods(container)) { if(Distribution.WEBSITE.equals(method)) { continue; } if(Distribution.WEBSITE_CDN.equals(method)) { continue; } final Distribution distribution = feature.read(container, method, new DisabledLoginCallback()); if(distribution.isEnabled()) { if(log.isInfoEnabled()) { log.info(String.format("Cache distribution %s", distribution)); } distributions.put(container, distribution); } } } return distributions; } }
@Override public DescriptiveUrlBag toUrl(final Path file) { final Path container = containerService.getContainer(file); if(distributions.containsKey(container)) { return new DistributionUrlProvider(distributions.get(container)).toUrl(file); } return DescriptiveUrlBag.empty(); }
public int getDefaultPort() { return this.getScheme().getPort(); }
@Override public Boolean run(final Session<?> session) throws BackgroundException { final DistributionConfiguration cdn = session.getFeature(DistributionConfiguration.class); final Purge feature = cdn.getFeature(Purge.class, method); for(Path file : this.getContainers(files)) { if(this.isCanceled()) { throw new ConnectionCanceledException(); } feature.invalidate(file, method, files, prompt); } return true; }
@Override protected List<DescriptiveUrl> getURLs(final Path selected) { final ArrayList<DescriptiveUrl> list = new ArrayList<DescriptiveUrl>(); final SessionPool pool = this.getSession(); final UrlProvider provider = pool.getFeature(UrlProvider.class); if(provider != null) { list.addAll(provider.toUrl(selected)); } final DistributionConfiguration feature = pool.getFeature(DistributionConfiguration.class); if(feature != null) { list.addAll(feature.toUrl(selected)); } return list; }
@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 deleteStreamingDistribution(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.deleteStreamingDistribution(new DeleteStreamingDistributionRequest(distribution.getId(), distribution.getEtag())); }
@Override public DescriptiveUrlBag toUrl(final Path file) { if(distributions.containsKey(containerService.getContainer(file))) { return new DistributionUrlProvider(distributions.get(containerService.getContainer(file))).toUrl(file); } return DescriptiveUrlBag.empty(); }
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); } }
@Override protected List<DescriptiveUrl> getURLs(final Path selected) { final ArrayList<DescriptiveUrl> list = new ArrayList<DescriptiveUrl>(); final SessionPool pool = this.getSession(); final UrlProvider provider = pool.getFeature(UrlProvider.class); if(provider != null) { list.addAll(provider.toUrl(selected).filter( DescriptiveUrl.Type.http, DescriptiveUrl.Type.cname, DescriptiveUrl.Type.cdn, DescriptiveUrl.Type.signed, DescriptiveUrl.Type.authenticated, DescriptiveUrl.Type.torrent)); } final DistributionConfiguration feature = pool.getFeature(DistributionConfiguration.class); if(feature != null) { list.addAll(feature.toUrl(selected)); } return list; }
@Override public String getName(final Distribution.Method method) { if(method.equals(Distribution.WEBSITE)) { return method.toString(); } return super.getName(method); }