use of io.confluent.ksql.tools.migrations.MigrationException in project ksql by confluentinc.
the class DestroyMigrationsCommand method command.
@VisibleForTesting
int command(final MigrationConfig config, final Function<MigrationConfig, Client> clientSupplier) {
final String streamName = config.getString(MigrationConfig.KSQL_MIGRATIONS_STREAM_NAME);
final String tableName = config.getString(MigrationConfig.KSQL_MIGRATIONS_TABLE_NAME);
final Client ksqlClient;
try {
ksqlClient = clientSupplier.apply(config);
} catch (MigrationException e) {
LOGGER.error(e.getMessage());
return 1;
}
LOGGER.info("Cleaning migrations metadata stream and table from ksqlDB server");
if (ServerVersionUtil.serverVersionCompatible(ksqlClient, config) && deleteMigrationsTable(ksqlClient, tableName) && deleteMigrationsStream(ksqlClient, streamName)) {
LOGGER.info("Migrations metadata cleaned successfully");
ksqlClient.close();
return 0;
} else {
ksqlClient.close();
return 1;
}
}
use of io.confluent.ksql.tools.migrations.MigrationException in project ksql by confluentinc.
the class MigrationInfoCommand method command.
@VisibleForTesting
int command(final MigrationConfig config, final Function<MigrationConfig, Client> clientSupplier, final String migrationsDir) {
final Client ksqlClient;
try {
ksqlClient = clientSupplier.apply(config);
} catch (MigrationException e) {
LOGGER.error(e.getMessage());
return 1;
}
if (!validateMetadataInitialized(ksqlClient, config)) {
ksqlClient.close();
return 1;
}
boolean success;
try {
printCurrentVersion(config, ksqlClient);
printVersionInfoTable(config, ksqlClient, migrationsDir);
success = true;
} catch (MigrationException e) {
LOGGER.error(e.getMessage());
success = false;
} finally {
ksqlClient.close();
}
return success ? 0 : 1;
}
use of io.confluent.ksql.tools.migrations.MigrationException 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;
}
use of io.confluent.ksql.tools.migrations.MigrationException in project ksql by confluentinc.
the class MigrationsDirectoryUtil method getAllMigrations.
/**
* @return all migration files in sorted order
*/
public static List<MigrationFile> getAllMigrations(final String migrationsDir) {
final File directory = new File(migrationsDir);
if (!directory.isDirectory()) {
throw new MigrationException(migrationsDir + " is not a directory.");
}
final String[] allNames;
try {
allNames = directory.list();
} catch (SecurityException e) {
throw new MigrationException("Failed to retrieve files from " + migrationsDir + ": " + e.getMessage());
}
if (allNames == null) {
throw new MigrationException("Failed to retrieve files from " + migrationsDir);
}
final List<String> filenames = Arrays.stream(allNames).sorted().filter(name -> !new File(name).isDirectory()).collect(Collectors.toList());
final List<MigrationFile> migrations = filenames.stream().map(name -> getMigrationFromFilename(migrationsDir, name)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
validateMigrationVersionsUnique(migrations);
return migrations;
}
use of io.confluent.ksql.tools.migrations.MigrationException in project ksql by confluentinc.
the class CommandParserTest method shouldThrowOnDescribeStatement.
@Test
public void shouldThrowOnDescribeStatement() {
// When:
final MigrationException e = assertThrows(MigrationException.class, () -> parse("describe my_stream;"));
// Then:
assertThat(e.getMessage(), is("'DESCRIBE' statements are not supported."));
}
Aggregations