Skip to content

Commit

Permalink
use shared ReleaseStage type in standard definition types (#5961)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroslopez committed Apr 18, 2023
1 parent 4e0dd9d commit 3e1c488
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import io.airbyte.config.ConnectorBuilderProject;
import io.airbyte.config.ConnectorBuilderProjectVersionedManifest;
import io.airbyte.config.DeclarativeManifest;
import io.airbyte.config.ReleaseStage;
import io.airbyte.config.StandardSourceDefinition;
import io.airbyte.config.StandardSourceDefinition.ReleaseStage;
import io.airbyte.config.StandardSourceDefinition.SourceType;
import io.airbyte.config.init.CdkVersionProvider;
import io.airbyte.config.persistence.ConfigNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private StandardDestinationDefinition destinationDefinitionFromCreate(final Dest
.withSpec(spec)
.withProtocolVersion(airbyteProtocolVersion.serialize())
.withTombstone(false)
.withReleaseStage(StandardDestinationDefinition.ReleaseStage.CUSTOM)
.withReleaseStage(io.airbyte.config.ReleaseStage.CUSTOM)
.withResourceRequirements(ApiPojoConverters.actorDefResourceReqsToInternal(destinationDefCreate.getResourceRequirements()));
return destinationDefinition;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private StandardSourceDefinition sourceDefinitionFromCreate(final SourceDefiniti
.withSpec(spec)
.withProtocolVersion(airbyteProtocolVersion.serialize())
.withTombstone(false)
.withReleaseStage(StandardSourceDefinition.ReleaseStage.CUSTOM)
.withReleaseStage(io.airbyte.config.ReleaseStage.CUSTOM)
.withResourceRequirements(ApiPojoConverters.actorDefResourceReqsToInternal(sourceDefinitionCreate.getResourceRequirements()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import io.airbyte.config.ConnectorBuilderProject;
import io.airbyte.config.ConnectorBuilderProjectVersionedManifest;
import io.airbyte.config.DeclarativeManifest;
import io.airbyte.config.ReleaseStage;
import io.airbyte.config.StandardSourceDefinition;
import io.airbyte.config.StandardSourceDefinition.ReleaseStage;
import io.airbyte.config.StandardSourceDefinition.SourceType;
import io.airbyte.config.init.CdkVersionProvider;
import io.airbyte.config.persistence.ConfigNotFoundException;
Expand Down Expand Up @@ -346,7 +346,7 @@ void givenVersionWhenGetConnectorBuilderProjectWithManifestThenReturnSpecificVer
.withManifestVersion(A_VERSION)
.withManifestDescription(A_DESCRIPTION));

ConnectorBuilderProjectRead response = connectorBuilderProjectsHandler.getConnectorBuilderProjectWithManifest(
final ConnectorBuilderProjectRead response = connectorBuilderProjectsHandler.getConnectorBuilderProjectWithManifest(
new ConnectorBuilderProjectIdWithWorkspaceId().builderProjectId(A_BUILDER_PROJECT_ID).workspaceId(A_WORKSPACE_ID).version(A_VERSION));

assertEquals(A_BUILDER_PROJECT_ID, response.getBuilderProject().getBuilderProjectId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private StandardDestinationDefinition generateDestinationDefinition() {
.withSpec(spec)
.withProtocolVersion("0.2.2")
.withTombstone(false)
.withReleaseStage(StandardDestinationDefinition.ReleaseStage.ALPHA)
.withReleaseStage(io.airbyte.config.ReleaseStage.ALPHA)
.withReleaseDate(TODAY_DATE_STRING)
.withResourceRequirements(new ActorDefinitionResourceRequirements().withDefault(new ResourceRequirements().withCpuRequest("2")));
}
Expand Down Expand Up @@ -411,7 +411,7 @@ void testCreateDestinationDefinitionShouldCheckProtocolVersion() throws URISynta
verify(configRepository, never()).writeStandardDestinationDefinition(destination
.withProtocolVersion(DEFAULT_PROTOCOL_VERSION)
.withReleaseDate(null)
.withReleaseStage(StandardDestinationDefinition.ReleaseStage.CUSTOM));
.withReleaseStage(io.airbyte.config.ReleaseStage.CUSTOM));
}

@Test
Expand Down Expand Up @@ -464,7 +464,7 @@ void testCreateCustomDestinationDefinition() throws URISyntaxException, IOExcept
destination
.withProtocolVersion(DEFAULT_PROTOCOL_VERSION)
.withReleaseDate(null)
.withReleaseStage(StandardDestinationDefinition.ReleaseStage.CUSTOM)
.withReleaseStage(io.airbyte.config.ReleaseStage.CUSTOM)
.withCustom(true),
workspaceId);
}
Expand Down Expand Up @@ -504,7 +504,7 @@ void testCreateCustomDestinationDefinitionWithInvalidProtocol() throws URISyntax
destination
.withProtocolVersion(invalidProtocol)
.withReleaseDate(null)
.withReleaseStage(StandardDestinationDefinition.ReleaseStage.CUSTOM)
.withReleaseStage(io.airbyte.config.ReleaseStage.CUSTOM)
.withCustom(true),
workspaceId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private StandardSourceDefinition generateSourceDefinition() {
.withIcon("rss.svg")
.withSpec(spec)
.withTombstone(false)
.withReleaseStage(StandardSourceDefinition.ReleaseStage.ALPHA)
.withReleaseStage(io.airbyte.config.ReleaseStage.ALPHA)
.withReleaseDate(TODAY_DATE_STRING)
.withResourceRequirements(new ActorDefinitionResourceRequirements().withDefault(new ResourceRequirements().withCpuRequest("2")));

Expand Down Expand Up @@ -361,7 +361,7 @@ void testCreateSourceDefinitionWithInvalidProtocol() throws URISyntaxException,
.writeStandardSourceDefinition(
sourceDefinition
.withReleaseDate(null)
.withReleaseStage(StandardSourceDefinition.ReleaseStage.CUSTOM)
.withReleaseStage(io.airbyte.config.ReleaseStage.CUSTOM)
.withProtocolVersion(DEFAULT_PROTOCOL_VERSION));
}

Expand Down Expand Up @@ -412,7 +412,7 @@ void testCreateCustomSourceDefinition() throws URISyntaxException, IOException,
verify(configRepository).writeCustomSourceDefinition(
sourceDefinition
.withReleaseDate(null)
.withReleaseStage(StandardSourceDefinition.ReleaseStage.CUSTOM)
.withReleaseStage(io.airbyte.config.ReleaseStage.CUSTOM)
.withProtocolVersion(DEFAULT_PROTOCOL_VERSION)
.withCustom(true),
workspaceId);
Expand Down Expand Up @@ -452,7 +452,7 @@ void testCreateCustomSourceDefinitionWithInvalidProtocol() throws URISyntaxExcep
verify(configRepository, never()).writeCustomSourceDefinition(
sourceDefinition
.withReleaseDate(null)
.withReleaseStage(StandardSourceDefinition.ReleaseStage.CUSTOM)
.withReleaseStage(io.airbyte.config.ReleaseStage.CUSTOM)
.withProtocolVersion(invalidVersion)
.withCustom(true),
workspaceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import io.airbyte.config.ConnectorRegistryDestinationDefinition;
import io.airbyte.config.ConnectorRegistrySourceDefinition;
import io.airbyte.config.ReleaseStage;
import io.airbyte.config.StandardDestinationDefinition;
import io.airbyte.config.StandardSourceDefinition;
import io.airbyte.config.StandardSourceDefinition.SourceType;
Expand Down Expand Up @@ -38,7 +37,7 @@ public static StandardSourceDefinition toStandardSourceDefinition(@Nullable fina
.withPublic(def.getPublic())
.withCustom(def.getCustom())
.withReleaseDate(def.getReleaseDate())
.withReleaseStage(toStandardSourceReleaseStage(def.getReleaseStage()))
.withReleaseStage(def.getReleaseStage())
.withResourceRequirements(def.getResourceRequirements())
.withProtocolVersion(def.getProtocolVersion())
.withAllowedHosts(def.getAllowedHosts())
Expand Down Expand Up @@ -66,58 +65,14 @@ public static StandardDestinationDefinition toStandardDestinationDefinition(@Nul
.withPublic(def.getPublic())
.withCustom(def.getCustom())
.withReleaseDate(def.getReleaseDate())
.withReleaseStage(toStandardDestinationReleaseStage(def.getReleaseStage()))
.withReleaseStage(def.getReleaseStage())
.withResourceRequirements(def.getResourceRequirements())
.withProtocolVersion(def.getProtocolVersion())
.withAllowedHosts(def.getAllowedHosts())
.withNormalizationConfig(def.getNormalizationConfig())
.withSupportsDbt(def.getSupportsDbt());
}

private static StandardSourceDefinition.ReleaseStage toStandardSourceReleaseStage(@Nullable final ReleaseStage releaseStage) {
if (releaseStage == null) {
return null;
}

switch (releaseStage) {
case ALPHA -> {
return StandardSourceDefinition.ReleaseStage.ALPHA;
}
case BETA -> {
return StandardSourceDefinition.ReleaseStage.BETA;
}
case GENERALLY_AVAILABLE -> {
return StandardSourceDefinition.ReleaseStage.GENERALLY_AVAILABLE;
}
case CUSTOM -> {
return StandardSourceDefinition.ReleaseStage.CUSTOM;
}
default -> throw new IllegalArgumentException("Unknown release stage: " + releaseStage);
}
}

private static StandardDestinationDefinition.ReleaseStage toStandardDestinationReleaseStage(@Nullable final ReleaseStage releaseStage) {
if (releaseStage == null) {
return null;
}

switch (releaseStage) {
case ALPHA -> {
return StandardDestinationDefinition.ReleaseStage.ALPHA;
}
case BETA -> {
return StandardDestinationDefinition.ReleaseStage.BETA;
}
case GENERALLY_AVAILABLE -> {
return StandardDestinationDefinition.ReleaseStage.GENERALLY_AVAILABLE;
}
case CUSTOM -> {
return StandardDestinationDefinition.ReleaseStage.CUSTOM;
}
default -> throw new IllegalArgumentException("Unknown release stage: " + releaseStage);
}
}

private static SourceType toStandardSourceType(@Nullable final ConnectorRegistrySourceDefinition.SourceType sourceType) {
if (sourceType == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ properties:
default: false
releaseStage:
type: string
enum:
- alpha
- beta
- generally_available
- custom
existingJavaType: io.airbyte.config.ReleaseStage
releaseDate:
description: The date when this connector was first released, in yyyy-mm-dd format.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ properties:
default: false
releaseStage:
type: string
enum:
- alpha
- beta
- generally_available
- custom
existingJavaType: io.airbyte.config.ReleaseStage
releaseDate:
description: The date when this connector was first released, in yyyy-mm-dd format.
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void testConvertRegistrySourceToStandardSourceDef() {
.withTombstone(false)
.withPublic(true)
.withCustom(false)
.withReleaseStage(StandardSourceDefinition.ReleaseStage.GENERALLY_AVAILABLE)
.withReleaseStage(ReleaseStage.GENERALLY_AVAILABLE)
.withReleaseDate(RELEASE_DATE)
.withProtocolVersion(PROTOCOL_VERSION)
.withAllowedHosts(ALLOWED_HOSTS)
Expand Down Expand Up @@ -116,7 +116,7 @@ void testConvertRegistryDestinationToStandardDestinationDef() {
.withTombstone(false)
.withPublic(true)
.withCustom(false)
.withReleaseStage(StandardDestinationDefinition.ReleaseStage.GENERALLY_AVAILABLE)
.withReleaseStage(ReleaseStage.GENERALLY_AVAILABLE)
.withReleaseDate(RELEASE_DATE)
.withProtocolVersion(PROTOCOL_VERSION)
.withAllowedHosts(ALLOWED_HOSTS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import io.airbyte.config.JobSyncConfig.NamespaceDefinitionType;
import io.airbyte.config.NormalizationDestinationDefinitionConfig;
import io.airbyte.config.Notification;
import io.airbyte.config.ReleaseStage;
import io.airbyte.config.ResourceRequirements;
import io.airbyte.config.Schedule;
import io.airbyte.config.ScheduleData;
Expand Down Expand Up @@ -222,7 +223,7 @@ public static StandardSourceDefinition buildStandardSourceDefinition(final Recor
.withPublic(record.get(ACTOR_DEFINITION.PUBLIC))
.withCustom(record.get(ACTOR_DEFINITION.CUSTOM))
.withReleaseStage(record.get(ACTOR_DEFINITION.RELEASE_STAGE) == null ? null
: Enums.toEnum(record.get(ACTOR_DEFINITION.RELEASE_STAGE, String.class), StandardSourceDefinition.ReleaseStage.class).orElseThrow())
: Enums.toEnum(record.get(ACTOR_DEFINITION.RELEASE_STAGE, String.class), ReleaseStage.class).orElseThrow())
.withReleaseDate(record.get(ACTOR_DEFINITION.RELEASE_DATE) == null ? null
: record.get(ACTOR_DEFINITION.RELEASE_DATE).toString())
.withResourceRequirements(record.get(ACTOR_DEFINITION.RESOURCE_REQUIREMENTS) == null
Expand Down Expand Up @@ -259,7 +260,7 @@ public static StandardDestinationDefinition buildStandardDestinationDefinition(f
.withPublic(record.get(ACTOR_DEFINITION.PUBLIC))
.withCustom(record.get(ACTOR_DEFINITION.CUSTOM))
.withReleaseStage(record.get(ACTOR_DEFINITION.RELEASE_STAGE) == null ? null
: Enums.toEnum(record.get(ACTOR_DEFINITION.RELEASE_STAGE, String.class), StandardDestinationDefinition.ReleaseStage.class).orElseThrow())
: Enums.toEnum(record.get(ACTOR_DEFINITION.RELEASE_STAGE, String.class), ReleaseStage.class).orElseThrow())
.withReleaseDate(record.get(ACTOR_DEFINITION.RELEASE_DATE) == null ? null
: record.get(ACTOR_DEFINITION.RELEASE_DATE).toString())
.withSupportsDbt(record.get(ACTOR_DEFINITION.SUPPORTS_DBT) == null ? null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

import com.fasterxml.jackson.databind.JsonNode;
import io.airbyte.commons.json.Jsons;
import io.airbyte.config.ReleaseStage;
import io.airbyte.config.StandardDestinationDefinition;
import io.airbyte.config.StandardSourceDefinition;
import io.airbyte.config.StandardSourceDefinition.ReleaseStage;
import io.airbyte.config.StandardSourceDefinition.SourceType;
import io.airbyte.config.persistence.ActorDefinitionMigrator.ConnectorInfo;
import io.airbyte.db.ExceptionWrappingDatabase;
Expand Down Expand Up @@ -67,7 +67,7 @@ class ActorDefinitionMigratorTest extends BaseConfigDatabaseTest {
.withDocumentationUrl("https://docs.airbyte.io/integrations/sources/postgres")
.withIcon("postgresql.svg")
.withCustom(true)
.withReleaseStage(StandardDestinationDefinition.ReleaseStage.CUSTOM)
.withReleaseStage(ReleaseStage.CUSTOM)
.withTombstone(false);

private ActorDefinitionMigrator migrator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import io.airbyte.config.DestinationConnection;
import io.airbyte.config.Geography;
import io.airbyte.config.JobSyncConfig.NamespaceDefinitionType;
import io.airbyte.config.ReleaseStage;
import io.airbyte.config.ResourceRequirements;
import io.airbyte.config.SourceConnection;
import io.airbyte.config.StandardDestinationDefinition;
import io.airbyte.config.StandardSourceDefinition;
import io.airbyte.config.StandardSourceDefinition.ReleaseStage;
import io.airbyte.config.StandardSourceDefinition.SourceType;
import io.airbyte.config.StandardSync;
import io.airbyte.config.StandardSync.NonBreakingChangesPreference;
Expand Down Expand Up @@ -347,13 +347,13 @@ private void createBaseObjects() throws IOException, JsonValidationException {
sourceDefAlpha = createStandardSourceDefinition("1.0.0", ReleaseStage.ALPHA);
sourceAlpha = createSourceConnection(workspaceId, sourceDefAlpha);

destDef1 = createStandardDestDefinition("0.2.3", StandardDestinationDefinition.ReleaseStage.GENERALLY_AVAILABLE);
destDef1 = createStandardDestDefinition("0.2.3", ReleaseStage.GENERALLY_AVAILABLE);
destination1 = createDestinationConnection(workspaceId, destDef1);

destDef2 = createStandardDestDefinition("1.3.0", StandardDestinationDefinition.ReleaseStage.GENERALLY_AVAILABLE);
destDef2 = createStandardDestDefinition("1.3.0", ReleaseStage.GENERALLY_AVAILABLE);
destination2 = createDestinationConnection(workspaceId, destDef2);

destDefBeta = createStandardDestDefinition("1.3.0", StandardDestinationDefinition.ReleaseStage.BETA);
destDefBeta = createStandardDestDefinition("1.3.0", ReleaseStage.BETA);
destinationBeta = createDestinationConnection(workspaceId, destDefBeta);
}

Expand All @@ -379,8 +379,7 @@ private StandardSourceDefinition createStandardSourceDefinition(final String pro
return sourceDef;
}

private StandardDestinationDefinition createStandardDestDefinition(final String protocolVersion,
final StandardDestinationDefinition.ReleaseStage releaseStage)
private StandardDestinationDefinition createStandardDestDefinition(final String protocolVersion, final ReleaseStage releaseStage)
throws JsonValidationException, IOException {
final UUID destDefId = UUID.randomUUID();
final StandardDestinationDefinition destDef = new StandardDestinationDefinition()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
import io.airbyte.commons.lang.MoreBooleans;
import io.airbyte.config.DestinationConnection;
import io.airbyte.config.Geography;
import io.airbyte.config.ReleaseStage;
import io.airbyte.config.SourceConnection;
import io.airbyte.config.StandardDestinationDefinition;
import io.airbyte.config.StandardSourceDefinition;
import io.airbyte.config.StandardSourceDefinition.ReleaseStage;
import io.airbyte.config.StandardSync;
import io.airbyte.config.StandardWorkspace;
import io.airbyte.db.ExceptionWrappingDatabase;
Expand Down Expand Up @@ -104,7 +104,7 @@ private static DestinationConnection createBaseDestination() {
.withWorkspaceId(WORKSPACE_ID);
}

private static StandardSourceDefinition createSourceDefinition(final ReleaseStage releaseStage) {
private static StandardSourceDefinition createSourceDefinition(final io.airbyte.config.ReleaseStage releaseStage) {
return new StandardSourceDefinition()
.withSourceDefinitionId(SOURCE_DEFINITION_ID)
.withTombstone(false)
Expand All @@ -114,7 +114,7 @@ private static StandardSourceDefinition createSourceDefinition(final ReleaseStag
.withReleaseStage(releaseStage);
}

private static StandardDestinationDefinition createDestinationDefinition(final StandardDestinationDefinition.ReleaseStage releaseStage) {
private static StandardDestinationDefinition createDestinationDefinition(final io.airbyte.config.ReleaseStage releaseStage) {
return new StandardDestinationDefinition()
.withDestinationDefinitionId(DESTINATION_DEFINITION_ID)
.withTombstone(false)
Expand All @@ -124,9 +124,8 @@ private static StandardDestinationDefinition createDestinationDefinition(final S
.withReleaseStage(releaseStage);
}

private void persistConnectorsWithReleaseStages(
final ReleaseStage sourceReleaseStage,
final StandardDestinationDefinition.ReleaseStage destinationReleaseStage)
private void persistConnectorsWithReleaseStages(final ReleaseStage sourceReleaseStage,
final ReleaseStage destinationReleaseStage)
throws JsonValidationException, IOException {

configRepository.writeStandardSourceDefinition(createSourceDefinition(sourceReleaseStage));
Expand Down Expand Up @@ -194,16 +193,16 @@ void testWorkspaceHasAlphaOrBetaConnector() throws JsonValidationException, IOEx

configRepository.writeStandardWorkspaceNoSecrets(workspace);

persistConnectorsWithReleaseStages(ReleaseStage.GENERALLY_AVAILABLE, StandardDestinationDefinition.ReleaseStage.GENERALLY_AVAILABLE);
persistConnectorsWithReleaseStages(ReleaseStage.GENERALLY_AVAILABLE, ReleaseStage.GENERALLY_AVAILABLE);
assertFalse(configRepository.getWorkspaceHasAlphaOrBetaConnector(WORKSPACE_ID));

persistConnectorsWithReleaseStages(ReleaseStage.ALPHA, StandardDestinationDefinition.ReleaseStage.GENERALLY_AVAILABLE);
persistConnectorsWithReleaseStages(ReleaseStage.ALPHA, ReleaseStage.GENERALLY_AVAILABLE);
assertTrue(configRepository.getWorkspaceHasAlphaOrBetaConnector(WORKSPACE_ID));

persistConnectorsWithReleaseStages(ReleaseStage.GENERALLY_AVAILABLE, StandardDestinationDefinition.ReleaseStage.BETA);
persistConnectorsWithReleaseStages(ReleaseStage.GENERALLY_AVAILABLE, ReleaseStage.BETA);
assertTrue(configRepository.getWorkspaceHasAlphaOrBetaConnector(WORKSPACE_ID));

persistConnectorsWithReleaseStages(ReleaseStage.CUSTOM, StandardDestinationDefinition.ReleaseStage.CUSTOM);
persistConnectorsWithReleaseStages(ReleaseStage.CUSTOM, ReleaseStage.CUSTOM);
assertFalse(configRepository.getWorkspaceHasAlphaOrBetaConnector(WORKSPACE_ID));
}

Expand Down
Loading

0 comments on commit 3e1c488

Please sign in to comment.