Search in sources :

Example 1 with MigrationStepsExecutor

use of org.sonar.server.platform.db.migration.step.MigrationStepsExecutor in project sonarqube by SonarSource.

the class SQDatabase method executeDbMigrations.

private void executeDbMigrations(NoopDatabase noopDatabase) {
    SpringComponentContainer container = new SpringComponentContainer();
    container.add(noopDatabase);
    MigrationConfigurationModule migrationConfigurationModule = new MigrationConfigurationModule();
    migrationConfigurationModule.configure(container);
    // dependencies required by DB migrations
    container.add(SonarRuntimeImpl.forSonarQube(Version.create(8, 0), SonarQubeSide.SERVER, SonarEdition.COMMUNITY));
    container.add(UuidFactoryFast.getInstance());
    container.add(System2.INSTANCE);
    container.add(MapSettings.class);
    container.startComponents();
    MigrationContainer migrationContainer = new MigrationContainerImpl(container, H2StepExecutor.class);
    MigrationSteps migrationSteps = migrationContainer.getComponentByType(MigrationSteps.class);
    MigrationStepsExecutor executor = migrationContainer.getComponentByType(MigrationStepsExecutor.class);
    executor.execute(migrationSteps.readAll());
}
Also used : SpringComponentContainer(org.sonar.core.platform.SpringComponentContainer) MigrationContainer(org.sonar.server.platform.db.migration.engine.MigrationContainer) MigrationConfigurationModule(org.sonar.server.platform.db.migration.MigrationConfigurationModule) MigrationStepsExecutor(org.sonar.server.platform.db.migration.step.MigrationStepsExecutor) MigrationContainerImpl(org.sonar.server.platform.db.migration.engine.MigrationContainerImpl) MigrationSteps(org.sonar.server.platform.db.migration.step.MigrationSteps)

Example 2 with MigrationStepsExecutor

use of org.sonar.server.platform.db.migration.step.MigrationStepsExecutor in project sonarqube by SonarSource.

the class MigrationEngineImpl method execute.

@Override
public void execute() {
    MigrationContainer migrationContainer = new MigrationContainerImpl(serverContainer, MigrationStepsExecutorImpl.class);
    boolean blueGreen = configuration.getBoolean(ProcessProperties.Property.BLUE_GREEN_ENABLED.getKey()).orElse(false);
    try {
        MigrationStepsExecutor stepsExecutor = migrationContainer.getComponentByType(MigrationStepsExecutor.class);
        Optional<Long> lastMigrationNumber = migrationHistory.getLastMigrationNumber();
        List<RegisteredMigrationStep> steps = lastMigrationNumber.map(i -> migrationSteps.readFrom(i + 1)).orElse(migrationSteps.readAll());
        if (blueGreen) {
            ensureSupportBlueGreen(steps);
        }
        stepsExecutor.execute(steps);
    } finally {
        migrationContainer.cleanup();
    }
}
Also used : SupportsBlueGreen(org.sonar.server.platform.db.migration.SupportsBlueGreen) MigrationHistory(org.sonar.server.platform.db.migration.history.MigrationHistory) AnnotationUtils(org.sonar.api.utils.AnnotationUtils) SpringComponentContainer(org.sonar.core.platform.SpringComponentContainer) String.format(java.lang.String.format) MigrationStepsExecutorImpl(org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl) List(java.util.List) ProcessProperties(org.sonar.process.ProcessProperties) MigrationStepsExecutor(org.sonar.server.platform.db.migration.step.MigrationStepsExecutor) Configuration(org.sonar.api.config.Configuration) Optional(java.util.Optional) MigrationSteps(org.sonar.server.platform.db.migration.step.MigrationSteps) RegisteredMigrationStep(org.sonar.server.platform.db.migration.step.RegisteredMigrationStep) MigrationStepsExecutor(org.sonar.server.platform.db.migration.step.MigrationStepsExecutor) RegisteredMigrationStep(org.sonar.server.platform.db.migration.step.RegisteredMigrationStep)

Aggregations

SpringComponentContainer (org.sonar.core.platform.SpringComponentContainer)2 MigrationSteps (org.sonar.server.platform.db.migration.step.MigrationSteps)2 MigrationStepsExecutor (org.sonar.server.platform.db.migration.step.MigrationStepsExecutor)2 String.format (java.lang.String.format)1 List (java.util.List)1 Optional (java.util.Optional)1 Configuration (org.sonar.api.config.Configuration)1 AnnotationUtils (org.sonar.api.utils.AnnotationUtils)1 ProcessProperties (org.sonar.process.ProcessProperties)1 MigrationConfigurationModule (org.sonar.server.platform.db.migration.MigrationConfigurationModule)1 SupportsBlueGreen (org.sonar.server.platform.db.migration.SupportsBlueGreen)1 MigrationContainer (org.sonar.server.platform.db.migration.engine.MigrationContainer)1 MigrationContainerImpl (org.sonar.server.platform.db.migration.engine.MigrationContainerImpl)1 MigrationHistory (org.sonar.server.platform.db.migration.history.MigrationHistory)1 MigrationStepsExecutorImpl (org.sonar.server.platform.db.migration.step.MigrationStepsExecutorImpl)1 RegisteredMigrationStep (org.sonar.server.platform.db.migration.step.RegisteredMigrationStep)1