| 5241 | |
| 5242 | |
| 5243 | void Slave::subscribe( |
| 5244 | StreamingHttpConnection<v1::executor::Event> http, |
| 5245 | const Call::Subscribe& subscribe, |
| 5246 | Framework* framework, |
| 5247 | Executor* executor) |
| 5248 | { |
| 5249 | CHECK_NOTNULL(framework); |
| 5250 | CHECK_NOTNULL(executor); |
| 5251 | |
| 5252 | LOG(INFO) << "Received Subscribe request for HTTP executor " << *executor; |
| 5253 | |
| 5254 | CHECK(state == RECOVERING || state == DISCONNECTED || |
| 5255 | state == RUNNING || state == TERMINATING) |
| 5256 | << state; |
| 5257 | |
| 5258 | if (state == TERMINATING) { |
| 5259 | LOG(WARNING) << "Shutting down executor " << *executor << " as the agent " |
| 5260 | << "is terminating"; |
| 5261 | http.send(ShutdownExecutorMessage()); |
| 5262 | http.close(); |
| 5263 | return; |
| 5264 | } |
| 5265 | |
| 5266 | CHECK(framework->state == Framework::RUNNING || |
| 5267 | framework->state == Framework::TERMINATING) |
| 5268 | << framework->state; |
| 5269 | |
| 5270 | if (framework->state == Framework::TERMINATING) { |
| 5271 | LOG(WARNING) << "Shutting down executor " << *executor << " as the " |
| 5272 | << "framework is terminating"; |
| 5273 | http.send(ShutdownExecutorMessage()); |
| 5274 | http.close(); |
| 5275 | return; |
| 5276 | } |
| 5277 | |
| 5278 | switch (executor->state) { |
| 5279 | case Executor::TERMINATING: |
| 5280 | case Executor::TERMINATED: |
| 5281 | // TERMINATED is possible if the executor forks, the parent process |
| 5282 | // terminates and the child process (driver) tries to register! |
| 5283 | LOG(WARNING) << "Shutting down executor " << *executor |
| 5284 | << " because it is in unexpected state " << executor->state; |
| 5285 | http.send(ShutdownExecutorMessage()); |
| 5286 | http.close(); |
| 5287 | break; |
| 5288 | case Executor::RUNNING: |
| 5289 | case Executor::REGISTERING: { |
| 5290 | // Close the earlier connection if one existed. This can even |
| 5291 | // be a retried Subscribe request from an already connected |
| 5292 | // executor. |
| 5293 | if (executor->http.isSome()) { |
| 5294 | LOG(WARNING) << "Closing already existing HTTP connection from " |
| 5295 | << "executor " << *executor; |
| 5296 | executor->http->close(); |
| 5297 | } |
| 5298 | |
| 5299 | executor->state = Executor::RUNNING; |
| 5300 |
no test coverage detected