Refactored some code into a separate function.

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


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

Branch: refs/heads/master
Commit: 0645e7d9d5354375f4020ef8c8b30f053c6ccca5
Parents: 0312bc1
Author: Neil Conway <neil.con...@gmail.com>
Authored: Fri Oct 21 14:13:24 2016 -0700
Committer: Vinod Kone <vinodk...@gmail.com>
Committed: Fri Oct 21 14:13:24 2016 -0700

----------------------------------------------------------------------
 src/slave/slave.cpp | 15 +--------------
 src/slave/slave.hpp | 25 ++++++++++++++++++++++---
 2 files changed, 23 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0645e7d9/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 6a5057e..a0019cb 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -1269,21 +1269,8 @@ void Slave::reregistered(
       const TaskID& taskId = status.task_id();
 
       bool known = false;
-
-      // Try to locate the task.
       if (framework != nullptr) {
-        foreachkey (const ExecutorID& executorId, framework->pending) {
-          if (framework->pending[executorId].contains(taskId)) {
-            known = true;
-          }
-        }
-        foreachvalue (Executor* executor, framework->executors) {
-          if (executor->queuedTasks.contains(taskId) ||
-              executor->launchedTasks.contains(taskId) ||
-              executor->terminatedTasks.contains(taskId)) {
-            known = true;
-          }
-        }
+        known = framework->hasTask(taskId);
       }
 
       // Send a terminal status update for each task that is known to

http://git-wip-us.apache.org/repos/asf/mesos/blob/0645e7d9/src/slave/slave.hpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp
index d8c5873..c0a1765 100644
--- a/src/slave/slave.hpp
+++ b/src/slave/slave.hpp
@@ -1004,9 +1004,9 @@ struct Framework
     TERMINATING,  // Framework is shutting down in the cluster.
   } state;
 
-  // We store the pointer to 'Slave' to get access to its methods
-  // variables. One could imagine 'Framework' as being an inner class
-  // of the 'Slave' class.
+  // We store the pointer to 'Slave' to get access to its methods and
+  // variables. One could imagine 'Framework' being an inner class of
+  // the 'Slave' class.
   Slave* slave;
 
   const FrameworkInfo info;
@@ -1026,6 +1026,25 @@ struct Framework
 
   boost::circular_buffer<process::Owned<Executor>> completedExecutors;
 
+  bool hasTask(const TaskID& taskId)
+  {
+    foreachkey (const ExecutorID& executorId, pending) {
+      if (pending[executorId].contains(taskId)) {
+        return true;
+      }
+    }
+
+    foreachvalue (Executor* executor, executors) {
+      if (executor->queuedTasks.contains(taskId) ||
+          executor->launchedTasks.contains(taskId) ||
+          executor->terminatedTasks.contains(taskId)) {
+        return true;
+      }
+    }
+
+    return false;
+  }
+
 private:
   Framework(const Framework&);              // No copying.
   Framework& operator=(const Framework&); // No assigning.

Reply via email to