You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2015/09/25 02:48:06 UTC

[5/5] mesos git commit: Make common public header type_utils symmetrical to v1 mesos.

Make common public header type_utils symmetrical to v1 mesos.

This aids in verifying the files are kept in sync.
diff include/mesos/type_utils.cpp include/mesos/v1/mesos.cpp should
result in only include and namespace differences.

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


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

Branch: refs/heads/master
Commit: cad6db90392034d4e76778c4a9b24b92f8f00f3f
Parents: bd791ca
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Thu Sep 24 17:17:58 2015 -0700
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Thu Sep 24 17:47:27 2015 -0700

----------------------------------------------------------------------
 include/mesos/module/module.hpp       |  11 ++
 include/mesos/scheduler/scheduler.hpp |  18 +++
 include/mesos/type_utils.hpp          |  28 +----
 include/mesos/v1/mesos.hpp            | 196 ++++++++++++++++++++++++-----
 include/mesos/v1/mesos.proto          |  75 -----------
 5 files changed, 198 insertions(+), 130 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/cad6db90/include/mesos/module/module.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/module/module.hpp b/include/mesos/module/module.hpp
index e83be28..6ef106e 100644
--- a/include/mesos/module/module.hpp
+++ b/include/mesos/module/module.hpp
@@ -22,4 +22,15 @@
 // ONLY USEFUL AFTER RUNNING PROTOC.
 #include <mesos/module/module.pb.h>
 
+namespace mesos {
+
+inline std::ostream& operator<<(
+    std::ostream& stream,
+    const Modules& modules)
+{
+  return stream << modules.DebugString();
+}
+
+} // namespace mesos {
+
 #endif // __MESOS_MODULE_MODULE_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/cad6db90/include/mesos/scheduler/scheduler.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/scheduler/scheduler.hpp b/include/mesos/scheduler/scheduler.hpp
index 5c31191..30de72b 100644
--- a/include/mesos/scheduler/scheduler.hpp
+++ b/include/mesos/scheduler/scheduler.hpp
@@ -22,4 +22,22 @@
 // ONLY USEFUL AFTER RUNNING PROTOC.
 #include <mesos/scheduler/scheduler.pb.h>
 
+namespace mesos {
+
+inline std::ostream& operator<<(std::ostream& stream,
+                                const scheduler::Call::Type& type)
+{
+  return stream << scheduler::Call_Type_Name(type);
+}
+
+
+inline std::ostream& operator<<(
+    std::ostream& stream,
+    const scheduler::Event::Type& type)
+{
+  return stream << scheduler::Event_Type_Name(type);
+}
+
+} // namespace mesos {
+
 #endif // __SCHEDULER_PROTO_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/cad6db90/include/mesos/type_utils.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/type_utils.hpp b/include/mesos/type_utils.hpp
index 06bf55d..1076cbd 100644
--- a/include/mesos/type_utils.hpp
+++ b/include/mesos/type_utils.hpp
@@ -353,21 +353,6 @@ inline std::ostream& operator<<(std::ostream& stream, const TaskState& state)
 }
 
 
-inline std::ostream& operator<<(std::ostream& stream,
-                                const scheduler::Call::Type& type)
-{
-  return stream << scheduler::Call_Type_Name(type);
-}
-
-
-inline std::ostream& operator<<(
-    std::ostream& stream,
-    const scheduler::Event::Type& type)
-{
-  return stream << scheduler::Event_Type_Name(type);
-}
-
-
 inline std::ostream& operator<<(
     std::ostream& stream,
     const std::vector<TaskID>& taskIds)
@@ -417,12 +402,6 @@ inline std::ostream& operator<<(
 }
 
 
-inline std::ostream& operator<<(std::ostream& stream, const Modules& modules)
-{
-  return stream << modules.DebugString();
-}
-
-
 inline std::ostream& operator<<(
     std::ostream& stream,
     const hashmap<std::string, std::string>& map)
@@ -602,11 +581,11 @@ struct hash<mesos::TaskStatus_Reason>
 
 
 template <>
-struct hash<mesos::Image_Type>
+struct hash<mesos::Image::Type>
 {
   typedef size_t result_type;
 
-  typedef mesos::Image_Type argument_type;
+  typedef mesos::Image::Type argument_type;
 
   result_type operator()(const argument_type& imageType) const
   {
@@ -621,7 +600,8 @@ struct hash<std::pair<mesos::FrameworkID, mesos::ExecutorID>>
 {
   typedef size_t result_type;
 
-  typedef std::pair<mesos::FrameworkID, mesos::ExecutorID> argument_type;
+  typedef std::pair<
+      mesos::FrameworkID, mesos::ExecutorID> argument_type;
 
   result_type operator()(const argument_type& pair) const
   {

http://git-wip-us.apache.org/repos/asf/mesos/blob/cad6db90/include/mesos/v1/mesos.hpp
----------------------------------------------------------------------
diff --git a/include/mesos/v1/mesos.hpp b/include/mesos/v1/mesos.hpp
index e5a0e69..fe4c4b7 100644
--- a/include/mesos/v1/mesos.hpp
+++ b/include/mesos/v1/mesos.hpp
@@ -25,6 +25,19 @@
 
 #include <mesos/v1/mesos.pb.h> // ONLY USEFUL AFTER RUNNING PROTOC.
 
+#include <stout/strings.hpp>
+
+// This file includes definitions for operators on public protobuf
+// classes (defined in mesos.proto, module.proto, etc.) that don't
+// have these operators generated by the protobuf compiler. The
+// corresponding definitions are in src/v1/type_utils.cpp.
+//
+// Mesos modules need some of the protobuf classes defined in
+// mesos.proto, module.proto, etc., and require some of these
+// operators declared in mesos.hpp. Exposing mesos.hpp
+// allows us to build modules without having a dependency on mesos
+// source tree (src/*).
+
 namespace mesos {
 namespace v1 {
 
@@ -142,15 +155,18 @@ inline bool operator==(const TaskID& left, const std::string& right)
 }
 
 
-inline bool operator!=(const TimeInfo& left, const TimeInfo& right)
-{
-  return !(left == right);
-}
-
-
-inline bool operator!=(const DurationInfo& left, const DurationInfo& right)
+/**
+ * For machines to match, both the `hostname` and `ip` must be equivalent.
+ * Hostname is not case sensitive, so it is lowercased before comparison.
+ */
+inline bool operator==(const MachineID& left, const MachineID& right)
 {
-  return !(left == right);
+  // NOTE: Both fields default to the empty string if they are not specified,
+  // so the string comparisons are safe.
+  return left.has_hostname() == right.has_hostname() &&
+    strings::lower(left.hostname()) == strings::lower(right.hostname()) &&
+    left.has_ip() == right.has_ip() &&
+    left.ip() == right.ip();
 }
 
 
@@ -178,6 +194,18 @@ inline bool operator!=(const AgentID& left, const AgentID& right)
 }
 
 
+inline bool operator!=(const TimeInfo& left, const TimeInfo& right)
+{
+  return !(left == right);
+}
+
+
+inline bool operator!=(const DurationInfo& left, const DurationInfo& right)
+{
+  return !(left == right);
+}
+
+
 inline bool operator<(const ContainerID& left, const ContainerID& right)
 {
   return left.value() < right.value();
@@ -214,12 +242,6 @@ inline bool operator<(const TaskID& left, const TaskID& right)
 }
 
 
-inline std::ostream& operator<<(std::ostream& stream, const ACLs& acls)
-{
-  return stream << acls.DebugString();
-}
-
-
 inline std::ostream& operator<<(
     std::ostream& stream,
     const ContainerID& containerId)
@@ -260,23 +282,6 @@ inline std::ostream& operator<<(
 }
 
 
-inline std::ostream& operator<<(
-    std::ostream& stream,
-    const MachineID& machineId)
-{
-  if (machineId.has_hostname() && machineId.has_ip()) {
-    return stream << machineId.hostname() << " (" << machineId.ip() << ")";
-  }
-
-  // If only a hostname is present.
-  if (machineId.has_hostname()) {
-    return stream << machineId.hostname();
-  } else { // If there is no hostname, then there is an IP.
-    return stream << "(" << machineId.ip() << ")";
-  }
-}
-
-
 inline std::ostream& operator<<(std::ostream& stream, const MasterInfo& master)
 {
   return stream << master.DebugString();
@@ -313,6 +318,23 @@ inline std::ostream& operator<<(std::ostream& stream, const TaskID& taskId)
 }
 
 
+inline std::ostream& operator<<(
+    std::ostream& stream,
+    const MachineID& machineId)
+{
+  if (machineId.has_hostname() && machineId.has_ip()) {
+    return stream << machineId.hostname() << " (" << machineId.ip() << ")";
+  }
+
+  // If only a hostname is present.
+  if (machineId.has_hostname()) {
+    return stream << machineId.hostname();
+  } else { // If there is no hostname, then there is an IP.
+    return stream << "(" << machineId.ip() << ")";
+  }
+}
+
+
 inline std::ostream& operator<<(std::ostream& stream, const TaskInfo& task)
 {
   return stream << task.DebugString();
@@ -349,6 +371,14 @@ inline std::ostream& operator<<(
 }
 
 
+inline std::ostream& operator<<(
+    std::ostream& stream,
+    const Image::Type& imageType)
+{
+  return stream << Image::Type_Name(imageType);
+}
+
+
 template <typename T>
 inline std::ostream& operator<<(
     std::ostream& stream,
@@ -365,6 +395,15 @@ inline std::ostream& operator<<(
   return stream;
 }
 
+
+inline std::ostream& operator<<(
+    std::ostream& stream,
+    const hashmap<std::string, std::string>& map)
+{
+  stream << stringify(map);
+  return stream;
+}
+
 } // namespace v1 {
 } // namespace mesos {
 
@@ -490,6 +529,101 @@ struct hash<mesos::v1::TaskID>
   }
 };
 
+
+template <>
+struct hash<mesos::v1::TaskState>
+{
+  typedef size_t result_type;
+
+  typedef mesos::v1::TaskState argument_type;
+
+  result_type operator()(const argument_type& taskState) const
+  {
+    // Use the underlying type of the enum as hash value.
+    return static_cast<size_t>(taskState);
+  }
+};
+
+
+template <>
+struct hash<mesos::v1::TaskStatus_Source>
+{
+  typedef size_t result_type;
+
+  typedef mesos::v1::TaskStatus_Source argument_type;
+
+  result_type operator()(const argument_type& source) const
+  {
+    // Use the underlying type of the enum as hash value.
+    return static_cast<size_t>(source);
+  }
+};
+
+
+template <>
+struct hash<mesos::v1::TaskStatus_Reason>
+{
+  typedef size_t result_type;
+
+  typedef mesos::v1::TaskStatus_Reason argument_type;
+
+  result_type operator()(const argument_type& reason) const
+  {
+    // Use the underlying type of the enum as hash value.
+    return static_cast<size_t>(reason);
+  }
+};
+
+
+template <>
+struct hash<mesos::v1::Image::Type>
+{
+  typedef size_t result_type;
+
+  typedef mesos::v1::Image::Type argument_type;
+
+  result_type operator()(const argument_type& imageType) const
+  {
+    // Use the underlying type of the enum as hash value.
+    return static_cast<size_t>(imageType);
+  }
+};
+
+
+template <>
+struct hash<std::pair<mesos::v1::FrameworkID, mesos::v1::ExecutorID>>
+{
+  typedef size_t result_type;
+
+  typedef std::pair<
+      mesos::v1::FrameworkID, mesos::v1::ExecutorID> argument_type;
+
+  result_type operator()(const argument_type& pair) const
+  {
+    size_t seed = 0;
+    boost::hash_combine(seed, std::hash<mesos::v1::FrameworkID>()(pair.first));
+    boost::hash_combine(seed, std::hash<mesos::v1::ExecutorID>()(pair.second));
+    return seed;
+  }
+};
+
+
+template <>
+struct hash<mesos::v1::MachineID>
+{
+  typedef size_t result_type;
+
+  typedef mesos::v1::MachineID argument_type;
+
+  result_type operator()(const argument_type& machineId) const
+  {
+    size_t seed = 0;
+    boost::hash_combine(seed, strings::lower(machineId.hostname()));
+    boost::hash_combine(seed, machineId.ip());
+    return seed;
+  }
+};
+
 } // namespace std {
 
 #endif // __MESOS_V1_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/cad6db90/include/mesos/v1/mesos.proto
----------------------------------------------------------------------
diff --git a/include/mesos/v1/mesos.proto b/include/mesos/v1/mesos.proto
index 58e5a6b..eadbc9d 100644
--- a/include/mesos/v1/mesos.proto
+++ b/include/mesos/v1/mesos.proto
@@ -1222,81 +1222,6 @@ message Credentials {
 
 
 /**
- * ACLs used for authorization.
- */
-message ACL {
-
-  // Entity is used to describe a subject(s) or an object(s) of an ACL.
-  // NOTE:
-  // To allow everyone access to an Entity set its type to 'ANY'.
-  // To deny access to an Entity set its type to 'NONE'.
-  message Entity {
-    enum Type {
-      SOME = 0;
-      ANY = 1;
-      NONE = 2;
-    }
-    optional Type type = 1 [default = SOME];
-    repeated string values = 2; // Ignored for ANY/NONE.
-  }
-
-  // ACLs.
-  message RegisterFramework {
-    // Subjects.
-    required Entity principals = 1; // Framework principals.
-
-    // Objects.
-    required Entity roles = 2; // Roles for resource offers.
-  }
-
-  message RunTask {
-    // Subjects.
-    required Entity principals = 1; // Framework principals.
-
-    // Objects.
-    required Entity users = 2; // Users to run the tasks/executors as.
-  }
-
-  // Which principals are authorized to shutdown frameworks of other
-  // principals.
-  message ShutdownFramework {
-    // Subjects.
-    required Entity principals = 1;
-
-    // Objects.
-    required Entity framework_principals = 2;
-  }
-}
-
-
-/**
- * Collection of ACL.
- *
- * Each authorization request is evaluated against the ACLs in the order
- * they are defined.
- *
- * For simplicity, the ACLs for a given action are not aggregated even
- * when they have the same subjects or objects. The first ACL that
- * matches the request determines whether that request should be
- * permitted or not. An ACL matches iff both the subjects
- * (e.g., clients, principals) and the objects (e.g., urls, users,
- * roles) of the ACL match the request.
- *
- * If none of the ACLs match the request, the 'permissive' field
- * determines whether the request should be permitted or not.
- *
- * TODO(vinod): Do aggregation of ACLs when possible.
- *
- */
-message ACLs {
-  optional bool permissive = 1 [default = true];
-  repeated ACL.RegisterFramework register_frameworks = 2;
-  repeated ACL.RunTask run_tasks = 3;
-  repeated ACL.ShutdownFramework shutdown_frameworks = 4;
-}
-
-
-/**
  * Rate (queries per second, QPS) limit for messages from a framework to master.
  * Strictly speaking they are the combined rate from all frameworks of the same
  * principal.