Skip to content

Commit

Permalink
Bmoric/extract workspace api (#18996)
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
  • Loading branch information
benmoriceau committed Nov 8, 2022
1 parent b05a5b2 commit 1cdf1ba
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -238,6 +241,8 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul

WebBackendApiFactory.setValues(webBackendConnectionsHandler, webBackendGeographiesHandler);

WorkspaceApiFactory.setValues(workspacesHandler);

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

final Set<Object> components = Set.of(
new CorsFilter(),
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}

}
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.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);
}

}
Original file line number Diff line number Diff line change
@@ -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<WorkspaceApiController> {

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 */
}

}

0 comments on commit 1cdf1ba

Please sign in to comment.