Extracted strings into constants in example frameworks.

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


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

Branch: refs/heads/master
Commit: 4b9a543fae7a5932fc638aafd1502b8d648550fe
Parents: 7d67251
Author: Armand Grillet <agril...@mesosphere.io>
Authored: Thu Aug 10 16:58:52 2017 +0200
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Thu Aug 10 18:26:05 2017 +0200

----------------------------------------------------------------------
 src/examples/balloon_framework.cpp             | 27 ++++++++++---------
 src/examples/disk_full_framework.cpp           | 15 ++++++-----
 src/examples/docker_no_executor_framework.cpp  |  7 +++--
 src/examples/dynamic_reservation_framework.cpp |  4 ++-
 src/examples/load_generator_framework.cpp      |  3 ++-
 src/examples/long_lived_framework.cpp          | 29 ++++++++++++---------
 src/examples/no_executor_framework.cpp         |  4 ++-
 src/examples/persistent_volume_framework.cpp   |  3 ++-
 src/examples/test_framework.cpp                | 18 ++++++++-----
 src/examples/test_http_framework.cpp           | 15 ++++++-----
 10 files changed, 76 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/4b9a543f/src/examples/balloon_framework.cpp
----------------------------------------------------------------------
diff --git a/src/examples/balloon_framework.cpp 
b/src/examples/balloon_framework.cpp
index 1045333..08cf566 100644
--- a/src/examples/balloon_framework.cpp
+++ b/src/examples/balloon_framework.cpp
@@ -63,6 +63,10 @@ const double CPUS_PER_TASK = 0.1;
 const double CPUS_PER_EXECUTOR = 0.1;
 const int32_t MEM_PER_EXECUTOR = 64;
 
+constexpr char EXECUTOR_BINARY[] = "balloon-executor";
+constexpr char FRAMEWORK_PRINCIPAL[] = "balloon-framework-cpp";
+constexpr char FRAMEWORK_METRICS_PREFIX[] = "balloon_framework";
+
 class Flags : public virtual flags::FlagsBase
 {
 public:
@@ -324,15 +328,16 @@ private:
   {
     Metrics(const BalloonSchedulerProcess& _scheduler)
       : uptime_secs(
-            "balloon_framework/uptime_secs",
+            string(FRAMEWORK_METRICS_PREFIX) + "/uptime_secs",
             defer(_scheduler, &BalloonSchedulerProcess::_uptime_secs)),
         registered(
-            "balloon_framework/registered",
+            string(FRAMEWORK_METRICS_PREFIX) + "/registered",
             defer(_scheduler, &BalloonSchedulerProcess::_registered)),
-        tasks_finished("balloon_framework/tasks_finished"),
-        tasks_oomed("balloon_framework/tasks_oomed"),
-        launch_failures("balloon_framework/launch_failures"),
-        abnormal_terminations("balloon_framework/abnormal_terminations")
+        tasks_finished(string(FRAMEWORK_METRICS_PREFIX) + "/tasks_finished"),
+        tasks_oomed(string(FRAMEWORK_METRICS_PREFIX) + "/tasks_oomed"),
+        launch_failures(string(FRAMEWORK_METRICS_PREFIX) + "/launch_failures"),
+        abnormal_terminations(
+            string(FRAMEWORK_METRICS_PREFIX) + "/abnormal_terminations")
     {
       process::metrics::add(uptime_secs);
       process::metrics::add(registered);
@@ -513,12 +518,10 @@ int main(int argc, char** argv)
   if (flags.executor_command.isSome()) {
     command = flags.executor_command.get();
   } else if (flags.build_dir.isSome()) {
-    command = path::join(
-        flags.build_dir.get(), "src", "balloon-executor");
+    command = path::join(flags.build_dir.get(), "src", EXECUTOR_BINARY);
   } else {
-    command = path::join(
-        os::realpath(Path(argv[0]).dirname()).get(),
-        "balloon-executor");
+    command =
+      path::join(os::realpath(Path(argv[0]).dirname()).get(), EXECUTOR_BINARY);
   }
 
   executor.mutable_command()->set_value(command);
@@ -596,7 +599,7 @@ int main(int argc, char** argv)
     driver = new MesosSchedulerDriver(
         &scheduler, framework, flags.master, credential);
   } else {
-    framework.set_principal("balloon-framework-cpp");
+    framework.set_principal(FRAMEWORK_PRINCIPAL);
 
     driver = new MesosSchedulerDriver(
         &scheduler, framework, flags.master);

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b9a543f/src/examples/disk_full_framework.cpp
----------------------------------------------------------------------
diff --git a/src/examples/disk_full_framework.cpp 
b/src/examples/disk_full_framework.cpp
index 5639024..5eacc81 100644
--- a/src/examples/disk_full_framework.cpp
+++ b/src/examples/disk_full_framework.cpp
@@ -56,6 +56,8 @@ const double CPUS_PER_TASK = 0.1;
 const int MEMORY_PER_TASK = 16;
 const Bytes DISK_PER_TASK = Megabytes(5);
 
+constexpr char FRAMEWORK_PRINCIPAL[] = "disk-full-framework-cpp";
+constexpr char FRAMEWORK_METRICS_PREFIX[] = "disk_full_framework";
 
 class Flags : public virtual flags::FlagsBase
 {
@@ -288,14 +290,15 @@ private:
   {
     Metrics(const DiskFullSchedulerProcess& _scheduler)
       : uptime_secs(
-            "disk_full_framework/uptime_secs",
+            string(FRAMEWORK_METRICS_PREFIX) + "/uptime_secs",
             defer(_scheduler, &DiskFullSchedulerProcess::_uptime_secs)),
         registered(
-            "disk_full_framework/registered",
+            string(FRAMEWORK_METRICS_PREFIX) + "/registered",
             defer(_scheduler, &DiskFullSchedulerProcess::_registered)),
-        tasks_finished("disk_full_framework/tasks_finished"),
-        tasks_disk_full("disk_full_framework/tasks_disk_full"),
-        abnormal_terminations("disk_full_framework/abnormal_terminations")
+        tasks_finished(string(FRAMEWORK_METRICS_PREFIX) + "/tasks_finished"),
+        tasks_disk_full(string(FRAMEWORK_METRICS_PREFIX) + "/tasks_disk_full"),
+        abnormal_terminations(
+            string(FRAMEWORK_METRICS_PREFIX) + "/abnormal_terminations")
     {
       process::metrics::add(uptime_secs);
       process::metrics::add(registered);
@@ -480,7 +483,7 @@ int main(int argc, char** argv)
     driver = new MesosSchedulerDriver(
         &scheduler, framework, flags.master, credential);
   } else {
-    framework.set_principal("disk-full-framework-cpp");
+    framework.set_principal(FRAMEWORK_PRINCIPAL);
 
     driver = new MesosSchedulerDriver(
         &scheduler, framework, flags.master);

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b9a543f/src/examples/docker_no_executor_framework.cpp
----------------------------------------------------------------------
diff --git a/src/examples/docker_no_executor_framework.cpp 
b/src/examples/docker_no_executor_framework.cpp
index 4a58f11..312d281 100644
--- a/src/examples/docker_no_executor_framework.cpp
+++ b/src/examples/docker_no_executor_framework.cpp
@@ -39,6 +39,9 @@ using std::vector;
 const int32_t CPUS_PER_TASK = 1;
 const int32_t MEM_PER_TASK = 32;
 
+constexpr char FRAMEWORK_NAME[] = "Docker No Executor Framework (C++)";
+constexpr char FRAMEWORK_PRINCIPAL[] = "no-executor-framework-cpp";
+
 class DockerNoExecutorScheduler : public Scheduler
 {
 public:
@@ -178,7 +181,7 @@ int main(int argc, char** argv)
 
   FrameworkInfo framework;
   framework.set_user(""); // Have Mesos fill in the current user.
-  framework.set_name("Docker No Executor Framework (C++)");
+  framework.set_name(FRAMEWORK_NAME);
   framework.set_checkpoint(true);
   framework.add_capabilities()->set_type(
       FrameworkInfo::Capability::RESERVATION_REFINEMENT);
@@ -209,7 +212,7 @@ int main(int argc, char** argv)
     driver = new MesosSchedulerDriver(
         &scheduler, framework, argv[1], credential);
   } else {
-    framework.set_principal("no-executor-framework-cpp");
+    framework.set_principal(FRAMEWORK_PRINCIPAL);
 
     driver = new MesosSchedulerDriver(
         &scheduler, framework, argv[1]);

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b9a543f/src/examples/dynamic_reservation_framework.cpp
----------------------------------------------------------------------
diff --git a/src/examples/dynamic_reservation_framework.cpp 
b/src/examples/dynamic_reservation_framework.cpp
index f3b1c8c..f378479 100644
--- a/src/examples/dynamic_reservation_framework.cpp
+++ b/src/examples/dynamic_reservation_framework.cpp
@@ -42,6 +42,8 @@ using std::vector;
 const int32_t CPUS_PER_TASK = 1;
 const int32_t MEM_PER_TASK = 128;
 
+constexpr char FRAMEWORK_NAME[] = "Dynamic Reservation Framework (C++)";
+
 // The framework reserves resources to run at most one task at a time
 // on each agent; the resources are reserved when they are offered to
 // the framework for the first time, and are unreserved when all tasks
@@ -378,7 +380,7 @@ int main(int argc, char** argv)
 
   FrameworkInfo framework;
   framework.set_user(""); // Mesos'll fill in the current user.
-  framework.set_name("Dynamic Reservation Framework (C++)");
+  framework.set_name(FRAMEWORK_NAME);
   framework.set_role(flags.role.get());
   framework.set_principal(flags.principal);
   framework.add_capabilities()->set_type(

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b9a543f/src/examples/load_generator_framework.cpp
----------------------------------------------------------------------
diff --git a/src/examples/load_generator_framework.cpp 
b/src/examples/load_generator_framework.cpp
index abb70f4..f30895b 100644
--- a/src/examples/load_generator_framework.cpp
+++ b/src/examples/load_generator_framework.cpp
@@ -41,6 +41,7 @@ using std::endl;
 using std::string;
 using std::vector;
 
+constexpr char FRAMEWORK_NAME[] = "Load Generator Framework (C++)";
 
 // Generate load towards the master (by repeatedly sending
 // ReconcileTasksMessages) at the specified rate and for the
@@ -323,7 +324,7 @@ int main(int argc, char** argv)
 
   FrameworkInfo framework;
   framework.set_user(""); // Have Mesos fill in the current user.
-  framework.set_name("Load Generator Framework (C++)");
+  framework.set_name(FRAMEWORK_NAME);
   framework.add_capabilities()->set_type(
       FrameworkInfo::Capability::RESERVATION_REFINEMENT);
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b9a543f/src/examples/long_lived_framework.cpp
----------------------------------------------------------------------
diff --git a/src/examples/long_lived_framework.cpp 
b/src/examples/long_lived_framework.cpp
index 6e80f50..61ea64f 100644
--- a/src/examples/long_lived_framework.cpp
+++ b/src/examples/long_lived_framework.cpp
@@ -95,6 +95,10 @@ const int32_t MEM_PER_TASK = 1;
 const double CPUS_PER_EXECUTOR = 0.1;
 const int32_t MEM_PER_EXECUTOR = 32;
 
+constexpr char EXECUTOR_BINARY[] = "long-lived-executor";
+constexpr char EXECUTOR_NAME[] = "Long Lived Executor (C++)";
+constexpr char FRAMEWORK_NAME[] = "Long Lived Framework (C++)";
+constexpr char FRAMEWORK_METRICS_PREFIX[] = "long_lived_framework";
 
 // This scheduler picks one agent and repeatedly launches sleep tasks on it,
 // using a single multi-task executor. If the agent or executor fails, the
@@ -437,14 +441,17 @@ private:
   {
     Metrics(const LongLivedScheduler& scheduler)
       : uptime_secs(
-            "long_lived_framework/uptime_secs",
+            string(FRAMEWORK_METRICS_PREFIX) + "/uptime_secs",
             defer(scheduler, &LongLivedScheduler::_uptime_secs)),
         subscribed(
-            "long_lived_framework/subscribed",
+            string(FRAMEWORK_METRICS_PREFIX) + "/subscribed",
             defer(scheduler, &LongLivedScheduler::_subscribed)),
-        offers_received("long_lived_framework/offers_received"),
-        tasks_launched("long_lived_framework/tasks_launched"),
-        abnormal_terminations("long_lived_framework/abnormal_terminations")
+        offers_received(
+            string(FRAMEWORK_METRICS_PREFIX) + "/offers_received"),
+        tasks_launched(
+            string(FRAMEWORK_METRICS_PREFIX) + "/tasks_launched"),
+        abnormal_terminations(
+            string(FRAMEWORK_METRICS_PREFIX) + "/abnormal_terminations")
     {
       process::metrics::add(uptime_secs);
       process::metrics::add(subscribed);
@@ -580,7 +587,7 @@ int main(int argc, char** argv)
   ExecutorInfo executor;
   executor.mutable_executor_id()->set_value("default");
   executor.mutable_resources()->CopyFrom(resources);
-  executor.set_name("Long Lived Executor (C++)");
+  executor.set_name(EXECUTOR_NAME);
 
   // Determine the command to run the executor based on three possibilities:
   //   1) `--executor_command` was set, which overrides the below cases.
@@ -594,12 +601,10 @@ int main(int argc, char** argv)
   if (flags.executor_command.isSome()) {
     command = flags.executor_command.get();
   } else if (flags.build_dir.isSome()) {
-    command = path::join(
-        flags.build_dir.get(), "src", "long-lived-executor");
+    command = path::join(flags.build_dir.get(), "src", EXECUTOR_BINARY);
   } else {
-    command = path::join(
-        os::realpath(Path(argv[0]).dirname()).get(),
-        "long-lived-executor");
+    command =
+      path::join(os::realpath(Path(argv[0]).dirname()).get(), EXECUTOR_BINARY);
   }
 
   executor.mutable_command()->set_value(command);
@@ -635,7 +640,7 @@ int main(int argc, char** argv)
 
   FrameworkInfo framework;
   framework.set_user(os::user().get());
-  framework.set_name("Long Lived Framework (C++)");
+  framework.set_name(FRAMEWORK_NAME);
   framework.set_checkpoint(flags.checkpoint);
   framework.add_capabilities()->set_type(
       FrameworkInfo::Capability::RESERVATION_REFINEMENT);

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b9a543f/src/examples/no_executor_framework.cpp
----------------------------------------------------------------------
diff --git a/src/examples/no_executor_framework.cpp 
b/src/examples/no_executor_framework.cpp
index 7d841c6..8d31db3 100644
--- a/src/examples/no_executor_framework.cpp
+++ b/src/examples/no_executor_framework.cpp
@@ -43,6 +43,8 @@ using std::vector;
 
 using mesos::Resources;
 
+constexpr char FRAMEWORK_NAME[] = "No Executor Framework";
+
 
 static Offer::Operation LAUNCH(const vector<TaskInfo>& tasks)
 {
@@ -327,7 +329,7 @@ int main(int argc, char** argv)
 
   FrameworkInfo framework;
   framework.set_user(""); // Have Mesos fill in the current user.
-  framework.set_name("No Executor Framework");
+  framework.set_name(FRAMEWORK_NAME);
   framework.set_checkpoint(flags.checkpoint);
   framework.add_capabilities()->set_type(
       FrameworkInfo::Capability::RESERVATION_REFINEMENT);

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b9a543f/src/examples/persistent_volume_framework.cpp
----------------------------------------------------------------------
diff --git a/src/examples/persistent_volume_framework.cpp 
b/src/examples/persistent_volume_framework.cpp
index 1714029..46add06 100644
--- a/src/examples/persistent_volume_framework.cpp
+++ b/src/examples/persistent_volume_framework.cpp
@@ -52,6 +52,7 @@ using std::ostringstream;
 using std::string;
 using std::vector;
 
+constexpr char FRAMEWORK_NAME[] = "Persistent Volume Framework (C++)";
 
 // TODO(jieyu): Currently, persistent volume is only allowed for
 // reserved resources.
@@ -573,7 +574,7 @@ int main(int argc, char** argv)
 
   FrameworkInfo framework;
   framework.set_user(""); // Have Mesos fill in the current user.
-  framework.set_name("Persistent Volume Framework (C++)");
+  framework.set_name(FRAMEWORK_NAME);
   framework.set_role(flags.role);
   framework.set_checkpoint(true);
   framework.set_principal(flags.principal);

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b9a543f/src/examples/test_framework.cpp
----------------------------------------------------------------------
diff --git a/src/examples/test_framework.cpp b/src/examples/test_framework.cpp
index e9235a0..0f2f97d 100644
--- a/src/examples/test_framework.cpp
+++ b/src/examples/test_framework.cpp
@@ -51,6 +51,11 @@ using mesos::Resources;
 const int32_t CPUS_PER_TASK = 1;
 const int32_t MEM_PER_TASK = 128;
 
+constexpr char EXECUTOR_BINARY[] = "test-executor";
+constexpr char EXECUTOR_NAME[] = "Test Executor (C++)";
+constexpr char FRAMEWORK_NAME[] = "Test Framework (C++)";
+constexpr char FRAMEWORK_PRINCIPAL[] = "test-framework-cpp";
+
 class TestScheduler : public Scheduler
 {
 public:
@@ -220,11 +225,10 @@ int main(int argc, char** argv)
   string uri;
   Option<string> value = os::getenv("MESOS_HELPER_DIR");
   if (value.isSome()) {
-    uri = path::join(value.get(), "test-executor");
+    uri = path::join(value.get(), EXECUTOR_BINARY);
   } else {
-    uri = path::join(
-        os::realpath(Path(argv[0]).dirname()).get(),
-        "test-executor");
+    uri =
+      path::join(os::realpath(Path(argv[0]).dirname()).get(), EXECUTOR_BINARY);
   }
 
   Flags flags;
@@ -251,11 +255,11 @@ int main(int argc, char** argv)
   ExecutorInfo executor;
   executor.mutable_executor_id()->set_value("default");
   executor.mutable_command()->set_value(uri);
-  executor.set_name("Test Executor (C++)");
+  executor.set_name(EXECUTOR_NAME);
 
   FrameworkInfo framework;
   framework.set_user(""); // Have Mesos fill in the current user.
-  framework.set_name("Test Framework (C++)");
+  framework.set_name(FRAMEWORK_NAME);
   framework.set_role(flags.role);
   framework.add_capabilities()->set_type(
       FrameworkInfo::Capability::RESERVATION_REFINEMENT);
@@ -305,7 +309,7 @@ int main(int argc, char** argv)
         implicitAcknowledgements,
         credential);
   } else {
-    framework.set_principal("test-framework-cpp");
+    framework.set_principal(FRAMEWORK_PRINCIPAL);
 
     driver = new MesosSchedulerDriver(
         &scheduler,

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b9a543f/src/examples/test_http_framework.cpp
----------------------------------------------------------------------
diff --git a/src/examples/test_http_framework.cpp 
b/src/examples/test_http_framework.cpp
index d51a751..7000897 100644
--- a/src/examples/test_http_framework.cpp
+++ b/src/examples/test_http_framework.cpp
@@ -65,6 +65,10 @@ using mesos::v1::scheduler::Event;
 const int32_t CPUS_PER_TASK = 1;
 const int32_t MEM_PER_TASK = 128;
 
+constexpr char EXECUTOR_BINARY[] = "test-http-executor";
+constexpr char EXECUTOR_NAME[] = "Test Executor (C++)";
+constexpr char FRAMEWORK_NAME[] = "Event Call Scheduler using libprocess 
(C++)";
+
 class HTTPScheduler : public process::Process<HTTPScheduler>
 {
 public:
@@ -406,11 +410,10 @@ int main(int argc, char** argv)
   string uri;
   Option<string> value = os::getenv("MESOS_HELPER_DIR");
   if (value.isSome()) {
-    uri = path::join(value.get(), "test-http-executor");
+    uri = path::join(value.get(), EXECUTOR_BINARY);
   } else {
-    uri = path::join(
-        os::realpath(Path(argv[0]).dirname()).get(),
-        "test-http-executor");
+    uri =
+      path::join(os::realpath(Path(argv[0]).dirname()).get(), EXECUTOR_BINARY);
   }
 
   Flags flags;
@@ -436,7 +439,7 @@ int main(int argc, char** argv)
   }
 
   FrameworkInfo framework;
-  framework.set_name("Event Call Scheduler using libprocess (C++)");
+  framework.set_name(FRAMEWORK_NAME);
   framework.set_role(flags.role);
   framework.add_capabilities()->set_type(
       FrameworkInfo::Capability::RESERVATION_REFINEMENT);
@@ -455,7 +458,7 @@ int main(int argc, char** argv)
   ExecutorInfo executor;
   executor.mutable_executor_id()->set_value("default");
   executor.mutable_command()->set_value(uri);
-  executor.set_name("Test Executor (C++)");
+  executor.set_name(EXECUTOR_NAME);
 
   value = os::getenv("DEFAULT_PRINCIPAL");
   if (value.isNone()) {

Reply via email to