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());
}
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;
}
Aggregations