Repository: mesos
Updated Branches:
  refs/heads/master fcd966bbc -> 820ecf4a5


Removed Resources::Transformation in favor of using Offer::Operation.

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


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

Branch: refs/heads/master
Commit: 728192a83661e0729d23a9016c20b7d3b345ca09
Parents: fcd966b
Author: Jie Yu <[email protected]>
Authored: Tue Jan 20 16:58:33 2015 -0800
Committer: Jie Yu <[email protected]>
Committed: Mon Jan 26 11:19:42 2015 -0800

----------------------------------------------------------------------
 include/mesos/resources.hpp                   |  86 +++-------
 src/common/resources.cpp                      | 180 ++++++++++-----------
 src/master/allocator.hpp                      |  26 +--
 src/master/drf_sorter.cpp                     |   2 +-
 src/master/drf_sorter.hpp                     |   6 +-
 src/master/hierarchical_allocator_process.hpp |  46 +++---
 src/master/master.cpp                         |   4 +-
 src/master/sorter.hpp                         |  10 +-
 src/tests/hierarchical_allocator_tests.cpp    |  51 +++---
 src/tests/mesos.hpp                           |  12 +-
 src/tests/resources_tests.cpp                 |  16 +-
 src/tests/sorter_tests.cpp                    |  21 +--
 12 files changed, 211 insertions(+), 249 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/728192a8/include/mesos/resources.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/resources.hpp b/include/mesos/resources.hpp
index 7935e7f..b5893d3 100644
--- a/include/mesos/resources.hpp
+++ b/include/mesos/resources.hpp
@@ -27,6 +27,7 @@
 #include <mesos/values.hpp>
 
 #include <stout/bytes.hpp>
+#include <stout/error.hpp>
 #include <stout/foreach.hpp>
 #include <stout/option.hpp>
 #include <stout/try.hpp>
@@ -148,6 +149,30 @@ public:
   // example frameworks to leverage.
   Option<Resources> find(const Resources& targets) const;
 
+  // Certain offer operations (e.g., RESERVE, UNRESERVE, CREATE or
+  // DESTROY) alter the offered resources. The following methods
+  // provide a convenient way to get the transformed resources by
+  // applying the given offer operation(s). Returns an Error if the
+  // offer operation(s) cannot be applied.
+  Try<Resources> apply(const Offer::Operation& operation) const;
+
+  template <typename Iterable>
+  Try<Resources> apply(const Iterable& operations) const
+  {
+    Resources result = *this;
+
+    foreach (const Offer::Operation& operation, operations) {
+      Try<Resources> transformed = result.apply(operation);
+      if (transformed.isError()) {
+        return Error(transformed.error());
+      }
+
+      result = transformed.get();
+    }
+
+    return result;
+  }
+
   // Helpers to get resource values. We consider all roles here.
   template <typename T>
   Option<T> get(const std::string& name) const;
@@ -200,67 +225,6 @@ public:
   Resources& operator -= (const Resource& that);
   Resources& operator -= (const Resources& that);
 
-  // This is an abstraction for describing a transformation that can
-  // be applied to Resources. Transformations cannot not alter the
-  // quantity, or the static role of the resources.
-  class Transformation
-  {
-  public:
-    virtual ~Transformation() {}
-
-    // Returns the result of the transformation, applied to the given
-    // 'resources'. Returns an Error if the transformation cannot be
-    // applied, or the transformation invariants do not hold.
-    Try<Resources> operator () (const Resources& resources) const;
-
-  protected:
-    virtual Try<Resources> apply(const Resources& resources) const = 0;
-  };
-
-  // Represents a sequence of transformations, the transformations are
-  // applied in an all-or-nothing manner. We follow the composite
-  // pattern here.
-  class CompositeTransformation : public Transformation
-  {
-  public:
-    CompositeTransformation() {}
-
-    ~CompositeTransformation()
-    {
-      foreach (Transformation* transformation, transformations) {
-        delete transformation;
-      }
-    }
-
-    // TODO(jieyu): Consider using unique_ptr here once we finialize
-    // our style guide for unique_ptr.
-    template <typename T>
-    void add(const T& t)
-    {
-      transformations.push_back(new T(t));
-    }
-
-  protected:
-    virtual Try<Resources> apply(const Resources& resources) const;
-
-  private:
-    std::vector<Transformation*> transformations;
-  };
-
-  // Acquires a persistent disk from a regular disk resource.
-  class AcquirePersistentDisk : public Transformation
-  {
-  public:
-    AcquirePersistentDisk(const Resource& _disk);
-
-  protected:
-    virtual Try<Resources> apply(const Resources& resources) const;
-
-  private:
-    // The target persistent disk resource to acquire.
-    Resource disk;
-  };
-
 private:
   // Similar to 'contains(const Resource&)' but skips the validity
   // check. This can be used to avoid the performance overhead of

http://git-wip-us.apache.org/repos/asf/mesos/blob/728192a8/src/common/resources.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources.cpp b/src/common/resources.cpp
index 214e441..27125a8 100644
--- a/src/common/resources.cpp
+++ b/src/common/resources.cpp
@@ -603,6 +603,96 @@ Option<Resources> Resources::find(const Resources& 
targets) const
 }
 
 
+Try<Resources> Resources::apply(const Offer::Operation& operation) const
+{
+  Resources result = *this;
+
+  switch (operation.type()) {
+    case Offer::Operation::LAUNCH:
+      // Launch operation does not alter the offered resources.
+      break;
+
+    case Offer::Operation::RESERVE:
+    case Offer::Operation::UNRESERVE:
+      // TODO(mpark): Provide implementation.
+      return Error("Unimplemented");
+
+    case Offer::Operation::CREATE: {
+      Option<Error> error = validate(operation.create().volumes());
+      if (error.isSome()) {
+        return Error("Invalid CREATE Operation: " + error.get().message);
+      }
+
+      foreach (const Resource& volume, operation.create().volumes()) {
+        if (!volume.has_disk()) {
+          return Error("Invalid CREATE Operation: Missing 'disk'");
+        } else if (!volume.disk().has_persistence()) {
+          return Error("Invalid CREATE Operation: Missing 'persistence'");
+        }
+
+        // Strip the disk info so that we can subtract it from the
+        // original resources.
+        // TODO(jieyu): Non-persistent volumes are not supported for
+        // now. Persistent volumes can only be be created from regular
+        // disk resources. Revisit this once we start to support
+        // non-persistent volumes.
+        Resource stripped = volume;
+        stripped.clear_disk();
+
+        if (!result.contains(stripped)) {
+          return Error("Invalid CREATE Operation: Insufficient disk 
resources");
+        }
+
+        result -= stripped;
+        result += volume;
+      }
+      break;
+    }
+
+    case Offer::Operation::DESTROY: {
+      Option<Error> error = validate(operation.destroy().volumes());
+      if (error.isSome()) {
+        return Error("Invalid DESTROY Operation: " + error.get().message);
+      }
+
+      foreach (const Resource& volume, operation.destroy().volumes()) {
+        if (!volume.has_disk()) {
+          return Error("Invalid DESTROY Operation: Missing 'disk'");
+        } else if (!volume.disk().has_persistence()) {
+          return Error("Invalid DESTROY Operation: Missing 'persistence'");
+        }
+
+        if (!result.contains(volume)) {
+          return Error(
+              "Invalid DESTROY Operation: Persistent volume does not exist");
+        }
+
+        Resource stripped = volume;
+        stripped.clear_disk();
+
+        result -= volume;
+        result += stripped;
+      }
+      break;
+    }
+
+    default:
+      return Error("Unknown offer operation " + stringify(operation.type()));
+  }
+
+  // This is a sanity check to ensure the amount of each type of
+  // resource does not change.
+  // TODO(jieyu): Currently, we only check known resource types like
+  // cpus, mem, disk, ports, etc. We should generalize this.
+  CHECK(result.cpus() == cpus() &&
+        result.mem() == mem() &&
+        result.disk() == disk() &&
+        result.ports() == ports());
+
+  return result;
+}
+
+
 template <>
 Option<Value::Scalar> Resources::get(const string& name) const
 {
@@ -889,94 +979,4 @@ ostream& operator << (ostream& stream, const Resources& 
resources)
   return stream;
 }
 
-
-/////////////////////////////////////////////////
-// Resources transformations.
-/////////////////////////////////////////////////
-
-
-Try<Resources> Resources::Transformation::operator () (
-    const Resources& resources) const
-{
-  Try<Resources> applied = apply(resources);
-
-  if (applied.isSome()) {
-    // Additional checks.
-
-    // Ensure the amount of each type of resource does not change.
-    // TODO(jieyu): Currently, we only checks known resource types
-    // like cpus, mem, disk, ports, etc. We should generalize this.
-    if (resources.cpus() != applied.get().cpus() ||
-        resources.mem() != applied.get().mem() ||
-        resources.disk() != applied.get().disk() ||
-        resources.ports() != applied.get().ports()) {
-      return Error("Resource amount does not match");
-    }
-
-    // TODO(jieyu): Ensure that static role does not change.
-  }
-
-  return applied;
-}
-
-
-Try<Resources> Resources::CompositeTransformation::apply(
-    const Resources& resources) const
-{
-  Resources result = resources;
-
-  foreach (Transformation* transformation, transformations) {
-    Try<Resources> transformed = (*transformation)(result);
-
-    if (transformed.isError()) {
-      return Error(transformed.error());
-    }
-
-    result = transformed.get();
-  }
-
-  return result;
-}
-
-
-Resources::AcquirePersistentDisk::AcquirePersistentDisk(const Resource& _disk)
-  : disk(_disk)
-{
-  CHECK(disk.has_disk());
-  CHECK(disk.disk().has_persistence());
-}
-
-
-Try<Resources> Resources::AcquirePersistentDisk::apply(
-    const Resources& resources) const
-{
-  foreach (const Resource& resource, resources) {
-    // TODO(jieyu): Non-persistent volumes are not supported for now.
-    // Persistent disk can only be be acquired from regular disk
-    // resources. Revisit this once we start to support non-persistent
-    // disk volumes.
-    if (resource.name() == "disk" &&
-        !resource.has_disk() &&
-        resource.role() == disk.role()) {
-      CHECK_EQ(resource.type(), Value::SCALAR);
-      CHECK_EQ(disk.type(), Value::SCALAR);
-
-      if (disk.scalar() <= resource.scalar()) {
-        // Strip the disk info so that we can subtract it from the
-        // original resources.
-        Resource stripped = disk;
-        stripped.clear_disk();
-
-        Resources result = resources;
-        result -= stripped;
-        result += disk;
-
-        return result;
-      }
-    }
-  }
-
-  return Error("Insufficient disk resources");
-}
-
 } // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/728192a8/src/master/allocator.hpp
----------------------------------------------------------------------
diff --git a/src/master/allocator.hpp b/src/master/allocator.hpp
index 224569a..318a756 100644
--- a/src/master/allocator.hpp
+++ b/src/master/allocator.hpp
@@ -20,6 +20,7 @@
 #define __ALLOCATOR_HPP__
 
 #include <string>
+#include <vector>
 
 #include <mesos/resources.hpp>
 
@@ -27,7 +28,6 @@
 #include <process/dispatch.hpp>
 #include <process/pid.hpp>
 #include <process/process.hpp>
-#include <process/shared.hpp>
 
 #include <stout/hashmap.hpp>
 #include <stout/hashset.hpp>
@@ -50,10 +50,10 @@ class AllocatorProcess; // Forward declaration.
 
 // Basic model of an allocator: resources are allocated to a framework
 // in the form of offers. A framework can refuse some resources in
-// offers and run tasks in others. Allocated resources can have
-// transformations applied to them in order for frameworks to alter
-// the resource metadata (e.g. persistent disk). Resources can be
-// recovered from a framework when tasks finish/fail (or are lost
+// offers and run tasks in others. Allocated resources can have offer
+// operations applied to them in order for frameworks to alter the
+// resource metadata (e.g. creating persistent volumes). Resources can
+// be recovered from a framework when tasks finish/fail (or are lost
 // due to a slave failure) or when an offer is rescinded.
 //
 // NOTE: DO NOT subclass this class when implementing a new allocator.
@@ -118,10 +118,10 @@ public:
       const FrameworkID& frameworkId,
       const std::vector<Request>& requests);
 
-  void transformAllocation(
+  void updateAllocation(
       const FrameworkID& frameworkId,
       const SlaveID& slaveId,
-      const process::Shared<Resources::Transformation>& transformation);
+      const std::vector<Offer::Operation>& operations);
 
   // Informs the allocator to recover resources that are considered
   // used by the framework.
@@ -198,10 +198,10 @@ public:
       const FrameworkID& frameworkId,
       const std::vector<Request>& requests) = 0;
 
-  virtual void transformAllocation(
+  virtual void updateAllocation(
       const FrameworkID& frameworkId,
       const SlaveID& slaveId,
-      const process::Shared<Resources::Transformation>& transformation) = 0;
+      const std::vector<Offer::Operation>& operations) = 0;
 
   virtual void recoverResources(
       const FrameworkID& frameworkId,
@@ -353,17 +353,17 @@ inline void Allocator::requestResources(
 }
 
 
-inline void Allocator::transformAllocation(
+inline void Allocator::updateAllocation(
     const FrameworkID& frameworkId,
     const SlaveID& slaveId,
-    const process::Shared<Resources::Transformation>& transformation)
+    const std::vector<Offer::Operation>& operations)
 {
   process::dispatch(
       process,
-      &AllocatorProcess::transformAllocation,
+      &AllocatorProcess::updateAllocation,
       frameworkId,
       slaveId,
-      transformation);
+      operations);
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/728192a8/src/master/drf_sorter.cpp
----------------------------------------------------------------------
diff --git a/src/master/drf_sorter.cpp b/src/master/drf_sorter.cpp
index 967c8aa..28b16b2 100644
--- a/src/master/drf_sorter.cpp
+++ b/src/master/drf_sorter.cpp
@@ -117,7 +117,7 @@ void DRFSorter::allocated(
 }
 
 
-void DRFSorter::transform(
+void DRFSorter::update(
     const string& name,
     const Resources& oldAllocation,
     const Resources& newAllocation)

http://git-wip-us.apache.org/repos/asf/mesos/blob/728192a8/src/master/drf_sorter.hpp
----------------------------------------------------------------------
diff --git a/src/master/drf_sorter.hpp b/src/master/drf_sorter.hpp
index e0ec58b..5a66313 100644
--- a/src/master/drf_sorter.hpp
+++ b/src/master/drf_sorter.hpp
@@ -76,9 +76,9 @@ public:
   virtual void allocated(const std::string& name,
                          const Resources& resources);
 
-  virtual void transform(const std::string& name,
-                         const Resources& oldAllocation,
-                         const Resources& newAllocation);
+  virtual void update(const std::string& name,
+                      const Resources& oldAllocation,
+                      const Resources& newAllocation);
 
   virtual void unallocated(const std::string& name,
                            const Resources& resources);

http://git-wip-us.apache.org/repos/asf/mesos/blob/728192a8/src/master/hierarchical_allocator_process.hpp
----------------------------------------------------------------------
diff --git a/src/master/hierarchical_allocator_process.hpp 
b/src/master/hierarchical_allocator_process.hpp
index ccd37b4..6b44892 100644
--- a/src/master/hierarchical_allocator_process.hpp
+++ b/src/master/hierarchical_allocator_process.hpp
@@ -112,10 +112,10 @@ public:
       const FrameworkID& frameworkId,
       const std::vector<Request>& requests);
 
-  void transformAllocation(
+  void updateAllocation(
       const FrameworkID& frameworkId,
       const SlaveID& slaveId,
-      const process::Shared<Resources::Transformation>& transformation);
+      const std::vector<Offer::Operation>& operations);
 
   void recoverResources(
       const FrameworkID& frameworkId,
@@ -548,10 +548,10 @@ HierarchicalAllocatorProcess<RoleSorter, 
FrameworkSorter>::requestResources(
 
 template <class RoleSorter, class FrameworkSorter>
 void
-HierarchicalAllocatorProcess<RoleSorter, FrameworkSorter>::transformAllocation(
+HierarchicalAllocatorProcess<RoleSorter, FrameworkSorter>::updateAllocation(
     const FrameworkID& frameworkId,
     const SlaveID& slaveId,
-    const process::Shared<Resources::Transformation>& transformation)
+    const std::vector<Offer::Operation>& operations)
 {
   CHECK(initialized);
   CHECK(slaves.contains(slaveId));
@@ -562,9 +562,9 @@ HierarchicalAllocatorProcess<RoleSorter, 
FrameworkSorter>::transformAllocation(
   //
   //    total = available + allocated
   //
-  // Here we apply a transformation to the allocated resources,
-  // which in turns leads to a transformation of the total. The
-  // available resources remain unchanged.
+  // Here we apply offer operations to the allocated resources, which
+  // in turns leads to an update of the total. The available resources
+  // remain unchanged.
 
   FrameworkSorter* frameworkSorter =
     frameworkSorters[frameworks[frameworkId].role];
@@ -572,44 +572,36 @@ HierarchicalAllocatorProcess<RoleSorter, 
FrameworkSorter>::transformAllocation(
   Resources allocation = frameworkSorter->allocation(frameworkId.value());
 
   // Update the allocated resources.
-  // TODO(bmahler): Check transformation invariants! Namely,
-  // we don't want the quantity or the static roles of the
-  // allocation to be altered.
-  Try<Resources> transformedAllocation = (*transformation)(allocation);
+  Try<Resources> updatedAllocation = allocation.apply(operations);
+  CHECK_SOME(updatedAllocation);
 
-  CHECK_SOME(transformedAllocation);
-
-  frameworkSorter->transform(
+  frameworkSorter->update(
       frameworkId.value(),
       allocation,
-      transformedAllocation.get());
+      updatedAllocation.get());
 
-  roleSorter->transform(
+  roleSorter->update(
       frameworks[frameworkId].role,
       allocation.unreserved(),
-      transformedAllocation.get().unreserved());
+      updatedAllocation.get().unreserved());
 
   // Update the total resources.
-  // TODO(bmahler): Check transformation invariants! Namely,
-  // we don't want the quantity or the static roles of the
-  // total to be altered.
-  Try<Resources> transformedTotal = (*transformation)(slaves[slaveId].total);
-
-  CHECK_SOME(transformedTotal);
+  Try<Resources> updatedTotal = slaves[slaveId].total.apply(operations);
+  CHECK_SOME(updatedTotal);
 
-  slaves[slaveId].total = transformedTotal.get();
+  slaves[slaveId].total = updatedTotal.get();
 
   // TODO(bmahler): Validate that the available resources are
   // unaffected. This requires augmenting the sorters with
   // SlaveIDs for allocations, so that we can do:
   //
-  //   CHECK_EQ(slaves[slaveId].total - transformedSlaveAllocation,
+  //   CHECK_EQ(slaves[slaveId].total - updatedAllocation,
   //            slaves[slaveId].available);
 
-  // TODO(jieyu): Do not log if there is no transformation.
+  // TODO(jieyu): Do not log if there is no update.
   LOG(INFO) << "Updated allocation of framework " << frameworkId
             << " on slave " << slaveId
-            << " from " << allocation << " to " << transformedAllocation.get();
+            << " from " << allocation << " to " << updatedAllocation.get();
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/728192a8/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index bda8fda..2856cc3 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -2782,8 +2782,8 @@ void Master::_accept(
     return;
   }
 
-  // Some offer operations transform the offered resources. We keep
-  // transformed offered resources here.
+  // Some offer operations update the offered resources. We keep
+  // updated offered resources here.
   Resources _offeredResources = offeredResources;
 
   // Accumulated resources used.

http://git-wip-us.apache.org/repos/asf/mesos/blob/728192a8/src/master/sorter.hpp
----------------------------------------------------------------------
diff --git a/src/master/sorter.hpp b/src/master/sorter.hpp
index 333c293..8915c61 100644
--- a/src/master/sorter.hpp
+++ b/src/master/sorter.hpp
@@ -64,13 +64,13 @@ public:
   virtual void allocated(const std::string& client,
                          const Resources& resources) = 0;
 
-  // Transforms a portion of the allocation for the client, in
-  // order to augment the resources with additional metadata.
+  // Updates a portion of the allocation for the client, in order to
+  // augment the resources with additional metadata (e.g., volumes)
   // This means that the new allocation must not affect the static
   // roles, or the overall quantities of resources!
-  virtual void transform(const std::string& client,
-                         const Resources& oldAllocation,
-                         const Resources& newAllocation) = 0;
+  virtual void update(const std::string& client,
+                      const Resources& oldAllocation,
+                      const Resources& newAllocation) = 0;
 
   // Specify that resources have been unallocated from the given client.
   virtual void unallocated(const std::string& client,

http://git-wip-us.apache.org/repos/asf/mesos/blob/728192a8/src/tests/hierarchical_allocator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/hierarchical_allocator_tests.cpp 
b/src/tests/hierarchical_allocator_tests.cpp
index 7c05123..f44d9e9 100644
--- a/src/tests/hierarchical_allocator_tests.cpp
+++ b/src/tests/hierarchical_allocator_tests.cpp
@@ -669,10 +669,9 @@ TEST_F(HierarchicalAllocatorTest, Allocatable)
 }
 
 
-// This test ensures that frameworks can apply resource
-// transformations on their allocations. This allows them
-// to augment the resource metadata (e.g. persistent disk).
-TEST_F(HierarchicalAllocatorTest, TransformAllocation)
+// This test ensures that frameworks can apply offer operations (e.g.,
+// creating persistent volumes) on their allocations.
+TEST_F(HierarchicalAllocatorTest, UpdateAllocation)
 {
   Clock::pause();
   initialize(vector<string>{"role1"});
@@ -693,32 +692,33 @@ TEST_F(HierarchicalAllocatorTest, TransformAllocation)
   EXPECT_TRUE(allocation.get().resources.contains(slave.id()));
   EXPECT_EQ(slave.resources(), sum(allocation.get().resources.values()));
 
-  // Construct a transformation for the framework's allocation.
-  Resource disk = Resources::parse("disk", "5", "*").get();
-  disk.mutable_disk()->mutable_persistence()->set_id("ID");
-  disk.mutable_disk()->mutable_volume()->set_container_path("data");
+  // Construct an offer operation for the framework's allocation.
+  Resource volume = Resources::parse("disk", "5", "*").get();
+  volume.mutable_disk()->mutable_persistence()->set_id("ID");
+  volume.mutable_disk()->mutable_volume()->set_container_path("data");
 
-  Shared<Resources::Transformation> transformation(
-      new Resources::AcquirePersistentDisk(disk));
+  Offer::Operation create;
+  create.set_type(Offer::Operation::CREATE);
+  create.mutable_create()->add_volumes()->CopyFrom(volume);
 
-  // Ensure the transformation can be applied.
-  Try<Resources> transformed = (*transformation)(
-      sum(allocation.get().resources.values()));
+  // Ensure the offer operation can be applied.
+  Try<Resources> updated =
+    sum(allocation.get().resources.values()).apply(create);
 
-  ASSERT_SOME(transformed);
+  ASSERT_SOME(updated);
 
-  // Transform the allocation in the allocator.
-  allocator->transformAllocation(
+  // Update the allocation in the allocator.
+  allocator->updateAllocation(
       framework.id(),
       slave.id(),
-      transformation);
+      {create});
 
-  // Now recover the resources, and expect the next allocation
-  // to contain the disk transformation!
+  // Now recover the resources, and expect the next allocation to
+  // contain the updated resources.
   allocator->recoverResources(
       framework.id(),
       slave.id(),
-      transformed.get(),
+      updated.get(),
       None());
 
   Clock::advance(flags.allocation_interval);
@@ -729,16 +729,15 @@ TEST_F(HierarchicalAllocatorTest, TransformAllocation)
   EXPECT_EQ(1u, allocation.get().resources.size());
   EXPECT_TRUE(allocation.get().resources.contains(slave.id()));
 
-  // The allocation should be the slave's resources with the
-  // disk transformation applied.
-  transformed = (*transformation)(slave.resources());
-
-  ASSERT_SOME(transformed);
+  // The allocation should be the slave's resources with the offer
+  // operation applied.
+  updated = Resources(slave.resources()).apply(create);
+  ASSERT_SOME(updated);
 
   EXPECT_NE(Resources(slave.resources()),
             sum(allocation.get().resources.values()));
 
-  EXPECT_EQ(transformed.get(),
+  EXPECT_EQ(updated.get(),
             sum(allocation.get().resources.values()));
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/728192a8/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index 591134b..3f4704b 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -718,8 +718,8 @@ public:
     ON_CALL(*this, requestResources(_, _))
       .WillByDefault(InvokeResourcesRequested(this));
 
-    ON_CALL(*this, transformAllocation(_, _, _))
-      .WillByDefault(InvokeTransformAllocation(this));
+    ON_CALL(*this, updateAllocation(_, _, _))
+      .WillByDefault(InvokeUpdateAllocation(this));
 
     ON_CALL(*this, recoverResources(_, _, _, _))
       .WillByDefault(InvokeResourcesRecovered(this));
@@ -777,10 +777,10 @@ public:
       const FrameworkID&,
       const std::vector<Request>&));
 
-  MOCK_METHOD3(transformAllocation, void(
+  MOCK_METHOD3(updateAllocation, void(
       const FrameworkID&,
       const SlaveID&,
-      const process::Shared<Resources::Transformation>&));
+      const std::vector<Offer::Operation>&));
 
   MOCK_METHOD4(recoverResources, void(
       const FrameworkID&,
@@ -906,11 +906,11 @@ ACTION_P(InvokeResourcesRequested, allocator)
 }
 
 
-ACTION_P(InvokeTransformAllocation, allocator)
+ACTION_P(InvokeUpdateAllocation, allocator)
 {
   process::dispatch(
       allocator->real,
-      &master::allocator::AllocatorProcess::transformAllocation,
+      &master::allocator::AllocatorProcess::updateAllocation,
       arg0,
       arg1,
       arg2);

http://git-wip-us.apache.org/repos/asf/mesos/blob/728192a8/src/tests/resources_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/resources_tests.cpp b/src/tests/resources_tests.cpp
index b7c1ddf..351e26d 100644
--- a/src/tests/resources_tests.cpp
+++ b/src/tests/resources_tests.cpp
@@ -938,20 +938,26 @@ TEST(DiskResourcesTest, FilterPersistentDisks)
 }
 
 
-TEST(ResourcesTransformationTest, AcquirePersistentDisk)
+TEST(ResourcesOperationTest, CreatePersistentVolume)
 {
   Resources total = Resources::parse("cpus:1;mem:512;disk(role):1000").get();
 
   Resource disk1 = createDiskResource("200", "role", "1", "path");
-  Resources::AcquirePersistentDisk acquire1(disk1);
+
+  Offer::Operation create1;
+  create1.set_type(Offer::Operation::CREATE);
+  create1.mutable_create()->add_volumes()->CopyFrom(disk1);
 
   EXPECT_SOME_EQ(
       Resources::parse("cpus:1;mem:512;disk(role):800").get() + disk1,
-      acquire1(total));
+      total.apply(create1));
 
   // Check the case of insufficient disk resources.
   Resource disk2 = createDiskResource("2000", "role", "1", "path");
-  Resources::AcquirePersistentDisk acquire2(disk2);
 
-  EXPECT_ERROR(acquire2(total));
+  Offer::Operation create2;
+  create2.set_type(Offer::Operation::CREATE);
+  create2.mutable_create()->add_volumes()->CopyFrom(disk2);
+
+  EXPECT_ERROR(total.apply(create2));
 }

http://git-wip-us.apache.org/repos/asf/mesos/blob/728192a8/src/tests/sorter_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/sorter_tests.cpp b/src/tests/sorter_tests.cpp
index 56e5714..f085d80 100644
--- a/src/tests/sorter_tests.cpp
+++ b/src/tests/sorter_tests.cpp
@@ -198,7 +198,7 @@ TEST(SorterTest, SplitResourceShares)
 }
 
 
-TEST(SorterTest, Transform)
+TEST(SorterTest, Update)
 {
   DRFSorter sorter;
 
@@ -209,21 +209,22 @@ TEST(SorterTest, Transform)
 
   sorter.allocated("a", Resources::parse("cpus:10;mem:10;disk:10").get());
 
-  // Construct a transformation.
-  Resource disk = Resources::parse("disk", "5", "*").get();
-  disk.mutable_disk()->mutable_persistence()->set_id("ID");
-  disk.mutable_disk()->mutable_volume()->set_container_path("data");
+  // Construct an offer operation.
+  Resource volume = Resources::parse("disk", "5", "*").get();
+  volume.mutable_disk()->mutable_persistence()->set_id("ID");
+  volume.mutable_disk()->mutable_volume()->set_container_path("data");
 
-  Resources::AcquirePersistentDisk transformation(disk);
+  Offer::Operation create;
+  create.set_type(Offer::Operation::CREATE);
+  create.mutable_create()->add_volumes()->CopyFrom(volume);
 
   // Compute the updated allocation.
   Resources allocation = sorter.allocation("a");
-  Try<Resources> newAllocation = transformation(allocation);
-
+  Try<Resources> newAllocation = allocation.apply(create);
   ASSERT_SOME(newAllocation);
 
-  // Transform the resources for the client.
-  sorter.transform("a", allocation, newAllocation.get());
+  // Update the resources for the client.
+  sorter.update("a", allocation, newAllocation.get());
 
   EXPECT_EQ(newAllocation.get(), sorter.allocation("a"));
 }


Reply via email to