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

[1/4] mesos git commit: Removed setting up of ACLs (unneeded) in PersistentVolumeTests.

Repository: mesos
Updated Branches:
  refs/heads/master 2bf3d4985 -> dfa58cfae


Removed setting up of ACLs (unneeded) in PersistentVolumeTests.

This fix removes the setting up of ACLs in PersistentVolumeTests
as it is no longer needed any more with implicit roles (MESOS-4868).

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


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

Branch: refs/heads/master
Commit: 0d0658d4f2c2be1e38e28c56fdf9f8470d615579
Parents: 2bf3d49
Author: Yong Tang <yo...@outlook.com>
Authored: Tue Mar 8 23:38:51 2016 -0800
Committer: Adam B <ad...@mesosphere.io>
Committed: Tue Mar 8 23:38:51 2016 -0800

----------------------------------------------------------------------
 src/tests/persistent_volume_tests.cpp | 71 +++++++++++-------------------
 1 file changed, 25 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0d0658d4/src/tests/persistent_volume_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/persistent_volume_tests.cpp b/src/tests/persistent_volume_tests.cpp
index bf19c81..f25d59b 100644
--- a/src/tests/persistent_volume_tests.cpp
+++ b/src/tests/persistent_volume_tests.cpp
@@ -86,27 +86,6 @@ protected:
     diskPath = path.get();
   }
 
-  master::Flags MasterFlags(const vector<FrameworkInfo>& frameworks)
-  {
-    master::Flags flags = CreateMasterFlags();
-
-    ACLs acls;
-    hashset<string> roles;
-
-    foreach (const FrameworkInfo& framework, frameworks) {
-      mesos::ACL::RegisterFramework* acl = acls.add_register_frameworks();
-      acl->mutable_principals()->add_values(framework.principal());
-      acl->mutable_roles()->add_values(framework.role());
-
-      roles.insert(framework.role());
-    }
-
-    flags.acls = acls;
-    flags.roles = strings::join(",", roles);
-
-    return flags;
-  }
-
   Resource getDiskResource(const Megabytes& mb)
   {
     Resource diskResource;
@@ -280,10 +259,7 @@ TEST_P(PersistentVolumeTest, SendingCheckpointResourcesMessage)
 // sends them to the master during re-registration.
 TEST_P(PersistentVolumeTest, ResourcesCheckpointing)
 {
-  FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
-  frameworkInfo.set_role("role1");
-
-  Try<PID<Master>> master = StartMaster(MasterFlags({frameworkInfo}));
+  Try<PID<Master>> master = StartMaster(CreateMasterFlags());
   ASSERT_SOME(master);
 
   slave::Flags slaveFlags = CreateSlaveFlags();
@@ -292,6 +268,9 @@ TEST_P(PersistentVolumeTest, ResourcesCheckpointing)
   Try<PID<Slave>> slave = StartSlave(slaveFlags);
   ASSERT_SOME(slave);
 
+  FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
+  frameworkInfo.set_role("role1");
+
   MockScheduler sched;
   MesosSchedulerDriver driver(
       &sched, frameworkInfo, master.get(), DEFAULT_CREDENTIAL);
@@ -346,10 +325,7 @@ TEST_P(PersistentVolumeTest, ResourcesCheckpointing)
 
 TEST_P(PersistentVolumeTest, PreparePersistentVolume)
 {
-  FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
-  frameworkInfo.set_role("role1");
-
-  Try<PID<Master>> master = StartMaster(MasterFlags({frameworkInfo}));
+  Try<PID<Master>> master = StartMaster(CreateMasterFlags());
   ASSERT_SOME(master);
 
   slave::Flags slaveFlags = CreateSlaveFlags();
@@ -358,6 +334,9 @@ TEST_P(PersistentVolumeTest, PreparePersistentVolume)
   Try<PID<Slave>> slave = StartSlave(slaveFlags);
   ASSERT_SOME(slave);
 
+  FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
+  frameworkInfo.set_role("role1");
+
   MockScheduler sched;
   MesosSchedulerDriver driver(
       &sched, frameworkInfo, master.get(), DEFAULT_CREDENTIAL);
@@ -412,10 +391,7 @@ TEST_P(PersistentVolumeTest, PreparePersistentVolume)
 // persistent volumes are later correctly offered to the framework.
 TEST_P(PersistentVolumeTest, MasterFailover)
 {
-  FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
-  frameworkInfo.set_role("role1");
-
-  master::Flags masterFlags = MasterFlags({frameworkInfo});
+  master::Flags masterFlags = CreateMasterFlags();
 
   Try<PID<Master>> master = StartMaster(masterFlags);
   ASSERT_SOME(master);
@@ -428,6 +404,9 @@ TEST_P(PersistentVolumeTest, MasterFailover)
   Try<PID<Slave>> slave = StartSlave(&detector, slaveFlags);
   ASSERT_SOME(slave);
 
+  FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
+  frameworkInfo.set_role("role1");
+
   MockScheduler sched;
   TestingMesosSchedulerDriver driver(&sched, &detector, frameworkInfo);
 
@@ -508,10 +487,7 @@ TEST_P(PersistentVolumeTest, MasterFailover)
 // slave resources specified using the '--resources' flag.
 TEST_P(PersistentVolumeTest, IncompatibleCheckpointedResources)
 {
-  FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
-  frameworkInfo.set_role("role1");
-
-  Try<PID<Master>> master = StartMaster(MasterFlags({frameworkInfo}));
+  Try<PID<Master>> master = StartMaster(CreateMasterFlags());
   ASSERT_SOME(master);
 
   slave::Flags slaveFlags = CreateSlaveFlags();
@@ -524,6 +500,9 @@ TEST_P(PersistentVolumeTest, IncompatibleCheckpointedResources)
   MockSlave slave1(slaveFlags, &detector, &containerizer);
   spawn(slave1);
 
+  FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
+  frameworkInfo.set_role("role1");
+
   MockScheduler sched;
   MesosSchedulerDriver driver(
       &sched, frameworkInfo, master.get(), DEFAULT_CREDENTIAL);
@@ -595,10 +574,7 @@ TEST_P(PersistentVolumeTest, IncompatibleCheckpointedResources)
 // the container path it specifies.
 TEST_P(PersistentVolumeTest, AccessPersistentVolume)
 {
-  FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
-  frameworkInfo.set_role("role1");
-
-  Try<PID<Master>> master = StartMaster(MasterFlags({frameworkInfo}));
+  Try<PID<Master>> master = StartMaster(CreateMasterFlags());
   ASSERT_SOME(master);
 
   slave::Flags slaveFlags = CreateSlaveFlags();
@@ -608,6 +584,9 @@ TEST_P(PersistentVolumeTest, AccessPersistentVolume)
   Try<PID<Slave>> slave = StartSlave(slaveFlags);
   ASSERT_SOME(slave);
 
+  FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
+  frameworkInfo.set_role("role1");
+
   MockScheduler sched;
   MesosSchedulerDriver driver(
       &sched, frameworkInfo, master.get(), DEFAULT_CREDENTIAL);
@@ -701,11 +680,7 @@ TEST_P(PersistentVolumeTest, AccessPersistentVolume)
 // slave finishes recovery.
 TEST_P(PersistentVolumeTest, SlaveRecovery)
 {
-  FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
-  frameworkInfo.set_role("role1");
-  frameworkInfo.set_checkpoint(true);
-
-  Try<PID<Master>> master = StartMaster(MasterFlags({frameworkInfo}));
+  Try<PID<Master>> master = StartMaster(CreateMasterFlags());
   ASSERT_SOME(master);
 
   slave::Flags slaveFlags = CreateSlaveFlags();
@@ -715,6 +690,10 @@ TEST_P(PersistentVolumeTest, SlaveRecovery)
   Try<PID<Slave>> slave = StartSlave(slaveFlags);
   ASSERT_SOME(slave);
 
+  FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
+  frameworkInfo.set_role("role1");
+  frameworkInfo.set_checkpoint(true);
+
   MockScheduler sched;
   MesosSchedulerDriver driver(
       &sched, frameworkInfo, master.get(), DEFAULT_CREDENTIAL);


[3/4] mesos git commit: Addressed comments of 41672.

Posted by me...@apache.org.
Addressed comments of 41672.

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


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

Branch: refs/heads/master
Commit: 17ed0eeadeddd7df6d83e825efc37525c8b8453b
Parents: feef247
Author: Yongqiao Wang <yq...@cn.ibm.com>
Authored: Tue Mar 8 23:47:46 2016 -0800
Committer: Adam B <ad...@mesosphere.io>
Committed: Tue Mar 8 23:49:49 2016 -0800

----------------------------------------------------------------------
 src/tests/hierarchical_allocator_tests.cpp | 421 +++++++++++++-----------
 1 file changed, 224 insertions(+), 197 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/17ed0eea/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp
index 3e4ad31..7ff227d 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -230,6 +230,35 @@ protected:
     return weightInfo;
   }
 
+  void handleAllocationsAndRecoverResources(
+      Resources& totalAllocatedResources,
+      hashmap<FrameworkID, Allocation>& frameworkAllocations,
+      int allocationsCount,
+      bool recoverResources)
+  {
+    for (unsigned i = 0; i < allocationsCount; i++) {
+      Future<Allocation> allocation = allocations.get();
+      AWAIT_READY(allocation);
+
+      frameworkAllocations[allocation.get().frameworkId] = allocation.get();
+      totalAllocatedResources += Resources::sum(allocation.get().resources);
+
+      if (recoverResources) {
+        // Recover the allocated resources so they can be offered again
+        // next time.
+        foreachpair (const SlaveID& slaveId,
+                     const Resources& resources,
+                     allocation.get().resources) {
+          allocator->recoverResources(
+              allocation.get().frameworkId,
+              slaveId,
+              resources,
+              None());
+        }
+      }
+    }
+  }
+
 protected:
   master::Flags flags;
 
@@ -2377,6 +2406,201 @@ TEST_F(HierarchicalAllocatorTest, DeactivateAndReactivateFramework)
 }
 
 
+// This test ensures that resource allocation is done according to each role's
+// weight. This is done by having six agents and three frameworks and making
+// sure each framework gets the appropriate number of resources.
+TEST_F(HierarchicalAllocatorTest, UpdateWeight)
+{
+  // Pausing the clock is not necessary, but ensures that the test
+  // doesn't rely on the batch allocation in the allocator, which
+  // would slow down the test.
+  Clock::pause();
+
+  initialize();
+
+  // Define some constants to make the code read easily.
+  const string SINGLE_RESOURCE = "cpus:2;mem:1024";
+  const string DOUBLE_RESOURCES = "cpus:4;mem:2048";
+  const string TRIPLE_RESOURCES = "cpus:6;mem:3072";
+  const string FOURFOLD_RESOURCES = "cpus:8;mem:4096";
+  const string TOTAL_RESOURCES = "cpus:12;mem:6144";
+
+  // Register six agents with the same resources (cpus:2;mem:1024).
+  vector<SlaveInfo> agents;
+  for (unsigned i = 0; i < 6; i++) {
+    SlaveInfo agent = createSlaveInfo(SINGLE_RESOURCE);
+    agents.push_back(agent);
+    allocator->addSlave(agent.id(), agent, None(), agent.resources(), {});
+  }
+
+  // Total cluster resources (6 agents): cpus=12, mem=6144.
+
+  // Framework1 registers with 'role1' which uses the default weight (1.0),
+  // and all resources will be offered to this framework since it is the only
+  // framework running so far.
+  FrameworkInfo framework1 = createFrameworkInfo("role1");
+  allocator->addFramework(framework1.id(), framework1, {});
+
+  // Framework2 registers with 'role2' which also uses the default weight.
+  // It will not get any offers due to all resources having outstanding offers
+  // to framework1 when it registered.
+  FrameworkInfo framework2 = createFrameworkInfo("role2");
+  allocator->addFramework(framework2.id(), framework2, {});
+
+  Future<Allocation> allocation = allocations.get();
+  AWAIT_READY(allocation);
+
+  // role1 share = 1 (cpus=12, mem=6144)
+  //   framework1 share = 1
+  // role2 share = 0
+  //   framework2 share = 0
+
+  ASSERT_EQ(allocation.get().frameworkId, framework1.id());
+  ASSERT_EQ(6u, allocation.get().resources.size());
+  EXPECT_EQ(Resources::parse(TOTAL_RESOURCES).get(),
+            Resources::sum(allocation.get().resources));
+
+  // Recover all resources so they can be offered again next time.
+  foreachpair (const SlaveID& slaveId,
+               const Resources& resources,
+               allocation.get().resources) {
+    allocator->recoverResources(
+        allocation.get().frameworkId,
+        slaveId,
+        resources,
+        None());
+  }
+
+  // Tests whether `framework1` and `framework2` each get half of the resources
+  // when their roles' weights are 1:1.
+  {
+    // Advance the clock and trigger a batch allocation.
+    Clock::advance(flags.allocation_interval);
+    Clock::settle();
+
+    // role1 share = 0.5 (cpus=6, mem=3072)
+    //   framework1 share = 1
+    // role2 share = 0.5 (cpus=6, mem=3072)
+    //   framework2 share = 1
+
+    // Ensure that all resources are offered equally between both frameworks,
+    // since each framework's role has a weight of 1.0 by default.
+    hashmap<FrameworkID, Allocation> frameworkAllocations;
+    Resources totalAllocatedResources;
+    handleAllocationsAndRecoverResources(totalAllocatedResources,
+        frameworkAllocations, 2, true);
+
+    // Framework1 should get one allocation with three agents.
+    ASSERT_EQ(3u, frameworkAllocations[framework1.id()].resources.size());
+    EXPECT_EQ(Resources::parse(TRIPLE_RESOURCES).get(),
+        Resources::sum(frameworkAllocations[framework1.id()].resources));
+
+    // Framework2 should also get one allocation with three agents.
+    ASSERT_EQ(3u, frameworkAllocations[framework2.id()].resources.size());
+    EXPECT_EQ(Resources::parse(TRIPLE_RESOURCES).get(),
+        Resources::sum(frameworkAllocations[framework2.id()].resources));
+
+    // Check to ensure that these two allocations sum to the total resources;
+    // this check can ensure there are only two allocations in this case.
+    EXPECT_EQ(Resources::parse(TOTAL_RESOURCES).get(), totalAllocatedResources);
+  }
+
+  // Tests whether `framework1` gets 1/3 of the resources and `framework2` gets
+  // 2/3 of the resources when their roles' weights are 1:2.
+  {
+    // Update the weight of framework2's role to 2.0.
+    vector<WeightInfo> weightInfos;
+    weightInfos.push_back(createWeightInfo(framework2.role(), 2.0));
+    allocator->updateWeights(weightInfos);
+
+    // 'updateWeights' will trigger the allocation immediately, so it does not
+    // need to manually advance the clock here.
+    Clock::settle();
+
+    // role1 share = 0.33 (cpus=4, mem=2048)
+    //   framework1 share = 1
+    // role2 share = 0.66 (cpus=8, mem=4096)
+    //   framework2 share = 1
+
+    // Now that the frameworks's weights are 1:2, ensure that all
+    // resources are offered with a ratio of 1:2 between both frameworks.
+    hashmap<FrameworkID, Allocation> frameworkAllocations;
+    Resources totalAllocatedResources;
+    handleAllocationsAndRecoverResources(totalAllocatedResources,
+        frameworkAllocations, 2, true);
+
+    // Framework1 should get one allocation with two agents.
+    ASSERT_EQ(2u, frameworkAllocations[framework1.id()].resources.size());
+    EXPECT_EQ(Resources::parse(DOUBLE_RESOURCES).get(),
+        Resources::sum(frameworkAllocations[framework1.id()].resources));
+
+    // Framework2 should get one allocation with four agents.
+    ASSERT_EQ(4u, frameworkAllocations[framework2.id()].resources.size());
+    EXPECT_EQ(Resources::parse(FOURFOLD_RESOURCES).get(),
+        Resources::sum(frameworkAllocations[framework2.id()].resources));
+
+    // Check to ensure that these two allocations sum to the total resources;
+    // this check can ensure there are only two allocations in this case.
+    EXPECT_EQ(Resources::parse(TOTAL_RESOURCES).get(), totalAllocatedResources);
+  }
+
+  // Tests whether `framework1` gets 1/6 of the resources, `framework2` gets
+  // 2/6 of the resources and `framework3` gets 3/6 of the resources when their
+  // roles' weights are 1:2:3.
+  {
+    // Add a new role with a weight of 3.0.
+    vector<WeightInfo> weightInfos;
+    weightInfos.push_back(createWeightInfo("role3", 3.0));
+    allocator->updateWeights(weightInfos);
+
+    // 'updateWeights' will not trigger the allocation immediately because no
+    // framework exists in 'role3' yet.
+
+    // Framework3 registers with 'role3'.
+    FrameworkInfo framework3 = createFrameworkInfo("role3");
+    allocator->addFramework(framework3.id(), framework3, {});
+
+    // 'addFramework' will trigger the allocation immediately, so it does not
+    // need to manually advance the clock here.
+    Clock::settle();
+
+    // role1 share = 0.166 (cpus=2, mem=1024)
+    //   framework1 share = 1
+    // role2 share = 0.333 (cpus=4, mem=2048)
+    //   framework2 share = 1
+    // role3 share = 0.50 (cpus=6, mem=3072)
+    //   framework3 share = 1
+
+    // Currently, there are three frameworks and six agents in this cluster,
+    // and the weight ratio of these frameworks is 1:2:3, therefore frameworks
+    // will get the proper resource ratio of 1:2:3.
+    hashmap<FrameworkID, Allocation> frameworkAllocations;
+    Resources totalAllocatedResources;
+    handleAllocationsAndRecoverResources(totalAllocatedResources,
+        frameworkAllocations, 3, false);
+
+    // Framework1 should get one allocation with one agent.
+    ASSERT_EQ(1u, frameworkAllocations[framework1.id()].resources.size());
+    EXPECT_EQ(Resources::parse(SINGLE_RESOURCE).get(),
+        Resources::sum(frameworkAllocations[framework1.id()].resources));
+
+    // Framework2 should get one allocation with two agents.
+    ASSERT_EQ(2u, frameworkAllocations[framework2.id()].resources.size());
+    EXPECT_EQ(Resources::parse(DOUBLE_RESOURCES).get(),
+        Resources::sum(frameworkAllocations[framework2.id()].resources));
+
+    // Framework3 should get one allocation with three agents.
+    ASSERT_EQ(3u, frameworkAllocations[framework3.id()].resources.size());
+    EXPECT_EQ(Resources::parse(TRIPLE_RESOURCES).get(),
+        Resources::sum(frameworkAllocations[framework3.id()].resources));
+
+    // Check to ensure that these three allocations sum to the total resources;
+    // this check can ensure there are only three allocations in this case.
+    EXPECT_EQ(Resources::parse(TOTAL_RESOURCES).get(), totalAllocatedResources);
+  }
+}
+
+
 class HierarchicalAllocator_BENCHMARK_Test
   : public HierarchicalAllocatorTestBase,
     public WithParamInterface<std::tr1::tuple<size_t, size_t>> {};
@@ -2765,203 +2989,6 @@ TEST_F(HierarchicalAllocator_BENCHMARK_Test, ResourceLabels)
   Clock::resume();
 }
 
-
-// This test ensures that resource allocation is done per role's weight.
-// This is done by having six slaves and three frameworks and making sure each
-// framework gets the number of resources by their role's weight.
-TEST_F(HierarchicalAllocatorTest, UpdateWeight)
-{
-  // Pausing the clock is not necessary, but ensures that the test
-  // doesn't rely on the periodic allocation in the allocator, which
-  // would slow down the test.
-  Clock::pause();
-
-  initialize();
-
-  // Register six slaves with the same resources (cpus:2;mem:1024).
-  vector<SlaveInfo> slaves;
-  const string SINGLE_RESOURCE = "cpus:2;mem:1024";
-  const string DOUBLE_RESOURCES = "cpus:4;mem:2048";
-  const string TRIPLE_RESOURCES = "cpus:6;mem:3072";
-  const string FOURFOLD_RESOURCES = "cpus:8;mem:4096";
-  const string TOTAL_RESOURCES = "cpus:12;mem:6144";
-  for (unsigned i = 0; i < 6; i++) {
-    slaves.push_back(createSlaveInfo(SINGLE_RESOURCE));
-  }
-
-  foreach (const SlaveInfo& slave, slaves) {
-    allocator->addSlave(
-        slave.id(),
-        slave,
-        None(),
-        slave.resources(),
-        hashmap<FrameworkID, Resources>());
-  }
-
-  // Framework1 registers with 'role1' which uses the default
-  // weight (1.0), and all resources will be offered to this framework.
-  FrameworkInfo framework1 = createFrameworkInfo("role1");
-  allocator->addFramework(
-      framework1.id(), framework1, hashmap<SlaveID, Resources>());
-
-  // Framework2 registers with 'role2' which also uses the
-  // default weight (1.0).
-  FrameworkInfo framework2 = createFrameworkInfo("role2");
-  allocator->addFramework(
-      framework2.id(), framework2, hashmap<SlaveID, Resources>());
-
-  // Framework1 gets one allocation with all resources, and Framework2
-  // does not get any offers due to all resources having outstanding
-  // offers to framework1 when it registered.
-  // Recover all resources owned by framework1 so they can be offered
-  // again next time.
-  Future<Allocation> allocation = allocations.get();
-  AWAIT_READY(allocation);
-  ASSERT_EQ(allocation.get().frameworkId, framework1.id());
-  ASSERT_EQ(6u, allocation.get().resources.size());
-  EXPECT_EQ(Resources::parse(TOTAL_RESOURCES).get(),
-            Resources::sum(allocation.get().resources));
-  foreachpair (const SlaveID& slaveId,
-               const Resources& resources,
-               allocation.get().resources) {
-    allocator->recoverResources(
-        allocation.get().frameworkId,
-        slaveId,
-        resources,
-        None());
-  }
-
-  // Because each framework's role has a weight of 1.0 by default, test to
-  // ensure that all resources are offered equally between both frameworks.
-  hashmap<FrameworkID, size_t> counts;
-  Clock::advance(flags.allocation_interval);
-  Resources totalAllocatedResources1;
-  for (unsigned i = 0; i < 2; i++) {
-    Future<Allocation> allocation = allocations.get();
-    AWAIT_READY(allocation);
-    counts[allocation.get().frameworkId]++;
-    totalAllocatedResources1 += Resources::sum(allocation.get().resources);
-
-    // Each framework will get one allocation with three slaves.
-    ASSERT_EQ(3u, allocation.get().resources.size());
-    EXPECT_EQ(Resources::parse(TRIPLE_RESOURCES).get(),
-              Resources::sum(allocation.get().resources));
-
-    // Recover the offered resources so they can be offered again next time.
-    foreachpair (const SlaveID& slaveId,
-                 const Resources& resources,
-                 allocation.get().resources) {
-      allocator->recoverResources(
-          allocation.get().frameworkId,
-          slaveId,
-          resources,
-          None());
-    }
-  }
-
-  // Check to ensure that these two allocations sum to the total resources,
-  // this check can ensure there are only two allocations in this case.
-  EXPECT_EQ(Resources::parse(TOTAL_RESOURCES).get(), totalAllocatedResources1);
-  EXPECT_EQ(1u, counts[framework1.id()]);
-  EXPECT_EQ(1u, counts[framework2.id()]);
-
-  // Update the weight of framework2's role to 2.0, then their
-  // weights should be 1:2.
-  vector<WeightInfo> weightInfos1;
-  weightInfos1.push_back(createWeightInfo(framework2.role(), 2.0));
-  allocator->updateWeights(weightInfos1);
-
-  // Now that the frameworks's weights are 1:2, test to ensure that all
-  // resources are offered with a ratio of 1:2 between both frameworks.
-  counts.clear();
-  Resources totalAllocatedResources2;
-  Clock::advance(flags.allocation_interval);
-  for (unsigned i = 0; i < 2; i++) {
-    Future<Allocation> allocation = allocations.get();
-    AWAIT_READY(allocation);
-    counts[allocation.get().frameworkId]++;
-    totalAllocatedResources2 += Resources::sum(allocation.get().resources);
-
-    // Framework1 should get one allocation with two slaves.
-    if (allocation.get().frameworkId == framework1.id()) {
-      ASSERT_EQ(2u, allocation.get().resources.size());
-      EXPECT_EQ(Resources::parse(DOUBLE_RESOURCES).get(),
-                Resources::sum(allocation.get().resources));
-    } else {
-      // Framework2 should get one allocation with four slaves.
-      ASSERT_EQ(allocation.get().frameworkId, framework2.id());
-      ASSERT_EQ(4u, allocation.get().resources.size());
-      EXPECT_EQ(Resources::parse(FOURFOLD_RESOURCES).get(),
-                Resources::sum(allocation.get().resources));
-    }
-
-    // Recover the allocated resources so they can be offered again next time.
-    foreachpair (const SlaveID& slaveId,
-                 const Resources& resources,
-                 allocation.get().resources) {
-      allocator->recoverResources(
-          allocation.get().frameworkId,
-          slaveId,
-          resources,
-          None());
-    }
-  }
-  // Check to ensure that these two allocations sum to the total resources,
-  // this check can ensure there are only two allocations in this case.
-  EXPECT_EQ(Resources::parse(TOTAL_RESOURCES).get(), totalAllocatedResources2);
-  EXPECT_EQ(1u, counts[framework1.id()]);
-  EXPECT_EQ(1u, counts[framework2.id()]);
-
-  // Add a new role with a weight of 3.0.
-  vector<WeightInfo> weightInfos2;
-  weightInfos2.push_back(createWeightInfo("role3", 3.0));
-  allocator->updateWeights(weightInfos2);
-
-  // Framework3 registers with 'role3'.
-  FrameworkInfo framework3 = createFrameworkInfo("role3");
-  allocator->addFramework(
-      framework3.id(), framework3, hashmap<SlaveID, Resources>());
-
-  // Currently, there are three frameworks and six slaves in this cluster,
-  // and the weight ratio of these frameworks is 1:2:3, therefore frameworks
-  // will get the proper resource ratio of 1:2:3.
-  counts.clear();
-  Resources totalAllocatedResources3;
-  for (unsigned i = 0; i < 3; i++) {
-    Future<Allocation> allocation = allocations.get();
-    AWAIT_READY(allocation);
-    counts[allocation.get().frameworkId]++;
-    totalAllocatedResources3 += Resources::sum(allocation.get().resources);
-
-    // Framework1 should get one allocation with one slave.
-    if (allocation.get().frameworkId == framework1.id()) {
-      ASSERT_EQ(1u, allocation.get().resources.size());
-      EXPECT_EQ(Resources::parse(SINGLE_RESOURCE).get(),
-                Resources::sum(allocation.get().resources));
-    } else if (allocation.get().frameworkId == framework2.id()) {
-      // Framework2 should get one allocation with two slaves.
-      ASSERT_EQ(2u, allocation.get().resources.size());
-      EXPECT_EQ(Resources::parse(DOUBLE_RESOURCES).get(),
-                Resources::sum(allocation.get().resources));
-    } else {
-      // Framework3 should get one allocation with three slaves.
-      ASSERT_EQ(allocation.get().frameworkId, framework3.id());
-      ASSERT_EQ(3u, allocation.get().resources.size());
-      EXPECT_EQ(Resources::parse(TRIPLE_RESOURCES).get(),
-                Resources::sum(allocation.get().resources));
-    }
-  }
-
-  // Check to ensure that these three allocations sum to the total resources,
-  // this check can ensure there are only three allocations in this case.
-  EXPECT_EQ(Resources::parse(TOTAL_RESOURCES).get(), totalAllocatedResources3);
-  EXPECT_EQ(1u, counts[framework1.id()]);
-  EXPECT_EQ(1u, counts[framework2.id()]);
-  EXPECT_EQ(1u, counts[framework3.id()]);
-
-  Clock::resume();
-}
-
 } // namespace tests {
 } // namespace internal {
 } // namespace mesos {


[2/4] mesos git commit: Removed redundant CreateMasterFlags in StartMaster calls.

Posted by me...@apache.org.
Removed redundant CreateMasterFlags in StartMaster calls.


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

Branch: refs/heads/master
Commit: feef247770034865aa435eb6c3093b390280eb50
Parents: 0d0658d
Author: Adam B <ad...@mesosphere.io>
Authored: Tue Mar 8 23:42:27 2016 -0800
Committer: Adam B <ad...@mesosphere.io>
Committed: Tue Mar 8 23:42:27 2016 -0800

----------------------------------------------------------------------
 src/tests/containerizer/port_mapping_tests.cpp |  2 +-
 src/tests/hook_tests.cpp                       |  4 ++--
 src/tests/persistent_volume_tests.cpp          | 10 +++++-----
 3 files changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/feef2477/src/tests/containerizer/port_mapping_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/port_mapping_tests.cpp b/src/tests/containerizer/port_mapping_tests.cpp
index 983a633..a1427fd 100644
--- a/src/tests/containerizer/port_mapping_tests.cpp
+++ b/src/tests/containerizer/port_mapping_tests.cpp
@@ -2218,7 +2218,7 @@ TEST_F(PortMappingMesosTest, ROOT_NetworkNamespaceHandleSymlink)
 // described in MESOS-2914.
 TEST_F(PortMappingMesosTest, CGROUPS_ROOT_RecoverMixedKnownAndUnKnownOrphans)
 {
-  Try<PID<Master>> master = StartMaster(CreateMasterFlags());
+  Try<PID<Master>> master = StartMaster();
   ASSERT_SOME(master);
 
   slave::Flags flags = CreateSlaveFlags();

http://git-wip-us.apache.org/repos/asf/mesos/blob/feef2477/src/tests/hook_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hook_tests.cpp b/src/tests/hook_tests.cpp
index 88ad780..bb287c7 100644
--- a/src/tests/hook_tests.cpp
+++ b/src/tests/hook_tests.cpp
@@ -142,7 +142,7 @@ TEST_F(HookTest, HookLoading)
 // taskinfo message during master launch task.
 TEST_F(HookTest, VerifyMasterLaunchTaskHook)
 {
-  Try<PID<Master>> master = StartMaster(CreateMasterFlags());
+  Try<PID<Master>> master = StartMaster();
   ASSERT_SOME(master);
 
   MockExecutor exec(DEFAULT_EXECUTOR_ID);
@@ -739,7 +739,7 @@ TEST_F(HookTest, ROOT_DOCKER_VerifySlavePreLaunchDockerHook)
 // propagated to the resource offer.
 TEST_F(HookTest, VerifySlaveResourcesAndAttributesDecorator)
 {
-  Try<PID<Master>> master = StartMaster(CreateMasterFlags());
+  Try<PID<Master>> master = StartMaster();
   ASSERT_SOME(master);
 
   MockExecutor exec(DEFAULT_EXECUTOR_ID);

http://git-wip-us.apache.org/repos/asf/mesos/blob/feef2477/src/tests/persistent_volume_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/persistent_volume_tests.cpp b/src/tests/persistent_volume_tests.cpp
index f25d59b..e9215de 100644
--- a/src/tests/persistent_volume_tests.cpp
+++ b/src/tests/persistent_volume_tests.cpp
@@ -259,7 +259,7 @@ TEST_P(PersistentVolumeTest, SendingCheckpointResourcesMessage)
 // sends them to the master during re-registration.
 TEST_P(PersistentVolumeTest, ResourcesCheckpointing)
 {
-  Try<PID<Master>> master = StartMaster(CreateMasterFlags());
+  Try<PID<Master>> master = StartMaster();
   ASSERT_SOME(master);
 
   slave::Flags slaveFlags = CreateSlaveFlags();
@@ -325,7 +325,7 @@ TEST_P(PersistentVolumeTest, ResourcesCheckpointing)
 
 TEST_P(PersistentVolumeTest, PreparePersistentVolume)
 {
-  Try<PID<Master>> master = StartMaster(CreateMasterFlags());
+  Try<PID<Master>> master = StartMaster();
   ASSERT_SOME(master);
 
   slave::Flags slaveFlags = CreateSlaveFlags();
@@ -487,7 +487,7 @@ TEST_P(PersistentVolumeTest, MasterFailover)
 // slave resources specified using the '--resources' flag.
 TEST_P(PersistentVolumeTest, IncompatibleCheckpointedResources)
 {
-  Try<PID<Master>> master = StartMaster(CreateMasterFlags());
+  Try<PID<Master>> master = StartMaster();
   ASSERT_SOME(master);
 
   slave::Flags slaveFlags = CreateSlaveFlags();
@@ -574,7 +574,7 @@ TEST_P(PersistentVolumeTest, IncompatibleCheckpointedResources)
 // the container path it specifies.
 TEST_P(PersistentVolumeTest, AccessPersistentVolume)
 {
-  Try<PID<Master>> master = StartMaster(CreateMasterFlags());
+  Try<PID<Master>> master = StartMaster();
   ASSERT_SOME(master);
 
   slave::Flags slaveFlags = CreateSlaveFlags();
@@ -680,7 +680,7 @@ TEST_P(PersistentVolumeTest, AccessPersistentVolume)
 // slave finishes recovery.
 TEST_P(PersistentVolumeTest, SlaveRecovery)
 {
-  Try<PID<Master>> master = StartMaster(CreateMasterFlags());
+  Try<PID<Master>> master = StartMaster();
   ASSERT_SOME(master);
 
   slave::Flags slaveFlags = CreateSlaveFlags();


[4/4] mesos git commit: Update docs for --weights flag and authorization.

Posted by me...@apache.org.
Update docs for --weights flag and authorization.

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


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

Branch: refs/heads/master
Commit: dfa58cfae3ff26774412217ff4666c4fdefe2d6d
Parents: 17ed0ee
Author: Yongqiao Wang <yq...@cn.ibm.com>
Authored: Tue Mar 8 23:56:43 2016 -0800
Committer: Adam B <ad...@mesosphere.io>
Committed: Tue Mar 8 23:56:43 2016 -0800

----------------------------------------------------------------------
 docs/authorization.md                      | 4 +++-
 docs/configuration.md                      | 4 +++-
 src/master/flags.cpp                       | 5 ++++-
 src/tests/hierarchical_allocator_tests.cpp | 2 +-
 4 files changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/dfa58cfa/docs/authorization.md
----------------------------------------------------------------------
diff --git a/docs/authorization.md b/docs/authorization.md
index c4449d5..0db5c34 100644
--- a/docs/authorization.md
+++ b/docs/authorization.md
@@ -13,6 +13,7 @@ Authorization currently allows
  4. Authorized _principals_ to set and remove quotas through the "/quota" HTTP endpoint.
  5. Authorized _principals_ to reserve and unreserve resources through the "/reserve" and "/unreserve" HTTP endpoints, as well as with the `RESERVE` and `UNRESERVE` offer operations.
  6. Authorized _principals_ to create and destroy persistent volumes through the "/create-volumes" and "/destroy-volumes" HTTP endpoints, as well as with the `CREATE` and `DESTROY` offer operations.
+ 7. Authorized _principals_ to update weights through the "/weights" HTTP endpoint.
 
 
 ## ACLs
@@ -32,12 +33,13 @@ The currently supported `Actions` are:
 7. "unreserve_resources": Unreserve resources
 8. "create_volumes": Create persistent volumes
 9. "destroy_volumes": Destroy persistent volumes
+10. "update_weights": Update weights
 
 The currently supported `Subjects` are:
 
 1. "principals"
 	- Framework principals (used by "register_frameworks", "run_tasks", "reserve", "unreserve", "create_volumes", and "destroy_volumes" actions)
-	- Operator usernames (used by "teardown_frameworks", "set_quotas", "remove_quotas", "reserve", "unreserve", "create_volumes", and "destroy_volumes" actions)
+	- Operator usernames (used by "teardown_frameworks", "set_quotas", "remove_quotas", "reserve", "unreserve", "create_volumes", "destroy_volumes", and "update_weights" actions)
 
 The currently supported `Objects` are:
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/dfa58cfa/docs/configuration.md
----------------------------------------------------------------------
diff --git a/docs/configuration.md b/docs/configuration.md
index 305ba2c..f6e8402 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -760,7 +760,9 @@ Directory path of the webui files/assets (default: /usr/local/share/mesos/webui)
   <td>
 A comma-separated list of role/weight pairs
 of the form <code>role=weight,role=weight</code>. Weights
-are used to indicate forms of priority.
+are used to indicate forms of priority. This flag is deprecated,
+and instead, after the Mesos master quorum is achieved, an operator
+can send an update weights request to do a batch configuration for weights.
   </td>
 </tr>
 <tr>

http://git-wip-us.apache.org/repos/asf/mesos/blob/dfa58cfa/src/master/flags.cpp
----------------------------------------------------------------------
diff --git a/src/master/flags.cpp b/src/master/flags.cpp
index be981ed..c1dd127 100644
--- a/src/master/flags.cpp
+++ b/src/master/flags.cpp
@@ -193,7 +193,10 @@ mesos::internal::master::Flags::Flags()
       "weights",
       "A comma-separated list of role/weight pairs\n"
       "of the form `role=weight,role=weight`. Weights\n"
-      "are used to indicate forms of priority.");
+      "are used to indicate forms of priority. This flag is deprecated;\n"
+      "if it is not specified, after the Mesos master quorum is achieved,\n"
+      "an operator can send an update weights request to do a batch\n"
+      "configuration for weights.");
 
   // TODO(adam-mesos): Deprecate --authenticate for --authenticate_frameworks.
   // See MESOS-4386 for details.

http://git-wip-us.apache.org/repos/asf/mesos/blob/dfa58cfa/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp b/src/tests/hierarchical_allocator_tests.cpp
index 7ff227d..9c2e519 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -236,7 +236,7 @@ protected:
       int allocationsCount,
       bool recoverResources)
   {
-    for (unsigned i = 0; i < allocationsCount; i++) {
+    for (int i = 0; i < allocationsCount; i++) {
       Future<Allocation> allocation = allocations.get();
       AWAIT_READY(allocation);