You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2017/02/24 22:11:59 UTC

[2/2] mesos git commit: Added allocation role validation for TaskInfo.

Added allocation role validation for TaskInfo.

With support for multi-role frameworks, we need to make sure that
individual task cannot mix allocation roles.

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


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

Branch: refs/heads/master
Commit: c2bdc651a457a573af320baf522d730b50d49773
Parents: 0b4086b
Author: Jay Guo <gu...@gmail.com>
Authored: Fri Feb 24 11:45:17 2017 -0800
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Fri Feb 24 14:10:47 2017 -0800

----------------------------------------------------------------------
 src/master/validation.cpp             |  5 ++++
 src/tests/master_validation_tests.cpp | 38 ++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/c2bdc651/src/master/validation.cpp
----------------------------------------------------------------------
diff --git a/src/master/validation.cpp b/src/master/validation.cpp
index 2fad457..ac91057 100644
--- a/src/master/validation.cpp
+++ b/src/master/validation.cpp
@@ -948,6 +948,11 @@ Option<Error> validateResources(const TaskInfo& task)
     return Error("Task uses duplicate persistence ID: " + error->message);
   }
 
+  error = resource::validateAllocatedToSingleRole(resources);
+  if (error.isSome()) {
+    return Error("Invalid task resources: " + error->message);
+  }
+
   error = resource::validateRevocableAndNonRevocableResources(resources);
   if (error.isSome()) {
     return Error("Task mixes revocable and non-revocable resources: " +

http://git-wip-us.apache.org/repos/asf/mesos/blob/c2bdc651/src/tests/master_validation_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/master_validation_tests.cpp b/src/tests/master_validation_tests.cpp
index 20f2ccd..9c4ad4f 100644
--- a/src/tests/master_validation_tests.cpp
+++ b/src/tests/master_validation_tests.cpp
@@ -1801,6 +1801,7 @@ TEST_F(TaskValidationTest, TaskUsesRevocableResources)
   cpus.set_name("cpus");
   cpus.set_type(Value::SCALAR);
   cpus.mutable_scalar()->set_value(2);
+  cpus.mutable_allocation_info()->set_role("role");
 
   // A task with only non-revocable cpus is valid.
   task.add_resources()->CopyFrom(cpus);
@@ -1832,6 +1833,43 @@ TEST_F(TaskValidationTest, TaskUsesRevocableResources)
 }
 
 
+TEST_F(TaskValidationTest, TaskInfoAllocatedResources)
+{
+  // Validation should pass if the task has resources
+  // allocated to a single role.
+  {
+    TaskInfo task;
+    Resources resources = Resources::parse("cpus:1;mem:1").get();
+    task.mutable_resources()->CopyFrom(allocatedResources(resources, "role"));
+
+    EXPECT_NONE(::task::internal::validateResources(task));
+  }
+
+  // Validation should fail if the task has unallocated resources.
+  {
+    TaskInfo task;
+    Resources resources = Resources::parse("cpus:1;mem:1").get();
+    task.mutable_resources()->CopyFrom(resources);
+
+    EXPECT_SOME(::task::internal::validateResources(task));
+  }
+
+  // Validation should fail if the task has resources
+  // allocated to multiple roles.
+  {
+    TaskInfo task;
+    Resources resources1 = Resources::parse("cpus:1").get();
+    Resources resources2 = Resources::parse("mem:1").get();
+
+    task.mutable_resources()->CopyFrom(
+        allocatedResources(resources1, "role1") +
+        allocatedResources(resources2, "role2"));
+
+    EXPECT_SOME(::task::internal::validateResources(task));
+  }
+}
+
+
 // This test verifies that a task and its executor are not allowed to
 // mix revocable and non-revocable resources.
 TEST_F(TaskValidationTest, TaskAndExecutorUseRevocableResources)