Search in sources :

Example 1 with MigrationVersionInfo

use of io.confluent.ksql.tools.migrations.util.MigrationVersionInfo in project ksql by confluentinc.

the class MigrationInfoCommand method printAsTable.

private static void printAsTable(final List<MigrationFile> allMigrations, final Map<Integer, Optional<MigrationVersionInfo>> versionInfos) {
    final MigrationVersionInfoFormatter formatter = new MigrationVersionInfoFormatter();
    for (final MigrationFile migration : allMigrations) {
        final MigrationVersionInfo versionInfo = versionInfos.get(migration.getVersion()).orElse(MigrationVersionInfo.pendingMigration(migration.getVersion(), migration.getName()));
        formatter.addVersionInfo(versionInfo);
    }
    LOGGER.info(formatter.getFormatted());
}
Also used : MigrationVersionInfo(io.confluent.ksql.tools.migrations.util.MigrationVersionInfo) MigrationFile(io.confluent.ksql.tools.migrations.util.MigrationFile) MigrationVersionInfoFormatter(io.confluent.ksql.tools.migrations.util.MigrationVersionInfoFormatter)

Example 2 with MigrationVersionInfo

use of io.confluent.ksql.tools.migrations.util.MigrationVersionInfo in project ksql by confluentinc.

the class ValidateMigrationsCommand method validate.

/**
 * @return true if validation passes, else false.
 */
static boolean validate(final MigrationConfig config, final String migrationsDir, final Client ksqlClient) {
    String version = getLatestMigratedVersion(config, ksqlClient);
    String nextVersion = null;
    while (!version.equals(MetadataUtil.NONE_VERSION)) {
        final MigrationVersionInfo versionInfo = getInfoForVersion(version, config, ksqlClient);
        if (nextVersion != null) {
            validateVersionIsMigrated(version, versionInfo, nextVersion);
        }
        final String filename;
        try {
            filename = getMigrationForVersion(version, migrationsDir).get().getFilepath();
        } catch (MigrationException | NoSuchElementException e) {
            LOGGER.error("No migrations file found for version with status {}. Version: {}", MigrationState.MIGRATED, version);
            return false;
        }
        final String hash = computeHashForFile(filename);
        final String expectedHash = versionInfo.getExpectedHash();
        if (!expectedHash.equals(hash)) {
            LOGGER.error("Migrations file found for version {} does not match the checksum saved " + "for this version. Expected checksum: {}. Actual checksum: {}. File name: {}", version, expectedHash, hash, filename);
            return false;
        }
        nextVersion = version;
        version = versionInfo.getPrevVersion();
    }
    return true;
}
Also used : MigrationException(io.confluent.ksql.tools.migrations.MigrationException) MigrationVersionInfo(io.confluent.ksql.tools.migrations.util.MigrationVersionInfo) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

MigrationVersionInfo (io.confluent.ksql.tools.migrations.util.MigrationVersionInfo)2 MigrationException (io.confluent.ksql.tools.migrations.MigrationException)1 MigrationFile (io.confluent.ksql.tools.migrations.util.MigrationFile)1 MigrationVersionInfoFormatter (io.confluent.ksql.tools.migrations.util.MigrationVersionInfoFormatter)1 NoSuchElementException (java.util.NoSuchElementException)1