59 client_info_iter; ++client_info_iter) {
60 CJsonNode client_info = *client_info_iter;
62 "worker node") ==
NPOS)
65 string session = client_info.
GetString(
"session");
67 if (unique_sessions.
insert(session).second) {
76 wn_info.
port = (
unsigned short)
77 client_info.
GetInteger(
"worker_node_control_port");
79 client_info.
GetString(
"last_access"),
"M/D/Y h:m:s.r");
89 list<SWorkerNodeInfo> worker_nodes;
92 ITERATE(list<CNetScheduleAdmin::SWorkerNodeInfo>, wn_info, worker_nodes) {
93 string wn_address = wn_info->host +
':' +
117 {
"STAT GROUPS",
"GROUP: ",
"group"},
119 {
"STAT CLIENTS",
"CLIENT: ",
"client_node"},
121 {
"STAT NOTIFICATIONS",
"CLIENT: ",
"client_node"},
123 {
"STAT AFFINITIES",
"AFFINITY: ",
"affinity_token"}
148 char* begin =
const_cast<char*
>(
key.data());
149 char* end = begin +
key.length();
151 while (begin < end && !
isalnum(*begin))
154 while (begin < end && !
isalnum(end[-1]))
162 key.assign(begin, end - begin);
164 for (; begin < end; ++begin)
177 if (misplaced_pid ==
NPOS)
180 SIZE_TYPE pos = misplaced_pid +
sizeof(
"; PID: ") - 1;
183 executable_path.
length() - pos)));
184 executable_path.
erase(misplaced_pid);
199 stat_cmd.append(
" VERBOSE");
211 while (
output.ReadLine(line)) {
214 entities.
Append(entity_info);
218 line.length() -
prefix.length())));
229 string key_norm(
key);
232 entity_info.
SetByKey(key_norm, array_value =
237 entity_info.
SetByKey(key_norm, node);
243 entities.
Append(entity_info);
251 bool server_version_key)
255 string attr_name, attr_value;
260 switch (old_format) {
262 if (attr_name ==
"Build")
263 attr_name =
"build_date";
272 attr_name = server_version_key ?
"server_version" :
"version";
279 if (server_version_key && attr_name ==
"version")
280 attr_name =
"server_version";
283 server_info_node.
SetString(attr_name, attr_value);
286 return server_info_node;
293 key.erase(0,
key.length());
295 key.reserve(line_len);
302 else if (c ==
' ' || c ==
'_' || c ==
'-')
304 else if (c !=
':' ||
key.empty())
307 if (++
i < line_len && line[
i] ==
' ')
309 value.assign(line,
i, line_len -
i);
319 list<CTempString> words;
322 ITERATE(list<CTempString>, it, words) {
345 int running_job_count = 0;
346 int free_worker_threads = 1;
347 bool suspended =
false;
348 bool shutting_down =
false;
349 bool exclusive_job =
false;
350 bool working =
false;
352 while (
output.ReadLine(line)) {
353 if (line.empty() ||
isspace(line[0]))
356 if (running_job_count > 0) {
362 pos +=
sizeof(
"running for ") - 1;
364 CTempString(line.data() + pos, line.length() - pos),
372 running_job.
SetString(
"key", line.substr(0, pos));
374 running_jobs.
Append(running_job);
379 line.length() - (
sizeof(
"Jobs ") - 1)),
key,
value)) {
381 if (
key ==
"running") {
386 working = running_job_count > 0;
387 free_worker_threads -= running_job_count;
393 if (
key ==
"host_name")
395 else if (
key ==
"node_started_at")
397 else if (
key ==
"executable_path")
399 else if (
key ==
"maximum_job_threads") {
404 free_worker_threads += maximum_job_threads - 1;
407 }
else if (
key ==
"netschedule_servers") {
413 }
else if (
key ==
"preferred_affinities") {
418 }
else if (wn_info.
GetSize() == 0)
423 shutting_down =
true;
425 exclusive_job =
true;
428 if (!wn_info.
HasKey(
"maximum_job_threads"))
430 if (!wn_info.
HasKey(
"version"))
432 if (!wn_info.
HasKey(
"build_date"))
436 shutting_down ?
"shutting_down" :
437 suspended ?
"suspended" :
438 exclusive_job ?
"processing_exclusive_job" :
439 free_worker_threads == 0 ?
"busy" :
440 working ?
"working" :
"ready");
442 wn_info.
SetByKey(
"job_counters", job_counters);
443 wn_info.
SetByKey(
"running_jobs", running_jobs);
Iterator for JSON arrays and objects.
size_t GetSize() const
For a container node (that is, either an array or an object), return the number of elements in the co...
static CJsonNode NewArrayNode()
Create a new JSON array node.
static CJsonNode GuessType(const CTempString &value)
Guess the type of a JSON scalar from the string representation of its value and initialize a new node...
bool HasKey(const string &key) const
Check if an object node has an element accessible by the specified key.
SJsonIteratorImpl * Iterate(EIterationMode mode=eNatural) const
For a container node (that is, either an array or an object), begin iteration over its elements.
void SetString(const string &key, const string &value)
Set a JSON object element to the specified string value.
Int8 GetInteger(const string &key) const
For a JSON object node, return the integer referred to by the specified key.
void AppendString(const string &value)
For an array node, add a string node at the end of the array.
string GetString(const string &key) const
For a JSON object node, return the string referred to by the specified key.
void SetInteger(const string &key, Int8 value)
Set a JSON object element to the specified integer value.
void SetByKey(const string &key, CJsonNode::TInstance value)
For a JSON object node, insert a new element or update an existing element.
static CJsonNode NewStringNode(const string &value)
Create a new JSON string node.
static CJsonNode NewObjectNode()
Create a new JSON object node.
void Append(CJsonNode::TInstance value)
For an array node, add a new element at the end of the array.
Client API for NCBI NetSchedule server.
bool GetNextAttribute(string &attr_name, string &attr_value)
Return the next attribute.
SExecResult ExecWithRetry(const string &cmd, bool multiline_output=false)
Execute remote command 'cmd', wait for the reply, check if it starts with 'OK:', and return the remai...
CNetServiceIterator Iterate(EIterationMode mode=eSortByLoad)
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
iterator_bool insert(const value_type &val)
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
int64_t Int8
8-byte (64-bit) signed integer
uint64_t Uint8
8-byte (64-bit) unsigned integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
NCBI_NS_STD::string::size_type SIZE_TYPE
static CTempString TruncateSpaces_Unsafe(const CTempString str, ETrunc where=eTrunc_Both)
Truncate spaces in a string.
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
static Int8 StringToInt8(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to Int8.
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
static bool EndsWith(const CTempString str, const CTempString end, ECase use_case=eCase)
Check if a string ends with a specified suffix value.
static SIZE_TYPE Find(const CTempString str, const CTempString pattern, ECase use_case=eCase, EDirection direction=eForwardSearch, SIZE_TYPE occurrence=0)
Find the pattern in the string.
const char * data(void) const
Return a pointer to the array represented.
void erase(size_type pos=0)
Truncate the string at some specified position Note: basic_string<> supports additional erase() optio...
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
static Uint8 StringToUInt8(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to Uint8.
static bool SplitInTwo(const CTempString str, const CTempString delim, string &str1, string &str2, TSplitFlags flags=0)
Split a string into two pieces using the specified delimiters.
size_type length(void) const
Return the length of the represented array.
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
static string & ReplaceInPlace(string &src, const string &search, const string &replace, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
static string TruncateSpaces(const string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string.
static string & ToLower(string &str)
Convert string to lower case – string& version.
static string ParseQuoted(const CTempString str, size_t *n_read=NULL)
Discard C-style backslash escapes and extract a quoted string.
@ fConvErr_NoThrow
Do not throw an exception on error.
@ fAllowTrailingSymbols
Ignore trailing non-numerics characters.
@ fAllowLeadingSpaces
Ignore leading spaces in converted string.
@ fSplit_MergeDelimiters
Merge adjacent delimiters.
@ eReverseSearch
Search in a backward direction.
@ eTrunc_Begin
Truncate leading spaces only.
@ eNocase
Case insensitive compare.
enum ENcbiSwitch ESwitch
Aux.
#define TEMP_STRING_CTOR(str)
const struct ncbi::grid::netcache::search::fields::KEY key
NetSchedule client specs.
@ eNetScheduleStatClients
@ eNumberOfNetStheduleStatTopics
string g_GetNetScheduleStatCommand(ENetScheduleStatTopic topic)
static bool s_ExtractKey(const CTempString &line, string &key, CTempString &value)
string g_UnquoteIfQuoted(const CTempString &str)
CNetScheduleAdmin::SWorkerNodeInfo SWorkerNodeInfo
CJsonNode g_ServerInfoToJson(CNetServerInfo server_info, bool server_version_key)
static CJsonNode s_WordsToJsonArray(const CTempString &str)
bool g_FixMisplacedPID(CJsonNode &stat_info, CTempString &executable_path, const char *pid_key)
CJsonNode g_GetWorkerNodeInfo(CNetScheduleAPI api)
const char * record_prefix
CJsonNode g_GenericStatToJson(CNetServer server, ENetScheduleStatTopic topic, bool verbose)
CJsonNode g_WorkerNodeInfoToJson(CNetServer worker_node)
void g_GetWorkerNodes(CNetScheduleAPI api, list< SWorkerNodeInfo > &worker_nodes)
struct @970 s_StatTopics[eNumberOfNetStheduleStatTopics]
static void NormalizeStatKeyName(CTempString &key)
void g_AppendClientIPSessionIDHitID(string &cmd)
static const char * prefix[]
static SQLCHAR output[256]
CNetServerInfo g_ServerInfoFromString(const string &server_info)
static const char * str(char *buf, int n)
const string & GetClientName() const