74 const string stat_cmd(
verbose ?
"STAT ALL" :
"STAT");
80 stat_info.
SetByKey(
"JobsByStatus", jobs_by_status);
86 while (
output.ReadLine(line)) {
87 if (line.empty() ||
isspace(line[0]))
91 size_t section_name_len = line.length();
92 while (--section_name_len > 0 &&
93 (line[section_name_len] ==
':' ||
94 line[section_name_len] ==
']' ||
95 isspace(line[section_name_len])))
98 line.resize(section_name_len);
102 else if (section_entries) {
111 if (
key ==
"Executable path" &&
113 if (!stat_info.
HasKey(
"Version"))
114 stat_info.
SetString(
"Version",
"Unknown");
116 if (!stat_info.
HasKey(
"Build date"))
117 stat_info.
SetString(
"Build date",
"Unknown");
130 const string& queue_name) :
152 return queue_info_node;
179 while (
output.ReadLine(line))
186 param_name, param_value,
195 const string& queue_name)
197 if (queue_name.empty()) {
233 if (!
key.queue.empty())
246 const string& attr_value)
293 if (
AddNode(parent, name, src)) {
304 :
node(parent.GetByKeyOrNull(name)),
337 static const string name =
"remote_app";
347 istringstream iss(data);
355 data.erase(0, iss.tellg());
363 if (files) node.
SetByKey(
"files", files);
399 file.SetString(
"filename",
i->first);
401 if (
i->second.empty()) {
402 file.SetString(
"storage",
"localfile");
404 file.SetString(
"storage",
"netcache");
405 file.SetString(
"netcache_key",
i->second);
441 static const string name =
"remote_cgi";
465 for (list<string>::iterator
i =
names.begin();
i !=
names.end(); ++
i) {
473 getline(stream, field);
476 if (field ==
"Status:") stream >> status;
491 exceptions(IOS_BASE::badbit | IOS_BASE::failbit);
496 template <
class TJobType>
501 typename TJobType::SRequest request(stream);
504 TJobType::Input(updater.
node, request);
514 template <
class TJobType>
518 const char*
value = data.empty() ?
"absent" :
"gone";
522 TJobType::Output(updater.
node, stream, data);
536 if (!SInputOutputProcessor::Input<SRemoteApp>(data,
m_JobInfo) &&
537 !SInputOutputProcessor::Input<SRemoteCgi>(data,
m_JobInfo))
547 SInputOutputProcessor::Output<SRemoteApp>(data,
m_JobInfo);
549 SInputOutputProcessor::Output<SRemoteCgi>(data,
m_JobInfo);
557 CJsonNode node(field_name !=
"ncbi_phid" ?
583 while (
output.ReadLine(line)) {
589 field_name, field_value,
602 attr_parser.
Reset(field_value);
609 &attr_name, &attr_value, &attr_column)) !=
611 if (next_attr_type ==
659 static void Indent(FILE* output_stream,
int indent_depth,
const char*
indent)
661 while (--indent_depth >= 0)
662 fprintf(output_stream,
"%s",
indent);
667 int struct_indent_depth = 0,
const char* struct_prefix =
"",
668 int scalar_indent_depth = 0,
const char* scalar_prefix =
"")
673 fputs(struct_prefix, output_stream);
675 putc(
'{', output_stream);
676 const char*
prefix =
"\n";
677 int indent_depth = struct_indent_depth + 1;
679 fputs(
prefix, output_stream);
681 fprintf(output_stream,
"\"%s\":",
684 indent_depth,
"\n", 0,
" ");
687 putc(
'\n', output_stream);
689 putc(
'}', output_stream);
694 fputs(struct_prefix, output_stream);
696 putc(
'[', output_stream);
697 const char*
prefix =
"\n";
698 int indent_depth = struct_indent_depth + 1;
700 fputs(
prefix, output_stream);
702 indent_depth,
"", indent_depth,
"");
705 putc(
'\n', output_stream);
707 putc(
']', output_stream);
711 fputs(scalar_prefix, output_stream);
713 fprintf(output_stream,
"\"%s\"",
717 fputs(scalar_prefix, output_stream);
719 fprintf(output_stream,
"%lld", (
long long) node.
AsInteger());
722 fputs(scalar_prefix, output_stream);
724 fprintf(output_stream,
"%.10g", node.
AsDouble());
727 fputs(scalar_prefix, output_stream);
729 fputs(node.
AsBoolean() ?
"true" :
"false", output_stream);
732 fputs(scalar_prefix, output_stream);
734 fputs(
"null", output_stream);
741 putc(
'\n', output_stream);
768 while (
output.ReadLine(line))
800 bool server_version_key)
810 string cmd(pullback_mode ?
"QPAUSE pullback=1" :
"QPAUSE");
819 string cmd(
"QRESUME");
827 bool pullback_mode,
unsigned timeout)
829 string cmd(
"SUSPEND");
848 result.SetInteger(
"key_version",
key.GetVersion());
850 if (
key.GetVersion() != 3) {
852 result.SetString(
"server_host", server_host);
853 result.SetInteger(
"server_port",
key.GetPort());
855 result.SetInteger(
"server_address_crc32",
key.GetHostPortCRC32());
860 CTime generation_time;
862 result.SetString(
"key_generation_time", generation_time.
AsString());
863 result.SetInteger(
"random",
key.GetRandomPart());
865 const string service(
key.GetServiceName());
867 if (!service.empty()) {
868 result.SetString(
"service_name", service);
870 result.SetNull(
"service_name");
929 m_NetStorageAdmin(netstorage_admin),
CJsonNode g_ServerInfoToJson(CNetService service, bool server_version_key)
static void Indent(FILE *output_stream, int indent_depth, const char *indent)
CJsonNode g_ExecAnyCmdToJson(CNetService service, const string &command, bool multiline)
CJsonNode g_ReconfAndReturnJson(CNetScheduleAPI ns_api)
CJsonNode g_LegacyStatToJson(CNetServer server, bool verbose)
CJsonNode g_QueueClassInfoToJson(CNetScheduleAPI ns_api)
void g_ResumeNetSchedule(CNetScheduleAPI netschedule_api)
CJsonNode s_GetBlobMeta(const CNetCacheKey &key)
void g_ProcessJobInfo(CNetScheduleAPI ns_api, const string &job_key, IJobInfoProcessor *processor, bool verbose, CCompoundIDPool::TInstance id_pool)
static void PrintJSONNode(FILE *output_stream, CJsonNode node, const char *indent, int struct_indent_depth=0, const char *struct_prefix="", int scalar_indent_depth=0, const char *scalar_prefix="")
void g_SuspendNetSchedule(CNetScheduleAPI netschedule_api, bool pullback_mode)
static const string s_JobType
void g_ResumeWorkerNode(CNetServer worker_node)
void g_PrintJSON(FILE *output_stream, CJsonNode node, const char *indent)
CJsonNode g_QueueInfoToJson(CNetScheduleAPI ns_api, const string &queue_name)
CJsonNode g_WhatIs(const string &id, CCompoundIDPool id_pool)
void g_SuspendWorkerNode(CNetServer worker_node, bool pullback_mode, unsigned timeout)
ENextAttributeType NextAttribute(CTempString *attr_name, string *attr_value, size_t *attr_column)
void Reset(const char *position, const char *eol)
static int x_GetTypeAndName(CNcbiIstream &istream, string &name)
Exception class for use by CCompoundIDPool, CCompoundID, and CCompoundIDField.
Pool of recycled CCompoundID objects.
virtual CJsonNode ExecOn(CNetServer server)
CExecAndParseStructuredOutput(const string &cmd)
CJsonNode m_UnparsableLines
virtual void ProcessInput(const string &data)
virtual void ProcessJobEventField(const CTempString &attr_name, const string &attr_value)
CJsonNode GetRootNode() const
virtual void BeginJobEvent(const CTempString &event_header)
virtual void ProcessOutput(const string &data)
virtual void ProcessJobInfoField(const CTempString &field_name, const CTempString &field_value)
virtual void ProcessJobMeta(const CNetScheduleKey &key)
virtual void ProcessRawLine(const string &line)
Iterator for JSON arrays and objects.
Int8 AsInteger() const
Provided that this is a numeric node (that is, either an integer or a floating point node),...
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.
static CJsonNode ParseJSON(const string &json, TParseFlags flags=0)
void DeleteByKey(const string &key)
Delete an element referred to by the specified key from a JSON object.
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.
void SetNull(const string &key)
Set a JSON object element to the specified null value.
void AppendString(const string &value)
For an array node, add a string node at the end of the array.
const string AsString() const
Provided that this is a string node, return the string value of this node.
string GetString(const string &key) const
For a JSON object node, return the string referred to by the specified key.
void SetBoolean(const string &key, bool value)
Set a JSON object element to the specified boolean value.
bool AsBoolean() const
Provided that this is a boolean node, return the boolean value of this node.
ENodeType GetNodeType() const
Return a ENodeType constant identifying the node type.
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.
double AsDouble() const
Provided that this is a numeric node (that is, either a floating point or an integer node),...
Client API for NCBI NetSchedule server.
void GetQueueInfo(CNetServer server, const string &queue_name, TQueueInfo &queue_info)
void DumpJob(CNcbiOstream &out, const string &job_key)
CNetServerInfo GetServerInfo()
Retrieve basic information about the server as attribute name-value pairs.
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...
void ExecOnAllServers(const string &cmd)
CJsonNode MkNetStorageRequest(const string &request_type)
CJsonNode ExchangeJson(const CJsonNode &request, CNetServer::TInstance server_to_use=NULL, CNetServerConnection *conn=NULL)
Exception class for use by CNetStorage, CNetStorageByKey, and CNetStorageObject.
void ToJSON(CJsonNode &root) const
Note about the "buf_size" parameter for streams in this API.
Reader-writer-based stream buffer.
Remote Application Request (both client side and application executor side)
bool IsExclusiveMode() const
const string & GetInBlobIdOrData() const
const string & GetCmdLine() const
Get the command line of the remote application.
bool x_Deserialize(CNcbiIstream &is, TStoredFiles *files=NULL)
unsigned int GetAppRunTimeout() const
Remote Application Result (both client side and application executor side)
String or Blob Storage Reader.
static EType x_GetDataType(string &data)
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
This class is for use by the grid_cli utility only.
virtual void ProcessJobMeta(const CNetScheduleKey &key)=0
virtual void ProcessRawLine(const string &line)=0
virtual void ProcessJobEventField(const CTempString &attr_name, const string &attr_value)=0
virtual void BeginJobEvent(const CTempString &event_header)=0
virtual void ProcessInput(const string &data)=0
virtual void ProcessOutput(const string &data)=0
virtual void ProcessJobInfoField(const CTempString &field_name, const CTempString &field_value)=0
CExecToJson(CNetStorageAdmin::TInstance, const string &)
virtual CJsonNode ExecOn(CNetServer) override
CNetStorageAdmin m_NetStorageAdmin
container_type::const_iterator const_iterator
const_iterator begin() const
const_iterator end() const
string g_NetService_TryResolveHost(const string &ip_or_hostname)
static const struct name_t names[]
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
const CNcbiEnvironment & GetEnvironment() const
const string & GetRequestMethodName(void) const
Get request method name.
@ fDoNotParseContent
do not automatically parse the request's content body (from "istr")
@ fIgnoreQueryString
do not parse $QUERY_STRING (or cmd.line if $REQUEST_METHOD not def)
static bool ParseBlobKey(const char *key_str, size_t key_len, CNetCacheKey *key_obj, CCompoundIDPool::TInstance id_pool=NULL)
Parse blob key string into a CNetCacheKey structure.
EJobStatus
Job status codes.
string output
Job result data.
bool ParseJobKey(const string &key_str, CCompoundIDPool::TInstance id_pool=NULL)
EJobStatus GetJobDetails(CNetScheduleJob &job, time_t *job_exptime=NULL, ENetScheduleQueuePauseMode *pause_mode=NULL)
Get job details.
static string StatusToString(EJobStatus status)
Printable status type.
unsigned version
Key version.
static EJobStatus StringToStatus(const CTempString &status_str)
Parse status string into enumerator value.
CNetScheduleAdmin GetAdmin()
string job_id
Output job key.
@ eDone
Job is ready (computed successfully)
@ eConfirmed
Final state - read confirmed.
@ eReading
Job has its output been reading.
@ eJobNotFound
No such job.
@ eReadFailed
Final state - read failed.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
static string PrintableString(const CTempString str, TPrintableMode mode=fNewLine_Quote|fNonAscii_Passthru)
Get a printable version of the specified string.
static CTempString TruncateSpaces_Unsafe(const CTempString str, ETrunc where=eTrunc_Both)
Truncate spaces in a string.
static Int8 StringToInt8(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to Int8.
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
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.
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 ParseQuoted(const CTempString str, size_t *n_read=NULL)
Discard C-style backslash escapes and extract a quoted string.
@ fSplit_MergeDelimiters
Merge adjacent delimiters.
@ eTrunc_Begin
Truncate leading spaces only.
string AsString(const CTimeFormat &format=kEmptyStr, TSeconds out_tz=eCurrentTimeZone) const
Transform time to string.
CTime & SetTimeT(const time_t t)
Set time using time_t time value.
#define TEMP_STRING_CTOR(str)
void RemoveStdReplyFields(CJsonNode &server_reply)
const struct ncbi::grid::netcache::search::fields::KEY key
string g_UnquoteIfQuoted(const CTempString &str)
bool g_FixMisplacedPID(CJsonNode &stat_info, CTempString &executable_path, const char *pid_key)
CJsonNode g_ExecToJson(IExecToJson &exec_to_json, CNetService service, CNetService::EIterationMode iteration_mode=CNetService::eSortByLoad)
This function is for use by the grid_cli utility only.
void g_AppendClientIPSessionIDHitID(string &cmd)
static const char * prefix[]
static SQLCHAR output[256]
Reader-writer based streams.
#define TOKEN_TYPE__NETCACHE_BLOB_KEY
#define TOKEN_TYPE__NETSTORAGEOBJECT_LOC
#define TOKEN_TYPE__NETSCHEDULE_JOB_KEY
CJsonNodeUpdater(const string &name, CJsonNode parent)
Meaningful information encoded in the NetCache key.
Meaningful information encoded in the NetSchedule key.
static bool AddNode(CJsonNode parent, const string &name, string data)
static CJsonNode x_CreateNode(EType type, const string &data)
static void AddNodes(CJsonNode parent, const string &name, const string &src)
virtual CJsonNode ExecOn(CNetServer server)
SExecAnyCmdToJson(const string &cmd, bool multiline)
SQueueInfoToJson(const string &cmd, const string §ion_prefix)
virtual CJsonNode ExecOn(CNetServer server)
SRequest(CNcbiIstream &is)
CJsonNode CreateFilesNode() const
static CJsonNode x_CreateArgsNode(const string &data, CJsonNode files)
static void Input(CJsonNode &node, SRequest &request)
static const string & Name()
static CJsonNode x_CreateDataNode(string data)
static bool x_GetFileName(string &data)
static void Output(CJsonNode &node, CRStream &stream, const string &)
SRequest(CRStream &stream)
static void Input(CJsonNode &node, SRequest &request)
static const string & Name()
static void Output(CJsonNode &node, CRStream &stream, const string &data)
virtual CJsonNode ExecOn(CNetServer server)
SServerInfoToJson(bool server_version_key)
CNetScheduleAdmin m_NetScheduleAdmin
virtual CJsonNode ExecOn(CNetServer server)
SSingleQueueInfoToJson(const CNetScheduleAdmin &ns_admin, const string &queue_name)