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

bennoe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git

commit f2ec6ab3e216a3f3898e8e021a7d4712c767bdd9
Author: Benno Evers <[email protected]>
AuthorDate: Mon Nov 25 17:53:28 2019 +0100

    Added domain socket-related flags to Mesos agent.
    
    Added two new flags 'http_executor_domain_sockets' and
    'domain_socket_location' to the agent, along with minimal
    logic to pass the relevant values on to executors.
    
    They are used to control whether the agent should
    provide a domain socket to HTTP executors and the
    location of the socket on the host filesystem, respectively.
    
    Review: https://reviews.apache.org/r/71816
---
 docs/configuration/agent.md | 31 +++++++++++++++++++++++++++++++
 src/slave/constants.hpp     |  4 ++++
 src/slave/flags.cpp         | 25 +++++++++++++++++++++++++
 src/slave/flags.hpp         |  2 ++
 src/slave/main.cpp          | 13 +++++++++++++
 src/slave/slave.cpp         |  7 +++++++
 6 files changed, 82 insertions(+)

diff --git a/docs/configuration/agent.md b/docs/configuration/agent.md
index 91e38c2..0e703d8 100644
--- a/docs/configuration/agent.md
+++ b/docs/configuration/agent.md
@@ -808,6 +808,25 @@ users. By default, this flag is off. (default: false)
   </td>
 </tr>
 
+<tr id="domain_socket_location">
+  <td>
+    --domain_socket_location=VALUE
+  </td>
+  <td>
+Location on the host filesystem of the domain socket used for
+communication with executors. Alternatively, this can be set to
+<code>'systemd:&lt;identifier&gt;'</code> to use the domain socket
+with the given identifier, which is expected to be passed by systemd.
+
+This flag will be ignored unless the 
<code>--http_executor_domain_sockets</code>
+flag is also set to true.
+
+Total path length must be less than 108 characters.
+
+Will be set to <code>&lt;runtime_dir&gt;/agent.sock</code> by default.
+  </td>
+</tr>
+
 <tr id="enforce_container_disk_quota">
   <td>
     --[no-]enforce_container_disk_quota
@@ -1076,6 +1095,18 @@ production yet. (default: false)
   </td>
 </tr>
 
+
+<tr id="http_executor_domain_sockets">
+  <td>
+      --http_executor_domain_sockets
+  </td>
+  <td>
+If true, the agent will provide a unix domain sockets that the
+executor can use to connect to the agent, instead of relying on
+a TCP connection.
+  </td>
+</tr>
+
 <tr id="http_heartbeat_interval">
   <td>
     --http_heartbeat_interval=VALUE
diff --git a/src/slave/constants.hpp b/src/slave/constants.hpp
index 721afe1..cfc83db 100644
--- a/src/slave/constants.hpp
+++ b/src/slave/constants.hpp
@@ -140,6 +140,10 @@ constexpr char DEFAULT_DOCKER_HOST_RESOURCE[] = 
"//./pipe/docker_engine";
 constexpr char DEFAULT_DOCKER_HOST_RESOURCE[] = "/var/run/docker.sock";
 #endif // __WINDOWS__
 
+// Default filename used for domain socket-based communication between
+// agent and executors, if that is enabled.
+constexpr char AGENT_EXECUTORS_SOCKET_FILENAME[] = "agent.sock";
+
 // Default duration that docker containers will be removed after exit.
 constexpr Duration DOCKER_REMOVE_DELAY = Hours(6);
 
diff --git a/src/slave/flags.cpp b/src/slave/flags.cpp
index 50b09cf..8c6c2ce 100644
--- a/src/slave/flags.cpp
+++ b/src/slave/flags.cpp
@@ -25,6 +25,7 @@
 
 #include <mesos/type_utils.hpp>
 
+#include "common/domain_sockets.hpp"
 #include "common/http.hpp"
 #include "common/parse.hpp"
 #include "common/protobuf_utils.hpp"
@@ -984,6 +985,23 @@ mesos::internal::slave::Flags::Flags()
 #endif // __WINDOWS__
       );
 
+  add(&Flags::domain_socket_location,
+      "domain_socket_location",
+      "Location on the host filesystem of the domain socket used for\n"
+      "communication with executors.\n This flag will be ignored unless\n"
+      "the '--http_executor_domain_sockets' flag is also set to true.\n"
+      "Total path length must be less than 108 characters.\n"
+      "Will be set to <runtime_dir>/agent.sock by default.",
+      [](const Option<string>& location) -> Option<Error> {
+        if (location.isSome() &&
+            location->size() >= common::DOMAIN_SOCKET_MAX_PATH_LENGTH) {
+          return Error(
+              "Domain socket location cannot be longer than 108 characters.");
+        }
+
+        return None();
+      });
+
   add(&Flags::default_container_dns,
       "default_container_dns",
       "JSON-formatted DNS information for CNI networks (Mesos containerizer)\n"
@@ -1381,6 +1399,13 @@ mesos::internal::slave::Flags::Flags()
       false);
 #endif // USE_SSL_SOCKET
 
+  add(&Flags::http_executor_domain_sockets,
+      "http_executor_domain_sockets",
+      "If true, the agent will provide a unix domain sockets that the\n"
+      "executor can use to connect to the agent, instead of relying on\n"
+      "a TCP connection.",
+      false);
+
   add(&Flags::http_credentials,
       "http_credentials",
       "Path to a JSON-formatted file containing credentials used to\n"
diff --git a/src/slave/flags.hpp b/src/slave/flags.hpp
index 3c5ffca..838aaee 100644
--- a/src/slave/flags.hpp
+++ b/src/slave/flags.hpp
@@ -182,6 +182,8 @@ public:
 #ifdef USE_SSL_SOCKET
   bool authenticate_http_executors;
 #endif // USE_SSL_SOCKET
+  bool http_executor_domain_sockets;
+  Option<std::string> domain_socket_location;
   Option<Path> http_credentials;
   Option<std::string> hooks;
   Option<std::string> secret_resolver;
diff --git a/src/slave/main.cpp b/src/slave/main.cpp
index fd58637..1d47fba 100644
--- a/src/slave/main.cpp
+++ b/src/slave/main.cpp
@@ -344,6 +344,19 @@ int main(int argc, char** argv)
     os::setenv("LIBPROCESS_ADVERTISE_PORT", flags.advertise_port.get());
   }
 
+  if (flags.http_executor_domain_sockets) {
+    if (flags.domain_socket_location.isNone()) {
+      flags.domain_socket_location = flags.runtime_dir + "/agent.sock";
+    }
+
+    if (flags.domain_socket_location->size() >=
+        common::DOMAIN_SOCKET_MAX_LENGTH) {
+      EXIT(EXIT_FAILURE)
+        << "Domain socket location '" << *flags.domain_socket_location << "'"
+        << " must have less than 108 characters.";
+    }
+  }
+
   os::setenv("LIBPROCESS_MEMORY_PROFILING", stringify(flags.memory_profiling));
 
   // Log build information.
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 3839a12..3f6b4fb 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -11092,6 +11092,13 @@ map<string, string> executorEnvironment(
   environment["MESOS_HTTP_COMMAND_EXECUTOR"] =
     flags.http_command_executor ? "1" : "0";
 
+  if (flags.http_executor_domain_sockets) {
+    // If `http_executor_domain_sockets` is true, the location should have
+    // been set either by the user or automatically during agent startup.
+    CHECK(flags.domain_socket_location.isSome());
+    environment["MESOS_DOMAIN_SOCKET"] = *flags.domain_socket_location;
+  }
+
   // Set executor's shutdown grace period. If set, the customized value
   // from `ExecutorInfo` overrides the default from agent flags.
   Duration executorShutdownGracePeriod = flags.executor_shutdown_grace_period;

Reply via email to