| 252 | } |
| 253 | |
| 254 | Future<APIResult> call(const Call& callMessage) |
| 255 | { |
| 256 | Option<Error> error = |
| 257 | validation::scheduler::call::validate(devolve(callMessage)); |
| 258 | |
| 259 | if (error.isSome()) { |
| 260 | return Failure(error->message); |
| 261 | } |
| 262 | |
| 263 | if (callMessage.type() == Call::SUBSCRIBE) { |
| 264 | return Failure("This method doesn't support SUBSCRIBE calls"); |
| 265 | } |
| 266 | |
| 267 | if (state != SUBSCRIBED) { |
| 268 | return Failure( |
| 269 | "Cannot perform calls until subscribed. Current state: " + |
| 270 | stringify(state)); |
| 271 | } |
| 272 | |
| 273 | VLOG(1) << "Sending " << callMessage.type() << " call to " << master.get(); |
| 274 | |
| 275 | // TODO(vinod): Add support for sending MESSAGE calls directly |
| 276 | // to the slave, instead of relaying it through the master, as |
| 277 | // the scheduler driver does. |
| 278 | |
| 279 | process::http::Request request; |
| 280 | request.method = "POST"; |
| 281 | request.url = master.get(); |
| 282 | request.body = serialize(contentType, callMessage); |
| 283 | request.keepAlive = true; |
| 284 | request.headers = {{"Accept", stringify(contentType)}, |
| 285 | {"Content-Type", stringify(contentType)}}; |
| 286 | |
| 287 | // TODO(tillt): Add support for multi-step authentication protocols. |
| 288 | return authenticatee->authenticate(request, credential) |
| 289 | .recover([](const Future<process::http::Request>& future) { |
| 290 | return Failure( |
| 291 | stringify("HTTP authenticatee ") + |
| 292 | (future.isFailed() ? "failed: " + future.failure() : "discarded")); |
| 293 | }) |
| 294 | .then(defer(self(), &Self::_call, callMessage, lambda::_1)); |
| 295 | } |
| 296 | |
| 297 | void reconnect() |
| 298 | { |
nothing calls this directly
no test coverage detected