You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bb...@apache.org on 2017/11/27 13:08:55 UTC

[2/4] mesos git commit: Added a helper to extract consumed resources from offer operations.

Added a helper to extract consumed resources from offer operations.

This patch is based on the work done in
https://reviews.apache.org/r/63104/.

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


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

Branch: refs/heads/master
Commit: e4cf0b021644fdc8b3f244c211869068385e0a38
Parents: 70f878a
Author: Benjamin Bannier <bb...@apache.org>
Authored: Mon Nov 27 12:37:37 2017 +0100
Committer: Benjamin Bannier <bb...@apache.org>
Committed: Mon Nov 27 12:37:42 2017 +0100

----------------------------------------------------------------------
 src/common/protobuf_utils.cpp | 41 ++++++++++++++++++++++++++++++++++++++
 src/common/protobuf_utils.hpp |  4 ++++
 2 files changed, 45 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e4cf0b02/src/common/protobuf_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/protobuf_utils.cpp b/src/common/protobuf_utils.cpp
index a5fc960..c1bd8b0 100644
--- a/src/common/protobuf_utils.cpp
+++ b/src/common/protobuf_utils.cpp
@@ -23,6 +23,7 @@
 #endif // __WINDOWS__
 
 #include <ostream>
+#include <vector>
 
 #include <mesos/slave/isolator.hpp>
 
@@ -56,6 +57,7 @@
 using std::ostream;
 using std::set;
 using std::string;
+using std::vector;
 
 using google::protobuf::RepeatedPtrField;
 
@@ -908,6 +910,45 @@ ContainerID getRootContainerId(const ContainerID& containerId)
   return rootContainerId;
 }
 
+
+Try<Resources> getConsumedResources(const Offer::Operation& operation)
+{
+  switch (operation.type()) {
+    case Offer::Operation::CREATE_VOLUME:
+      return operation.create_volume().source();
+    case Offer::Operation::DESTROY_VOLUME:
+      return operation.destroy_volume().volume();
+    case Offer::Operation::CREATE_BLOCK:
+      return operation.create_block().source();
+    case Offer::Operation::DESTROY_BLOCK:
+      return operation.destroy_block().block();
+    case Offer::Operation::RESERVE:
+    case Offer::Operation::UNRESERVE:
+    case Offer::Operation::CREATE:
+    case Offer::Operation::DESTROY: {
+      Try<vector<ResourceConversion>> conversions =
+        getResourceConversions(operation);
+
+      if (conversions.isError()) {
+        return Error(conversions.error());
+      }
+
+      Resources consumed;
+      foreach (const ResourceConversion& conversion, conversions.get()) {
+        consumed += conversion.consumed;
+      }
+
+      return consumed;
+    }
+    case Offer::Operation::LAUNCH:
+    case Offer::Operation::LAUNCH_GROUP:
+      // TODO(bbannier): Consider adding support for 'LAUNCH' and
+      // 'LAUNCH_GROUP' operations.
+    case Offer::Operation::UNKNOWN:
+      return Error("Unsupported operation");
+  }
+}
+
 namespace slave {
 
 bool operator==(const Capabilities& left, const Capabilities& right)

http://git-wip-us.apache.org/repos/asf/mesos/blob/e4cf0b02/src/common/protobuf_utils.hpp
----------------------------------------------------------------------
diff --git a/src/common/protobuf_utils.hpp b/src/common/protobuf_utils.hpp
index eff106f..6f991e8 100644
--- a/src/common/protobuf_utils.hpp
+++ b/src/common/protobuf_utils.hpp
@@ -38,6 +38,7 @@
 #include <stout/ip.hpp>
 #include <stout/none.hpp>
 #include <stout/option.hpp>
+#include <stout/try.hpp>
 #include <stout/uuid.hpp>
 
 #include "messages/messages.hpp"
@@ -225,6 +226,9 @@ FileInfo createFileInfo(const std::string& path, const struct stat& s);
 
 ContainerID getRootContainerId(const ContainerID& containerId);
 
+
+Try<Resources> getConsumedResources(const Offer::Operation& operation);
+
 namespace slave {
 
 // TODO(bmahler): Store the repeated field within this so that we