From 1cdf1ba9e8b75846a72fd9d8b3271f18eca240ad Mon Sep 17 00:00:00 2001 From: Benoit Moriceau Date: Tue, 8 Nov 2022 10:15:57 -0800 Subject: [PATCH] Bmoric/extract workspace api (#18996) * 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 --- .../integrations/base/IntegrationRunner.java | 3 +- .../java/io/airbyte/server/ServerFactory.java | 11 ++- .../airbyte/server/apis/ConfigurationApi.java | 52 +++++++------ .../server/apis/WorkspaceApiController.java | 78 +++++++++++++++++++ .../apis/binders/WorkspaceApiBinder.java | 21 +++++ .../apis/factories/WorkspaceApiFactory.java | 29 +++++++ 6 files changed, 168 insertions(+), 26 deletions(-) create mode 100644 airbyte-server/src/main/java/io/airbyte/server/apis/WorkspaceApiController.java create mode 100644 airbyte-server/src/main/java/io/airbyte/server/apis/binders/WorkspaceApiBinder.java create mode 100644 airbyte-server/src/main/java/io/airbyte/server/apis/factories/WorkspaceApiFactory.java diff --git a/airbyte-integrations/bases/base-java/src/main/java/io/airbyte/integrations/base/IntegrationRunner.java b/airbyte-integrations/bases/base-java/src/main/java/io/airbyte/integrations/base/IntegrationRunner.java index 6b37e65cd37fa..0ea6ec7f2ea7f 100644 --- a/airbyte-integrations/bases/base-java/src/main/java/io/airbyte/integrations/base/IntegrationRunner.java +++ b/airbyte-integrations/bases/base-java/src/main/java/io/airbyte/integrations/base/IntegrationRunner.java @@ -153,7 +153,8 @@ private void runInternal(final IntegrationConfig parsed) throws Exception { default -> throw new IllegalStateException("Unexpected value: " + parsed.getCommand()); } } catch (final Exception e) { - // Many of the exceptions thrown are nested inside layers of RuntimeExceptions. An attempt is made to + // Many of the exceptions thrown are nested inside layers of RuntimeExceptions. An attempt is made + // to // find the root exception that corresponds to a configuration error. If that does not exist, we // just return the original exception. final Throwable rootThrowable = getRootConfigError(e); diff --git a/airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java b/airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java index 494aeb93a7acf..b839d66c63878 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java +++ b/airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java @@ -34,6 +34,7 @@ import io.airbyte.server.apis.SourceOauthApiController; import io.airbyte.server.apis.StateApiController; import io.airbyte.server.apis.WebBackendApiController; +import io.airbyte.server.apis.WorkspaceApiController; import io.airbyte.server.apis.binders.AttemptApiBinder; import io.airbyte.server.apis.binders.ConnectionApiBinder; import io.airbyte.server.apis.binders.DbMigrationBinder; @@ -53,6 +54,7 @@ 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.binders.WorkspaceApiBinder; import io.airbyte.server.apis.factories.AttemptApiFactory; import io.airbyte.server.apis.factories.ConnectionApiFactory; import io.airbyte.server.apis.factories.DbMigrationApiFactory; @@ -72,6 +74,7 @@ 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.apis.factories.WorkspaceApiFactory; import io.airbyte.server.handlers.AttemptHandler; import io.airbyte.server.handlers.ConnectionsHandler; import io.airbyte.server.handlers.DbMigrationHandler; @@ -238,6 +241,8 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul WebBackendApiFactory.setValues(webBackendConnectionsHandler, webBackendGeographiesHandler); + WorkspaceApiFactory.setValues(workspacesHandler); + // server configurations final Set> componentClasses = Set.of( ConfigurationApi.class, @@ -259,7 +264,8 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul SourceDefinitionApiController.class, SourceOauthApiController.class, StateApiController.class, - WebBackendApiController.class); + WebBackendApiController.class, + WorkspaceApiController.class); final Set components = Set.of( new CorsFilter(), @@ -282,7 +288,8 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul new SourceDefinitionApiBinder(), new SourceOauthApiBinder(), new StateApiBinder(), - new WebBackendApiBinder()); + new WebBackendApiBinder(), + new WorkspaceApiBinder()); // construct server return new ServerApp(airbyteVersion, componentClasses, components); diff --git a/airbyte-server/src/main/java/io/airbyte/server/apis/ConfigurationApi.java b/airbyte-server/src/main/java/io/airbyte/server/apis/ConfigurationApi.java index 1bf5f38faf62f..2c965caf997a3 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/apis/ConfigurationApi.java +++ b/airbyte-server/src/main/java/io/airbyte/server/apis/ConfigurationApi.java @@ -120,7 +120,6 @@ import io.airbyte.server.handlers.SchedulerHandler; import io.airbyte.server.handlers.SourceDefinitionsHandler; import io.airbyte.server.handlers.SourceHandler; -import io.airbyte.server.handlers.WorkspacesHandler; import io.airbyte.server.scheduler.EventRunner; import io.airbyte.server.scheduler.SynchronousSchedulerClient; import io.airbyte.validation.json.JsonSchemaValidator; @@ -135,7 +134,6 @@ @Slf4j public class ConfigurationApi implements io.airbyte.api.generated.V1Api { - private final WorkspacesHandler workspacesHandler; private final SourceDefinitionsHandler sourceDefinitionsHandler; private final SourceHandler sourceHandler; private final DestinationDefinitionsHandler destinationDefinitionsHandler; @@ -190,67 +188,75 @@ public ConfigurationApi(final ConfigRepository configRepository, schemaValidator, connectionsHandler); destinationDefinitionsHandler = new DestinationDefinitionsHandler(configRepository, synchronousSchedulerClient, destinationHandler); - workspacesHandler = new WorkspacesHandler( - configRepository, - secretsRepositoryWriter, - connectionsHandler, - destinationHandler, - sourceHandler); jobHistoryHandler = new JobHistoryHandler(jobPersistence, workerEnvironment, logConfigs, connectionsHandler, sourceHandler, sourceDefinitionsHandler, destinationHandler, destinationDefinitionsHandler, airbyteVersion); } // WORKSPACE + /** + * This implementation has been moved to {@link WorkspaceApiController}. Since the path of + * {@link WorkspaceApiController} is more granular, it will override this implementation + */ @Override public WorkspaceReadList listWorkspaces() { - return execute(workspacesHandler::listWorkspaces); + throw new NotImplementedException(); } + /** + * This implementation has been moved to {@link WorkspaceApiController}. Since the path of + * {@link WorkspaceApiController} is more granular, it will override this implementation + */ @Override public WorkspaceRead createWorkspace(final WorkspaceCreate workspaceCreate) { - return execute(() -> workspacesHandler.createWorkspace(workspaceCreate)); + throw new NotImplementedException(); } + /** + * This implementation has been moved to {@link WorkspaceApiController}. Since the path of + * {@link WorkspaceApiController} is more granular, it will override this implementation + */ @Override public void deleteWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody) { - execute(() -> { - workspacesHandler.deleteWorkspace(workspaceIdRequestBody); - return null; - }); + throw new NotImplementedException(); } + /** + * This implementation has been moved to {@link WorkspaceApiController}. Since the path of + * {@link WorkspaceApiController} is more granular, it will override this implementation + */ @Override public WorkspaceRead getWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody) { - return execute(() -> workspacesHandler.getWorkspace(workspaceIdRequestBody)); + throw new NotImplementedException(); } @Override public WorkspaceRead getWorkspaceBySlug(final SlugRequestBody slugRequestBody) { - return execute(() -> workspacesHandler.getWorkspaceBySlug(slugRequestBody)); + throw new NotImplementedException(); } + /** + * This implementation has been moved to {@link WorkspaceApiController}. Since the path of + * {@link WorkspaceApiController} is more granular, it will override this implementation + */ @Override public WorkspaceRead getWorkspaceByConnectionId(final ConnectionIdRequestBody connectionIdRequestBody) { - return execute(() -> workspacesHandler.getWorkspaceByConnectionId(connectionIdRequestBody)); + throw new NotImplementedException(); } @Override public WorkspaceRead updateWorkspace(final WorkspaceUpdate workspaceUpdate) { - return execute(() -> workspacesHandler.updateWorkspace(workspaceUpdate)); + throw new NotImplementedException(); } @Override public WorkspaceRead updateWorkspaceName(final WorkspaceUpdateName workspaceUpdateName) { - return execute(() -> workspacesHandler.updateWorkspaceName(workspaceUpdateName)); + throw new NotImplementedException(); } @Override public void updateWorkspaceFeedback(final WorkspaceGiveFeedback workspaceGiveFeedback) { - execute(() -> { - workspacesHandler.setFeedbackDone(workspaceGiveFeedback); - return null; - }); + throw new NotImplementedException(); } /** diff --git a/airbyte-server/src/main/java/io/airbyte/server/apis/WorkspaceApiController.java b/airbyte-server/src/main/java/io/airbyte/server/apis/WorkspaceApiController.java new file mode 100644 index 0000000000000..f2d9283eceac6 --- /dev/null +++ b/airbyte-server/src/main/java/io/airbyte/server/apis/WorkspaceApiController.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2022 Airbyte, Inc., all rights reserved. + */ + +package io.airbyte.server.apis; + +import io.airbyte.api.generated.WorkspaceApi; +import io.airbyte.api.model.generated.ConnectionIdRequestBody; +import io.airbyte.api.model.generated.SlugRequestBody; +import io.airbyte.api.model.generated.WorkspaceCreate; +import io.airbyte.api.model.generated.WorkspaceGiveFeedback; +import io.airbyte.api.model.generated.WorkspaceIdRequestBody; +import io.airbyte.api.model.generated.WorkspaceRead; +import io.airbyte.api.model.generated.WorkspaceReadList; +import io.airbyte.api.model.generated.WorkspaceUpdate; +import io.airbyte.api.model.generated.WorkspaceUpdateName; +import io.airbyte.server.handlers.WorkspacesHandler; +import javax.ws.rs.Path; +import lombok.AllArgsConstructor; + +@Path("/v1/workspaces") +@AllArgsConstructor +public class WorkspaceApiController implements WorkspaceApi { + + private final WorkspacesHandler workspacesHandler; + + @Override + public WorkspaceRead createWorkspace(final WorkspaceCreate workspaceCreate) { + return ConfigurationApi.execute(() -> workspacesHandler.createWorkspace(workspaceCreate)); + } + + @Override + public void deleteWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody) { + ConfigurationApi.execute(() -> { + workspacesHandler.deleteWorkspace(workspaceIdRequestBody); + return null; + }); + } + + @Override + public WorkspaceRead getWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody) { + return ConfigurationApi.execute(() -> workspacesHandler.getWorkspace(workspaceIdRequestBody)); + } + + @Override + public WorkspaceRead getWorkspaceBySlug(final SlugRequestBody slugRequestBody) { + return ConfigurationApi.execute(() -> workspacesHandler.getWorkspaceBySlug(slugRequestBody)); + } + + @Override + public WorkspaceReadList listWorkspaces() { + return ConfigurationApi.execute(workspacesHandler::listWorkspaces); + } + + @Override + public WorkspaceRead updateWorkspace(final WorkspaceUpdate workspaceUpdate) { + return ConfigurationApi.execute(() -> workspacesHandler.updateWorkspace(workspaceUpdate)); + } + + @Override + public void updateWorkspaceFeedback(final WorkspaceGiveFeedback workspaceGiveFeedback) { + ConfigurationApi.execute(() -> { + workspacesHandler.setFeedbackDone(workspaceGiveFeedback); + return null; + }); + } + + @Override + public WorkspaceRead updateWorkspaceName(final WorkspaceUpdateName workspaceUpdateName) { + return ConfigurationApi.execute(() -> workspacesHandler.updateWorkspaceName(workspaceUpdateName)); + } + + @Override + public WorkspaceRead getWorkspaceByConnectionId(final ConnectionIdRequestBody connectionIdRequestBody) { + return ConfigurationApi.execute(() -> workspacesHandler.getWorkspaceByConnectionId(connectionIdRequestBody)); + } + +} diff --git a/airbyte-server/src/main/java/io/airbyte/server/apis/binders/WorkspaceApiBinder.java b/airbyte-server/src/main/java/io/airbyte/server/apis/binders/WorkspaceApiBinder.java new file mode 100644 index 0000000000000..f114235bac50b --- /dev/null +++ b/airbyte-server/src/main/java/io/airbyte/server/apis/binders/WorkspaceApiBinder.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Airbyte, Inc., all rights reserved. + */ + +package io.airbyte.server.apis.binders; + +import io.airbyte.server.apis.WorkspaceApiController; +import io.airbyte.server.apis.factories.WorkspaceApiFactory; +import org.glassfish.hk2.utilities.binding.AbstractBinder; +import org.glassfish.jersey.process.internal.RequestScoped; + +public class WorkspaceApiBinder extends AbstractBinder { + + @Override + protected void configure() { + bindFactory(WorkspaceApiFactory.class) + .to(WorkspaceApiController.class) + .in(RequestScoped.class); + } + +} diff --git a/airbyte-server/src/main/java/io/airbyte/server/apis/factories/WorkspaceApiFactory.java b/airbyte-server/src/main/java/io/airbyte/server/apis/factories/WorkspaceApiFactory.java new file mode 100644 index 0000000000000..644c7fdadc9aa --- /dev/null +++ b/airbyte-server/src/main/java/io/airbyte/server/apis/factories/WorkspaceApiFactory.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022 Airbyte, Inc., all rights reserved. + */ + +package io.airbyte.server.apis.factories; + +import io.airbyte.server.apis.WorkspaceApiController; +import io.airbyte.server.handlers.WorkspacesHandler; +import org.glassfish.hk2.api.Factory; + +public class WorkspaceApiFactory implements Factory { + + private static WorkspacesHandler workspacesHandler; + + public static void setValues(final WorkspacesHandler workspacesHandler) { + WorkspaceApiFactory.workspacesHandler = workspacesHandler; + } + + @Override + public WorkspaceApiController provide() { + return new WorkspaceApiController(WorkspaceApiFactory.workspacesHandler); + } + + @Override + public void dispose(final WorkspaceApiController instance) { + /* no op */ + } + +}