@Override public void write( boolean enabled, String origin, Distribution.Method method, String[] cnames, boolean logging, String loggingBucket, String defaultRootObject) { try { this.check(); // Configure CDN LoggingStatus loggingStatus = null; if (logging) { if (this.isLoggingSupported(method)) { final String loggingDestination = StringUtils.isNotBlank(loggingBucket) ? ServiceUtils.generateS3HostnameForBucket( loggingBucket, false, Protocol.S3_SSL.getDefaultHostname()) : origin; loggingStatus = new LoggingStatus( loggingDestination, Preferences.instance().getProperty("cloudfront.logging.prefix")); } } StringBuilder name = new StringBuilder(Locale.localizedString("Amazon CloudFront", "S3")) .append(" ") .append(method.toString()); if (enabled) { this.message( MessageFormat.format( Locale.localizedString("Enable {0} Distribution", "Status"), name)); } else { this.message( MessageFormat.format( Locale.localizedString("Disable {0} Distribution", "Status"), name)); } Distribution d = distributionStatus.get(method).get(origin); if (null == d) { if (log.isDebugEnabled()) { log.debug(String.format("No existing distribution found for method %s", method)); } this.createDistribution(enabled, method, origin, cnames, loggingStatus, defaultRootObject); } else { boolean modified = false; if (d.isEnabled() != enabled) { modified = true; } if (!Arrays.equals(d.getCNAMEs(), cnames)) { modified = true; } if (d.isLogging() != logging) { modified = true; } // Compare default root object for possible change if (!StringUtils.equals(d.getDefaultRootObject(), defaultRootObject)) { modified = true; } // Compare logging target for possible change if (!StringUtils.equals(d.getLoggingTarget(), loggingBucket)) { modified = true; } if (modified) { this.updateDistribution( enabled, method, origin, d.getId(), d.getEtag(), d.getReference(), cnames, loggingStatus, defaultRootObject); } else { log.info("Skip updating distribution not modified."); } } } catch (CloudFrontServiceException e) { this.error("Cannot write CDN configuration", e); } catch (IOException e) { this.error("Cannot write CDN configuration", e); } finally { distributionStatus.get(method).clear(); } }