You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2016/02/09 20:18:11 UTC

[3/4] mesos git commit: Modified `TestContainerizer` to handle HTTP based executors.

Modified `TestContainerizer` to handle HTTP based executors.

This change modifies the `TestContainerizer` class to handle HTTP based
executors. Previously, the containerizer test class only used to handle the
driver interface.

Review: https://reviews.apache.org/r/41290/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/37bb5ebc
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/37bb5ebc
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/37bb5ebc

Branch: refs/heads/master
Commit: 37bb5ebc7c181b35afd24a2cf55df68f63916fb5
Parents: 97d3527
Author: Anand Mazumdar <ma...@gmail.com>
Authored: Tue Feb 9 11:17:37 2016 -0800
Committer: Vinod Kone <vi...@gmail.com>
Committed: Tue Feb 9 11:17:37 2016 -0800

----------------------------------------------------------------------
 src/tests/containerizer.cpp | 43 ++++++++++++++++++++++++++++++++--------
 src/tests/containerizer.hpp | 11 ++++++++++
 2 files changed, 46 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/37bb5ebc/src/tests/containerizer.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer.cpp b/src/tests/containerizer.cpp
index 15c8b19..c6772ce 100644
--- a/src/tests/containerizer.cpp
+++ b/src/tests/containerizer.cpp
@@ -23,6 +23,7 @@
 #include "tests/mesos.hpp"
 
 using std::map;
+using std::shared_ptr;
 using std::string;
 
 using testing::_;
@@ -31,12 +32,23 @@ using testing::Return;
 
 using namespace process;
 
+using mesos::v1::executor::Mesos;
+
 namespace mesos {
 namespace internal {
 namespace tests {
 
 
 TestContainerizer::TestContainerizer(
+    const ExecutorID& executorId,
+    const shared_ptr<MockV1HTTPExecutor>& executor)
+{
+  v1Executors[executorId] = executor;
+  setup();
+}
+
+
+TestContainerizer::TestContainerizer(
     const hashmap<ExecutorID, Executor*>& _executors)
   : executors(_executors)
 {
@@ -90,7 +102,8 @@ Future<bool> TestContainerizer::_launch(
     << "' of framework " << executorInfo.framework_id()
     << " because it is already launched";
 
-  CHECK(executors.contains(executorInfo.executor_id()))
+  CHECK(executors.contains(executorInfo.executor_id()) ||
+        v1Executors.contains(executorInfo.executor_id()))
     << "Failed to launch executor '" << executorInfo.executor_id()
     << "' of framework " << executorInfo.framework_id()
     << " because it is unknown to the containerizer";
@@ -101,8 +114,6 @@ Future<bool> TestContainerizer::_launch(
                                          executorInfo.executor_id());
   containers_[key] = containerId;
 
-  Executor* executor = executors[executorInfo.executor_id()];
-
   // We need to synchronize all reads and writes to the environment as this is
   // global state.
   // TODO(jmlvanre): Even this is not sufficient, as other aspects of the code
@@ -115,9 +126,6 @@ Future<bool> TestContainerizer::_launch(
     // Since the constructor for `MesosExecutorDriver` reads environment
     // variables to load flags, even it needs to be within this synchronization
     // section.
-    Owned<MesosExecutorDriver> driver(new MesosExecutorDriver(executor));
-    drivers[containerId] = driver;
-
     // Prepare additional environment variables for the executor.
     // TODO(benh): Need to get flags passed into the TestContainerizer
     // in order to properly use here.
@@ -145,13 +153,28 @@ Future<bool> TestContainerizer::_launch(
     // code where we do this as well and it's likely we can do this once
     // in 'executorEnvironment()'.
     foreach (const Environment::Variable& variable,
-            executorInfo.command().environment().variables()) {
+             executorInfo.command().environment().variables()) {
       os::setenv(variable.name(), variable.value());
     }
 
     os::setenv("MESOS_LOCAL", "1");
 
-    driver->start();
+    if (executors.contains(executorInfo.executor_id())) {
+      Executor* executor = executors[executorInfo.executor_id()];
+
+      Owned<MesosExecutorDriver> driver(new MesosExecutorDriver(executor));
+      drivers[containerId] = driver;
+
+      driver->start();
+    } else {
+      shared_ptr<MockV1HTTPExecutor> executor =
+        v1Executors[executorInfo.executor_id()];
+
+      Owned<executor::TestV1Mesos> mesos(
+          new executor::TestV1Mesos(ContentType::PROTOBUF, executor));
+
+      v1Libraries[containerId] = mesos;
+    }
 
     os::unsetenv("MESOS_LOCAL");
 
@@ -234,6 +257,10 @@ void TestContainerizer::destroy(const ContainerID& containerId)
     drivers.erase(containerId);
   }
 
+  if (v1Libraries.contains(containerId)) {
+    v1Libraries.erase(containerId);
+  }
+
   if (promises.contains(containerId)) {
     containerizer::Termination termination;
     termination.set_message("Killed executor");

http://git-wip-us.apache.org/repos/asf/mesos/blob/37bb5ebc/src/tests/containerizer.hpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer.hpp b/src/tests/containerizer.hpp
index bd9ee2c..67fbe7f 100644
--- a/src/tests/containerizer.hpp
+++ b/src/tests/containerizer.hpp
@@ -20,6 +20,7 @@
 #include <unistd.h>
 
 #include <map>
+#include <memory>
 #include <string>
 
 #include <mesos/executor.hpp>
@@ -27,6 +28,8 @@
 #include <mesos/resources.hpp>
 #include <mesos/type_utils.hpp>
 
+#include <mesos/v1/executor.hpp>
+
 #include <process/dispatch.hpp>
 #include <process/future.hpp>
 #include <process/gmock.hpp>
@@ -42,6 +45,8 @@
 #include "slave/slave.hpp"
 #include "slave/state.hpp"
 
+#include "tests/mesos.hpp"
+
 namespace mesos {
 namespace internal {
 namespace tests {
@@ -52,6 +57,10 @@ class MockExecutor;
 class TestContainerizer : public slave::Containerizer
 {
 public:
+  TestContainerizer(
+      const ExecutorID& executorId,
+      const std::shared_ptr<MockV1HTTPExecutor>& executor);
+
   TestContainerizer(const hashmap<ExecutorID, Executor*>& executors);
 
   TestContainerizer(const ExecutorID& executorId, Executor* executor);
@@ -124,9 +133,11 @@ private:
       const ContainerID& containerId);
 
   hashmap<ExecutorID, Executor*> executors;
+  hashmap<ExecutorID, std::shared_ptr<MockV1HTTPExecutor>> v1Executors;
 
   hashmap<std::pair<FrameworkID, ExecutorID>, ContainerID> containers_;
   hashmap<ContainerID, process::Owned<MesosExecutorDriver> > drivers;
+  hashmap<ContainerID, process::Owned<executor::TestV1Mesos> > v1Libraries;
   hashmap<ContainerID,
       process::Owned<process::Promise<containerizer::Termination> > > promises;
 };