Repository: aurora Updated Branches: refs/heads/master 96a528746 -> 4137dd246
Improve in-process test ZooKeeper support MesosLogStreamModule tries to connect to ZooKeeper servers specified by -zk_endpoints even when -zk_in_proc=true. I updated the module to use injected server endpoints which will be based on the ephemeral port assigned to ZooKeeperTestServer if -zk_in_proc=true. This required to make @ServiceDiscoveryBindings.ZooKeeper public. I also tweaked shutdown process of ServiceDiscoveryModule.TestServerService so that it won't close existing ZooKeeper connections before clients close the session. While just delaying the execution by 1 second doesn't really guarantee that behavior, in practice this achieved clean shutdown of the scheduler with in-process ZooKeeper server. Testing Done: 1. Launch Mesos master and slave on my laptop. 2. Launch Aurora scheduler with following arguments: ``` -backup_dir=/var/lib/aurora/backups -cluster_name=local -mesos_master_address=localhost:5050 -serverset_path=/aurora/scheduler -ip=127.0.0.1 -hostname=localhost -http_port=8081 -zk_in_proc=true -zk_endpoints=localhost:2181 -native_log_zk_group_path=/aurora/replicated-log -native_log_file_path=/var/db/aurora ``` 3. Observe that there are no ZooKeeper error log outputs caused by missing endpoint. 4. Create a simple job, observer it launches normally and then kill it. 5. Stop the scheduler by sending /quitquitquit. 6. Observe that scheduler process shuts down normally. Bugs closed: AURORA-1947 Reviewed at https://reviews.apache.org/r/62423/ Project: http://git-wip-us.apache.org/repos/asf/aurora/repo Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/4137dd24 Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/4137dd24 Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/4137dd24 Branch: refs/heads/master Commit: 4137dd2467fe3c45417af0a8f3f71167ea63739a Parents: 96a5287 Author: Keisuke Nishimoto <[email protected]> Authored: Thu Sep 21 14:33:27 2017 -0700 Committer: Bill Farner <[email protected]> Committed: Thu Sep 21 14:33:27 2017 -0700 ---------------------------------------------------------------------- .../scheduler/discovery/ServiceDiscoveryBindings.java | 4 ++-- .../scheduler/discovery/ServiceDiscoveryModule.java | 10 ++++++++-- .../aurora/scheduler/discovery/ZooKeeperConfig.java | 2 +- .../aurora/scheduler/log/mesos/MesosLogStreamModule.java | 6 ++++-- 4 files changed, 15 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aurora/blob/4137dd24/src/main/java/org/apache/aurora/scheduler/discovery/ServiceDiscoveryBindings.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/aurora/scheduler/discovery/ServiceDiscoveryBindings.java b/src/main/java/org/apache/aurora/scheduler/discovery/ServiceDiscoveryBindings.java index 28cdc4b..b574c13 100644 --- a/src/main/java/org/apache/aurora/scheduler/discovery/ServiceDiscoveryBindings.java +++ b/src/main/java/org/apache/aurora/scheduler/discovery/ServiceDiscoveryBindings.java @@ -31,7 +31,7 @@ import org.apache.zookeeper.data.ACL; * Useful constants for Guice modules that provide or consume service discovery configuration * bindings. */ -final class ServiceDiscoveryBindings { +public final class ServiceDiscoveryBindings { /** * Indicates a binding for ZooKeeper configuration data. @@ -39,7 +39,7 @@ final class ServiceDiscoveryBindings { @Qualifier @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) - @interface ZooKeeper { } + public @interface ZooKeeper { } /** * A binding key for the ZooKeeper cluster endpoints. http://git-wip-us.apache.org/repos/asf/aurora/blob/4137dd24/src/main/java/org/apache/aurora/scheduler/discovery/ServiceDiscoveryModule.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/aurora/scheduler/discovery/ServiceDiscoveryModule.java b/src/main/java/org/apache/aurora/scheduler/discovery/ServiceDiscoveryModule.java index c105dbd..917a567 100644 --- a/src/main/java/org/apache/aurora/scheduler/discovery/ServiceDiscoveryModule.java +++ b/src/main/java/org/apache/aurora/scheduler/discovery/ServiceDiscoveryModule.java @@ -17,6 +17,9 @@ import java.io.File; import java.io.IOException; import java.net.InetSocketAddress; import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import javax.inject.Singleton; @@ -77,7 +80,7 @@ public class ServiceDiscoveryModule extends AbstractModule { bind(ZooKeeperTestServer.class).toInstance(new ZooKeeperTestServer(tempDir, tempDir)); SchedulerServicesModule.addAppStartupServiceBinding(binder()).to(TestServerService.class); - clusterBinder.toProvider(LocalZooKeeperClusterProvider.class); + clusterBinder.toProvider(LocalZooKeeperClusterProvider.class).in(Singleton.class); } else { clusterBinder.toInstance(zooKeeperConfig.getServers()); } @@ -125,7 +128,10 @@ public class ServiceDiscoveryModule extends AbstractModule { @Override protected void shutDown() { - testServer.stop(); + // Delay stopping ZooKeeper server to ensure that clients close first during service shutdown. + ScheduledExecutorService executorService = Executors.newScheduledThreadPool(0); + executorService.schedule(() -> testServer.stop(), 1000, TimeUnit.MILLISECONDS); + executorService.shutdown(); } } http://git-wip-us.apache.org/repos/asf/aurora/blob/4137dd24/src/main/java/org/apache/aurora/scheduler/discovery/ZooKeeperConfig.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/aurora/scheduler/discovery/ZooKeeperConfig.java b/src/main/java/org/apache/aurora/scheduler/discovery/ZooKeeperConfig.java index 3f32a62..4014a91 100644 --- a/src/main/java/org/apache/aurora/scheduler/discovery/ZooKeeperConfig.java +++ b/src/main/java/org/apache/aurora/scheduler/discovery/ZooKeeperConfig.java @@ -102,7 +102,7 @@ public class ZooKeeperConfig { return useCurator; } - public Iterable<InetSocketAddress> getServers() { + Iterable<InetSocketAddress> getServers() { return servers; } http://git-wip-us.apache.org/repos/asf/aurora/blob/4137dd24/src/main/java/org/apache/aurora/scheduler/log/mesos/MesosLogStreamModule.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/aurora/scheduler/log/mesos/MesosLogStreamModule.java b/src/main/java/org/apache/aurora/scheduler/log/mesos/MesosLogStreamModule.java index 6704a32..9a6c0c4 100644 --- a/src/main/java/org/apache/aurora/scheduler/log/mesos/MesosLogStreamModule.java +++ b/src/main/java/org/apache/aurora/scheduler/log/mesos/MesosLogStreamModule.java @@ -14,6 +14,7 @@ package org.apache.aurora.scheduler.log.mesos; import java.io.File; +import java.net.InetSocketAddress; import java.util.List; import java.util.Objects; import java.util.concurrent.TimeUnit; @@ -35,6 +36,7 @@ import org.apache.aurora.common.quantity.Amount; import org.apache.aurora.common.quantity.Time; import org.apache.aurora.common.zookeeper.Credentials; import org.apache.aurora.gen.storage.LogEntry; +import org.apache.aurora.scheduler.discovery.ServiceDiscoveryBindings; import org.apache.aurora.scheduler.discovery.ZooKeeperConfig; import org.apache.aurora.scheduler.log.mesos.LogInterface.ReaderInterface; import org.apache.aurora.scheduler.log.mesos.LogInterface.WriterInterface; @@ -138,14 +140,14 @@ public class MesosLogStreamModule extends PrivateModule { @Provides @Singleton - Log provideLog() { + Log provideLog(@ServiceDiscoveryBindings.ZooKeeper Iterable<InetSocketAddress> servers) { File parentDir = logPath.getParentFile(); if (!parentDir.exists() && !parentDir.mkdirs()) { addError("Failed to create parent directory to store native log at: %s", parentDir); } String zkConnectString = Joiner.on(',').join( - Iterables.transform(zkClientConfig.getServers(), InetSocketAddressHelper::toString)); + Iterables.transform(servers, InetSocketAddressHelper::toString)); if (zkClientConfig.getCredentials().isPresent()) { Credentials zkCredentials = zkClientConfig.getCredentials().get();
