Skip to content

Commit

Permalink
the finals
Browse files Browse the repository at this point in the history
  • Loading branch information
cgardens committed Aug 25, 2021
1 parent 7b7ff33 commit d1f91dd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ 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);
}
Expand All @@ -239,7 +239,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 @@ -311,15 +311,15 @@ 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());
}

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

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) {
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 @@ -120,7 +120,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 @@ -162,7 +162,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();

MDC.put(LogClientSingleton.WORKSPACE_MDC_KEY, LogClientSingleton.getServerLogsRoot(configs).toString());
Expand Down Expand Up @@ -201,8 +201,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 @@ -236,38 +236,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 d1f91dd

Please sign in to comment.