| 4130 | |
| 4131 | |
| 4132 | Future<Response> Master::Http::_unreserve( |
| 4133 | const SlaveID& slaveId, |
| 4134 | const RepeatedPtrField<Resource>& resources, |
| 4135 | const Option<Principal>& principal) const |
| 4136 | { |
| 4137 | Slave* slave = master->slaves.registered.get(slaveId); |
| 4138 | if (slave == nullptr) { |
| 4139 | return BadRequest("No agent found with specified ID"); |
| 4140 | } |
| 4141 | |
| 4142 | // Create an operation. |
| 4143 | Offer::Operation operation; |
| 4144 | operation.set_type(Offer::Operation::UNRESERVE); |
| 4145 | operation.mutable_unreserve()->mutable_resources()->CopyFrom(resources); |
| 4146 | |
| 4147 | Option<Error> error = validateAndUpgradeResources(&operation); |
| 4148 | if (error.isSome()) { |
| 4149 | return BadRequest(error->message); |
| 4150 | } |
| 4151 | |
| 4152 | error = validation::operation::validate(operation.unreserve()); |
| 4153 | if (error.isSome()) { |
| 4154 | return BadRequest("Invalid UNRESERVE operation: " + error->message); |
| 4155 | } |
| 4156 | |
| 4157 | return master->authorize( |
| 4158 | principal, ActionObject::unreserve(operation.unreserve())) |
| 4159 | .then(defer(master->self(), [=](bool authorized) -> Future<Response> { |
| 4160 | if (!authorized) { |
| 4161 | return Forbidden(); |
| 4162 | } |
| 4163 | |
| 4164 | return _operation(slaveId, operation); |
| 4165 | })); |
| 4166 | } |
| 4167 | |
| 4168 | |
| 4169 | Future<Response> Master::Http::_operation( |
nothing calls this directly
no test coverage detected