Skip to content

Commit

Permalink
Bmoric/convert source definition micronaut (#20338)
Browse files Browse the repository at this point in the history
* tmp

* Fix build

* tmp

* Tmp

* tmp

* tmp

* Tmp

* tmp

* tmp

* Clean up

* tmp

* Convert Connection Api Controller

* PR Comments

* convert openapiapicontroller to micronaut (#20258)

* convert openapiapicontroller to micronaut

* merge health/openapi locations into one entry

* Fix build

* Format

* Remove media type

* Format

* Tmp

* tmp

* Build

* missing bean

* Tmp

* Add Beans

* fix Bean

* Add passthrough

* Clean up

* Missing path

* FIx typo

* Fix conflicts

* for mat

Co-authored-by: Cole Snodgrass <cole@airbyte.io>
  • Loading branch information
benmoriceau and colesnodgrass authored Dec 12, 2022
1 parent f801280 commit 9fe2319
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion airbyte-proxy/nginx-auth.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ http {
}
}

location ~ ^/api/v1/(connections|destinations|destination_definitions|destination_definition_specifications|destination_oauths|operations|source_definitions|sources|scheduler|state)/.* {
location ~ ^/api/v1/(connections|destinations|destination_definitions|destination_definition_specifications|destination_oauths|operations
|scheduler|source_definitions|sources|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;
Expand Down
1 change: 1 addition & 0 deletions airbyte-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ dependencies {
testImplementation libs.postgresql
testImplementation libs.platform.testcontainers.postgresql
testImplementation 'com.squareup.okhttp3:mockwebserver:4.9.1'
testImplementation 'org.mockito:mockito-inline:4.7.0'
}

// we want to be able to access the generated db files from config/init when we build the server docker image.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ public static ServerRunnable getServer(final ServerFactory apiFactory,
schemaValidator,
connectionsHandler);

final SourceDefinitionsHandler sourceDefinitionsHandler = new SourceDefinitionsHandler(configRepository, syncSchedulerClient, sourceHandler);
final SourceDefinitionsHandler sourceDefinitionsHandler =
new SourceDefinitionsHandler(configRepository, syncSchedulerClient, sourceHandler, configs);

final JobHistoryHandler jobHistoryHandler = new JobHistoryHandler(
jobPersistence,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
import io.airbyte.server.apis.JobsApiController;
import io.airbyte.server.apis.LogsApiController;
import io.airbyte.server.apis.NotificationsApiController;
import io.airbyte.server.apis.OpenapiApiController;
import io.airbyte.server.apis.OperationApiController;
import io.airbyte.server.apis.SourceApiController;
import io.airbyte.server.apis.SourceDefinitionApiController;
import io.airbyte.server.apis.SourceDefinitionSpecificationApiController;
import io.airbyte.server.apis.SourceOauthApiController;
import io.airbyte.server.apis.StateApiController;
Expand Down Expand Up @@ -152,10 +148,6 @@ public ServerRunnable create(final SynchronousSchedulerClient synchronousSchedul
JobsApiController.class,
LogsApiController.class,
NotificationsApiController.class,
OpenapiApiController.class,
OperationApiController.class,
SourceApiController.class,
SourceDefinitionApiController.class,
SourceDefinitionSpecificationApiController.class,
SourceOauthApiController.class,
StateApiController.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
import io.airbyte.api.model.generated.SourceDefinitionUpdate;
import io.airbyte.api.model.generated.WorkspaceIdRequestBody;
import io.airbyte.server.handlers.SourceDefinitionsHandler;
import io.micronaut.context.annotation.Context;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Post;

@Controller("/api/v1/source_definitions")
@Context
public class SourceDefinitionApiController implements SourceDefinitionApi {

private final SourceDefinitionsHandler sourceDefinitionsHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import io.airbyte.commons.features.FeatureFlags;
import io.airbyte.commons.temporal.TemporalClient;
import io.airbyte.commons.temporal.config.WorkerMode;
import io.airbyte.commons.version.AirbyteProtocolVersionRange;
import io.airbyte.commons.version.AirbyteVersion;
import io.airbyte.commons.version.Version;
import io.airbyte.config.Configs.DeploymentMode;
import io.airbyte.config.Configs.TrackingStrategy;
import io.airbyte.config.persistence.ConfigRepository;
Expand Down Expand Up @@ -111,6 +113,13 @@ public AirbyteGithubStore airbyteGithubStore() {
return AirbyteGithubStore.production();
}

@Singleton
public AirbyteProtocolVersionRange airbyteProtocolVersionRange(
@Value("${airbyte.protocol.min-version}") final String minVersion,
@Value("${airbyte.protocol.max-version}") final String maxVersion) {
return new AirbyteProtocolVersionRange(new Version(minVersion), new Version(maxVersion));
}

private <T> T convertToEnum(final String value, final Function<String, T> creatorFunction, final T defaultValue) {
return StringUtils.isNotEmpty(value) ? creatorFunction.apply(value.toUpperCase(Locale.ROOT)) : defaultValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import io.airbyte.config.ActorDefinitionResourceRequirements;
import io.airbyte.config.ActorType;
import io.airbyte.config.Configs;
import io.airbyte.config.EnvConfigs;
import io.airbyte.config.StandardSourceDefinition;
import io.airbyte.config.persistence.ConfigNotFoundException;
import io.airbyte.config.persistence.ConfigRepository;
Expand All @@ -43,6 +42,7 @@
import io.airbyte.server.scheduler.SynchronousSchedulerClient;
import io.airbyte.server.services.AirbyteGithubStore;
import io.airbyte.validation.json.JsonValidationException;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import java.io.IOException;
import java.net.URI;
Expand All @@ -65,26 +65,29 @@ public class SourceDefinitionsHandler {
private final SourceHandler sourceHandler;
private final AirbyteProtocolVersionRange protocolVersionRange;

// TODO: remove this contructor after the migration is done
@Deprecated(forRemoval = true)
public SourceDefinitionsHandler(final ConfigRepository configRepository,
final SynchronousSchedulerClient schedulerSynchronousClient,
final SourceHandler sourceHandler) {
this(configRepository, UUID::randomUUID, schedulerSynchronousClient, AirbyteGithubStore.production(), sourceHandler);
final SourceHandler sourceHandler,
final Configs configs) {
this(configRepository, UUID::randomUUID, schedulerSynchronousClient, AirbyteGithubStore.production(), sourceHandler,
new AirbyteProtocolVersionRange(configs.getAirbyteProtocolVersionMin(), configs.getAirbyteProtocolVersionMax()));
}

@Inject
public SourceDefinitionsHandler(final ConfigRepository configRepository,
final Supplier<UUID> uuidSupplier,
final SynchronousSchedulerClient schedulerSynchronousClient,
final AirbyteGithubStore githubStore,
final SourceHandler sourceHandler) {
final SourceHandler sourceHandler,
final AirbyteProtocolVersionRange protocolVersionRange) {
this.configRepository = configRepository;
this.uuidSupplier = uuidSupplier;
this.schedulerSynchronousClient = schedulerSynchronousClient;
this.githubStore = githubStore;
this.sourceHandler = sourceHandler;

// TODO inject protocol min and max once this handler is being converted to micronaut
final Configs configs = new EnvConfigs();
protocolVersionRange = new AirbyteProtocolVersionRange(configs.getAirbyteProtocolVersionMin(), configs.getAirbyteProtocolVersionMax());
this.protocolVersionRange = protocolVersionRange;
}

@VisibleForTesting
Expand Down
3 changes: 3 additions & 0 deletions airbyte-server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ airbyte:
url: ${WEBAPP_URL:}
workspace:
root: ${WORKSPACE_ROOT}
protocol:
min-version: ${AIRBYTE_PROTOCOL_VERSION_MIN:0.0.0}
max-version: ${AIRBYTE_PROTOCOL_VERSION_MAX:0.3.0}

temporal:
cloud:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.airbyte.commons.docker.DockerUtils;
import io.airbyte.commons.json.Jsons;
import io.airbyte.commons.version.AirbyteProtocolVersionRange;
import io.airbyte.commons.version.Version;
import io.airbyte.config.ActorDefinitionResourceRequirements;
import io.airbyte.config.ActorType;
import io.airbyte.config.Configs;
Expand Down Expand Up @@ -77,6 +78,7 @@ class SourceDefinitionsHandlerTest {
private AirbyteGithubStore githubStore;
private SourceHandler sourceHandler;
private UUID workspaceId;
private AirbyteProtocolVersionRange protocolVersionRange;

@SuppressWarnings("unchecked")
@BeforeEach
Expand All @@ -90,7 +92,10 @@ void setUp() {

sourceDefinition = generateSourceDefinition();

sourceDefinitionsHandler = new SourceDefinitionsHandler(configRepository, uuidSupplier, schedulerSynchronousClient, githubStore, sourceHandler);
protocolVersionRange = new AirbyteProtocolVersionRange(new Version("0.0.0"), new Version("0.3.0"));

sourceDefinitionsHandler = new SourceDefinitionsHandler(configRepository, uuidSupplier, schedulerSynchronousClient, githubStore, sourceHandler,
protocolVersionRange);
}

private StandardSourceDefinition generateSourceDefinition() {
Expand Down

0 comments on commit 9fe2319

Please sign in to comment.