You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mp...@apache.org on 2018/01/08 18:09:07 UTC

[1/2] mesos git commit: Updated the comment for `precomputeResourcesContainment`.

Repository: mesos
Updated Branches:
  refs/heads/master 87629bf32 -> 8be2b0f58


Updated the comment for `precomputeResourcesContainment`.

`precomputeResourcesContainment` used return a `bool`, but was modified
to return `void` since the `bool` is already included in the `result`.
This fixes the corresponding comment that was not adjusted accordingly.

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


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

Branch: refs/heads/master
Commit: 02eefa2c74e19708a0fe3b9e1d0011b152e01ea6
Parents: 87629bf
Author: Michael Park <mp...@apache.org>
Authored: Wed Jan 3 10:56:32 2018 -0800
Committer: Michael Park <mp...@apache.org>
Committed: Mon Jan 8 10:08:00 2018 -0800

----------------------------------------------------------------------
 src/common/resources_utils.cpp | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/02eefa2c/src/common/resources_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources_utils.cpp b/src/common/resources_utils.cpp
index bd9e025..be52b31 100644
--- a/src/common/resources_utils.cpp
+++ b/src/common/resources_utils.cpp
@@ -770,12 +770,10 @@ Try<Nothing> downgradeResources(RepeatedPtrField<Resource>* resources)
 
 namespace internal {
 
-// Given a protobuf descriptor `descriptor`, returns `true` if `descriptor`
-// is a `mesos::Resource`, or contains a `mesos::Resource` somewhere within.
-//
-// The provided `result` is recursively populated, where the keys are the
-// message descriptors within `descriptor`'s schema (including itself), and
-//  the corresponding value is `true` if the key contains a `mesos::Resource`.
+// Given a protobuf descriptor `descriptor`, recursively populates the provided
+// `result` where the keys are the message descriptors within `descriptor`'s
+// schema (including itself), and the corresponding value is `true` if the key
+// contains a `mesos::Resource`, and `false` otherwise.
 static void precomputeResourcesContainment(
     const Descriptor* descriptor,
     hashmap<const Descriptor*, bool>* result)


[2/2] mesos git commit: Introduced `upgradeResources` to complement `downgradeResources`.

Posted by mp...@apache.org.
Introduced `upgradeResources` to complement `downgradeResources`.

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


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

Branch: refs/heads/master
Commit: 8be2b0f585f0e00d0ab62547fccd0cd160454a07
Parents: 02eefa2
Author: Michael Park <mp...@apache.org>
Authored: Wed Jan 3 10:58:20 2018 -0800
Committer: Michael Park <mp...@apache.org>
Committed: Mon Jan 8 10:08:09 2018 -0800

----------------------------------------------------------------------
 src/common/resources_utils.cpp | 277 ++++++++++++++----------------------
 src/common/resources_utils.hpp |  10 +-
 2 files changed, 115 insertions(+), 172 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/8be2b0f5/src/common/resources_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/resources_utils.cpp b/src/common/resources_utils.cpp
index be52b31..967cfd7 100644
--- a/src/common/resources_utils.cpp
+++ b/src/common/resources_utils.cpp
@@ -390,112 +390,133 @@ void convertResourceFormat(
 }
 
 
-void upgradeResources(Offer::Operation* operation)
+namespace internal {
+
+// Given a protobuf descriptor `descriptor`, recursively populates the provided
+// `result` where the keys are the message descriptors within `descriptor`'s
+// schema (including itself), and the corresponding value is `true` if the key
+// contains a `mesos::Resource`, and `false` otherwise.
+static void precomputeResourcesContainment(
+    const Descriptor* descriptor,
+    hashmap<const Descriptor*, bool>* result)
 {
-  CHECK_NOTNULL(operation);
+  CHECK_NOTNULL(descriptor);
+  CHECK_NOTNULL(result);
 
-  switch (operation->type()) {
-    case Offer::Operation::RESERVE: {
-      convertResourceFormat(
-          operation->mutable_reserve()->mutable_resources(),
-          POST_RESERVATION_REFINEMENT);
+  if (result->contains(descriptor)) {
+    return;
+  }
 
-      return;
-    }
-    case Offer::Operation::UNRESERVE: {
-      convertResourceFormat(
-          operation->mutable_unreserve()->mutable_resources(),
-          POST_RESERVATION_REFINEMENT);
+  if (descriptor == mesos::Resource::descriptor()) {
+    result->insert({descriptor, true});
+  }
 
-      return;
+  result->insert({descriptor, false});
+  for (int i = 0; i < descriptor->field_count(); ++i) {
+    // `message_type()` returns `nullptr` if the field is not a message type.
+    const Descriptor* messageDescriptor = descriptor->field(i)->message_type();
+    if (messageDescriptor == nullptr) {
+      continue;
     }
-    case Offer::Operation::CREATE: {
-      convertResourceFormat(
-          operation->mutable_create()->mutable_volumes(),
-          POST_RESERVATION_REFINEMENT);
+    precomputeResourcesContainment(messageDescriptor, result);
+    result->at(descriptor) |= result->at(messageDescriptor);
+  }
+}
 
-      return;
-    }
-    case Offer::Operation::DESTROY: {
-      convertResourceFormat(
-          operation->mutable_destroy()->mutable_volumes(),
-          POST_RESERVATION_REFINEMENT);
 
-      return;
-    }
-    case Offer::Operation::LAUNCH: {
-      foreach (
-          TaskInfo& task, *operation->mutable_launch()->mutable_task_infos()) {
-        convertResourceFormat(
-            task.mutable_resources(),
-            POST_RESERVATION_REFINEMENT);
+static Try<Nothing> convertResourcesImpl(
+    Message* message,
+    Try<Nothing> (*convertResource)(mesos::Resource* resource),
+    const hashmap<const Descriptor*, bool>& resourcesContainment)
+{
+  CHECK_NOTNULL(message);
 
-        if (task.has_executor()) {
-          convertResourceFormat(
-              task.mutable_executor()->mutable_resources(),
-              POST_RESERVATION_REFINEMENT);
-        }
-      }
+  const Descriptor* descriptor = message->GetDescriptor();
+
+  if (descriptor == mesos::Resource::descriptor()) {
+    return convertResource(static_cast<mesos::Resource*>(message));
+  }
 
-      return;
+  const google::protobuf::Reflection* reflection = message->GetReflection();
+
+  for (int i = 0; i < descriptor->field_count(); ++i) {
+    const google::protobuf::FieldDescriptor* field = descriptor->field(i);
+    const Descriptor* messageDescriptor = field->message_type();
+
+    if (messageDescriptor == nullptr ||
+        !resourcesContainment.at(messageDescriptor)) {
+      continue;
     }
-    case Offer::Operation::LAUNCH_GROUP: {
-      Offer::Operation::LaunchGroup* launchGroup =
-        operation->mutable_launch_group();
 
-      if (launchGroup->has_executor()) {
-        convertResourceFormat(
-            launchGroup->mutable_executor()->mutable_resources(),
-            POST_RESERVATION_REFINEMENT);
+    if (!field->is_repeated()) {
+      if (reflection->HasField(*message, field)) {
+        Try<Nothing> result = convertResourcesImpl(
+            reflection->MutableMessage(message, field),
+            convertResource,
+            resourcesContainment);
+
+        if (result.isError()) {
+          return result;
+        }
       }
+    } else {
+      const int size = reflection->FieldSize(*message, field);
 
-      foreach (
-          TaskInfo& task, *launchGroup->mutable_task_group()->mutable_tasks()) {
-        convertResourceFormat(
-            task.mutable_resources(), POST_RESERVATION_REFINEMENT);
+      for (int j = 0; j < size; ++j) {
+        Try<Nothing> result = convertResourcesImpl(
+            reflection->MutableRepeatedMessage(message, field, j),
+            convertResource,
+            resourcesContainment);
 
-        if (task.has_executor()) {
-          convertResourceFormat(
-              task.mutable_executor()->mutable_resources(),
-              POST_RESERVATION_REFINEMENT);
+        if (result.isError()) {
+          return result;
         }
       }
-
-      return;
     }
-    case Offer::Operation::CREATE_VOLUME: {
-      convertResourceFormat(
-          operation->mutable_create_volume()->mutable_source(),
-          POST_RESERVATION_REFINEMENT);
+  }
 
-      return;
-    }
-    case Offer::Operation::DESTROY_VOLUME: {
-      convertResourceFormat(
-          operation->mutable_destroy_volume()->mutable_volume(),
-          POST_RESERVATION_REFINEMENT);
+  return Nothing();
+}
 
-      return;
-    }
-    case Offer::Operation::CREATE_BLOCK: {
-      convertResourceFormat(
-          operation->mutable_create_block()->mutable_source(),
-          POST_RESERVATION_REFINEMENT);
+}  // namespace internal {
 
-      return;
-    }
-    case Offer::Operation::DESTROY_BLOCK: {
-      convertResourceFormat(
-          operation->mutable_destroy_block()->mutable_block(),
-          POST_RESERVATION_REFINEMENT);
 
-      return;
-    }
-    case Offer::Operation::UNKNOWN: {
-      return;
-    }
+void upgradeResource(Resource* resource)
+{
+  convertResourceFormat(resource, POST_RESERVATION_REFINEMENT);
+}
+
+
+void upgradeResources(RepeatedPtrField<Resource>* resources)
+{
+  CHECK_NOTNULL(resources);
+
+  foreach (Resource& resource, *resources) {
+    upgradeResource(&resource);
   }
-  UNREACHABLE();
+}
+
+
+void upgradeResources(Message* message)
+{
+  CHECK_NOTNULL(message);
+
+  const Descriptor* descriptor = message->GetDescriptor();
+
+  hashmap<const Descriptor*, bool> resourcesContainment;
+  internal::precomputeResourcesContainment(descriptor, &resourcesContainment);
+
+  if (!resourcesContainment.at(descriptor)) {
+    return;
+  }
+
+  internal::convertResourcesImpl(
+      message,
+      [](Resource* resource) -> Try<Nothing> {
+        upgradeResource(resource);
+        return Nothing();
+      },
+      resourcesContainment);
 }
 
 
@@ -768,91 +789,6 @@ Try<Nothing> downgradeResources(RepeatedPtrField<Resource>* resources)
   return Nothing();
 }
 
-namespace internal {
-
-// Given a protobuf descriptor `descriptor`, recursively populates the provided
-// `result` where the keys are the message descriptors within `descriptor`'s
-// schema (including itself), and the corresponding value is `true` if the key
-// contains a `mesos::Resource`, and `false` otherwise.
-static void precomputeResourcesContainment(
-    const Descriptor* descriptor,
-    hashmap<const Descriptor*, bool>* result)
-{
-  CHECK_NOTNULL(descriptor);
-  CHECK_NOTNULL(result);
-
-  if (result->contains(descriptor)) {
-    return;
-  }
-
-  if (descriptor == mesos::Resource::descriptor()) {
-    result->insert({descriptor, true});
-  }
-
-  result->insert({descriptor, false});
-  for (int i = 0; i < descriptor->field_count(); ++i) {
-    // `message_type()` returns `nullptr` if the field is not a message type.
-    const Descriptor* messageDescriptor = descriptor->field(i)->message_type();
-    if (messageDescriptor == nullptr) {
-      continue;
-    }
-    precomputeResourcesContainment(messageDescriptor, result);
-    result->at(descriptor) |= result->at(messageDescriptor);
-  }
-}
-
-
-static Try<Nothing> downgradeResourcesImpl(
-    Message* message,
-    const hashmap<const Descriptor*, bool>& resourcesContainment)
-{
-  CHECK_NOTNULL(message);
-
-  const Descriptor* descriptor = message->GetDescriptor();
-
-  if (descriptor == mesos::Resource::descriptor()) {
-    return downgradeResource(static_cast<mesos::Resource*>(message));
-  }
-
-  const google::protobuf::Reflection* reflection = message->GetReflection();
-
-  for (int i = 0; i < descriptor->field_count(); ++i) {
-    const google::protobuf::FieldDescriptor* field = descriptor->field(i);
-    const Descriptor* messageDescriptor = field->message_type();
-
-    if (messageDescriptor == nullptr ||
-        !resourcesContainment.at(messageDescriptor)) {
-      continue;
-    }
-
-    if (!field->is_repeated()) {
-      if (reflection->HasField(*message, field)) {
-        Try<Nothing> result = downgradeResourcesImpl(
-            reflection->MutableMessage(message, field), resourcesContainment);
-
-        if (result.isError()) {
-          return result;
-        }
-      }
-    } else {
-      const int size = reflection->FieldSize(*message, field);
-
-      for (int j = 0; j < size; ++j) {
-        Try<Nothing> result = downgradeResourcesImpl(
-            reflection->MutableRepeatedMessage(message, field, j),
-            resourcesContainment);
-
-        if (result.isError()) {
-          return result;
-        }
-      }
-    }
-  }
-
-  return Nothing();
-}
-
-}  // namespace internal {
 
 Try<Nothing> downgradeResources(Message* message)
 {
@@ -867,7 +803,8 @@ Try<Nothing> downgradeResources(Message* message)
     return Nothing();
   }
 
-  return internal::downgradeResourcesImpl(message, resourcesContainment);
+  return internal::convertResourcesImpl(
+      message, downgradeResource, resourcesContainment);
 }
 
 } // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/8be2b0f5/src/common/resources_utils.hpp
----------------------------------------------------------------------
diff --git a/src/common/resources_utils.hpp b/src/common/resources_utils.hpp
index ea0b18c..611e267 100644
--- a/src/common/resources_utils.hpp
+++ b/src/common/resources_utils.hpp
@@ -158,9 +158,15 @@ void convertResourceFormat(
     ResourceFormat format);
 
 
-// Convert any resources contained in the given offer operation
+// Convert any resources contained in the given message(s)
 // to the "post-reservation-refinement" format.
-void upgradeResources(Offer::Operation* operation);
+void upgradeResource(Resource* resource);
+
+
+void upgradeResources(google::protobuf::RepeatedPtrField<Resource>* resources);
+
+
+void upgradeResources(google::protobuf::Message* message);
 
 
 // Convert the resources in the given `Operation` to the