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 2015/06/11 02:17:08 UTC
[3/3] mesos git commit: Added a test for launching an executor on
revocable resources.
Added a test for launching an executor on revocable resources.
Review: https://reviews.apache.org/r/34911
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b5f4f7ba
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b5f4f7ba
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b5f4f7ba
Branch: refs/heads/master
Commit: b5f4f7ba6a585b747daeea76210742001b604b40
Parents: c6a9fff
Author: Vinod Kone <vi...@gmail.com>
Authored: Mon Jun 1 16:09:11 2015 -0700
Committer: Vinod Kone <vi...@gmail.com>
Committed: Wed Jun 10 16:55:55 2015 -0700
----------------------------------------------------------------------
src/master/validation.cpp | 2 +-
src/slave/slave.cpp | 1 +
src/tests/mesos.cpp | 26 +++++++++++++++++
src/tests/mesos.hpp | 7 +++++
src/tests/oversubscription_tests.cpp | 47 +++++++++++++++++++++++++------
5 files changed, 73 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/b5f4f7ba/src/master/validation.cpp
----------------------------------------------------------------------
diff --git a/src/master/validation.cpp b/src/master/validation.cpp
index 889387d..9d128aa 100644
--- a/src/master/validation.cpp
+++ b/src/master/validation.cpp
@@ -299,7 +299,7 @@ Option<Error> validateCheckpoint(Framework* framework, Slave* slave)
// Validates that the task and the executor are using proper amount of
-// resources. For instance, the used resources by a task on each slave
+// resources. For instance, the used resources by a task on a slave
// should not exceed the total resources offered on that slave.
Option<Error> validateResourceUsage(
const TaskInfo& task,
http://git-wip-us.apache.org/repos/asf/mesos/blob/b5f4f7ba/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 2eef391..0a2cd16 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -4511,6 +4511,7 @@ Executor* Framework::launchExecutor(
LOG(INFO) << "Launching executor " << executorInfo.executor_id()
<< " of framework " << id()
+ << " with resources " << executorInfo.resources()
<< " in work directory '" << directory << "'";
slave->files->attach(executor->directory, executor->directory)
http://git-wip-us.apache.org/repos/asf/mesos/blob/b5f4f7ba/src/tests/mesos.cpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.cpp b/src/tests/mesos.cpp
index dff45b0..5e574c5 100644
--- a/src/tests/mesos.cpp
+++ b/src/tests/mesos.cpp
@@ -332,6 +332,32 @@ Try<PID<slave::Slave>> MesosTest::StartSlave(
}
+Try<PID<slave::Slave>> MesosTest::StartSlave(
+ MockExecutor* executor,
+ mesos::slave::ResourceEstimator* resourceEstimator,
+ const Option<slave::Flags>& flags)
+{
+ slave::Containerizer* containerizer = new TestContainerizer(executor);
+
+ Try<PID<slave::Slave>> pid = cluster.slaves.start(
+ flags.isNone() ? CreateSlaveFlags() : flags.get(),
+ containerizer,
+ None(),
+ None(),
+ None(),
+ resourceEstimator);
+
+ if (pid.isError()) {
+ delete containerizer;
+ return pid;
+ }
+
+ containerizers[pid.get()] = containerizer;
+
+ return pid;
+}
+
+
void MesosTest::Stop(const PID<master::Master>& pid)
{
cluster.masters.stop(pid);
http://git-wip-us.apache.org/repos/asf/mesos/blob/b5f4f7ba/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index 087953d..50b0061 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -185,6 +185,13 @@ protected:
mesos::slave::ResourceEstimator* resourceEstimator,
const Option<slave::Flags>& flags = None());
+ // Starts a slave with the specified mock executor, resource
+ // estimator and flags.
+ virtual Try<process::PID<slave::Slave>> StartSlave(
+ MockExecutor* executor,
+ mesos::slave::ResourceEstimator* resourceEstimator,
+ const Option<slave::Flags>& flags = None());
+
// Stop the specified master.
virtual void Stop(
const process::PID<master::Master>& pid);
http://git-wip-us.apache.org/repos/asf/mesos/blob/b5f4f7ba/src/tests/oversubscription_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/oversubscription_tests.cpp b/src/tests/oversubscription_tests.cpp
index 59cf07e..58a20d4 100644
--- a/src/tests/oversubscription_tests.cpp
+++ b/src/tests/oversubscription_tests.cpp
@@ -63,6 +63,7 @@ using std::string;
using std::vector;
using testing::_;
+using testing::AtMost;
using testing::Return;
using testing::Invoke;
@@ -203,15 +204,17 @@ TEST_F(OversubscriptionTest, ForwardUpdateSlaveMessage)
}
-// This test verifies that a framework that desires revocable
-// resources gets an offer with revocable resources.
+// This test verifies that a framework that accepts revocable
+// resources can launch a task with revocable resources.
TEST_F(OversubscriptionTest, RevocableOffer)
{
// Start the master.
Try<PID<Master>> master = StartMaster();
ASSERT_SOME(master);
- // Start the slave with test resource estimator.
+ // Start the slave with mock executor and test resource estimator.
+ MockExecutor exec(DEFAULT_EXECUTOR_ID);
+
MockResourceEstimator resourceEstimator;
EXPECT_CALL(resourceEstimator, initialize(_));
@@ -222,10 +225,10 @@ TEST_F(OversubscriptionTest, RevocableOffer)
slave::Flags flags = CreateSlaveFlags();
- Try<PID<Slave>> slave = StartSlave(&resourceEstimator, flags);
+ Try<PID<Slave>> slave = StartSlave(&exec, &resourceEstimator, flags);
ASSERT_SOME(slave);
- // Start the framework which desires revocable resources.
+ // Start the framework which accepts revocable resources.
FrameworkInfo framework = DEFAULT_FRAMEWORK_INFO;
framework.add_capabilities()->set_type(
FrameworkInfo::Capability::REVOCABLE_RESOURCES);
@@ -252,14 +255,40 @@ TEST_F(OversubscriptionTest, RevocableOffer)
.WillOnce(FutureArg<1>(&offers2))
.WillRepeatedly(Return()); // Ignore subsequent offers.
- // Inject an estimation of oversubscribable resources.
- Resources resources = createRevocableResources("cpus", "1");
- estimations.put(resources);
+ // Inject an estimation of oversubscribable cpu resources.
+ Resources taskResources = createRevocableResources("cpus", "1");
+ Resources executorResources = createRevocableResources("cpus", "1");
+ estimations.put(taskResources + executorResources);
// Now the framework will get revocable resources.
AWAIT_READY(offers2);
EXPECT_NE(0u, offers2.get().size());
- EXPECT_EQ(resources, Resources(offers2.get()[0].resources()));
+ EXPECT_EQ(
+ taskResources + executorResources,
+ Resources(offers2.get()[0].resources()));
+
+ // Now launch a task that uses revocable resources.
+ TaskInfo task =
+ createTask(offers2.get()[0].slave_id(), taskResources, "", exec.id);
+
+ task.mutable_executor()->mutable_resources()->CopyFrom(executorResources);
+
+ EXPECT_CALL(exec, registered(_, _, _, _));
+
+ EXPECT_CALL(exec, launchTask(_, _))
+ .WillOnce(SendStatusUpdateFromTask(TASK_RUNNING));
+
+ Future<TaskStatus> status;
+ EXPECT_CALL(sched, statusUpdate(&driver, _))
+ .WillOnce(FutureArg<1>(&status));
+
+ driver.launchTasks({offers1.get()[0].id(), offers2.get()[0].id()}, {task});
+
+ AWAIT_READY(status);
+ EXPECT_EQ(TASK_RUNNING, status.get().state());
+
+ EXPECT_CALL(exec, shutdown(_))
+ .Times(AtMost(1));
driver.stop();
driver.join();