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

[7/9] mesos git commit: Fixed MULTI_ROLE related bugs when updating framework info.

Fixed MULTI_ROLE related bugs when updating framework info.

The first issue is that we need to update the capabilities member
to reflect the new capabilities.

The second issue is that when we allow an upgrade or downgrade
to or from MULTI_ROLE, we need to update the `role` and `roles`
fields of `FrameworkInfo`.

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


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

Branch: refs/heads/master
Commit: 7e976534062e221356bce96ef88718a413b734f8
Parents: 9f4dab1
Author: Benjamin Mahler <bm...@apache.org>
Authored: Thu Jan 26 14:53:50 2017 -0800
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Fri Feb 3 18:47:12 2017 -0800

----------------------------------------------------------------------
 src/master/master.hpp | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/7e976534/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index 616687f..a7e3c73 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -2409,34 +2409,35 @@ struct Framework
     // do however allow frameworks to opt in and out of `MULTI_ROLE`
     // capability, given that the `role` and `roles` field contain the
     // same number of roles.
-    if (protobuf::frameworkHasCapability(
-            source, FrameworkInfo::Capability::MULTI_ROLE) ||
-        protobuf::frameworkHasCapability(
-            info, FrameworkInfo::Capability::MULTI_ROLE)) {
+    if (capabilities.multiRole || protobuf::frameworkHasCapability(
+            source, FrameworkInfo::Capability::MULTI_ROLE)) {
       // Two `roles` sets are equivalent if they contain the same
       // elements. A `role` `*` is not equivalent to an empty `roles`
       // set, but to the set `{*}`. Since we might be dealing with a
       // framework upgrading to `MULTI_ROLE` capability or dropping
       // it, we need to examine either `role` or `roles` in order to
       // determine the roles a framework is subscribed to.
-      const std::set<std::string> newRoles =
-        protobuf::frameworkHasCapability(
-            source, FrameworkInfo::Capability::MULTI_ROLE)
-          ? std::set<std::string>(
-                {source.roles().begin(), source.roles().end()})
-          : std::set<std::string>({source.role()});
-
       const std::set<std::string> oldRoles =
-        protobuf::frameworkHasCapability(
-            info, FrameworkInfo::Capability::MULTI_ROLE)
-          ? std::set<std::string>({info.roles().begin(), info.roles().end()})
-          : std::set<std::string>({info.role()});
+        protobuf::framework::getRoles(info);
+      const std::set<std::string> newRoles =
+        protobuf::framework::getRoles(source);
 
       if (oldRoles != newRoles) {
         return Error(
             "Frameworks cannot change their roles: expected '" +
             stringify(oldRoles) + "', but got '" + stringify(newRoles) + "'");
       }
+
+      info.clear_role();
+      info.clear_roles();
+
+      if (source.has_role()) {
+        info.set_role(source.role());
+      }
+
+      if (source.roles_size() > 0) {
+        info.mutable_roles()->CopyFrom(source.roles());
+      }
     } else {
       if (source.role() != info.role()) {
         LOG(WARNING) << "Cannot update FrameworkInfo.role to '" << source.role()
@@ -2444,7 +2445,6 @@ struct Framework
       }
     }
 
-
     if (source.user() != info.user()) {
       LOG(WARNING) << "Cannot update FrameworkInfo.user to '" << source.user()
                    << "' for framework " << id() << ". Check MESOS-703";
@@ -2487,6 +2487,7 @@ struct Framework
     } else {
       info.clear_capabilities();
     }
+    capabilities = protobuf::framework::Capabilities(info.capabilities());
 
     if (source.has_labels()) {
       info.mutable_labels()->CopyFrom(source.labels());