本文整理汇总了C++中TaskInfo::task_id方法的典型用法代码示例。如果您正苦于以下问题:C++ TaskInfo::task_id方法的具体用法?C++ TaskInfo::task_id怎么用?C++ TaskInfo::task_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TaskInfo
的用法示例。
在下文中一共展示了TaskInfo::task_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: model
// TODO(bmahler): Expose the executor name / source.
JSON::Object model(
const TaskInfo& task,
const FrameworkID& frameworkId,
const TaskState& state,
const vector<TaskStatus>& statuses)
{
JSON::Object object;
object.values["id"] = task.task_id().value();
object.values["name"] = task.name();
object.values["framework_id"] = frameworkId.value();
if (task.has_executor()) {
object.values["executor_id"] = task.executor().executor_id().value();
} else {
object.values["executor_id"] = "";
}
object.values["slave_id"] = task.slave_id().value();
object.values["state"] = TaskState_Name(state);
object.values["resources"] = model(task.resources());
JSON::Array array;
foreach (const TaskStatus& status, statuses) {
array.values.push_back(model(status));
}
示例2: createTask
Task createTask(
const TaskInfo& task,
const TaskState& state,
const FrameworkID& frameworkId)
{
Task t;
t.mutable_framework_id()->MergeFrom(frameworkId);
t.set_state(state);
t.set_name(task.name());
t.mutable_task_id()->MergeFrom(task.task_id());
t.mutable_slave_id()->MergeFrom(task.slave_id());
t.mutable_resources()->MergeFrom(task.resources());
if (task.has_executor()) {
t.mutable_executor_id()->CopyFrom(task.executor().executor_id());
}
t.mutable_labels()->MergeFrom(task.labels());
if (task.has_discovery()) {
t.mutable_discovery()->MergeFrom(task.discovery());
}
return t;
}
示例3: launch
void launch(const TaskInfo& task)
{
cout << "Starting task " << task.task_id().value() << endl;
tasks[task.task_id()] = task;
std::thread thread([=]() {
os::sleep(Seconds(random() % 10));
process::dispatch(self(), &Self::update, task, TaskState::TASK_FINISHED);
});
thread.detach();
update(task, TaskState::TASK_RUNNING);
}
示例4: update
void update(const TaskInfo& task, const TaskState& state)
{
UUID uuid = UUID::random();
TaskStatus status;
status.mutable_task_id()->CopyFrom(task.task_id());
status.mutable_executor_id()->CopyFrom(executorId);
status.set_state(state);
status.set_source(TaskStatus::SOURCE_EXECUTOR);
status.set_timestamp(process::Clock::now().secs());
status.set_uuid(uuid.toBytes());
Call call;
call.mutable_framework_id()->CopyFrom(frameworkId);
call.mutable_executor_id()->CopyFrom(executorId);
call.set_type(Call::UPDATE);
call.mutable_update()->mutable_status()->CopyFrom(status);
// Capture the status update.
updates[uuid] = call.update();
mesos->send(call);
}
示例5: driver
// This test ensures that the command executor does not send
// TASK_KILLING to frameworks that do not support the capability.
TEST_P_TEMP_DISABLED_ON_WINDOWS(CommandExecutorTest, NoTaskKillingCapability)
{
Try<Owned<cluster::Master>> master = StartMaster();
ASSERT_SOME(master);
Owned<MasterDetector> detector = master.get()->createDetector();
slave::Flags flags = CreateSlaveFlags();
flags.http_command_executor = GetParam();
Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), flags);
ASSERT_SOME(slave);
// Start the framework without the task killing capability.
MockScheduler sched;
MesosSchedulerDriver driver(
&sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
EXPECT_CALL(sched, registered(&driver, _, _));
Future<vector<Offer>> offers;
EXPECT_CALL(sched, resourceOffers(&driver, _))
.WillOnce(FutureArg<1>(&offers))
.WillRepeatedly(Return()); // Ignore subsequent offers.
driver.start();
AWAIT_READY(offers);
EXPECT_EQ(1u, offers->size());
// Launch a task with the command executor.
TaskInfo task = createTask(
offers->front().slave_id(),
offers->front().resources(),
"sleep 1000");
Future<TaskStatus> statusRunning;
EXPECT_CALL(sched, statusUpdate(_, _))
.WillOnce(FutureArg<1>(&statusRunning));
driver.launchTasks(offers->front().id(), {task});
AWAIT_READY(statusRunning);
EXPECT_EQ(TASK_RUNNING, statusRunning->state());
// There should only be a TASK_KILLED update.
Future<TaskStatus> statusKilled;
EXPECT_CALL(sched, statusUpdate(_, _))
.WillOnce(FutureArg<1>(&statusKilled));
driver.killTask(task.task_id());
AWAIT_READY(statusKilled);
EXPECT_EQ(TASK_KILLED, statusKilled->state());
driver.stop();
driver.join();
}
示例6: driver
TEST_F(ResourceOffersTest, TaskUsesMoreResourcesThanOffered)
{
Try<PID<Master> > master = StartMaster();
ASSERT_SOME(master);
Try<PID<Slave> > slave = StartSlave();
ASSERT_SOME(slave);
MockScheduler sched;
MesosSchedulerDriver driver(&sched, DEFAULT_FRAMEWORK_INFO, master.get());
EXPECT_CALL(sched, registered(&driver, _, _))
.Times(1);
Future<vector<Offer> > offers;
EXPECT_CALL(sched, resourceOffers(&driver, _))
.WillOnce(FutureArg<1>(&offers))
.WillRepeatedly(Return()); // Ignore subsequent offers.
driver.start();
AWAIT_READY(offers);
EXPECT_NE(0u, offers.get().size());
TaskInfo task;
task.set_name("");
task.mutable_task_id()->set_value("1");
task.mutable_slave_id()->MergeFrom(offers.get()[0].slave_id());
task.mutable_executor()->MergeFrom(DEFAULT_EXECUTOR_INFO);
Resource* cpus = task.add_resources();
cpus->set_name("cpus");
cpus->set_type(Value::SCALAR);
cpus->mutable_scalar()->set_value(2.01);
vector<TaskInfo> tasks;
tasks.push_back(task);
Future<TaskStatus> status;
EXPECT_CALL(sched, statusUpdate(&driver, _))
.WillOnce(FutureArg<1>(&status));
driver.launchTasks(offers.get()[0].id(), tasks);
AWAIT_READY(status);
EXPECT_EQ(task.task_id(), status.get().task_id());
EXPECT_EQ(TASK_LOST, status.get().state());
EXPECT_TRUE(status.get().has_message());
EXPECT_EQ("Task uses more resources than offered", status.get().message());
driver.stop();
driver.join();
Shutdown();
}
示例7: launchTask
virtual void launchTask(ExecutorDriver* driver, const TaskInfo& task)
{
cout << "Starting task " << task.task_id().value() << endl;
TaskStatus status;
status.mutable_task_id()->MergeFrom(task.task_id());
status.set_state(TASK_RUNNING);
driver->sendStatusUpdate(status);
sleep(1);
cout << "Finishing task " << task.task_id().value() << endl;
status.mutable_task_id()->MergeFrom(task.task_id());
status.set_state(TASK_FINISHED);
driver->sendStatusUpdate(status);
}
示例8: launchTask
virtual void launchTask(ExecutorDriver* driver, const TaskInfo& task)
{
cout << "Starting task " << task.task_id().value() << endl;
TaskStatus status;
status.mutable_task_id()->MergeFrom(task.task_id());
status.set_state(TASK_RUNNING);
driver->sendStatusUpdate(status);
// This is where one would perform the requested task.
cout << "Finishing task " << task.task_id().value() << endl;
status.mutable_task_id()->MergeFrom(task.task_id());
status.set_state(TASK_FINISHED);
driver->sendStatusUpdate(status);
}
示例9: run
void run(ExecutorDriver* driver, const TaskInfo& task)
{
os::sleep(Seconds(random() % 10));
TaskStatus status;
status.mutable_task_id()->MergeFrom(task.task_id());
status.set_state(TASK_FINISHED);
driver->sendStatusUpdate(status);
}
示例10: operator
void operator()() {
TaskStatus status;
status.mutable_task_id()->MergeFrom(task.task_id());
// Currently, just call the K3 executable with the generated command line from task.data()
try {
FILE* pipe = popen(k3_cmd.c_str(), "r");
if (!pipe) {
status.set_state(TASK_FAILED);
driver->sendStatusUpdate(status);
cout << "Failed to open subprocess" << endl;
}
char buffer[256];
while (!feof(pipe)) {
if (fgets(buffer, 256, pipe) != NULL) {
std::string s = std::string(buffer);
if (this->isMaster) {
driver->sendFrameworkMessage(s);
cout << s << endl;
}
else {
cout << s << endl;
}
}
}
int k3 = pclose(pipe);
if (k3 == 0) {
status.set_state(TASK_FINISHED);
cout << "Task " << task.task_id().value() << " Completed!" << endl;
driver->sendStatusUpdate(status);
}
else {
status.set_state(TASK_FAILED);
cout << "K3 Task " << task.task_id().value() << " returned error code: " << k3 << endl;
driver->sendStatusUpdate(status);
}
}
catch (...) {
status.set_state(TASK_FAILED);
driver->sendStatusUpdate(status);
}
//------------- END OF TASK -------------------
}
示例11: launchTask
void launchTask (ExecutorDriver* driver, const TaskInfo& task) override {
cout << "Starting task " << task.task_id().value() << endl;
TaskStatus status;
status.mutable_task_id()->MergeFrom(task.task_id());
StartInfo* info = new StartInfo(driver, task);
pthread_t pthread;
int res = pthread_create(&pthread, NULL, &RunProcess, info);
if (res != 0) {
status.set_state(TASK_FAILED);
delete info;
}
else {
pthread_detach(pthread);
status.set_state(TASK_RUNNING);
}
driver->sendStatusUpdate(status);
}
示例12: launchTask
virtual void launchTask(ExecutorDriver* driver, const TaskInfo& task)
{
cout << "Starting task " << task.task_id().value() << endl;
lambda::function<void(void)>* thunk =
new lambda::function<void(void)>(lambda::bind(&run, driver, task));
pthread_t pthread;
if (pthread_create(&pthread, NULL, &start, thunk) != 0) {
TaskStatus status;
status.mutable_task_id()->MergeFrom(task.task_id());
status.set_state(TASK_FAILED);
driver->sendStatusUpdate(status);
} else {
pthread_detach(pthread);
TaskStatus status;
status.mutable_task_id()->MergeFrom(task.task_id());
status.set_state(TASK_RUNNING);
driver->sendStatusUpdate(status);
}
}
示例13: createTask
inline Task createTask(const TaskInfo& task,
const TaskState& state,
const ExecutorID& executorId,
const FrameworkID& frameworkId)
{
Task t;
t.mutable_framework_id()->MergeFrom(frameworkId);
t.set_state(state);
t.set_name(task.name());
t.mutable_task_id()->MergeFrom(task.task_id());
t.mutable_slave_id()->MergeFrom(task.slave_id());
t.mutable_resources()->MergeFrom(task.resources());
if (!task.has_command()) {
t.mutable_executor_id()->MergeFrom(executorId);
}
return t;
}
示例14: createTask
Task createTask(
const TaskInfo& task,
const TaskState& state,
const FrameworkID& frameworkId)
{
Task t;
t.mutable_framework_id()->CopyFrom(frameworkId);
t.set_state(state);
t.set_name(task.name());
t.mutable_task_id()->CopyFrom(task.task_id());
t.mutable_slave_id()->CopyFrom(task.slave_id());
t.mutable_resources()->CopyFrom(task.resources());
if (task.has_executor()) {
t.mutable_executor_id()->CopyFrom(task.executor().executor_id());
}
if (task.has_labels()) {
t.mutable_labels()->CopyFrom(task.labels());
}
if (task.has_discovery()) {
t.mutable_discovery()->CopyFrom(task.discovery());
}
if (task.has_container()) {
t.mutable_container()->CopyFrom(task.container());
}
// Copy `user` if set.
if (task.has_command() && task.command().has_user()) {
t.set_user(task.command().user());
} else if (task.has_executor() && task.executor().command().has_user()) {
t.set_user(task.executor().command().user());
}
return t;
}
示例15: exec
// This test ensures that a killTask() can happen between runTask()
// and _runTask() and then gets "handled properly". This means that
// the task never gets started, but also does not get lost. The end
// result is status TASK_KILLED. Essentially, killing the task is
// realized while preparing to start it. See MESOS-947.
// Temporarily disabled due to MESOS-1945.
TEST_F(SlaveTest, DISABLED_KillTaskBetweenRunTaskParts)
{
Try<PID<Master> > master = StartMaster();
ASSERT_SOME(master);
MockExecutor exec(DEFAULT_EXECUTOR_ID);
TestContainerizer containerizer(&exec);
StandaloneMasterDetector detector(master.get());
MockSlave slave(CreateSlaveFlags(), &detector, &containerizer);
process::spawn(slave);
MockScheduler sched;
MesosSchedulerDriver driver(
&sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL);
EXPECT_CALL(sched, registered(&driver, _, _))
.Times(1);
Future<vector<Offer> > offers;
EXPECT_CALL(sched, resourceOffers(&driver, _))
.WillOnce(FutureArg<1>(&offers))
.WillRepeatedly(Return()); // Ignore subsequent offers.
driver.start();
AWAIT_READY(offers);
EXPECT_NE(0u, offers.get().size());
TaskInfo task;
task.set_name("");
task.mutable_task_id()->set_value("1");
task.mutable_slave_id()->MergeFrom(offers.get()[0].slave_id());
task.mutable_resources()->MergeFrom(offers.get()[0].resources());
task.mutable_executor()->MergeFrom(DEFAULT_EXECUTOR_INFO);
vector<TaskInfo> tasks;
tasks.push_back(task);
EXPECT_CALL(exec, registered(_, _, _, _))
.Times(0);
EXPECT_CALL(exec, launchTask(_, _))
.Times(0);
EXPECT_CALL(exec, shutdown(_))
.Times(0);
Future<TaskStatus> status;
EXPECT_CALL(sched, statusUpdate(&driver, _))
.WillRepeatedly(FutureArg<1>(&status));
EXPECT_CALL(slave, runTask(_, _, _, _, _))
.WillOnce(Invoke(&slave, &MockSlave::unmocked_runTask));
// Saved arguments from Slave::_runTask().
Future<bool> future;
FrameworkInfo frameworkInfo;
FrameworkID frameworkId;
// Skip what Slave::_runTask() normally does, save its arguments for
// later, tie reaching the critical moment when to kill the task to
// a future.
Future<Nothing> _runTask;
EXPECT_CALL(slave, _runTask(_, _, _, _, _))
.WillOnce(DoAll(FutureSatisfy(&_runTask),
SaveArg<0>(&future),
SaveArg<1>(&frameworkInfo),
SaveArg<2>(&frameworkId)));
driver.launchTasks(offers.get()[0].id(), tasks);
AWAIT_READY(_runTask);
Future<Nothing> killTask;
EXPECT_CALL(slave, killTask(_, _, _))
.WillOnce(DoAll(Invoke(&slave, &MockSlave::unmocked_killTask),
FutureSatisfy(&killTask)));
driver.killTask(task.task_id());
// Since this is the only task ever for this framework, the
// framework should get removed in Slave::_runTask().
// Thus we can observe that this happens before Shutdown().
Future<Nothing> removeFramework;
EXPECT_CALL(slave, removeFramework(_))
.WillOnce(DoAll(Invoke(&slave, &MockSlave::unmocked_removeFramework),
FutureSatisfy(&removeFramework)));
AWAIT_READY(killTask);
slave.unmocked__runTask(
future, frameworkInfo, frameworkId, master.get(), task);
//.........这里部分代码省略.........