Skip to content
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 config persistence from seeding logic #18749

Merged
merged 6 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
import io.airbyte.config.Geography;
import io.airbyte.config.SourceConnection;
import io.airbyte.config.StandardWorkspace;
import io.airbyte.config.init.DefinitionProviderToConfigPersistenceAdapter;
import io.airbyte.config.init.DefinitionsProvider;
import io.airbyte.config.init.LocalDefinitionsProvider;
import io.airbyte.config.persistence.ConfigPersistence;
import io.airbyte.config.persistence.ConfigRepository;
import io.airbyte.config.persistence.DatabaseConfigPersistence;
import io.airbyte.config.persistence.SecretsRepositoryReader;
Expand Down Expand Up @@ -213,8 +211,7 @@ void testBootloaderAppRunSecretMigration() throws Exception {
initBootloader.load();

final DefinitionsProvider localDefinitions = new LocalDefinitionsProvider(LocalDefinitionsProvider.DEFAULT_SEED_DEFINITION_RESOURCE_CLASS);
final ConfigPersistence localConfigPersistence = new DefinitionProviderToConfigPersistenceAdapter(localDefinitions);
configRepository.loadDataNoSecrets(localConfigPersistence);
configRepository.seedActorDefinitions(localDefinitions.getSourceDefinitions(), localDefinitions.getDestinationDefinitions());

final String sourceSpecs = """
{
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,4 @@ public Map<String, Stream<JsonNode>> dumpConfigs() throws IOException {
return decoratedPersistence.dumpConfigs();
}

@Override
public void loadData(final ConfigPersistence seedPersistence) throws IOException {
decoratedPersistence.loadData(seedPersistence);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,4 @@ <T> ConfigWithMetadata<T> getConfigWithMetadata(AirbyteConfig configType, String

Map<String, Stream<JsonNode>> dumpConfigs() throws IOException;

void loadData(ConfigPersistence seedPersistence) throws IOException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,17 @@ public class ConfigRepository {

private final ConfigPersistence persistence;
private final ExceptionWrappingDatabase database;
private final ActorDefinitionMigrator actorDefinitionMigrator;

public ConfigRepository(final ConfigPersistence persistence, final Database database) {
this.persistence = persistence;
this.database = new ExceptionWrappingDatabase(database);
this(persistence, database, new ActorDefinitionMigrator(new ExceptionWrappingDatabase(database)));
}

public ConfigPersistence getConfigPersistence() {
return persistence;
@VisibleForTesting
ConfigRepository(final ConfigPersistence persistence, final Database database, final ActorDefinitionMigrator actorDefinitionMigrator) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep only this constructor? Otherwise it will make us to move away from Micronaut, We should update the bean of the different BeanFactories.

this.persistence = persistence;
this.database = new ExceptionWrappingDatabase(database);
this.actorDefinitionMigrator = actorDefinitionMigrator;
}

/**
Expand Down Expand Up @@ -657,7 +660,7 @@ public List<DestinationConnection> listDestinationConnection() throws JsonValida
* @return destinations
* @throws IOException - you never know when you IO
*/
public List<DestinationConnection> listWorkspaceDestinationConnection(UUID workspaceId) throws IOException {
public List<DestinationConnection> listWorkspaceDestinationConnection(final UUID workspaceId) throws IOException {
final Result<Record> result = database.query(ctx -> ctx.select(asterisk())
.from(ACTOR)
.where(ACTOR.ACTOR_TYPE.eq(ActorType.destination))
Expand All @@ -673,7 +676,7 @@ public List<DestinationConnection> listWorkspaceDestinationConnection(UUID works
* @return sources
* @throws IOException
*/
public List<SourceConnection> listSourcesForDefinition(UUID definitionId) throws IOException {
public List<SourceConnection> listSourcesForDefinition(final UUID definitionId) throws IOException {
final Result<Record> result = database.query(ctx -> ctx.select(asterisk())
.from(ACTOR)
.where(ACTOR.ACTOR_TYPE.eq(ActorType.source))
Expand All @@ -689,7 +692,7 @@ public List<SourceConnection> listSourcesForDefinition(UUID definitionId) throws
* @return destinations
* @throws IOException
*/
public List<DestinationConnection> listDestinationsForDefinition(UUID definitionId) throws IOException {
public List<DestinationConnection> listDestinationsForDefinition(final UUID definitionId) throws IOException {
final Result<Record> result = database.query(ctx -> ctx.select(asterisk())
.from(ACTOR)
.where(ACTOR.ACTOR_TYPE.eq(ActorType.destination))
Expand Down Expand Up @@ -915,6 +918,19 @@ private Map<UUID, AirbyteCatalog> findCatalogByHash(final String catalogHash, fi
return result;
}

/**
* Updates the database with the most up-to-date source and destination definitions in the connector
* catalog.
*
* @param seedSourceDefs - most up-to-date source definitions
* @param seedDestDefs - most up-to-date destination definitions
* @throws IOException - throws if exception when interacting with db
*/
public void seedActorDefinitions(final List<StandardSourceDefinition> seedSourceDefs, final List<StandardDestinationDefinition> seedDestDefs)
throws IOException {
actorDefinitionMigrator.migrate(seedSourceDefs, seedDestDefs);
}

// Data-carrier records to hold combined result of query for a Source or Destination and its
// corresponding Definition. This enables the API layer to
// process combined information about a Source/Destination/Definition pair without requiring two
Expand Down Expand Up @@ -1146,19 +1162,6 @@ public Map<String, Stream<JsonNode>> dumpConfigsNoSecrets() throws IOException {
return persistence.dumpConfigs();
}

/**
* MUST NOT ACCEPT SECRETS - Package private so that secrets are not accidentally passed in. Should
* only be called from { @link SecretsRepositoryWriter }
*
* Loads all Data from a ConfigPersistence into the database.
*
* @param seedPersistenceWithoutSecrets - seed persistence WITHOUT secrets
* @throws IOException - you never know when you IO
*/
public void loadDataNoSecrets(final ConfigPersistence seedPersistenceWithoutSecrets) throws IOException {
persistence.loadData(seedPersistenceWithoutSecrets);
}

/**
* The following methods are present to allow the JobCreationAndStatusUpdateActivity class to emit
* metrics without exposing the underlying database connection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1638,14 +1638,6 @@ public Map<String, Stream<JsonNode>> dumpConfigs() throws IOException {
return result;
}

@Override
public void loadData(final ConfigPersistence seedConfigPersistence) throws IOException {
database.transaction(ctx -> {
updateConfigsFromSeed(ctx, seedConfigPersistence);
return null;
});
}

@VisibleForTesting
void updateConfigsFromSeed(final DSLContext ctx, final ConfigPersistence seedConfigPersistence) throws SQLException {
LOGGER.info("Updating connector definitions from the seed if necessary...");
Expand Down Expand Up @@ -1940,8 +1932,8 @@ static class ConnectorInfo {
ConnectorInfo(final String definitionId, final JsonNode definition) {
this.definitionId = definitionId;
this.definition = definition;
this.dockerRepository = definition.get("dockerRepository").asText();
this.dockerImageTag = definition.get("dockerImageTag").asText();
dockerRepository = definition.get("dockerRepository").asText();
dockerImageTag = definition.get("dockerImageTag").asText();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,6 @@ public Map<String, Stream<JsonNode>> dumpConfigs() throws IOException {
return decoratedPersistence.dumpConfigs();
}

@Override
public void loadData(final ConfigPersistence seedPersistence) throws IOException {
decoratedPersistence.loadData(seedPersistence);
}

private <T> void validateJson(final T config, final AirbyteConfig configType) throws JsonValidationException {
final JsonNode schema = JsonSchemaValidator.getSchema(configType.getConfigSchemaFile());
schemaValidator.ensure(schema, Jsons.jsonNode(config));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import io.airbyte.config.StandardDestinationDefinition;
import io.airbyte.config.StandardSourceDefinition;
import io.airbyte.config.persistence.ConfigPersistence;
import io.airbyte.config.persistence.ConfigRepository;
import io.airbyte.validation.json.JsonValidationException;
import java.io.IOException;
Expand Down Expand Up @@ -49,9 +48,9 @@ public void apply(final boolean updateAll) throws JsonValidationException, IOExc
} else {
// todo (pedroslopez): Logic to apply definitions should be moved outside of the
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pedroslopez i think this PR does this todo. i don't have context into why it wasn't all just using loadData in the first place. is there any reason not to just reduce down to this one code path?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason for this updateAll branching is because there are still some differences in how Cloud applies definitions vs OSS, but maybe there's a way to override the updateActorDefinitions method for Cloud instead of using this helper class. I think ideally we eventually standardize the behaviors between OSS and Cloud.

// DatabaseConfigPersistence class and behavior standardized
final ConfigPersistence dbConfigPersistence = configRepository.getConfigPersistence();
final ConfigPersistence providerConfigPersistence = new DefinitionProviderToConfigPersistenceAdapter(definitionsProvider);
dbConfigPersistence.loadData(providerConfigPersistence);
configRepository.seedActorDefinitions(
definitionsProvider.getSourceDefinitions(),
definitionsProvider.getDestinationDefinitions());
}
}

Expand Down
Loading