-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove production use of DatabaseConfigPersistence #19275
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
96110d7
wip; looking at how to return boolean from jooq delete
cgardens 3572933
clean up
cgardens 7a789ee
def get => throws confignotfound
cgardens 8a645d3
pmd check
cgardens 09f8aae
fix default protocol version behavior for devs
cgardens 95d881e
remove workspace service acount list endpoint
cgardens 1ae83b8
fix test
cgardens File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
729 changes: 491 additions & 238 deletions
729
...nfig/config-persistence/src/main/java/io/airbyte/config/persistence/ConfigRepository.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,508 changes: 0 additions & 1,508 deletions
1,508
...ig-persistence/src/main/java/io/airbyte/config/persistence/DatabaseConfigPersistence.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
...-persistence/src/test/java/io/airbyte/config/persistence/ActorDefinitionMigratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
/* | ||
* Copyright (c) 2022 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.config.persistence; | ||
|
||
import static io.airbyte.config.ConfigSchema.STANDARD_DESTINATION_DEFINITION; | ||
import static io.airbyte.config.ConfigSchema.STANDARD_SOURCE_DEFINITION; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.airbyte.commons.json.Jsons; | ||
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; | ||
import java.sql.SQLException; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ActorDefinitionMigratorTest extends BaseConfigDatabaseTest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests from DatabaseConfigPersistenceTest that were specific to migrator. |
||
|
||
public static final String DEFAULT_PROTOCOL_VERSION = "0.2.0"; | ||
protected static final StandardSourceDefinition SOURCE_POSTGRES = new StandardSourceDefinition() | ||
.withName("Postgres") | ||
.withSourceDefinitionId(UUID.fromString("decd338e-5647-4c0b-adf4-da0e75f5a750")) | ||
.withDockerRepository("airbyte/source-postgres") | ||
.withDockerImageTag("0.3.11") | ||
.withDocumentationUrl("https://docs.airbyte.io/integrations/sources/postgres") | ||
.withIcon("postgresql.svg") | ||
.withSourceType(SourceType.DATABASE) | ||
.withTombstone(false); | ||
protected static final StandardSourceDefinition SOURCE_CUSTOM = new StandardSourceDefinition() | ||
.withName("Custom") | ||
.withSourceDefinitionId(UUID.fromString("baba338e-5647-4c0b-adf4-da0e75f5a750")) | ||
.withDockerRepository("airbyte/custom") | ||
.withDockerImageTag("0.3.11") | ||
.withDocumentationUrl("https://docs.airbyte.io/integrations/sources/postgres") | ||
.withIcon("postgresql.svg") | ||
.withSourceType(SourceType.DATABASE) | ||
.withCustom(true) | ||
.withReleaseStage(ReleaseStage.CUSTOM) | ||
.withTombstone(false); | ||
protected static final StandardDestinationDefinition DESTINATION_S3 = new StandardDestinationDefinition() | ||
.withName("S3") | ||
.withDestinationDefinitionId(UUID.fromString("4816b78f-1489-44c1-9060-4b19d5fa9362")) | ||
.withDockerRepository("airbyte/destination-s3") | ||
.withDockerImageTag("0.1.12") | ||
.withDocumentationUrl("https://docs.airbyte.io/integrations/destinations/s3") | ||
.withProtocolVersion(DEFAULT_PROTOCOL_VERSION) | ||
.withTombstone(false); | ||
protected static final StandardDestinationDefinition DESTINATION_CUSTOM = new StandardDestinationDefinition() | ||
.withName("Custom") | ||
.withDestinationDefinitionId(UUID.fromString("baba338e-5647-4c0b-adf4-da0e75f5a750")) | ||
.withDockerRepository("airbyte/custom") | ||
.withDockerImageTag("0.3.11") | ||
.withDocumentationUrl("https://docs.airbyte.io/integrations/sources/postgres") | ||
.withIcon("postgresql.svg") | ||
.withCustom(true) | ||
.withReleaseStage(StandardDestinationDefinition.ReleaseStage.CUSTOM) | ||
.withTombstone(false); | ||
|
||
private ActorDefinitionMigrator migrator; | ||
private ConfigRepository configRepository; | ||
|
||
@BeforeEach | ||
void setup() throws SQLException { | ||
truncateAllTables(); | ||
|
||
migrator = new ActorDefinitionMigrator(new ExceptionWrappingDatabase(database)); | ||
configRepository = new ConfigRepository(database, migrator, null); | ||
} | ||
|
||
private void writeSource(final StandardSourceDefinition source) throws Exception { | ||
configRepository.writeStandardSourceDefinition(source); | ||
} | ||
|
||
@Test | ||
void testGetConnectorRepositoryToInfoMap() throws Exception { | ||
final String connectorRepository = "airbyte/duplicated-connector"; | ||
final String oldVersion = "0.1.10"; | ||
final String newVersion = DEFAULT_PROTOCOL_VERSION; | ||
final StandardSourceDefinition source1 = new StandardSourceDefinition() | ||
.withSourceDefinitionId(UUID.randomUUID()) | ||
.withName("source-1") | ||
.withDockerRepository(connectorRepository) | ||
.withDockerImageTag(oldVersion); | ||
final StandardSourceDefinition source2 = new StandardSourceDefinition() | ||
.withSourceDefinitionId(UUID.randomUUID()) | ||
.withName("source-2") | ||
.withDockerRepository(connectorRepository) | ||
.withDockerImageTag(newVersion); | ||
writeSource(source1); | ||
writeSource(source2); | ||
final Map<String, ConnectorInfo> result = database.query(ctx -> migrator.getConnectorRepositoryToInfoMap(ctx)); | ||
// when there are duplicated connector definitions, the one with the latest version should be | ||
// retrieved | ||
assertEquals(newVersion, result.get(connectorRepository).dockerImageTag); | ||
} | ||
|
||
@Test | ||
void testHasNewVersion() { | ||
assertTrue(ActorDefinitionMigrator.hasNewVersion("0.1.99", DEFAULT_PROTOCOL_VERSION)); | ||
assertFalse(ActorDefinitionMigrator.hasNewVersion("invalid_version", "0.1.2")); | ||
} | ||
|
||
@Test | ||
void testHasNewPatchVersion() { | ||
assertFalse(ActorDefinitionMigrator.hasNewPatchVersion("0.1.99", DEFAULT_PROTOCOL_VERSION)); | ||
assertFalse(ActorDefinitionMigrator.hasNewPatchVersion("invalid_version", "0.3.1")); | ||
assertTrue(ActorDefinitionMigrator.hasNewPatchVersion("0.1.0", "0.1.3")); | ||
} | ||
|
||
@Test | ||
void testGetNewFields() { | ||
final JsonNode o1 = Jsons.deserialize("{ \"field1\": 1, \"field2\": 2 }"); | ||
final JsonNode o2 = Jsons.deserialize("{ \"field1\": 1, \"field3\": 3 }"); | ||
assertEquals(Collections.emptySet(), ActorDefinitionMigrator.getNewFields(o1, o1)); | ||
assertEquals(Collections.singleton("field3"), ActorDefinitionMigrator.getNewFields(o1, o2)); | ||
assertEquals(Collections.singleton("field2"), ActorDefinitionMigrator.getNewFields(o2, o1)); | ||
} | ||
|
||
@Test | ||
void testGetDefinitionWithNewFields() { | ||
final JsonNode current = Jsons.deserialize("{ \"field1\": 1, \"field2\": 2 }"); | ||
final JsonNode latest = Jsons.deserialize("{ \"field1\": 1, \"field3\": 3, \"field4\": 4 }"); | ||
final Set<String> newFields = Set.of("field3"); | ||
|
||
assertEquals(current, ActorDefinitionMigrator.getDefinitionWithNewFields(current, latest, Collections.emptySet())); | ||
|
||
final JsonNode currentWithNewFields = Jsons.deserialize("{ \"field1\": 1, \"field2\": 2, \"field3\": 3 }"); | ||
assertEquals(currentWithNewFields, ActorDefinitionMigrator.getDefinitionWithNewFields(current, latest, newFields)); | ||
} | ||
|
||
@Test | ||
void testActorDefinitionReleaseDate() throws Exception { | ||
final UUID definitionId = UUID.randomUUID(); | ||
final String connectorRepository = "airbyte/test-connector"; | ||
|
||
// when the record does not exist, it is inserted | ||
final StandardSourceDefinition sourceDef = new StandardSourceDefinition() | ||
.withSourceDefinitionId(definitionId) | ||
.withDockerRepository(connectorRepository) | ||
.withDockerImageTag("0.1.2") | ||
.withName("random-name") | ||
.withProtocolVersion(DEFAULT_PROTOCOL_VERSION) | ||
.withTombstone(false); | ||
writeSource(sourceDef); | ||
assertEquals(sourceDef, configRepository.getStandardSourceDefinition(sourceDef.getSourceDefinitionId())); | ||
} | ||
|
||
@Test | ||
void filterCustomSource() { | ||
final Map<String, ConnectorInfo> sourceMap = new HashMap<>(); | ||
final String nonCustomKey = "non-custom"; | ||
final String customKey = "custom"; | ||
sourceMap.put(nonCustomKey, new ConnectorInfo("id", Jsons.jsonNode(SOURCE_POSTGRES))); | ||
sourceMap.put(customKey, new ConnectorInfo("id", Jsons.jsonNode(SOURCE_CUSTOM))); | ||
|
||
final Map<String, ConnectorInfo> filteredSrcMap = migrator.filterCustomConnector(sourceMap, STANDARD_SOURCE_DEFINITION); | ||
|
||
assertThat(filteredSrcMap).containsOnlyKeys(nonCustomKey); | ||
} | ||
|
||
@Test | ||
void filterCustomDestination() { | ||
final Map<String, ConnectorInfo> sourceMap = new HashMap<>(); | ||
final String nonCustomKey = "non-custom"; | ||
final String customKey = "custom"; | ||
sourceMap.put(nonCustomKey, new ConnectorInfo("id", Jsons.jsonNode(DESTINATION_S3))); | ||
sourceMap.put(customKey, new ConnectorInfo("id", Jsons.jsonNode(DESTINATION_CUSTOM))); | ||
|
||
final Map<String, ConnectorInfo> filteredDestMap = migrator.filterCustomConnector(sourceMap, STANDARD_DESTINATION_DEFINITION); | ||
|
||
assertThat(filteredDestMap).containsOnlyKeys(nonCustomKey); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved from
ConfigRepository