This is an automated email from the ASF dual-hosted git repository. grag pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mesos.git
commit 3c959eb769ec4a39721947e7ec173dd9eefc6af4 Author: Greg Mann <g...@mesosphere.io> AuthorDate: Mon Jul 15 10:25:30 2019 -0700 Added minimal agent handler for 'DrainSlaveMessage'. This patch adds a minimal handler to the agent for the `DrainSlaveMessage`. This handler will later be extended to implement the full functionality. Review: https://reviews.apache.org/r/70834/ --- src/slave/paths.cpp | 9 +++++++++ src/slave/paths.hpp | 6 ++++++ src/slave/slave.cpp | 20 ++++++++++++++++++++ src/slave/slave.hpp | 8 ++++++++ 4 files changed, 43 insertions(+) diff --git a/src/slave/paths.cpp b/src/slave/paths.cpp index 1163c88..28a7cf9 100644 --- a/src/slave/paths.cpp +++ b/src/slave/paths.cpp @@ -55,6 +55,7 @@ namespace paths { // File names. const char BOOT_ID_FILE[] = "boot_id"; const char SLAVE_INFO_FILE[] = "slave.info"; +const char DRAIN_CONFIG_FILE[] = "drain.config"; const char FRAMEWORK_PID_FILE[] = "framework.pid"; const char FRAMEWORK_INFO_FILE[] = "framework.info"; const char LIBPROCESS_PID_FILE[] = "libprocess.pid"; @@ -658,6 +659,14 @@ string getResourcesTargetPath( } +string getDrainConfigPath( + const string& metaDir, + const SlaveID& slaveId) +{ + return path::join(getSlavePath(metaDir, slaveId), DRAIN_CONFIG_FILE); +} + + Try<list<string>> getPersistentVolumePaths( const std::string& workDir) { diff --git a/src/slave/paths.hpp b/src/slave/paths.hpp index ad76826..e077587 100644 --- a/src/slave/paths.hpp +++ b/src/slave/paths.hpp @@ -76,6 +76,7 @@ namespace paths { // | | |-- latest (symlink) // | | |-- <slave_id> // | | |-- slave.info +// | | |-- drain.config // | | |-- operations // | | | |-- <operation_uuid> // | | | |-- operation.updates @@ -422,6 +423,11 @@ std::string getResourcesTargetPath( const std::string& rootDir); +std::string getDrainConfigPath( + const std::string& metaDir, + const SlaveID& slaveId); + + Try<std::list<std::string>> getPersistentVolumePaths( const std::string& workDir); diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp index 30039b0..fc688dc 100644 --- a/src/slave/slave.cpp +++ b/src/slave/slave.cpp @@ -749,6 +749,8 @@ void Slave::initialize() &Slave::shutdown, &ShutdownMessage::message); + install<DrainSlaveMessage>(&Slave::drain); + install<PingSlaveMessage>( &Slave::ping, &PingSlaveMessage::connected); @@ -982,6 +984,24 @@ void Slave::shutdown(const UPID& from, const string& message) } +void Slave::drain( + const UPID& from, + DrainSlaveMessage&& drainSlaveMessage) +{ + LOG(INFO) + << "Checkpointing DrainConfig. Previous drain config was " + << (drainConfig.isSome() ? stringify(drainConfig.get()) : "NONE") + << ", new drain config is " << drainSlaveMessage.config(); + + CHECK_SOME(state::checkpoint( + paths::getDrainConfigPath(metaDir, info.id()), + drainSlaveMessage.config())) + << "Failed to checkpoint DrainConfig"; + + drainConfig = drainSlaveMessage.config(); +} + + void Slave::fileAttached( const Future<Nothing>& result, const string& path, diff --git a/src/slave/slave.hpp b/src/slave/slave.hpp index 6954f53..dbcceed 100644 --- a/src/slave/slave.hpp +++ b/src/slave/slave.hpp @@ -376,6 +376,10 @@ public: const process::UPID& from, const AcknowledgeOperationStatusMessage& acknowledgement); + void drain( + const process::UPID& from, + DrainSlaveMessage&& drainSlaveMessage); + void executorLaunched( const FrameworkID& frameworkId, const ExecutorID& executorId, @@ -885,6 +889,10 @@ private: // Operations that are checkpointed by the agent. hashmap<UUID, Operation> checkpointedOperations; + + // If the agent is currently draining, contains the configuration used to + // drain the agent. If NONE, the agent is not currently draining. + Option<DrainConfig> drainConfig; };