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 2014/02/11 08:25:50 UTC
[3/5] git commit: Added 'hostname' flag to the master.
Added 'hostname' flag to the master.
Review: https://reviews.apache.org/r/17210
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/3cce8ea7
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/3cce8ea7
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/3cce8ea7
Branch: refs/heads/master
Commit: 3cce8ea7e14cafa6aa15d64b7f068d39edabdb50
Parents: 8a79d31
Author: Vinod Kone <vi...@twitter.com>
Authored: Tue Jan 21 21:17:57 2014 -0800
Committer: Vinod Kone <vi...@twitter.com>
Committed: Mon Feb 10 22:34:06 2014 -0800
----------------------------------------------------------------------
include/mesos/mesos.proto | 1 +
src/common/date_utils.cpp | 4 ++--
src/common/date_utils.hpp | 2 +-
src/master/flags.hpp | 6 ++++++
src/master/http.cpp | 1 +
src/master/master.cpp | 20 +++++++++++++++++++-
6 files changed, 30 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/3cce8ea7/include/mesos/mesos.proto
----------------------------------------------------------------------
diff --git a/include/mesos/mesos.proto b/include/mesos/mesos.proto
index 1503e73..7079e03 100644
--- a/include/mesos/mesos.proto
+++ b/include/mesos/mesos.proto
@@ -161,6 +161,7 @@ message MasterInfo {
required uint32 ip = 2;
required uint32 port = 3 [default = 5050];
optional string pid = 4;
+ optional string hostname = 5;
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/3cce8ea7/src/common/date_utils.cpp
----------------------------------------------------------------------
diff --git a/src/common/date_utils.cpp b/src/common/date_utils.cpp
index 3af9b4d..22c7dac 100644
--- a/src/common/date_utils.cpp
+++ b/src/common/date_utils.cpp
@@ -30,7 +30,7 @@ bool DateUtils::useMockDate = false;
string DateUtils::mockDate = "";
-// Get the current date in the format used for Mesos IDs (YYYYMMDDhhmm).
+// Get the current date in the format used for Mesos IDs (YYYYMMDDhhmmss).
string DateUtils::currentDate()
{
if (useMockDate) {
@@ -41,7 +41,7 @@ string DateUtils::currentDate()
time(&rawtime);
timeinfo = localtime(&rawtime);
char date[32];
- strftime(date, sizeof(date), "%Y%m%d%H%M", timeinfo);
+ strftime(date, sizeof(date), "%Y-%m-%d-%H:%M:%S", timeinfo);
return date;
}
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/3cce8ea7/src/common/date_utils.hpp
----------------------------------------------------------------------
diff --git a/src/common/date_utils.hpp b/src/common/date_utils.hpp
index 69fa03a..085c1ce 100644
--- a/src/common/date_utils.hpp
+++ b/src/common/date_utils.hpp
@@ -31,7 +31,7 @@ class DateUtils
{
public:
/**
- * Get the current date in the format used for Mesos IDs (YYYYMMDDhhmm).
+ * Get the current date in the format used for Mesos IDs (YYYYMMDDhhmmss).
*/
static std::string currentDate();
http://git-wip-us.apache.org/repos/asf/mesos/blob/3cce8ea7/src/master/flags.hpp
----------------------------------------------------------------------
diff --git a/src/master/flags.hpp b/src/master/flags.hpp
index 16faf96..159b2de 100644
--- a/src/master/flags.hpp
+++ b/src/master/flags.hpp
@@ -35,6 +35,11 @@ class Flags : public logging::Flags
public:
Flags()
{
+ add(&Flags::hostname,
+ "hostname",
+ "The hostname the master should advertise in ZooKeeper.\n"
+ "If left unset, system hostname will be used (recommended).");
+
add(&Flags::root_submissions,
"root_submissions",
"Can root submit frameworks?",
@@ -115,6 +120,7 @@ public:
"Path could be of the form 'file:///path/to/file' or '/path/to/file'");
}
+ Option<std::string> hostname;
bool root_submissions;
std::string work_dir;
std::string registry;
http://git-wip-us.apache.org/repos/asf/mesos/blob/3cce8ea7/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index fb15483..e1c3d65 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -409,6 +409,7 @@ Future<Response> Master::Http::state(const Request& request)
object.values["start_time"] = master.startTime.secs();
object.values["id"] = master.info.id();
object.values["pid"] = string(master.self());
+ object.values["hostname"] = master.info.hostname();
object.values["activated_slaves"] = master.slaves.size();
object.values["deactivated_slaves"] = master.deactivatedSlaves.size();
object.values["staged_tasks"] = master.stats.tasks[TASK_STAGING];
http://git-wip-us.apache.org/repos/asf/mesos/blob/3cce8ea7/src/master/master.cpp
----------------------------------------------------------------------
diff --git a/src/master/master.cpp b/src/master/master.cpp
index 4d9a9d1..6827852 100644
--- a/src/master/master.cpp
+++ b/src/master/master.cpp
@@ -297,7 +297,25 @@ void Master::initialize()
info.set_port(self().port);
info.set_pid(self());
- LOG(INFO) << "Master ID: " << info.id();
+ // Determine our hostname or use the hostname provided.
+ string hostname;
+
+ if (flags.hostname.isNone()) {
+ Try<string> result = os::hostname();
+
+ if (result.isError()) {
+ LOG(FATAL) << "Failed to get hostname: " << result.error();
+ }
+
+ hostname = result.get();
+ } else {
+ hostname = flags.hostname.get();
+ }
+
+ info.set_hostname(hostname);
+
+ LOG(INFO) << "Master ID: '" << info.id()
+ << "' Hostname: '" << info.hostname() << "'";
if (flags.authenticate) {
LOG(INFO) << "Master only allowing authenticated frameworks to register!";