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

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

commit f05f0616841bd539a8b6abfc591f3c287ad998d9
Author: Meng Zhu <[email protected]>
AuthorDate: Tue Jun 4 17:34:52 2019 -0700

    Added a wrapper struct for quota guarantees and limits.
    
    This struct is temporarily named to `Quota2` to differentiate
    with the existing `Quota` struct. It will replace all `Quota`
    and rename to `Quota`.
    
    Review: https://reviews.apache.org/r/70799
---
 include/mesos/quota/quota.hpp | 23 ++++++++++++++++++++
 src/master/quota.cpp          | 50 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+)

diff --git a/include/mesos/quota/quota.hpp b/include/mesos/quota/quota.hpp
index b028e12..edfd1c0 100644
--- a/include/mesos/quota/quota.hpp
+++ b/include/mesos/quota/quota.hpp
@@ -17,6 +17,8 @@
 #ifndef __MESOS_QUOTA_PROTO_HPP__
 #define __MESOS_QUOTA_PROTO_HPP__
 
+#include <mesos/resource_quantities.hpp>
+
 // ONLY USEFUL AFTER RUNNING PROTOC.
 #include <mesos/quota/quota.pb.h>
 
@@ -28,4 +30,25 @@ struct Quota
   mesos::quota::QuotaInfo info;
 };
 
+
+namespace mesos {
+
+// TODO(mzhu): replace `struct Quota` above.
+struct Quota2
+{
+  ResourceQuantities guarantees;
+  ResourceLimits limits;
+
+  Quota2() {};
+
+  Quota2(const mesos::quota::QuotaConfig& config);
+  Quota2(const mesos::quota::QuotaInfo& info);
+  Quota2(const mesos::quota::QuotaRequest& request);
+
+  bool operator==(const Quota2& quota) const;
+  bool operator!=(const Quota2& quota) const;
+};
+
+} // namespace mesos {
+
 #endif // __MESOS_QUOTA_PROTO_HPP__
diff --git a/src/master/quota.cpp b/src/master/quota.cpp
index 001c240..4f2a59c 100644
--- a/src/master/quota.cpp
+++ b/src/master/quota.cpp
@@ -19,6 +19,7 @@
 #include <string>
 
 #include <mesos/mesos.hpp>
+#include <mesos/quota/quota.hpp>
 #include <mesos/resource_quantities.hpp>
 #include <mesos/resources.hpp>
 #include <mesos/roles.hpp>
@@ -237,4 +238,53 @@ Option<Error> validate(const QuotaConfig& config)
 } // namespace quota {
 } // namespace master {
 } // namespace internal {
+
+Quota2::Quota2(const QuotaConfig& config)
+{
+  guarantees = ResourceQuantities(config.guarantees());
+  limits = ResourceLimits(config.limits());
+}
+
+
+Quota2::Quota2(const QuotaInfo& info)
+{
+  guarantees = ResourceQuantities::fromScalarResources(info.guarantee());
+
+  // For legacy `QuotaInfo`, guarantee also acts as limit.
+  limits = [&info]() {
+    google::protobuf::Map<string, Value::Scalar> limits;
+    foreach (const Resource& r, info.guarantee()) {
+      limits[r.name()] = r.scalar();
+    }
+    return ResourceLimits(limits);
+  }();
+}
+
+
+Quota2::Quota2(const QuotaRequest& request)
+{
+  guarantees = ResourceQuantities::fromScalarResources(request.guarantee());
+
+  // For legacy `QuotaInfo`, guarantee also acts as limit.
+  limits = [&request]() {
+    google::protobuf::Map<string, Value::Scalar> limits;
+    foreach (const Resource& r, request.guarantee()) {
+      limits[r.name()] = r.scalar();
+    }
+    return ResourceLimits(limits);
+  }();
+}
+
+
+bool Quota2::operator==(const Quota2& that) const
+{
+  return guarantees == that.guarantees && limits == that.limits;
+}
+
+
+bool Quota2::operator!=(const Quota2& that) const
+{
+  return guarantees != that.guarantees || limits != that.limits;
+}
+
 } // namespace mesos {

Reply via email to