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
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
Modifier and TypeClassDescriptionstatic class
Amigrator
wrapper to send invalidations to other nodes when callingMigrationServiceImpl.InvalidatorMigrator.notifyStatusChange()
.protected static class
Migration context implementation that reports progress in the key/value store and can be shutdown.static class
class
protected static class
Thread pool executor that recordsRunnable
s to be able to request shutdown on them.protected static class
Runnable for the migrator, that knows about the migration context.protected static class
Progress 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
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
protected String
static final String
static final String
static final String
static final String
protected static final Random
static final String
static final String
static final long
static final String
Fields inherited from class org.nuxeo.runtime.model.DefaultComponent
lastModified, name
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
atomic
(String id, Consumer<KeyValueStore> consumer) Executes something while setting a lock, retrying a few times if the lock is already set.int
The component notification order forComponent.start(ComponentContext)
.protected static KeyValueStore
getMigration
(String id) Gets a migration object.Gets all the migration objects.getMigrator
(String id) Gets the current status for a migration.protected long
parseLong
(KeyValueStore kv, String key) void
probeAndRun
(String id) Probes the migration state and runs a migration.Probes the current state of a migration by analyzing persistent data, and sets it as the new current state.void
Restart the executor thread, only for testing purpose.void
Runs a migration step for a migration.protected void
protected void
setState
(String id, String state, MigrationService.Migrator migrator, MigrationServiceImpl.ProgressReporter progressReporter) protected void
setState
(String id, String state, MigrationServiceImpl.ProgressReporter progressReporter, KeyValueStore kv) void
start
(ComponentContext context) Start the component.void
stop
(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
-
Field Details
-
KEYVALUE_STORE_NAME
- See Also:
-
XP_CONFIG
- See Also:
-
LOCK
- See Also:
-
STEP
- See Also:
-
START_TIME
- See Also:
-
PING_TIME
- See Also:
-
ERROR_MESSAGE
- See Also:
-
ERROR_CODE
- See Also:
-
PROGRESS_MESSAGE
- See Also:
-
PROGRESS_NUM
- See Also:
-
PROGRESS_TOTAL
- See Also:
-
WRITE_LOCK_TTL
public static final long WRITE_LOCK_TTL- See Also:
-
MIGRATION_INVAL_PUBSUB_TOPIC
- See Also:
-
RANDOM
-
executor
-
nodeId
-
invalidator
-
-
Constructor Details
-
MigrationServiceImpl
public MigrationServiceImpl()
-
-
Method Details
-
getKeyValueStore
-
getMigrationDescriptors
-
getApplicationStartedOrder
public int getApplicationStartedOrder()Description copied from interface:Component
The component notification order forComponent.start(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:
getApplicationStartedOrder
in interfaceComponent
- Returns:
- the order, 1000 by default
-
start
Description copied from interface:Component
Start the component. This method is called after all the components were resolved and activated- Specified by:
start
in interfaceComponent
- Overrides:
start
in classDefaultComponent
-
stop
Description copied from interface:Component
Stop the component.- Specified by:
stop
in interfaceComponent
- Overrides:
stop
in classDefaultComponent
- Throws:
InterruptedException
-
getStatus
Description copied from interface:MigrationService
Gets the current status for a migration.- Specified by:
getStatus
in interfaceMigrationService
- Parameters:
id
- the migration id- Returns:
- the status, or
null
if the migration is unknown
-
parseLong
-
probeAndSetState
Description copied from interface:MigrationService
Probes 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:
probeAndSetState
in interfaceMigrationService
- Parameters:
id
- the migration id- Returns:
- the new state, or
null
if 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
Description copied from interface:MigrationService
Runs 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:
runStep
in interfaceMigrationService
- Parameters:
id
- the migration idstep
- the step id
-
runStep
-
getMigrator
-
atomic
Executes something while setting a lock, retrying a few times if the lock is already set. -
getMigration
Description copied from interface:MigrationService
Gets a migration object.- Specified by:
getMigration
in interfaceMigrationService
- Parameters:
id
- the migration id- Returns:
- the migration, or
null
if the migration is unknown
-
getMigrations
Description copied from interface:MigrationService
Gets all the migration objects.- Specified by:
getMigrations
in interfaceMigrationService
- Returns:
- a list of all migrations
-
probeAndRun
Description copied from interface:MigrationService
Probes the migration state and runs a migration.THIS METHOD MAY TAKE A WHILE as it may call
MigrationService.probeAndSetState(String)
.- Specified by:
probeAndRun
in interfaceMigrationService
- Parameters:
id
- the migration id- Implementation Note:
- Runs a migration if it has exactly one available step to run.
-
restartExecutor
Restart the executor thread, only for testing purpose.- Throws:
InterruptedException
- Since:
- 2023.5
-