Skip to content

Commit

Permalink
the finals
Browse files Browse the repository at this point in the history
  • Loading branch information
cgardens committed Sep 11, 2021
1 parent efacd5d commit a04808c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ public WorkerEnvironment getWorkerEnvironment() {

@Override
public WorkspaceRetentionConfig getWorkspaceRetentionConfig() {
long minDays = getEnvOrDefault(MINIMUM_WORKSPACE_RETENTION_DAYS, DEFAULT_MINIMUM_WORKSPACE_RETENTION_DAYS);
long maxDays = getEnvOrDefault(MAXIMUM_WORKSPACE_RETENTION_DAYS, DEFAULT_MAXIMUM_WORKSPACE_RETENTION_DAYS);
long maxSizeMb = getEnvOrDefault(MAXIMUM_WORKSPACE_SIZE_MB, DEFAULT_MAXIMUM_WORKSPACE_SIZE_MB);
final long minDays = getEnvOrDefault(MINIMUM_WORKSPACE_RETENTION_DAYS, DEFAULT_MINIMUM_WORKSPACE_RETENTION_DAYS);
final long maxDays = getEnvOrDefault(MAXIMUM_WORKSPACE_RETENTION_DAYS, DEFAULT_MAXIMUM_WORKSPACE_RETENTION_DAYS);
final long maxSizeMb = getEnvOrDefault(MAXIMUM_WORKSPACE_SIZE_MB, DEFAULT_MAXIMUM_WORKSPACE_SIZE_MB);

return new WorkspaceRetentionConfig(minDays, maxDays, maxSizeMb);
}

private WorkerPodToleration workerPodToleration(String tolerationStr) {
Map<String, String> tolerationMap = Splitter.on(",")
private WorkerPodToleration workerPodToleration(final String tolerationStr) {
final Map<String, String> tolerationMap = Splitter.on(",")
.splitToStream(tolerationStr)
.map(s -> s.split("="))
.collect(Collectors.toMap(s -> s[0], s -> s[1]));
Expand Down Expand Up @@ -288,9 +288,9 @@ private WorkerPodToleration workerPodToleration(String tolerationStr) {
*/
@Override
public List<WorkerPodToleration> getWorkerPodTolerations() {
String tolerationsStr = getEnvOrDefault(WORKER_POD_TOLERATIONS, "");
final String tolerationsStr = getEnvOrDefault(WORKER_POD_TOLERATIONS, "");

Stream<String> tolerations = Strings.isNullOrEmpty(tolerationsStr) ? Stream.of()
final Stream<String> tolerations = Strings.isNullOrEmpty(tolerationsStr) ? Stream.of()
: Splitter.on(";")
.splitToStream(tolerationsStr)
.filter(tolerationStr -> !Strings.isNullOrEmpty(tolerationStr));
Expand All @@ -317,7 +317,7 @@ public String getTemporalHost() {

@Override
public Set<Integer> getTemporalWorkerPorts() {
var ports = getEnvOrDefault(TEMPORAL_WORKER_PORTS, "");
final var ports = getEnvOrDefault(TEMPORAL_WORKER_PORTS, "");
if (ports.isEmpty()) {
return new HashSet<>();
}
Expand Down Expand Up @@ -389,27 +389,27 @@ public String getGoogleApplicationCredentials() {
return getEnvOrDefault(LogClientSingleton.GOOGLE_APPLICATION_CREDENTIALS, "");
}

private String getEnvOrDefault(String key, String defaultValue) {
private String getEnvOrDefault(final String key, final String defaultValue) {
return getEnvOrDefault(key, defaultValue, Function.identity(), false);
}

private String getEnvOrDefault(String key, String defaultValue, boolean isSecret) {
private String getEnvOrDefault(final String key, final String defaultValue, final boolean isSecret) {
return getEnvOrDefault(key, defaultValue, Function.identity(), isSecret);
}

private long getEnvOrDefault(String key, long defaultValue) {
private long getEnvOrDefault(final String key, final long defaultValue) {
return getEnvOrDefault(key, defaultValue, Long::parseLong, false);
}

private boolean getEnvOrDefault(String key, boolean defaultValue) {
private boolean getEnvOrDefault(final String key, final boolean defaultValue) {
return getEnvOrDefault(key, defaultValue, Boolean::parseBoolean);
}

private <T> T getEnvOrDefault(String key, T defaultValue, Function<String, T> parser) {
private <T> T getEnvOrDefault(final String key, final T defaultValue, final Function<String, T> parser) {
return getEnvOrDefault(key, defaultValue, parser, false);
}

private <T> T getEnvOrDefault(String key, T defaultValue, Function<String, T> parser, boolean isSecret) {
private <T> T getEnvOrDefault(final String key, final T defaultValue, final Function<String, T> parser, final boolean isSecret) {
final String value = getEnv.apply(key);
if (value != null && !value.isEmpty()) {
return parser.apply(value);
Expand Down
28 changes: 14 additions & 14 deletions airbyte-server/src/main/java/io/airbyte/server/ServerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void start() throws Exception {
customComponentClasses.forEach(rc::register);
customComponents.forEach(rc::register);

ServletHolder configServlet = new ServletHolder(new ServletContainer(rc));
final ServletHolder configServlet = new ServletHolder(new ServletContainer(rc));

handler.addServlet(configServlet, "/api/*");

Expand Down Expand Up @@ -167,7 +167,7 @@ private static void createWorkspaceIfNoneExists(final ConfigRepository configRep
TrackingClientSingleton.get().identify(workspaceId);
}

public static ServerRunnable getServer(ServerFactory apiFactory) throws Exception {
public static ServerRunnable getServer(final ServerFactory apiFactory) throws Exception {
final Configs configs = new EnvConfigs();

LogClientSingleton.setWorkspaceMdc(LogClientSingleton.getServerLogsRoot(configs));
Expand Down Expand Up @@ -212,8 +212,8 @@ public static ServerRunnable getServer(ServerFactory apiFactory) throws Exceptio

Optional<String> airbyteDatabaseVersion = jobPersistence.getVersion();
if (airbyteDatabaseVersion.isPresent() && isDatabaseVersionBehindAppVersion(airbyteVersion, airbyteDatabaseVersion.get())) {
boolean isKubernetes = configs.getWorkerEnvironment() == WorkerEnvironment.KUBERNETES;
boolean versionSupportsAutoMigrate =
final boolean isKubernetes = configs.getWorkerEnvironment() == WorkerEnvironment.KUBERNETES;
final boolean versionSupportsAutoMigrate =
new AirbyteVersion(airbyteDatabaseVersion.get()).patchVersionCompareTo(KUBE_SUPPORT_FOR_AUTOMATIC_MIGRATION) >= 0;
if (!isKubernetes || versionSupportsAutoMigrate) {
runAutomaticMigration(configRepository, jobPersistence, airbyteVersion, airbyteDatabaseVersion.get());
Expand Down Expand Up @@ -253,38 +253,38 @@ public static ServerRunnable getServer(ServerFactory apiFactory) throws Exceptio
}
}

public static void main(String[] args) throws Exception {
public static void main(final String[] args) throws Exception {
getServer(new ServerFactory.Api()).start();
}

/**
* Ideally when automatic migration runs, we should make sure that we acquire a lock on database and
* no other operation is allowed
*/
private static void runAutomaticMigration(ConfigRepository configRepository,
JobPersistence jobPersistence,
String airbyteVersion,
String airbyteDatabaseVersion) {
private static void runAutomaticMigration(final ConfigRepository configRepository,
final JobPersistence jobPersistence,
final String airbyteVersion,
final String airbyteDatabaseVersion) {
LOGGER.info("Running Automatic Migration from version : " + airbyteDatabaseVersion + " to version : " + airbyteVersion);
try (final RunMigration runMigration = new RunMigration(
jobPersistence,
configRepository,
airbyteVersion,
YamlSeedConfigPersistence.get())) {
runMigration.run();
} catch (Exception e) {
} catch (final Exception e) {
LOGGER.error("Automatic Migration failed ", e);
}
}

public static boolean isDatabaseVersionBehindAppVersion(String airbyteVersion, String airbyteDatabaseVersion) {
boolean bothVersionsCompatible = AirbyteVersion.isCompatible(airbyteVersion, airbyteDatabaseVersion);
public static boolean isDatabaseVersionBehindAppVersion(final String airbyteVersion, final String airbyteDatabaseVersion) {
final boolean bothVersionsCompatible = AirbyteVersion.isCompatible(airbyteVersion, airbyteDatabaseVersion);
if (bothVersionsCompatible) {
return false;
}

AirbyteVersion serverVersion = new AirbyteVersion(airbyteVersion);
AirbyteVersion databaseVersion = new AirbyteVersion(airbyteDatabaseVersion);
final AirbyteVersion serverVersion = new AirbyteVersion(airbyteVersion);
final AirbyteVersion databaseVersion = new AirbyteVersion(airbyteDatabaseVersion);

if (databaseVersion.getMajorVersion().compareTo(serverVersion.getMajorVersion()) < 0) {
return true;
Expand Down

0 comments on commit a04808c

Please sign in to comment.