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

bbannier pushed a commit to branch 1.5.x
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit 2f2146ac61abd54bc3296d8cbb5429cd10584db1
Author: Benjamin Bannier <[email protected]>
AuthorDate: Thu Jan 23 14:19:57 2020 +0100

    Remembered whether an executor was agent-generated.
    
    This patch adds code to pass on whether was generated in the agent from
    the point where the executor is generated to the point where we create
    an actual `slave::Executor` instance. This allows us to persist this
    information in the executor state.
    
    Review: https://reviews.apache.org/r/72035/
---
 src/slave/slave.cpp | 49 ++++++++++++++++++++++++++++---------------------
 src/slave/slave.hpp | 14 ++++++++++----
 2 files changed, 38 insertions(+), 25 deletions(-)

diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 07ccbcd..1bf6ac4 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -1932,13 +1932,16 @@ void Slave::runTask(
 
   const ExecutorInfo executorInfo = getExecutorInfo(frameworkInfo, task);
 
+  bool executorGeneratedForCommandTask = !task.has_executor();
+
   run(frameworkInfo,
       executorInfo,
       task,
       None(),
       resourceVersionUuids,
       pid,
-      launchExecutor);
+      launchExecutor,
+      executorGeneratedForCommandTask);
 }
 
 
@@ -1949,7 +1952,8 @@ void Slave::run(
     Option<TaskGroupInfo> taskGroup,
     const vector<ResourceVersionUUID>& resourceVersionUuids,
     const UPID& pid,
-    const Option<bool>& launchExecutor)
+    const Option<bool>& launchExecutor,
+    bool executorGeneratedForCommandTask)
 {
   CHECK_NE(task.isSome(), taskGroup.isSome())
     << "Either task or task group should be set but not both";
@@ -2267,7 +2271,8 @@ void Slave::run(
             task,
             taskGroup,
             resourceVersionUuids,
-            launchExecutor))
+            launchExecutor,
+            executorGeneratedForCommandTask))
         .onFailed(defer(self(), [=](const string& failure) {
           Framework* _framework = getFramework(frameworkId);
           if (_framework == nullptr) {
@@ -2497,7 +2502,8 @@ void Slave::__run(
     const Option<TaskInfo>& task,
     const Option<TaskGroupInfo>& taskGroup,
     const vector<ResourceVersionUUID>& resourceVersionUuids,
-    const Option<bool>& launchExecutor)
+    const Option<bool>& launchExecutor,
+    bool executorGeneratedForCommandTask)
 {
   CHECK_NE(task.isSome(), taskGroup.isSome())
     << "Either task or task group should be set but not both";
@@ -2864,7 +2870,8 @@ void Slave::__run(
             << " for framework " << frameworkId;
 
   auto doLaunchExecutor = [&]() {
-    Executor* executor = framework->addExecutor(executorInfo);
+    Executor* executor =
+      framework->addExecutor(executorInfo, executorGeneratedForCommandTask);
 
     if (secretGenerator) {
       generateSecret(framework->id(), executor->id, executor->containerId)
@@ -3638,13 +3645,17 @@ void Slave::runTaskGroup(
     return;
   }
 
+  // Executors for task groups are injected by the master, not the agent.
+  constexpr bool executorGeneratedForCommandTask = false;
+
   run(frameworkInfo,
       executorInfo,
       None(),
       taskGroupInfo,
       resourceVersionUuids,
       UPID(),
-      launchExecutor);
+      launchExecutor,
+      executorGeneratedForCommandTask);
 }
 
 
@@ -8867,7 +8878,9 @@ void Framework::checkpointFramework() const
 }
 
 
-Executor* Framework::addExecutor(const ExecutorInfo& executorInfo)
+Executor* Framework::addExecutor(
+    const ExecutorInfo& executorInfo,
+    bool isGeneratedForCommandTask)
 {
   // Verify that Resource.AllocationInfo is set, if coming
   // from a MULTI_ROLE master this will be set, otherwise
@@ -8918,7 +8931,8 @@ Executor* Framework::addExecutor(const ExecutorInfo& 
executorInfo)
       containerId,
       directory,
       user,
-      info.checkpoint());
+      info.checkpoint(),
+      isGeneratedForCommandTask);
 
   if (executor->checkpoint) {
     executor->checkpointExecutor();
@@ -9113,7 +9127,8 @@ void Framework::recoverExecutor(
       latest,
       directory,
       info.user(),
-      info.checkpoint());
+      info.checkpoint(),
+      state.generatedForCommandTask);
 
   // Recover the libprocess PID if possible for PID based executors.
   if (run->http.isSome()) {
@@ -9445,7 +9460,8 @@ Executor::Executor(
     const ContainerID& _containerId,
     const string& _directory,
     const Option<string>& _user,
-    bool _checkpoint)
+    bool _checkpoint,
+    bool isGeneratedForCommandTask)
   : state(REGISTERING),
     slave(_slave),
     id(_info.executor_id()),
@@ -9456,7 +9472,8 @@ Executor::Executor(
     user(_user),
     checkpoint(_checkpoint),
     http(None()),
-    pid(None())
+    pid(None()),
+    isGeneratedForCommandTask_(isGeneratedForCommandTask)
 {
   CHECK_NOTNULL(slave);
 
@@ -9473,16 +9490,6 @@ Executor::Executor(
 
   completedTasks =
     boost::circular_buffer<shared_ptr<Task>>(MAX_COMPLETED_TASKS_PER_EXECUTOR);
-
-  // TODO(jieyu): The way we determine if an executor is generated for
-  // a command task (either command or docker executor) is really
-  // hacky. We rely on the fact that docker executor launch command is
-  // set in the docker containerizer so that this check is still valid
-  // in the slave.
-  // TODO(bbannier): Initialize this field with a value passed to constructor.
-  isGeneratedForCommandTask_ =
-    strings::endsWith(info.command().value(), MESOS_EXECUTOR) &&
-    strings::startsWith(info.name(), "Command Executor");
 }
 
 
diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp
index d638b88..0c9c1a7 100644
--- a/src/slave/slave.hpp
+++ b/src/slave/slave.hpp
@@ -168,7 +168,8 @@ public:
       Option<TaskGroupInfo> taskGroup,
       const std::vector<ResourceVersionUUID>& resourceVersionUuids,
       const process::UPID& pid,
-      const Option<bool>& launchExecutor);
+      const Option<bool>& launchExecutor,
+      bool executorGeneratedForCommandTask);
 
   // Made 'virtual' for Slave mocking.
   //
@@ -399,7 +400,8 @@ public:
       const Option<TaskInfo>& task,
       const Option<TaskGroupInfo>& taskGroup,
       const std::vector<ResourceVersionUUID>& resourceVersionUuids,
-      const Option<bool>& launchExecutor);
+      const Option<bool>& launchExecutor,
+      bool executorGeneratedForCommandTask);
 
   // This is called when the resource limits of the container have
   // been updated for the given tasks and task groups. If the update is
@@ -879,7 +881,8 @@ public:
       const ContainerID& containerId,
       const std::string& directory,
       const Option<std::string>& user,
-      bool checkpoint);
+      bool checkpoint,
+      bool isGeneratedForCommandTask);
 
   ~Executor();
 
@@ -1070,7 +1073,10 @@ public:
 
   const FrameworkID id() const { return info.id(); }
 
-  Executor* addExecutor(const ExecutorInfo& executorInfo);
+  Executor* addExecutor(
+      const ExecutorInfo& executorInfo,
+      bool isGeneratedForCommandTask);
+
   Executor* getExecutor(const ExecutorID& executorId) const;
   Executor* getExecutor(const TaskID& taskId) const;
 

Reply via email to