diff --git a/airbyte-server/src/main/java/io/airbyte/server/ConfigurationApiFactory.java b/airbyte-server/src/main/java/io/airbyte/server/ConfigurationApiFactory.java index 297718c74fd9f4..4cf5484e4d7bb2 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/ConfigurationApiFactory.java +++ b/airbyte-server/src/main/java/io/airbyte/server/ConfigurationApiFactory.java @@ -36,7 +36,6 @@ public class ConfigurationApiFactory implements Factory { private static TrackingClient trackingClient; private static WorkerEnvironment workerEnvironment; private static LogConfigs logConfigs; - private static Path workspaceRoot; private static AirbyteVersion airbyteVersion; private static HttpClient httpClient; private static EventRunner eventRunner; @@ -69,7 +68,6 @@ public static void setValues( ConfigurationApiFactory.trackingClient = trackingClient; ConfigurationApiFactory.workerEnvironment = workerEnvironment; ConfigurationApiFactory.logConfigs = logConfigs; - ConfigurationApiFactory.workspaceRoot = workspaceRoot; ConfigurationApiFactory.airbyteVersion = airbyteVersion; ConfigurationApiFactory.httpClient = httpClient; ConfigurationApiFactory.eventRunner = eventRunner; @@ -91,7 +89,6 @@ public ConfigurationApi provide() { ConfigurationApiFactory.workerEnvironment, ConfigurationApiFactory.logConfigs, ConfigurationApiFactory.airbyteVersion, - ConfigurationApiFactory.workspaceRoot, ConfigurationApiFactory.httpClient, ConfigurationApiFactory.eventRunner); } 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 82c5edda01aeae..51d81736b04c77 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/ServerApp.java +++ b/airbyte-server/src/main/java/io/airbyte/server/ServerApp.java @@ -58,6 +58,7 @@ import io.airbyte.server.handlers.DestinationHandler; import io.airbyte.server.handlers.HealthCheckHandler; import io.airbyte.server.handlers.JobHistoryHandler; +import io.airbyte.server.handlers.LogsHandler; import io.airbyte.server.handlers.OperationsHandler; import io.airbyte.server.handlers.SchedulerHandler; import io.airbyte.server.handlers.SourceDefinitionsHandler; @@ -318,6 +319,8 @@ public static ServerRunnable getServer(final ServerFactory apiFactory, destinationDefinitionsHandler, configs.getAirbyteVersion()); + final LogsHandler logsHandler = new LogsHandler(configs); + LOGGER.info("Starting server..."); return apiFactory.create( @@ -344,6 +347,7 @@ public static ServerRunnable getServer(final ServerFactory apiFactory, destinationHandler, healthCheckHandler, jobHistoryHandler, + logsHandler, operationsHandler, schedulerHandler); } 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 4e8723a5cb00f6..dccdda8604d623 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java +++ b/airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java @@ -23,6 +23,7 @@ import io.airbyte.server.apis.DestinationDefinitionSpecificationApiController; import io.airbyte.server.apis.HealthApiController; import io.airbyte.server.apis.JobsApiController; +import io.airbyte.server.apis.LogsApiController; import io.airbyte.server.apis.binders.AttemptApiBinder; import io.airbyte.server.apis.binders.ConnectionApiBinder; import io.airbyte.server.apis.binders.DbMigrationBinder; @@ -31,6 +32,7 @@ import io.airbyte.server.apis.binders.DestinationDefinitionSpecificationApiBinder; 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.factories.AttemptApiFactory; import io.airbyte.server.apis.factories.ConnectionApiFactory; import io.airbyte.server.apis.factories.DbMigrationApiFactory; @@ -39,6 +41,7 @@ import io.airbyte.server.apis.factories.DestinationDefinitionSpecificationApiFactory; 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.handlers.AttemptHandler; import io.airbyte.server.handlers.ConnectionsHandler; import io.airbyte.server.handlers.DbMigrationHandler; @@ -46,6 +49,7 @@ import io.airbyte.server.handlers.DestinationHandler; import io.airbyte.server.handlers.HealthCheckHandler; import io.airbyte.server.handlers.JobHistoryHandler; +import io.airbyte.server.handlers.LogsHandler; import io.airbyte.server.handlers.OperationsHandler; import io.airbyte.server.handlers.SchedulerHandler; import io.airbyte.server.scheduler.EventRunner; @@ -82,6 +86,7 @@ ServerRunnable create(final SynchronousSchedulerClient synchronousSchedulerClien final DestinationHandler destinationApiHandler, final HealthCheckHandler healthCheckHandler, final JobHistoryHandler jobHistoryHandler, + final LogsHandler logsHandler, final OperationsHandler operationsHandler, final SchedulerHandler schedulerHandler); @@ -111,6 +116,7 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul final DestinationHandler destinationApiHandler, final HealthCheckHandler healthCheckHandler, final JobHistoryHandler jobHistoryHandler, + final LogsHandler logsHandler, final OperationsHandler operationsHandler, final SchedulerHandler schedulerHandler) { final Map mdc = MDC.getCopyOfContextMap(); @@ -156,6 +162,8 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul JobsApiFactory.setValues(jobHistoryHandler, schedulerHandler); + LogsApiFactory.setValues(logsHandler); + // server configurations final Set> componentClasses = Set.of( ConfigurationApi.class, @@ -166,7 +174,8 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul DestinationDefinitionApiController.class, DestinationDefinitionSpecificationApiController.class, HealthApiController.class, - JobsApiController.class); + JobsApiController.class, + LogsApiController.class); final Set components = Set.of( new CorsFilter(), @@ -178,7 +187,8 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul new DestinationDefinitionApiBinder(), new DestinationDefinitionSpecificationApiBinder(), new HealthApiBinder(), - new JobsApiBinder()); + new JobsApiBinder(), + new LogsApiBinder()); // 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 6eab18d1998c8c..6aef4945b46588 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 @@ -117,7 +117,6 @@ import io.airbyte.server.handlers.DestinationDefinitionsHandler; import io.airbyte.server.handlers.DestinationHandler; import io.airbyte.server.handlers.JobHistoryHandler; -import io.airbyte.server.handlers.LogsHandler; import io.airbyte.server.handlers.OAuthHandler; import io.airbyte.server.handlers.OpenApiConfigHandler; import io.airbyte.server.handlers.OperationsHandler; @@ -135,7 +134,6 @@ import java.io.File; import java.io.IOException; import java.net.http.HttpClient; -import java.nio.file.Path; import java.util.Map; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.NotImplementedException; @@ -156,12 +154,8 @@ public class ConfigurationApi implements io.airbyte.api.generated.V1Api { private final JobHistoryHandler jobHistoryHandler; private final WebBackendConnectionsHandler webBackendConnectionsHandler; private final WebBackendGeographiesHandler webBackendGeographiesHandler; - private final LogsHandler logsHandler; private final OpenApiConfigHandler openApiConfigHandler; private final OAuthHandler oAuthHandler; - private final WorkerEnvironment workerEnvironment; - private final LogConfigs logConfigs; - private final Path workspaceRoot; public ConfigurationApi(final ConfigRepository configRepository, final JobPersistence jobPersistence, @@ -173,12 +167,8 @@ public ConfigurationApi(final ConfigRepository configRepository, final WorkerEnvironment workerEnvironment, final LogConfigs logConfigs, final AirbyteVersion airbyteVersion, - final Path workspaceRoot, final HttpClient httpClient, final EventRunner eventRunner) { - this.workerEnvironment = workerEnvironment; - this.logConfigs = logConfigs; - this.workspaceRoot = workspaceRoot; final JsonSchemaValidator schemaValidator = new JsonSchemaValidator(); @@ -235,7 +225,6 @@ public ConfigurationApi(final ConfigRepository configRepository, eventRunner, configRepository); webBackendGeographiesHandler = new WebBackendGeographiesHandler(); - logsHandler = new LogsHandler(); openApiConfigHandler = new OpenApiConfigHandler(); } @@ -945,9 +934,13 @@ public AttemptNormalizationStatusReadList getAttemptNormalizationStatusesForJob( return execute(() -> jobHistoryHandler.getAttemptNormalizationStatuses(jobIdRequestBody)); } + /** + * This implementation has been moved to {@link LogsApiController}. Since the path of + * {@link LogsApiController} is more granular, it will override this implementation + */ @Override public File getLogs(final LogsRequestBody logsRequestBody) { - return execute(() -> logsHandler.getLogs(workspaceRoot, workerEnvironment, logConfigs, logsRequestBody)); + throw new NotImplementedException(); } @Override diff --git a/airbyte-server/src/main/java/io/airbyte/server/apis/LogsApiController.java b/airbyte-server/src/main/java/io/airbyte/server/apis/LogsApiController.java new file mode 100644 index 00000000000000..b3c1e5f586190f --- /dev/null +++ b/airbyte-server/src/main/java/io/airbyte/server/apis/LogsApiController.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022 Airbyte, Inc., all rights reserved. + */ + +package io.airbyte.server.apis; + +import io.airbyte.api.generated.LogsApi; +import io.airbyte.api.model.generated.LogsRequestBody; +import io.airbyte.server.handlers.LogsHandler; +import java.io.File; +import javax.ws.rs.Path; +import lombok.AllArgsConstructor; + +@Path("/v1/logs/get") +@AllArgsConstructor +public class LogsApiController implements LogsApi { + + private final LogsHandler logsHandler; + + @Override + public File getLogs(final LogsRequestBody logsRequestBody) { + return ConfigurationApi.execute(() -> logsHandler.getLogs(logsRequestBody)); + } + +} diff --git a/airbyte-server/src/main/java/io/airbyte/server/apis/binders/LogsApiBinder.java b/airbyte-server/src/main/java/io/airbyte/server/apis/binders/LogsApiBinder.java new file mode 100644 index 00000000000000..037597e9e5f1b3 --- /dev/null +++ b/airbyte-server/src/main/java/io/airbyte/server/apis/binders/LogsApiBinder.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 Airbyte, Inc., all rights reserved. + */ + +package io.airbyte.server.apis.binders; + +import io.airbyte.server.apis.LogsApiController; +import io.airbyte.server.apis.factories.LogsApiFactory; +import org.glassfish.hk2.utilities.binding.AbstractBinder; +import org.glassfish.jersey.process.internal.RequestScoped; + +public class LogsApiBinder extends AbstractBinder { + + @Override + protected void configure() { + bindFactory(LogsApiFactory.class) + .to(LogsApiController.class) + .in(RequestScoped.class); + } + +} diff --git a/airbyte-server/src/main/java/io/airbyte/server/apis/factories/LogsApiFactory.java b/airbyte-server/src/main/java/io/airbyte/server/apis/factories/LogsApiFactory.java new file mode 100644 index 00000000000000..450419d6a51514 --- /dev/null +++ b/airbyte-server/src/main/java/io/airbyte/server/apis/factories/LogsApiFactory.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022 Airbyte, Inc., all rights reserved. + */ + +package io.airbyte.server.apis.factories; + +import io.airbyte.server.apis.LogsApiController; +import io.airbyte.server.handlers.LogsHandler; +import org.glassfish.hk2.api.Factory; + +public class LogsApiFactory implements Factory { + + private static LogsHandler logsHandler; + + public static void setValues(final LogsHandler logsHandler) { + LogsApiFactory.logsHandler = logsHandler; + } + + @Override + public LogsApiController provide() { + return new LogsApiController(logsHandler); + } + + @Override + public void dispose(final LogsApiController instance) { + /* no op */ + } + +} diff --git a/airbyte-server/src/main/java/io/airbyte/server/handlers/LogsHandler.java b/airbyte-server/src/main/java/io/airbyte/server/handlers/LogsHandler.java index 1b3f581aec0926..eacb4760bfb3b6 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/handlers/LogsHandler.java +++ b/airbyte-server/src/main/java/io/airbyte/server/handlers/LogsHandler.java @@ -5,28 +5,28 @@ package io.airbyte.server.handlers; import io.airbyte.api.model.generated.LogsRequestBody; -import io.airbyte.config.Configs.WorkerEnvironment; +import io.airbyte.config.Configs; import io.airbyte.config.helpers.LogClientSingleton; -import io.airbyte.config.helpers.LogConfigs; import java.io.File; -import java.nio.file.Path; +import lombok.AllArgsConstructor; /** * This handler is only responsible for server and scheduler logs. Jobs logs paths are determined by * the submitJob function in the JobSubmitter class in the airbyte-server module. */ +@AllArgsConstructor public class LogsHandler { - public File getLogs(final Path workspaceRoot, - final WorkerEnvironment workerEnvironment, - final LogConfigs logConfigs, - final LogsRequestBody logsRequestBody) { + private final Configs configs; + + public File getLogs(final LogsRequestBody logsRequestBody) { switch (logsRequestBody.getLogType()) { case SERVER -> { - return LogClientSingleton.getInstance().getServerLogFile(workspaceRoot, workerEnvironment, logConfigs); + return LogClientSingleton.getInstance().getServerLogFile(configs.getWorkspaceRoot(), configs.getWorkerEnvironment(), configs.getLogConfigs()); } case SCHEDULER -> { - return LogClientSingleton.getInstance().getSchedulerLogFile(workspaceRoot, workerEnvironment, logConfigs); + return LogClientSingleton.getInstance().getSchedulerLogFile(configs.getWorkspaceRoot(), configs.getWorkerEnvironment(), + configs.getLogConfigs()); } default -> throw new IllegalStateException("Unexpected value: " + logsRequestBody.getLogType()); } diff --git a/airbyte-server/src/test/java/io/airbyte/server/handlers/LogsHandlerTest.java b/airbyte-server/src/test/java/io/airbyte/server/handlers/LogsHandlerTest.java index 3ae3065d754926..098f05f1a4a361 100644 --- a/airbyte-server/src/test/java/io/airbyte/server/handlers/LogsHandlerTest.java +++ b/airbyte-server/src/test/java/io/airbyte/server/handlers/LogsHandlerTest.java @@ -28,8 +28,7 @@ void testServerLogs() { when(configs.getLogConfigs()).thenReturn(LogConfigs.EMPTY); final File expected = Path.of(String.format("/workspace/server/logs/%s", LogClientSingleton.LOG_FILENAME)).toFile(); - final File actual = new LogsHandler().getLogs(configs.getWorkspaceRoot(), configs.getWorkerEnvironment(), - configs.getLogConfigs(), new LogsRequestBody().logType(LogType.SERVER)); + final File actual = new LogsHandler(configs).getLogs(new LogsRequestBody().logType(LogType.SERVER)); assertEquals(expected, actual); } @@ -42,8 +41,7 @@ void testSchedulerLogs() { when(configs.getLogConfigs()).thenReturn(LogConfigs.EMPTY); final File expected = Path.of(String.format("/workspace/scheduler/logs/%s", LogClientSingleton.LOG_FILENAME)).toFile(); - final File actual = new LogsHandler().getLogs(configs.getWorkspaceRoot(), configs.getWorkerEnvironment(), - configs.getLogConfigs(), new LogsRequestBody().logType(LogType.SCHEDULER)); + final File actual = new LogsHandler(configs).getLogs(new LogsRequestBody().logType(LogType.SCHEDULER)); assertEquals(expected, actual); }