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 2016/03/02 00:37:55 UTC

[3/5] mesos git commit: Modified executor library to read grace period from environment.

Modified executor library to read grace period from environment.

This change modifies the executor library to read shutdown grace
period from the environment instead of reading it from the `Shutdown`
event in executor protobuf.

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


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

Branch: refs/heads/master
Commit: 588ecefacf532c4166331bb858f136c94bf845e5
Parents: 7f9a3b3
Author: Anand Mazumdar <ma...@gmail.com>
Authored: Tue Mar 1 15:37:28 2016 -0800
Committer: Vinod Kone <vi...@gmail.com>
Committed: Tue Mar 1 15:37:28 2016 -0800

----------------------------------------------------------------------
 src/executor/executor.cpp | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/588ecefa/src/executor/executor.cpp
----------------------------------------------------------------------
diff --git a/src/executor/executor.cpp b/src/executor/executor.cpp
index c5f22e7..c3e95ea 100644
--- a/src/executor/executor.cpp
+++ b/src/executor/executor.cpp
@@ -87,19 +87,16 @@ namespace executor {
 class ShutdownProcess : public process::Process<ShutdownProcess>
 {
 public:
-  ShutdownProcess(double _gracePeriod)
+  explicit ShutdownProcess(const Duration& _gracePeriod)
     : gracePeriod(_gracePeriod) {}
 
 protected:
   virtual void initialize()
   {
-    Try<Duration> gracePeriod_ = Duration::create(gracePeriod);
-    CHECK_SOME(gracePeriod_);
-
     VLOG(1) << "Scheduling shutdown of the executor with grace period: "
-            << gracePeriod_.get();
+            << gracePeriod;
 
-    delay(gracePeriod_.get(), self(), &Self::kill);
+    delay(gracePeriod, self(), &Self::kill);
   }
 
   void kill()
@@ -117,7 +114,7 @@ protected:
   }
 
 private:
-  const double gracePeriod;
+  const Duration gracePeriod;
 };
 
 
@@ -229,6 +226,21 @@ public:
                 << "in the environment";
       }
     }
+
+    // Get shutdown grace period from environment.
+    value = os::getenv("MESOS_EXECUTOR_SHUTDOWN_GRACE_PERIOD");
+    if (value.isSome()) {
+      Try<Duration> _shutdownGracePeriod = Duration::parse(value.get());
+
+      CHECK_SOME(_shutdownGracePeriod)
+          << "Failed to parse MESOS_EXECUTOR_SHUTDOWN_GRACE_PERIOD '"
+          << value.get() << "': " << _shutdownGracePeriod.error();
+
+      shutdownGracePeriod = _shutdownGracePeriod.get();
+    } else {
+      EXIT(1) << "Expecting 'MESOS_EXECUTOR_SHUTDOWN_GRACE_PERIOD' to be set "
+              << "in the environment";
+    }
   }
 
   void send(const Call& call)
@@ -601,23 +613,14 @@ protected:
     }
 
     if (event.type() == Event::SHUTDOWN) {
-      shutdown(event.shutdown().grace_period_seconds());
+      shutdown();
     }
   }
 
   void shutdown()
   {
-    Event event;
-    event.set_type(Event::SHUTDOWN);
-    event.mutable_shutdown();
-
-    receive(event, true);
-  }
-
-  void shutdown(double gracePeriod)
-  {
     if (!local) {
-      spawn(new ShutdownProcess(gracePeriod), true);
+      spawn(new ShutdownProcess(shutdownGracePeriod), true);
     } else {
       // Process any pending received events from agent and then terminate.
       terminate(this, false);
@@ -660,6 +663,7 @@ private:
   bool checkpoint;
   Option<Duration> recoveryTimeout;
   Option<Duration> maxBackoff;
+  Duration shutdownGracePeriod;
 };