From b63e251edabc768a7d3dfde643747f975af193f8 Mon Sep 17 00:00:00 2001 From: Cole Snodgrass Date: Fri, 9 Dec 2022 12:47:50 -0800 Subject: [PATCH 1/3] convert to micronaut --- .../airbyte/api/client/AirbyteApiClient.java | 39 +++++++++---------- .../java/io/airbyte/server/ServerApp.java | 1 - .../java/io/airbyte/server/ServerFactory.java | 10 ----- .../server/apis/StateApiController.java | 13 +++++-- .../server/apis/binders/StateApiBinder.java | 21 ---------- .../apis/factories/StateApiFactory.java | 29 -------------- .../airbyte/server/handlers/StateHandler.java | 2 + 7 files changed, 29 insertions(+), 86 deletions(-) delete mode 100644 airbyte-server/src/main/java/io/airbyte/server/apis/binders/StateApiBinder.java delete mode 100644 airbyte-server/src/main/java/io/airbyte/server/apis/factories/StateApiFactory.java diff --git a/airbyte-api/src/main/java/io/airbyte/api/client/AirbyteApiClient.java b/airbyte-api/src/main/java/io/airbyte/api/client/AirbyteApiClient.java index cf53428e296d..a2c8ae9290f5 100644 --- a/airbyte-api/src/main/java/io/airbyte/api/client/AirbyteApiClient.java +++ b/airbyte-api/src/main/java/io/airbyte/api/client/AirbyteApiClient.java @@ -25,14 +25,14 @@ import org.slf4j.LoggerFactory; /** - * 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: + * 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: *

* ApiClient.java, FirstApi.java, SecondApi.java *

- * 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. + * 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. *

* This is currently manually maintained. We could look into autogenerating it if needed. */ @@ -74,7 +74,7 @@ public AirbyteApiClient(final ApiClient apiClient, final ApiClient micronautApiC workspaceApi = new WorkspaceApi(apiClient); healthApi = new HealthApi(micronautApiClient); attemptApi = new AttemptApi(micronautApiClient); - stateApi = new StateApi(apiClient); + stateApi = new StateApi(micronautApiClient); } public ConnectionApi getConnectionApi() { @@ -134,35 +134,32 @@ public StateApi getStateApi() { } /** - * Default to 4 retries with a randomised 1 - 10 seconds interval between the first two retries and - * an 10-minute wait for the last retry. + * Default to 4 retries with a randomised 1 - 10 seconds interval between the first two retries and an 10-minute wait for the last retry. */ public static T retryWithJitter(final Callable call, final String desc) { return retryWithJitter(call, desc, DEFAULT_RETRY_INTERVAL_SECS, DEFAULT_FINAL_INTERVAL_SECS, DEFAULT_MAX_RETRIES); } /** - * Provides a simple retry wrapper for api calls. This retry behaviour is slightly different from - * generally available retries libraries - the last retry is able to wait an interval inconsistent - * with regular intervals/exponential backoff. + * Provides a simple retry wrapper for api calls. This retry behaviour is slightly different from generally available retries libraries - the last + * retry is able to wait an interval inconsistent with regular intervals/exponential backoff. *

- * Since the primary retries use case is long-running workflows, the benefit of waiting a couple of - * minutes as a last ditch effort to outlast networking disruption outweighs the cost of slightly - * longer jobs. + * Since the primary retries use case is long-running workflows, the benefit of waiting a couple of minutes as a last ditch effort to outlast + * networking disruption outweighs the cost of slightly longer jobs. * - * @param call method to execute - * @param desc short readable explanation of why this method is executed + * @param call method to execute + * @param desc short readable explanation of why this method is executed * @param jitterMaxIntervalSecs upper limit of the randomised retry interval. Minimum value is 1. - * @param finalIntervalSecs retry interval before the last retry. + * @param finalIntervalSecs retry interval before the last retry. */ @VisibleForTesting // This is okay since we are logging the stack trace, which PMD is not detecting. @SuppressWarnings("PMD.PreserveStackTrace") public static T retryWithJitter(final Callable call, - final String desc, - final int jitterMaxIntervalSecs, - final int finalIntervalSecs, - final int maxTries) { + final String desc, + final int jitterMaxIntervalSecs, + final int finalIntervalSecs, + final int maxTries) { int currRetries = 0; boolean keepTrying = true; 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 df80788247e4..06c7e05405cb 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/ServerApp.java +++ b/airbyte-server/src/main/java/io/airbyte/server/ServerApp.java @@ -374,7 +374,6 @@ public static ServerRunnable getServer(final ServerFactory apiFactory, schedulerHandler, sourceHandler, sourceDefinitionsHandler, - stateHandler, workspacesHandler, webBackendConnectionsHandler, webBackendGeographiesHandler, 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 4a8ba1617dfa..34d7770e2771 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java +++ b/airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java @@ -28,7 +28,6 @@ import io.airbyte.server.apis.SourceDefinitionApiController; import io.airbyte.server.apis.SourceDefinitionSpecificationApiController; 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; @@ -45,7 +44,6 @@ import io.airbyte.server.apis.binders.SourceDefinitionApiBinder; import io.airbyte.server.apis.binders.SourceDefinitionSpecificationApiBinder; 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; @@ -62,7 +60,6 @@ import io.airbyte.server.apis.factories.SourceDefinitionApiFactory; import io.airbyte.server.apis.factories.SourceDefinitionSpecificationApiFactory; 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; @@ -78,7 +75,6 @@ import io.airbyte.server.handlers.SchedulerHandler; import io.airbyte.server.handlers.SourceDefinitionsHandler; import io.airbyte.server.handlers.SourceHandler; -import io.airbyte.server.handlers.StateHandler; import io.airbyte.server.handlers.WebBackendCheckUpdatesHandler; import io.airbyte.server.handlers.WebBackendConnectionsHandler; import io.airbyte.server.handlers.WebBackendGeographiesHandler; @@ -123,7 +119,6 @@ ServerRunnable create(final SynchronousSchedulerClient synchronousSchedulerClien final SchedulerHandler schedulerHandler, final SourceHandler sourceHandler, final SourceDefinitionsHandler sourceDefinitionsHandler, - final StateHandler stateHandler, final WorkspacesHandler workspacesHandler, final WebBackendConnectionsHandler webBackendConnectionsHandler, final WebBackendGeographiesHandler webBackendGeographiesHandler, @@ -161,7 +156,6 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul final SchedulerHandler schedulerHandler, final SourceHandler sourceHandler, final SourceDefinitionsHandler sourceDefinitionsHandler, - final StateHandler stateHandler, final WorkspacesHandler workspacesHandler, final WebBackendConnectionsHandler webBackendConnectionsHandler, final WebBackendGeographiesHandler webBackendGeographiesHandler, @@ -200,8 +194,6 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul SourceDefinitionSpecificationApiFactory.setValues(schedulerHandler); - StateApiFactory.setValues(stateHandler); - WebBackendApiFactory.setValues(webBackendConnectionsHandler, webBackendGeographiesHandler, webBackendCheckUpdatesHandler); WorkspaceApiFactory.setValues(workspacesHandler); @@ -223,7 +215,6 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul SourceDefinitionApiController.class, SourceDefinitionSpecificationApiController.class, SourceOauthApiController.class, - StateApiController.class, WebBackendApiController.class, WorkspaceApiController.class); @@ -243,7 +234,6 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul new SourceDefinitionApiBinder(), new SourceDefinitionSpecificationApiBinder(), new SourceOauthApiBinder(), - new StateApiBinder(), new WebBackendApiBinder(), new WorkspaceApiBinder()); diff --git a/airbyte-server/src/main/java/io/airbyte/server/apis/StateApiController.java b/airbyte-server/src/main/java/io/airbyte/server/apis/StateApiController.java index e148c1010fe3..0692d4f475ba 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/apis/StateApiController.java +++ b/airbyte-server/src/main/java/io/airbyte/server/apis/StateApiController.java @@ -9,20 +9,25 @@ import io.airbyte.api.model.generated.ConnectionState; import io.airbyte.api.model.generated.ConnectionStateCreateOrUpdate; import io.airbyte.server.handlers.StateHandler; -import javax.ws.rs.Path; -import lombok.AllArgsConstructor; +import io.micronaut.http.annotation.Controller; +import io.micronaut.http.annotation.Post; -@Path("/v1/state") -@AllArgsConstructor +@Controller("/api/v1/state") public class StateApiController implements StateApi { private final StateHandler stateHandler; + public StateApiController(final StateHandler stateHandler) { + this.stateHandler = stateHandler; + } + + @Post("/create_or_update") @Override public ConnectionState createOrUpdateState(final ConnectionStateCreateOrUpdate connectionStateCreateOrUpdate) { return ApiHelper.execute(() -> stateHandler.createOrUpdateState(connectionStateCreateOrUpdate)); } + @Post("/get") @Override public ConnectionState getState(final ConnectionIdRequestBody connectionIdRequestBody) { return ApiHelper.execute(() -> stateHandler.getState(connectionIdRequestBody)); diff --git a/airbyte-server/src/main/java/io/airbyte/server/apis/binders/StateApiBinder.java b/airbyte-server/src/main/java/io/airbyte/server/apis/binders/StateApiBinder.java deleted file mode 100644 index 65ab669528c0..000000000000 --- a/airbyte-server/src/main/java/io/airbyte/server/apis/binders/StateApiBinder.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2022 Airbyte, Inc., all rights reserved. - */ - -package io.airbyte.server.apis.binders; - -import io.airbyte.server.apis.StateApiController; -import io.airbyte.server.apis.factories.StateApiFactory; -import org.glassfish.hk2.utilities.binding.AbstractBinder; -import org.glassfish.jersey.process.internal.RequestScoped; - -public class StateApiBinder extends AbstractBinder { - - @Override - protected void configure() { - bindFactory(StateApiFactory.class) - .to(StateApiController.class) - .in(RequestScoped.class); - } - -} diff --git a/airbyte-server/src/main/java/io/airbyte/server/apis/factories/StateApiFactory.java b/airbyte-server/src/main/java/io/airbyte/server/apis/factories/StateApiFactory.java deleted file mode 100644 index 0498681d7629..000000000000 --- a/airbyte-server/src/main/java/io/airbyte/server/apis/factories/StateApiFactory.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2022 Airbyte, Inc., all rights reserved. - */ - -package io.airbyte.server.apis.factories; - -import io.airbyte.server.apis.StateApiController; -import io.airbyte.server.handlers.StateHandler; -import org.glassfish.hk2.api.Factory; - -public class StateApiFactory implements Factory { - - private static StateHandler stateHandler; - - public static void setValues(final StateHandler stateHandler) { - StateApiFactory.stateHandler = stateHandler; - } - - @Override - public StateApiController provide() { - return new StateApiController(StateApiFactory.stateHandler); - } - - @Override - public void dispose(final StateApiController instance) { - /* no op */ - } - -} diff --git a/airbyte-server/src/main/java/io/airbyte/server/handlers/StateHandler.java b/airbyte-server/src/main/java/io/airbyte/server/handlers/StateHandler.java index c9a42e9e3b93..977f95813aad 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/handlers/StateHandler.java +++ b/airbyte-server/src/main/java/io/airbyte/server/handlers/StateHandler.java @@ -10,10 +10,12 @@ import io.airbyte.config.StateWrapper; import io.airbyte.config.persistence.StatePersistence; import io.airbyte.workers.helper.StateConverter; +import jakarta.inject.Singleton; import java.io.IOException; import java.util.Optional; import java.util.UUID; +@Singleton public class StateHandler { private final StatePersistence statePersistence; From 9ff32877dac9d58b2c4bfd73369f9e6963199287 Mon Sep 17 00:00:00 2001 From: Cole Snodgrass Date: Fri, 9 Dec 2022 12:49:13 -0800 Subject: [PATCH 2/3] nginx updates --- airbyte-proxy/nginx-auth.conf.template | 4 ++-- airbyte-proxy/nginx-no-auth.conf.template | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/airbyte-proxy/nginx-auth.conf.template b/airbyte-proxy/nginx-auth.conf.template index f4afada3ea82..31a42825b643 100644 --- a/airbyte-proxy/nginx-auth.conf.template +++ b/airbyte-proxy/nginx-auth.conf.template @@ -38,7 +38,7 @@ http { } } - location ~ ^/api/v1/(connections|destinations|operations)/.* { + location ~ ^/api/v1/(connections|destinations|operations|state)/.* { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -93,7 +93,7 @@ http { } } - location ~ ^/api/v1/(connections|destinations|operations)/.* { + location ~ ^/api/v1/(connections|destinations|operations|state)/.* { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; diff --git a/airbyte-proxy/nginx-no-auth.conf.template b/airbyte-proxy/nginx-no-auth.conf.template index 664a048bbcbd..d1799a1af6d9 100644 --- a/airbyte-proxy/nginx-no-auth.conf.template +++ b/airbyte-proxy/nginx-no-auth.conf.template @@ -20,7 +20,7 @@ http { proxy_pass "${PROXY_PASS_MICRONAUT_API}"; } - location ~ ^/api/v1/(connections|destinations|operations)/.* { + location ~ ^/api/v1/(connections|destinations|operations|state)/.* { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -48,7 +48,7 @@ http { proxy_pass "${PROXY_PASS_MICRONAUT_API}"; } - location ~ ^/api/v1/(connections|destinations|operations)/.* { + location ~ ^/api/v1/(connections|destinations|operations|state)/.* { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; From 17d9e986ec8c80ebb2fa77b299af3d18dd0f7365 Mon Sep 17 00:00:00 2001 From: Cole Snodgrass Date: Fri, 9 Dec 2022 12:58:31 -0800 Subject: [PATCH 3/3] format --- .../airbyte/api/client/AirbyteApiClient.java | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/airbyte-api/src/main/java/io/airbyte/api/client/AirbyteApiClient.java b/airbyte-api/src/main/java/io/airbyte/api/client/AirbyteApiClient.java index 53ee82a3eae8..740b5edca86a 100644 --- a/airbyte-api/src/main/java/io/airbyte/api/client/AirbyteApiClient.java +++ b/airbyte-api/src/main/java/io/airbyte/api/client/AirbyteApiClient.java @@ -25,14 +25,14 @@ import org.slf4j.LoggerFactory; /** - * 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: + * 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: *

* ApiClient.java, FirstApi.java, SecondApi.java *

- * 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. + * 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. *

* This is currently manually maintained. We could look into autogenerating it if needed. */ @@ -134,32 +134,35 @@ public StateApi getStateApi() { } /** - * Default to 4 retries with a randomised 1 - 10 seconds interval between the first two retries and an 10-minute wait for the last retry. + * Default to 4 retries with a randomised 1 - 10 seconds interval between the first two retries and + * an 10-minute wait for the last retry. */ public static T retryWithJitter(final Callable call, final String desc) { return retryWithJitter(call, desc, DEFAULT_RETRY_INTERVAL_SECS, DEFAULT_FINAL_INTERVAL_SECS, DEFAULT_MAX_RETRIES); } /** - * Provides a simple retry wrapper for api calls. This retry behaviour is slightly different from generally available retries libraries - the last - * retry is able to wait an interval inconsistent with regular intervals/exponential backoff. + * Provides a simple retry wrapper for api calls. This retry behaviour is slightly different from + * generally available retries libraries - the last retry is able to wait an interval inconsistent + * with regular intervals/exponential backoff. *

- * Since the primary retries use case is long-running workflows, the benefit of waiting a couple of minutes as a last ditch effort to outlast - * networking disruption outweighs the cost of slightly longer jobs. + * Since the primary retries use case is long-running workflows, the benefit of waiting a couple of + * minutes as a last ditch effort to outlast networking disruption outweighs the cost of slightly + * longer jobs. * - * @param call method to execute - * @param desc short readable explanation of why this method is executed + * @param call method to execute + * @param desc short readable explanation of why this method is executed * @param jitterMaxIntervalSecs upper limit of the randomised retry interval. Minimum value is 1. - * @param finalIntervalSecs retry interval before the last retry. + * @param finalIntervalSecs retry interval before the last retry. */ @VisibleForTesting // This is okay since we are logging the stack trace, which PMD is not detecting. @SuppressWarnings("PMD.PreserveStackTrace") public static T retryWithJitter(final Callable call, - final String desc, - final int jitterMaxIntervalSecs, - final int finalIntervalSecs, - final int maxTries) { + final String desc, + final int jitterMaxIntervalSecs, + final int finalIntervalSecs, + final int maxTries) { int currRetries = 0; boolean keepTrying = true;