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

allow injecting filters for server #4677

Merged
merged 2 commits into from
Jul 12, 2021
Merged
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
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