Class RemoteTemplateStorage
java.lang.Object
eu.cloudnetservice.driver.template.defaults.RemoteTemplateStorage
- All Implemented Interfaces:
eu.cloudnetservice.common.Nameable,TemplateStorage,AutoCloseable
The default implementation of a template storage which pulls its information from a remote provider.
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ComponentInfoprivate final Stringprivate final NetworkClient -
Constructor Summary
ConstructorsConstructorDescriptionRemoteTemplateStorage(@NonNull String name, @NonNull ComponentInfo componentInfo, @NonNull NetworkClient networkClient) Constructs a new remote template storage instance. -
Method Summary
Modifier and TypeMethodDescriptionappendOutputStream(@NonNull ServiceTemplate template, @NonNull String path) Creates a new output stream which appends to the file at the given path in the given template in this storage.booleandeploy(@NonNull ServiceTemplate target, @NonNull InputStream inputStream) Deploys all files in the given input stream to the given target template.booleandeployDirectory(@NonNull ServiceTemplate target, @NonNull Path directory, @Nullable Predicate<Path> filter) Deploys all files in the given directory to the associated target in this template storage for the given template.name()newInputStream(@NonNull ServiceTemplate template, @NonNull String path) Opens a new input stream to read the content of the file at the given path in the given template in this storage.newOutputStream(@NonNull ServiceTemplate template, @NonNull String path) Creates a new output stream which overrides the content of the file at the given path in the given template in this storage.private @NonNull OutputStreamopenLocalOutputStream(@NonNull ServiceTemplate template, @NonNull String path, @NonNull Path localPath, boolean append) Opens a new output stream to a temporary local file which will be deployed to the remote component once the stream was closed.zipTemplate(@NonNull ServiceTemplate template) Pulls the data of the given template into a temporary directory and zip it.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface eu.cloudnetservice.driver.template.TemplateStorage
appendOutputStreamAsync, close, closeAsync, contains, containsAsync, create, createAsync, createDirectory, createDirectoryAsync, createFile, createFileAsync, delete, deleteAsync, deleteFile, deleteFileAsync, deployAsync, deployDirectory, deployDirectoryAsync, deployDirectoryAsync, fileInfo, fileInfoAsync, hasFile, hasFileAsync, listFiles, listFilesAsync, newInputStreamAsync, newOutputStreamAsync, openZipInputStream, openZipInputStreamAsync, pull, pullAsync, templates, templatesAsync, zipTemplateAsync
-
Field Details
-
name
-
componentInfo
-
networkClient
-
-
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
- Specified by:
namein interfaceeu.cloudnetservice.common.Nameable
-
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:
deployDirectoryin interfaceTemplateStorage- 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:
deployin interfaceTemplateStorage- 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
@Nullable public @Nullable InputStream zipTemplate(@NonNull @NonNull ServiceTemplate template) throws IOException 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 usingTemplateStorage.openZipInputStream(ServiceTemplate)instead.When the returned input stream is closed the created temporary zip file will be deleted automatically.
- Specified by:
zipTemplatein interfaceTemplateStorage- 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:
appendOutputStreamin interfaceTemplateStorage- 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
@NonNull public @NonNull OutputStream newOutputStream(@NonNull @NonNull ServiceTemplate template, @NonNull @NonNull String path) throws IOException 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:
newOutputStreamin interfaceTemplateStorage- 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
@Nullable public @Nullable InputStream newInputStream(@NonNull @NonNull ServiceTemplate template, @NonNull @NonNull String path) throws IOException 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:
newInputStreamin interfaceTemplateStorage- 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.
-