aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject git commit: Added extra_modules option to Scheduler.
Date Fri, 13 Dec 2013 00:59:14 GMT
Updated Branches:
  refs/heads/skarumuri/extra_modules [created] 201ceb469


Added extra_modules option to Scheduler.


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

Branch: refs/heads/skarumuri/extra_modules
Commit: 201ceb469f7acb053c8266827acaa6bb2b332469
Parents: cf7ee5a
Author: Suman Karumuri <skarumuri@twitter.com>
Authored: Mon Dec 9 09:33:32 2013 -0800
Committer: Suman Karumuri <skarumuri@twitter.com>
Committed: Mon Dec 9 09:33:32 2013 -0800

----------------------------------------------------------------------
 .../twitter/aurora/scheduler/app/Modules.java   | 54 +++++++++++++++++
 .../aurora/scheduler/app/SchedulerMain.java     | 61 ++++++--------------
 2 files changed, 72 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/201ceb46/src/main/java/com/twitter/aurora/scheduler/app/Modules.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/twitter/aurora/scheduler/app/Modules.java b/src/main/java/com/twitter/aurora/scheduler/app/Modules.java
new file mode 100644
index 0000000..18253b0
--- /dev/null
+++ b/src/main/java/com/twitter/aurora/scheduler/app/Modules.java
@@ -0,0 +1,54 @@
+package com.twitter.aurora.scheduler.app;
+
+import com.google.inject.Module;
+import com.google.inject.PrivateModule;
+
+/**
+ * A utility class for managing guice modules.
+ */
+final class Modules {
+
+  private Modules() {
+    // Utility class
+  }
+
+  private static Module instantiateModule(final Class<? extends Module> moduleClass)
{
+    try {
+      return moduleClass.newInstance();
+    } catch (InstantiationException e) {
+      throw new IllegalArgumentException(
+          String.format(
+              "Failed to instantiate module %s. Are you sure it has a no-arg constructor?",
+              moduleClass.getName()),
+          e);
+    } catch (IllegalAccessException e) {
+      throw new IllegalArgumentException(
+          String.format(
+              "Failed to instantiate module %s. Are you sure it's public?",
+              moduleClass.getName()),
+          e);
+    }
+  }
+
+  // Defensively wrap each module provided on the command-line in a PrivateModule that only
+  // exposes requested classes to ensure that we don't depend on surprise extra bindings
across
+  // different implementations.
+  static Module wrapInPrivateModule(
+      Class<? extends Module> moduleClass,
+      final Iterable<Class<?>> exposedClasses) {
+
+    final Module module = instantiateModule(moduleClass);
+    return new PrivateModule() {
+      @Override protected void configure() {
+        install(module);
+        for (Class<?> klass : exposedClasses) {
+          expose(klass);
+        }
+      }
+    };
+  }
+
+  static Module getModule(Class<? extends Module> moduleClass) {
+    return instantiateModule(moduleClass);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/201ceb46/src/main/java/com/twitter/aurora/scheduler/app/SchedulerMain.java
----------------------------------------------------------------------
diff --git a/src/main/java/com/twitter/aurora/scheduler/app/SchedulerMain.java b/src/main/java/com/twitter/aurora/scheduler/app/SchedulerMain.java
index 73b86a9..778472b 100644
--- a/src/main/java/com/twitter/aurora/scheduler/app/SchedulerMain.java
+++ b/src/main/java/com/twitter/aurora/scheduler/app/SchedulerMain.java
@@ -20,6 +20,7 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.net.InetSocketAddress;
+import java.util.List;
 import java.util.logging.Logger;
 
 import javax.annotation.Nonnegative;
@@ -28,9 +29,9 @@ import javax.inject.Singleton;
 
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
 import com.google.inject.AbstractModule;
 import com.google.inject.Module;
-import com.google.inject.PrivateModule;
 
 import com.twitter.aurora.auth.CapabilityValidator;
 import com.twitter.aurora.auth.SessionValidator;
@@ -136,6 +137,12 @@ public class SchedulerMain extends AbstractApplication {
       .add(JobFilter.class)
       .build();
 
+  // TODO(Suman Karumuri): Pass in AUTH, QUOTA and CRON modules as extra modules
+  @CmdLine(name = "extra_modules",
+      help = "A list of modules that provide additional functionality.")
+  private static final Arg<List<Class<? extends Module>>> EXTRA_MODULES
=
+      Arg.create((List<Class<? extends Module>>) ImmutableList.<Class<?
extends Module>>of());
+
   @Inject private SingletonService schedulerService;
   @Inject private LocalServiceRegistry serviceRegistry;
   @Inject private SchedulerLifecycle schedulerLifecycle;
@@ -149,49 +156,17 @@ public class SchedulerMain extends AbstractApplication {
     );
   }
 
-  // TODO(ksweeney): Consider factoring this out into a ModuleParser library.
-  private static Module instantiateFlaggedModule(Arg<? extends Class<? extends Module>>
moduleArg) {
-    Class<? extends Module> moduleClass = moduleArg.get();
-    try {
-      return moduleClass.newInstance();
-    } catch (InstantiationException e) {
-      throw new IllegalArgumentException(
-          String.format(
-              "Failed to instantiate module %s. Are you sure it has a no-arg constructor?",
-              moduleClass.getName()),
-          e);
-    } catch (IllegalAccessException e) {
-      throw new IllegalArgumentException(
-          String.format(
-              "Failed to instantiate module %s. Are you sure it's public?",
-              moduleClass.getName()),
-          e);
-    }
-  }
-
-  // Defensively wrap each module provided on the command-line in a PrivateModule that only
-  // exposes requested classes to ensure that we don't depend on surprise extra bindings
across
-  // different implementations.
-  private static Module getFlaggedModule(
-      Arg<? extends Class<? extends Module>> moduleArg,
-      final Iterable<Class<?>> exposedClasses) {
+  private static Iterable<? extends Module> getExtraModules() {
+    Builder<Module> modules = ImmutableList.builder();
+    modules.add(Modules.wrapInPrivateModule(AUTH_MODULE.get(), AUTH_MODULE_CLASSES))
+        .add(Modules.wrapInPrivateModule(CRON_MODULE.get(), CRON_MODULE_CLASSES)).
+        add(Modules.wrapInPrivateModule(QUOTA_MODULE.get(), QUOTA_MODULE_CLASSES));
 
-    final Module module = instantiateFlaggedModule(moduleArg);
-    return new PrivateModule() {
-      @Override protected void configure() {
-        install(module);
-        for (Class<?> klass : exposedClasses) {
-          expose(klass);
-        }
-      }
-    };
-  }
+    for (Class<? extends Module> moduleClass : EXTRA_MODULES.get()) {
+      modules.add(Modules.getModule(moduleClass));
+    }
 
-  private static Iterable<? extends Module> getFlaggedModules() {
-    return ImmutableList.of(
-        getFlaggedModule(AUTH_MODULE, AUTH_MODULE_CLASSES),
-        getFlaggedModule(CRON_MODULE, CRON_MODULE_CLASSES),
-        getFlaggedModule(QUOTA_MODULE, QUOTA_MODULE_CLASSES));
+    return modules.build();
   }
 
   static Iterable<? extends Module> getModules(
@@ -200,9 +175,9 @@ public class SchedulerMain extends AbstractApplication {
       ClientConfig zkClientConfig) {
 
     return ImmutableList.<Module>builder()
-        .addAll(getFlaggedModules())
         .addAll(getSystemModules())
         .add(new AppModule(clusterName, serverSetPath, zkClientConfig))
+        .addAll(getExtraModules())
         .add(new LogStorageModule())
         .add(new MemStorageModule(Bindings.annotatedKeyFactory(LogStorage.WriteBehind.class)))
         .add(new ThriftModule())


Mime
View raw message