You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by as...@apache.org on 2020/08/25 14:35:10 UTC

[mesos] 02/03: Implemented offer constraints on a string attribute equality.

This is an automated email from the ASF dual-hosted git repository.

asekretenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit 5e5d6832b196a450cad55a16cfb202256bef5b37
Author: Andrei Sekretenko <as...@apache.org>
AuthorDate: Mon Aug 3 18:35:06 2020 +0200

    Implemented offer constraints on a string attribute equality.
    
    Review: https://reviews.apache.org/r/72775
---
 .../allocator/mesos/offer_constraints_filter.cpp   | 49 ++++++++++++++++++++--
 1 file changed, 45 insertions(+), 4 deletions(-)

diff --git a/src/master/allocator/mesos/offer_constraints_filter.cpp b/src/master/allocator/mesos/offer_constraints_filter.cpp
index ef8a948..d724fd0 100644
--- a/src/master/allocator/mesos/offer_constraints_filter.cpp
+++ b/src/master/allocator/mesos/offer_constraints_filter.cpp
@@ -87,6 +87,15 @@ public:
         return Self(Exists{});
       case AttributeConstraint::Predicate::kNotExists:
         return Self(NotExists{});
+
+      case AttributeConstraint::Predicate::kTextEquals:
+        return Self(TextEquals{
+          std::move(*predicate.mutable_text_equals()->mutable_value())});
+
+      case AttributeConstraint::Predicate::kTextNotEquals:
+        return Self(TextNotEquals{
+          std::move(*predicate.mutable_text_not_equals()->mutable_value())});
+
       case AttributeConstraint::Predicate::PREDICATE_NOT_SET:
         return Error("Unknown predicate type");
     }
@@ -113,9 +122,39 @@ private:
     bool apply(const Attribute&) const { return false; }
   };
 
-  // TODO(asekretenko): Introduce offer constraints for attribute equality
-  // (MESOS-10172) and regex match (MESOS-10173).
-  using Predicate = Variant<Nothing, Exists, NotExists>;
+  struct TextEquals
+  {
+    string value;
+
+    bool apply(const Nothing&) const { return false; }
+    bool apply(const string& str) const { return str == value; }
+    bool apply(const Attribute& attr) const
+    {
+      return attr.type() != Value::TEXT || attr.text().value() == value;
+    }
+  };
+
+  struct TextNotEquals
+  {
+    string value;
+
+    bool apply(const Nothing&) const { return true; }
+    bool apply(const string& str) const { return str != value; }
+    bool apply(const Attribute& attr) const
+    {
+      return attr.type() != Value::TEXT || attr.text().value() != value;
+    }
+  };
+
+  // TODO(asekretenko): Introduce offer constraints for regex match
+  // (MESOS-10173).
+
+  using Predicate = Variant<
+      Nothing,
+      Exists,
+      NotExists,
+      TextEquals,
+      TextNotEquals>;
 
   Predicate predicate;
 
@@ -130,7 +169,9 @@ private:
           UNREACHABLE();
         },
         [&](const Exists& p) { return p.apply(attribute); },
-        [&](const NotExists& p) { return p.apply(attribute); });
+        [&](const NotExists& p) { return p.apply(attribute); },
+        [&](const TextEquals& p) { return p.apply(attribute); },
+        [&](const TextNotEquals& p) { return p.apply(attribute); });
   }
 };