aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zma...@apache.org
Subject aurora git commit: Populate `host` and `webURL`fields of FrameworkInfo.
Date Sat, 18 Mar 2017 00:06:26 GMT
Repository: aurora
Updated Branches:
  refs/heads/master e1504a7e8 -> 5bffe8f6a


Populate `host` and `webURL`fields of FrameworkInfo.

This patch extracts out `FrameworkInfo` construction from the `DriverSettings`
data class to a factory class. This factory class combines the base info
constructed via CLI arguments with the HTTP server's host and port information.
This allows us to populate the `host` and `weburl` fields of framework info,
which enhance the Mesos UI.

This is necessary for users of the `V1_DRIVER` as the new driver does not
automatically populate the `host` field. Further, by using our own host and port
information, we ensure the information in ZooKeeper, the information used for
HTTP redirects and the information in the Mesos UI are all in sync.

Note that in vagrant, the hostname and URL are `aurora.local` because we set the
`--hostname` argument of the scheduler. By default Java will set it to the FQDN
or IP address of the host.

Testing Done:
e2e tests.

Bugs closed: AURORA-1905

Reviewed at https://reviews.apache.org/r/57708/


Project: http://git-wip-us.apache.org/repos/asf/aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/5bffe8f6
Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/5bffe8f6
Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/5bffe8f6

Branch: refs/heads/master
Commit: 5bffe8f6a03af1d809f0eaa88af1c73223341f1e
Parents: e1504a7
Author: Zameer Manji <zmanji@apache.org>
Authored: Fri Mar 17 17:06:15 2017 -0700
Committer: Zameer Manji <zmanji@apache.org>
Committed: Fri Mar 17 17:06:15 2017 -0700

----------------------------------------------------------------------
 .../aurora/benchmark/StatusUpdateBenchmark.java | 11 +--
 .../aurora/scheduler/app/SchedulerMain.java     | 12 +++
 .../mesos/CommandLineDriverSettingsModule.java  | 15 +++-
 .../aurora/scheduler/mesos/DriverSettings.java  |  9 +-
 .../scheduler/mesos/FrameworkInfoFactory.java   | 90 ++++++++++++++++++++
 .../scheduler/mesos/SchedulerDriverService.java |  7 +-
 .../mesos/VersionedMesosSchedulerImpl.java      |  8 +-
 .../mesos/VersionedSchedulerDriverService.java  |  7 +-
 .../aurora/scheduler/app/SchedulerIT.java       | 15 ++--
 .../scheduler/app/local/LocalSchedulerMain.java | 16 ++--
 .../mesos/FrameworkInfoFactoryImplTest.java     | 54 ++++++++++++
 .../mesos/SchedulerDriverServiceTest.java       | 22 +++--
 .../mesos/VersionedMesosSchedulerImplTest.java  |  8 +-
 .../VersionedSchedulerDriverServiceTest.java    | 18 ++--
 .../aurora/scheduler/thrift/ThriftIT.java       | 22 +++--
 15 files changed, 256 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/5bffe8f6/src/jmh/java/org/apache/aurora/benchmark/StatusUpdateBenchmark.java
----------------------------------------------------------------------
diff --git a/src/jmh/java/org/apache/aurora/benchmark/StatusUpdateBenchmark.java b/src/jmh/java/org/apache/aurora/benchmark/StatusUpdateBenchmark.java
index 95496c1..206b114 100644
--- a/src/jmh/java/org/apache/aurora/benchmark/StatusUpdateBenchmark.java
+++ b/src/jmh/java/org/apache/aurora/benchmark/StatusUpdateBenchmark.java
@@ -61,6 +61,7 @@ import org.apache.aurora.scheduler.filter.SchedulingFilterImpl;
 import org.apache.aurora.scheduler.mesos.Driver;
 import org.apache.aurora.scheduler.mesos.DriverFactory;
 import org.apache.aurora.scheduler.mesos.DriverSettings;
+import org.apache.aurora.scheduler.mesos.FrameworkInfoFactory;
 import org.apache.aurora.scheduler.mesos.MesosCallbackHandler;
 import org.apache.aurora.scheduler.mesos.MesosCallbackHandler.MesosCallbackHandlerImpl;
 import org.apache.aurora.scheduler.mesos.MesosSchedulerImpl;
@@ -206,11 +207,11 @@ public class StatusUpdateBenchmark {
             bind(DriverSettings.class).toInstance(
                 new DriverSettings(
                     "fakemaster",
-                    Optional.absent(),
-                    Protos.FrameworkInfo.newBuilder()
-                        .setUser("framework user")
-                        .setName("test framework")
-                        .build()));
+                    Optional.absent()));
+            bind(FrameworkInfoFactory.class).toInstance(() -> Protos.FrameworkInfo.newBuilder()
+                    .setUser("framework user")
+                    .setName("test framework")
+                    .build());
             bind(RescheduleCalculator.class).toInstance(new FakeRescheduleCalculator());
             bind(Clock.class).toInstance(new FakeClock());
             bind(ExecutorSettings.class).toInstance(TestExecutorSettings.THERMOS_EXECUTOR);

http://git-wip-us.apache.org/repos/asf/aurora/blob/5bffe8f6/src/main/java/org/apache/aurora/scheduler/app/SchedulerMain.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/app/SchedulerMain.java b/src/main/java/org/apache/aurora/scheduler/app/SchedulerMain.java
index 3665c4d..3fbe99c 100644
--- a/src/main/java/org/apache/aurora/scheduler/app/SchedulerMain.java
+++ b/src/main/java/org/apache/aurora/scheduler/app/SchedulerMain.java
@@ -56,6 +56,7 @@ import org.apache.aurora.scheduler.events.WebhookModule;
 import org.apache.aurora.scheduler.http.HttpService;
 import org.apache.aurora.scheduler.log.mesos.MesosLogStreamModule;
 import org.apache.aurora.scheduler.mesos.CommandLineDriverSettingsModule;
+import org.apache.aurora.scheduler.mesos.FrameworkInfoFactory.FrameworkInfoFactoryImpl.SchedulerProtocol;
 import org.apache.aurora.scheduler.mesos.LibMesosLoadingModule;
 import org.apache.aurora.scheduler.stats.StatsModule;
 import org.apache.aurora.scheduler.storage.Storage;
@@ -82,6 +83,7 @@ public class SchedulerMain {
   @CmdLine(name = "serverset_path", help = "ZooKeeper ServerSet path to register at.")
   private static final Arg<String> SERVERSET_PATH = Arg.create();
 
+  // TODO(zmanji): Consider making this an enum of HTTP or HTTPS.
   @CmdLine(name = "serverset_endpoint_name",
       help = "Name of the scheduler endpoint published in ZooKeeper.")
   private static final Arg<String> SERVERSET_ENDPOINT_NAME = Arg.create("http");
@@ -111,6 +113,15 @@ public class SchedulerMain {
   @CmdLine(name = "mesos_driver", help = "Which Mesos Driver to use")
   private static final Arg<DriverKind> DRIVER_IMPL = Arg.create(DriverKind.SCHEDULER_DRIVER);
 
+  public static class ProtocolModule extends AbstractModule {
+    @Override
+    protected void configure() {
+      bind(String.class)
+          .annotatedWith(SchedulerProtocol.class)
+          .toInstance(SERVERSET_ENDPOINT_NAME.get());
+    }
+  }
+
   @Inject private SingletonService schedulerService;
   @Inject private HttpService httpService;
   @Inject private SchedulerLifecycle schedulerLifecycle;
@@ -157,6 +168,7 @@ public class SchedulerMain {
   @VisibleForTesting
   static Module getUniversalModule() {
     return Modules.combine(
+        new ProtocolModule(),
         new LifecycleModule(),
         new StatsModule(),
         new AppModule(ALLOW_GPU_RESOURCE.get(), DRIVER_IMPL.get()),

http://git-wip-us.apache.org/repos/asf/aurora/blob/5bffe8f6/src/main/java/org/apache/aurora/scheduler/mesos/CommandLineDriverSettingsModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/mesos/CommandLineDriverSettingsModule.java
b/src/main/java/org/apache/aurora/scheduler/mesos/CommandLineDriverSettingsModule.java
index ad6110a..97d3c20 100644
--- a/src/main/java/org/apache/aurora/scheduler/mesos/CommandLineDriverSettingsModule.java
+++ b/src/main/java/org/apache/aurora/scheduler/mesos/CommandLineDriverSettingsModule.java
@@ -19,6 +19,7 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Properties;
+import javax.inject.Singleton;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Optional;
@@ -116,7 +117,10 @@ public class CommandLineDriverSettingsModule extends AbstractModule {
         MESOS_ROLE.hasAppliedValue() ? Optional.of(MESOS_ROLE.get()) : Optional.absent();
     DriverSettings settings = new DriverSettings(
         MESOS_MASTER_ADDRESS.get(),
-        credentials,
+        credentials);
+    bind(DriverSettings.class).toInstance(settings);
+
+    FrameworkInfo base =
         buildFrameworkInfo(
             FRAMEWORK_NAME.get(),
             EXECUTOR_USER.get(),
@@ -124,8 +128,13 @@ public class CommandLineDriverSettingsModule extends AbstractModule {
             FRAMEWORK_FAILOVER_TIMEOUT.get(),
             RECEIVE_REVOCABLE_RESOURCES.get(),
             allowGpuResource,
-            role));
-    bind(DriverSettings.class).toInstance(settings);
+            role);
+    bind(FrameworkInfo.class)
+        .annotatedWith(FrameworkInfoFactory.FrameworkInfoFactoryImpl.BaseFrameworkInfo.class)
+        .toInstance(base);
+    bind(FrameworkInfoFactory.class).to(FrameworkInfoFactory.FrameworkInfoFactoryImpl.class);
+    bind(FrameworkInfoFactory.FrameworkInfoFactoryImpl.class).in(Singleton.class);
+
   }
 
   private static Optional<Protos.Credential> getCredentials() {

http://git-wip-us.apache.org/repos/asf/aurora/blob/5bffe8f6/src/main/java/org/apache/aurora/scheduler/mesos/DriverSettings.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/mesos/DriverSettings.java b/src/main/java/org/apache/aurora/scheduler/mesos/DriverSettings.java
index f477404..39c0144 100644
--- a/src/main/java/org/apache/aurora/scheduler/mesos/DriverSettings.java
+++ b/src/main/java/org/apache/aurora/scheduler/mesos/DriverSettings.java
@@ -27,16 +27,13 @@ import static java.util.Objects.requireNonNull;
 public class DriverSettings {
   private final String masterUri;
   private final Optional<Protos.Credential> credentials;
-  private final Protos.FrameworkInfo frameworkInfo;
 
   public DriverSettings(
       String masterUri,
-      Optional<Protos.Credential> credentials,
-      Protos.FrameworkInfo frameworkInfo) {
+      Optional<Protos.Credential> credentials) {
 
     this.masterUri = requireNonNull(masterUri);
     this.credentials = requireNonNull(credentials);
-    this.frameworkInfo = requireNonNull(frameworkInfo);
   }
 
   public String getMasterUri() {
@@ -46,8 +43,4 @@ public class DriverSettings {
   public Optional<Protos.Credential> getCredentials() {
     return credentials;
   }
-
-  public Protos.FrameworkInfo getFrameworkInfo() {
-    return frameworkInfo;
-  }
 }

http://git-wip-us.apache.org/repos/asf/aurora/blob/5bffe8f6/src/main/java/org/apache/aurora/scheduler/mesos/FrameworkInfoFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/mesos/FrameworkInfoFactory.java b/src/main/java/org/apache/aurora/scheduler/mesos/FrameworkInfoFactory.java
new file mode 100644
index 0000000..8ad9d21
--- /dev/null
+++ b/src/main/java/org/apache/aurora/scheduler/mesos/FrameworkInfoFactory.java
@@ -0,0 +1,90 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aurora.scheduler.mesos;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import java.net.MalformedURLException;
+import java.net.URL;
+import javax.inject.Inject;
+import javax.inject.Qualifier;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.net.HostAndPort;
+
+import org.apache.aurora.scheduler.http.HttpService;
+import org.apache.mesos.v1.Protos.FrameworkInfo;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static java.util.Objects.requireNonNull;
+
+public interface FrameworkInfoFactory {
+  /**
+   * Creates the FrameworkInfo for Mesos.
+   */
+  FrameworkInfo getFrameworkInfo();
+
+  class FrameworkInfoFactoryImpl implements FrameworkInfoFactory {
+    /**
+     * Binding annotation for the base FrameworkInfo.
+     */
+    @VisibleForTesting
+    @Qualifier
+    @Target({ FIELD, PARAMETER, METHOD }) @Retention(RUNTIME)
+    public @interface BaseFrameworkInfo { }
+
+    /**
+     * Annotation for the protocol to advertise.
+     */
+    @Qualifier
+    @Target({ FIELD, PARAMETER, METHOD }) @Retention(RUNTIME)
+    public @interface SchedulerProtocol { }
+
+    private final FrameworkInfo baseInfo;
+    private final HttpService service;
+    private final String protocol;
+
+    @Inject
+    public FrameworkInfoFactoryImpl(
+        @BaseFrameworkInfo FrameworkInfo base,
+        HttpService service,
+        @SchedulerProtocol String protocol) {
+
+      this.baseInfo = requireNonNull(base);
+      this.service = requireNonNull(service);
+      this.protocol = requireNonNull(protocol);
+    }
+
+    @Override
+    public FrameworkInfo getFrameworkInfo() {
+      HostAndPort hostAndPort = service.getAddress();
+      URL url;
+      try {
+        url = new URL(protocol, hostAndPort.getHost(), hostAndPort.getPort(), "");
+      } catch (MalformedURLException e) {
+        throw new RuntimeException(e);
+      }
+
+      FrameworkInfo.Builder info = baseInfo.toBuilder();
+
+      info.setHostname(hostAndPort.getHost());
+      info.setWebuiUrl(url.toString());
+
+      return info.build();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/aurora/blob/5bffe8f6/src/main/java/org/apache/aurora/scheduler/mesos/SchedulerDriverService.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/mesos/SchedulerDriverService.java b/src/main/java/org/apache/aurora/scheduler/mesos/SchedulerDriverService.java
index f65a29d..4a604f5 100644
--- a/src/main/java/org/apache/aurora/scheduler/mesos/SchedulerDriverService.java
+++ b/src/main/java/org/apache/aurora/scheduler/mesos/SchedulerDriverService.java
@@ -54,6 +54,7 @@ class SchedulerDriverService extends AbstractIdleService implements Driver
{
 
   private final AtomicLong killFailures = Stats.exportLong("scheduler_driver_kill_failures");
   private final DriverFactory driverFactory;
+  private final FrameworkInfoFactory infoFactory;
 
   private final Scheduler scheduler;
   private final Storage storage;
@@ -65,12 +66,14 @@ class SchedulerDriverService extends AbstractIdleService implements Driver
{
       Scheduler scheduler,
       Storage storage,
       DriverSettings driverSettings,
-      DriverFactory driverFactory) {
+      DriverFactory driverFactory,
+      FrameworkInfoFactory infoFactory) {
 
     this.scheduler = requireNonNull(scheduler);
     this.storage = requireNonNull(storage);
     this.driverSettings = requireNonNull(driverSettings);
     this.driverFactory = requireNonNull(driverFactory);
+    this.infoFactory = requireNonNull(infoFactory);
   }
 
   @Override
@@ -83,7 +86,7 @@ class SchedulerDriverService extends AbstractIdleService implements Driver
{
       LOG.warn("Connecting to master without authentication!");
     }
 
-    Protos.FrameworkInfo.Builder frameworkBuilder = driverSettings.getFrameworkInfo().toBuilder();
+    Protos.FrameworkInfo.Builder frameworkBuilder = infoFactory.getFrameworkInfo().toBuilder();
 
     if (frameworkId.isPresent()) {
       LOG.info("Found persisted framework ID: " + frameworkId);

http://git-wip-us.apache.org/repos/asf/aurora/blob/5bffe8f6/src/main/java/org/apache/aurora/scheduler/mesos/VersionedMesosSchedulerImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/mesos/VersionedMesosSchedulerImpl.java
b/src/main/java/org/apache/aurora/scheduler/mesos/VersionedMesosSchedulerImpl.java
index 84e3f47..a519c7d 100644
--- a/src/main/java/org/apache/aurora/scheduler/mesos/VersionedMesosSchedulerImpl.java
+++ b/src/main/java/org/apache/aurora/scheduler/mesos/VersionedMesosSchedulerImpl.java
@@ -47,7 +47,7 @@ public class VersionedMesosSchedulerImpl implements Scheduler {
   private final CachedCounters counters;
   private final MesosCallbackHandler handler;
   private final Storage storage;
-  private final DriverSettings settings;
+  private final FrameworkInfoFactory infoFactory;
 
   private volatile boolean isRegistered = false;
 
@@ -68,11 +68,11 @@ public class VersionedMesosSchedulerImpl implements Scheduler {
       MesosCallbackHandler handler,
       CachedCounters counters,
       Storage storage,
-      DriverSettings settings) {
+      FrameworkInfoFactory factory) {
     this.handler = requireNonNull(handler);
     this.counters = requireNonNull(counters);
     this.storage = requireNonNull(storage);
-    this.settings = requireNonNull(settings);
+    this.infoFactory = requireNonNull(factory);
     initializeEventMetrics();
   }
 
@@ -83,7 +83,7 @@ public class VersionedMesosSchedulerImpl implements Scheduler {
     Optional<String> frameworkId = storage.read(
         storeProvider -> storeProvider.getSchedulerStore().fetchFrameworkId());
 
-    Protos.FrameworkInfo.Builder frameworkBuilder = settings.getFrameworkInfo().toBuilder();
+    Protos.FrameworkInfo.Builder frameworkBuilder = infoFactory.getFrameworkInfo().toBuilder();
 
     Call.Builder call = Call.newBuilder().setType(Call.Type.SUBSCRIBE);
 

http://git-wip-us.apache.org/repos/asf/aurora/blob/5bffe8f6/src/main/java/org/apache/aurora/scheduler/mesos/VersionedSchedulerDriverService.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/mesos/VersionedSchedulerDriverService.java
b/src/main/java/org/apache/aurora/scheduler/mesos/VersionedSchedulerDriverService.java
index d928d02..f1326ea 100644
--- a/src/main/java/org/apache/aurora/scheduler/mesos/VersionedSchedulerDriverService.java
+++ b/src/main/java/org/apache/aurora/scheduler/mesos/VersionedSchedulerDriverService.java
@@ -57,6 +57,7 @@ class VersionedSchedulerDriverService extends AbstractIdleService
   private final DriverSettings driverSettings;
   private final Scheduler scheduler;
   private final VersionedDriverFactory factory;
+  private final FrameworkInfoFactory infoFactory;
   private final SettableFuture<Mesos> mesosFuture = SettableFuture.create();
   private final CountDownLatch terminationLatch = new CountDownLatch(1);
   private final CountDownLatch registrationLatch = new CountDownLatch(1);
@@ -66,11 +67,13 @@ class VersionedSchedulerDriverService extends AbstractIdleService
       Storage storage,
       DriverSettings settings,
       Scheduler scheduler,
-      VersionedDriverFactory factory) {
+      VersionedDriverFactory factory,
+      FrameworkInfoFactory infoFactory) {
     this.storage = requireNonNull(storage);
     this.driverSettings = requireNonNull(settings);
     this.scheduler = requireNonNull(scheduler);
     this.factory = requireNonNull(factory);
+    this.infoFactory = requireNonNull(infoFactory);
   }
 
   private FrameworkID getFrameworkId() {
@@ -89,7 +92,7 @@ class VersionedSchedulerDriverService extends AbstractIdleService
       LOG.warn("Connecting to master without authentication!");
     }
 
-    FrameworkInfo.Builder frameworkBuilder = driverSettings.getFrameworkInfo().toBuilder();
+    FrameworkInfo.Builder frameworkBuilder = infoFactory.getFrameworkInfo().toBuilder();
 
     if (frameworkId.isPresent()) {
       LOG.info("Found persisted framework ID: " + frameworkId);

http://git-wip-us.apache.org/repos/asf/aurora/blob/5bffe8f6/src/test/java/org/apache/aurora/scheduler/app/SchedulerIT.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/app/SchedulerIT.java b/src/test/java/org/apache/aurora/scheduler/app/SchedulerIT.java
index f579975..a7c9c83 100644
--- a/src/test/java/org/apache/aurora/scheduler/app/SchedulerIT.java
+++ b/src/test/java/org/apache/aurora/scheduler/app/SchedulerIT.java
@@ -72,6 +72,7 @@ import org.apache.aurora.scheduler.log.Log.Position;
 import org.apache.aurora.scheduler.log.Log.Stream;
 import org.apache.aurora.scheduler.mesos.DriverFactory;
 import org.apache.aurora.scheduler.mesos.DriverSettings;
+import org.apache.aurora.scheduler.mesos.FrameworkInfoFactory;
 import org.apache.aurora.scheduler.mesos.TestExecutorSettings;
 import org.apache.aurora.scheduler.storage.backup.BackupModule;
 import org.apache.aurora.scheduler.storage.entities.IHostAttributes;
@@ -127,13 +128,14 @@ public class SchedulerIT extends BaseZooKeeperClientTest {
       .setMode(MaintenanceMode.NONE)
       .setAttributes(ImmutableSet.of()));
 
-  private static final DriverSettings SETTINGS = new DriverSettings(
-      "fakemaster",
-      Optional.absent(),
-      FrameworkInfo.newBuilder()
+  private static final FrameworkInfo BASE_INFO = FrameworkInfo.newBuilder()
           .setUser("framework user")
           .setName("test framework")
-          .build());
+          .build();
+
+  private static final DriverSettings SETTINGS = new DriverSettings(
+      "fakemaster",
+      Optional.absent());
 
   private final ExecutorService executor = Executors.newCachedThreadPool(
       new ThreadFactoryBuilder().setNameFormat("SchedulerIT-%d").setDaemon(true).build());
@@ -187,6 +189,7 @@ public class SchedulerIT extends BaseZooKeeperClientTest {
       @Override
       protected void configure() {
         bind(DriverFactory.class).toInstance(driverFactory);
+        bind(FrameworkInfoFactory.class).toInstance(() -> BASE_INFO);
         bind(DriverSettings.class).toInstance(SETTINGS);
         bind(Log.class).toInstance(log);
         Set<Resource> overhead = ImmutableSet.of(
@@ -299,7 +302,7 @@ public class SchedulerIT extends BaseZooKeeperClientTest {
     expect(driverFactory.create(
         capture(scheduler),
         eq(SETTINGS.getCredentials()),
-        eq(SETTINGS.getFrameworkInfo()),
+        eq(BASE_INFO),
         eq(SETTINGS.getMasterUri())))
         .andReturn(driver).anyTimes();
 

http://git-wip-us.apache.org/repos/asf/aurora/blob/5bffe8f6/src/test/java/org/apache/aurora/scheduler/app/local/LocalSchedulerMain.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/app/local/LocalSchedulerMain.java b/src/test/java/org/apache/aurora/scheduler/app/local/LocalSchedulerMain.java
index 7151b81..7a342bd 100644
--- a/src/test/java/org/apache/aurora/scheduler/app/local/LocalSchedulerMain.java
+++ b/src/test/java/org/apache/aurora/scheduler/app/local/LocalSchedulerMain.java
@@ -32,6 +32,7 @@ import org.apache.aurora.scheduler.app.SchedulerMain;
 import org.apache.aurora.scheduler.app.local.simulator.ClusterSimulatorModule;
 import org.apache.aurora.scheduler.mesos.DriverFactory;
 import org.apache.aurora.scheduler.mesos.DriverSettings;
+import org.apache.aurora.scheduler.mesos.FrameworkInfoFactory;
 import org.apache.aurora.scheduler.storage.DistributedSnapshotStore;
 import org.apache.aurora.scheduler.storage.Storage;
 import org.apache.aurora.scheduler.storage.Storage.NonVolatileStorage;
@@ -48,13 +49,13 @@ public final class LocalSchedulerMain {
     // Utility class.
   }
 
-  private static final DriverSettings DRIVER_SETTINGS = new DriverSettings(
-      "fakemaster",
-      Optional.absent(),
-      Protos.FrameworkInfo.newBuilder()
+  private static final Protos.FrameworkInfo BASE_FRAMEWORK_INFO = Protos.FrameworkInfo.newBuilder()
           .setUser("framework user")
           .setName("test framework")
-          .build());
+          .build();
+  private static final DriverSettings DRIVER_SETTINGS = new DriverSettings(
+      "fakemaster",
+      Optional.absent());
 
   public static void main(String[] args) {
     File backupDir = Files.createTempDir();
@@ -96,6 +97,11 @@ public final class LocalSchedulerMain {
         bind(SchedulerDriver.class).to(FakeMaster.class);
         bind(DriverFactory.class).to(FakeMaster.class);
         bind(FakeMaster.class).in(Singleton.class);
+        bind(Protos.FrameworkInfo.class)
+            .annotatedWith(FrameworkInfoFactory.FrameworkInfoFactoryImpl.BaseFrameworkInfo.class)
+            .toInstance(BASE_FRAMEWORK_INFO);
+        bind(FrameworkInfoFactory.class).to(FrameworkInfoFactory.FrameworkInfoFactoryImpl.class);
+        bind(FrameworkInfoFactory.FrameworkInfoFactoryImpl.class).in(Singleton.class);
         install(new ClusterSimulatorModule());
       }
     };

http://git-wip-us.apache.org/repos/asf/aurora/blob/5bffe8f6/src/test/java/org/apache/aurora/scheduler/mesos/FrameworkInfoFactoryImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/mesos/FrameworkInfoFactoryImplTest.java
b/src/test/java/org/apache/aurora/scheduler/mesos/FrameworkInfoFactoryImplTest.java
new file mode 100644
index 0000000..b22f047
--- /dev/null
+++ b/src/test/java/org/apache/aurora/scheduler/mesos/FrameworkInfoFactoryImplTest.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.aurora.scheduler.mesos;
+
+import com.google.common.net.HostAndPort;
+
+import org.apache.aurora.common.testing.easymock.EasyMockTest;
+import org.apache.aurora.scheduler.http.HttpService;
+import org.apache.mesos.v1.Protos;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.easymock.EasyMock.expect;
+import static org.junit.Assert.assertEquals;
+
+public class FrameworkInfoFactoryImplTest extends EasyMockTest {
+  private static final Protos.FrameworkInfo INFO = Protos.FrameworkInfo.newBuilder()
+      .setId(Protos.FrameworkID.newBuilder().setValue("framework-id"))
+      .setName("name")
+      .setFailoverTimeout(100)
+      .setUser("user")
+      .build();
+
+  private HttpService service;
+  private FrameworkInfoFactory factory;
+
+  @Before
+  public void setUp() {
+    service = createMock(HttpService.class);
+    factory = new FrameworkInfoFactory.FrameworkInfoFactoryImpl(INFO, service, "http");
+  }
+
+  @Test
+  public void testHostnameAndURLAdded() {
+    expect(service.getAddress()).andReturn(HostAndPort.fromParts("hostname", 80));
+
+    control.replay();
+    Protos.FrameworkInfo result = factory.getFrameworkInfo();
+
+    assertEquals(result.getHostname(), "hostname");
+    assertEquals(result.getWebuiUrl(), "http://hostname:80");
+  }
+}

http://git-wip-us.apache.org/repos/asf/aurora/blob/5bffe8f6/src/test/java/org/apache/aurora/scheduler/mesos/SchedulerDriverServiceTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/mesos/SchedulerDriverServiceTest.java
b/src/test/java/org/apache/aurora/scheduler/mesos/SchedulerDriverServiceTest.java
index 38e9135..be6e481 100644
--- a/src/test/java/org/apache/aurora/scheduler/mesos/SchedulerDriverServiceTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/mesos/SchedulerDriverServiceTest.java
@@ -34,13 +34,13 @@ public class SchedulerDriverServiceTest extends EasyMockTest {
   private static final Optional<String> FRAMEWORK_ID = Optional.of("test framework");
   private static final Optional<String> NEW_FRAMEWORK_ID = Optional.absent();
 
-  private static final DriverSettings SETTINGS = new DriverSettings(
-      "fakemaster",
-      Optional.absent(),
-      FrameworkInfo.newBuilder()
+  private static final FrameworkInfo BASE_INFO = FrameworkInfo.newBuilder()
           .setUser("framework user")
           .setName("test framework")
-          .build());
+          .build();
+  private static final DriverSettings SETTINGS = new DriverSettings(
+      "fakemaster",
+      Optional.absent());
 
   private static final String TASK_1 = "1";
   private static final String TASK_2 = "2";
@@ -50,6 +50,7 @@ public class SchedulerDriverServiceTest extends EasyMockTest {
   private DriverFactory driverFactory;
   private Driver driverService;
   private SchedulerDriver schedulerDriver;
+  private FrameworkInfoFactory infoFactory;
 
   private static TaskID createTaskId(String taskId) {
     return TaskID.newBuilder().setValue(taskId).build();
@@ -61,7 +62,13 @@ public class SchedulerDriverServiceTest extends EasyMockTest {
     storage = new StorageTestUtil(this);
     driverFactory = createMock(DriverFactory.class);
     schedulerDriver = createMock(SchedulerDriver.class);
-    driverService = new SchedulerDriverService(scheduler, storage.storage, SETTINGS, driverFactory);
+    infoFactory = createMock(FrameworkInfoFactory.class);
+    driverService = new SchedulerDriverService(
+        scheduler,
+        storage.storage,
+        SETTINGS,
+        driverFactory,
+        infoFactory);
   }
 
   @Test
@@ -134,8 +141,9 @@ public class SchedulerDriverServiceTest extends EasyMockTest {
   private void expectCreateDriver(Optional<String> frameworkId) {
     storage.expectOperations();
     expect(storage.schedulerStore.fetchFrameworkId()).andReturn(frameworkId);
+    expect(infoFactory.getFrameworkInfo()).andReturn(BASE_INFO);
 
-    FrameworkInfo.Builder builder = SETTINGS.getFrameworkInfo().toBuilder();
+    FrameworkInfo.Builder builder = BASE_INFO.toBuilder();
     if (frameworkId.isPresent()) {
       builder.setId(FrameworkID.newBuilder().setValue(frameworkId.get()));
     }

http://git-wip-us.apache.org/repos/asf/aurora/blob/5bffe8f6/src/test/java/org/apache/aurora/scheduler/mesos/VersionedMesosSchedulerImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/mesos/VersionedMesosSchedulerImplTest.java
b/src/test/java/org/apache/aurora/scheduler/mesos/VersionedMesosSchedulerImplTest.java
index 988ec50..756d0d9 100644
--- a/src/test/java/org/apache/aurora/scheduler/mesos/VersionedMesosSchedulerImplTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/mesos/VersionedMesosSchedulerImplTest.java
@@ -52,7 +52,7 @@ public class VersionedMesosSchedulerImplTest extends EasyMockTest {
   private StorageTestUtil storageUtil;
   private Mesos driver;
   private FakeStatsProvider statsProvider;
-  private DriverSettings driverSettings;
+  private FrameworkInfoFactory infoFactory;
 
   private VersionedMesosSchedulerImpl scheduler;
 
@@ -144,13 +144,13 @@ public class VersionedMesosSchedulerImplTest extends EasyMockTest {
     storageUtil = new StorageTestUtil(this);
     driver = createMock(Mesos.class);
     statsProvider = new FakeStatsProvider();
-    driverSettings = createMock(DriverSettings.class);
+    infoFactory = createMock(FrameworkInfoFactory.class);
 
     scheduler = new VersionedMesosSchedulerImpl(
         handler,
         new CachedCounters(statsProvider),
         storageUtil.storage,
-        driverSettings);
+        infoFactory);
   }
 
   @Test
@@ -159,7 +159,7 @@ public class VersionedMesosSchedulerImplTest extends EasyMockTest {
 
     storageUtil.expectOperations();
     expect(storageUtil.schedulerStore.fetchFrameworkId()).andReturn(Optional.of(FRAMEWORK_ID));
-    expect(driverSettings.getFrameworkInfo()).andReturn(FRAMEWORK_INFO);
+    expect(infoFactory.getFrameworkInfo()).andReturn(FRAMEWORK_INFO);
 
     Capture<Call> subscribeCapture = createCapture();
 

http://git-wip-us.apache.org/repos/asf/aurora/blob/5bffe8f6/src/test/java/org/apache/aurora/scheduler/mesos/VersionedSchedulerDriverServiceTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/mesos/VersionedSchedulerDriverServiceTest.java
b/src/test/java/org/apache/aurora/scheduler/mesos/VersionedSchedulerDriverServiceTest.java
index 72aede8..a6c28bb 100644
--- a/src/test/java/org/apache/aurora/scheduler/mesos/VersionedSchedulerDriverServiceTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/mesos/VersionedSchedulerDriverServiceTest.java
@@ -40,18 +40,19 @@ public class VersionedSchedulerDriverServiceTest extends EasyMockTest
{
       Protos.OfferID.newBuilder().setValue("offer-id").build();
   private static final Protos.Filters FILTER =
       Protos.Filters.newBuilder().setRefuseSeconds(10).build();
-  private static final DriverSettings SETTINGS = new DriverSettings(
-      "fakemaster",
-      Optional.absent(),
-      Protos.FrameworkInfo.newBuilder()
+  private static final Protos.FrameworkInfo BASE_INFO = Protos.FrameworkInfo.newBuilder()
           .setUser("framework user")
           .setName("test framework")
-          .build());
+          .build();
+  private static final DriverSettings SETTINGS = new DriverSettings(
+      "fakemaster",
+      Optional.absent());
 
   private StorageTestUtil storage;
   private Scheduler scheduler;
   private VersionedSchedulerDriverService driverService;
   private VersionedDriverFactory driverFactory;
+  private FrameworkInfoFactory infoFactory;
   private Mesos mesos;
 
   @Before
@@ -60,11 +61,13 @@ public class VersionedSchedulerDriverServiceTest extends EasyMockTest
{
     storage = new StorageTestUtil(this);
     driverFactory = createMock(VersionedDriverFactory.class);
     mesos = createMock(Mesos.class);
+    infoFactory = createMock(FrameworkInfoFactory.class);
     driverService = new VersionedSchedulerDriverService(
         storage.storage,
         SETTINGS,
         scheduler,
-        driverFactory);
+        driverFactory,
+        infoFactory);
   }
 
   @Test
@@ -180,8 +183,9 @@ public class VersionedSchedulerDriverServiceTest extends EasyMockTest
{
   private void expectStart() {
     storage.expectOperations();
     expect(storage.schedulerStore.fetchFrameworkId()).andReturn(Optional.of(FRAMEWORK_ID));
+    expect(infoFactory.getFrameworkInfo()).andReturn(BASE_INFO);
 
-    Protos.FrameworkInfo.Builder builder = SETTINGS.getFrameworkInfo().toBuilder();
+    Protos.FrameworkInfo.Builder builder = BASE_INFO.toBuilder();
     builder.setId(Protos.FrameworkID.newBuilder().setValue(FRAMEWORK_ID));
 
     expect(driverFactory.create(

http://git-wip-us.apache.org/repos/asf/aurora/blob/5bffe8f6/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java b/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
index 1421821..6b4b17f 100644
--- a/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
+++ b/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
@@ -14,6 +14,7 @@
 package org.apache.aurora.scheduler.thrift;
 
 import java.util.Optional;
+import javax.inject.Singleton;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMultimap;
@@ -42,6 +43,7 @@ import org.apache.aurora.gen.TaskQuery;
 import org.apache.aurora.scheduler.TierModule;
 import org.apache.aurora.scheduler.app.AppModule;
 import org.apache.aurora.scheduler.app.LifecycleModule;
+import org.apache.aurora.scheduler.app.SchedulerMain;
 import org.apache.aurora.scheduler.app.ServiceGroupMonitor;
 import org.apache.aurora.scheduler.app.local.FakeNonVolatileStorage;
 import org.apache.aurora.scheduler.base.TaskTestUtil;
@@ -50,6 +52,9 @@ import org.apache.aurora.scheduler.configuration.executor.ExecutorSettings;
 import org.apache.aurora.scheduler.cron.quartz.CronModule;
 import org.apache.aurora.scheduler.mesos.DriverFactory;
 import org.apache.aurora.scheduler.mesos.DriverSettings;
+import org.apache.aurora.scheduler.mesos.FrameworkInfoFactory;
+import org.apache.aurora.scheduler.mesos.FrameworkInfoFactory.FrameworkInfoFactoryImpl;
+import org.apache.aurora.scheduler.mesos.FrameworkInfoFactory.FrameworkInfoFactoryImpl.BaseFrameworkInfo;
 import org.apache.aurora.scheduler.mesos.TestExecutorSettings;
 import org.apache.aurora.scheduler.quota.QuotaModule;
 import org.apache.aurora.scheduler.resources.ResourceTestUtil;
@@ -99,20 +104,27 @@ public class ThriftIT extends EasyMockTest {
             bind(ExecutorSettings.class).toInstance(TestExecutorSettings.THERMOS_EXECUTOR);
 
             install(new AppModule(configurationManagerSettings, SCHEDULER_DRIVER));
+            install(new SchedulerMain.ProtocolModule());
 
             bind(NonVolatileStorage.class).to(FakeNonVolatileStorage.class);
 
             ServiceGroupMonitor schedulers = createMock(ServiceGroupMonitor.class);
             bind(ServiceGroupMonitor.class).toInstance(schedulers);
 
+            FrameworkInfo base = FrameworkInfo.newBuilder()
+                    .setUser("framework user")
+                    .setName("test framework")
+                    .build();
+
             bindMock(DriverFactory.class);
             bind(DriverSettings.class).toInstance(new DriverSettings(
                 "fakemaster",
-                com.google.common.base.Optional.absent(),
-                FrameworkInfo.newBuilder()
-                    .setUser("framework user")
-                    .setName("test framework")
-                    .build()));
+                com.google.common.base.Optional.absent()));
+            bind(FrameworkInfo.class)
+                .annotatedWith(BaseFrameworkInfo.class)
+                .toInstance(base);
+            bind(FrameworkInfoFactory.class).to(FrameworkInfoFactoryImpl.class);
+            bind(FrameworkInfoFactoryImpl.class).in(Singleton.class);
             bindMock(Recovery.class);
             bindMock(StorageBackup.class);
             bind(IServerInfo.class).toInstance(SERVER_INFO);


Mime
View raw message