Implemented DESTROY_VOLUMES Call in v1 master API. Review: https://reviews.apache.org/r/48927/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/1c7ff6ea Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/1c7ff6ea Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/1c7ff6ea Branch: refs/heads/master Commit: 1c7ff6eab94ccc3deca3da990c8a69f4c9fc5e76 Parents: 28a029d Author: Shuai Lin <linshuai2...@gmail.com> Authored: Wed Jun 22 14:18:03 2016 -0700 Committer: Vinod Kone <vinodk...@gmail.com> Committed: Wed Jun 22 14:18:03 2016 -0700 ---------------------------------------------------------------------- src/master/http.cpp | 76 ++++++++++++++++++++++++++++++---------------- src/master/master.hpp | 10 ++++++ 2 files changed, 60 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/1c7ff6ea/src/master/http.cpp ---------------------------------------------------------------------- diff --git a/src/master/http.cpp b/src/master/http.cpp index 00cf8a6..70f084b 100644 --- a/src/master/http.cpp +++ b/src/master/http.cpp @@ -659,7 +659,7 @@ Future<Response> Master::Http::api( return createVolumes(call, principal, acceptType); case mesos::master::Call::DESTROY_VOLUMES: - return NotImplemented(); + return destroyVolumes(call, principal, acceptType); case mesos::master::Call::GET_MAINTENANCE_STATUS: return getMaintenanceStatus(call, principal, acceptType); @@ -1122,6 +1122,54 @@ string Master::Http::DESTROY_VOLUMES_HELP() } +Future<Response> Master::Http::_destroyVolumes( + const SlaveID& slaveId, + const RepeatedPtrField<Resource>& volumes, + const Option<string>& principal) const +{ + Slave* slave = master->slaves.registered.get(slaveId); + if (slave == nullptr) { + return BadRequest("No agent found with specified ID"); + } + + // Create an offer operation. + Offer::Operation operation; + operation.set_type(Offer::Operation::DESTROY); + operation.mutable_destroy()->mutable_volumes()->CopyFrom(volumes); + + Option<Error> validate = validation::operation::validate( + operation.destroy(), slave->checkpointedResources); + + if (validate.isSome()) { + return BadRequest("Invalid DESTROY operation: " + validate.get().message); + } + + return master->authorizeDestroyVolume(operation.destroy(), principal) + .then(defer(master->self(), [=](bool authorized) -> Future<Response> { + if (!authorized) { + return Forbidden(); + } + + return _operation(slaveId, volumes, operation); + })); +} + + +Future<Response> Master::Http::destroyVolumes( + const mesos::master::Call& call, + const Option<string>& principal, + ContentType /*contentType*/) const +{ + CHECK_EQ(mesos::master::Call::DESTROY_VOLUMES, call.type()); + CHECK(call.has_destroy_volumes()); + + SlaveID slaveId = call.destroy_volumes().agent_id(); + RepeatedPtrField<Resource> volumes = call.destroy_volumes().volumes(); + + return _destroyVolumes(slaveId, volumes, principal); +} + + Future<Response> Master::Http::destroyVolumes( const Request& request, const Option<string>& principal) const @@ -1155,11 +1203,6 @@ Future<Response> Master::Http::destroyVolumes( SlaveID slaveId; slaveId.set_value(value.get()); - Slave* slave = master->slaves.registered.get(slaveId); - if (slave == nullptr) { - return BadRequest("No agent found with specified ID"); - } - value = values.get("volumes"); if (value.isNone()) { return BadRequest("Missing 'volumes' query parameter"); @@ -1183,26 +1226,7 @@ Future<Response> Master::Http::destroyVolumes( volumes += volume.get(); } - // Create an offer operation. - Offer::Operation operation; - operation.set_type(Offer::Operation::DESTROY); - operation.mutable_destroy()->mutable_volumes()->CopyFrom(volumes); - - Option<Error> validate = validation::operation::validate( - operation.destroy(), slave->checkpointedResources); - - if (validate.isSome()) { - return BadRequest("Invalid DESTROY operation: " + validate.get().message); - } - - return master->authorizeDestroyVolume(operation.destroy(), principal) - .then(defer(master->self(), [=](bool authorized) -> Future<Response> { - if (!authorized) { - return Forbidden(); - } - - return _operation(slaveId, volumes, operation); - })); + return _destroyVolumes(slaveId, volumes, principal); } http://git-wip-us.apache.org/repos/asf/mesos/blob/1c7ff6ea/src/master/master.hpp ---------------------------------------------------------------------- diff --git a/src/master/master.hpp b/src/master/master.hpp index d9d5964..e983d1b 100644 --- a/src/master/master.hpp +++ b/src/master/master.hpp @@ -1310,6 +1310,11 @@ private: const google::protobuf::RepeatedPtrField<Resource>& volumes, const Option<std::string>& principal) const; + process::Future<process::http::Response> _destroyVolumes( + const SlaveID& slaveId, + const google::protobuf::RepeatedPtrField<Resource>& volumes, + const Option<std::string>& principal) const; + /** * Continuation for operations: /reserve, /unreserve, * /create-volumes and /destroy-volumes. First tries to recover @@ -1426,6 +1431,11 @@ private: const Option<std::string>& principal, ContentType contentType) const; + process::Future<process::http::Response> destroyVolumes( + 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