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

Use constructor injection for singleton #18163

Merged
merged 1 commit into from
Oct 19, 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 @@ -4,9 +4,14 @@

package io.airbyte.cron.config;

import io.airbyte.config.Configs.DeploymentMode;
import io.airbyte.config.persistence.split_secrets.JsonSecretsProcessor;
import io.micronaut.context.annotation.Factory;
import io.micronaut.context.annotation.Value;
import io.micronaut.core.util.StringUtils;
import jakarta.inject.Singleton;
import java.util.Locale;
import java.util.function.Function;
import lombok.extern.slf4j.Slf4j;

/**
Expand All @@ -16,11 +21,20 @@
@Slf4j
public class ApplicationBeanFactory {

@Singleton
public DeploymentMode deploymentMode(@Value("${airbyte.deployment-mode}") final String deploymentMode) {
return convertToEnum(deploymentMode, DeploymentMode::valueOf, DeploymentMode.OSS);
}

@Singleton
public JsonSecretsProcessor jsonSecretsProcessor() {
return JsonSecretsProcessor.builder()
.copySecrets(false)
.build();
}

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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@

import datadog.trace.api.Trace;
import io.airbyte.config.Configs.DeploymentMode;
import io.airbyte.config.EnvConfigs;
import io.airbyte.config.init.ApplyDefinitionsHelper;
import io.airbyte.config.init.RemoteDefinitionsProvider;
import io.airbyte.config.persistence.ConfigRepository;
import io.micronaut.context.annotation.Value;
import io.micronaut.scheduling.annotation.Scheduled;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import java.net.URI;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -29,29 +27,33 @@
@Slf4j
public class DefinitionsUpdater {

@Inject
private ConfigRepository configRepository;
private final ConfigRepository configRepository;

@Value("${airbyte.cron.update-definitions.enabled}")
private boolean shouldUpdateDefinitions;
private final boolean shouldUpdateDefinitions;

private final URI remoteCatalogUrl;
private final DeploymentMode deploymentMode;

public DefinitionsUpdater() {
public DefinitionsUpdater(final ConfigRepository configRepository,
final DeploymentMode deploymentMode,
@Value("${airbyte.remote-connector-catalog-url}") final String remoteCatalogUrl,
@Value("${airbyte.cron.update-definitions.enabled}") final boolean shouldUpdateDefinitions) {
log.info("Creating connector definitions updater");

final EnvConfigs envConfigs = new EnvConfigs();
remoteCatalogUrl = envConfigs.getRemoteConnectorCatalogUrl().orElse(null);
deploymentMode = envConfigs.getDeploymentMode();
this.configRepository = configRepository;
this.deploymentMode = deploymentMode;
this.remoteCatalogUrl = remoteCatalogUrl != null ? URI.create(remoteCatalogUrl) : null;
this.shouldUpdateDefinitions = shouldUpdateDefinitions;
}

@Trace(operationName = SCHEDULED_TRACE_OPERATION_NAME)
@Scheduled(fixedRate = "30s",
initialDelay = "1m")
void updateDefinitions() {
if (!shouldUpdateDefinitions)
if (!shouldUpdateDefinitions) {
log.info("Connector definitions update disabled.");
return;
}

if (remoteCatalogUrl == null) {
log.warn("Tried to update definitions, but the remote catalog url is not set");
Expand Down
1 change: 1 addition & 0 deletions airbyte-cron/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ airbyte:
local:
docker-mount: ${LOCAL_DOCKER_MOUNT:}
root: ${LOCAL_ROOT}
remote-connector-catalog-url: ${REMOTE_CONNECTOR_CATALOG_URL:}
role: ${AIRBYTE_ROLE:}
temporal:
worker:
Expand Down