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 class
MigrationServiceImpl.InvalidatorMigrator
Amigrator
wrapper to send invalidations to other nodes when callingMigrationServiceImpl.InvalidatorMigrator.notifyStatusChange()
.protected static class
MigrationServiceImpl.MigrationContextImpl
Migration context implementation that reports progress in the key/value store and can be shutdown.static class
MigrationServiceImpl.MigrationInvalidation
class
MigrationServiceImpl.MigrationInvalidator
protected static class
MigrationServiceImpl.MigrationThreadPoolExecutor
Thread pool executor that recordsRunnable
s to be able to request shutdown on them.protected static class
MigrationServiceImpl.MigratorWithContext
Runnable for the migrator, that knows about the migration context.protected static class
MigrationServiceImpl.ProgressReporter
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
Fields Modifier and Type Field Description static String
ERROR_CODE
static String
ERROR_MESSAGE
protected MigrationServiceImpl.MigrationThreadPoolExecutor
executor
protected MigrationServiceImpl.MigrationInvalidator
invalidator
static String
KEYVALUE_STORE_NAME
static String
LOCK
static String
MIGRATION_INVAL_PUBSUB_TOPIC
protected String
nodeId
static String
PING_TIME
static String
PROGRESS_MESSAGE
static String
PROGRESS_NUM
static String
PROGRESS_TOTAL
protected static Random
RANDOM
static String
START_TIME
static String
STEP
static long
WRITE_LOCK_TTL
static String
XP_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 void
atomic(String id, Consumer<KeyValueStore> consumer)
Executes something while setting a lock, retrying a few times if the lock is already set.int
getApplicationStartedOrder()
The component notification order forComponent.applicationStarted(org.nuxeo.runtime.model.ComponentContext)
.protected static KeyValueStore
getKeyValueStore()
Migration
getMigration(String id)
Gets a migration object.Collection<MigrationDescriptor>
getMigrationDescriptors()
List<Migration>
getMigrations()
Gets all the migration objects.MigrationService.Migrator
getMigrator(String id)
MigrationService.MigrationStatus
getStatus(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.String
probeAndSetState(String id)
Probes the current state of a migration by analyzing persistent data, and sets it as the new current state.void
restartExecutor()
Restart the executor thread, only for testing purpose.void
runStep(String id, String step)
Runs a migration step for a migration.protected void
runStep(String id, String step, boolean resume)
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
-
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
-
ERROR_MESSAGE
public static final String ERROR_MESSAGE
- See Also:
- Constant Field Values
-
ERROR_CODE
public static final String ERROR_CODE
- 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
-
RANDOM
protected static final Random RANDOM
-
executor
protected MigrationServiceImpl.MigrationThreadPoolExecutor executor
-
nodeId
protected String nodeId
-
invalidator
protected MigrationServiceImpl.MigrationInvalidator invalidator
-
-
Method Detail
-
getKeyValueStore
protected static KeyValueStore getKeyValueStore()
-
getMigrationDescriptors
public Collection<MigrationDescriptor> getMigrationDescriptors()
-
getApplicationStartedOrder
public int getApplicationStartedOrder()
Description copied from interface:Component
The 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:
getApplicationStartedOrder
in interfaceComponent
- Returns:
- the order, 1000 by default
-
start
public void start(ComponentContext context)
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
public void stop(ComponentContext context) throws InterruptedException
Description copied from interface:Component
Stop the component.- Specified by:
stop
in interfaceComponent
- Overrides:
stop
in classDefaultComponent
- Throws:
InterruptedException
-
getStatus
public MigrationService.MigrationStatus getStatus(String id)
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
protected long parseLong(KeyValueStore kv, String key)
-
probeAndSetState
public String probeAndSetState(String id)
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
public void runStep(String id, String step)
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
-
getMigrator
public 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: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
public List<Migration> getMigrations()
Description copied from interface:MigrationService
Gets all the migration objects.- Specified by:
getMigrations
in interfaceMigrationService
- Returns:
- a list of all migrations
-
probeAndRun
public void probeAndRun(String id)
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
public void restartExecutor() throws InterruptedException
Restart the executor thread, only for testing purpose.- Throws:
InterruptedException
- Since:
- 2023.5
-
-