MCPcopy Create free account
hub / github.com/apache/mesos / launchTask

Method launchTask

src/tests/fetcher_cache_tests.cpp:448–504  ·  view source on GitHub ↗

Launches a task as described by its CommandInfo and returns its sandbox run directory path. Its completion will be indicated by the result of awaitFinished(task), where `task` is the return value of this method. TODO(bernd-mesos): Make this abstraction as generic and generally available for all testing as possible.

Source from the content-addressed store, hash-verified

446// TODO(bernd-mesos): Make this abstraction as generic and generally
447// available for all testing as possible.
448Try<FetcherCacheTest::Task> FetcherCacheTest::launchTask(
449 const CommandInfo& commandInfo,
450 size_t taskIndex)
451{
452 Future<vector<Offer>> offers;
453 EXPECT_CALL(scheduler, resourceOffers(driver.get(), _))
454 .WillOnce(FutureArg<1>(&offers))
455 .WillRepeatedly(DeclineOffers());
456
457 offers.await(TEST_AWAIT_TIMEOUT);
458 if (!offers.isReady()) {
459 return Error("Failed to wait for resource offers: " +
460 (offers.isFailed() ? offers.failure() : "discarded"));
461 }
462
463 if (offers->empty()) {
464 return Error("Received empty list of offers");
465 }
466 const Offer offer = offers.get()[0];
467
468 TaskInfo task;
469 task.set_name(taskName(taskIndex));
470 task.mutable_task_id()->set_value(taskName(taskIndex));
471 task.mutable_slave_id()->CopyFrom(offer.slave_id());
472
473 // We don't care about resources in these tests. This small amount
474 // will always succeed.
475 task.mutable_resources()->CopyFrom(
476 Resources::parse("cpus:1;mem:1").get());
477
478 task.mutable_command()->CopyFrom(commandInfo);
479
480 // Since we are always using a command executor here, the executor
481 // ID can be determined by copying the task ID.
482 ExecutorID executorId;
483 executorId.set_value(task.task_id().value());
484
485 vector<TaskInfo> tasks;
486 tasks.push_back(task);
487
488 Queue<TaskStatus> taskStatusQueue;
489
490 EXPECT_CALL(scheduler, statusUpdate(driver.get(), _))
491 .WillRepeatedly(PushTaskStatus(taskStatusQueue));
492
493 driver->launchTasks(offer.id(), tasks);
494
495 const Path sandboxPath = Path(slave::paths::getExecutorLatestRunPath(
496 flags.work_dir,
497 slaveId,
498 offer.framework_id(),
499 executorId));
500
501 sandboxes.push_back(sandboxPath);
502
503 return Task{sandboxPath, taskStatusQueue};
504}
505

Callers

nothing calls this directly

Calls 15

taskNameFunction · 0.85
PathClass · 0.85
getExecutorLatestRunPathFunction · 0.85
isReadyMethod · 0.80
isFailedMethod · 0.80
failureMethod · 0.80
CopyFromMethod · 0.80
launchTasksMethod · 0.65
ErrorFunction · 0.50
parseFunction · 0.50
getMethod · 0.45
awaitMethod · 0.45

Tested by

no test coverage detected