| 4057 | |
| 4058 | |
| 4059 | Future<Response> Master::Http::unreserve( |
| 4060 | const Request& request, |
| 4061 | const Option<Principal>& principal) const |
| 4062 | { |
| 4063 | // TODO(greggomann): Remove this check once the `Principal` type is used in |
| 4064 | // `ReservationInfo`, `DiskInfo`, and within the master's `principals` map. |
| 4065 | // See MESOS-7202. |
| 4066 | if (principal.isSome() && principal->value.isNone()) { |
| 4067 | return Forbidden( |
| 4068 | "The request's authenticated principal contains claims, but no value " |
| 4069 | "string. The master currently requires that principals have a value"); |
| 4070 | } |
| 4071 | |
| 4072 | // When current master is not the leader, redirect to the leading master. |
| 4073 | if (!master->elected()) { |
| 4074 | return redirect(request); |
| 4075 | } |
| 4076 | |
| 4077 | if (request.method != "POST") { |
| 4078 | return MethodNotAllowed({"POST"}, request.method); |
| 4079 | } |
| 4080 | |
| 4081 | // Parse the query string in the request body. |
| 4082 | Try<hashmap<string, string>> decode = |
| 4083 | process::http::query::decode(request.body); |
| 4084 | |
| 4085 | if (decode.isError()) { |
| 4086 | return BadRequest("Unable to decode query string: " + decode.error()); |
| 4087 | } |
| 4088 | |
| 4089 | const hashmap<string, string>& values = decode.get(); |
| 4090 | |
| 4091 | Option<string> value; |
| 4092 | |
| 4093 | value = values.get("slaveId"); |
| 4094 | if (value.isNone()) { |
| 4095 | return BadRequest("Missing 'slaveId' query parameter in the request body"); |
| 4096 | } |
| 4097 | |
| 4098 | SlaveID slaveId; |
| 4099 | slaveId.set_value(value.get()); |
| 4100 | |
| 4101 | value = values.get("resources"); |
| 4102 | if (value.isNone()) { |
| 4103 | return BadRequest( |
| 4104 | "Missing 'resources' query parameter in the request body"); |
| 4105 | } |
| 4106 | |
| 4107 | Try<JSON::Array> parse = |
| 4108 | JSON::parse<JSON::Array>(value.get()); |
| 4109 | |
| 4110 | if (parse.isError()) { |
| 4111 | return BadRequest( |
| 4112 | "Error in parsing 'resources' query parameter in the request body: " + |
| 4113 | parse.error()); |
| 4114 | } |
| 4115 | |
| 4116 | RepeatedPtrField<Resource> resources; |