Skip to content

Commit

Permalink
Extend Task with optional start time field.
Browse files Browse the repository at this point in the history
Task start time will be updated when it's not set
or status update is ealier then current start time.
  • Loading branch information
janisz committed Dec 28, 2016
1 parent 3cb30eb commit 0256557
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/mesos/mesos.proto
Expand Up @@ -1547,6 +1547,8 @@ message Task {

// Specific user under which task is running.
optional string user = 14;

optional double start_time = 15;
}


Expand Down
4 changes: 4 additions & 0 deletions src/common/http.cpp
Expand Up @@ -360,6 +360,10 @@ JSON::Object model(const Task& task)
object.values["container"] = JSON::protobuf(task.container());
}

if (task.has_start_time()) {
object.values["start_time"] = task.start_time();
}

return object;
}

Expand Down
3 changes: 2 additions & 1 deletion src/common/type_utils.cpp
Expand Up @@ -392,7 +392,8 @@ bool operator==(const Task& left, const Task& right)
left.status_update_uuid() == right.status_update_uuid() &&
left.labels() == right.labels() &&
left.discovery() == right.discovery() &&
left.user() == right.user();
left.user() == right.user() &&
left.start_time() == right.start_time();
}


Expand Down
6 changes: 6 additions & 0 deletions src/master/master.cpp
Expand Up @@ -7822,6 +7822,12 @@ void Master::updateTask(Task* task, const StatusUpdate& update)
// task transitioned to a new state.
bool sendSubscribersUpdate = false;

// Set start_time
if (status.state() != TASK_STAGING &&
(!task->has_start_time() || status.timestamp() < task->start_time())) {
task->set_start_time(status.timestamp());
}

// Set 'terminated' to true if this is the first time the task
// transitioned to terminal state. Also set the latest state.
bool terminated;
Expand Down
4 changes: 3 additions & 1 deletion src/tests/common/http_tests.cpp
Expand Up @@ -91,6 +91,7 @@ TEST(HTTPTest, ModelTask)

Task task = createTask(taskInfo, state, frameworkId);
task.add_statuses()->CopyFrom(statuses[0]);
task.set_start_time(1482932544);

JSON::Value object = model(task);

Expand Down Expand Up @@ -140,7 +141,8 @@ TEST(HTTPTest, ModelTask)
" },"
" \"visibility\":\"CLUSTER\""
" },"
" \"user\":\"user1\""
" \"user\":\"user1\","
" \"start_time\":1482932544"
"}");

ASSERT_SOME(expected);
Expand Down

0 comments on commit 0256557

Please sign in to comment.