Skip to content

Commit

Permalink
Prepare YamlSeedConfigPersistence for dependency injection (#13384)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpgrailsdev authored Jun 3, 2022
1 parent 0f61411 commit 568057a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class BootloaderApp {
private final FeatureFlags featureFlags;
private final SecretMigrator secretMigrator;
private ConfigPersistence configPersistence;
private ConfigPersistence yamlSeedConfigPersistence;
private Database configDatabase;
private Database jobDatabase;
private JobPersistence jobPersistence;
Expand Down Expand Up @@ -122,7 +123,7 @@ public BootloaderApp(final Configs configs,

postLoadExecution = () -> {
try {
configPersistence.loadData(YamlSeedConfigPersistence.getDefault());
configPersistence.loadData(yamlSeedConfigPersistence);

if (featureFlags.forceSecretMigration() || !jobPersistence.isSecretMigrated()) {
if (this.secretMigrator != null) {
Expand Down Expand Up @@ -190,6 +191,10 @@ private static ConfigPersistence getConfigPersistence(final Database configDatab
return DatabaseConfigPersistence.createWithValidation(configDatabase, jsonSecretsProcessor);
}

private static ConfigPersistence getYamlSeedConfigPersistence() throws IOException {
return new YamlSeedConfigPersistence(YamlSeedConfigPersistence.DEFAULT_SEED_DEFINITION_RESOURCE_CLASS);
}

private static Database getJobDatabase(final DSLContext dslContext) throws IOException {
return new Database(dslContext);
}
Expand All @@ -202,6 +207,7 @@ private void initPersistences(final DSLContext configsDslContext, final DSLConte
try {
configDatabase = getConfigDatabase(configsDslContext);
configPersistence = getConfigPersistence(configDatabase);
yamlSeedConfigPersistence = getYamlSeedConfigPersistence();
jobDatabase = getJobDatabase(jobsDslContext);
jobPersistence = getJobPersistence(jobDatabase);
} catch (final IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void testBootloaderAppRunSecretMigration() throws Exception {
val initBootloader = new BootloaderApp(mockedConfigs, mockedFeatureFlags, null, configsDslContext, jobsDslContext, configsFlyway, jobsFlyway);
initBootloader.load();

final ConfigPersistence localSchema = YamlSeedConfigPersistence.getDefault();
final ConfigPersistence localSchema = new YamlSeedConfigPersistence(YamlSeedConfigPersistence.DEFAULT_SEED_DEFINITION_RESOURCE_CLASS);
final ConfigRepository configRepository = new ConfigRepository(configPersistence, configDatabase);
configRepository.loadDataNoSecrets(localSchema);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,22 @@ final public class YamlSeedConfigPersistence implements ConfigPersistence {
ConfigSchema.STANDARD_DESTINATION_DEFINITION, SeedType.STANDARD_DESTINATION_DEFINITION);

// A mapping from seed config type to config UUID to config.
private final ImmutableMap<SeedType, Map<String, JsonNode>> allSeedConfigs;
private ImmutableMap<SeedType, Map<String, JsonNode>> allSeedConfigs;

public static YamlSeedConfigPersistence getDefault() throws IOException {
return new YamlSeedConfigPersistence(DEFAULT_SEED_DEFINITION_RESOURCE_CLASS);
}
// TODO inject via dependency injection framework
private final Class<?> seedResourceClass;

public YamlSeedConfigPersistence(final Class<?> seedResourceClass) throws IOException {
this.seedResourceClass = seedResourceClass;

public static YamlSeedConfigPersistence get(final Class<?> seedDefinitionsResourceClass) throws IOException {
return new YamlSeedConfigPersistence(seedDefinitionsResourceClass);
// TODO remove this call once dependency injection framework manages object creation
initialize();
}

private YamlSeedConfigPersistence(final Class<?> seedResourceClass) throws IOException {
final Map<String, JsonNode> sourceDefinitionConfigs = getConfigs(seedResourceClass, SeedType.STANDARD_SOURCE_DEFINITION);
final Map<String, JsonNode> sourceSpecConfigs = getConfigs(seedResourceClass, SeedType.SOURCE_SPEC);
// TODO will be called automatically by the dependency injection framework on object creation
public void initialize() throws IOException {
final Map<String, JsonNode> sourceDefinitionConfigs = getConfigs(this.seedResourceClass, SeedType.STANDARD_SOURCE_DEFINITION);
final Map<String, JsonNode> sourceSpecConfigs = getConfigs(this.seedResourceClass, SeedType.SOURCE_SPEC);
final Map<String, JsonNode> fullSourceDefinitionConfigs = sourceDefinitionConfigs.entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, e -> {
final JsonNode withMissingFields =
Expand All @@ -67,8 +70,8 @@ private YamlSeedConfigPersistence(final Class<?> seedResourceClass) throws IOExc
return output;
}));

final Map<String, JsonNode> destinationDefinitionConfigs = getConfigs(seedResourceClass, SeedType.STANDARD_DESTINATION_DEFINITION);
final Map<String, JsonNode> destinationSpecConfigs = getConfigs(seedResourceClass, SeedType.DESTINATION_SPEC);
final Map<String, JsonNode> destinationDefinitionConfigs = getConfigs(this.seedResourceClass, SeedType.STANDARD_DESTINATION_DEFINITION);
final Map<String, JsonNode> destinationSpecConfigs = getConfigs(this.seedResourceClass, SeedType.DESTINATION_SPEC);
final Map<String, JsonNode> fullDestinationDefinitionConfigs = destinationDefinitionConfigs.entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, e -> {
final JsonNode withMissingFields =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SpecFormatTest {

@Test
void testOnAllExistingConfig() throws IOException, JsonValidationException {
final ConfigPersistence configPersistence = YamlSeedConfigPersistence.getDefault();
final ConfigPersistence configPersistence = new YamlSeedConfigPersistence(YamlSeedConfigPersistence.DEFAULT_SEED_DEFINITION_RESOURCE_CLASS);

final List<JsonNode> sourceSpecs = configPersistence.listConfigs(
ConfigSchema.STANDARD_SOURCE_DEFINITION, StandardSourceDefinition.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class YamlSeedConfigPersistenceTest {

@BeforeAll
static void setup() throws IOException {
persistence = YamlSeedConfigPersistence.getDefault();
persistence = new YamlSeedConfigPersistence(YamlSeedConfigPersistence.DEFAULT_SEED_DEFINITION_RESOURCE_CLASS);
}

@Test
Expand Down
5 changes: 3 additions & 2 deletions airbyte-server/src/main/java/io/airbyte/server/ServerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,10 @@ public static void main(final String[] args) throws Exception {
ConfigsDatabaseMigrator.DB_IDENTIFIER, ConfigsDatabaseMigrator.MIGRATION_FILE_LOCATION);
final Flyway jobsFlyway = FlywayFactory.create(jobsDataSource, DbMigrationHandler.class.getSimpleName(), JobsDatabaseMigrator.DB_IDENTIFIER,
JobsDatabaseMigrator.MIGRATION_FILE_LOCATION);
final ConfigPersistence yamlSeedConfigPersistence =
new YamlSeedConfigPersistence(YamlSeedConfigPersistence.DEFAULT_SEED_DEFINITION_RESOURCE_CLASS);

getServer(new ServerFactory.Api(), YamlSeedConfigPersistence.getDefault(),
configs, configsDslContext, configsFlyway, jobsDslContext, jobsFlyway).start();
getServer(new ServerFactory.Api(), yamlSeedConfigPersistence, configs, configsDslContext, configsFlyway, jobsDslContext, jobsFlyway).start();
}
} catch (final Throwable e) {
LOGGER.error("Server failed", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void setup() throws Exception {
jobDatabase = databaseProviders.createNewJobsDatabase();
configDatabase = databaseProviders.createNewConfigsDatabase();
jobPersistence = new DefaultJobPersistence(jobDatabase);
seedPersistence = YamlSeedConfigPersistence.getDefault();
seedPersistence = new YamlSeedConfigPersistence(YamlSeedConfigPersistence.DEFAULT_SEED_DEFINITION_RESOURCE_CLASS);
jsonSecretsProcessor = JsonSecretsProcessor.builder()
.maskSecrets(false)
.copySecrets(false)
Expand All @@ -145,7 +145,7 @@ public void setup() throws Exception {
secretsRepositoryReader,
secretsRepositoryWriter,
jobPersistence,
YamlSeedConfigPersistence.getDefault(),
seedPersistence,
new WorkspaceHelper(configRepository, jobPersistence),
new NoOpFileTtlManager(),
true);
Expand Down

0 comments on commit 568057a

Please sign in to comment.