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
-
-
Constructor Summary
Constructors Constructor Description MigrationExtensionPoint()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
_applyInitializationActions(Map<Version,List<ActionData>> allInitializationActions)
Execute all needed upgradesprotected boolean
_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(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 Versionsprotected 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.boolean
doMigration()
All migrations are parsed and executed one per one in the right orderString
getExpectedVersionForComponent(String id)
Get the expected version for a component.MigrationConfiguration
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 smanager)
-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
-
-
-
Constructor Detail
-
MigrationExtensionPoint
public MigrationExtensionPoint()
-
-
Method Detail
-
service
public void service(ServiceManager smanager) 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 boolean doMigration()
All migrations are parsed and executed one per one in the right order- Returns:
- true if the migration requires a server restart ; false otherwise
-
_notifyEndOfMigration
protected void _notifyEndOfMigration()
Notify with anEvent
the end of the migration.
-
_applyInitializationActions
protected boolean _applyInitializationActions(Map<Version,List<ActionData>> allInitializationActions) throws MigrationException
Execute all needed upgrades- Parameters:
allInitializationActions
- list of needed upgrades- Returns:
- true if an action requires a restart
- Throws:
MigrationException
- Something went wrong
-
_applyUpgradeActions
protected boolean _applyUpgradeActions(List<ActionData> allActions) throws MigrationException
Execute all needed upgrades- Parameters:
allActions
- list of needed upgrades- Returns:
- true if an action requires a restart
- 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(MigrationConfiguration migrationConfiguration) throws ConfigurationException
Returns the most recent version to apply (after an initialization)- Parameters:
migrationConfiguration
- Configuration of the extension- Returns:
- the id of the most current available version, or "0" if none available
- Throws:
ConfigurationException
- Sompthing wrong while reading the configuration
-
_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
-
getExpectedVersionForComponent
public String getExpectedVersionForComponent(String id) throws MigrationException
Get the expected version for a component. This is the latest upgrade number declared- Parameters:
id
- the id of the component- Returns:
- the expected version number for each version in this component
- Throws:
MigrationException
- Component not found in the calculated map of expected versions
-
-