Class RemoteTemplateStorage

java.lang.Object
eu.cloudnetservice.driver.template.defaults.RemoteTemplateStorage
All Implemented Interfaces:
eu.cloudnetservice.common.Named, TemplateStorage, AutoCloseable

public abstract class RemoteTemplateStorage extends Object implements TemplateStorage
The default implementation of a template storage which pulls its information from a remote provider.
Since:
4.0
  • Field Details

  • Constructor Details

    • RemoteTemplateStorage

      public RemoteTemplateStorage(@NonNull @NonNull String name, @NonNull @NonNull ComponentInfo componentInfo, @NonNull @NonNull NetworkClient networkClient)
      Constructs a new remote template storage instance.
      Parameters:
      name - the name of the storage which was created.
      componentInfo - the information about the current component.
      networkClient - the network client of the current component.
      Throws:
      NullPointerException - if the given name, component info or network client is null.
  • Method Details

    • name

      @NonNull public @NonNull String name()
      Specified by:
      name in interface eu.cloudnetservice.common.Named
    • deployDirectory

      public boolean deployDirectory(@NonNull @NonNull ServiceTemplate target, @NonNull @NonNull Path directory, @Nullable @Nullable Predicate<Path> filter)
      Deploys all files in the given directory to the associated target in this template storage for the given template. All files in the directory will be passed to the given filter, if present. If the filter returns false for a path the file or directory will not be deployed into the storage.
      Specified by:
      deployDirectory in interface TemplateStorage
      Parameters:
      target - the template to deploy the directory to.
      directory - the directory to deploy to the storage.
      filter - an optional filter which can be used to filter out files which shouldn't get deployed.
      Returns:
      true if the operation completed successfully, false otherwise.
    • deploy

      public boolean deploy(@NonNull @NonNull ServiceTemplate target, @NonNull @NonNull InputStream inputStream)
      Deploys all files in the given input stream to the given target template. The given input stream is expected to be backed by a zip file, each entry of that zip file will be deployed. If anything else than a stream of a zip file is given to this method it will either not deploy anything or fail with an exception.
      Specified by:
      deploy in interface TemplateStorage
      Parameters:
      target - the template to deploy the data inside the zip file to.
      inputStream - the stream to the zip file which should be deployed.
      Returns:
      true if the operation completed successfully, false otherwise.
    • zipTemplate

      Pulls the data of the given template into a temporary directory and zip it. The returned input stream is a stream which can read from the created zip file but is not necessarily a zip input stream. If you specifically want a zip input stream consider using TemplateStorage.openZipInputStream(ServiceTemplate) instead.

      When the returned input stream is closed the created temporary zip file will be deleted automatically.

      Specified by:
      zipTemplate in interface TemplateStorage
      Parameters:
      template - the template to download and zip.
      Returns:
      a stream which reads from the pulled and zipped template file, null if the template doesn't exist.
      Throws:
      IOException - if an I/O error occurred while zipping the template data.
    • appendOutputStream

      @NonNull public @NonNull OutputStream appendOutputStream(@NonNull @NonNull ServiceTemplate template, @NonNull @NonNull String path) throws IOException
      Creates a new output stream which appends to the file at the given path in the given template in this storage. If the file at the given path doesn't exist already it will be created automatically. After all the content was written to the given output stream it must be closed in order to persist your changes in this storage.
      Specified by:
      appendOutputStream in interface TemplateStorage
      Parameters:
      template - the template in which the file to append to is located.
      path - the path to the file in the given template to open the append-stream for.
      Returns:
      an output stream which appends to the given file in the given template.
      Throws:
      IOException - if an I/O error occurred.
    • newOutputStream

      Creates a new output stream which overrides the content of the file at the given path in the given template in this storage. If the file at the given path doesn't exist already it will be created automatically. After all the content was written to the given output stream it must be closed in order to persist your changes in this storage.
      Specified by:
      newOutputStream in interface TemplateStorage
      Parameters:
      template - the template in which the file to write to is located.
      path - the path to the file in the given template to open the stream for.
      Returns:
      an output stream which overrides to the given file in the given template.
      Throws:
      IOException - if an I/O error occurred.
    • openLocalOutputStream

      @NonNull private @NonNull OutputStream openLocalOutputStream(@NonNull @NonNull ServiceTemplate template, @NonNull @NonNull String path, @NonNull @NonNull Path localPath, boolean append) throws IOException
      Opens a new output stream to a temporary local file which will be deployed to the remote component once the stream was closed.
      Parameters:
      template - the template in which the file to open the stream for is located.
      path - the path to the file in the given template for which the stream was opened.
      localPath - the local path to the file which should be used as a temporary location to write to.
      append - if the stream should append to the content in the remote file.
      Returns:
      a new output stream which writes to a local temp files and deploys its data once closed.
      Throws:
      IOException - if an I/O error occurs while opening the stream.
      NullPointerException - if one of the given parameters is null.
    • newInputStream

      Opens a new input stream to read the content of the file at the given path in the given template in this storage. This method returns null if either the file doesn't exist or is a directory.
      Specified by:
      newInputStream in interface TemplateStorage
      Parameters:
      template - the template in which the file to read is located in.
      path - the path to the file in the template to read.
      Returns:
      a new input stream to read the content of the file at the given path, null if the file isn't readable.
      Throws:
      IOException - if an I/O error occurred.