You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2017/05/31 21:51:17 UTC

[03/16] mesos git commit: Reordered some methods in the agent code into logic units.

Reordered some methods in the agent code into logic units.

Also, make sure the order in the header is in sync with that in the
corresponding source file.

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


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

Branch: refs/heads/master
Commit: 6254e2df9a609139cc478b1eea4f7e4925db269d
Parents: fc00c5b
Author: Jie Yu <yu...@gmail.com>
Authored: Tue May 30 15:55:19 2017 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed May 31 14:51:10 2017 -0700

----------------------------------------------------------------------
 src/slave/slave.cpp | 112 +++++++++++++++++++++++------------------------
 src/slave/slave.hpp |  10 +++--
 2 files changed, 62 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/6254e2df/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 0c62622..052a7f7 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -4882,6 +4882,26 @@ Executor* Slave::getExecutor(
 }
 
 
+Executor* Slave::getExecutor(const ContainerID& containerId) const
+{
+  const ContainerID rootContainerId = protobuf::getRootContainerId(containerId);
+
+  // Locate the executor (for now we just loop since we don't
+  // index based on container id and this likely won't have a
+  // significant performance impact due to the low number of
+  // executors per-agent).
+  foreachvalue (Framework* framework, frameworks) {
+    foreachvalue (Executor* executor, framework->executors) {
+      if (rootContainerId == executor->containerId) {
+        return executor;
+      }
+    }
+  }
+
+  return nullptr;
+}
+
+
 ExecutorInfo Slave::getExecutorInfo(
     const FrameworkInfo& frameworkInfo,
     const TaskInfo& task) const
@@ -6943,6 +6963,15 @@ Framework::Framework(
     completedExecutors(slaveFlags.max_completed_executors_per_framework) {}
 
 
+Framework::~Framework()
+{
+  // We own the non-completed executor pointers, so they need to be deleted.
+  foreachvalue (Executor* executor, executors) {
+    delete executor;
+  }
+}
+
+
 void Framework::checkpointFramework() const
 {
   // Checkpoint the framework info.
@@ -6968,15 +6997,6 @@ void Framework::checkpointFramework() const
 }
 
 
-Framework::~Framework()
-{
-  // We own the non-completed executor pointers, so they need to be deleted.
-  foreachvalue (Executor* executor, executors) {
-    delete executor;
-  }
-}
-
-
 Executor* Framework::addExecutor(const ExecutorInfo& executorInfo)
 {
   // Verify that Resource.AllocationInfo is set, if coming
@@ -7066,18 +7086,6 @@ Executor* Framework::addExecutor(const ExecutorInfo& executorInfo)
 }
 
 
-void Framework::destroyExecutor(const ExecutorID& executorId)
-{
-  if (executors.contains(executorId)) {
-    Executor* executor = executors[executorId];
-    executors.erase(executorId);
-
-    // Pass ownership of the executor pointer.
-    completedExecutors.push_back(Owned<Executor>(executor));
-  }
-}
-
-
 Executor* Framework::getExecutor(const ExecutorID& executorId) const
 {
   if (executors.contains(executorId)) {
@@ -7101,44 +7109,15 @@ Executor* Framework::getExecutor(const TaskID& taskId) const
 }
 
 
-// Return `true` if `task` was a pending task of this framework
-// before the removal; `false` otherwise.
-bool Framework::removePendingTask(
-    const TaskInfo& task,
-    const ExecutorInfo& executorInfo)
-{
-  const ExecutorID executorId = executorInfo.executor_id();
-
-  if (pending.contains(executorId) &&
-      pending.at(executorId).contains(task.task_id())) {
-    pending.at(executorId).erase(task.task_id());
-    if (pending.at(executorId).empty()) {
-      pending.erase(executorId);
-    }
-    return true;
-  }
-
-  return false;
-}
-
-
-Executor* Slave::getExecutor(const ContainerID& containerId) const
+void Framework::destroyExecutor(const ExecutorID& executorId)
 {
-  const ContainerID rootContainerId = protobuf::getRootContainerId(containerId);
+  if (executors.contains(executorId)) {
+    Executor* executor = executors[executorId];
+    executors.erase(executorId);
 
-  // Locate the executor (for now we just loop since we don't
-  // index based on container id and this likely won't have a
-  // significant performance impact due to the low number of
-  // executors per-agent).
-  foreachvalue (Framework* framework, frameworks) {
-    foreachvalue (Executor* executor, framework->executors) {
-      if (rootContainerId == executor->containerId) {
-        return executor;
-      }
-    }
+    // Pass ownership of the executor pointer.
+    completedExecutors.push_back(Owned<Executor>(executor));
   }
-
-  return nullptr;
 }
 
 
@@ -7327,6 +7306,27 @@ bool Framework::hasTask(const TaskID& taskId)
 }
 
 
+// Return `true` if `task` was a pending task of this framework
+// before the removal; `false` otherwise.
+bool Framework::removePendingTask(
+    const TaskInfo& task,
+    const ExecutorInfo& executorInfo)
+{
+  const ExecutorID executorId = executorInfo.executor_id();
+
+  if (pending.contains(executorId) &&
+      pending.at(executorId).contains(task.task_id())) {
+    pending.at(executorId).erase(task.task_id());
+    if (pending.at(executorId).empty()) {
+      pending.erase(executorId);
+    }
+    return true;
+  }
+
+  return false;
+}
+
+
 Executor::Executor(
     Slave* _slave,
     const FrameworkID& _frameworkId,

http://git-wip-us.apache.org/repos/asf/mesos/blob/6254e2df/src/slave/slave.hpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp
index 4054ab3..afa3a12 100644
--- a/src/slave/slave.hpp
+++ b/src/slave/slave.hpp
@@ -854,25 +854,27 @@ public:
 
   ~Framework();
 
+  void checkpointFramework() const;
+
+  const FrameworkID id() const { return info.id(); }
+
   Executor* addExecutor(const ExecutorInfo& executorInfo);
-  void destroyExecutor(const ExecutorID& executorId);
   Executor* getExecutor(const ExecutorID& executorId) const;
   Executor* getExecutor(const TaskID& taskId) const;
 
+  void destroyExecutor(const ExecutorID& executorId);
+
   void recoverExecutor(
       const state::ExecutorState& state,
       bool recheckpointExecutor,
       const hashset<TaskID>& tasksToRecheckpoint);
 
-  void checkpointFramework() const;
   bool hasTask(const TaskID& taskId);
 
   bool removePendingTask(
       const TaskInfo& task,
       const ExecutorInfo& executorInfo);
 
-  const FrameworkID id() const { return info.id(); }
-
   enum State
   {
     RUNNING,      // First state of a newly created framework.