| 260 | } |
| 261 | |
| 262 | void offers(const vector<Offer>& offers) |
| 263 | { |
| 264 | CHECK_EQ(SUBSCRIBED, state); |
| 265 | |
| 266 | const Resources executorResources = [this]() { |
| 267 | Resources resources(executor.resources()); |
| 268 | resources.allocate(role); |
| 269 | return resources; |
| 270 | }(); |
| 271 | |
| 272 | metrics.offers_received += offers.size(); |
| 273 | |
| 274 | foreach (const Offer& offer, offers) { |
| 275 | if (agentId.isNone()) { |
| 276 | // No active executor running in the cluster. |
| 277 | // Launch a new task with executor. |
| 278 | |
| 279 | if (Resources(offer.resources()) |
| 280 | .toUnreserved() |
| 281 | .contains(taskResources + executorResources)) { |
| 282 | LOG(INFO) << "Starting executor and task " << tasksLaunched << " on " |
| 283 | << offer.hostname(); |
| 284 | |
| 285 | launch(offer); |
| 286 | |
| 287 | agentId = offer.agent_id(); |
| 288 | } else { |
| 289 | decline(offer); |
| 290 | } |
| 291 | } else if (agentId == offer.agent_id()) { |
| 292 | // Offer from the same agent that has an active executor. |
| 293 | // Launch more tasks on that executor. |
| 294 | |
| 295 | if (Resources(offer.resources()) |
| 296 | .toUnreserved() |
| 297 | .contains(taskResources)) { |
| 298 | LOG(INFO) << "Starting task " << tasksLaunched << " on " |
| 299 | << offer.hostname(); |
| 300 | |
| 301 | launch(offer); |
| 302 | } else { |
| 303 | decline(offer); |
| 304 | } |
| 305 | } else { |
| 306 | // We have an active executor but this offer comes from a |
| 307 | // different agent; decline the offer. |
| 308 | decline(offer); |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | void update(const TaskStatus& status) |
| 314 | { |