Class LiquibaseStatusProvider

java.lang.Object
com.github.jpmsilva.jsystemd.spring.LiquibaseStatusProvider
All Implemented Interfaces:
StatusProvider, BeanPostProcessor

public class LiquibaseStatusProvider extends Object implements StatusProvider, BeanPostProcessor
Implementation of StatusProvider that provides the progress of the Liquibase database migrations run on startup, such as Liquibase: applying changeset 042-add-index (41 applied).

The migrations are run by the SpringLiquibase beans, such as the one Spring Boot sets up, while they are created. This provider is a bean post processor that follows their creation, and makes the Liquibase instance they run report each changeset it applies, with the customizer of the bean. Each changeset also extends the startup timeout, as a migration with many changesets can take longer than the TimeoutStartSec of the service unit; a single changeset that takes longer than the timeout extension still exceeds it, in which case TimeoutStartSec must be raised.

The progress is reported through a PhaseStatusProvider of its own, sent to systemd right away on every change, and cleared once the migrations complete. When they fail, the changeset that failed is still reported, while the application fails to start.

The changesets are reported with a ChangeExecListener that is set before the customizer the bean already has, if any: a customizer that sets a listener of its own replaces it, in which case the changesets are not reported.

Author:
Joao Silva
  • Constructor Details

    • LiquibaseStatusProvider

      public LiquibaseStatusProvider()
      Creates a new instance, which sends the status to systemd on every change, and extends the startup timeout on every changeset.

      The created instance is not registered as a status provider of Systemd.instance(): that is up to the caller.

  • Method Details

    • postProcessBeforeInitialization

      public Object postProcessBeforeInitialization(Object bean, String beanName)
      Makes the Liquibase instance run by a SpringLiquibase bean report each changeset it applies, before the bean runs the migrations.
      Specified by:
      postProcessBeforeInitialization in interface BeanPostProcessor
      Parameters:
      bean - the bean being created
      beanName - the name of the bean
      Returns:
      the bean
    • postProcessAfterInitialization

      public Object postProcessAfterInitialization(Object bean, String beanName)
      Clears the progress once a SpringLiquibase bean ran the migrations.
      Specified by:
      postProcessAfterInitialization in interface BeanPostProcessor
      Parameters:
      bean - the bean being created
      beanName - the name of the bean
      Returns:
      the bean
    • status

      public String status()
      Description copied from interface: StatusProvider
      Exposes status information to send to systemd.
      Specified by:
      status in interface StatusProvider
      Returns:
      the string message to add to the service status