All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openmetadata.service.migration.context.MigrationWorkflowContext Maven / Gradle / Ivy

There is a newer version: 1.5.11
Show newest version
package org.openmetadata.service.migration.context;

import java.util.HashMap;
import java.util.List;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.jdbi.v3.core.Handle;
import org.openmetadata.service.migration.api.MigrationProcess;

@Slf4j
public class MigrationWorkflowContext {
  @Getter private final HashMap migrationContext;
  private final Handle handle;

  public MigrationWorkflowContext(Handle handle) {
    this.migrationContext = new HashMap<>();
    this.handle = handle;
  }

  public void computeInitialContext(String currentMaxMigrationVersion) {
    computeMigrationSafely(new MigrationContext(currentMaxMigrationVersion, List.of(), handle));
  }

  public void computeMigrationContext(MigrationProcess process) {
    MigrationContext context =
        new MigrationContext(process.getVersion(), process.getMigrationOps(), handle);
    computeMigrationSafely(context);
  }

  private void computeMigrationSafely(MigrationContext context) {
    try {
      context.compute();
      context.show();
      this.migrationContext.put(context.getVersion(), context);
    } catch (Exception e) {
      LOG.warn(
          String.format("Error computing context for [%s] due to [%s]", context.getVersion(), e));
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy