Skip to content

Commit

Permalink
allow injecting filters for server (#4677)
Browse files Browse the repository at this point in the history
* allow injecting filters

* fmt
  • Loading branch information
jrhizor authored and gl-pix committed Jul 22, 2021
1 parent c074c8e commit 9e1575a
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions airbyte-server/src/main/java/io/airbyte/server/ServerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,14 @@
import io.temporal.serviceclient.WorkflowServiceStubs;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.ContainerResponseFilter;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
Expand All @@ -89,13 +93,19 @@ public class ServerApp {
private final ConfigRepository configRepository;
private final JobPersistence jobPersistence;
private final Configs configs;
private final Set<ContainerRequestFilter> requestFilters;
private final Set<ContainerResponseFilter> responseFilters;

public ServerApp(final ConfigRepository configRepository,
final JobPersistence jobPersistence,
final Configs configs) {
final Configs configs,
final Set<ContainerRequestFilter> requestFilters,
final Set<ContainerResponseFilter> responseFilters) {
this.configRepository = configRepository;
this.jobPersistence = jobPersistence;
this.configs = configs;
this.requestFilters = requestFilters;
this.responseFilters = responseFilters;
}

public void start() throws Exception {
Expand Down Expand Up @@ -123,9 +133,9 @@ public void start() throws Exception {

ResourceConfig rc =
new ResourceConfig()
// todo (cgardens) - the CORs settings are wide open. will need to revisit when we add auth.
// cors
.register(new CorsFilter())
// add filters
.registerInstances(requestFilters)
.registerInstances(responseFilters)
// request logging
.register(new RequestLogger(mdc))
// api
Expand Down Expand Up @@ -183,7 +193,9 @@ private static void setCustomerIdIfNotSet(final ConfigRepository configRepositor
}
}

public static void main(String[] args) throws Exception {
public static void runServer(final Set<ContainerRequestFilter> requestFilters,
final Set<ContainerResponseFilter> responseFilters)
throws Exception {
final Configs configs = new EnvConfigs();

MDC.put(LogClientSingleton.WORKSPACE_MDC_KEY, LogClientSingleton.getServerLogsRoot(configs).toString());
Expand Down Expand Up @@ -233,13 +245,17 @@ public static void main(String[] args) throws Exception {

if (airbyteDatabaseVersion.isPresent() && AirbyteVersion.isCompatible(airbyteVersion, airbyteDatabaseVersion.get())) {
LOGGER.info("Starting server...");
new ServerApp(configRepository, jobPersistence, configs).start();
new ServerApp(configRepository, jobPersistence, configs, requestFilters, responseFilters).start();
} else {
LOGGER.info("Start serving version mismatch errors. Automatic migration either failed or didn't run");
new VersionMismatchServer(airbyteVersion, airbyteDatabaseVersion.get(), PORT).start();
}
}

public static void main(String[] args) throws Exception {
runServer(Collections.emptySet(), Set.of(new CorsFilter()));
}

/**
* Ideally when automatic migration runs, we should make sure that we acquire a lock on database and
* no other operation is allowed
Expand Down

0 comments on commit 9e1575a

Please sign in to comment.