NCBI C++ ToolKit
netschedule_api_int.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef CONNECT_SERVICES_IMPL__NETSCHEDULE_API_INT__HPP
2 #define CONNECT_SERVICES_IMPL__NETSCHEDULE_API_INT__HPP
3 
4 /* $Id: netschedule_api_int.hpp 80734 2018-01-03 15:14:01Z sadyrovr $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Dmitry Kazimirov, Rafael Sadyrov
30  *
31  * File Description:
32  * Internal declarations for NetSchedule client API.
33  *
34  */
35 
36 #include <util/ncbi_url.hpp>
37 
38 #include <tuple>
39 
41 
42 
43 const unsigned int kNetScheduleMaxDBDataSize = 2048;
44 
45 const unsigned int kNetScheduleMaxDBErrSize = 4096;
46 
47 
49 
50 extern NCBI_XCONNECT_EXPORT const char* const kNetScheduleAPIDriverName;
51 
52 /// @deprecated, use SNetScheduleOutputParser instead
54 int g_ParseNSOutput(const string& attr_string, const char* const* attr_names,
55  string* attr_values, size_t attr_count);
56 
58 {
59  SNetScheduleOutputParser(const string& output);
60  const string& operator()(const string& param) const;
61 };
62 
66 
68 {
70  unsigned short port;
71  string message;
72 
74  bool operator()(string* server_host);
75 };
76 
78 {
79 public:
81 
82  bool ReceiveNotification(string* server_host = NULL);
83 
84  bool WaitForNotification(const CDeadline& deadline,
85  string* server_host = NULL);
86 
87  unsigned short GetPort() const { return m_Receiver.port; }
88 
89  const string& GetMessage() const { return m_Receiver.message; }
90 
91  void PrintPortNumber();
92 
93 // Submitter methods.
94 public:
95  void SubmitJob(CNetScheduleSubmitter::TInstance submitter,
96  CNetScheduleJob& job,
97  unsigned wait_time,
98  CNetServer* server = NULL);
99 
100  bool CheckJobStatusNotification(const string& job_id,
101  CNetScheduleAPI::EJobStatus* job_status,
102  int* last_event_index = NULL);
103 
104  // This method requires calling SubmitJob prior with wait_time set
105  CNetScheduleAPI::EJobStatus WaitForJobCompletion(CNetScheduleJob& job,
106  CDeadline& deadline, CNetScheduleAPI ns_api, time_t* job_exptime = NULL);
107 
110  using TJobInfo = tuple<CNetScheduleAPI::EJobStatus, TLastEventIndex, TProgressMessage>;
111 
112  TJobInfo RequestJobWatching(CNetScheduleAPI::TInstance ns_api,
113  const string& job_id,
114  const CDeadline& deadline);
115 
116  /// @deprecated, use tuple returning overload instead
118  bool RequestJobWatching(CNetScheduleAPI::TInstance ns_api,
119  const string& job_id,
120  const CDeadline& deadline,
121  CNetScheduleAPI::EJobStatus* job_status,
122  int* last_event_index);
123 
125  fJSM_Pending = 1 << CNetScheduleAPI::ePending,
126  fJSM_Running = 1 << CNetScheduleAPI::eRunning,
127  fJSM_Canceled = 1 << CNetScheduleAPI::eCanceled,
128  fJSM_Failed = 1 << CNetScheduleAPI::eFailed,
129  fJSM_Done = 1 << CNetScheduleAPI::eDone,
130  fJSM_Reading = 1 << CNetScheduleAPI::eReading,
131  fJSM_Confirmed = 1 << CNetScheduleAPI::eConfirmed,
132  fJSM_ReadFailed = 1 << CNetScheduleAPI::eReadFailed,
133  fJSM_Deleted = 1 << CNetScheduleAPI::eDeleted
134  };
135  typedef int TJobStatusMask;
136 
137  CNetScheduleAPI::EJobStatus WaitForJobEvent(
138  const string& job_key,
139  CDeadline& deadline,
140  CNetScheduleAPI ns_api,
141  TJobStatusMask status_mask,
142  int last_event_index = kMax_Int,
143  int *new_event_index = NULL);
144 
145 // Worker node methods.
146 public:
147  static string MkBaseGETCmd(
149  const string& affinity_list);
150  void CmdAppendTimeoutGroupAndClientInfo(string& cmd,
151  const CDeadline* deadline, const string& job_group);
152  bool RequestJob(CNetScheduleExecutor::TInstance executor,
153  CNetScheduleJob& job,
154  const string& cmd);
155  bool CheckRequestJobNotification(CNetScheduleExecutor::TInstance executor,
156  CNetServer* server);
157 
158 protected:
159  bool GetJobDetailsIfCompleted(CNetScheduleAPI ns_api, CNetScheduleJob& job,
160  time_t* job_exptime, CNetScheduleAPI::EJobStatus& job_status);
161 
163 };
164 
166 {
170  {
172  return *this;
173  }
174  void AddToClientNode(const string& data);
175  void UpdateAuthString();
176  void UseOldStyleAuth();
177  CCompoundIDPool GetCompoundIDPool();
178 
179  /// Extract one of the servers comprising this service
180  /// as a separate NetSchedule API object.
181  CNetScheduleAPI GetServer(CNetServer::TInstance server);
182 
183  // These allow empty values, too (unlike Set* counterparts)
184  void ReSetClientNode(const string&);
185  void ReSetClientSession(const string&);
186 
187  // Create workernode-compatible API
188  static TInstance CreateWnCompat(const string&, const string&);
189 
190  // Create API with no auto config loading (from server)
191  static TInstance CreateNoCfgLoad(const string&, const string&, const string&);
192 };
193 
194 struct SNetScheduleAdminImpl;
195 
197 {
198  NCBI_NET_COMPONENT(NetScheduleAdmin);
199 
200  /// Status map, shows number of jobs in each status
202 
203  /// Returns statuses for a given affinity token
204  /// @param status_map
205  /// Status map (status to job count)
206  /// @param affinity_token
207  /// Affinity token (optional)
208  /// @param job_group
209  /// Only jobs belonging to the specified group (optional)
210  void StatusSnapshot(TStatusMap& status_map,
211  const string& affinity_token = kEmptyStr,
212  const string& job_group = kEmptyStr);
213 
214  /// Create an instance of the given queue class.
215  /// @param qname
216  /// Name of the queue to create
217  /// @param qclass
218  /// Parameter set described in config file in a qclass_<qname> section.
219  /// @param description
220  /// Brief free text description of the queue.
221  void CreateQueue(
222  const string& qname,
223  const string& qclass,
224  const string& description = kEmptyStr);
225 
226  /// Delete queue
227  /// Applicable only to queues, created through CreateQueue method
228  /// @param qname
229  /// Name of the queue to delete.
230  void DeleteQueue(const string& qname);
231 
232 
233  /// Shutdown level
234  ///
236  eNoShutdown = 0, ///< No Shutdown was requested
237  eNormalShutdown, ///< Normal shutdown was requested
238  eShutdownImmediate, ///< Urgent shutdown was requested
239  eDie, ///< A serious error occurred, the server shuts down
240  eDrain ///< Wait for all server data to expire.
241  };
242 
243  /// Enable server drain mode.
244  ///
245  void SwitchToDrainMode(ESwitch on_off);
246 
247  /// Shutdown the server daemon.
248  ///
249  void ShutdownServer(EShutdownLevel level = eNormalShutdown);
250 
251  /// Cancel all jobs in the queue (optionally with particular statuses).
252  ///
253  /// @param job_statuses
254  /// Optional comma-separated list of job statuses
255  void CancelAllJobs(const string& job_statuses = kEmptyStr);
256 
257  void DumpJob(CNcbiOstream& out, const string& job_key);
258  CNetServerMultilineCmdOutput DumpJob(const string& job_key);
259 
260  void ReloadServerConfig();
261 
262  //////////////////////////////////////////////////////
263  /// Print version string
264  void PrintServerVersion(CNcbiOstream& output_stream);
265 
267  string name;
268  string prog;
269  string session;
270  string host;
271  unsigned short port;
273  };
274 
275  void GetWorkerNodes(list<SWorkerNodeInfo>& worker_nodes);
276 
277  void PrintConf(CNcbiOstream& output_stream);
278 
280  {
283  eStatisticsClients
284  };
285 
286  void PrintServerStatistics(CNcbiOstream& output_stream,
287  EStatisticsOptions opt = eStatisticsBrief);
288 
289  void PrintHealth(CNcbiOstream& output_stream);
290 
291  // Two versions of DumpQueue to keep the code compile compatible
292  void DumpQueue(CNcbiOstream& output_stream,
293  const string& start_after_job = kEmptyStr,
294  size_t job_count = 0,
295  const string& job_statuses = kEmptyStr,
296  const string& job_group = kEmptyStr);
297  void DumpQueue(CNcbiOstream& output_stream,
298  const string& start_after_job,
299  size_t job_count,
301  const string& job_group = kEmptyStr);
302 
304  // Get information on a particular queue of a particular server.
305  void GetQueueInfo(CNetServer server, const string& queue_name,
306  TQueueInfo& queue_info);
307  // The same as above, but for any random server in the service.
308  void GetQueueInfo(const string& queue_name, TQueueInfo& queue_info);
309  // Return information on the current queue.
310  void GetQueueInfo(CNetServer server, TQueueInfo& queue_info);
311  // The same as above, but for any random server in the service.
312  void GetQueueInfo(TQueueInfo& queue_info);
313  void PrintQueueInfo(const string& queue_name, CNcbiOstream& output_stream);
314 
317  list<string> queues;
318 
319  SServerQueueList(SNetServerImpl* server_impl) : server(server_impl) {}
320  };
321 
322  typedef list<SServerQueueList> TQueueList;
323 
324  void GetQueueList(TQueueList& result);
325 };
326 
333 };
334 // Return a JSON object where each key is a worker node
335 // session and the value is a JSON object containing
336 // status information reported by the worker node itself.
340 string g_UnquoteIfQuoted(const CTempString& str);
346 bool g_FixMisplacedPID(CJsonNode& stat_info, CTempString& executable_path, const char* pid_key);
348 CJsonNode g_ServerInfoToJson(CNetServerInfo server_info, bool server_version_key);
351 
353 
354 
355 #endif
Pool of recycled CCompoundID objects.
CDatagramSocket::
CDeadline.
Definition: ncbitime.hpp:1830
JSON node abstraction.
Client API for NCBI NetSchedule server.
map< string, unsigned > TStatusMap
Status map, shows number of jobs in each status.
NCBI_NET_COMPONENT(NetScheduleAdmin)
EShutdownLevel
Shutdown level.
@ eNormalShutdown
Normal shutdown was requested.
@ eDie
A serious error occurred, the server shuts down.
@ eShutdownImmediate
Urgent shutdown was requested.
list< SServerQueueList > TQueueList
map< string, string > TQueueInfo
tuple< CNetScheduleAPI::EJobStatus, TLastEventIndex, TProgressMessage > TJobInfo
SNetScheduleNotificationReceiver m_Receiver
CPluginManager<> –.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
CTime –.
Definition: ncbitime.hpp:296
CUrlArgs::
Definition: ncbi_url.hpp:240
std::ofstream out("events_result.xml")
main entry point for tests
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static SQLCHAR output[256]
Definition: print.c:5
static const char * str(char *buf, int n)
Definition: stats.c:84
char data[12]
Definition: iconv.c:80
@ eDrain
Definition: grid_cli.hpp:245
string
Definition: cgiapp.hpp:687
#define NULL
Definition: ncbistd.hpp:225
EJobStatus
Job status codes.
EJobAffinityPreference
Affinity matching modes.
CNetScheduleAPI & operator=(SNetScheduleAPIImpl *impl)
@ eDeleted
The job has been wiped out of the database.
@ eDone
Job is ready (computed successfully)
@ eConfirmed
Final state - read confirmed.
@ eReading
Job has its output been reading.
@ eCanceled
Explicitly canceled.
@ eRunning
Running on a worker node.
@ ePending
Waiting for execution.
@ eReadFailed
Final state - read failed.
@ eFailed
Failed to run (execution timeout)
#define NCBI_DEPRECATED
#define kMax_Int
Definition: ncbi_limits.h:184
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define kEmptyStr
Definition: ncbistr.hpp:123
enum ENcbiSwitch ESwitch
Aux.
#define NCBI_XCONNECT_EXPORT
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
NCBI_XCONNECT_EXPORT int g_ParseNSOutput(const string &attr_string, const char *const *attr_names, string *attr_values, size_t attr_count)
string g_GetNetScheduleStatCommand(ENetScheduleStatTopic topic)
string g_UnquoteIfQuoted(const CTempString &str)
CJsonNode g_ServerInfoToJson(CNetServerInfo server_info, bool server_version_key)
ENetScheduleStatTopic
@ eNetScheduleStatClients
@ eNetScheduleStatNotifications
@ eNetScheduleStatJobGroups
@ eNetScheduleStatAffinities
@ eNumberOfNetStheduleStatTopics
bool g_FixMisplacedPID(CJsonNode &stat_info, CTempString &executable_path, const char *pid_key)
const unsigned int kNetScheduleMaxDBDataSize
CJsonNode g_GetWorkerNodeInfo(CNetScheduleAPI api)
CJsonNode g_GenericStatToJson(CNetServer server, ENetScheduleStatTopic topic, bool verbose)
CJsonNode g_WorkerNodeInfoToJson(CNetServer worker_node)
void NCBI_EntryPoint_xnetscheduleapi(CPluginManager< SNetScheduleAPIImpl >::TDriverInfoList &info_list, CPluginManager< SNetScheduleAPIImpl >::EEntryPointRequest method)
const unsigned int kNetScheduleMaxDBErrSize
const char *const kNetScheduleAPIDriverName
NCBI_DECLARE_INTERFACE_VERSION(SNetScheduleAPIImpl, "xnetschedule_api", 1, 0, 0)
true_type verbose
Definition: processing.cpp:890
CNetScheduleAPIExt(TInstance api)
CNetScheduleAPIExt & operator=(TInstance api)
SServerQueueList(SNetServerImpl *server_impl)
Job description.
bool operator()(string *server_host)
else result
Definition: token2.c:20
Modified on Wed Jun 19 17:05:35 2024 by modify_doxy.py rev. 669887