diff --git a/airbyte-server/src/main/java/io/airbyte/server/ServerApp.java b/airbyte-server/src/main/java/io/airbyte/server/ServerApp.java index 51d81736b04c..193c4e069446 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/ServerApp.java +++ b/airbyte-server/src/main/java/io/airbyte/server/ServerApp.java @@ -63,6 +63,7 @@ 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.DefaultSynchronousSchedulerClient; import io.airbyte.server.scheduler.EventRunner; import io.airbyte.server.scheduler.TemporalEventRunner; @@ -321,6 +322,13 @@ public static ServerRunnable getServer(final ServerFactory apiFactory, final LogsHandler logsHandler = new LogsHandler(configs); + final WorkspacesHandler workspacesHandler = new WorkspacesHandler( + configRepository, + secretsRepositoryWriter, + connectionsHandler, + destinationHandler, + sourceHandler); + LOGGER.info("Starting server..."); return apiFactory.create( @@ -349,7 +357,8 @@ public static ServerRunnable getServer(final ServerFactory apiFactory, jobHistoryHandler, logsHandler, operationsHandler, - schedulerHandler); + schedulerHandler, + workspacesHandler); } @VisibleForTesting 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 dccdda8604d6..53343cee235e 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java +++ b/airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java @@ -24,6 +24,7 @@ import io.airbyte.server.apis.HealthApiController; import io.airbyte.server.apis.JobsApiController; import io.airbyte.server.apis.LogsApiController; +import io.airbyte.server.apis.NotificationsApiController; import io.airbyte.server.apis.binders.AttemptApiBinder; import io.airbyte.server.apis.binders.ConnectionApiBinder; import io.airbyte.server.apis.binders.DbMigrationBinder; @@ -33,6 +34,7 @@ import io.airbyte.server.apis.binders.HealthApiBinder; import io.airbyte.server.apis.binders.JobsApiBinder; import io.airbyte.server.apis.binders.LogsApiBinder; +import io.airbyte.server.apis.binders.NotificationApiBinder; import io.airbyte.server.apis.factories.AttemptApiFactory; import io.airbyte.server.apis.factories.ConnectionApiFactory; import io.airbyte.server.apis.factories.DbMigrationApiFactory; @@ -42,6 +44,7 @@ import io.airbyte.server.apis.factories.HealthApiFactory; import io.airbyte.server.apis.factories.JobsApiFactory; import io.airbyte.server.apis.factories.LogsApiFactory; +import io.airbyte.server.apis.factories.NotificationsApiFactory; import io.airbyte.server.handlers.AttemptHandler; import io.airbyte.server.handlers.ConnectionsHandler; import io.airbyte.server.handlers.DbMigrationHandler; @@ -52,6 +55,7 @@ import io.airbyte.server.handlers.LogsHandler; import io.airbyte.server.handlers.OperationsHandler; import io.airbyte.server.handlers.SchedulerHandler; +import io.airbyte.server.handlers.WorkspacesHandler; import io.airbyte.server.scheduler.EventRunner; import io.airbyte.server.scheduler.SynchronousSchedulerClient; import java.net.http.HttpClient; @@ -88,7 +92,8 @@ ServerRunnable create(final SynchronousSchedulerClient synchronousSchedulerClien final JobHistoryHandler jobHistoryHandler, final LogsHandler logsHandler, final OperationsHandler operationsHandler, - final SchedulerHandler schedulerHandler); + final SchedulerHandler schedulerHandler, + final WorkspacesHandler workspacesHandler); class Api implements ServerFactory { @@ -118,7 +123,8 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul final JobHistoryHandler jobHistoryHandler, final LogsHandler logsHandler, final OperationsHandler operationsHandler, - final SchedulerHandler schedulerHandler) { + final SchedulerHandler schedulerHandler, + final WorkspacesHandler workspacesHandler) { final Map mdc = MDC.getCopyOfContextMap(); // set static values for factory @@ -164,6 +170,8 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul LogsApiFactory.setValues(logsHandler); + NotificationsApiFactory.setValues(workspacesHandler); + // server configurations final Set> componentClasses = Set.of( ConfigurationApi.class, @@ -175,7 +183,8 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul DestinationDefinitionSpecificationApiController.class, HealthApiController.class, JobsApiController.class, - LogsApiController.class); + LogsApiController.class, + NotificationsApiController.class); final Set components = Set.of( new CorsFilter(), @@ -188,7 +197,8 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul new DestinationDefinitionSpecificationApiBinder(), new HealthApiBinder(), new JobsApiBinder(), - new LogsApiBinder()); + new LogsApiBinder(), + new NotificationApiBinder()); // 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 6aef4945b465..81eeab6ec982 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 @@ -276,9 +276,13 @@ public void updateWorkspaceFeedback(final WorkspaceGiveFeedback workspaceGiveFee }); } + /** + * This implementation has been moved to {@link AttemptApiController}. Since the path of + * {@link AttemptApiController} is more granular, it will override this implementation + */ @Override public NotificationRead tryNotificationConfig(final Notification notification) { - return execute(() -> workspacesHandler.tryNotification(notification)); + throw new NotImplementedException(); } // SOURCE diff --git a/airbyte-server/src/main/java/io/airbyte/server/apis/NotificationsApiController.java b/airbyte-server/src/main/java/io/airbyte/server/apis/NotificationsApiController.java new file mode 100644 index 000000000000..e6f6df3b6370 --- /dev/null +++ b/airbyte-server/src/main/java/io/airbyte/server/apis/NotificationsApiController.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022 Airbyte, Inc., all rights reserved. + */ + +package io.airbyte.server.apis; + +import io.airbyte.api.generated.NotificationsApi; +import io.airbyte.api.model.generated.Notification; +import io.airbyte.api.model.generated.NotificationRead; +import io.airbyte.server.handlers.WorkspacesHandler; +import javax.ws.rs.Path; +import lombok.AllArgsConstructor; + +@Path("/v1/notifications/try") +@AllArgsConstructor +public class NotificationsApiController implements NotificationsApi { + + private final WorkspacesHandler workspacesHandler; + + @Override + public NotificationRead tryNotificationConfig(final Notification notification) { + return ConfigurationApi.execute(() -> workspacesHandler.tryNotification(notification)); + } + +} diff --git a/airbyte-server/src/main/java/io/airbyte/server/apis/binders/NotificationApiBinder.java b/airbyte-server/src/main/java/io/airbyte/server/apis/binders/NotificationApiBinder.java new file mode 100644 index 000000000000..009c3e2d48b5 --- /dev/null +++ b/airbyte-server/src/main/java/io/airbyte/server/apis/binders/NotificationApiBinder.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Airbyte, Inc., all rights reserved. + */ + +package io.airbyte.server.apis.binders; + +import io.airbyte.server.apis.NotificationsApiController; +import io.airbyte.server.apis.factories.NotificationsApiFactory; +import org.glassfish.hk2.utilities.binding.AbstractBinder; +import org.glassfish.jersey.process.internal.RequestScoped; + +public class NotificationApiBinder extends AbstractBinder { + + @Override + protected void configure() { + bindFactory(NotificationsApiFactory.class) + .to(NotificationsApiController.class) + .in(RequestScoped.class); + } + +} diff --git a/airbyte-server/src/main/java/io/airbyte/server/apis/factories/NotificationsApiFactory.java b/airbyte-server/src/main/java/io/airbyte/server/apis/factories/NotificationsApiFactory.java new file mode 100644 index 000000000000..29a3cf7e9096 --- /dev/null +++ b/airbyte-server/src/main/java/io/airbyte/server/apis/factories/NotificationsApiFactory.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022 Airbyte, Inc., all rights reserved. + */ + +package io.airbyte.server.apis.factories; + +import io.airbyte.server.apis.NotificationsApiController; +import io.airbyte.server.handlers.WorkspacesHandler; +import org.glassfish.hk2.api.Factory; + +public class NotificationsApiFactory implements Factory { + + private static WorkspacesHandler workspacesHandler; + + public static void setValues(final WorkspacesHandler workspacesHandler) { + NotificationsApiFactory.workspacesHandler = workspacesHandler; + } + + @Override + public NotificationsApiController provide() { + return new NotificationsApiController(NotificationsApiFactory.workspacesHandler); + } + + @Override + public void dispose(final NotificationsApiController instance) { + /* no op */ + } + +}