Package org.ametys.core.migration
Class MigrationEngine
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.core.migration.MigrationEngine
- All Implemented Interfaces:
DeferredServiceable
,LogEnabled
,Component
,Contextualizable
public class MigrationEngine
extends AbstractLogEnabled
implements Contextualizable, DeferredServiceable, Component
Main entry point for all automatic migration related tasks.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final record
All data needed to actually execute an upgrade action: the current version and the action configuration.static final record
A migration component represents a versioned feature setstatic final record
The leaf of theMigrationEngine.Versions
tree.static interface
A version tree, grouped recursively by sub-components.static final class
Contains a list of versions for a sub-component -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
_checkFromUpgrades
(List<ActionConfiguration> actions, List<Pair<String, String>> fromTo) Tests that in the list of fromTo, that each "fromTo" is linked to an action with the same id and without "from"void
contextualize
(Context context) void
deferredService
(ServiceManager smanager) Pass theServiceManager
used to access other components.boolean
doAction
(MigrationEngine.ActionData actionData, ActionExtensionPoint extensionPoint) Executes a migration action.If the upgrade process has failed, returns the correspondingActionConfiguration
.
Returns null if the process went well.If the upgrade process has failed, returns the correspondingMigrationException
.
Returns null if the process went well.Returns the highest version number among all components' upgradesgetLatestVersion
(List<Version> versions) Returns the latest version (according to version numbers) among the given list of versionsgetUpgrades
(Version currentVersion, List<ActionConfiguration> availableUpgrades) Return all upgrades to execute for the current versiongetVersionList
(MigrationEngine.Versions versions, String id) Search a given version list among all thos returned by aVersionHandler
getVersions
(MigrationEngine.MigrationComponent component) Retrives all stored versions for the given componentboolean
Execute all needed initializationsboolean
migrate()
All migrations are parsed and executed one per one in the right orderboolean
Execute an upgradeMethods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
ROLE
Avalon Role
-
-
Constructor Details
-
MigrationEngine
public MigrationEngine()
-
-
Method Details
-
contextualize
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
deferredService
Description copied from interface:DeferredServiceable
Pass theServiceManager
used to access other components.- Specified by:
deferredService
in interfaceDeferredServiceable
- Parameters:
smanager
- TheServiceManager
which thisDeferredServiceable
uses. Must not benull
.- Throws:
ServiceException
- if an error occurs
-
migrate
All migrations are parsed and executed one per one in the right order- Returns:
- true if the migration requires a server restart ; false otherwise
-
getUpgrades
public List<ActionConfiguration> getUpgrades(Version currentVersion, List<ActionConfiguration> availableUpgrades) throws MigrationException Return all upgrades to execute for the current version- Parameters:
currentVersion
- the current versionavailableUpgrades
- all available upgrades- Returns:
- all upgrade to execute
- Throws:
MigrationException
- if the upgrades are not compatible
-
getVersions
public MigrationEngine.Versions getVersions(MigrationEngine.MigrationComponent component) throws MigrationException Retrives all stored versions for the given component- Parameters:
component
- the component to check- Returns:
- all stored versions.
- Throws:
MigrationException
- if something wrong occured
-
getVersionList
Search a given version list among all thos returned by aVersionHandler
- Parameters:
versions
- the version treeid
- the wanted id- Returns:
- the corresponding
MigrationEngine.VersionList
-
getLatestVersion
Returns the latest version (according to version numbers) among the given list of versions- Parameters:
versions
- a list ofVersion
- Returns:
- the latest version, or null if the list is empty
-
initializeVersion
Execute all needed initializations- Parameters:
action
- the version and action configuration to initialize- Returns:
- true if an action requires a restart
- Throws:
MigrationException
- Something went wrong
-
upgradeVersion
Execute an upgrade- Parameters:
action
- the version and action configuration to upgrade- Returns:
- true if an action requires a restart
- Throws:
MigrationException
- Something went wrong
-
doAction
public boolean doAction(MigrationEngine.ActionData actionData, ActionExtensionPoint extensionPoint) throws MigrationException Executes a migration action.- Parameters:
actionData
- the version and action configuration to executeextensionPoint
- the relatedActionExtensionPoint
- Returns:
- true if the action needs a restart after its execution
- Throws:
MigrationException
- Something went wrong
-
getHighestUpgradeVersionNumber
Returns the highest version number among all components' upgrades- Parameters:
component
- theMigrationEngine.MigrationComponent
to consider- Returns:
- the highest upgrade version number
-
_checkFromUpgrades
protected void _checkFromUpgrades(List<ActionConfiguration> actions, List<Pair<String, String>> fromTo) throws MigrationExceptionTests that in the list of fromTo, that each "fromTo" is linked to an action with the same id and without "from"- Parameters:
actions
- list of actionsfromTo
- list of actions overriding multiple actions- Throws:
MigrationException
- there is an overriding version without a "simple" version with the same id
-
getFailedAction
If the upgrade process has failed, returns the correspondingActionConfiguration
.
Returns null if the process went well.- Returns:
- the failed action data
-
getFailedException
If the upgrade process has failed, returns the correspondingMigrationException
.
Returns null if the process went well.- Returns:
- the exception causing the upgrade failure
-