/Users/deen/code/yugabyte-db/src/yb/server/webui_util.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // |
18 | | // The following only applies to changes made to this file as part of YugaByte development. |
19 | | // |
20 | | // Portions Copyright (c) YugaByte, Inc. |
21 | | // |
22 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
23 | | // in compliance with the License. You may obtain a copy of the License at |
24 | | // |
25 | | // http://www.apache.org/licenses/LICENSE-2.0 |
26 | | // |
27 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
28 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
29 | | // or implied. See the License for the specific language governing permissions and limitations |
30 | | // under the License. |
31 | | // |
32 | | |
33 | | #include "yb/server/webui_util.h" |
34 | | |
35 | | #include <string> |
36 | | |
37 | | #include "yb/common/schema.h" |
38 | | |
39 | | #include "yb/gutil/strings/human_readable.h" |
40 | | #include "yb/gutil/strings/substitute.h" |
41 | | |
42 | | #include "yb/server/monitored_task.h" |
43 | | |
44 | | #include "yb/util/url-coding.h" |
45 | | |
46 | | using strings::Substitute; |
47 | | |
48 | | namespace yb { |
49 | | namespace server { |
50 | | |
51 | | void HtmlOutputSchemaTable(const Schema& schema, |
52 | 2 | std::stringstream* output) { |
53 | 2 | *output << "<table class='table table-striped'>\n"; |
54 | 2 | *output << "<tr><th>Column</th><th>ID</th><th>Type</th></tr>\n"; |
55 | | |
56 | 8 | for (size_t i = 0; i < schema.num_columns(); i++) { |
57 | 6 | const ColumnSchema& col = schema.column(i); |
58 | 6 | *output << Format("<tr><th>$0</th><td>$1</td><td>$2</td></tr>\n", |
59 | 6 | EscapeForHtmlToString(col.name()), |
60 | 6 | schema.column_id(i), |
61 | 6 | col.TypeToString()); |
62 | 6 | } |
63 | 2 | *output << "</table>\n"; |
64 | 2 | } |
65 | | |
66 | | void HtmlOutputTask(const std::shared_ptr<MonitoredTask>& task, |
67 | 0 | std::stringstream* output) { |
68 | 0 | double time_since_started = 0; |
69 | 0 | if (task->start_timestamp().Initialized()) { |
70 | 0 | time_since_started = |
71 | 0 | MonoTime::Now().GetDeltaSince(task->start_timestamp()).ToSeconds(); |
72 | 0 | } |
73 | 0 | double running_secs = 0; |
74 | 0 | if (task->completion_timestamp().Initialized()) { |
75 | 0 | running_secs = task->completion_timestamp().GetDeltaSince( |
76 | 0 | task->start_timestamp()).ToSeconds(); |
77 | 0 | } else if (task->start_timestamp().Initialized()) { |
78 | 0 | running_secs = MonoTime::Now().GetDeltaSince( |
79 | 0 | task->start_timestamp()).ToSeconds(); |
80 | 0 | } |
81 | |
|
82 | 0 | *output << Substitute( |
83 | 0 | "<tr><th>$0</th><td>$1</td><td>$2 ago</td><td>$3</td><td>$4</td></tr>\n", |
84 | 0 | EscapeForHtmlToString(task->type_name()), |
85 | 0 | EscapeForHtmlToString(ToString(task->state())), |
86 | 0 | EscapeForHtmlToString( |
87 | 0 | HumanReadableElapsedTime::ToShortString(time_since_started)), |
88 | 0 | EscapeForHtmlToString( |
89 | 0 | HumanReadableElapsedTime::ToShortString(running_secs)), |
90 | 0 | EscapeForHtmlToString(task->description())); |
91 | 0 | } |
92 | | |
93 | | void HtmlOutputTasks(const std::unordered_set<std::shared_ptr<MonitoredTask>>& tasks, |
94 | 1 | std::stringstream* output) { |
95 | 1 | *output << "<table class='table table-striped'>\n"; |
96 | 1 | *output << " <tr><th>Task Name</th><th>State</th><th>Start " |
97 | 1 | "Time</th><th>Duration</th><th>Description</th></tr>\n"; |
98 | 0 | for (const auto& task : tasks) { |
99 | 0 | HtmlOutputTask(task, output); |
100 | 0 | } |
101 | 1 | *output << "</table>\n"; |
102 | 1 | } |
103 | | |
104 | | } // namespace server |
105 | | } // namespace yb |