From bfa7f7c95ffb2b3504cbba914ae3de4d0962b874 Mon Sep 17 00:00:00 2001 From: wxyu Date: Thu, 22 Aug 2019 19:01:44 +0800 Subject: [PATCH] MS-402 Add dump implementation for TaskTableItem Former-commit-id: f2957c7e7cf0c719b9b814f2e8ac16b42c396b2b --- cpp/CHANGELOG.md | 1 + cpp/src/scheduler/ResourceMgr.cpp | 3 +- cpp/src/scheduler/TaskTable.cpp | 74 ++++++++++++++++++------------- cpp/src/scheduler/TaskTable.h | 3 ++ 4 files changed, 48 insertions(+), 33 deletions(-) diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index 9291e5a15a..ca8c8fb29c 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -39,6 +39,7 @@ Please mark all change in change log and use the ticket from JIRA. - MS-391 - Add PushTaskToNeighbourHasExecutor action - MS-394 - Update scheduler unittest - MS-400 - Add timestamp record in task state change function +- MS-402 - Add dump implementation for TaskTableItem ## New Feature - MS-343 - Implement ResourceMgr diff --git a/cpp/src/scheduler/ResourceMgr.cpp b/cpp/src/scheduler/ResourceMgr.cpp index 44ebbfad44..cf54472732 100644 --- a/cpp/src/scheduler/ResourceMgr.cpp +++ b/cpp/src/scheduler/ResourceMgr.cpp @@ -99,7 +99,8 @@ ResourceMgr::DumpTaskTables() { ss << ">>>>>>>>>>>>>>>ResourceMgr::DumpTaskTable<<<<<<<<<<<<<<<" << std::endl; for (auto &resource : resources_) { ss << resource->Dump() << std::endl; - ss << resource->task_table().Dump() << std::endl; + ss << resource->task_table().Dump(); + ss << resource->Dump() << std::endl << std::endl; } return ss.str(); } diff --git a/cpp/src/scheduler/TaskTable.cpp b/cpp/src/scheduler/TaskTable.cpp index fb3c317747..87083c0c6f 100644 --- a/cpp/src/scheduler/TaskTable.cpp +++ b/cpp/src/scheduler/TaskTable.cpp @@ -23,6 +23,35 @@ get_now_timestamp() { return millis; } +std::string +ToString(TaskTableItemState state) { + switch (state) { + case TaskTableItemState::INVALID: return "INVALID"; + case TaskTableItemState::START: return "START"; + case TaskTableItemState::LOADING: return "LOADING"; + case TaskTableItemState::LOADED: return "LOADED"; + case TaskTableItemState::EXECUTING: return "EXECUTING"; + case TaskTableItemState::EXECUTED: return "EXECUTED"; + case TaskTableItemState::MOVING: return "MOVING"; + case TaskTableItemState::MOVED: return "MOVED"; + default: return ""; + } +} + +std::string +ToString(const TaskTimestamp ×tamp) { + std::stringstream ss; + ss << ""; + return ss.str(); +} + bool TaskTableItem::Load() { std::unique_lock lock(mutex); @@ -90,6 +119,16 @@ TaskTableItem::Moved() { return false; } +std::string +TaskTableItem::Dump() { + std::stringstream ss; + ss << ""; + return ss.str(); +} void TaskTable::Put(TaskPtr task) { @@ -98,6 +137,7 @@ TaskTable::Put(TaskPtr task) { item->id = id_++; item->task = std::move(task); item->state = TaskTableItemState::START; + item->timestamp.start = get_now_timestamp(); table_.push_back(item); if (subscriber_) { subscriber_(); @@ -112,6 +152,7 @@ TaskTable::Put(std::vector &tasks) { item->id = id_++; item->task = std::move(task); item->state = TaskTableItemState::START; + item->timestamp.start = get_now_timestamp(); table_.push_back(item); } if (subscriber_) { @@ -135,43 +176,12 @@ TaskTable::Clear() { // table_.erase(table_.begin(), iterator); } -std::string -ToString(TaskTableItemState state) { - switch (state) { - case TaskTableItemState::INVALID: return "INVALID"; - case TaskTableItemState::START: return "START"; - case TaskTableItemState::LOADING: return "LOADING"; - case TaskTableItemState::LOADED: return "LOADED"; - case TaskTableItemState::EXECUTING: return "EXECUTING"; - case TaskTableItemState::EXECUTED: return "EXECUTED"; - case TaskTableItemState::MOVING: return "MOVING"; - case TaskTableItemState::MOVED: return "MOVED"; - default: return ""; - } -} - -std::string -ToString(const TaskTimestamp ×tamp) { - std::stringstream ss; - ss << ""; - return ss.str(); -} std::string TaskTable::Dump() { std::stringstream ss; for (auto &item : table_) { - ss << "id; - ss << ", state=" << ToString(item->state); - ss << ", timestamp=" << ToString(item->timestamp); - ss << ">" << std::endl; + ss << item->Dump() << std::endl; } return ss.str(); } diff --git a/cpp/src/scheduler/TaskTable.h b/cpp/src/scheduler/TaskTable.h index 45cb9a815e..cb91e01e9d 100644 --- a/cpp/src/scheduler/TaskTable.h +++ b/cpp/src/scheduler/TaskTable.h @@ -70,6 +70,9 @@ struct TaskTableItem { bool Moved(); + + std::string + Dump(); }; using TaskTableItemPtr = std::shared_ptr;