Skip to content

Commit

Permalink
Bmoric/extract healt api (#18523)
Browse files Browse the repository at this point in the history
* Tmp

* Extract the Attempt API from the V1 API

* Add comments

* Move Connection API out of configuration API

* format

* format

* Rename to Controller

* Rename to Controller

* Add values to the factory

* Change the constructor to use hadler instead of objects needed by the handler

* Update with new tags.

* tmp

* Fix PMD errors

* Extract DB migrator

* Add something that I forgot

* extract destination definition api

* restore destination factory initialization

* extract destination definition specification api

* format

* format

* format

* extract health check api

* fix test

* format
  • Loading branch information
benmoriceau authored Oct 28, 2022
1 parent c5d5ef3 commit e39f882
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 64 deletions.
4 changes: 4 additions & 0 deletions airbyte-server/src/main/java/io/airbyte/server/ServerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import io.airbyte.server.handlers.DbMigrationHandler;
import io.airbyte.server.handlers.DestinationDefinitionsHandler;
import io.airbyte.server.handlers.DestinationHandler;
import io.airbyte.server.handlers.HealthCheckHandler;
import io.airbyte.server.handlers.OperationsHandler;
import io.airbyte.server.handlers.SchedulerHandler;
import io.airbyte.server.scheduler.DefaultSynchronousSchedulerClient;
Expand Down Expand Up @@ -299,6 +300,8 @@ public static ServerRunnable getServer(final ServerFactory apiFactory,
final DestinationDefinitionsHandler destinationDefinitionsHandler = new DestinationDefinitionsHandler(configRepository, syncSchedulerClient,
destinationHandler);

final HealthCheckHandler healthCheckHandler = new HealthCheckHandler(configRepository);

LOGGER.info("Starting server...");

return apiFactory.create(
Expand All @@ -323,6 +326,7 @@ public static ServerRunnable getServer(final ServerFactory apiFactory,
dbMigrationHandler,
destinationDefinitionsHandler,
destinationHandler,
healthCheckHandler,
operationsHandler,
schedulerHandler);
}
Expand Down
34 changes: 28 additions & 6 deletions airbyte-server/src/main/java/io/airbyte/server/ServerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,27 @@
import io.airbyte.server.apis.DestinationApiController;
import io.airbyte.server.apis.DestinationDefinitionApiController;
import io.airbyte.server.apis.DestinationDefinitionSpecificationApiController;
import io.airbyte.server.apis.HealthApiController;
import io.airbyte.server.apis.binders.AttemptApiBinder;
import io.airbyte.server.apis.binders.ConnectionApiBinder;
import io.airbyte.server.apis.binders.DbMigrationBinder;
import io.airbyte.server.apis.binders.DestinationApiBinder;
import io.airbyte.server.apis.binders.DestinationDefinitionApiBinder;
import io.airbyte.server.apis.binders.DestinationDefinitionSpecificationApiBinder;
import io.airbyte.server.apis.binders.HealthApiBinder;
import io.airbyte.server.apis.factories.AttemptApiFactory;
import io.airbyte.server.apis.factories.ConnectionApiFactory;
import io.airbyte.server.apis.factories.DbMigrationApiFactory;
import io.airbyte.server.apis.factories.DestinationApiFactory;
import io.airbyte.server.apis.factories.DestinationDefinitionApiFactory;
import io.airbyte.server.apis.factories.DestinationDefinitionSpecificationApiFactory;
import io.airbyte.server.apis.factories.HealthApiFactory;
import io.airbyte.server.handlers.AttemptHandler;
import io.airbyte.server.handlers.ConnectionsHandler;
import io.airbyte.server.handlers.DbMigrationHandler;
import io.airbyte.server.handlers.DestinationDefinitionsHandler;
import io.airbyte.server.handlers.DestinationHandler;
import io.airbyte.server.handlers.HealthCheckHandler;
import io.airbyte.server.handlers.OperationsHandler;
import io.airbyte.server.handlers.SchedulerHandler;
import io.airbyte.server.scheduler.EventRunner;
Expand Down Expand Up @@ -72,6 +76,7 @@ ServerRunnable create(final SynchronousSchedulerClient synchronousSchedulerClien
final DbMigrationHandler dbMigrationHandler,
final DestinationDefinitionsHandler destinationDefinitionsHandler,
final DestinationHandler destinationApiHandler,
final HealthCheckHandler healthCheckHandler,
final OperationsHandler operationsHandler,
final SchedulerHandler schedulerHandler);

Expand Down Expand Up @@ -99,6 +104,7 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
final DbMigrationHandler dbMigrationHandler,
final DestinationDefinitionsHandler destinationDefinitionsHandler,
final DestinationHandler destinationApiHandler,
final HealthCheckHandler healthCheckHandler,
final OperationsHandler operationsHandler,
final SchedulerHandler schedulerHandler) {
final Map<String, String> mdc = MDC.getCopyOfContextMap();
Expand Down Expand Up @@ -140,13 +146,29 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul

DestinationDefinitionSpecificationApiFactory.setValues(schedulerHandler);

HealthApiFactory.setValues(healthCheckHandler);

// server configurations
final Set<Class<?>> componentClasses = Set.of(ConfigurationApi.class, AttemptApiController.class, ConnectionApiController.class,
DbMigrationApiController.class, DestinationApiController.class, DestinationDefinitionApiController.class,
DestinationDefinitionSpecificationApiController.class);
final Set<Object> components = Set.of(new CorsFilter(), new ConfigurationApiBinder(), new AttemptApiBinder(), new ConnectionApiBinder(),
new DbMigrationBinder(), new DestinationApiBinder(), new DestinationDefinitionApiBinder(),
new DestinationDefinitionSpecificationApiBinder());
final Set<Class<?>> componentClasses = Set.of(
ConfigurationApi.class,
AttemptApiController.class,
ConnectionApiController.class,
DbMigrationApiController.class,
DestinationApiController.class,
DestinationDefinitionApiController.class,
DestinationDefinitionSpecificationApiController.class,
HealthApiController.class);

final Set<Object> components = Set.of(
new CorsFilter(),
new ConfigurationApiBinder(),
new AttemptApiBinder(),
new ConnectionApiBinder(),
new DbMigrationBinder(),
new DestinationApiBinder(),
new DestinationDefinitionApiBinder(),
new DestinationDefinitionSpecificationApiBinder(),
new HealthApiBinder());

// construct server
return new ServerApp(airbyteVersion, componentClasses, components);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
import io.airbyte.server.handlers.ConnectionsHandler;
import io.airbyte.server.handlers.DestinationDefinitionsHandler;
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.OAuthHandler;
Expand Down Expand Up @@ -157,7 +156,6 @@ public class ConfigurationApi implements io.airbyte.api.generated.V1Api {
private final JobHistoryHandler jobHistoryHandler;
private final WebBackendConnectionsHandler webBackendConnectionsHandler;
private final WebBackendGeographiesHandler webBackendGeographiesHandler;
private final HealthCheckHandler healthCheckHandler;
private final LogsHandler logsHandler;
private final OpenApiConfigHandler openApiConfigHandler;
private final OAuthHandler oAuthHandler;
Expand All @@ -169,7 +167,6 @@ public ConfigurationApi(final ConfigRepository configRepository,
final JobPersistence jobPersistence,
final SecretsRepositoryReader secretsRepositoryReader,
final SecretsRepositoryWriter secretsRepositoryWriter,

final SynchronousSchedulerClient synchronousSchedulerClient,
final StatePersistence statePersistence,
final TrackingClient trackingClient,
Expand Down Expand Up @@ -238,7 +235,6 @@ public ConfigurationApi(final ConfigRepository configRepository,
eventRunner,
configRepository);
webBackendGeographiesHandler = new WebBackendGeographiesHandler();
healthCheckHandler = new HealthCheckHandler(configRepository);
logsHandler = new LogsHandler();
openApiConfigHandler = new OpenApiConfigHandler();
}
Expand Down Expand Up @@ -936,9 +932,13 @@ public File getOpenApiSpec() {
}

// HEALTH
/**
* This implementation has been moved to {@link HealthApiController}. Since the path of
* {@link HealthApiController} is more granular, it will override this implementation
*/
@Override
public HealthCheckRead getHealthCheck() {
return healthCheckHandler.health();
throw new NotImplementedException();
}

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

package io.airbyte.server.apis;

import io.airbyte.api.generated.HealthApi;
import io.airbyte.api.model.generated.HealthCheckRead;
import io.airbyte.server.handlers.HealthCheckHandler;
import javax.ws.rs.Path;
import lombok.AllArgsConstructor;

@Path("/v1/health")
@AllArgsConstructor
public class HealthApiController implements HealthApi {

private final HealthCheckHandler healthCheckHandler;

@Override
public HealthCheckRead getHealthCheck() {
return healthCheckHandler.health();
}

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

public class HealthApiBinder extends AbstractBinder {

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

public class HealthApiFactory implements Factory<HealthApiController> {

private static HealthCheckHandler healthCheckHandler;

public static void setValues(final HealthCheckHandler healthCheckHandler) {
HealthApiFactory.healthCheckHandler = healthCheckHandler;
}

@Override
public HealthApiController provide() {
return new HealthApiController(healthCheckHandler);
}

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

}

This file was deleted.

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;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import io.airbyte.api.model.generated.HealthCheckRead;
import io.airbyte.server.handlers.HealthCheckHandler;
import org.junit.jupiter.api.Test;

class HealthCheckApiTest {

@Test
void testImportDefinitions() {
final HealthCheckHandler healthCheckHandler = mock(HealthCheckHandler.class);
when(healthCheckHandler.health())
.thenReturn(new HealthCheckRead().available(
false));

final HealthApiController configurationApi = new HealthApiController(healthCheckHandler);

assertFalse(configurationApi.getHealthCheck().getAvailable());
}

}

0 comments on commit e39f882

Please sign in to comment.