| 1135 | |
| 1136 | |
| 1137 | Future<Response> Master::Http::shrinkVolume( |
| 1138 | const mesos::master::Call& call, |
| 1139 | const Option<Principal>& principal, |
| 1140 | ContentType /*contentType*/) const |
| 1141 | { |
| 1142 | // TODO(greggomann): Remove this check once the `Principal` type is used in |
| 1143 | // `ReservationInfo`, `DiskInfo`, and within the master's `principals` map. |
| 1144 | // See MESOS-7202. |
| 1145 | if (principal.isSome() && principal->value.isNone()) { |
| 1146 | return Forbidden( |
| 1147 | "The request's authenticated principal contains claims, but no value " |
| 1148 | "string. The master currently requires that principals have a value"); |
| 1149 | } |
| 1150 | |
| 1151 | CHECK_EQ(mesos::master::Call::SHRINK_VOLUME, call.type()); |
| 1152 | CHECK(call.has_shrink_volume()); |
| 1153 | |
| 1154 | // Only persistent volumes are supported right now. |
| 1155 | CHECK(call.shrink_volume().has_slave_id()); |
| 1156 | |
| 1157 | const SlaveID& slaveId = call.shrink_volume().slave_id(); |
| 1158 | |
| 1159 | Slave* slave = master->slaves.registered.get(slaveId); |
| 1160 | if (slave == nullptr) { |
| 1161 | return BadRequest("No agent found with specified ID"); |
| 1162 | } |
| 1163 | |
| 1164 | // Create an operation. |
| 1165 | Offer::Operation operation; |
| 1166 | operation.set_type(Offer::Operation::SHRINK_VOLUME); |
| 1167 | |
| 1168 | operation.mutable_shrink_volume()->mutable_volume()->CopyFrom( |
| 1169 | call.shrink_volume().volume()); |
| 1170 | |
| 1171 | operation.mutable_shrink_volume()->mutable_subtract()->CopyFrom( |
| 1172 | call.shrink_volume().subtract()); |
| 1173 | |
| 1174 | Option<Error> error = validateAndUpgradeResources(&operation); |
| 1175 | if (error.isSome()) { |
| 1176 | return BadRequest(error->message); |
| 1177 | } |
| 1178 | |
| 1179 | error = validation::operation::validate( |
| 1180 | operation.shrink_volume(), slave->capabilities); |
| 1181 | |
| 1182 | if (error.isSome()) { |
| 1183 | return BadRequest( |
| 1184 | "Invalid SHRINK_VOLUME operation on agent " + |
| 1185 | stringify(*slave) + ": " + error->message); |
| 1186 | } |
| 1187 | |
| 1188 | return master->authorize( |
| 1189 | principal, ActionObject::shrinkVolume(operation.shrink_volume())) |
| 1190 | .then(defer(master->self(), [=](bool authorized) -> Future<Response> { |
| 1191 | if (!authorized) { |
| 1192 | return Forbidden(); |
| 1193 | } |
| 1194 |
nothing calls this directly
no test coverage detected