You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2015/03/13 02:30:10 UTC

[1/2] mesos git commit: Fixed protobuf comparisons by accounting for new fields.

Repository: mesos
Updated Branches:
  refs/heads/master 0c7104d4d -> 8385bbaf4


Fixed protobuf comparisons by accounting for new fields.

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


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

Branch: refs/heads/master
Commit: 8385bbaf47c5a5f03a12e595356f56768e452727
Parents: 0d272b5
Author: Vinod Kone <vi...@gmail.com>
Authored: Tue Mar 10 10:32:53 2015 -0700
Committer: Vinod Kone <vi...@gmail.com>
Committed: Thu Mar 12 18:29:54 2015 -0700

----------------------------------------------------------------------
 src/common/type_utils.cpp | 249 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 234 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/8385bbaf/src/common/type_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/type_utils.cpp b/src/common/type_utils.cpp
index 48fa56d..c946991 100644
--- a/src/common/type_utils.cpp
+++ b/src/common/type_utils.cpp
@@ -26,12 +26,16 @@
 
 namespace mesos {
 
+// TODO(vinod): Ensure that these operators do not go out of sync
+// when new fields are added to the protobufs (MESOS-2487).
+
 bool operator == (const CommandInfo& left, const CommandInfo& right)
 {
   if (left.uris().size() != right.uris().size()) {
     return false;
   }
 
+  // TODO(vinod): Factor out the comparison for repeated fields.
   for (int i = 0; i < left.uris().size(); i++) {
     bool found = false;
     for (int j = 0; j < right.uris().size(); j++) {
@@ -56,16 +60,22 @@ bool operator == (const CommandInfo& left, const CommandInfo& right)
     }
   }
 
+  // NOTE: We are not validating CommandInfo::ContainerInfo here
+  // because it is being deprecated in favor of ContainerInfo.
+  // TODO(vinod): Kill the above comment when
+  // CommandInfo::ContainerInfo is removed.
   return left.environment() == right.environment() &&
     left.value() == right.value() &&
+    left.user() == right.user() &&
     left.shell() == right.shell();
 }
 
 
 bool operator == (const CommandInfo::URI& left, const CommandInfo::URI& right)
 {
-  return left.executable() == right.executable() &&
-    left.value() == right.value();
+  return left.value() == right.value() &&
+    left.executable() == right.executable() &&
+    left.extract() == right.extract();
 }
 
 
@@ -76,19 +86,184 @@ bool operator == (const Credential& left, const Credential& right)
 }
 
 
+bool operator == (
+    const Environment::Variable& left,
+    const Environment::Variable& right)
+{
+  return left.name() == right.name() && left.value() == right.value();
+}
+
+
 bool operator == (const Environment& left, const Environment& right)
 {
+  // Order of variables is not important.
   if (left.variables().size() != right.variables().size()) {
     return false;
   }
 
   for (int i = 0; i < left.variables().size(); i++) {
-    const std::string& name = left.variables().Get(i).name();
-    const std::string& value = left.variables().Get(i).value();
     bool found = false;
     for (int j = 0; j < right.variables().size(); j++) {
-      if (name == right.variables().Get(j).name() &&
-          value == right.variables().Get(j).value()) {
+      if (left.variables().Get(i) == right.variables().Get(j)) {
+        found = true;
+        break;
+      }
+    }
+    if (!found) {
+      return false;
+    }
+  }
+
+  return true;
+}
+
+
+bool operator == (const Volume& left, const Volume& right)
+{
+  return left.container_path() == right.container_path() &&
+    left.host_path() == right.host_path() &&
+    left.mode() == right.mode();
+}
+
+
+bool operator == (
+    const ContainerInfo::DockerInfo::PortMapping& left,
+    const ContainerInfo::DockerInfo::PortMapping& right)
+{
+  return left.host_port() == right.host_port() &&
+    left.container_port() == right.container_port() &&
+    left.protocol() == right.protocol();
+}
+
+
+bool operator == (const Parameter& left, const Parameter& right)
+{
+  return left.key() == right.key() && left.value() == right.value();
+}
+
+
+bool operator == (
+    const ContainerInfo::DockerInfo& left,
+    const ContainerInfo::DockerInfo& right)
+{
+  // Order of port mappings is not important.
+  if (left.port_mappings().size() != right.port_mappings().size()) {
+    return false;
+  }
+
+  for (int i = 0; i < left.port_mappings().size(); i++) {
+    bool found = false;
+    for (int j = 0; j < right.port_mappings().size(); j++) {
+      if (left.port_mappings().Get(i) == right.port_mappings().Get(j)) {
+        found = true;
+        break;
+      }
+    }
+    if (!found) {
+      return false;
+    }
+  }
+
+  // Order of parameters is not important.
+  if (left.parameters().size() != right.parameters().size()) {
+    return false;
+  }
+
+  for (int i = 0; i < left.parameters().size(); i++) {
+    bool found = false;
+    for (int j = 0; j < right.parameters().size(); j++) {
+      if (left.parameters().Get(i) == right.parameters().Get(j)) {
+        found = true;
+        break;
+      }
+    }
+    if (!found) {
+      return false;
+    }
+  }
+
+  return left.image() == right.image() &&
+    left.network() == right.network() &&
+    left.privileged() == right.privileged() &&
+    left.force_pull_image() == right.force_pull_image();
+}
+
+
+bool operator == (const ContainerInfo& left, const ContainerInfo& right)
+{
+  // Order of volumes is not important.
+  if (left.volumes().size() != right.volumes().size()) {
+    return false;
+  }
+
+  for (int i = 0; i < left.volumes().size(); i++) {
+    bool found = false;
+    for (int j = 0; j < right.volumes().size(); j++) {
+      if (left.volumes().Get(i) == right.volumes().Get(j)) {
+        found = true;
+        break;
+      }
+    }
+    if (!found) {
+      return false;
+    }
+  }
+
+  return left.type() == right.type() &&
+    left.hostname() == right.hostname() &&
+    left.docker() == right.docker();
+}
+
+
+bool operator == (const Port& left, const Port& right)
+{
+  return left.number() == right.number() &&
+    left.name() == right.name() &&
+    left.protocol() == right.protocol();
+}
+
+
+bool operator == (const Ports& left, const Ports& right)
+{
+  // Order of ports is not important.
+  if (left.ports().size() != right.ports().size()) {
+    return false;
+  }
+
+  for (int i = 0; i < left.ports().size(); i++) {
+    bool found = false;
+    for (int j = 0; j < right.ports().size(); j++) {
+      if (left.ports().Get(i) == right.ports().Get(j)) {
+        found = true;
+        break;
+      }
+    }
+    if (!found) {
+      return false;
+    }
+  }
+
+  return true;
+}
+
+
+bool operator == (const Label& left, const Label& right)
+{
+  return left.key() == right.key() && left.value() == right.value();
+}
+
+
+bool operator == (const Labels& left, const Labels& right)
+{
+  // Order of labels is not important.
+  if (left.labels().size() != right.labels().size()) {
+    return false;
+  }
+
+  for (int i = 0; i < left.labels().size(); i++) {
+    bool found = false;
+    for (int j = 0; j < right.labels().size(); j++) {
+      if (left.labels().Get(i) == right.labels().Get(j)) {
         found = true;
         break;
       }
@@ -102,15 +277,29 @@ bool operator == (const Environment& left, const Environment& right)
 }
 
 
+bool operator == (const DiscoveryInfo& left, const DiscoveryInfo& right)
+{
+  return left.visibility() == right.visibility() &&
+    left.name() == right.name() &&
+    left.environment() == right.environment() &&
+    left.location() == right.location() &&
+    left.version() == right.version() &&
+    left.ports() == right.ports() &&
+    left.labels() == right.labels();
+}
+
+
 bool operator == (const ExecutorInfo& left, const ExecutorInfo& right)
 {
   return left.executor_id() == right.executor_id() &&
-    left.framework_id() == right.framework_id() &&
-    left.command() == right.command() &&
+    left.data() == right.data() &&
     Resources(left.resources()) == Resources(right.resources()) &&
+    left.command() == right.command() &&
+    left.framework_id() == right.framework_id() &&
     left.name() == right.name() &&
     left.source() == right.source() &&
-    left.data() == right.data();
+    left.container() == right.container() &&
+    left.discovery() == right.discovery();
 }
 
 
@@ -131,15 +320,30 @@ bool operator == (const SlaveInfo& left, const SlaveInfo& right)
     internal::Attributes(left.attributes()) ==
       internal::Attributes(right.attributes()) &&
     left.id() == right.id() &&
-    left.checkpoint() == right.checkpoint();
+    left.checkpoint() == right.checkpoint() &&
+    left.port() == right.port();
 }
 
 
-bool operator == (const Volume& left, const Volume& right)
+bool operator == (const TaskStatus& left, const TaskStatus& right)
 {
-  return left.container_path() == right.container_path() &&
-    left.mode() == right.mode() &&
-    left.host_path() == right.host_path();
+  return left.task_id() == right.task_id();
+    left.state() == right.state() &&
+    left.data() == right.data() &&
+    left.message() == right.message() &&
+    left.slave_id() == right.slave_id() &&
+    left.timestamp() == right.timestamp() &&
+    left.executor_id() == right.executor_id() &&
+    left.healthy() == right.healthy() &&
+    left.source() == right.source() &&
+    left.reason() == right.reason() &&
+    left.uuid() == right.uuid();
+}
+
+
+bool operator != (const TaskStatus& left, const TaskStatus& right)
+{
+  return !(left == right);
 }
 
 
@@ -147,13 +351,28 @@ namespace internal {
 
 bool operator == (const Task& left, const Task& right)
 {
+  // Order of task statuses is important.
+  if (left.statuses().size() != right.statuses().size()) {
+    return false;
+  }
+
+  for (int i = 0; i < left.statuses().size(); i++) {
+    if (left.statuses().Get(i) != right.statuses().Get(i)) {
+      return false;
+    }
+  }
+
   return left.name() == right.name() &&
     left.task_id() == right.task_id() &&
     left.framework_id() == right.framework_id() &&
+    left.executor_id() == right.executor_id() &&
     left.slave_id() == right.slave_id() &&
     left.state() == right.state() &&
     Resources(left.resources()) == Resources(right.resources()) &&
-    left.executor_id() == right.executor_id();
+    left.status_update_state() == right.status_update_state() &&
+    left.status_update_uuid() == right.status_update_uuid() &&
+    left.labels() == right.labels() &&
+    left.discovery() == right.discovery();
 }
 
 


[2/2] mesos git commit: Fixed comparison of protobufs with optional fields.

Posted by vi...@apache.org.
Fixed comparison of protobufs with optional fields.

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


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

Branch: refs/heads/master
Commit: 0d272b5b12ae01d771985af7e78ddc29028d86a8
Parents: 0c7104d
Author: Vinod Kone <vi...@gmail.com>
Authored: Mon Mar 9 16:28:45 2015 -0700
Committer: Vinod Kone <vi...@gmail.com>
Committed: Thu Mar 12 18:29:54 2015 -0700

----------------------------------------------------------------------
 src/common/type_utils.cpp | 48 ++++++++++++++----------------------------
 1 file changed, 16 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0d272b5b/src/common/type_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/type_utils.cpp b/src/common/type_utils.cpp
index a1704c6..48fa56d 100644
--- a/src/common/type_utils.cpp
+++ b/src/common/type_utils.cpp
@@ -56,19 +56,15 @@ bool operator == (const CommandInfo& left, const CommandInfo& right)
     }
   }
 
-  return left.has_environment() == right.has_environment() &&
-    (!left.has_environment() || (left.environment() == right.environment())) &&
-    left.has_value() == right.has_value() &&
-    (!left.has_value() || (left.value() == right.value())) &&
-    left.has_shell() == right.has_shell() &&
-    (!left.has_shell() || (left.shell() == right.shell()));
+  return left.environment() == right.environment() &&
+    left.value() == right.value() &&
+    left.shell() == right.shell();
 }
 
 
 bool operator == (const CommandInfo::URI& left, const CommandInfo::URI& right)
 {
-  return left.has_executable() == right.has_executable() &&
-    (!left.has_executable() || (left.executable() == right.executable())) &&
+  return left.executable() == right.executable() &&
     left.value() == right.value();
 }
 
@@ -76,8 +72,7 @@ bool operator == (const CommandInfo::URI& left, const CommandInfo::URI& right)
 bool operator == (const Credential& left, const Credential& right)
 {
   return left.principal() == right.principal() &&
-         left.has_secret() == right.has_secret() &&
-         (!left.has_secret() || (left.secret() == right.secret()));
+    left.secret() == right.secret();
 }
 
 
@@ -110,17 +105,12 @@ bool operator == (const Environment& left, const Environment& right)
 bool operator == (const ExecutorInfo& left, const ExecutorInfo& right)
 {
   return left.executor_id() == right.executor_id() &&
-    left.has_framework_id() == right.has_framework_id() &&
-    (!left.has_framework_id() ||
-    (left.framework_id() == right.framework_id())) &&
+    left.framework_id() == right.framework_id() &&
     left.command() == right.command() &&
     Resources(left.resources()) == Resources(right.resources()) &&
-    left.has_name() == right.has_name() &&
-    (!left.has_name() || (left.name() == right.name())) &&
-    left.has_source() == right.has_source() &&
-    (!left.has_source() || (left.source() == right.source())) &&
-    left.has_data() == right.has_data() &&
-    (!left.has_data() || (left.data() == right.data()));
+    left.name() == right.name() &&
+    left.source() == right.source() &&
+    left.data() == right.data();
 }
 
 
@@ -129,10 +119,8 @@ bool operator == (const MasterInfo& left, const MasterInfo& right)
   return left.id() == right.id() &&
     left.ip() == right.ip() &&
     left.port() == right.port() &&
-    left.has_pid() == right.has_pid() &&
-    (!left.has_pid() || (left.pid() == right.pid())) &&
-    left.has_hostname() == right.has_hostname() &&
-    (!left.has_hostname() || (left.hostname() == right.hostname()));
+    left.pid() == right.pid() &&
+    left.hostname() == right.hostname();
 }
 
 
@@ -141,11 +129,9 @@ bool operator == (const SlaveInfo& left, const SlaveInfo& right)
   return left.hostname() == right.hostname() &&
     Resources(left.resources()) == Resources(right.resources()) &&
     internal::Attributes(left.attributes()) ==
-    internal::Attributes(right.attributes()) &&
-    left.has_id() == right.has_id() &&
-    (!left.has_id() || (left.id() == right.id())) &&
-    left.has_checkpoint() == right.has_checkpoint() &&
-    (!left.has_checkpoint() || (left.checkpoint() == right.checkpoint()));
+      internal::Attributes(right.attributes()) &&
+    left.id() == right.id() &&
+    left.checkpoint() == right.checkpoint();
 }
 
 
@@ -153,8 +139,7 @@ bool operator == (const Volume& left, const Volume& right)
 {
   return left.container_path() == right.container_path() &&
     left.mode() == right.mode() &&
-    left.has_host_path() == right.has_host_path() &&
-    (!left.has_host_path() || (left.host_path() == right.host_path()));
+    left.host_path() == right.host_path();
 }
 
 
@@ -168,8 +153,7 @@ bool operator == (const Task& left, const Task& right)
     left.slave_id() == right.slave_id() &&
     left.state() == right.state() &&
     Resources(left.resources()) == Resources(right.resources()) &&
-    left.has_executor_id() == right.has_executor_id() &&
-    (!left.has_executor_id() || (left.executor_id() == right.executor_id()));
+    left.executor_id() == right.executor_id();
 }