Class CdnData


public class CdnData extends Object
Currently implemented directly in the filesystem, leveraging Csync2 in multi-master mode for replication.

TODO: Have a central warnings/errors structure. Warnings by path for things that are anamolous (spelling), such as resource hash directories with unexpected names. Warnings for things failed to auto-cleanup. Errors by path for csync2 failures, could initialize state from a csync2 -t test. Could background re-test either all csync2 or paths with known synchronization failures. Could integrated into status page (or status.json). Could integrated into AO monitoring.

  • Field Details


      public static final char EXTENSION_SEPARATOR
      The separator character to go between the resource or filename and the extension. This is used internally in the filesystem and externally in the URL.
      See Also:
  • Constructor Details

    • CdnData

      public CdnData(Path cdnRoot, String csync2Group, boolean isUploader) throws IOException
      Creates a new CDN data accessor. An fsck() is performed immediately in start-up mode. Any issue that is severe or higher will cause the CDN to fail by throwing IOException.
      cdnRoot - The directory that contains the underlying CDN data. This should not be in the web root directly, but instead should be mapped into Tomcat via the <PreResource> mechanism. The front-end component will dispatch to the resource after URL rewriting and access control. Back-end components interact with this CDN data directly.
      csync2Group - The Csync2 group to be synchronized after each change. When null empty (after trimming), no synchronization is performed.
      isUploader - Is this the uploader instance of cdn-data, which is responsible for introducing entirely new resources?
      IOException - When CDN start-up fsck() fails.
      See Also:
  • Method Details

    • toString

      public String toString()
      toString in class Object
    • fsck

      public Map<Path,FsckIssue> fsck()
      Performs a non-startup fsck of this CDN data.
      Unmodifiable map of issues
    • getResources

      public Resources getResources()
      Gets the resources handler for this CDN.
    • getUploads

      public Uploads getUploads() throws IllegalStateException
      Gets the uploads handler for this CDN.
      IllegalStateException - when this CDN data upload is disabled.
    • findOrAdd

      public Version findOrAdd(UploadFile uploadFile) throws IOException, IllegalArgumentException
      Stores a new file in CDN data.

      First searches all existing resources for a match, including matching derived resources. A full byte-by-byte check is performed.

      When a match is found, the existing resource is returned. This means that a higher quality resource may be returned than the one requested.

      uploadFile - This underlying file should have been returned from Uploads.createUploadFile( If a different file is used, it may not have correct permissions and also may not be able to be moved into place efficiently.

      The underlying file must have an extension matching the expected extension for the type.

      This underlying file must not be changed after being stored. Doing so may corrupted the underlying CDN data.

      The resource, whether found existing or stored new. This resource will be equivalent to, or higher quality, than the requested resource. Furthermore, the requested resource is guaranteed to be immediately available at its specific resolution without any on-demand scaling.
      IllegalArgumentException - if the upload file is from a different CDN data instance, if the upload file has already been stored, or if the upload file has an incorrect extension
      See Also: