| 347 | |
| 348 | |
| 349 | Future<Containerizer::LaunchResult> ComposingContainerizerProcess::_launch( |
| 350 | const ContainerID& containerId, |
| 351 | const ContainerConfig& containerConfig, |
| 352 | const map<string, string>& environment, |
| 353 | const Option<std::string>& pidCheckpointPath, |
| 354 | vector<Containerizer*>::iterator containerizer, |
| 355 | Containerizer::LaunchResult launchResult) |
| 356 | { |
| 357 | if (!containers_.contains(containerId)) { |
| 358 | // If we are here a destroy started and finished in the interim. |
| 359 | return launchResult; |
| 360 | } |
| 361 | |
| 362 | Container* container = containers_.at(containerId); |
| 363 | |
| 364 | if (launchResult == Containerizer::LaunchResult::SUCCESS) { |
| 365 | // Note that we don't update the state if a destroy is in progress. |
| 366 | if (container->state == LAUNCHING) { |
| 367 | container->state = LAUNCHED; |
| 368 | |
| 369 | // This is needed for eventually removing the given container from |
| 370 | // the list of active containers. |
| 371 | container->containerizer->wait(containerId) |
| 372 | .onAny(defer(self(), [=](const Future<Option<ContainerTermination>>&) { |
| 373 | if (containers_.contains(containerId)) { |
| 374 | delete containers_.at(containerId); |
| 375 | containers_.erase(containerId); |
| 376 | } |
| 377 | })); |
| 378 | } |
| 379 | |
| 380 | // Note that the return value is not impacted |
| 381 | // by whether a destroy is currently in progress. |
| 382 | return Containerizer::LaunchResult::SUCCESS; |
| 383 | } |
| 384 | |
| 385 | // If we are here, the launch is not supported by `containerizer`. |
| 386 | |
| 387 | // Try the next containerizer. |
| 388 | ++containerizer; |
| 389 | |
| 390 | if (containerizer == containerizers_.end()) { |
| 391 | // If we are here none of the containerizers support the launch. |
| 392 | |
| 393 | // We destroy the container irrespective whether |
| 394 | // a destroy is already in progress, for simplicity. |
| 395 | containers_.erase(containerId); |
| 396 | delete container; |
| 397 | |
| 398 | // None of the containerizers support the launch. |
| 399 | return Containerizer::LaunchResult::NOT_SUPPORTED; |
| 400 | } |
| 401 | |
| 402 | if (container->state == DESTROYING) { |
| 403 | // If we are here there is at least one more containerizer that could |
| 404 | // potentially launch this container. But since a destroy is in progress |
| 405 | // we do not try any other containerizers. |
| 406 | // |