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

[05/14] mesos git commit: Added a helper to get the resoruce provider ID from an offer operation.

Added a helper to get the resoruce provider ID from an offer operation.

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


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

Branch: refs/heads/master
Commit: 9cdac390632831777632a0d437a51654ff2f4759
Parents: 88dbbce
Author: Jie Yu <yu...@gmail.com>
Authored: Mon Oct 30 13:56:09 2017 +0100
Committer: Jie Yu <yu...@gmail.com>
Committed: Mon Nov 6 14:37:26 2017 -0800

----------------------------------------------------------------------
 src/common/resources_utils.cpp | 48 +++++++++++++++++++++++++++++++++++++
 src/common/resources_utils.hpp |  9 +++++++
 2 files changed, 57 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/9cdac390/src/common/resources_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources_utils.cpp b/src/common/resources_utils.cpp
index e34cd8a..8304da4 100644
--- a/src/common/resources_utils.cpp
+++ b/src/common/resources_utils.cpp
@@ -91,6 +91,54 @@ Try<Resources> applyCheckpointedResources(
 }
 
 
+Result<ResourceProviderID> getResourceProviderId(
+    const Offer::Operation& operation)
+{
+  Option<Resource> resource;
+
+  switch (operation.type()) {
+    case Offer::Operation::LAUNCH:
+      return Error("Unexpected LAUNCH operation");
+    case Offer::Operation::LAUNCH_GROUP:
+      return Error("Unexpected LAUNCH_GROUP operation");
+    case Offer::Operation::RESERVE:
+      resource = operation.reserve().resources(0);
+      break;
+    case Offer::Operation::UNRESERVE:
+      resource = operation.unreserve().resources(0);
+      break;
+    case Offer::Operation::CREATE:
+      resource = operation.create().volumes(0);
+      break;
+    case Offer::Operation::DESTROY:
+      resource = operation.destroy().volumes(0);
+      break;
+    case Offer::Operation::CREATE_VOLUME:
+      resource = operation.create_volume().source();
+      break;
+    case Offer::Operation::DESTROY_VOLUME:
+      resource = operation.destroy_volume().volume();
+      break;
+    case Offer::Operation::CREATE_BLOCK:
+      resource = operation.create_block().source();
+      break;
+    case Offer::Operation::DESTROY_BLOCK:
+      resource = operation.destroy_block().block();
+      break;
+    case Offer::Operation::UNKNOWN:
+      return Error("Unknown offer operation");
+  }
+
+  CHECK_SOME(resource);
+
+  if (resource->has_provider_id()) {
+    return resource->provider_id();
+  }
+
+  return None();
+}
+
+
 void convertResourceFormat(Resource* resource, ResourceFormat format)
 {
   switch (format) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/9cdac390/src/common/resources_utils.hpp
----------------------------------------------------------------------
diff --git a/src/common/resources_utils.hpp b/src/common/resources_utils.hpp
index 18e3d9d..b8c29b3 100644
--- a/src/common/resources_utils.hpp
+++ b/src/common/resources_utils.hpp
@@ -46,6 +46,15 @@ Try<Resources> applyCheckpointedResources(
     const Resources& checkpointedResources);
 
 
+// Returns the resource provider ID associated with the given
+// operation. Returns None() if the operation is for agent default
+// resources. We assume the given operation is validated. Therefore,
+// the specified operation should not contain resources from more than
+// one resource provider.
+Result<ResourceProviderID> getResourceProviderId(
+    const Offer::Operation& operation);
+
+
 // Resource format options to be used with the `convertResourceFormat` function.
 //
 // The preconditions of the options are asymmetric, centered around the