public interface ExportMigrationContext extends MigrationContext
The export migration context is provided to a Migratable
during the export migration
operation to give a migratable a chance to create new entries representing files or blobs of
information required for export. It also allows a migratable to indicate which system properties
are expected to reference files on disk that should also be migrated.
For example:
public class MyMigratable implements Migratable { ... public void doExport(ExportMigrationContext context) { // export a file located on disk context.getEntry(Paths.get("etc", "myfile.properties")) .store(); // export all files located under a specific sub-directory context.entries(Paths.get("etc", "subdir")) .forEach(ExportMigrationEntry::store); // export the file referenced from the "my.property" system property context.getSystemPropertyReferencedEntry("my.property") .ifPresent(ExportMigrationEntry::store); } ... }
This code is experimental. While this interface is functional and tested, it may change or be removed in a future version of the library.
Modifier and Type | Method and Description |
---|---|
Stream<ExportMigrationEntry> |
entries(Path path)
Recursively walks the provided path's tree to create or retrieve (if already created) entries
for all files found and returns existing or new migration entries for each one of them.
|
Stream<ExportMigrationEntry> |
entries(Path path,
PathMatcher filter)
Recursively walks the provided path's tree to create or retrieve (if already created) entries
for all files found that match the provided path filter and returns existing or new migration
entries for each one of them.
|
ExportMigrationEntry |
getEntry(Path path)
Creates or retrieves (if already created) a migration entry to be exported by the corresponding
migratable corresponding to the specified path.
|
default Optional<ExportMigrationEntry> |
getSystemPropertyReferencedEntry(String name)
Creates or retrieves (if already created) a migration entry referenced from the specified
system property to be exported by the corresponding migratable.
|
Optional<ExportMigrationEntry> |
getSystemPropertyReferencedEntry(String name,
BiPredicate<MigrationReport,String> validator)
Creates or retrieves (if already created) a migration entry referenced from the specified
system property to be exported by the corresponding migratable.
|
getId, getReport
default Optional<ExportMigrationEntry> getSystemPropertyReferencedEntry(String name)
An error will automatically be recorded with the associated migration report if the system property is not defined or its value is blank.
Note: The file referenced from the property is assumed to be relative to ${ddf.home} if not defined as absolute. All paths will automatically be relativized from ${ddf.home} if located underneath.
The entry returned would be an entry representing the file that was referenced by the specified system property value on the current system. For example:
If system properties defines the following mapping: javax.net.ssl.keyStore=etc/keystores/serverKeystore.jks
when the following code:
final Optional<ExportMigrationEntry> entry = context.getSystemPropertyReferenceEntry("javax.net.ssl.keyStore");
would return an entry representing the local file etc/keystores/serverKeystore.jks
giving the migratable a chance to export it alongside the original system property
value so it can be later restored and the property value can be verified after the import
operation such that it would still be defined with the same value.
name
- the name of the system property referencing a migration entry to create or retrieveIllegalArgumentException
- if name
is null
Optional<ExportMigrationEntry> getSystemPropertyReferencedEntry(String name, BiPredicate<MigrationReport,String> validator)
The provided predicate is always invoked (as long as the entry was not previously created)
to validate the property value which may be null
if not defined. Returning
false
will abort the process and yield an Optional.empty()
being returned out of
this method. In such case, it is up to the validator to record any required errors or warnings.
Returning true
from the predicate will allow for a new entry to be created for the
corresponding system property unless the property is not defined or its value is blank in which
case an error will be recorded and an Optional.empty()
is returned from this method. In
other words:
false
, no migration entry is created and no error
is recorded.
true
and ...
Note: The file referenced from the property is assumed to be relative to ${ddf.home} if not defined as absolute. All paths will automatically be relativized from ${ddf.home} if located underneath.
name
- the name of the system property referencing a migration entry to create or retrievevalidator
- a predicate to be invoked to validate the property value further which must
return true
to have a migration entry created and returnedIllegalArgumentException
- if name
or validator
is null
SecurityException
- if a security manager exists and its checkPropertyAccess()
method doesn't allow read access to the specified system propertyExportMigrationEntry getEntry(Path path)
Note: The file referenced is assumed to be relative to ${ddf.home} if not defined as absolute. All paths will automatically be relativized from ${ddf.home} if located underneath.
path
- the path of the file to be exportedIllegalArgumentException
- if path
is null
Stream<ExportMigrationEntry> entries(Path path)
Note: Files referenced are assumed to be relative to ${ddf.home} if not defined as absolute. All paths will automatically be relativized from ${ddf.home} if located underneath.
path
- the path to the directory to recursively walkpath
IllegalArgumentException
- if path
is null
SecurityException
- if a security manager exists and its checkRead()
method
doesn't allow read access to the specified pathStream<ExportMigrationEntry> entries(Path path, PathMatcher filter)
Note: Files referenced are assumed to be relative to ${ddf.home} if not defined as absolute. All paths will automatically be relativized from ${ddf.home} if located underneath.
path
- the path to the directory to recursively walkfilter
- the path filter to usepath
which matches the given filterIllegalArgumentException
- if path
or filter
is null
SecurityException
- if a security manager exists and its checkRead()
method
doesn't allow read access to the specified pathThis work is licensed under a Creative Commons Attribution 4.0 International License.