Skip to content
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

convert WorkspaceApiController to micronaut #20214

Merged
Show file tree
Hide file tree
Changes from 7 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 @@ -28,12 +28,12 @@
* This class is meant to consolidate all our API endpoints into a fluent-ish client. Currently, all
* open API generators create a separate class per API "root-route". For example, if our API has two
* routes "/v1/First/get" and "/v1/Second/get", OpenAPI generates (essentially) the following files:
*
* <p>
* ApiClient.java, FirstApi.java, SecondApi.java
*
* <p>
* To call the API type-safely, we'd do new FirstApi(new ApiClient()).get() or new SecondApi(new
* ApiClient()).get(), which can get cumbersome if we're interacting with many pieces of the API.
*
* <p>
* This is currently manually maintained. We could look into autogenerating it if needed.
*/
public class AirbyteApiClient {
Expand Down Expand Up @@ -71,7 +71,7 @@ public AirbyteApiClient(final ApiClient apiClient, final ApiClient micronautApiC
sourceDefinitionApi = new SourceDefinitionApi(apiClient);
sourceApi = new SourceApi(apiClient);
sourceDefinitionSpecificationApi = new SourceDefinitionSpecificationApi(apiClient);
workspaceApi = new WorkspaceApi(apiClient);
workspaceApi = new WorkspaceApi(micronautApiClient);
healthApi = new HealthApi(micronautApiClient);
attemptApi = new AttemptApi(micronautApiClient);
stateApi = new StateApi(apiClient);
Expand Down
34 changes: 34 additions & 0 deletions airbyte-proxy/nginx-auth.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ http {
auth_basic off;
}
}

location /api/v1/workspaces {
colesnodgrass marked this conversation as resolved.
Show resolved Hide resolved
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

auth_basic "Welcome to Airbyte";
auth_basic_user_file /etc/nginx/.htpasswd;

proxy_pass "${PROXY_PASS_MICRONAUT_API}";

error_page 401 /etc/nginx/401.html;
location ~ (401.html)$ {
alias /etc/nginx/$1;
auth_basic off;
}
}
}

server {
Expand Down Expand Up @@ -75,6 +92,23 @@ http {
auth_basic off;
}
}

location /api/v1/workspaces {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

auth_basic "Welcome to Airbyte";
auth_basic_user_file /etc/nginx/.htpasswd;

proxy_pass "${PROXY_PASS_MICRONAUT_API}";

error_page 401 /etc/nginx/401.html;
location ~ (401.html)$ {
alias /etc/nginx/$1;
auth_basic off;
}
}
}

server {
Expand Down
24 changes: 24 additions & 0 deletions airbyte-proxy/nginx-no-auth.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ http {

proxy_pass "${PROXY_PASS_MICRONAUT_API}";
}

location /api/v1/workspaces {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass "${PROXY_PASS_MICRONAUT_API}";
}

location /api/test {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass "${PROXY_PASS_MICRONAUT_API}";
}
}

server {
Expand All @@ -39,6 +55,14 @@ http {

proxy_pass "${PROXY_PASS_MICRONAUT_API}";
}

location /api/v1/workspaces {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass "${PROXY_PASS_MICRONAUT_API}";
}
}

server {
Expand Down
4 changes: 3 additions & 1 deletion airbyte-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ dependencies {

annotationProcessor platform(libs.micronaut.bom)
annotationProcessor libs.bundles.micronaut.annotation.processor
annotationProcessor libs.micronaut.jaxrs.processor

implementation platform(libs.micronaut.bom)
implementation libs.bundles.micronaut
implementation libs.micronaut.jaxrs.server

// Ensure that the versions defined in deps.toml are used
// instead of versions from transitive dependencies
implementation (libs.flyway.core) {
implementation(libs.flyway.core) {
force = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ public class EventListener {
public void startEmitters(final ApplicationStartupEvent event) {
try {
/*
In order to have a smooth transition to micronaut for the server, we are starting 2 server. One managed by glassfish (legacy), one by
micronaut. Once all the controller are migrated, this will go away.
* In order to have a smooth transition to micronaut for the server, we are starting 2 server. One
* managed by glassfish (legacy), one by micronaut. Once all the controller are migrated, this will
* go away.
*/
final Configs configs = new EnvConfigs();

Expand Down
5 changes: 3 additions & 2 deletions airbyte-server/src/main/java/io/airbyte/server/ServerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ public static ServerRunnable getServer(final ServerFactory apiFactory,
final Optional<SecretPersistence> ephemeralSecretPersistence = SecretPersistence.getEphemeral(configsDslContext, configs);
final ConfigRepository configRepository = new ConfigRepository(configsDatabase);
final SecretsRepositoryReader secretsRepositoryReader = new SecretsRepositoryReader(configRepository, secretsHydrator);
final SecretsRepositoryWriter secretsRepositoryWriter =
new SecretsRepositoryWriter(configRepository, secretPersistence, ephemeralSecretPersistence);
final SecretsRepositoryWriter secretsRepositoryWriter = new SecretsRepositoryWriter(configRepository, secretPersistence,
ephemeralSecretPersistence);

LOGGER.info("Creating jobs persistence...");
final Database jobsDatabase = new Database(jobsDslContext);
Expand Down Expand Up @@ -374,4 +374,5 @@ public static ServerRunnable getServer(final ServerFactory apiFactory,
webBackendConnectionsHandler,
webBackendGeographiesHandler);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
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.ConnectionApiBinder;
import io.airbyte.server.apis.binders.DestinationApiBinder;
import io.airbyte.server.apis.binders.DestinationDefinitionApiBinder;
Expand All @@ -48,7 +47,6 @@
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.ConnectionApiFactory;
import io.airbyte.server.apis.factories.DestinationApiFactory;
import io.airbyte.server.apis.factories.DestinationDefinitionApiFactory;
Expand All @@ -66,7 +64,6 @@
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.DestinationDefinitionsHandler;
Expand Down Expand Up @@ -205,8 +202,6 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul

WebBackendApiFactory.setValues(webBackendConnectionsHandler, webBackendGeographiesHandler);

WorkspaceApiFactory.setValues(workspacesHandler);

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

final Set<Object> components = Set.of(
new CorsFilter(),
Expand All @@ -246,8 +240,7 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
new SourceDefinitionSpecificationApiBinder(),
new SourceOauthApiBinder(),
new StateApiBinder(),
new WebBackendApiBinder(),
new WorkspaceApiBinder());
new WebBackendApiBinder());

// construct server
return new ServerApp(airbyteVersion, componentClasses, components);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,63 +15,76 @@
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;
import io.micronaut.http.annotation.Body;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Post;

@Path("/v1/workspaces")
@AllArgsConstructor
@Controller("/api/v1/workspaces")
public class WorkspaceApiController implements WorkspaceApi {

private final WorkspacesHandler workspacesHandler;

public WorkspaceApiController(final WorkspacesHandler workspacesHandler) {
this.workspacesHandler = workspacesHandler;
}

@Post("/create")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add the payload mediatype?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @Controller annotation defaults to application/json, so we only need to specify it if we're not using json.

@Override
public WorkspaceRead createWorkspace(final WorkspaceCreate workspaceCreate) {
public WorkspaceRead createWorkspace(@Body final WorkspaceCreate workspaceCreate) {
return ApiHelper.execute(() -> workspacesHandler.createWorkspace(workspaceCreate));
}

@Post("/delete")
@Override
public void deleteWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody) {
public void deleteWorkspace(@Body final WorkspaceIdRequestBody workspaceIdRequestBody) {
ApiHelper.execute(() -> {
workspacesHandler.deleteWorkspace(workspaceIdRequestBody);
return null;
});
}

@Post("/get")
@Override
public WorkspaceRead getWorkspace(final WorkspaceIdRequestBody workspaceIdRequestBody) {
public WorkspaceRead getWorkspace(@Body final WorkspaceIdRequestBody workspaceIdRequestBody) {
return ApiHelper.execute(() -> workspacesHandler.getWorkspace(workspaceIdRequestBody));
}

@Post("/get_by_slug")
@Override
public WorkspaceRead getWorkspaceBySlug(final SlugRequestBody slugRequestBody) {
public WorkspaceRead getWorkspaceBySlug(@Body final SlugRequestBody slugRequestBody) {
return ApiHelper.execute(() -> workspacesHandler.getWorkspaceBySlug(slugRequestBody));
}

@Post("/list")
@Override
public WorkspaceReadList listWorkspaces() {
return ApiHelper.execute(workspacesHandler::listWorkspaces);
}

@Post("/update")
@Override
public WorkspaceRead updateWorkspace(final WorkspaceUpdate workspaceUpdate) {
public WorkspaceRead updateWorkspace(@Body final WorkspaceUpdate workspaceUpdate) {
return ApiHelper.execute(() -> workspacesHandler.updateWorkspace(workspaceUpdate));
}

@Post("/tag_feedback_status_as_done")
@Override
public void updateWorkspaceFeedback(final WorkspaceGiveFeedback workspaceGiveFeedback) {
public void updateWorkspaceFeedback(@Body final WorkspaceGiveFeedback workspaceGiveFeedback) {
ApiHelper.execute(() -> {
workspacesHandler.setFeedbackDone(workspaceGiveFeedback);
return null;
});
}

@Post("/update_name")
@Override
public WorkspaceRead updateWorkspaceName(final WorkspaceUpdateName workspaceUpdateName) {
public WorkspaceRead updateWorkspaceName(@Body final WorkspaceUpdateName workspaceUpdateName) {
return ApiHelper.execute(() -> workspacesHandler.updateWorkspaceName(workspaceUpdateName));
}

@Post("/get_by_connection_id")
@Override
public WorkspaceRead getWorkspaceByConnectionId(final ConnectionIdRequestBody connectionIdRequestBody) {
public WorkspaceRead getWorkspaceByConnectionId(@Body final ConnectionIdRequestBody connectionIdRequestBody) {
return ApiHelper.execute(() -> workspacesHandler.getWorkspaceByConnectionId(connectionIdRequestBody));
}

Expand Down

This file was deleted.

This file was deleted.

Loading