Repository: mesos Updated Branches: refs/heads/master 127766845 -> 589d5b260
Implemented CREATE_VOLUMES Call in v1 master API. Review: https://reviews.apache.org/r/48926/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/28a029d2 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/28a029d2 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/28a029d2 Branch: refs/heads/master Commit: 28a029d214db115117dbdff7fb93c77eaf2a6d59 Parents: 1277668 Author: Shuai Lin <linshuai2...@gmail.com> Authored: Wed Jun 22 14:17:56 2016 -0700 Committer: Vinod Kone <vinodk...@gmail.com> Committed: Wed Jun 22 14:17:56 2016 -0700 ---------------------------------------------------------------------- src/master/http.cpp | 74 ++++++++++++++++++++++++++++++---------------- src/master/master.hpp | 10 +++++++ 2 files changed, 59 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/28a029d2/src/master/http.cpp ---------------------------------------------------------------------- diff --git a/src/master/http.cpp b/src/master/http.cpp index 7daaf12..00cf8a6 100644 --- a/src/master/http.cpp +++ b/src/master/http.cpp @@ -656,7 +656,7 @@ Future<Response> Master::Http::api( return NotImplemented(); case mesos::master::Call::CREATE_VOLUMES: - return NotImplemented(); + return createVolumes(call, principal, acceptType); case mesos::master::Call::DESTROY_VOLUMES: return NotImplemented(); @@ -988,6 +988,42 @@ string Master::Http::CREATE_VOLUMES_HELP() } +Future<Response> Master::Http::_createVolumes( + 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::CREATE); + operation.mutable_create()->mutable_volumes()->CopyFrom(volumes); + + Option<Error> validate = validation::operation::validate( + operation.create(), slave->checkpointedResources, principal); + + if (validate.isSome()) { + return BadRequest("Invalid CREATE operation: " + validate.get().message); + } + + return master->authorizeCreateVolume(operation.create(), principal) + .then(defer(master->self(), [=](bool authorized) -> Future<Response> { + if (!authorized) { + return Forbidden(); + } + + // The resources required for this operation are equivalent to the + // volumes specified by the user minus any DiskInfo (DiskInfo will + // be created when this operation is applied). + return _operation(slaveId, removeDiskInfos(volumes), operation); + })); +} + + Future<Response> Master::Http::createVolumes( const Request& request, const Option<string>& principal) const @@ -1021,11 +1057,6 @@ Future<Response> Master::Http::createVolumes( 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"); @@ -1049,29 +1080,22 @@ Future<Response> Master::Http::createVolumes( volumes += volume.get(); } - // Create an offer operation. - Offer::Operation operation; - operation.set_type(Offer::Operation::CREATE); - operation.mutable_create()->mutable_volumes()->CopyFrom(volumes); + return _createVolumes(slaveId, volumes, principal); +} - Option<Error> validate = validation::operation::validate( - operation.create(), slave->checkpointedResources, principal); - if (validate.isSome()) { - return BadRequest("Invalid CREATE operation: " + validate.get().message); - } +Future<Response> Master::Http::createVolumes( + const mesos::master::Call& call, + const Option<string>& principal, + ContentType /*contentType*/) const +{ + CHECK_EQ(mesos::master::Call::CREATE_VOLUMES, call.type()); + CHECK(call.has_create_volumes()); - return master->authorizeCreateVolume(operation.create(), principal) - .then(defer(master->self(), [=](bool authorized) -> Future<Response> { - if (!authorized) { - return Forbidden(); - } + SlaveID slaveId = call.create_volumes().agent_id(); + RepeatedPtrField<Resource> volumes = call.create_volumes().volumes(); - // The resources required for this operation are equivalent to the - // volumes specified by the user minus any DiskInfo (DiskInfo will - // be created when this operation is applied). - return _operation(slaveId, removeDiskInfos(volumes), operation); - })); + return _createVolumes(slaveId, volumes, principal); } http://git-wip-us.apache.org/repos/asf/mesos/blob/28a029d2/src/master/master.hpp ---------------------------------------------------------------------- diff --git a/src/master/master.hpp b/src/master/master.hpp index fe57878..d9d5964 100644 --- a/src/master/master.hpp +++ b/src/master/master.hpp @@ -1305,6 +1305,11 @@ private: process::Future<process::http::Response> _stopMaintenance( const google::protobuf::RepeatedPtrField<MachineID>& machineIds) const; + process::Future<process::http::Response> _createVolumes( + 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 @@ -1416,6 +1421,11 @@ private: const Option<std::string>& principal, ContentType contentType) const; + process::Future<process::http::Response> createVolumes( + 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