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

Fix exception on API calls #6346

Merged
merged 1 commit into from
Sep 21, 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 @@ -89,14 +89,13 @@ public class ConfigDumpImporter {
private static final String CONFIG_FOLDER_NAME = "airbyte_config";
private static final String DB_FOLDER_NAME = "airbyte_db";
private static final String VERSION_FILE_NAME = "VERSION";
private static final String TMP_AIRBYTE_STAGED_RESOURCES = "/tmp/airbyte_staged_resources";
private static final Path TMP_AIRBYTE_STAGED_RESOURCES = Path.of("/tmp/airbyte_staged_resources");

private final ConfigRepository configRepository;
private final WorkspaceHelper workspaceHelper;
private final SpecFetcher specFetcher;
private final JsonSchemaValidator jsonSchemaValidator;
private final JobPersistence jobPersistence;
private final Path stagedResourceRoot;

public ConfigDumpImporter(ConfigRepository configRepository,
JobPersistence jobPersistence,
Expand All @@ -116,13 +115,22 @@ public ConfigDumpImporter(ConfigRepository configRepository,
this.configRepository = configRepository;
this.workspaceHelper = workspaceHelper;
this.specFetcher = specFetcher;
}

/**
* Re-initialize the staged resource folder that contains uploaded artifacts when importing
* workspaces. This is because they need to be done in two steps (two API endpoints), upload
* resource first then import. When server starts, we flush the content of this folder, deleting
* previously staged resources that were not imported yet.
*/
public static void initStagedResourceFolder() {
try {
this.stagedResourceRoot = Path.of(TMP_AIRBYTE_STAGED_RESOURCES);
if (stagedResourceRoot.toFile().exists()) {
FileUtils.forceDelete(stagedResourceRoot.toFile());
File stagedResourceRoot = TMP_AIRBYTE_STAGED_RESOURCES.toFile();
if (stagedResourceRoot.exists()) {
FileUtils.forceDelete(stagedResourceRoot);
}
FileUtils.forceMkdir(stagedResourceRoot.toFile());
FileUtils.forceDeleteOnExit(stagedResourceRoot.toFile());
FileUtils.forceMkdir(stagedResourceRoot);
FileUtils.forceDeleteOnExit(stagedResourceRoot);
} catch (IOException e) {
throw new RuntimeException("Failed to create staging resource folder", e);
}
Expand Down Expand Up @@ -325,7 +333,7 @@ private void checkDBVersion(final String airbyteVersion) throws IOException {
public UploadRead uploadArchiveResource(File archive) {
try {
final UUID resourceId = UUID.randomUUID();
FileUtils.moveFile(archive, stagedResourceRoot.resolve(resourceId.toString()).toFile());
FileUtils.moveFile(archive, TMP_AIRBYTE_STAGED_RESOURCES.resolve(resourceId.toString()).toFile());
return new UploadRead()
.status(UploadRead.StatusEnum.SUCCEEDED)
.resourceId(resourceId);
Expand All @@ -336,7 +344,7 @@ public UploadRead uploadArchiveResource(File archive) {
}

public File getArchiveResource(UUID resourceId) {
final File archive = stagedResourceRoot.resolve(resourceId.toString()).toFile();
final File archive = TMP_AIRBYTE_STAGED_RESOURCES.resolve(resourceId.toString()).toFile();
if (!archive.exists()) {
throw new IdNotFoundKnownException("Archive Resource not found", resourceId.toString());
}
Expand Down
3 changes: 3 additions & 0 deletions airbyte-server/src/main/java/io/airbyte/server/ServerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ public static ServerRunnable getServer(final ServerFactory apiFactory) throws Ex

LogClientSingleton.setWorkspaceMdc(LogClientSingleton.getServerLogsRoot(configs));

LOGGER.info("Creating Staged Resource folder...");
ConfigDumpImporter.initStagedResourceFolder();

LOGGER.info("Creating config repository...");
final Database configDatabase = new ConfigsDatabaseInstance(
configs.getConfigDatabaseUser(),
Expand Down