Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Add back seeds for config import #5209

Merged
merged 2 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public class ConfigDumpImporter {

private static final Logger LOGGER = LoggerFactory.getLogger(ConfigDumpImporter.class);
Expand All @@ -95,16 +94,7 @@ public ConfigDumpImporter(ConfigRepository configRepository, JobPersistence post
this.configRepository = configRepository;
}

public ImportRead importData(String targetVersion, File archive) {
return importDataInternal(targetVersion, archive, Optional.empty());
}

public ImportRead importDataWithSeed(String targetVersion, File archive, Path seedPath) {
return importDataInternal(targetVersion, archive, Optional.of(seedPath));
}

// seedPath - if present, merge with the import. otherwise just use the data in the import.
private ImportRead importDataInternal(String targetVersion, File archive, Optional<Path> seedPath) {
Preconditions.checkNotNull(seedPath);

ImportRead result;
Expand Down Expand Up @@ -150,7 +140,7 @@ private ImportRead importDataInternal(String targetVersion, File archive, Option
return result;
}

private void checkImport(String targetVersion, Path tempFolder, Optional<Path> seed) throws IOException, JsonValidationException {
private void checkImport(String targetVersion, Path tempFolder, Path seed) throws IOException, JsonValidationException {
final Path versionFile = tempFolder.resolve(VERSION_FILE_NAME);
final String importVersion = Files.readString(versionFile, Charset.defaultCharset())
.replace("\n", "").strip();
Expand All @@ -172,7 +162,7 @@ private List<String> listDirectories(Path sourceRoot) throws IOException {
}
}

private <T> void importConfigsFromArchive(final Path sourceRoot, Optional<Path> seedPath, final boolean dryRun)
private <T> void importConfigsFromArchive(final Path sourceRoot, Path seedPath, final boolean dryRun)
throws IOException, JsonValidationException {
final List<String> sourceDefinitionsToMigrate = new ArrayList<>();
final List<String> destinationDefinitionsToMigrate = new ArrayList<>();
Expand All @@ -185,12 +175,8 @@ private <T> void importConfigsFromArchive(final Path sourceRoot, Optional<Path>
Collections.sort(directories);
final Map<AirbyteConfig, Stream<T>> data = new LinkedHashMap<>();

final Map<ConfigSchema, Map<String, T>> seed;
if (seedPath.isPresent()) {
seed = getSeed(seedPath.get());
} else {
seed = new HashMap<>();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the root cause of the bug.

}
final Map<ConfigSchema, Map<String, T>> seed = getSeed(seedPath);

for (final String directory : directories) {
final Optional<ConfigSchema> configSchemaOptional = Enums.toEnum(directory.replace(".yaml", ""), ConfigSchema.class);

Expand Down
7 changes: 3 additions & 4 deletions airbyte-server/src/main/java/io/airbyte/server/ServerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@
import io.airbyte.server.errors.KnownExceptionMapper;
import io.airbyte.server.errors.NotFoundExceptionMapper;
import io.airbyte.server.errors.UncaughtExceptionMapper;
import io.airbyte.server.handlers.ArchiveHandler;
import io.airbyte.server.version_mismatch.VersionMismatchServer;
import io.airbyte.validation.json.JsonValidationException;
import io.airbyte.workers.temporal.TemporalClient;
import io.airbyte.workers.temporal.TemporalUtils;
import io.temporal.serviceclient.WorkflowServiceStubs;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -250,13 +250,12 @@ private static void runAutomaticMigration(ConfigRepository configRepository,
String airbyteVersion,
String airbyteDatabaseVersion) {
LOGGER.info("Running Automatic Migration from version : " + airbyteDatabaseVersion + " to version : " + airbyteVersion);
final Path latestSeedsPath = Path.of(System.getProperty("user.dir")).resolve("latest_seeds");
LOGGER.info("Last seeds dir: {}", latestSeedsPath);
LOGGER.info("Last seeds dir: {}", ArchiveHandler.SEEDS_PATH);
try (final RunMigration runMigration = new RunMigration(
jobPersistence,
configRepository,
airbyteVersion,
latestSeedsPath)) {
ArchiveHandler.SEEDS_PATH)) {
runMigration.run();
} catch (Exception e) {
LOGGER.error("Automatic Migration failed ", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class ArchiveHandler {

private static final Logger LOGGER = LoggerFactory.getLogger(ArchiveHandler.class);

public static final Path SEEDS_PATH = Path.of(System.getProperty("user.dir")).resolve("latest_seeds");

private final String version;
private final ConfigRepository configRepository;
private final ConfigDumpExporter configDumpExporter;
Expand Down Expand Up @@ -96,7 +98,7 @@ public ImportRead importData(File archive) {
try {
final Path tempFolder = Files.createTempDirectory(Path.of("/tmp"), "airbyte_archive");
try {
configDumpImporter.importData(version, archive);
configDumpImporter.importDataWithSeed(version, archive, SEEDS_PATH);
result = new ImportRead().status(StatusEnum.SUCCEEDED);
} finally {
FileUtils.deleteDirectory(tempFolder.toFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void testImport() throws IOException {
// make sure it cleans up the file.
assertFalse(Files.exists(file.toPath()));

verify(configDumpImporter).importData(VERSION, file);
verify(configDumpImporter).importDataWithSeed(VERSION, file, ArchiveHandler.SEEDS_PATH);
}

}