Skip to content

Commit

Permalink
Remove configuration API (#18998)
Browse files Browse the repository at this point in the history
* Extract Operation API

* Extract scheduler API

* Format

* extract source api

* Extract source definition api

* Add path

* Extract State API

* extract webbackend api

* extract webbackend api

* extract workspace api

* Extract source definition specification api

* Remove configuration API
  • Loading branch information
benmoriceau authored Nov 15, 2022
1 parent 78fb528 commit 41f3c0a
Show file tree
Hide file tree
Showing 26 changed files with 140 additions and 1,338 deletions.

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions airbyte-server/src/main/java/io/airbyte/server/ServerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,22 +348,7 @@ public static ServerRunnable getServer(final ServerFactory apiFactory,
LOGGER.info("Starting server...");

return apiFactory.create(
syncSchedulerClient,
configRepository,
secretsRepositoryReader,
secretsRepositoryWriter,
jobPersistence,
configsDatabase,
jobsDatabase,
trackingClient,
configs.getWorkerEnvironment(),
configs.getLogConfigs(),
configs.getAirbyteVersion(),
configs.getWorkspaceRoot(),
httpClient,
eventRunner,
configsFlyway,
jobsFlyway,
attemptHandler,
connectionsHandler,
dbMigrationHandler,
Expand Down
53 changes: 2 additions & 51 deletions airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,8 @@

package io.airbyte.server;

import io.airbyte.analytics.TrackingClient;
import io.airbyte.commons.version.AirbyteVersion;
import io.airbyte.config.Configs.WorkerEnvironment;
import io.airbyte.config.helpers.LogConfigs;
import io.airbyte.config.persistence.ConfigRepository;
import io.airbyte.config.persistence.SecretsRepositoryReader;
import io.airbyte.config.persistence.SecretsRepositoryWriter;
import io.airbyte.db.Database;
import io.airbyte.persistence.job.JobPersistence;
import io.airbyte.server.apis.AttemptApiController;
import io.airbyte.server.apis.ConfigurationApi;
import io.airbyte.server.apis.ConnectionApiController;
import io.airbyte.server.apis.DbMigrationApiController;
import io.airbyte.server.apis.DestinationApiController;
Expand Down Expand Up @@ -95,33 +86,13 @@
import io.airbyte.server.handlers.WebBackendConnectionsHandler;
import io.airbyte.server.handlers.WebBackendGeographiesHandler;
import io.airbyte.server.handlers.WorkspacesHandler;
import io.airbyte.server.scheduler.EventRunner;
import io.airbyte.server.scheduler.SynchronousSchedulerClient;
import java.net.http.HttpClient;
import java.nio.file.Path;
import java.util.Map;
import java.util.Set;
import org.flywaydb.core.Flyway;
import org.slf4j.MDC;

public interface ServerFactory {

ServerRunnable create(final SynchronousSchedulerClient synchronousSchedulerClient,
final ConfigRepository configRepository,
final SecretsRepositoryReader secretsRepositoryReader,
final SecretsRepositoryWriter secretsRepositoryWriter,
final JobPersistence jobPersistence,
final Database configsDatabase,
final Database jobsDatabase,
final TrackingClient trackingClient,
final WorkerEnvironment workerEnvironment,
final LogConfigs logConfigs,
final AirbyteVersion airbyteVersion,
final Path workspaceRoot,
final HttpClient httpClient,
final EventRunner eventRunner,
final Flyway configsFlyway,
final Flyway jobsFlyway,
ServerRunnable create(final AirbyteVersion airbyteVersion,
final AttemptHandler attemptHandler,
final ConnectionsHandler connectionsHandler,
final DbMigrationHandler dbMigrationHandler,
Expand All @@ -144,22 +115,7 @@ ServerRunnable create(final SynchronousSchedulerClient synchronousSchedulerClien
class Api implements ServerFactory {

@Override
public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedulerClient,
final ConfigRepository configRepository,
final SecretsRepositoryReader secretsRepositoryReader,
final SecretsRepositoryWriter secretsRepositoryWriter,
final JobPersistence jobPersistence,
final Database configsDatabase,
final Database jobsDatabase,
final TrackingClient trackingClient,
final WorkerEnvironment workerEnvironment,
final LogConfigs logConfigs,
final AirbyteVersion airbyteVersion,
final Path workspaceRoot,
final HttpClient httpClient,
final EventRunner eventRunner,
final Flyway configsFlyway,
final Flyway jobsFlyway,
public ServerRunnable create(final AirbyteVersion airbyteVersion,
final AttemptHandler attemptHandler,
final ConnectionsHandler connectionsHandler,
final DbMigrationHandler dbMigrationHandler,
Expand All @@ -180,9 +136,6 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
final WebBackendGeographiesHandler webBackendGeographiesHandler) {
final Map<String, String> mdc = MDC.getCopyOfContextMap();

// set static values for factory
ConfigurationApiFactory.setValues(mdc);

AttemptApiFactory.setValues(attemptHandler, mdc);

ConnectionApiFactory.setValues(
Expand Down Expand Up @@ -231,7 +184,6 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul

// server configurations
final Set<Class<?>> componentClasses = Set.of(
ConfigurationApi.class,
AttemptApiController.class,
ConnectionApiController.class,
DbMigrationApiController.class,
Expand All @@ -256,7 +208,6 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul

final Set<Object> components = Set.of(
new CorsFilter(),
new ConfigurationApiBinder(),
new AttemptApiBinder(),
new ConnectionApiBinder(),
new DbMigrationBinder(),
Expand Down
35 changes: 35 additions & 0 deletions airbyte-server/src/main/java/io/airbyte/server/apis/ApiHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2022 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.server.apis;

import io.airbyte.config.persistence.ConfigNotFoundException;
import io.airbyte.server.errors.BadObjectSchemaKnownException;
import io.airbyte.server.errors.IdNotFoundKnownException;
import io.airbyte.validation.json.JsonValidationException;
import java.io.IOException;

public class ApiHelper {

static <T> T execute(final HandlerCall<T> call) {
try {
return call.call();
} catch (final ConfigNotFoundException e) {
throw new IdNotFoundKnownException(String.format("Could not find configuration for %s: %s.", e.getType(), e.getConfigId()),
e.getConfigId(), e);
} catch (final JsonValidationException e) {
throw new BadObjectSchemaKnownException(
String.format("The provided configuration does not fulfill the specification. Errors: %s", e.getMessage()), e);
} catch (final IOException e) {
throw new RuntimeException(e);
}
}

interface HandlerCall<T> {

T call() throws ConfigNotFoundException, IOException, JsonValidationException;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public InternalOperationResult saveStats(final SaveStatsRequestBody saveStatsReq

@Override
public InternalOperationResult setWorkflowInAttempt(final SetWorkflowInAttemptRequestBody requestBody) {
return ConfigurationApi.execute(() -> attemptHandler.setWorkflowInAttempt(requestBody));
return ApiHelper.execute(() -> attemptHandler.setWorkflowInAttempt(requestBody));
}

}
Loading

0 comments on commit 41f3c0a

Please sign in to comment.