Package org.ametys.core.migration
Class MigrationExtensionPoint
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.core.migration.MigrationExtensionPoint
-
- All Implemented Interfaces:
LogEnabled
,ExtensionPoint<MigrationConfiguration>
,Component
,Serviceable
,ThreadSafe
public class MigrationExtensionPoint extends AbstractLogEnabled implements ExtensionPoint<MigrationConfiguration>, ThreadSafe, Component, Serviceable
Migration Extension Point that will list all migration needed by the current state of the application
-
-
Field Summary
Fields Modifier and Type Field Description private Map<String,MigrationConfiguration>
_configurations
private ActionExtensionPoint
_initializationEP
private ObservationManager
_observationManager
private ActionExtensionPoint
_upgradeEP
private VersionHandlerExtensionPoint
_versionHandlerEP
static String
ROLE
Avalon Role
-
Constructor Summary
Constructors Constructor Description MigrationExtensionPoint()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_applyInitializationActions(Map<Version,List<ActionData>> allInitializationActions)
Execute all needed upgradesprotected void
_applyUpgradeActions(List<ActionData> allActions)
Execute all needed upgradesprotected void
_checkFromUpgrades(List<ActionData> 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"protected String
_getHigherCurrentUpgradeVersionNumber(Version version, MigrationConfiguration migrationConfiguration)
Returns the most recent version to apply (after an initialization)protected Map<Version,List<ActionData>>
_getInitializationActions(List<Version> currentVersions, MigrationConfiguration migrationConfiguration)
Analyze the configuration to get a list of initializations needed based on the current Versionsprotected List<ActionData>
_getUpgradeActions(List<Version> currentVersions, MigrationConfiguration migrationConfiguration)
Analyze the configuration to get a list of upgrades needed based on the current Versionsprivate VersionHandler
_getVersionHandler(Configuration versionConfiguration)
protected void
_notifyEndOfMigration()
Notify with anEvent
the end of the migration.protected List<ActionData>
_removeDuplicatedActions(List<ActionData> actions)
Parse the list of upgrade to remove the group-migrationprotected void
_upgradeVersion(ActionData action)
When an upgrade (or an initialization) have been done, we write the new versionprotected void
_upgradeVersion(Version newVersion)
When an upgrade (or an initialization) have been done, we write the new versionvoid
addExtension(String id, String pluginName, String featureName, Configuration configuration)
Add an extension to this point.void
doMigration()
All migrations are parsed and executed one per one in the right orderMigrationConfiguration
getExtension(String id)
Returns the named extensionSet<String>
getExtensionsIds()
Returns a Set containing the ids of all known extensionsboolean
hasExtension(String id)
Returns true if the named extension existsvoid
initializeExtensions()
Finalize the initialization of the extensions.
This method is called after alladdExtension()
calls.
This is the last step before the actual startup of the application.void
service(ServiceManager manager)
-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Field Detail
-
_configurations
private Map<String,MigrationConfiguration> _configurations
-
_versionHandlerEP
private VersionHandlerExtensionPoint _versionHandlerEP
-
_upgradeEP
private ActionExtensionPoint _upgradeEP
-
_initializationEP
private ActionExtensionPoint _initializationEP
-
_observationManager
private ObservationManager _observationManager
-
-
Constructor Detail
-
MigrationExtensionPoint
public MigrationExtensionPoint()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
addExtension
public void addExtension(String id, String pluginName, String featureName, Configuration configuration) throws ConfigurationException
Description copied from interface:ExtensionPoint
Add an extension to this point. Each implementation knows the meaning of the given configuration.- Specified by:
addExtension
in interfaceExtensionPoint<MigrationConfiguration>
- Parameters:
id
- the unique identifier of the extension.pluginName
- Unique identifier for the plugin hosting the extensionfeatureName
- Unique feature identifier (unique for a given pluginName)configuration
- the information about the extension to be added- Throws:
ConfigurationException
- when a configuration problem occurs
-
initializeExtensions
public void initializeExtensions() throws Exception
Description copied from interface:ExtensionPoint
Finalize the initialization of the extensions.
This method is called after alladdExtension()
calls.
This is the last step before the actual startup of the application.- Specified by:
initializeExtensions
in interfaceExtensionPoint<MigrationConfiguration>
- Throws:
Exception
- if something wrong occurs
-
doMigration
public void doMigration()
All migrations are parsed and executed one per one in the right order
-
_getVersionHandler
private VersionHandler _getVersionHandler(Configuration versionConfiguration) throws ConfigurationException
- Throws:
ConfigurationException
-
_notifyEndOfMigration
protected void _notifyEndOfMigration()
Notify with anEvent
the end of the migration.
-
_applyInitializationActions
protected void _applyInitializationActions(Map<Version,List<ActionData>> allInitializationActions) throws MigrationException
Execute all needed upgrades- Parameters:
allInitializationActions
- list of needed upgrades- Throws:
MigrationException
- Something went wrong
-
_applyUpgradeActions
protected void _applyUpgradeActions(List<ActionData> allActions) throws MigrationException
Execute all needed upgrades- Parameters:
allActions
- list of needed upgrades- Throws:
MigrationException
- Something went wrong
-
_upgradeVersion
protected void _upgradeVersion(ActionData action) throws MigrationException
When an upgrade (or an initialization) have been done, we write the new version- Parameters:
action
- upgrade/initialization executed- Throws:
MigrationException
- Something went wrong
-
_upgradeVersion
protected void _upgradeVersion(Version newVersion) throws MigrationException
When an upgrade (or an initialization) have been done, we write the new version- Parameters:
newVersion
- upgrade/initialization executed- Throws:
MigrationException
- Something went wrong
-
_getUpgradeActions
protected List<ActionData> _getUpgradeActions(List<Version> currentVersions, MigrationConfiguration migrationConfiguration) throws MigrationException
Analyze the configuration to get a list of upgrades needed based on the current Versions- Parameters:
currentVersions
- list of current versionsmigrationConfiguration
- configuration for this extension- Returns:
- a list of actions to work on, or null if an error occured
- Throws:
MigrationException
- impossible to parse the configuration
-
_getInitializationActions
protected Map<Version,List<ActionData>> _getInitializationActions(List<Version> currentVersions, MigrationConfiguration migrationConfiguration) throws MigrationException
Analyze the configuration to get a list of initializations needed based on the current Versions- Parameters:
currentVersions
- list of current versionsmigrationConfiguration
- configuration for this extension- Returns:
- a list of actions to work on, or null if an error occured
- Throws:
MigrationException
- impossible to parse the configuration
-
_getHigherCurrentUpgradeVersionNumber
protected String _getHigherCurrentUpgradeVersionNumber(Version version, MigrationConfiguration migrationConfiguration) throws MigrationException
Returns the most recent version to apply (after an initialization)- Parameters:
version
- Version usedmigrationConfiguration
- Configuration of the extension- Returns:
- the id of the most current available version, or "0" if none available
- Throws:
MigrationException
- Something went wrong
-
_removeDuplicatedActions
protected List<ActionData> _removeDuplicatedActions(List<ActionData> actions) throws MigrationException
Parse the list of upgrade to remove the group-migration- Parameters:
actions
- list of upgrades to clean- Returns:
- a list with only needed upgrades.
- Throws:
MigrationException
- list of actions incoherent
-
_checkFromUpgrades
protected void _checkFromUpgrades(List<ActionData> actions, List<Pair<String,String>> fromTo) throws MigrationException
Tests 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
-
hasExtension
public boolean hasExtension(String id)
Description copied from interface:ExtensionPoint
Returns true if the named extension exists- Specified by:
hasExtension
in interfaceExtensionPoint<MigrationConfiguration>
- Parameters:
id
- the unique id of the extension- Returns:
- true if the named extension exists
-
getExtension
public MigrationConfiguration getExtension(String id)
Description copied from interface:ExtensionPoint
Returns the named extension- Specified by:
getExtension
in interfaceExtensionPoint<MigrationConfiguration>
- Parameters:
id
- the unique id of the extension- Returns:
- the named extension
-
getExtensionsIds
public Set<String> getExtensionsIds()
Description copied from interface:ExtensionPoint
Returns a Set containing the ids of all known extensions- Specified by:
getExtensionsIds
in interfaceExtensionPoint<MigrationConfiguration>
- Returns:
- a Set containing the ids of all known extensions
-
-