Package org.nuxeo.runtime.migration
Class MigrationServiceImpl
- java.lang.Object
-
- org.nuxeo.runtime.model.DefaultComponent
-
- org.nuxeo.runtime.migration.MigrationServiceImpl
-
- All Implemented Interfaces:
MigrationService,Adaptable,Component,Extensible,TimestampedService
public class MigrationServiceImpl extends DefaultComponent implements MigrationService
Implementation for the Migration Service.Data about migration status is stored in the "migration" Key/Value Store in the following format:
mymigration:lock write lock, containing debug info about locker; set with a TTL mymigration the state of the migration, if not running mymigration:step the step of the migration, if running mymigration:starttime the migration step start time (milliseconds since epoch) mymigration:pingtime the migration step last ping time (milliseconds since epoch) mymigration:message the migration step current message mymigration:num the migration step current num mymigration:total the migration step current total
- Since:
- 9.3
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMigrationServiceImpl.InvalidatorMigratorAmigratorwrapper to send invalidations to other nodes when callingMigrationServiceImpl.InvalidatorMigrator.notifyStatusChange().protected static classMigrationServiceImpl.MigrationContextImplMigration context implementation that reports progress in the key/value store and can be shutdown.static classMigrationServiceImpl.MigrationInvalidationclassMigrationServiceImpl.MigrationInvalidatorprotected static classMigrationServiceImpl.MigrationThreadPoolExecutorThread pool executor that recordsRunnables to be able to request shutdown on them.protected static classMigrationServiceImpl.MigratorWithContextRunnable for the migrator, that knows about the migration context.protected static classMigrationServiceImpl.ProgressReporterProgress reporter that reports progress in the key/value store.-
Nested classes/interfaces inherited from interface org.nuxeo.runtime.migration.MigrationService
MigrationService.MigrationContext, MigrationService.MigrationStatus, MigrationService.Migrator
-
-
Field Summary
Fields Modifier and Type Field Description protected MigrationServiceImpl.MigrationThreadPoolExecutorexecutorprotected MigrationServiceImpl.MigrationInvalidatorinvalidatorstatic StringKEYVALUE_STORE_NAMEstatic StringLOCKstatic StringMIGRATION_INVAL_PUBSUB_TOPICprotected StringnodeIdstatic StringPING_TIMEstatic StringPROGRESS_MESSAGEstatic StringPROGRESS_NUMstatic StringPROGRESS_TOTALprotected static RandomRANDOMstatic StringSTART_TIMEstatic StringSTEPstatic longWRITE_LOCK_TTLstatic StringXP_CONFIG-
Fields inherited from class org.nuxeo.runtime.model.DefaultComponent
lastModified, name
-
-
Constructor Summary
Constructors Constructor Description MigrationServiceImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidatomic(String id, Consumer<KeyValueStore> consumer)Executes something while setting a lock, retrying a few times if the lock is already set.intgetApplicationStartedOrder()The component notification order forComponent.applicationStarted(org.nuxeo.runtime.model.ComponentContext).protected static KeyValueStoregetKeyValueStore()MigrationgetMigration(String id)Gets a migration object.Collection<MigrationDescriptor>getMigrationDescriptors()List<Migration>getMigrations()Gets all the migration objects.protected MigrationService.MigratorgetMigrator(String id)MigrationService.MigrationStatusgetStatus(String id)Gets the current status for a migration.voidprobeAndRun(String id)Probes the migration state and runs a migration.StringprobeAndSetState(String id)Probes the current state of a migration by analyzing persistent data, and sets it as the new current state.voidrunStep(String id, String step)Runs a migration step for a migration.protected voidsetState(String id, String state, MigrationService.Migrator migrator, MigrationServiceImpl.ProgressReporter progressReporter)protected voidsetState(String id, String state, MigrationServiceImpl.ProgressReporter progressReporter, KeyValueStore kv)voidstart(ComponentContext context)Start the component.voidstop(ComponentContext context)Stop the component.-
Methods inherited from class org.nuxeo.runtime.model.DefaultComponent
activate, addRuntimeMessage, addRuntimeMessage, deactivate, getAdapter, getDescriptor, getDescriptors, getLastModified, getRegistry, register, registerContribution, registerExtension, setLastModified, setModifiedNow, setName, unregister, unregisterContribution, unregisterExtension
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.nuxeo.runtime.model.Component
applicationStarted
-
-
-
-
Field Detail
-
KEYVALUE_STORE_NAME
public static final String KEYVALUE_STORE_NAME
- See Also:
- Constant Field Values
-
XP_CONFIG
public static final String XP_CONFIG
- See Also:
- Constant Field Values
-
LOCK
public static final String LOCK
- See Also:
- Constant Field Values
-
STEP
public static final String STEP
- See Also:
- Constant Field Values
-
START_TIME
public static final String START_TIME
- See Also:
- Constant Field Values
-
PING_TIME
public static final String PING_TIME
- See Also:
- Constant Field Values
-
PROGRESS_MESSAGE
public static final String PROGRESS_MESSAGE
- See Also:
- Constant Field Values
-
PROGRESS_NUM
public static final String PROGRESS_NUM
- See Also:
- Constant Field Values
-
PROGRESS_TOTAL
public static final String PROGRESS_TOTAL
- See Also:
- Constant Field Values
-
WRITE_LOCK_TTL
public static final long WRITE_LOCK_TTL
- See Also:
- Constant Field Values
-
MIGRATION_INVAL_PUBSUB_TOPIC
public static final String MIGRATION_INVAL_PUBSUB_TOPIC
- See Also:
- Constant Field Values
-
executor
protected MigrationServiceImpl.MigrationThreadPoolExecutor executor
-
invalidator
protected MigrationServiceImpl.MigrationInvalidator invalidator
-
-
Constructor Detail
-
MigrationServiceImpl
public MigrationServiceImpl()
-
-
Method Detail
-
getKeyValueStore
protected static KeyValueStore getKeyValueStore()
-
getMigrationDescriptors
public Collection<MigrationDescriptor> getMigrationDescriptors()
-
getApplicationStartedOrder
public int getApplicationStartedOrder()
Description copied from interface:ComponentThe component notification order forComponent.applicationStarted(org.nuxeo.runtime.model.ComponentContext).Components are notified in increasing order. Order 1000 is the default order for components that don't care. Order 100 is the repository initialization.
- Specified by:
getApplicationStartedOrderin interfaceComponent- Returns:
- the order, 1000 by default
-
start
public void start(ComponentContext context)
Description copied from interface:ComponentStart the component. This method is called after all the components were resolved and activated- Specified by:
startin interfaceComponent- Overrides:
startin classDefaultComponent
-
stop
public void stop(ComponentContext context) throws InterruptedException
Description copied from interface:ComponentStop the component.- Specified by:
stopin interfaceComponent- Overrides:
stopin classDefaultComponent- Throws:
InterruptedException
-
getStatus
public MigrationService.MigrationStatus getStatus(String id)
Description copied from interface:MigrationServiceGets the current status for a migration.- Specified by:
getStatusin interfaceMigrationService- Parameters:
id- the migration id- Returns:
- the status, or
nullif the migration is unknown
-
probeAndSetState
public String probeAndSetState(String id)
Description copied from interface:MigrationServiceProbes the current state of a migration by analyzing persistent data, and sets it as the new current state.THIS METHOD MAY TAKE A WHILE as it needs to get information from persistent storage.
- Specified by:
probeAndSetStatein interfaceMigrationService- Parameters:
id- the migration id- Returns:
- the new state, or
nullif it cannot be determined
-
setState
protected void setState(String id, String state, MigrationService.Migrator migrator, MigrationServiceImpl.ProgressReporter progressReporter)
-
setState
protected void setState(String id, String state, MigrationServiceImpl.ProgressReporter progressReporter, KeyValueStore kv)
-
runStep
public void runStep(String id, String step)
Description copied from interface:MigrationServiceRuns a migration step for a migration.This launches the migration asynchronously. The status of the migration can be checked with
MigrationService.getStatus(java.lang.String).- Specified by:
runStepin interfaceMigrationService- Parameters:
id- the migration idstep- the step id
-
getMigrator
protected MigrationService.Migrator getMigrator(String id)
-
atomic
protected void atomic(String id, Consumer<KeyValueStore> consumer)
Executes something while setting a lock, retrying a few times if the lock is already set.
-
getMigration
public Migration getMigration(String id)
Description copied from interface:MigrationServiceGets a migration object.- Specified by:
getMigrationin interfaceMigrationService- Parameters:
id- the migration id- Returns:
- the migration, or
nullif the migration is unknown
-
getMigrations
public List<Migration> getMigrations()
Description copied from interface:MigrationServiceGets all the migration objects.- Specified by:
getMigrationsin interfaceMigrationService- Returns:
- a list of all migrations
-
probeAndRun
public void probeAndRun(String id)
Description copied from interface:MigrationServiceProbes the migration state and runs a migration.THIS METHOD MAY TAKE A WHILE as it may call
MigrationService.probeAndSetState(String).- Specified by:
probeAndRunin interfaceMigrationService- Parameters:
id- the migration id- Implementation Note:
- Runs a migration if it has exactly one available step to run.
-
-