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/06/17 17:41:59 UTC

[7/9] mesos git commit: Implemented START_MAINTENANCE Call in v1 master API.

Implemented START_MAINTENANCE Call in v1 master API.

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


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

Branch: refs/heads/master
Commit: 9d7475af3a54334950ea0eab5d7af71d4ccee440
Parents: 0102f6e
Author: haosdent huang <ha...@gmail.com>
Authored: Fri Jun 17 10:40:54 2016 -0700
Committer: Vinod Kone <vi...@gmail.com>
Committed: Fri Jun 17 10:40:54 2016 -0700

----------------------------------------------------------------------
 src/master/http.cpp   | 83 +++++++++++++++++++++++++++++-----------------
 src/master/master.hpp |  8 +++++
 2 files changed, 60 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/9d7475af/src/master/http.cpp
----------------------------------------------------------------------
diff --git a/src/master/http.cpp b/src/master/http.cpp
index e9fc1b2..f4dad22 100644
--- a/src/master/http.cpp
+++ b/src/master/http.cpp
@@ -671,7 +671,7 @@ Future<Response> Master::Http::api(
       return updateMaintenanceSchedule(call, principal, acceptType);
 
     case mesos::master::Call::START_MAINTENANCE:
-      return NotImplemented();
+      return startMaintenance(call, principal, acceptType);
 
     case mesos::master::Call::STOP_MAINTENANCE:
       return NotImplemented();
@@ -3016,41 +3016,18 @@ string Master::Http::MACHINE_DOWN_HELP()
 }
 
 
-// /master/machine/down endpoint handler.
-Future<Response> Master::Http::machineDown(
-    const Request& request,
-    const Option<string>& /*principal*/) const
+Future<Response> Master::Http::_startMaintenance(
+    const RepeatedPtrField<MachineID>& machineIds) const
 {
-  // When current master is not the leader, redirect to the leading master.
-  if (!master->elected()) {
-    return redirect(request);
-  }
-
-  if (request.method != "POST") {
-    return MethodNotAllowed({"POST"}, request.method);
-  }
-
-  // Parse the POST body as JSON.
-  Try<JSON::Array> jsonIds = JSON::parse<JSON::Array>(request.body);
-  if (jsonIds.isError()) {
-    return BadRequest(jsonIds.error());
-  }
-
-  // Convert the machines to a protobuf.
-  auto ids = ::protobuf::parse<RepeatedPtrField<MachineID>>(jsonIds.get());
-  if (ids.isError()) {
-    return BadRequest(ids.error());
-  }
-
   // Validate every machine in the list.
-  Try<Nothing> isValid = maintenance::validation::machines(ids.get());
+  Try<Nothing> isValid = maintenance::validation::machines(machineIds);
   if (isValid.isError()) {
     return BadRequest(isValid.error());
   }
 
   // Check that all machines are part of a maintenance schedule.
   // TODO(josephw): Allow a transition from `UP` to `DOWN`.
-  foreach (const MachineID& id, ids.get()) {
+  foreach (const MachineID& id, machineIds) {
     if (!master->machines.contains(id)) {
       return BadRequest(
           "Machine '" + stringify(JSON::protobuf(id)) +
@@ -3065,7 +3042,7 @@ Future<Response> Master::Http::machineDown(
   }
 
   return master->registrar->apply(Owned<Operation>(
-      new maintenance::StartMaintenance(ids.get())))
+      new maintenance::StartMaintenance(machineIds)))
     .then(defer(master->self(), [=](bool result) -> Future<Response> {
       // See the top comment in "master/maintenance.hpp" for why this check
       // is here, and is appropriate.
@@ -3077,7 +3054,7 @@ Future<Response> Master::Http::machineDown(
       // for all the tasks that were running on the slave and `LostSlaveMessage`
       // messages to the framework. This guards against the slave having dropped
       // the `ShutdownMessage`.
-      foreach (const MachineID& machineId, ids.get()) {
+      foreach (const MachineID& machineId, machineIds) {
         // The machine may not be in machines. This means no slaves are
         // currently registered on that machine so this is a no-op.
         if (master->machines.contains(machineId)) {
@@ -3103,7 +3080,7 @@ Future<Response> Master::Http::machineDown(
       }
 
       // Update the master's local state with the downed machines.
-      foreach (const MachineID& id, ids.get()) {
+      foreach (const MachineID& id, machineIds) {
         master->machines[id].info.set_mode(MachineInfo::DOWN);
       }
 
@@ -3112,6 +3089,50 @@ Future<Response> Master::Http::machineDown(
 }
 
 
+// /master/machine/down endpoint handler.
+Future<Response> Master::Http::machineDown(
+    const Request& request,
+    const Option<string>& /*principal*/) const
+{
+  // When current master is not the leader, redirect to the leading master.
+  if (!master->elected()) {
+    return redirect(request);
+  }
+
+  if (request.method != "POST") {
+    return MethodNotAllowed({"POST"}, request.method);
+  }
+
+  // Parse the POST body as JSON.
+  Try<JSON::Array> jsonIds = JSON::parse<JSON::Array>(request.body);
+  if (jsonIds.isError()) {
+    return BadRequest(jsonIds.error());
+  }
+
+  // Convert the machines to a protobuf.
+  auto ids = ::protobuf::parse<RepeatedPtrField<MachineID>>(jsonIds.get());
+  if (ids.isError()) {
+    return BadRequest(ids.error());
+  }
+
+  return _startMaintenance(ids.get());
+}
+
+
+Future<Response> Master::Http::startMaintenance(
+    const mesos::master::Call& call,
+    const Option<string>& principal,
+    ContentType /*contentType*/) const
+{
+  CHECK_EQ(mesos::master::Call::START_MAINTENANCE, call.type());
+  CHECK(call.has_start_maintenance());
+
+  RepeatedPtrField<MachineID> machineIds = call.start_maintenance().machines();
+
+  return _startMaintenance(machineIds);
+}
+
+
 // /master/machine/up endpoint help.
 string Master::Http::MACHINE_UP_HELP()
 {

http://git-wip-us.apache.org/repos/asf/mesos/blob/9d7475af/src/master/master.hpp
----------------------------------------------------------------------
diff --git a/src/master/master.hpp b/src/master/master.hpp
index 8c4a8ce..4a201b2 100644
--- a/src/master/master.hpp
+++ b/src/master/master.hpp
@@ -1249,6 +1249,9 @@ private:
     process::Future<mesos::maintenance::ClusterStatus>
       _getMaintenanceStatus() const;
 
+    process::Future<process::http::Response> _startMaintenance(
+        const google::protobuf::RepeatedPtrField<MachineID>& machineIds) const;
+
     /**
      * Continuation for operations: /reserve, /unreserve,
      * /create-volumes and /destroy-volumes. First tries to recover
@@ -1340,6 +1343,11 @@ private:
         const Option<std::string>& principal,
         ContentType contentType) const;
 
+    process::Future<process::http::Response> startMaintenance(
+        const mesos::master::Call& call,
+        const Option<std::string>& principal,
+        ContentType contentType) const;
+
     Master* master;
 
     // NOTE: The quota specific pieces of the Operator API are factored