Skip to content

Bmoric/extract webbackend api #18988

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

Merged
merged 16 commits into from
Nov 8, 2022
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 @@ -31,7 +31,6 @@ public class ConfigurationApiFactory implements Factory<ConfigurationApi> {
private static SecretsRepositoryReader secretsRepositoryReader;
private static SecretsRepositoryWriter secretsRepositoryWriter;
private static SynchronousSchedulerClient synchronousSchedulerClient;
private static StatePersistence statePersistence;
private static Map<String, String> mdc;
private static TrackingClient trackingClient;
private static WorkerEnvironment workerEnvironment;
Expand Down Expand Up @@ -69,7 +68,6 @@ public static void setValues(
ConfigurationApiFactory.logConfigs = logConfigs;
ConfigurationApiFactory.airbyteVersion = airbyteVersion;
ConfigurationApiFactory.eventRunner = eventRunner;
ConfigurationApiFactory.statePersistence = statePersistence;
}

@Override
Expand All @@ -82,7 +80,6 @@ public ConfigurationApi provide() {
ConfigurationApiFactory.secretsRepositoryReader,
ConfigurationApiFactory.secretsRepositoryWriter,
ConfigurationApiFactory.synchronousSchedulerClient,
ConfigurationApiFactory.statePersistence,
ConfigurationApiFactory.trackingClient,
ConfigurationApiFactory.workerEnvironment,
ConfigurationApiFactory.logConfigs,
Expand Down
19 changes: 18 additions & 1 deletion airbyte-server/src/main/java/io/airbyte/server/ServerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
import io.airbyte.server.handlers.SourceDefinitionsHandler;
import io.airbyte.server.handlers.SourceHandler;
import io.airbyte.server.handlers.StateHandler;
import io.airbyte.server.handlers.WebBackendConnectionsHandler;
import io.airbyte.server.handlers.WebBackendGeographiesHandler;
import io.airbyte.server.handlers.WorkspacesHandler;
import io.airbyte.server.scheduler.DefaultSynchronousSchedulerClient;
import io.airbyte.server.scheduler.EventRunner;
Expand Down Expand Up @@ -326,6 +328,19 @@ public static ServerRunnable getServer(final ServerFactory apiFactory,

final StateHandler stateHandler = new StateHandler(statePersistence);

final WebBackendConnectionsHandler webBackendConnectionsHandler = new WebBackendConnectionsHandler(
connectionsHandler,
stateHandler,
sourceHandler,
destinationHandler,
jobHistoryHandler,
schedulerHandler,
operationsHandler,
eventRunner,
configRepository);

final WebBackendGeographiesHandler webBackendGeographiesHandler = new WebBackendGeographiesHandler();

LOGGER.info("Starting server...");

return apiFactory.create(
Expand Down Expand Up @@ -360,7 +375,9 @@ public static ServerRunnable getServer(final ServerFactory apiFactory,
sourceHandler,
sourceDefinitionsHandler,
stateHandler,
workspacesHandler);
workspacesHandler,
webBackendConnectionsHandler,
webBackendGeographiesHandler);
}

public static void main(final String[] args) {
Expand Down
21 changes: 17 additions & 4 deletions airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import io.airbyte.server.apis.SourceDefinitionApiController;
import io.airbyte.server.apis.SourceOauthApiController;
import io.airbyte.server.apis.StateApiController;
import io.airbyte.server.apis.WebBackendApiController;
import io.airbyte.server.apis.binders.AttemptApiBinder;
import io.airbyte.server.apis.binders.ConnectionApiBinder;
import io.airbyte.server.apis.binders.DbMigrationBinder;
Expand All @@ -51,6 +52,7 @@
import io.airbyte.server.apis.binders.SourceDefinitionApiBinder;
import io.airbyte.server.apis.binders.SourceOauthApiBinder;
import io.airbyte.server.apis.binders.StateApiBinder;
import io.airbyte.server.apis.binders.WebBackendApiBinder;
import io.airbyte.server.apis.factories.AttemptApiFactory;
import io.airbyte.server.apis.factories.ConnectionApiFactory;
import io.airbyte.server.apis.factories.DbMigrationApiFactory;
Expand All @@ -69,6 +71,7 @@
import io.airbyte.server.apis.factories.SourceDefinitionApiFactory;
import io.airbyte.server.apis.factories.SourceOauthApiFactory;
import io.airbyte.server.apis.factories.StateApiFactory;
import io.airbyte.server.apis.factories.WebBackendApiFactory;
import io.airbyte.server.handlers.AttemptHandler;
import io.airbyte.server.handlers.ConnectionsHandler;
import io.airbyte.server.handlers.DbMigrationHandler;
Expand All @@ -84,6 +87,8 @@
import io.airbyte.server.handlers.SourceDefinitionsHandler;
import io.airbyte.server.handlers.SourceHandler;
import io.airbyte.server.handlers.StateHandler;
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;
Expand Down Expand Up @@ -127,7 +132,9 @@ ServerRunnable create(final SynchronousSchedulerClient synchronousSchedulerClien
final SourceHandler sourceHandler,
final SourceDefinitionsHandler sourceDefinitionsHandler,
final StateHandler stateHandler,
final WorkspacesHandler workspacesHandler);
final WorkspacesHandler workspacesHandler,
final WebBackendConnectionsHandler webBackendConnectionsHandler,
final WebBackendGeographiesHandler webBackendGeographiesHandler);

class Api implements ServerFactory {

Expand Down Expand Up @@ -163,7 +170,9 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
final SourceHandler sourceHandler,
final SourceDefinitionsHandler sourceDefinitionsHandler,
final StateHandler stateHandler,
final WorkspacesHandler workspacesHandler) {
final WorkspacesHandler workspacesHandler,
final WebBackendConnectionsHandler webBackendConnectionsHandler,
final WebBackendGeographiesHandler webBackendGeographiesHandler) {
final Map<String, String> mdc = MDC.getCopyOfContextMap();

// set static values for factory
Expand Down Expand Up @@ -227,6 +236,8 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul

StateApiFactory.setValues(stateHandler);

WebBackendApiFactory.setValues(webBackendConnectionsHandler, webBackendGeographiesHandler);

// server configurations
final Set<Class<?>> componentClasses = Set.of(
ConfigurationApi.class,
Expand All @@ -247,7 +258,8 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
SourceApiController.class,
SourceDefinitionApiController.class,
SourceOauthApiController.class,
StateApiController.class);
StateApiController.class,
WebBackendApiController.class);

final Set<Object> components = Set.of(
new CorsFilter(),
Expand All @@ -269,7 +281,8 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
new SourceApiBinder(),
new SourceDefinitionApiBinder(),
new SourceOauthApiBinder(),
new StateApiBinder());
new StateApiBinder(),
new WebBackendApiBinder());

// construct server
return new ServerApp(airbyteVersion, componentClasses, components);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
import io.airbyte.config.persistence.ConfigRepository;
import io.airbyte.config.persistence.SecretsRepositoryReader;
import io.airbyte.config.persistence.SecretsRepositoryWriter;
import io.airbyte.config.persistence.StatePersistence;
import io.airbyte.persistence.job.JobPersistence;
import io.airbyte.persistence.job.WorkspaceHelper;
import io.airbyte.server.errors.BadObjectSchemaKnownException;
Expand All @@ -118,13 +117,9 @@
import io.airbyte.server.handlers.DestinationDefinitionsHandler;
import io.airbyte.server.handlers.DestinationHandler;
import io.airbyte.server.handlers.JobHistoryHandler;
import io.airbyte.server.handlers.OperationsHandler;
import io.airbyte.server.handlers.SchedulerHandler;
import io.airbyte.server.handlers.SourceDefinitionsHandler;
import io.airbyte.server.handlers.SourceHandler;
import io.airbyte.server.handlers.StateHandler;
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;
Expand All @@ -146,19 +141,14 @@ public class ConfigurationApi implements io.airbyte.api.generated.V1Api {
private final DestinationDefinitionsHandler destinationDefinitionsHandler;
private final DestinationHandler destinationHandler;
private final ConnectionsHandler connectionsHandler;
private final OperationsHandler operationsHandler;
private final SchedulerHandler schedulerHandler;
private final StateHandler stateHandler;
private final JobHistoryHandler jobHistoryHandler;
private final WebBackendConnectionsHandler webBackendConnectionsHandler;
private final WebBackendGeographiesHandler webBackendGeographiesHandler;

public ConfigurationApi(final ConfigRepository configRepository,
final JobPersistence jobPersistence,
final SecretsRepositoryReader secretsRepositoryReader,
final SecretsRepositoryWriter secretsRepositoryWriter,
final SynchronousSchedulerClient synchronousSchedulerClient,
final StatePersistence statePersistence,
final TrackingClient trackingClient,
final WorkerEnvironment workerEnvironment,
final LogConfigs logConfigs,
Expand Down Expand Up @@ -186,15 +176,13 @@ public ConfigurationApi(final ConfigRepository configRepository,
eventRunner,
connectionsHandler);

stateHandler = new StateHandler(statePersistence);
sourceHandler = new SourceHandler(
configRepository,
secretsRepositoryReader,
secretsRepositoryWriter,
schemaValidator,
connectionsHandler);
sourceDefinitionsHandler = new SourceDefinitionsHandler(configRepository, synchronousSchedulerClient, sourceHandler);
operationsHandler = new OperationsHandler(configRepository);
destinationHandler = new DestinationHandler(
configRepository,
secretsRepositoryReader,
Expand All @@ -210,17 +198,6 @@ public ConfigurationApi(final ConfigRepository configRepository,
sourceHandler);
jobHistoryHandler = new JobHistoryHandler(jobPersistence, workerEnvironment, logConfigs, connectionsHandler, sourceHandler,
sourceDefinitionsHandler, destinationHandler, destinationDefinitionsHandler, airbyteVersion);
webBackendConnectionsHandler = new WebBackendConnectionsHandler(
connectionsHandler,
stateHandler,
sourceHandler,
destinationHandler,
jobHistoryHandler,
schedulerHandler,
operationsHandler,
eventRunner,
configRepository);
webBackendGeographiesHandler = new WebBackendGeographiesHandler();
}

// WORKSPACE
Expand Down Expand Up @@ -417,7 +394,7 @@ public void revokeSourceDefinitionFromWorkspace(final SourceDefinitionIdWithWork

@Override
public InternalOperationResult saveStats(final SaveStatsRequestBody saveStatsRequestBody) {
throw new UnsupportedOperationException();
throw new NotImplementedException();
}

// SOURCE SPECIFICATION
Expand Down Expand Up @@ -1116,39 +1093,67 @@ public HealthCheckRead getHealthCheck() {

// WEB BACKEND

/**
* This implementation has been moved to {@link HealthApiController}. Since the path of
* {@link HealthApiController} is more granular, it will override this implementation
*/
@Override
public WebBackendConnectionReadList webBackendListConnectionsForWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody) {
return execute(() -> webBackendConnectionsHandler.webBackendListConnectionsForWorkspace(workspaceIdRequestBody));
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link HealthApiController}. Since the path of
* {@link HealthApiController} is more granular, it will override this implementation
*/
@Override
public WebBackendGeographiesListResult webBackendListGeographies() {
return execute(webBackendGeographiesHandler::listGeographiesOSS);
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link HealthApiController}. Since the path of
* {@link HealthApiController} is more granular, it will override this implementation
*/
@Override
public WebBackendConnectionRead webBackendGetConnection(final WebBackendConnectionRequestBody webBackendConnectionRequestBody) {
return execute(() -> webBackendConnectionsHandler.webBackendGetConnection(webBackendConnectionRequestBody));
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link HealthApiController}. Since the path of
* {@link HealthApiController} is more granular, it will override this implementation
*/
@Override
public WebBackendConnectionRead webBackendCreateConnection(final WebBackendConnectionCreate webBackendConnectionCreate) {
return execute(() -> webBackendConnectionsHandler.webBackendCreateConnection(webBackendConnectionCreate));
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link HealthApiController}. Since the path of
* {@link HealthApiController} is more granular, it will override this implementation
*/
@Override
public WebBackendConnectionRead webBackendUpdateConnection(final WebBackendConnectionUpdate webBackendConnectionUpdate) {
return execute(() -> webBackendConnectionsHandler.webBackendUpdateConnection(webBackendConnectionUpdate));
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link HealthApiController}. Since the path of
* {@link HealthApiController} is more granular, it will override this implementation
*/
@Override
public ConnectionStateType getStateType(final ConnectionIdRequestBody connectionIdRequestBody) {
return ConfigurationApi.execute(() -> webBackendConnectionsHandler.getStateType(connectionIdRequestBody));
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link HealthApiController}. Since the path of
* {@link HealthApiController} is more granular, it will override this implementation
*/
@Override
public WebBackendWorkspaceStateResult webBackendGetWorkspaceState(final WebBackendWorkspaceState webBackendWorkspaceState) {
return execute(() -> webBackendConnectionsHandler.getWorkspaceState(webBackendWorkspaceState));
throw new NotImplementedException();
}

// TODO: Move to common when all the api are moved
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2022 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.server.apis;

import io.airbyte.api.generated.WebBackendApi;
import io.airbyte.api.model.generated.ConnectionIdRequestBody;
import io.airbyte.api.model.generated.ConnectionStateType;
import io.airbyte.api.model.generated.WebBackendConnectionCreate;
import io.airbyte.api.model.generated.WebBackendConnectionRead;
import io.airbyte.api.model.generated.WebBackendConnectionReadList;
import io.airbyte.api.model.generated.WebBackendConnectionRequestBody;
import io.airbyte.api.model.generated.WebBackendConnectionUpdate;
import io.airbyte.api.model.generated.WebBackendGeographiesListResult;
import io.airbyte.api.model.generated.WebBackendWorkspaceState;
import io.airbyte.api.model.generated.WebBackendWorkspaceStateResult;
import io.airbyte.api.model.generated.WorkspaceIdRequestBody;
import io.airbyte.server.handlers.WebBackendConnectionsHandler;
import io.airbyte.server.handlers.WebBackendGeographiesHandler;
import javax.ws.rs.Path;
import lombok.AllArgsConstructor;

@Path("/v1/web_backend")
@AllArgsConstructor
public class WebBackendApiController implements WebBackendApi {

private final WebBackendConnectionsHandler webBackendConnectionsHandler;
private final WebBackendGeographiesHandler webBackendGeographiesHandler;

@Override
public ConnectionStateType getStateType(final ConnectionIdRequestBody connectionIdRequestBody) {
return ConfigurationApi.execute(() -> webBackendConnectionsHandler.getStateType(connectionIdRequestBody));
}

@Override
public WebBackendConnectionRead webBackendCreateConnection(final WebBackendConnectionCreate webBackendConnectionCreate) {
return ConfigurationApi.execute(() -> webBackendConnectionsHandler.webBackendCreateConnection(webBackendConnectionCreate));
}

@Override
public WebBackendConnectionRead webBackendGetConnection(final WebBackendConnectionRequestBody webBackendConnectionRequestBody) {
return ConfigurationApi.execute(() -> webBackendConnectionsHandler.webBackendGetConnection(webBackendConnectionRequestBody));
}

@Override
public WebBackendWorkspaceStateResult webBackendGetWorkspaceState(final WebBackendWorkspaceState webBackendWorkspaceState) {
return ConfigurationApi.execute(() -> webBackendConnectionsHandler.getWorkspaceState(webBackendWorkspaceState));
}

@Override
public WebBackendConnectionReadList webBackendListConnectionsForWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody) {
return ConfigurationApi.execute(() -> webBackendConnectionsHandler.webBackendListConnectionsForWorkspace(workspaceIdRequestBody));
}

@Override
public WebBackendGeographiesListResult webBackendListGeographies() {
return ConfigurationApi.execute(webBackendGeographiesHandler::listGeographiesOSS);
}

@Override
public WebBackendConnectionRead webBackendUpdateConnection(final WebBackendConnectionUpdate webBackendConnectionUpdate) {
return ConfigurationApi.execute(() -> webBackendConnectionsHandler.webBackendUpdateConnection(webBackendConnectionUpdate));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2022 Airbyte, Inc., all rights reserved.
*/

package io.airbyte.server.apis.binders;

import io.airbyte.server.apis.WebBackendApiController;
import io.airbyte.server.apis.factories.WebBackendApiFactory;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.process.internal.RequestScoped;

public class WebBackendApiBinder extends AbstractBinder {

@Override
protected void configure() {
bindFactory(WebBackendApiFactory.class)
.to(WebBackendApiController.class)
.in(RequestScoped.class);
}

}
Loading