Skip to content

Commit

Permalink
Extract source definition api (#18977)
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
  • Loading branch information
benmoriceau authored Nov 7, 2022
1 parent f9863d6 commit 29676e1
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ public static ServerRunnable getServer(final ServerFactory apiFactory,
operationsHandler,
schedulerHandler,
sourceHandler,
sourceDefinitionsHandler,
workspacesHandler);
}

Expand Down
10 changes: 10 additions & 0 deletions airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.airbyte.server.apis.OperationApiController;
import io.airbyte.server.apis.SchedulerApiController;
import io.airbyte.server.apis.SourceApiController;
import io.airbyte.server.apis.SourceDefinitionApiController;
import io.airbyte.server.apis.binders.AttemptApiBinder;
import io.airbyte.server.apis.binders.ConnectionApiBinder;
import io.airbyte.server.apis.binders.DbMigrationBinder;
Expand All @@ -45,6 +46,7 @@
import io.airbyte.server.apis.binders.OperationApiBinder;
import io.airbyte.server.apis.binders.SchedulerApiBinder;
import io.airbyte.server.apis.binders.SourceApiBinder;
import io.airbyte.server.apis.binders.SourceDefinitionApiBinder;
import io.airbyte.server.apis.binders.SourceOauthApiBinder;
import io.airbyte.server.apis.factories.AttemptApiFactory;
import io.airbyte.server.apis.factories.ConnectionApiFactory;
Expand All @@ -61,6 +63,7 @@
import io.airbyte.server.apis.factories.OperationApiFactory;
import io.airbyte.server.apis.factories.SchedulerApiFactory;
import io.airbyte.server.apis.factories.SourceApiFactory;
import io.airbyte.server.apis.factories.SourceDefinitionApiFactory;
import io.airbyte.server.apis.factories.SourceOauthApiFactory;
import io.airbyte.server.handlers.AttemptHandler;
import io.airbyte.server.handlers.ConnectionsHandler;
Expand All @@ -74,6 +77,7 @@
import io.airbyte.server.handlers.OpenApiConfigHandler;
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.WorkspacesHandler;
import io.airbyte.server.scheduler.EventRunner;
Expand Down Expand Up @@ -116,6 +120,7 @@ ServerRunnable create(final SynchronousSchedulerClient synchronousSchedulerClien
final OperationsHandler operationsHandler,
final SchedulerHandler schedulerHandler,
final SourceHandler sourceHandler,
final SourceDefinitionsHandler sourceDefinitionsHandler,
final WorkspacesHandler workspacesHandler);

class Api implements ServerFactory {
Expand Down Expand Up @@ -150,6 +155,7 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
final OperationsHandler operationsHandler,
final SchedulerHandler schedulerHandler,
final SourceHandler sourceHandler,
final SourceDefinitionsHandler sourceDefinitionsHandler,
final WorkspacesHandler workspacesHandler) {
final Map<String, String> mdc = MDC.getCopyOfContextMap();

Expand Down Expand Up @@ -210,6 +216,8 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul

SourceApiFactory.setValues(schedulerHandler, sourceHandler);

SourceDefinitionApiFactory.setValues(sourceDefinitionsHandler);

// server configurations
final Set<Class<?>> componentClasses = Set.of(
ConfigurationApi.class,
Expand All @@ -228,6 +236,7 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
OperationApiController.class,
SchedulerApiController.class,
SourceApiController.class,
SourceDefinitionApiController.class,
SourceOauthApiFactory.class);

final Set<Object> components = Set.of(
Expand All @@ -248,6 +257,7 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
new OperationApiBinder(),
new SchedulerApiBinder(),
new SourceApiBinder(),
new SourceDefinitionApiBinder(),
new SourceOauthApiBinder());

// construct server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,85 +287,132 @@ public NotificationRead tryNotificationConfig(final Notification notification) {

// SOURCE

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

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

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

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

/**
* This implementation has been moved to {@link SourceDefinitionApiController}. Since the path of
* {@link SourceDefinitionApiController} is more granular, it will override this implementation
*/
@Override
public SourceDefinitionRead getSourceDefinition(final SourceDefinitionIdRequestBody sourceDefinitionIdRequestBody) {
return execute(() -> sourceDefinitionsHandler.getSourceDefinition(sourceDefinitionIdRequestBody));
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link SourceDefinitionApiController}. Since the path of
* {@link SourceDefinitionApiController} is more granular, it will override this implementation
*/
@Override
public SourceDefinitionRead getSourceDefinitionForWorkspace(final SourceDefinitionIdWithWorkspaceId sourceDefinitionIdWithWorkspaceId) {
return execute(() -> sourceDefinitionsHandler.getSourceDefinitionForWorkspace(sourceDefinitionIdWithWorkspaceId));
throw new NotImplementedException();
}

// TODO: Deprecate this route in favor of createCustomSourceDefinition
// since all connector definitions created through the API are custom
/**
* This implementation has been moved to {@link SourceDefinitionApiController}. Since the path of
* {@link SourceDefinitionApiController} is more granular, it will override this implementation
*/
@Override
public SourceDefinitionRead createSourceDefinition(final SourceDefinitionCreate sourceDefinitionCreate) {
return execute(() -> sourceDefinitionsHandler.createPrivateSourceDefinition(sourceDefinitionCreate));
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link SourceDefinitionApiController}. Since the path of
* {@link SourceDefinitionApiController} is more granular, it will override this implementation
*/
@Override
public SourceDefinitionRead createCustomSourceDefinition(final CustomSourceDefinitionCreate customSourceDefinitionCreate) {
return execute(() -> sourceDefinitionsHandler.createCustomSourceDefinition(customSourceDefinitionCreate));
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link SourceDefinitionApiController}. Since the path of
* {@link SourceDefinitionApiController} is more granular, it will override this implementation
*/
@Override
public SourceDefinitionRead updateSourceDefinition(final SourceDefinitionUpdate sourceDefinitionUpdate) {
return execute(() -> sourceDefinitionsHandler.updateSourceDefinition(sourceDefinitionUpdate));
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link SourceDefinitionApiController}. Since the path of
* {@link SourceDefinitionApiController} is more granular, it will override this implementation
*/
@Override
public SourceDefinitionRead updateCustomSourceDefinition(final CustomSourceDefinitionUpdate customSourceDefinitionUpdate) {
return execute(() -> sourceDefinitionsHandler.updateCustomSourceDefinition(customSourceDefinitionUpdate));
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link SourceDefinitionApiController}. Since the path of
* {@link SourceDefinitionApiController} is more granular, it will override this implementation
*/
@Override
public void deleteSourceDefinition(final SourceDefinitionIdRequestBody sourceDefinitionIdRequestBody) {
execute(() -> {
sourceDefinitionsHandler.deleteSourceDefinition(sourceDefinitionIdRequestBody);
return null;
});
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link SourceDefinitionApiController}. Since the path of
* {@link SourceDefinitionApiController} is more granular, it will override this implementation
*/
@Override
public void deleteCustomSourceDefinition(final SourceDefinitionIdWithWorkspaceId sourceDefinitionIdWithWorkspaceId) {
execute(() -> {
sourceDefinitionsHandler.deleteCustomSourceDefinition(sourceDefinitionIdWithWorkspaceId);
return null;
});
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link SourceDefinitionApiController}. Since the path of
* {@link SourceDefinitionApiController} is more granular, it will override this implementation
*/
@Override
public PrivateSourceDefinitionRead grantSourceDefinitionToWorkspace(final SourceDefinitionIdWithWorkspaceId sourceDefinitionIdWithWorkspaceId) {
return execute(() -> sourceDefinitionsHandler.grantSourceDefinitionToWorkspace(sourceDefinitionIdWithWorkspaceId));
throw new NotImplementedException();
}

/**
* This implementation has been moved to {@link SourceDefinitionApiController}. Since the path of
* {@link SourceDefinitionApiController} is more granular, it will override this implementation
*/
@Override
public void revokeSourceDefinitionFromWorkspace(final SourceDefinitionIdWithWorkspaceId sourceDefinitionIdWithWorkspaceId) {
execute(() -> {
sourceDefinitionsHandler.revokeSourceDefinitionFromWorkspace(sourceDefinitionIdWithWorkspaceId);
return null;
});
throw new NotImplementedException();
}

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

package io.airbyte.server.apis;

import io.airbyte.api.generated.SourceDefinitionApi;
import io.airbyte.api.model.generated.CustomSourceDefinitionCreate;
import io.airbyte.api.model.generated.CustomSourceDefinitionUpdate;
import io.airbyte.api.model.generated.PrivateSourceDefinitionRead;
import io.airbyte.api.model.generated.PrivateSourceDefinitionReadList;
import io.airbyte.api.model.generated.SourceDefinitionCreate;
import io.airbyte.api.model.generated.SourceDefinitionIdRequestBody;
import io.airbyte.api.model.generated.SourceDefinitionIdWithWorkspaceId;
import io.airbyte.api.model.generated.SourceDefinitionRead;
import io.airbyte.api.model.generated.SourceDefinitionReadList;
import io.airbyte.api.model.generated.SourceDefinitionUpdate;
import io.airbyte.api.model.generated.WorkspaceIdRequestBody;
import io.airbyte.server.handlers.SourceDefinitionsHandler;
import javax.ws.rs.Path;
import lombok.AllArgsConstructor;

@Path("/v1/source_definitions")
@AllArgsConstructor
public class SourceDefinitionApiController implements SourceDefinitionApi {

private final SourceDefinitionsHandler sourceDefinitionsHandler;

@Override
public SourceDefinitionRead createCustomSourceDefinition(final CustomSourceDefinitionCreate customSourceDefinitionCreate) {
return ConfigurationApi.execute(() -> sourceDefinitionsHandler.createCustomSourceDefinition(customSourceDefinitionCreate));
}

// TODO: Deprecate this route in favor of createCustomSourceDefinition
// since all connector definitions created through the API are custom
@Override
public SourceDefinitionRead createSourceDefinition(final SourceDefinitionCreate sourceDefinitionCreate) {
return ConfigurationApi.execute(() -> sourceDefinitionsHandler.createPrivateSourceDefinition(sourceDefinitionCreate));
}

@Override
public void deleteCustomSourceDefinition(final SourceDefinitionIdWithWorkspaceId sourceDefinitionIdWithWorkspaceId) {
ConfigurationApi.execute(() -> {
sourceDefinitionsHandler.deleteCustomSourceDefinition(sourceDefinitionIdWithWorkspaceId);
return null;
});
}

@Override
public void deleteSourceDefinition(final SourceDefinitionIdRequestBody sourceDefinitionIdRequestBody) {
ConfigurationApi.execute(() -> {
sourceDefinitionsHandler.deleteSourceDefinition(sourceDefinitionIdRequestBody);
return null;
});
}

@Override
public SourceDefinitionRead getSourceDefinition(final SourceDefinitionIdRequestBody sourceDefinitionIdRequestBody) {
return ConfigurationApi.execute(() -> sourceDefinitionsHandler.getSourceDefinition(sourceDefinitionIdRequestBody));
}

@Override
public SourceDefinitionRead getSourceDefinitionForWorkspace(final SourceDefinitionIdWithWorkspaceId sourceDefinitionIdWithWorkspaceId) {
return ConfigurationApi.execute(() -> sourceDefinitionsHandler.getSourceDefinitionForWorkspace(sourceDefinitionIdWithWorkspaceId));
}

@Override
public PrivateSourceDefinitionRead grantSourceDefinitionToWorkspace(final SourceDefinitionIdWithWorkspaceId sourceDefinitionIdWithWorkspaceId) {
return ConfigurationApi.execute(() -> sourceDefinitionsHandler.grantSourceDefinitionToWorkspace(sourceDefinitionIdWithWorkspaceId));
}

@Override
public SourceDefinitionReadList listLatestSourceDefinitions() {
return ConfigurationApi.execute(sourceDefinitionsHandler::listLatestSourceDefinitions);
}

@Override
public PrivateSourceDefinitionReadList listPrivateSourceDefinitions(final WorkspaceIdRequestBody workspaceIdRequestBody) {
return ConfigurationApi.execute(() -> sourceDefinitionsHandler.listPrivateSourceDefinitions(workspaceIdRequestBody));
}

@Override
public SourceDefinitionReadList listSourceDefinitions() {
return ConfigurationApi.execute(sourceDefinitionsHandler::listSourceDefinitions);
}

@Override
public SourceDefinitionReadList listSourceDefinitionsForWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody) {
return ConfigurationApi.execute(() -> sourceDefinitionsHandler.listSourceDefinitionsForWorkspace(workspaceIdRequestBody));
}

@Override
public void revokeSourceDefinitionFromWorkspace(final SourceDefinitionIdWithWorkspaceId sourceDefinitionIdWithWorkspaceId) {
ConfigurationApi.execute(() -> {
sourceDefinitionsHandler.revokeSourceDefinitionFromWorkspace(sourceDefinitionIdWithWorkspaceId);
return null;
});
}

@Override
public SourceDefinitionRead updateCustomSourceDefinition(final CustomSourceDefinitionUpdate customSourceDefinitionUpdate) {
return ConfigurationApi.execute(() -> sourceDefinitionsHandler.updateCustomSourceDefinition(customSourceDefinitionUpdate));
}

@Override
public SourceDefinitionRead updateSourceDefinition(final SourceDefinitionUpdate sourceDefinitionUpdate) {
return ConfigurationApi.execute(() -> sourceDefinitionsHandler.updateSourceDefinition(sourceDefinitionUpdate));
}

}
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.SourceDefinitionApiController;
import io.airbyte.server.apis.factories.SourceDefinitionApiFactory;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.process.internal.RequestScoped;

public class SourceDefinitionApiBinder extends AbstractBinder {

@Override
protected void configure() {
bindFactory(SourceDefinitionApiFactory.class)
.to(SourceDefinitionApiController.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.SourceDefinitionApiController;
import io.airbyte.server.handlers.SourceDefinitionsHandler;
import org.glassfish.hk2.api.Factory;

public class SourceDefinitionApiFactory implements Factory<SourceDefinitionApiController> {

private static SourceDefinitionsHandler sourceDefinitionsHandler;

public static void setValues(final SourceDefinitionsHandler sourceDefinitionsHandler) {
SourceDefinitionApiFactory.sourceDefinitionsHandler = sourceDefinitionsHandler;
}

@Override
public SourceDefinitionApiController provide() {
return new SourceDefinitionApiController(SourceDefinitionApiFactory.sourceDefinitionsHandler);
}

@Override
public void dispose(final SourceDefinitionApiController instance) {
/* no op */
}

}
Loading

0 comments on commit 29676e1

Please sign in to comment.