use of io.confluent.ksql.tools.migrations.util.MigrationFile in project ksql by confluentinc.
the class ApplyMigrationCommand method apply.
private boolean apply(final MigrationConfig config, final Client ksqlClient, final String migrationsDir, final Clock clock) {
String previous = MetadataUtil.getLatestMigratedVersion(config, ksqlClient);
LOGGER.info("Loading migration files");
final List<MigrationFile> migrations;
try {
migrations = loadMigrationsToApply(migrationsDir, previous);
} catch (MigrationException e) {
LOGGER.error(e.getMessage());
return false;
}
if (migrations.size() == 0) {
LOGGER.info("No eligible migrations found.");
} else {
LOGGER.info(migrations.size() + " migration file(s) loaded.");
}
for (MigrationFile migration : migrations) {
if (!applyMigration(config, ksqlClient, migration, clock, previous)) {
return false;
}
previous = Integer.toString(migration.getVersion());
}
return true;
}
use of io.confluent.ksql.tools.migrations.util.MigrationFile 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.MigrationFile in project ksql by confluentinc.
the class ApplyMigrationCommand method executeCommands.
/**
* If validateOnly is set to true, then this parses each of the commands but only executes
* DEFINE/UNDEFINE commands (variables are needed for parsing INSERT INTO... VALUES, SET/UNSET
* and DEFINE commands). If validateOnly is set to false, then each command will execute after
* parsing.
*/
private void executeCommands(final List<String> commands, final Client ksqlClient, final MigrationConfig config, final String executionStart, final MigrationFile migration, final Clock clock, final String previous, final boolean validateOnly) {
setUpJavaClientVariables(ksqlClient);
final Map<String, Object> properties = new HashMap<>();
for (final String command : commands) {
try {
final Map<String, String> variables = ksqlClient.getVariables().entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().toString()));
executeCommand(CommandParser.transformToSqlCommand(command, variables), ksqlClient, properties, validateOnly);
} catch (InterruptedException | ExecutionException | MigrationException e) {
final String action = validateOnly ? "parse" : "execute";
final String errorMsg = String.format("Failed to %s sql: %s. Error: %s", action, command, e.getMessage());
updateState(config, ksqlClient, MigrationState.ERROR, executionStart, migration, clock, previous, Optional.of(errorMsg));
throw new MigrationException(errorMsg);
}
}
}
Aggregations