1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
#include "job_counters.h"
namespace NYT {
////////////////////////////////////////////////////////////////////
namespace {
ui64 CountTotal(const TNode& data)
{
if (data.IsMap()) {
if (auto totalPtr = data.AsMap().FindPtr("total")) {
return data["total"].IntCast<ui64>();
} else {
ui64 total = 0;
for (const auto& keyVal: data.AsMap()) {
total += CountTotal(keyVal.second);
}
return total;
}
} else {
return data.IntCast<ui64>();
}
}
TNode GetNode(const TNode& data, const TStringBuf& key)
{
if (auto resPtr = data.AsMap().FindPtr(key)) {
return *resPtr;
}
return TNode();
}
} // namespace
////////////////////////////////////////////////////////////////////
TJobCounter::TJobCounter(TNode data)
: Data_(std::move(data))
{
if (Data_.HasValue()) {
Total_ = CountTotal(Data_);
}
}
TJobCounter::TJobCounter(ui64 total)
: Total_(total)
{ }
ui64 TJobCounter::GetTotal() const
{
return Total_;
}
ui64 TJobCounter::GetValue(const TStringBuf key) const
{
if (Data_.HasValue()) {
return CountTotal(Data_[key]);
}
return 0;
}
////////////////////////////////////////////////////////////////////
TJobCounters::TJobCounters(const NYT::TNode& counters)
: Total_(0)
{
if (!counters.IsMap()) {
ythrow yexception() << "TJobCounters must be initialized with Map type TNode";
}
auto abortedNode = GetNode(counters, "aborted");
if (abortedNode.HasValue()) {
Aborted_ = TJobCounter(GetNode(abortedNode, "total"));
AbortedScheduled_ = TJobCounter(GetNode(abortedNode, "scheduled"));
AbortedNonScheduled_ = TJobCounter(GetNode(abortedNode, "non_scheduled"));
}
auto completedNode = GetNode(counters, "completed");
if (completedNode.HasValue()) {
Completed_ = TJobCounter(GetNode(completedNode, "total"));
CompletedNonInterrupted_ = TJobCounter(GetNode(completedNode, "non-interrupted"));
CompletedInterrupted_ = TJobCounter(GetNode(completedNode, "interrupted"));
}
Lost_ = TJobCounter(GetNode(counters, "lost"));
Invalidated_ = TJobCounter(GetNode(counters, "invalidated"));
Failed_ = TJobCounter(GetNode(counters, "failed"));
Running_ = TJobCounter(GetNode(counters, "running"));
Suspended_ = TJobCounter(GetNode(counters, "suspended"));
Pending_ = TJobCounter(GetNode(counters, "pending"));
Blocked_ = TJobCounter(GetNode(counters, "blocked"));
Total_ = CountTotal(counters);
}
const TJobCounter& TJobCounters::GetAborted() const
{
return Aborted_;
}
const TJobCounter& TJobCounters::GetAbortedScheduled() const
{
return AbortedScheduled_;
}
const TJobCounter& TJobCounters::GetAbortedNonScheduled() const
{
return AbortedNonScheduled_;
}
const TJobCounter& TJobCounters::GetCompleted() const
{
return Completed_;
}
const TJobCounter& TJobCounters::GetCompletedNonInterrupted() const
{
return CompletedNonInterrupted_;
}
const TJobCounter& TJobCounters::GetCompletedInterrupted() const
{
return CompletedInterrupted_;
}
const TJobCounter& TJobCounters::GetLost() const
{
return Lost_;
}
const TJobCounter& TJobCounters::GetInvalidated() const
{
return Invalidated_;
}
const TJobCounter& TJobCounters::GetFailed() const
{
return Failed_;
}
const TJobCounter& TJobCounters::GetRunning() const
{
return Running_;
}
const TJobCounter& TJobCounters::GetSuspended() const
{
return Suspended_;
}
const TJobCounter& TJobCounters::GetPending() const
{
return Pending_;
}
const TJobCounter& TJobCounters::GetBlocked() const
{
return Blocked_;
}
ui64 TJobCounters::GetTotal() const
{
return Total_;
}
////////////////////////////////////////////////////////////////////
} // namespace NYT
|