NCBI C++ ToolKit
grid_cli.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: grid_cli.cpp 97020 2022-06-08 15:27:50Z sadyrovr $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Dmitry Kazimirov
27  *
28  * File Description: Entry point and command line parsing
29  * of the grid_cli application.
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
34 
35 #include "grid_cli.hpp"
36 
41 
42 #ifdef WIN32
43 #include <io.h>
44 #include <fcntl.h>
45 #endif
46 
47 /* This header must go last */
48 #include <common/test_assert.h>
49 
51 
52 #define ANY_JOB_STATUS "Any"
53 
55  int argc, const char* argv[]) :
56  m_ArgC(argc),
57  m_ArgV(argv),
58  m_AdminMode(false),
59  m_NetICacheClient(eVoid),
60  m_NetStorage(eVoid),
61  m_NetStorageByKey(eVoid)
62 {
64 }
65 
66 #ifdef _DEBUG
67 #define OPT_DEF(opt_type, opt_id) CCommandLineParser::opt_type, opt_id
68 #else
69 #define OPT_DEF(opt_type, opt_id) CCommandLineParser::opt_type
70 #endif
71 
74 #ifdef _DEBUG
75  int opt_id;
76 #endif
77  const char* name_variants;
78  const char* description;
80 } static const s_OptionDefinitions[eNumberOfOptions] = {
81 
82  {OPT_DEF(ePositionalArgument, eUntypedArg), "ARG", NULL, {-1}},
83 
84  {OPT_DEF(eOptionalPositional, eOptionalID), "ID", NULL, {-1}},
85 
86  {OPT_DEF(ePositionalArgument, eID), "ID", NULL, {-1}},
87 
88  {OPT_DEF(ePositionalArgument, eAppUID), "APP_UID", NULL, {-1}},
89 
90  {OPT_DEF(ePositionalArgument, eAttrName), "ATTR_NAME", NULL, {-1}},
91 
92  {OPT_DEF(eOptionalPositional, eAttrValue), ATTR_VALUE_ARG, NULL, {-1}},
93 
94 #ifdef NCBI_GRID_XSITE_CONN_SUPPORT
95  {OPT_DEF(eSwitch, eAllowXSiteConn),
96  "allow-xsite-conn", "Allow cross-site connections.", {-1}},
97 #endif
98 
99  {OPT_DEF(eSwitch, eNoConnRetries),
100  "no-conn-retries", "Do not attempt to reconnect to "
101  "services after the first connection failure.", {-1}},
102 
103  {OPT_DEF(eOptionWithParameter, eLoginToken),
104  LOGIN_TOKEN_OPTION, "Login token (see the '"
105  LOGIN_COMMAND "' command).", {-1}},
106 
107  {OPT_DEF(eOptionWithParameter, eAuth),
108  "auth", "Authentication string (\"client_name\").", {-1}},
109 
110  {OPT_DEF(eOptionWithParameter, eInput),
111  INPUT_OPTION, "Provide input data on the command line. "
112  "The standard input stream will not be read.", {-1}},
113 
114  {OPT_DEF(eOptionWithParameter, eInputFile),
115  INPUT_FILE_OPTION, "Read input from the specified file.", {-1}},
116 
117  {OPT_DEF(eOptionWithParameter, eRemoteAppArgs),
118  REMOTE_APP_ARGS_OPTION, "Submit a remote_app job and "
119  "specify its arguments.", {-1}},
120 
121  {OPT_DEF(eSwitch, eRemoteAppStdIn),
122  "remote-app-stdin", "Treat the job as a 'remote_app' job "
123  "and extract the standard input stream of the "
124  "remote application.", {-1}},
125 
126  {OPT_DEF(eSwitch, eRemoteAppStdOut),
127  "remote-app-stdout", "Treat the job as a 'remote_app' job "
128  "and extract the standard output stream of the "
129  "remote application.", {-1}},
130 
131  {OPT_DEF(eSwitch, eRemoteAppStdErr),
132  "remote-app-stderr", "Extract the standard error stream of the "
133  "remote application.", {-1}},
134 
135  {OPT_DEF(eOptionWithParameter, eOutputFile),
136  "o|" OUTPUT_FILE_OPTION, "Save output to the specified file.", {-1}},
137 
138  {OPT_DEF(eOptionWithParameter, eOutputFormat),
139  "of|output-format",
140  "One of the output formats supported by this command.", {-1}},
141 
142  {OPT_DEF(eOptionWithParameter, eNetCache),
143  "nc|" NETCACHE_OPTION, "NetCache service name "
144  "or server address.", {-1}},
145 
146  {OPT_DEF(eOptionWithParameter, eCache),
147  CACHE_OPTION, "Enable ICache mode and specify "
148  "cache name to use.", {-1}},
149 
150  {OPT_DEF(ePositionalArgument, eCacheArg), "CACHE", NULL, {-1}},
151 
152  {OPT_DEF(eOptionWithParameter, ePassword),
153  PASSWORD_OPTION, "Enable NetCache password protection.", {-1}},
154 
155  {OPT_DEF(eOptionWithParameter, eOffset),
156  OFFSET_OPTION, "Byte offset of the portion of data.", {-1}},
157 
158  {OPT_DEF(eOptionWithParameter, eSize),
159  "size|" SIZE_OPTION, "Length (in bytes) of the portion of data.", {-1}},
160 
161  {OPT_DEF(eOptionWithParameter, eTTL),
162  "ttl", "Override the default time-to-live value (in seconds).", {-1}},
163 
164  {OPT_DEF(eSwitch, eEnableMirroring),
165  "enable-mirroring", "Enable NetCache mirroring functionality.", {-1}},
166 
167  {OPT_DEF(eSwitch, eTryAllServers),
168  TRY_ALL_SERVERS_OPTION, "Try all servers in the service "
169  "to find the blob.", {-1}},
170 
171  {OPT_DEF(eSwitch, eUseCompoundID),
172  "use-compound-id", "Return key in CompoundID format.", {-1}},
173 
174  {OPT_DEF(eOptionWithParameter, eNetStorage),
175  "nst|" NETSTORAGE_OPTION, "NetStorage service name "
176  "or server address.", {-1}},
177 
178  {OPT_DEF(eSwitch, eObjectKey),
179  OBJECT_KEY_OPTION, "Enable object keys mode. "
180  "Cannot be used together with '--" NAMESPACE_OPTION "'.", {-1}},
181 
182  {OPT_DEF(eSwitch, eUserKey),
183  USER_KEY_OPTION, "Enable user-defined keys mode. "
184  "Requires '--" NAMESPACE_OPTION "'.", {-1}},
185 
186  {OPT_DEF(eOptionWithParameter, eNamespace),
187  NAMESPACE_OPTION, "Domain-specific name that isolates objects "
188  "created with a user-defined key from objects created "
189  "by other users.", {-1}},
190 
191  {OPT_DEF(eSwitch, ePersistent),
192  PERSISTENT_OPTION, "Use a persistent storage like FileTrack.", {-1}},
193 
194  {OPT_DEF(eSwitch, eFastStorage),
195  FAST_STORAGE_OPTION, "Use a fast storage like NetCache.", {-1}},
196 
197  {OPT_DEF(eSwitch, eMovable),
198  MOVABLE_OPTION, "Allow the object to move between storages.", {-1}},
199 
200  {OPT_DEF(eSwitch, eCacheable),
201  CACHEABLE_OPTION, "Use NetCache for data caching.", {-1}},
202 
203  {OPT_DEF(eSwitch, eNoMetaData),
204  "no-meta-data", "Do not use relational database for "
205  "ownership, change tracking, and object attributes.", {-1}},
206 
207  {OPT_DEF(eOptionWithParameter, eNetSchedule),
208  "ns|" NETSCHEDULE_OPTION, "NetSchedule service name "
209  "or server address.", {-1}},
210 
211  {OPT_DEF(eOptionWithParameter, eQueue),
212  QUEUE_OPTION, "NetSchedule queue.", {-1}},
213 
214  {OPT_DEF(eOptionWithParameter, eWorkerNode),
215  "wn|" WORKER_NODE_OPTION, "Worker node address "
216  "(a host:port pair).", {-1}},
217 
218  {OPT_DEF(eOptionWithParameter, eBatch),
219  BATCH_OPTION, "Enable batch mode and specify batch size.", {-1}},
220 
221  {OPT_DEF(eOptionWithParameter, eAffinity),
222  AFFINITY_OPTION, "Affinity token.", {-1}},
223 
224  {OPT_DEF(eOptionWithParameter, eAffinityList),
225  "affinity-list", "Comma-separated list of affinity tokens.", {-1}},
226 
227  {OPT_DEF(eSwitch, eUsePreferredAffinities),
228  "use-preferred-affinities", "Accept a job with any of "
229  "the affinities registered earlier as preferred.", {-1}},
230 
231  {OPT_DEF(eSwitch, eClaimNewAffinities),
232  CLAIM_NEW_AFFINITIES_OPTION, "Accept a job with a preferred "
233  "affinity, without an affinity, or with an affinity "
234  "that is not preferred by any worker (in which case "
235  "it is added to the preferred affinities).", {-1}},
236 
237  {OPT_DEF(eSwitch, eAnyAffinity),
238  ANY_AFFINITY_OPTION, "Accept job with any available affinity.", {-1}},
239 
240  {OPT_DEF(eSwitch, eExclusiveJob),
241  "exclusive-job", "Create an exclusive job.", {-1}},
242 
243  {OPT_DEF(eOptionWithParameter, eJobOutput),
244  JOB_OUTPUT_OPTION, "Provide job output on the command line "
245  "(inhibits reading from the standard input stream or an "
246  "input file).", {-1}},
247 
248  {OPT_DEF(eOptionWithParameter, eJobOutputBlob),
249  JOB_OUTPUT_BLOB_OPTION, "Specify a NetCache blob "
250  "to use as the job output.", {-1}},
251 
252  {OPT_DEF(eOptionWithParameter, eReturnCode),
253  "return-code", "Job return code.", {-1}},
254 
255  {OPT_DEF(eOptionWithParameter, eLimit),
256  LIMIT_OPTION, "Maximum number of records to return.", {-1}},
257 
258  {OPT_DEF(ePositionalArgument, eAuthToken),
259  "AUTH_TOKEN", "Security token that grants the "
260  "caller permission to manipulate the job.", {-1}},
261 
262  {OPT_DEF(eSwitch, eReliableRead),
263  RELIABLE_READ_OPTION, "Enable reading confirmation mode.", {-1}},
264 
265  {OPT_DEF(eOptionWithParameter, eConfirmRead),
266  CONFIRM_READ_OPTION, "For the reading reservation specified as "
267  "the argument to this option, mark the job identified by "
268  "'--" JOB_ID_OPTION "' as successfully retrieved.", {-1}},
269 
270  {OPT_DEF(eOptionWithParameter, eRollbackRead),
271  ROLLBACK_READ_OPTION, "Release the specified reading "
272  "reservation of the specified job.", {-1}},
273 
274  {OPT_DEF(eOptionWithParameter, eFailRead),
275  FAIL_READ_OPTION, "Use the specified reading reservation "
276  "to mark the job as impossible to read.", {-1}},
277 
278  {OPT_DEF(eOptionWithParameter, eErrorMessage),
279  "error-message", "Provide an optional error message.", {-1}},
280 
281  {OPT_DEF(eOptionWithParameter, eJobId),
282  JOB_ID_OPTION, "Job ID to operate on.", {-1}},
283 
284  {OPT_DEF(eSwitch, eJobGroupInfo),
285  "job-group-info", "Print information on job groups.", {eQueue, -1}},
286 
287  {OPT_DEF(eSwitch, eClientInfo),
288  "client-info", "Print information on the recently "
289  "connected clients.", {eQueue, -1}},
290 
291  {OPT_DEF(eSwitch, eNotificationInfo),
292  "notification-info", "Print a snapshot of the "
293  "currently subscribed notification listeners.", {eQueue, -1}},
294 
295  {OPT_DEF(eSwitch, eAffinityInfo),
296  "affinity-info", "Print information on the "
297  "currently handled affinities.", {eQueue, -1}},
298 
299  {OPT_DEF(eSwitch, eActiveJobCount),
300  "active-job-count", "Only print the total number of "
301  "Pending and Running jobs in all queues combined.", {-1}},
302 
303  {OPT_DEF(eSwitch, eJobsByStatus),
304  "jobs-by-status", "Print the number of jobs itemized by their "
305  "current status. If the '--" AFFINITY_OPTION "' option "
306  "is given, only the jobs with the specified affinity "
307  "will be counted.", {-1}},
308 
309  {OPT_DEF(eOptionWithParameter, eStartAfterJob),
310  "start-after-job", "Specify the key of the last job "
311  "in the previous dump batch.", {-1}},
312 
313  {OPT_DEF(eOptionWithParameter, eJobCount),
314  "job-count", "Specify the maximum number of jobs in the output.", {-1}},
315 
316  {OPT_DEF(eOptionWithParameter, eJobStatus),
317  "job-status", "Select jobs by job status.", {-1}},
318 
319  {OPT_DEF(eSwitch, eVerbose),
320  "verbose", "Produce more verbose output.", {-1}},
321 
322  {OPT_DEF(eSwitch, eBrief),
323  BRIEF_OPTION, "Produce less verbose output.", {-1}},
324 
325  {OPT_DEF(eSwitch, eStatusOnly),
326  "status-only", "Print job status only.", {-1}},
327 
328  {OPT_DEF(eSwitch, eProgressMessageOnly),
329  "progress-message-only", "Print only the progress message.", {-1}},
330 
331  {OPT_DEF(eSwitch, eDeferExpiration),
332  "defer-expiration", "Prolong job lifetime by "
333  "updating its last access timestamp.", {-1}},
334 
335  {OPT_DEF(eOptionWithParameter, eWaitForJobStatus),
336  WAIT_FOR_JOB_STATUS_OPTION, "Wait until the job status "
337  "changes to the given value. The option can be given "
338  "more than once to wait for any one of multiple values. "
339  "Use the keyword 'Any' to wait for any status change.", {-1}},
340 
341  {OPT_DEF(eOptionWithParameter, eWaitForJobEventAfter),
342  WAIT_FOR_JOB_EVENT_AFTER_OPTION, "Wait for a job event with "
343  "the index greater than ARG.", {-1}},
344 
345  {OPT_DEF(eOptionWithParameter, eExtendLifetime),
346  "extend-lifetime", "Extend job lifetime by "
347  "the specified number of seconds.", {-1}},
348 
349  {OPT_DEF(eOptionWithParameter, eProgressMessage),
350  "progress-message", "Set job progress message.", {-1}},
351 
352  {OPT_DEF(eOptionWithParameter, eJobGroup),
353  "group|" JOB_GROUP_OPTION, "Job group.", {-1}},
354 
355  {OPT_DEF(eSwitch, eAllJobs),
356  "all-jobs", "Apply to all jobs in the queue.", {-1}},
357 
358  {OPT_DEF(eOptionWithParameter, eWaitTimeout),
359  TIMEOUT_OPTION "|" WAIT_TIMEOUT_OPTION, "Timeout in seconds.", {-1}},
360 
361  {OPT_DEF(eOptionWithParameter, eFailJob),
362  FAIL_JOB_OPTION, "Report the job as failed "
363  "and specify an error message.", {-1}},
364 
365  {OPT_DEF(eOptionalPositional, eQueueArg), QUEUE_ARG, NULL, {-1}},
366 
367  {OPT_DEF(eSwitch, eAllQueues),
368  ALL_QUEUES_OPTION, "Print information on all queues.", {-1}},
369 
370  {OPT_DEF(eSwitch, eQueueClasses),
371  QUEUE_CLASSES_OPTION, "Print information on queue classes.", {-1}},
372 
373  {OPT_DEF(ePositionalArgument, eTargetQueueArg), QUEUE_ARG, NULL, {-1}},
374 
375  {OPT_DEF(ePositionalArgument, eQueueClassArg), "QUEUE_CLASS", NULL, {-1}},
376 
377  {OPT_DEF(eOptionWithParameter, eQueueClass),
378  QUEUE_CLASS_OPTION, "NetSchedule queue class.", {-1}},
379 
380  {OPT_DEF(eOptionWithParameter, eQueueDescription),
381  "queue-description", "Optional queue description.", {-1}},
382 
383  {OPT_DEF(eOptionalPositional, eSwitchArg), SWITCH_ARG, NULL, {-1}},
384 
385  {OPT_DEF(eSwitch, ePullback),
386  PULLBACK_OPTION, "Pause job queue with pullback.", {-1}},
387 
388  {OPT_DEF(eSwitch, eWaitForJobCompletion),
389  WAIT_FOR_JOB_COMPLETION_OPTION, "Do not return until all "
390  "running jobs are completed.", {-1}},
391 
392  {OPT_DEF(eSwitch, eNow),
393  NOW_OPTION, "Take action immediately.", {-1}},
394 
395  {OPT_DEF(eSwitch, eDie),
396  DIE_OPTION, "Terminate the server process abruptly.", {-1}},
397 
398  {OPT_DEF(eSwitch, eDrain),
399  DRAIN_OPTION, "Tell the server to wait until all of its "
400  "data is expired prior to shutting down.", {-1}},
401 
402  {OPT_DEF(eSwitch, eCompatMode),
403  "compat-mode", "Enable backward compatibility tweaks.", {-1}},
404 
405  {OPT_DEF(eOptionWithParameter, eJobInputDir),
406  JOB_INPUT_DIR_OPTION, "Job input directory.", {-1}},
407 
408  {OPT_DEF(eOptionWithParameter, eJobOutputDir),
409  JOB_OUTPUT_DIR_OPTION, "Job output directory.", {-1}},
410 
411  {OPT_DEF(eSwitch, eDumpCGIEnv),
412  "dump-cgi-env", "For remote_cgi jobs, print the CGI environment "
413  "variables saved by cgi2rcgi as a part of job input.", {-1}},
414 
415  {OPT_DEF(eSwitch, eDumpCGIStdIn),
416  "dump-cgi-stdin", "For remote_cgi jobs, dump the standard "
417  "input saved by cgi2rcgi as a part of job input.", {-1}},
418 
419  {OPT_DEF(eOptionWithParameter, eAggregationInterval),
420  "aggregation-interval", "NetCache: specify the statistics "
421  "aggregation interval to return ('1min', '5min', '1h', "
422  "'life', and so on). Default: 'life'.", {-1}},
423 
424  {OPT_DEF(eSwitch, ePreviousInterval),
425  "previous-interval", "NetCache: return statistics for the "
426  "previous (complete) aggregation interval (instead of "
427  "returning the current but incomplete statistics).", {-1}},
428 
429  {OPT_DEF(eOptionWithParameter, eFileTrackSite),
430  "ft-site", "FileTrack site to use: 'submit' (or 'prod'), "
431  "'dsubmit' (or 'dev'), 'qsubmit' (or 'qa'). "
432  "Default: 'submit'.", {-1}},
433 
434  {OPT_DEF(eOptionWithParameter, eFileTrackToken),
435  FT_TOKEN_OPTION, "FileTrack auth token. When connecting to "
436  "FileTrack directly, either an API key or token is required.", {-1}},
437 
438  {OPT_DEF(eSwitch, eMirror),
439  "mirror", "NetCache: reconfigure mirroring.", {-1}},
440 
441  {OPT_DEF(ePositionalArgument, eServiceName), "SERVICE_NAME", NULL, {-1}},
442 
443  {OPT_DEF(eSwitch, eNoDNSLookup),
444  "no-dns-lookup", "Disable reverse DNS lookup "
445  "for the server IP addresses.", {-1}},
446 
447  {OPT_DEF(eOneOrMorePositional, eNCID), "ID", NULL, {-1}},
448 
449  {OPT_DEF(eZeroOrMorePositional, eOptionalNCID), "ID", NULL, {-1}},
450 
451  {OPT_DEF(eSwitch, eDirectMode),
452  DIRECT_MODE_OPTION, "Use direct connection to the storage back-end "
453  "even if provided locator has a NetStorage service. Cannot be "
454  "used together with '--" NETSTORAGE_OPTION "' option.", {-1}},
455 
456  {OPT_DEF(eSwitch, eNoServerCheck),
457  "no-server-check", "Disable server check.", {-1}},
458 
459  {OPT_DEF(eSwitch, eReportProgress),
460  "report-progress", "Report progress.", {-1}},
461 
462  /* Options available only with --extended-cli go below. */
463 
464  {OPT_DEF(eSwitch, eExtendedOptionDelimiter), NULL, NULL, {-1}},
465 
466  {OPT_DEF(eOptionWithParameter, eClientNode),
467  "client-node", "Client application identifier.", {-1}},
468 
469  {OPT_DEF(eOptionWithParameter, eClientSession),
470  CLIENT_SESSION_OPTION, "Client session identifier.", {-1}},
471 
472  {OPT_DEF(ePositionalArgument, eCommand), "COMMAND", NULL, {-1}},
473 
474  {OPT_DEF(eSwitch, eMultiline),
475  "multiline", "Expect multiple lines of output.", {-1}},
476 
477  {OPT_DEF(eOptionWithParameter, eProtocolDump),
478  PROTOCOL_DUMP_OPTION, "Dump input and output messages of "
479  "the automation protocol to the specified file.", {-1}},
480 
481  {OPT_DEF(eSwitch, eDebugConsole),
482  "debug-console", "Start an automation debugging session "
483  "(inhibits '--" PROTOCOL_DUMP_OPTION "').", {-1}},
484 
485  {OPT_DEF(eSwitch, eDumpNSNotifications),
486  "dump-ns-notifications", "Suppress normal processing "
487  "of this command, but print notifications received "
488  "from the NetSchedule servers over UDP within "
489  "the specified timeout.", {-1}},
490 };
491 
502 };
503 
505  int cat_id;
506  const char* title;
508  {eGeneralCommand, "General commands"},
509  {eNetCacheCommand, "NetCache commands"},
510  {eNetStorageCommand, "NetStorage commands"},
511  {eNetScheduleCommand, "Universal NetSchedule commands"},
512  {eSubmitterCommand, "Submitter commands"},
513  {eWorkerNodeCommand, "Worker node commands"},
514  {eAdministrativeCommand, "Administrative commands"},
515  {eExtendedCLICommand, "Extended commands"},
516 };
517 
518 #define ICACHE_KEY_FORMAT_EXPLANATION_BASE \
519  "\n\nBoth NetCache and ICache modes are supported. " \
520  "ICache mode requires blob ID to be specified in one of the " \
521  "following formats:\n" \
522  " * \"key,version,subkey\"\n"
523 
524 #define ICACHE_KEY_FORMAT_EXPLANATION \
525  ICACHE_KEY_FORMAT_EXPLANATION_BASE \
526  " * \"key\" \"version\" \"subkey\""
527 
528 #define ICACHE_KEY_FORMAT_EXPLANATION_OPT_VERSION \
529  ICACHE_KEY_FORMAT_EXPLANATION_BASE \
530  " * \"key\" [\"version\"] \"subkey\"\n" \
531  " (version could be omitted only if " PASSWORD_OPTION ", " \
532  OFFSET_OPTION " and " SIZE_OPTION " options are not used)."
533 
534 #define MAY_REQUIRE_LOCATION_HINTING \
535  "Some object locators may require additional options " \
536  "to hint at the actual object location."
537 
538 #define ABOUT_NETSTORAGE_OPTION \
539  "\n\nIf a NetStorage service (or server) is specified " \
540  "via the '--" NETSTORAGE_OPTION "' option or provided object locator " \
541  "contains a NetStorage service, that service " \
542  "or server will be used as a gateway to the actual storage " \
543  "back-end (e.g. NetCache). If the option is not specified " \
544  "and either the locator does not contain a NetStorage service " \
545  "or '--" DIRECT_MODE_OPTION "' option specified, " \
546  "a direct connection to the storage back-end is established."
547 
548 #define WN_NOT_NOTIFIED_DISCLAIMER \
549  "Worker nodes that may have already " \
550  "started job processing will not be notified."
551 
552 #define ABOUT_SWITCH_ARG \
553  "The " SWITCH_ARG " argument can be either 'on' or 'off'."
554 
555 #ifdef NCBI_GRID_XSITE_CONN_SUPPORT
556 #define ALLOW_XSITE_CONN_IF_SUPPORTED eAllowXSiteConn,
557 #else
558 #define ALLOW_XSITE_CONN_IF_SUPPORTED
559 #endif
560 
561 #define NETSTORAGE_COMMON_OPTIONS \
562  eNetStorage, eObjectKey, eUserKey, eNamespace, \
563  eFastStorage, ePersistent, eMovable, eCacheable, eNoMetaData, \
564  eAuth, eLoginToken
565 
566 #define NETSTORAGE_DIRECT_OPTIONS \
567  eDirectMode, eNetCache, eFileTrackSite
568 
570  int cat_id;
572  const char* name_variants;
573  const char* synopsis;
574  const char* usage;
577 } static const s_CommandDefinitions[] = {
578 
580  "whatis", "Determine argument type and characteristics.",
581  "This command makes an attempt to guess the type of its "
582  "argument. If the argument is successfully recognized "
583  "as a token that represents a Grid object, the type-"
584  "dependent information about the object is printed.\n\n"
585  "Valid output formats are \"" HUMAN_READABLE_OUTPUT_FORMAT
586  "\" and \"" JSON_OUTPUT_FORMAT "\". The default is \""
588  {eUntypedArg, eOutputFormat, -1},
589  {eHumanReadable, eJSON, -1}},
590 
592  LOGIN_COMMAND, "Generate a client identification token.",
593  "This command wraps the specified client identification "
594  "parameters in a session token. The returned token can "
595  "be passed later to other commands either through "
596  "the " LOGIN_TOKEN_ENV " environment variable or via "
597  "the '--" LOGIN_TOKEN_OPTION "' command line option, "
598  "which makes it possible to set client identification "
599  "parameters all at once.\n",
604 
606  "blobinfo|bi", "Retrieve metadata of a NetCache blob.",
607  "Print vital information about the specified blob. "
608  "Expired blobs will be reported as not found."
613 
615  "getblob|gb", "Retrieve a blob from NetCache.",
616  "Read the blob identified by ID and send its contents "
617  "to the standard output (or to the specified output "
618  "file). Expired blobs will be reported as not found."
623 
625  "putblob|pb", "Create or rewrite a NetCache blob.",
626  "Read data from the standard input (or a file) until EOF is "
627  "encountered and save the received data as a NetCache blob."
633 
635  "rmblob|rb", "Remove a NetCache blob.",
636  "Delete a blob if it exists. If the blob has expired "
637  "(or never existed), no errors are reported."
642 
644  "purge", "Delete all blobs from an ICache database.",
645  "This command purges the specified ICache database. "
646  "Administrative privileges are required.",
649 
651  "upload", "Create or rewrite a NetStorage object.",
652  "Save the data coming from the standard input (or an input file) "
653  "to a network storage. The choice of the storage is based on the "
654  "specified options and/or NetStorage server settings "
655  "(if NetStorage service is used). After the data has been written, "
656  "if new object is created and no locator/user key is provided, "
657  "the generated object locator is printed to the standard output."
663 
665  "download", "Retrieve a NetStorage object.",
666  "Read the object pointed to by the specified locator or user key and "
667  "send its contents to the standard output or a file."
671  eOutputFile,
673 
675  "relocate", "Move a NetStorage object to a different storage.",
676  "Transfer object contents to the new location hinted by "
677  "a combination of the specified options and/or "
678  "NetStorage server settings (if NetStorage service is used). "
679  "After the data has been transferred, a new object locator "
680  "will be generated and printed to the standard output, "
681  "unless user key is provided to specify the original object."
687 
690  "objectinfo", "Print information about a NetStorage object.",
696 
699  "rmobject", "Remove a NetStorage object.",
705 
707  "createloc", "Create a NetStorage object locator.",
708  "Create a NetStorage object locator for an ICache blob. "
709  "Blob ID must be specified in one of the following formats:\n" \
710  " * \"key,version,subkey\"\n"
711  " * \"key\" [\"version\"] \"subkey\"\n" \
712  " (version could be omitted).",
713  {eNCID, eNetCache, eCache, eLoginToken, -1}},
714 
716  "getattrlist", "Get list of all attributes set on a NetStorage object.",
717  "",
719  eOutputFile,
721 
723  "getattr", "Get a NetStorage object attribute value.",
724  "",
726  eOutputFile,
728 
730  "setattr", "Set a NetStorage object attribute value.",
731  "",
735 
737  JOBINFO_COMMAND "|ji", "Print information about a NetSchedule job.",
738  "Print vital information about the specified NetSchedule job. "
739  "Expired jobs will be reported as not found."
740  "\n\nThe following output formats are supported: \""
742  "\", and \"" JSON_OUTPUT_FORMAT "\". "
743  "The default is \"" HUMAN_READABLE_OUTPUT_FORMAT "\".",
748  {eHumanReadable, eRaw, eJSON, -1}},
749 
751  "submitjob", "Submit one or more jobs to a NetSchedule queue.",
752  "Create one or multiple jobs by submitting input data to "
753  "a NetSchedule queue. The first submitted job will be "
754  "executed immediately as long as there is a worker node "
755  "waiting for a job on that queue.\n\n"
756  "This command has three modes of operation:\n\n"
757  " - single job submission;\n"
758  " - batch submission;\n"
759  " - preparation of input for \"offline\" job execution.\n\n"
760  "In single job submission mode, unless the '--" INPUT_FILE_OPTION
761  "' or '--" INPUT_OPTION "' options are given, job input is read "
762  "from the standard input stream, and the rest of attributes are "
763  "taken from their respective command line options. The '--"
764  REMOTE_APP_ARGS_OPTION "' option creates a job for processing "
765  "by the 'remote_app' worker node, in which case either '--"
766  INPUT_OPTION "' or '--" INPUT_FILE_OPTION "' option can be used to "
767  "define the standard input stream of the remote_app job.\n\n"
768  "If the '--" WAIT_TIMEOUT_OPTION "' option is given in single "
769  "job submission mode, " GRID_APP_NAME " will wait for the job "
770  "to terminate, and if the job terminates within the specified "
771  "number of seconds or when this timeout has passed while the "
772  "job is still Pending or Running, job status will be printed right "
773  "after the job ID. And if this status is 'Done', job output will be "
774  "printed on the next line (unless the '--" OUTPUT_FILE_OPTION "' "
775  "option is given, in which case the output goes to the specified "
776  "file).\n\n"
777  "A NetCache server is required for saving job input if it "
778  "exceeds the capability of the NetSchedule internal storage.\n\n"
779  "Batch submission mode is activated by the '--"
780  BATCH_OPTION "' option, which takes the maximum batch size "
781  "as its argument. When this mode is enabled, all options that "
782  "define job attributes are ignored. Instead, job attributes "
783  "are read from the standard input stream or the specified "
784  "input file - one line per job. Each line must contain a "
785  "space-separated list of job attributes as follows:\n\n"
786  " input=\"DATA\" OR args=\"REMOTE_APP_ARGS\"\n"
787  " affinity=\"TOKEN\"\n"
788  " exclusive\n\n"
789  "Special characters in all quoted strings must be properly "
790  "escaped. It is OK to omit quotation marks for a string that "
791  "doesn't contain spaces. The \"input\" attribute is required "
792  "unless the \"args\" attribute is specified. The latter enables "
793  "remote_app mode and defines command line arguments for a "
794  "remote_app job, in which case the \"input\" attribute becomes "
795  "optional and defines the standard input stream for the "
796  "remote_app job.\n\n"
797  "Examples:\n\n"
798  " input=\"db, 8548@394.701\" exclusive\n"
799  " args=\"checkout p1/d2\" affinity=\"bin1\"\n\n"
800  "In batch mode, the IDs of the created jobs are printed to the "
801  "standard output stream (or the specified output file) one job "
802  "ID per line.\n\n"
803  "The third mode of operation bypasses NetSchedule and NetCache, "
804  "and saves the input data for direct consumption by the worker node "
805  "(primarily for testing or debugging). This mode is enabled by the "
806  "'--" JOB_INPUT_DIR_OPTION "' option, which defines the target "
807  "directory where input data will be saved.",
812  eJobInputDir, -1}},
813 
815  WATCHJOB_COMMAND, "Wait for a job to change status.",
816  "Listen to the job status change notifications and return "
817  "when one of the following conditions has been met:\n\n"
818  "* The wait timeout specified by the '--" WAIT_TIMEOUT_OPTION
819  "' option has passed. This option is required.\n\n"
820  "* The job has come to a status indicated by one or "
821  "more '--" WAIT_FOR_JOB_STATUS_OPTION "' options.\n\n"
822  "* A new job history event with the index greater than the "
823  "one specified by the '--" WAIT_FOR_JOB_EVENT_AFTER_OPTION
824  "' option has occurred.\n\n"
825  "If neither '--" WAIT_FOR_JOB_STATUS_OPTION "' nor '--"
826  WAIT_FOR_JOB_EVENT_AFTER_OPTION "' option is specified, "
827  "the '" WATCHJOB_COMMAND "' command waits until the job "
828  "progresses to a status other than 'Pending' or 'Running'.\n\n"
829  "The output of this command is independent of the reason it "
830  "exits: the latest job event index is printed to the standard "
831  "output on the first line and the current job status is printed "
832  "on the second line.",
837 
839  "getjobinput", "Read job input.",
840  "Retrieve and print job input to the standard output stream or "
841  "save it to a file.",
846 
848  "getjoboutput", "Read job output if the job is completed.",
849  "Retrieve and print job output to the standard output stream or "
850  "save it to a file. If the job does not exist or has not been "
851  "completed successfully, an appropriate error message is printed "
852  "to the standard error stream and the program exits with a non-zero "
853  "return code.",
857 
859  READJOB_COMMAND, "Return the next finished job.",
860  "Incrementally harvest IDs of successfully completed, failed, "
861  "and canceled jobs. This command has two modes of operation: "
862  "simple mode (without acknowledgment) and reliable mode (with "
863  "acknowledgment). The former is the default; the latter is "
864  "triggered by the '--" RELIABLE_READ_OPTION "' option.\n\n"
865  "In simple mode, if any of the specified NetSchedule servers "
866  "has a job that's done, failed, or canceled, the ID of that job will "
867  "be printed on the first line, and its status - 'Done', 'Failed', "
868  "or 'Canceled' - on the second line. Also, if the job is 'Done', "
869  "its entire output will be printed as well, starting from the third "
870  "line (unless the '--" OUTPUT_FILE_OPTION "' option is given, in "
871  "which case the output goes to the specified file).\n\n"
872  "After the job output has been successfully printed, the status "
873  "of the job is immediately changed to 'Confirmed', which means "
874  "that the job won't be available for reading anymore.\n\n"
875  "In reliable mode, job reading is a two-step process. The first "
876  "step, which is triggered by the '--" RELIABLE_READ_OPTION "' "
877  "option, acquires a reading reservation. If there's a job that's "
878  "done, failed, or canceled, its ID is printed on the first line along "
879  "with its final status ('Done', 'Failed', or 'Canceled') on the next "
880  "line and a unique reservation token on the third line. This first "
881  "step changes the status of the returned job from 'Done' to "
882  "'Reading'. The reading reservation is valid for a short period "
883  "of time configurable on the server. "
884  "If the server does not receive a reading confirmation (see "
885  "below) within this time frame, the job will change its status "
886  "back to the original status ('Done', 'Failed', or 'Canceled').\n\n"
887  "The second step is activated by one of the following "
888  "finalization options: '--" CONFIRM_READ_OPTION "', '--"
889  ROLLBACK_READ_OPTION "', or '--" FAIL_READ_OPTION "'. Each of "
890  "these options requires the reservation token that was issued "
891  "by NetSchedule during the first step to be passed as the "
892  "argument for the option. The corresponding job ID must be "
893  "provided with the '--" JOB_ID_OPTION "' option. The job must "
894  "still be in the 'Reading' status. After the finalization "
895  "step, the status of the job will change depending on the "
896  "option given as per the following table:\n\n"
897  " Option Resulting status\n"
898  " ================ ================\n"
899  " --" CONFIRM_READ_OPTION " Confirmed\n"
900  " --" FAIL_READ_OPTION " ReadFailed\n"
901  " --" ROLLBACK_READ_OPTION " Done, Failed, or Canceled\n\n"
902  "The 'Confirmed' status and the 'ReadFailed' status are final and "
903  "cannot be changed, while '--" ROLLBACK_READ_OPTION "' makes the "
904  "jobs available for subsequent '" READJOB_COMMAND "' commands.\n\n"
905  "In either mode, the '--" WAIT_TIMEOUT_OPTION "' option allows to "
906  "wait the specified number of seconds until a job becomes available "
907  "for reading. Without this option, if there are no completed, "
908  "failed, or canceled jobs in the queue, nothing will be printed "
909  "and the exit code will be zero.",
916 
918  "canceljob", "Cancel one or more NetSchedule jobs.",
919  "Mark the specified job (or multiple jobs) as canceled. "
920  "This command also instructs the worker node that may be "
921  "processing those jobs to stop the processing.",
925 
927  "requestjob", "Get a job from NetSchedule for processing.",
928  "Return a job pending for execution. The status of the job is changed "
929  "from \"Pending\" to \"Running\" before the job is returned. "
930  "This command makes it possible for " GRID_APP_NAME " to emulate a "
931  "worker node.\n\n"
932  "The affinity-related options affect how the job is selected. "
933  "Unless the '--" ANY_AFFINITY_OPTION "' option is given, a job "
934  "is returned only if its affinity matches one of the specified "
935  "affinities.\n\n"
936  "Job retrieval can also be restricted to the group name specified "
937  "by the '--" JOB_GROUP_OPTION "' option.\n\n"
938  "If a job is acquired, its ID and attributes are printed to the "
939  "standard output stream on the first and the second lines "
940  "respectively, followed by the input data of the job unless the '--"
941  OUTPUT_FILE_OPTION "' option is specified, in which case the "
942  "input data will be saved to that file.\n\n"
943  "The format of the line with job attributes is as follows:\n\n"
944  "auth_token [affinity=\"job_affinity\"] [exclusive]\n\n"
945  "If none of the NetSchedule servers has pending jobs in the "
946  "specified queue, nothing is printed and the exit code of zero "
947  "is returned.",
953 
955  "commitjob", "Mark the job as complete or failed.",
956  "Change the state of the job to either 'Done' or 'Failed'. This "
957  "command can only be executed on jobs that are in the 'Running' "
958  "state.\n\n"
959  "Unless one of the '--" JOB_OUTPUT_OPTION "', '--"
960  JOB_OUTPUT_BLOB_OPTION "', or '--" INPUT_FILE_OPTION "' options is "
961  "given, the job output is read from the standard input stream.\n\n"
962  "If the job is being reported as failed, an error message "
963  "must be provided with the '--" FAIL_JOB_OPTION "' command "
964  "line option.",
970 
972  "returnjob", "Return a previously accepted job.",
973  "Due to insufficient resources or for any other reason, "
974  "this command can be used by a worker node to return a "
975  "previously accepted job back to the NetSchedule queue. "
976  "The job will change its state from Running back to "
977  "Pending, but the information about previous runs will "
978  "not be discarded, and the expiration time will not be "
979  "advanced.",
983 
985  "clearnode", "Fail incomplete jobs and clear client record.",
986  "The '--" LOGIN_TOKEN_OPTION "' option must be provided for "
987  "client identification. This command removes the corresponding "
988  "client registry record from all NetSchedule servers. If there "
989  "are running jobs assigned to the client, their status will be "
990  "changed back to Pending (or Failed if no retries left).",
994 
996  "updatejob", "Modify attributes of an existing job.",
997  "Change one or more job properties. The outcome depends "
998  "on the current state of the job.",
1003 
1005  QUEUEINFO_COMMAND "|qi", "Get information about NetSchedule queues.",
1006  "When neither '--" ALL_QUEUES_OPTION "' nor '--"
1007  QUEUE_CLASSES_OPTION "' option is given, this command "
1008  "prints the following information on the specified queue: "
1009  "the queue configuration parameters, queue type (static or "
1010  "dynamic), and, if the queue is dynamic, its description and "
1011  "the queue class name. For newer NetSchedule versions, additional "
1012  "queue parameters may be printed.\n\n"
1013  "If the '--" ALL_QUEUES_OPTION "' option is given, this "
1014  "command prints information about every queue on each server "
1015  "specified by the '--" NETSCHEDULE_OPTION "' option.\n\n"
1016  "The '--" QUEUE_CLASSES_OPTION "' switch provides an option "
1017  "to get the information on queue classes instead of queues.\n\n"
1018  "Valid output formats are \"" RAW_OUTPUT_FORMAT "\" and \""
1019  JSON_OUTPUT_FORMAT "\". The default is \"" RAW_OUTPUT_FORMAT "\".",
1023  {eRaw, eJSON, -1}},
1024 
1026  "dumpqueue", "Dump a NetSchedule queue.",
1027  "This command dumps detailed information about jobs in a "
1028  "NetSchedule queue. It is possible to limit the number of "
1029  "records printed and also to filter the output by job status "
1030  "and/or job group.",
1034 
1036  "createqueue", "Create a dynamic NetSchedule queue.",
1037  "This command creates a new NetSchedule queue using "
1038  "a template known as queue class.",
1042 
1044  "getqueuelist", "Print the list of available NetSchedule queues.",
1045  "This command takes a NetSchedule service name (or server "
1046  "address) and queries each server participating that service "
1047  "for the list of configured or dynamically created queues. "
1048  "The collected lists are then combined in a single list of "
1049  "queues available on all servers in the service. For each "
1050  "queue available only on a subset of servers, its servers "
1051  "are listed in parentheses after the queue name.",
1054 
1056  "deletequeue", "Delete a dynamic NetSchedule queue.",
1058  "Static queues cannot be deleted, although it is "
1059  "possible to cancel all jobs in a static queue.",
1063 
1065  "replay", "Rerun a job in debugging environment.",
1066  "This command facilitates debugging of remote_cgi and remote_app "
1067  "jobs as well as \"native\" worker nodes. By using this command, "
1068  "job input can be preserved for later re-run in debugging or "
1069  "testing environment. Job output can also be preserved to compare "
1070  "it with \"reference\" runs.",
1075 
1077  "serverinfo|si", "Print information about a Grid server.",
1078  "Query and print information about a running "
1079  "NetCache, NetSchedule, NetStorage, or worker node process."
1080  "\n\nThe following output formats are supported: \""
1082  "\", and \"" JSON_OUTPUT_FORMAT "\". "
1083  "The default is \"" HUMAN_READABLE_OUTPUT_FORMAT "\".",
1088  {eHumanReadable, eRaw, eJSON, -1}},
1089 
1091  "stats|stat|status", "Show server status and access statistics.",
1092  "Dump accumulated statistics on server access and "
1093  "performance.\n\n"
1094  "When applied to a NetSchedule server, this operation "
1095  "supports the following format options: \"" RAW_OUTPUT_FORMAT "\", "
1097  "If none specified, \"" HUMAN_READABLE_OUTPUT_FORMAT "\" is assumed.",
1105  {eHumanReadable, eRaw, eJSON, -1}},
1106 
1108  "health", "Evaluate availability of a server.",
1109  "Retrieve vital parameters of a running NetCache "
1110  "or NetSchedule server and estimate its availability "
1111  "coefficient."
1112  /*"\n\nValid output format options for this operation: "
1113  "\"raw\""/ *, \"xml\", \"json\"* /". If none specified, "
1114  "\"raw\" is assumed."*/,
1115  {eNetCache, eNetSchedule, /*eOutputFormat,*/ eLoginToken, eAuth,
1117 
1119  "sanitycheck", "Run basic functionality tests on a service.",
1120  "Verify that the specified service is capable of performing "
1121  "its primary tasks. For NetCache servers, it means writing and "
1122  "reading blobs; for NetSchedule servers - submitting, returning, "
1123  "failing, and completing jobs.\n\n"
1124  "A queue name and/or a queue class name is required for NetSchedule "
1125  "testing. If a queue class is specified, it will be used to create a "
1126  "temporary queue (with the given name, if the '--" QUEUE_OPTION
1127  "' option is also specified). The default value for '--" QUEUE_OPTION
1128  "' is \"" NETSCHEDULE_CHECK_QUEUE "\".",
1132 
1134  "getconf", "Dump actual configuration of a server.",
1135  "Print the effective configuration parameters of a "
1136  "running NetCache, NetSchedule, or NetStorage server.",
1140 
1142  "reconf", "Reload server configuration.",
1143  "Update configuration parameters of a running server. "
1144  "The server will look for a configuration file in the "
1145  "same location that was used during start-up.",
1148 
1150  "drain", "Turn server drain mode on or off.",
1151  "When in drain mode, NetSchedule does not accept new jobs. "
1152  "As existing jobs expire naturally, the server is drained. "
1153  "Drain mode can be enabled for a particular queue or for "
1154  "the whole server.\n\n"
1159 
1161  SUSPEND_COMMAND "|pause", "Pause job processing.",
1162  "Depending on whether the command is applied to a worker node "
1163  "or a NetSchedule service, the worker node or the entire "
1164  "NetSchedule queue will be paused.\n\n"
1165  "The '--" PULLBACK_OPTION "' option instructs the worker node "
1166  "(if the option is applied to a single worker node) or all "
1167  "worker nodes connected to the given queue (if the option is "
1168  "applied to a NetSchedule service) to stop processing and return "
1169  "all running jobs.\n\n"
1170  "For worker nodes, two additional options can be specified:\n\n"
1171  "The '--" TIMEOUT_OPTION "' option indicates how long the "
1172  "worker node must wait for the running jobs to complete.\n\n"
1173  "The '--" WAIT_FOR_JOB_COMPLETION_OPTION "' option makes sure "
1174  "that when '" GRID_APP_NAME "' returns, no jobs are running.",
1179 
1181  "resume", "Continue job processing.",
1182  "This command undoes the effect of the '" SUSPEND_COMMAND
1183  "' command.",
1187 
1189  "shutdown", "Send a shutdown request to a remote server.",
1190  "Depending on the option specified, this command sends "
1191  "a shutdown request to a NetCache, NetSchedule or NetStorage "
1192  "server or a worker node process.\n\n"
1193  "Additional options '--" NOW_OPTION "' and '--" DIE_OPTION
1194  "' are applicable only to worker nodes and NetStorage servers.\n\n"
1195  "The '--" DRAIN_OPTION "' option is supported by NetSchedule "
1196  "servers version 4.11.0 and up and by NetCache servers version "
1197  "6.6.3 and up.",
1201 
1203  "discover|lbsm", "Perform service name resolution using LBSM.",
1204  "Query LBSM for the specified service name and print IPv4 socket "
1205  "addresses and rates of the servers in that service.",
1206  {eServiceName, eNoDNSLookup, -1}},
1207 
1209  "exec", "Execute an arbitrary command on one or more servers.",
1210  "This command is intended for testing and debugging purposes."
1211  "\n\nThe following output formats are supported: \""
1212  RAW_OUTPUT_FORMAT "\" and \"" JSON_OUTPUT_FORMAT "\". "
1213  "The default is \"" RAW_OUTPUT_FORMAT "\".",
1217  {eRaw, eJSON, -1}},
1218 
1220  "automate", "Run as a pipe-based automation server.",
1221  "This command starts " GRID_APP_NAME " as an automation "
1222  "server that can be used to interact with Grid objects "
1223  "through a Python module (ncbi.grid).",
1224  {eProtocolDump, eDebugConsole, -1}},
1225 };
1226 
1227 #define TOTAL_NUMBER_OF_COMMANDS int(sizeof(s_CommandDefinitions) / \
1228  sizeof(*s_CommandDefinitions))
1229 
1230 static const char* const s_OutputFormats[eNumberOfOutputFormats] = {
1231  HUMAN_READABLE_OUTPUT_FORMAT, /* eHumanReadable */
1232  RAW_OUTPUT_FORMAT, /* eRaw */
1233  JSON_OUTPUT_FORMAT /* eJSON */
1234 };
1235 
1236 static char s_ConnDebugEnv[] = "CONN_DEBUG_PRINTOUT=DATA";
1237 
1239 {
1240 public:
1242  FILE* CreateTemporaryFile(const char* output_file_name);
1243  void SaveOutputFile();
1245 
1246 private:
1250 };
1251 
1252 FILE* COutputFileHelper::CreateTemporaryFile(const char* output_file_name)
1253 {
1254  m_OutputFileName = output_file_name;
1256  if ((m_OutputStream = fopen(m_TemporaryFileName.c_str(), "wb")) == NULL) {
1257  NCBI_USER_THROW_FMT("Cannot create temporary file '" <<
1258  m_TemporaryFileName << "': " << strerror(errno));
1259  }
1260  return m_OutputStream;
1261 }
1262 
1264 {
1265  if (m_OutputStream != NULL) {
1266  fclose(m_OutputStream);
1267  rename(m_TemporaryFileName.c_str(), m_OutputFileName.c_str());
1268  m_OutputStream = NULL;
1269  }
1270 }
1271 
1273 {
1274  if (m_OutputStream != NULL) {
1275  fclose(m_OutputStream);
1277  }
1278 }
1279 
1281 {
1282  if (!strcmp(arg, "--latency")) {
1283  return CLogLatencies::eLast;
1284 
1285  } else if (!strcmp(arg, "--first-latency")) {
1286  return CLogLatencies::eFirst;
1287 
1288  } else if (!strcmp(arg, "--last-latency")) {
1289  return CLogLatencies::eLast;
1290 
1291  } else if (!strcmp(arg, "--all-latency")) {
1292  return CLogLatencies::eAll;
1293 
1294  } else {
1295  return CLogLatencies::eOff;
1296  }
1297 }
1298 
1300 {
1301  // Override connection defaults.
1302  CNcbiRegistry& reg = GetRWConfig();
1303  const string netservice_api_section("netservice_api");
1304  const string max_find_lbname_retries("max_find_lbname_retries");
1305  if (!reg.HasEntry(netservice_api_section, max_find_lbname_retries))
1306  reg.Set(netservice_api_section, max_find_lbname_retries, "0");
1307 
1308  if (!reg.HasEntry(netservice_api_section, "warn_on_unexpected_reply")) {
1309  reg.Set(netservice_api_section, "warn_on_unexpected_reply", "true");
1310  }
1311 
1312  const SCommandDefinition* cmd_def;
1313  const int* cmd_opt;
1314 
1315  ifstream input_file;
1316  COutputFileHelper output_file_helper;
1317 
1318  // Atom . does not match line terminators (coming with "Raw Data") thus the use of [\s\S] below
1319  CLogLatencyReport latency_report{
1320  "/connect/ (302.109)",
1321  R"(SOCK#\d+\[\d+\]@([0-9.:]+): Written at offset \d+[\s\S]+ ncbi_phid=[\s\S]+)",
1322  R"(SOCK#\d+\[\d+\]@([0-9.:]+): Read at offset \d+[\s\S]+)"
1323  };
1324 
1325  {
1326  bool enable_extended_cli = false;
1327  bool debug = false;
1328 
1329  int argc = m_ArgC - 1;
1330  const char** argv = m_ArgV + 1;
1331 
1332  while (--argc >= 0) {
1333  if (strcmp(*argv, "--extended-cli") == 0)
1334  enable_extended_cli = true;
1335  else if (strcmp(*argv, "--admin") == 0)
1336  m_AdminMode = true;
1337  else if (strcmp(*argv, "--debug") == 0)
1338  debug = true;
1339  else if (auto latency = s_GetLatency(*argv)) {
1340  latency_report.Start(latency);
1341  } else {
1342  ++argv;
1343  continue;
1344  }
1345  --m_ArgC;
1346  if (argc > 0)
1347  memmove(argv, argv + 1, argc * sizeof(*argv));
1348  }
1349 
1350  if (enable_extended_cli && (debug || latency_report)) {
1351  // Setup error posting
1360  // Print conn data
1362  // Enable data logging
1363  reg.Set(netservice_api_section, "connection_data_logging", "true");
1364  latency_report.SetDebug(debug);
1365  }
1366 
1368  "Utility to access and control NCBI Grid services.");
1369 
1370  const SOptionDefinition* opt_def = s_OptionDefinitions;
1371  int opt_id = 0;
1372  do {
1373 #ifdef _DEBUG
1374  _ASSERT(opt_def->opt_id == opt_id &&
1375  "EOption order must match positions in s_OptionDefinitions.");
1376 #endif
1377  if (opt_id != eExtendedOptionDelimiter)
1378  clparser.AddOption(opt_def->type, opt_id,
1379  opt_def->name_variants, opt_def->description ?
1380  opt_def->description : kEmptyStr);
1381  else if (!enable_extended_cli)
1382  break;
1383  ++opt_def;
1384  } while (++opt_id < eNumberOfOptions);
1385 
1388  do {
1389  clparser.AddCommandCategory(cat_def->cat_id, cat_def->title);
1390  ++cat_def;
1391  } while (--i > 0);
1392 
1393  cmd_def = s_CommandDefinitions;
1394  for (i = 0; i < TOTAL_NUMBER_OF_COMMANDS; ++i, ++cmd_def) {
1395  if (!enable_extended_cli &&
1396  ((cmd_def->cat_id == eExtendedCLICommand) ||
1397  ((cmd_def->cat_id ==
1399  continue;
1400  clparser.AddCommand(i, cmd_def->name_variants,
1401  cmd_def->synopsis, cmd_def->usage, cmd_def->cat_id);
1402  for (cmd_opt = cmd_def->options; *cmd_opt >= 0; ++cmd_opt)
1403  if (*cmd_opt < eExtendedOptionDelimiter || enable_extended_cli)
1404  clparser.AddAssociation(i, *cmd_opt);
1405  }
1406 
1408  return 1;
1409 
1410  try {
1411  int cmd_id = clparser.Parse(m_ArgC, m_ArgV);
1412  if (cmd_id < 0)
1413  return 0;
1414 
1415  cmd_def = s_CommandDefinitions + cmd_id;
1416  }
1417  catch (exception& e) {
1418  NcbiCerr << e.what();
1419  return 1;
1420  }
1421 
1422  for (cmd_opt = cmd_def->options; *cmd_opt >= 0; ++cmd_opt)
1423  MarkOptionAsAccepted(*cmd_opt);
1424 
1427 
1428  const char* opt_value;
1429 
1430  while (clparser.NextOption(&opt_id, &opt_value)) {
1431  MarkOptionAsExplicitlySet(opt_id);
1432  switch (EOption(opt_id)) {
1433  case eUntypedArg:
1434  /* FALL THROUGH */
1435  case eOptionalID:
1438  /* FALL THROUGH */
1439  case eID:
1440  case eJobId:
1441  case eTargetQueueArg:
1442  m_Opts.id = opt_value;
1443  break;
1444  case eLoginToken:
1445  if (!ParseLoginToken(opt_value))
1446  return 1;
1447  break;
1448  case eAuth:
1449  m_Opts.auth = opt_value;
1450  break;
1451  case eAppUID:
1452  m_Opts.app_uid = opt_value;
1453  break;
1454  case eOutputFormat:
1455  {
1456  const int* format = cmd_def->output_formats;
1457  while (NStr::CompareNocase(opt_value,
1458  s_OutputFormats[*format]) != 0)
1459  if (*++format < 0) {
1460  fprintf(stderr, GRID_APP_NAME
1461  " %s: invalid output format '%s'.\n",
1462  cmd_def->name_variants, opt_value);
1463  return 2;
1464  }
1466  }
1467  break;
1468  case eNetCache:
1469  m_Opts.nc_service = opt_value;
1470  break;
1471  case eCache:
1472  case eCacheArg:
1473  m_Opts.cache_name = opt_value;
1474  break;
1475  case ePassword:
1476  m_Opts.password = opt_value;
1477  break;
1478  case eOffset:
1479  m_Opts.offset = size_t(NStr::StringToUInt8(opt_value));
1480  break;
1481  case eSize:
1482  m_Opts.size = size_t(NStr::StringToUInt8(opt_value));
1483  break;
1484  case eTTL:
1485  m_Opts.ttl = NStr::StringToUInt(opt_value);
1486  break;
1487  case eNetStorage:
1488  m_Opts.nst_service = opt_value;
1489  break;
1490  case eNamespace:
1491  m_Opts.app_domain = opt_value;
1492  break;
1493  case ePersistent:
1495  break;
1496  case eFastStorage:
1498  break;
1499  case eMovable:
1501  break;
1502  case eCacheable:
1504  break;
1505  case eNoMetaData:
1507  break;
1508  case eAttrName:
1509  m_Opts.attr_name = opt_value;
1510  break;
1511  case eAttrValue:
1512  m_Opts.attr_value = opt_value;
1513  break;
1514  case eNetSchedule:
1515  case eWorkerNode:
1516  m_Opts.ns_service = opt_value;
1517  break;
1518  case eQueue:
1519  case eQueueArg:
1520  m_Opts.queue = opt_value;
1521  break;
1522  case eAffinity:
1523  case eAffinityList:
1524  m_Opts.affinity = opt_value;
1525  break;
1526  case eJobOutput:
1527  m_Opts.job_output = opt_value;
1528  break;
1529  case eJobOutputBlob:
1530  m_Opts.job_output_blob = opt_value;
1531  break;
1532  case eReturnCode:
1533  m_Opts.return_code = NStr::StringToInt(opt_value);
1534  break;
1535  case eBatch:
1536  if ((m_Opts.batch_size = NStr::StringToUInt(opt_value)) == 0) {
1537  fprintf(stderr, GRID_APP_NAME
1538  " %s: batch size must be greater that zero.\n",
1539  cmd_def->name_variants);
1540  return 2;
1541  }
1542  break;
1543  case eLimit:
1544  m_Opts.limit = NStr::StringToUInt(opt_value);
1545  break;
1546  case eWaitTimeout:
1547  m_Opts.timeout = NStr::StringToUInt(opt_value);
1548  break;
1549  case eAuthToken:
1550  case eConfirmRead:
1551  case eRollbackRead:
1552  case eFailRead:
1553  m_Opts.auth_token = opt_value;
1554  break;
1555  case eStartAfterJob:
1556  m_Opts.start_after_job = opt_value;
1557  break;
1558  case eJobCount:
1559  m_Opts.job_count = NStr::StringToSizet(opt_value);
1560  break;
1561  case eJobStatus:
1562  // Job status validation, will throw on fail
1563  StringToJobStatus(opt_value);
1564  if (!m_Opts.job_statuses.empty()) {
1565  m_Opts.job_statuses.append(",");
1566  }
1567  m_Opts.job_statuses.append(opt_value);
1568  break;
1569  case eWaitForJobStatus:
1570  if (NStr::CompareNocase(opt_value, ANY_JOB_STATUS) == 0)
1571  m_Opts.job_status_mask = -1;
1572  else
1573  m_Opts.job_status_mask |= 1 << StringToJobStatus(opt_value);
1574  break;
1575  case eWaitForJobEventAfter:
1577  break;
1578  case eExtendLifetime:
1580  break;
1581  case eAggregationInterval:
1582  m_Opts.aggregation_interval = opt_value;
1583  break;
1584  case eClientNode:
1585  m_Opts.client_node = opt_value;
1586  break;
1587  case eClientSession:
1588  m_Opts.client_session = opt_value;
1589  break;
1590  case eProgressMessage:
1591  m_Opts.progress_message = opt_value;
1592  break;
1593  case eJobGroup:
1594  m_Opts.job_group = opt_value;
1595  break;
1596  case eErrorMessage:
1597  case eFailJob:
1598  m_Opts.error_message = opt_value;
1599  break;
1600  case eQueueClass:
1601  case eQueueClassArg:
1602  m_Opts.queue_class = opt_value;
1603  break;
1604  case eQueueDescription:
1605  m_Opts.queue_description = opt_value;
1606  break;
1607  case eSwitchArg:
1608  if (NStr::CompareNocase(opt_value, "on") == 0)
1610  else if (NStr::CompareNocase(opt_value, "off") == 0)
1612  else {
1613  fputs(ABOUT_SWITCH_ARG "\n", stderr);
1614  return 2;
1615  }
1616  case eInput:
1617  m_Opts.input = opt_value;
1618  break;
1619  case eCommand:
1620  m_Opts.command = opt_value;
1621  break;
1622  case eInputFile:
1623  // If not special value for stdin
1624  if (strcmp(opt_value, "-")) {
1625  input_file.open(opt_value, ifstream::binary);
1626  if (input_file.fail()) {
1627  fprintf(stderr, "%s: %s\n", opt_value, strerror(errno));
1628  return 2;
1629  }
1631  } else {
1632  ReadFromCin();
1633  }
1634  break;
1635  case eRemoteAppArgs:
1636  m_Opts.remote_app_args = opt_value;
1637  break;
1638  case eJobInputDir:
1639  m_Opts.job_input_dir = opt_value;
1640  break;
1641  case eJobOutputDir:
1642  m_Opts.job_output_dir = opt_value;
1643  break;
1644  case eOutputFile:
1646  output_file_helper.CreateTemporaryFile(opt_value);
1647  break;
1648  case eFileTrackSite:
1649  m_Opts.ft_site = opt_value;
1650  break;
1651  case eFileTrackToken:
1652  m_Opts.ft_token = opt_value;
1653  break;
1654  case eServiceName:
1655  m_Opts.service_name = opt_value;
1656  break;
1657  case eNCID:
1658  case eOptionalNCID:
1659  if (!m_Opts.ncid.AddPart(opt_value)) {
1660  fprintf(stderr, GRID_APP_NAME
1661  ": too many positional parameters.\n");
1662  return 2;
1663  }
1664  break;
1665  case eProtocolDump:
1666  if ((m_Opts.protocol_dump = fopen(opt_value, "a")) == NULL) {
1667  fprintf(stderr, "%s: %s\n", opt_value, strerror(errno));
1668  return 2;
1669  }
1670  break;
1671 #ifdef NCBI_GRID_XSITE_CONN_SUPPORT
1672  case eAllowXSiteConn:
1675  break;
1676 #endif
1677  default: // Just to silence the compiler.
1678  break;
1679  }
1680  }
1681 
1682  opt_id = eNumberOfOptions - 1;
1683  do
1684  if (IsOptionSet(opt_id))
1685  for (const int* required_opt =
1686  s_OptionDefinitions[opt_id].required_options;
1687  *required_opt != -1; ++required_opt)
1688  if (!IsOptionSet(*required_opt)) {
1689  fprintf(stderr, GRID_APP_NAME
1690  ": option '--%s' requires option '--%s'.\n",
1691  s_OptionDefinitions[opt_id].name_variants,
1693  *required_opt].name_variants);
1694  return 2;
1695  }
1696  while (--opt_id >= 0);
1697 
1698  if (IsOptionSet(eNoConnRetries)) {
1699  const string connection_max_retries("connection_max_retries");
1700  if (!reg.HasEntry(netservice_api_section, connection_max_retries))
1701  reg.Set(netservice_api_section, connection_max_retries, "0");
1702  }
1703 
1704  if (m_Opts.auth.empty())
1706 
1708  ReadFromCin();
1709  } else if (IsOptionSet(eInput) && IsOptionSet(eInputFile)) {
1710  fprintf(stderr, GRID_APP_NAME ": options '--" INPUT_FILE_OPTION
1711  "' and '--" INPUT_OPTION "' are mutually exclusive.\n");
1712  return 2;
1713  }
1715  m_Opts.output_stream = stdout;
1716 #ifdef WIN32
1717  _setmode(_fileno(stdout), O_BINARY);
1718 #endif
1719  }
1720  }
1721 
1723 
1724  try {
1725  int retcode = (this->*cmd_def->cmd_proc)();
1726  output_file_helper.SaveOutputFile();
1727  return retcode;
1728  }
1729  catch (CConfigException& e) {
1730  fprintf(stderr, "%s\n", e.GetMsg().c_str());
1731  return 2;
1732  }
1733  catch (CArgException& e) {
1734  fprintf(stderr, GRID_APP_NAME " %s: %s\n",
1735  cmd_def->name_variants, e.GetMsg().c_str());
1736  return 2;
1737  }
1738  catch (CException& e) {
1739  fprintf(stderr, GRID_APP_NAME ": %s\n",
1740  e.ReportThis(eDPF_ErrorID).c_str());
1741  return 3;
1742  }
1743  catch (string& s) {
1744  fprintf(stderr, "%s\n", s.c_str());
1745  return 4;
1746  }
1747 }
1748 
1749 bool CGridCommandLineInterfaceApp::OnWarning(bool not_worker_node_admin,
1750  const string& warn_msg, CNetServer server)
1751 {
1752  string warning(warn_msg);
1753 
1754  const char* server_type = not_worker_node_admin ?
1755  "NetSchedule server" : "Worker node";
1756 
1759 
1760  if (warning_type != CNetScheduleAPI::eWarnUnknown)
1761  fprintf(stderr, "%s at %s: WARNING [%s]: %s\n",
1762  server_type,
1763  server.GetServerAddress().c_str(),
1765  warning.c_str());
1766  else
1767  fprintf(stderr, "%s at %s: WARNING: %s\n",
1768  server_type,
1769  server.GetServerAddress().c_str(),
1770  warning.c_str());
1771 
1772  return true;
1773 }
1774 
1776 {
1777  puts(line.c_str());
1778 }
1779 
1781  const char* status_str)
1782 {
1783  CNetScheduleAPI::EJobStatus job_status =
1784  CNetScheduleAPI::StringToStatus(status_str);
1785 
1786  if (job_status != CNetScheduleAPI::eJobNotFound)
1787  return job_status;
1788 
1789  NCBI_THROW_FMT(CArgException, eInvalidArg,
1790  "invalid job status '" << status_str << '\'');
1791 }
1792 
1794 {
1795  if (token.empty())
1796  return true;
1797 
1799 
1800  CCompoundIDField label_field(cid.GetFirst(eCIT_Label));
1801 
1802  string user;
1803  string host;
1804  Uint8 pid = 0;
1805  Int8 timestamp = 0;
1806  string uid;
1807 
1808  while (label_field) {
1809  CCompoundIDField value_field(label_field.GetNextNeighbor());
1810  if (!value_field) {
1811  fprintf(stderr, GRID_APP_NAME ": invalid login token format.\n");
1812  return false;
1813  }
1814  string label(label_field.GetLabel());
1815 
1817  m_Opts.app_uid = value_field.GetString();
1819  } else if (label == LOGIN_TOKEN_AUTH_FIELD) {
1820  m_Opts.auth = value_field.GetString();
1822  } else if (label == LOGIN_TOKEN_USER_FIELD)
1823  user = value_field.GetString();
1824  else if (label == LOGIN_TOKEN_HOST_FIELD)
1825  host = value_field.GetHost();
1826  else if (label == LOGIN_TOKEN_NETCACHE_FIELD) {
1827  m_Opts.nc_service = value_field.GetServiceName();
1829  } else if (label == LOGIN_TOKEN_ICACHE_NAME_FIELD) {
1830  m_Opts.cache_name = value_field.GetDatabaseName();
1832  } else if (label == LOGIN_TOKEN_ENABLE_MIRRORING) {
1833  if (value_field.GetBoolean())
1835  } else if (label == LOGIN_TOKEN_NETSCHEDULE_FIELD) {
1836  m_Opts.ns_service = value_field.GetServiceName();
1838  } else if (label == LOGIN_TOKEN_QUEUE_FIELD) {
1839  m_Opts.queue = value_field.GetDatabaseName();
1841  } else if (label == LOGIN_TOKEN_SESSION_PID_FIELD)
1842  pid = value_field.GetID();
1844  timestamp = value_field.GetTimestamp();
1846  uid = value_field.GetString();
1847 #ifdef NCBI_GRID_XSITE_CONN_SUPPORT
1848  else if (label == LOGIN_TOKEN_ALLOW_XSITE_CONN) {
1849  if (value_field.GetBoolean())
1850  MarkOptionAsSet(eAllowXSiteConn);
1851  }
1852 #endif
1853  else if (label == LOGIN_TOKEN_NO_CONN_RETRIES) {
1854  if (value_field.GetBoolean())
1856  } else if (label == LOGIN_TOKEN_FILETRACK_SITE) {
1857  m_Opts.ft_site = value_field.GetString();
1859  } else if (label == LOGIN_TOKEN_FILETRACK_TOKEN) {
1860  m_Opts.ft_token = value_field.GetString();
1862  }
1863 
1864  label_field = label_field.GetNextHomogeneous();
1865  }
1866 
1867  const string& app(m_Opts.app_uid);
1869  (app.empty() ? DEFAULT_APP_UID : app) + "::" +
1870  (user.empty() ? kEmptyStr : user + '@') +
1871  host;
1872 
1874  NStr::NumericToString(pid) + '@' +
1875  NStr::NumericToString(timestamp) + ':' +
1876  uid;
1877 
1880 
1881  return true;
1882 }
1883 
1885 {
1887 #ifdef WIN32
1888  _setmode(_fileno(stdin), O_BINARY);
1889 #endif
1890 }
1891 
1892 int main(int argc, const char* argv[])
1893 {
1894  CGridCommandLineInterfaceApp app(argc, argv);
1895  return app.AppMain(argc, argv);
1896 }
#define GRID_APP_NAME
Definition: cgi2rcgi.cpp:63
CArgException –.
Definition: ncbiargs.hpp:120
int Parse(int argc, const char *const *argv)
Parse the command line.
Definition: clparser.cpp:734
bool NextOption(int *opt_id, const char **opt_value)
Definition: clparser.cpp:744
void AddOption(EOptionType type, int opt_id, const string &name_variants, const string &description)
Definition: clparser.cpp:648
void AddCommandCategory(int cat_id, const string &title)
Definition: clparser.cpp:678
void AddCommand(int cmd_id, const string &name_variants, const string &synopsis, const string &usage, int cat_id=-1)
Definition: clparser.cpp:686
void AddAssociation(int cmd_id, int opt_id)
Definition: clparser.cpp:704
Compound ID field – an element of the compound ID that has a type and a value.
string GetString() const
Return the string value that this field contains.
CCompoundIDField GetNextHomogeneous()
Return the next field of the same type.
CCompoundIDField GetNextNeighbor()
Return the next immediately adjacent field.
string GetServiceName() const
Return the LBSM service name that this field contains.
bool GetBoolean() const
Return the Boolean value that this field contains.
string GetHost() const
Return the host name or address that this field contains.
Int8 GetTimestamp() const
Return the UNIX timestamp that this field contains.
string GetDatabaseName() const
Return the database name that this field contains.
string GetLabel() const
Return the application-specific tag that this field contains.
Uint8 GetID() const
Return the ID value that this field contains.
CCompoundID FromString(const string &cid)
Unpack the base64-encoded ID and return a CCompoundID object for field extraction.
Base64-encoded ID string that contains extractable typed fields.
CCompoundIDField GetFirst(ECompoundIDFieldType field_type)
Return the first field of the specified type or NULL if this compound ID contains no fields of such t...
CConfigException –.
Definition: ncbi_config.hpp:53
CDirEntry –.
Definition: ncbifile.hpp:262
static bool OnWarning(bool worker_node_admin, const string &warn_msg, CNetServer server)
Definition: grid_cli.cpp:1749
CCompoundIDPool m_CompoundIDPool
Definition: grid_cli.hpp:457
bool IsOptionSet(int option) const
Definition: grid_cli.hpp:421
struct CGridCommandLineInterfaceApp::SOptions m_Opts
void MarkOptionAsExplicitlySet(int option)
Definition: grid_cli.hpp:431
void MarkOptionAsAccepted(int option)
Definition: grid_cli.hpp:391
bool ParseLoginToken(const string &token)
Definition: grid_cli.cpp:1793
void MarkOptionAsSet(int option)
Definition: grid_cli.hpp:416
CGridCommandLineInterfaceApp(int argc, const char *argv[])
Definition: grid_cli.cpp:54
static void PrintLine(const string &line)
Definition: grid_cli.cpp:1775
bool IsOptionAcceptedButNotSet(EOption option) const
Definition: grid_cli.hpp:406
virtual int Run()
Run the application.
Definition: grid_cli.cpp:1299
CNetScheduleAPI::EJobStatus StringToJobStatus(const char *status_str)
Definition: grid_cli.cpp:1780
CNcbiRegistry –.
Definition: ncbireg.hpp:913
string GetServerAddress() const
static void AllowXSiteConnections()
string m_TemporaryFileName
Definition: grid_cli.cpp:1248
FILE * CreateTemporaryFile(const char *output_file_name)
Definition: grid_cli.cpp:1252
string m_OutputFileName
Definition: grid_cli.cpp:1247
@ eCIT_Label
Definition: compound_id.hpp:77
static FILE * input_file
Definition: common.c:35
#define false
Definition: bool.h:36
void debug()
#define GRID_APP_VERSION_INFO
static char s_ConnDebugEnv[]
Definition: grid_cli.cpp:1236
struct SCommandDefinition s_CommandDefinitions[]
#define ABOUT_NETSTORAGE_OPTION
Definition: grid_cli.cpp:538
#define WN_NOT_NOTIFIED_DISCLAIMER
Definition: grid_cli.cpp:548
struct SOptionDefinition s_OptionDefinitions[eNumberOfOptions]
#define MAY_REQUIRE_LOCATION_HINTING
Definition: grid_cli.cpp:534
static const char *const s_OutputFormats[eNumberOfOutputFormats]
Definition: grid_cli.cpp:1230
#define TOTAL_NUMBER_OF_COMMANDS
Definition: grid_cli.cpp:1227
#define ABOUT_SWITCH_ARG
Definition: grid_cli.cpp:552
#define ALLOW_XSITE_CONN_IF_SUPPORTED
Definition: grid_cli.cpp:558
#define NETSTORAGE_DIRECT_OPTIONS
Definition: grid_cli.cpp:566
CLogLatencies::EWhich s_GetLatency(const char *arg)
Definition: grid_cli.cpp:1280
struct SCommandCategoryDefinition s_CategoryDefinitions[eNumberOfCommandCategories]
#define ICACHE_KEY_FORMAT_EXPLANATION
Definition: grid_cli.cpp:524
#define OPT_DEF(opt_type, opt_id)
Definition: grid_cli.cpp:67
int main(int argc, const char *argv[])
Definition: grid_cli.cpp:1892
#define ANY_JOB_STATUS
Definition: grid_cli.cpp:52
#define NETSTORAGE_COMMON_OPTIONS
Definition: grid_cli.cpp:561
USING_NCBI_SCOPE
Definition: grid_cli.cpp:50
#define ICACHE_KEY_FORMAT_EXPLANATION_OPT_VERSION
Definition: grid_cli.cpp:528
ECommandCategory
Definition: grid_cli.cpp:492
@ eGeneralCommand
Definition: grid_cli.cpp:493
@ eNetScheduleCommand
Definition: grid_cli.cpp:496
@ eAdministrativeCommand
Definition: grid_cli.cpp:499
@ eNetStorageCommand
Definition: grid_cli.cpp:495
@ eNumberOfCommandCategories
Definition: grid_cli.cpp:501
@ eNetCacheCommand
Definition: grid_cli.cpp:494
@ eExtendedCLICommand
Definition: grid_cli.cpp:500
@ eSubmitterCommand
Definition: grid_cli.cpp:497
@ eWorkerNodeCommand
Definition: grid_cli.cpp:498
Declarations of command line interface arguments and handlers.
#define TIMEOUT_OPTION
Definition: grid_cli.hpp:95
#define RAW_OUTPUT_FORMAT
Definition: grid_cli.hpp:137
#define QUEUEINFO_COMMAND
Definition: grid_cli.hpp:133
#define MOVABLE_OPTION
Definition: grid_cli.hpp:79
#define RELIABLE_READ_OPTION
Definition: grid_cli.hpp:96
#define LOGIN_TOKEN_HOST_FIELD
Definition: grid_cli.hpp:55
#define LOGIN_TOKEN_FILETRACK_SITE
Definition: grid_cli.hpp:66
#define WAIT_FOR_JOB_COMPLETION_OPTION
Definition: grid_cli.hpp:113
#define LOGIN_COMMAND
Definition: grid_cli.hpp:129
#define JOBINFO_COMMAND
Definition: grid_cli.hpp:130
#define PULLBACK_OPTION
Definition: grid_cli.hpp:112
#define LOGIN_TOKEN_SESSION_PID_FIELD
Definition: grid_cli.hpp:61
#define LOGIN_TOKEN_QUEUE_FIELD
Definition: grid_cli.hpp:60
EOutputFormat
Definition: grid_cli.hpp:276
@ eHumanReadable
Definition: grid_cli.hpp:277
@ eJSON
Definition: grid_cli.hpp:279
@ eNumberOfOutputFormats
Definition: grid_cli.hpp:280
#define LOGIN_TOKEN_FILETRACK_TOKEN
Definition: grid_cli.hpp:67
#define PASSWORD_OPTION
Definition: grid_cli.hpp:120
#define LOGIN_TOKEN_ENV
Definition: grid_cli.hpp:49
#define BRIEF_OPTION
Definition: grid_cli.hpp:101
#define DRAIN_OPTION
Definition: grid_cli.hpp:116
#define NOW_OPTION
Definition: grid_cli.hpp:114
#define CACHE_OPTION
Definition: grid_cli.hpp:71
#define FAIL_JOB_OPTION
Definition: grid_cli.hpp:106
#define QUEUE_ARG
Definition: grid_cli.hpp:110
#define LOGIN_TOKEN_OPTION
Definition: grid_cli.hpp:69
#define HUMAN_READABLE_OUTPUT_FORMAT
Definition: grid_cli.hpp:136
#define WAIT_FOR_JOB_EVENT_AFTER_OPTION
Definition: grid_cli.hpp:103
#define LOGIN_TOKEN_SESSION_TIMESTAMP_FIELD
Definition: grid_cli.hpp:62
#define OFFSET_OPTION
Definition: grid_cli.hpp:121
#define LOGIN_TOKEN_ENABLE_MIRRORING
Definition: grid_cli.hpp:58
#define AFFINITY_OPTION
Definition: grid_cli.hpp:89
#define LOGIN_TOKEN_USER_FIELD
Definition: grid_cli.hpp:54
#define FAST_STORAGE_OPTION
Definition: grid_cli.hpp:78
#define WORKER_NODE_OPTION
Definition: grid_cli.hpp:82
#define PROTOCOL_DUMP_OPTION
Definition: grid_cli.hpp:119
#define REMOTE_APP_ARGS_OPTION
Definition: grid_cli.hpp:85
#define QUEUE_CLASSES_OPTION
Definition: grid_cli.hpp:108
#define INPUT_FILE_OPTION
Definition: grid_cli.hpp:84
#define TRY_ALL_SERVERS_OPTION
Definition: grid_cli.hpp:72
#define QUEUE_OPTION
Definition: grid_cli.hpp:87
#define LOGIN_TOKEN_NO_CONN_RETRIES
Definition: grid_cli.hpp:65
#define QUEUE_CLASS_OPTION
Definition: grid_cli.hpp:109
#define JOB_OUTPUT_DIR_OPTION
Definition: grid_cli.hpp:118
#define WATCHJOB_COMMAND
Definition: grid_cli.hpp:132
#define LOGIN_TOKEN_NETCACHE_FIELD
Definition: grid_cli.hpp:56
#define CACHEABLE_OPTION
Definition: grid_cli.hpp:80
#define OBJECT_KEY_OPTION
Definition: grid_cli.hpp:74
#define FAIL_READ_OPTION
Definition: grid_cli.hpp:99
#define JOB_ID_OPTION
Definition: grid_cli.hpp:100
#define FT_TOKEN_OPTION
Definition: grid_cli.hpp:123
#define OUTPUT_FILE_OPTION
Definition: grid_cli.hpp:86
#define DEFAULT_APP_UID
Definition: grid_cli.hpp:50
#define WAIT_FOR_JOB_STATUS_OPTION
Definition: grid_cli.hpp:102
#define JOB_OUTPUT_BLOB_OPTION
Definition: grid_cli.hpp:93
#define NETSCHEDULE_CHECK_QUEUE
Definition: grid_cli.hpp:140
#define CONFIRM_READ_OPTION
Definition: grid_cli.hpp:97
#define ANY_AFFINITY_OPTION
Definition: grid_cli.hpp:91
#define NETSTORAGE_OPTION
Definition: grid_cli.hpp:73
#define SUSPEND_COMMAND
Definition: grid_cli.hpp:134
#define JOB_GROUP_OPTION
Definition: grid_cli.hpp:104
#define PERSISTENT_OPTION
Definition: grid_cli.hpp:77
#define SWITCH_ARG
Definition: grid_cli.hpp:111
#define JOB_OUTPUT_OPTION
Definition: grid_cli.hpp:92
#define LOGIN_TOKEN_ICACHE_NAME_FIELD
Definition: grid_cli.hpp:57
#define LOGIN_TOKEN_ALLOW_XSITE_CONN
Definition: grid_cli.hpp:64
#define LOGIN_TOKEN_AUTH_FIELD
Definition: grid_cli.hpp:53
#define CLIENT_SESSION_OPTION
Definition: grid_cli.hpp:125
#define JSON_OUTPUT_FORMAT
Definition: grid_cli.hpp:138
#define NETSCHEDULE_OPTION
Definition: grid_cli.hpp:81
#define DIE_OPTION
Definition: grid_cli.hpp:115
#define LOGIN_TOKEN_SESSION_UID_FIELD
Definition: grid_cli.hpp:63
EOption
Definition: grid_cli.hpp:150
@ eNoMetaData
Definition: grid_cli.hpp:189
@ eStartAfterJob
Definition: grid_cli.hpp:217
@ eID
Definition: grid_cli.hpp:153
@ eWaitForJobStatus
Definition: grid_cli.hpp:225
@ eFailRead
Definition: grid_cli.hpp:208
@ eRemoteAppArgs
Definition: grid_cli.hpp:165
@ eSwitchArg
Definition: grid_cli.hpp:240
@ eDie
Definition: grid_cli.hpp:244
@ eRemoteAppStdIn
Definition: grid_cli.hpp:166
@ eDirectMode
Definition: grid_cli.hpp:260
@ eQueueDescription
Definition: grid_cli.hpp:239
@ eCache
Definition: grid_cli.hpp:172
@ eProgressMessageOnly
Definition: grid_cli.hpp:223
@ ePreviousInterval
Definition: grid_cli.hpp:252
@ eClientSession
Definition: grid_cli.hpp:267
@ eReliableRead
Definition: grid_cli.hpp:205
@ eCommand
Definition: grid_cli.hpp:268
@ eAuth
Definition: grid_cli.hpp:162
@ eAffinityInfo
Definition: grid_cli.hpp:214
@ eReturnCode
Definition: grid_cli.hpp:202
@ eWaitForJobCompletion
Definition: grid_cli.hpp:242
@ eNCID
Definition: grid_cli.hpp:258
@ eVerbose
Definition: grid_cli.hpp:220
@ eRollbackRead
Definition: grid_cli.hpp:207
@ eFastStorage
Definition: grid_cli.hpp:186
@ eMultiline
Definition: grid_cli.hpp:269
@ eWaitTimeout
Definition: grid_cli.hpp:231
@ eDeferExpiration
Definition: grid_cli.hpp:224
@ eJobStatus
Definition: grid_cli.hpp:219
@ eQueueArg
Definition: grid_cli.hpp:233
@ eReportProgress
Definition: grid_cli.hpp:262
@ eDumpNSNotifications
Definition: grid_cli.hpp:272
@ eFailJob
Definition: grid_cli.hpp:232
@ eCacheable
Definition: grid_cli.hpp:188
@ eNoConnRetries
Definition: grid_cli.hpp:160
@ eLimit
Definition: grid_cli.hpp:203
@ eNoDNSLookup
Definition: grid_cli.hpp:257
@ eJobOutputBlob
Definition: grid_cli.hpp:201
@ eAppUID
Definition: grid_cli.hpp:154
@ eInputFile
Definition: grid_cli.hpp:164
@ eDrain
Definition: grid_cli.hpp:245
@ eNotificationInfo
Definition: grid_cli.hpp:213
@ eAttrValue
Definition: grid_cli.hpp:156
@ eAttrName
Definition: grid_cli.hpp:155
@ eDebugConsole
Definition: grid_cli.hpp:271
@ eAnyAffinity
Definition: grid_cli.hpp:198
@ eAffinityList
Definition: grid_cli.hpp:195
@ eClaimNewAffinities
Definition: grid_cli.hpp:197
@ eLoginToken
Definition: grid_cli.hpp:161
@ eJobInputDir
Definition: grid_cli.hpp:247
@ eQueueClasses
Definition: grid_cli.hpp:235
@ eClientNode
Definition: grid_cli.hpp:266
@ eRemoteAppStdOut
Definition: grid_cli.hpp:167
@ eJobId
Definition: grid_cli.hpp:210
@ eOutputFormat
Definition: grid_cli.hpp:170
@ eNetCache
Definition: grid_cli.hpp:171
@ eAuthToken
Definition: grid_cli.hpp:204
@ eNumberOfOptions
Definition: grid_cli.hpp:273
@ eFileTrackToken
Definition: grid_cli.hpp:254
@ eNetStorage
Definition: grid_cli.hpp:181
@ ePassword
Definition: grid_cli.hpp:174
@ eAffinity
Definition: grid_cli.hpp:194
@ eProtocolDump
Definition: grid_cli.hpp:270
@ eJobOutputDir
Definition: grid_cli.hpp:248
@ eQueueClass
Definition: grid_cli.hpp:238
@ eCompatMode
Definition: grid_cli.hpp:246
@ eTargetQueueArg
Definition: grid_cli.hpp:236
@ eBrief
Definition: grid_cli.hpp:221
@ eTTL
Definition: grid_cli.hpp:177
@ eMovable
Definition: grid_cli.hpp:187
@ eJobGroupInfo
Definition: grid_cli.hpp:211
@ eNetSchedule
Definition: grid_cli.hpp:190
@ eInput
Definition: grid_cli.hpp:163
@ eSize
Definition: grid_cli.hpp:176
@ ePersistent
Definition: grid_cli.hpp:185
@ eRemoteAppStdErr
Definition: grid_cli.hpp:168
@ eNoServerCheck
Definition: grid_cli.hpp:261
@ eErrorMessage
Definition: grid_cli.hpp:209
@ eJobCount
Definition: grid_cli.hpp:218
@ eExtendedOptionDelimiter
Definition: grid_cli.hpp:264
@ eNamespace
Definition: grid_cli.hpp:184
@ eOptionalID
Definition: grid_cli.hpp:152
@ eJobsByStatus
Definition: grid_cli.hpp:216
@ eCacheArg
Definition: grid_cli.hpp:173
@ eConfirmRead
Definition: grid_cli.hpp:206
@ eUntypedArg
Definition: grid_cli.hpp:151
@ eServiceName
Definition: grid_cli.hpp:256
@ eExtendLifetime
Definition: grid_cli.hpp:227
@ eAggregationInterval
Definition: grid_cli.hpp:251
@ eEnableMirroring
Definition: grid_cli.hpp:178
@ eOptionalNCID
Definition: grid_cli.hpp:259
@ eNow
Definition: grid_cli.hpp:243
@ eActiveJobCount
Definition: grid_cli.hpp:215
@ eExclusiveJob
Definition: grid_cli.hpp:199
@ eOutputFile
Definition: grid_cli.hpp:169
@ eTryAllServers
Definition: grid_cli.hpp:179
@ eQueue
Definition: grid_cli.hpp:191
@ eWaitForJobEventAfter
Definition: grid_cli.hpp:226
@ eAllQueues
Definition: grid_cli.hpp:234
@ eJobOutput
Definition: grid_cli.hpp:200
@ eDumpCGIEnv
Definition: grid_cli.hpp:249
@ eUsePreferredAffinities
Definition: grid_cli.hpp:196
@ eUseCompoundID
Definition: grid_cli.hpp:180
@ eDumpCGIStdIn
Definition: grid_cli.hpp:250
@ eWorkerNode
Definition: grid_cli.hpp:192
@ ePullback
Definition: grid_cli.hpp:241
@ eBatch
Definition: grid_cli.hpp:193
@ eProgressMessage
Definition: grid_cli.hpp:228
@ eOffset
Definition: grid_cli.hpp:175
@ eClientInfo
Definition: grid_cli.hpp:212
@ eFileTrackSite
Definition: grid_cli.hpp:253
@ eQueueClassArg
Definition: grid_cli.hpp:237
@ eObjectKey
Definition: grid_cli.hpp:182
@ eMirror
Definition: grid_cli.hpp:255
@ eUserKey
Definition: grid_cli.hpp:183
@ eAllJobs
Definition: grid_cli.hpp:230
@ eJobGroup
Definition: grid_cli.hpp:229
@ eStatusOnly
Definition: grid_cli.hpp:222
#define USER_KEY_OPTION
Definition: grid_cli.hpp:75
#define ATTR_VALUE_ARG
Definition: grid_cli.hpp:127
#define ALL_QUEUES_OPTION
Definition: grid_cli.hpp:107
#define LOGIN_TOKEN_NETSCHEDULE_FIELD
Definition: grid_cli.hpp:59
#define LOGIN_TOKEN_APP_UID_FIELD
Definition: grid_cli.hpp:52
#define DIRECT_MODE_OPTION
Definition: grid_cli.hpp:124
#define NAMESPACE_OPTION
Definition: grid_cli.hpp:76
#define WAIT_TIMEOUT_OPTION
Definition: grid_cli.hpp:105
#define SIZE_OPTION
Definition: grid_cli.hpp:122
#define READJOB_COMMAND
Definition: grid_cli.hpp:131
#define CLAIM_NEW_AFFINITIES_OPTION
Definition: grid_cli.hpp:90
#define NETCACHE_OPTION
Definition: grid_cli.hpp:70
#define INPUT_OPTION
Definition: grid_cli.hpp:83
#define JOB_INPUT_DIR_OPTION
Definition: grid_cli.hpp:117
#define BATCH_OPTION
Definition: grid_cli.hpp:88
#define LIMIT_OPTION
Definition: grid_cli.hpp:94
#define ROLLBACK_READ_OPTION
Definition: grid_cli.hpp:98
const CNcbiEnvironment & GetEnvironment(void) const
Get the application's cached environment.
int AppMain(int argc, const char *const *argv, const char *const *envp=0, EAppDiagStream diag=eDS_Default, const char *conf=NcbiEmptyCStr, const string &name=NcbiEmptyString)
Main function (entry point) for the NCBI application.
Definition: ncbiapp.cpp:819
void DisableArgDescriptions(TDisableArgDesc disable=fDisableStdArgs)
Definition: ncbiapp.cpp:1306
CNcbiRegistry & GetRWConfig(void)
Get the application's cached configuration parameters, accessible for read-write for an application's...
@ eOn
Definition: ncbi_types.h:111
#define NULL
Definition: ncbistd.hpp:225
void UnsetDiagPostFlag(EDiagPostFlag flag)
Unset the specified flag (globally).
Definition: ncbidiag.cpp:6075
EDiagSev SetDiagPostLevel(EDiagSev post_sev=eDiag_Error)
Set the threshold severity for posting the messages.
Definition: ncbidiag.cpp:6129
void SetDiagUserAndHost(TDiagUserAndHost flags=fDiag_AddUser|fDiag_AddHost)
Set username and hostname properties for the diag context.
TDiagPostFlags SetDiagTraceAllFlags(TDiagPostFlags flags)
Versions of the above for extra trace flags.
Definition: ncbidiag.cpp:6081
void SetDiagTrace(EDiagTrace how, EDiagTrace dflt=eDT_Default)
Set the diagnostic trace settings.
Definition: ncbidiag.cpp:6226
TDiagPostFlags SetDiagPostAllFlags(TDiagPostFlags flags)
Set global post flags to "flags".
Definition: ncbidiag.cpp:6065
@ eDPF_Location
Include class and function if any.
Definition: ncbidiag.hpp:704
@ eDPF_ErrorID
Error code and subcode (default)
Definition: ncbidiag.hpp:698
@ eDPF_OmitInfoSev
No sev. indication if eDiag_Info.
Definition: ncbidiag.hpp:753
@ eDPF_Default
Use global default flags (merge with).
Definition: ncbidiag.hpp:771
@ eDPF_Line
Source line.
Definition: ncbidiag.hpp:695
@ eDPF_File
File name (not full path)
Definition: ncbidiag.hpp:693
@ eDPF_LongFilename
Full file path.
Definition: ncbidiag.hpp:694
@ eDPF_All
All flags (except for the "unusual" ones!)
Definition: ncbidiag.hpp:718
@ eDT_Enable
Enable messages of severity "eDiag_Trace".
Definition: ncbidiag.hpp:1550
@ eDiag_Trace
Trace message.
Definition: ncbidiag.hpp:657
#define NCBI_USER_THROW_FMT(message)
Throw a "user exception" with message processed as output to ostream.
Definition: ncbiexpt.hpp:724
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
string ReportThis(TDiagPostFlags flags=eDPF_Exception) const
Report this exception only.
Definition: ncbiexpt.cpp:397
#define NCBI_THROW_FMT(exception_class, err_code, message)
The same as NCBI_THROW but with message processed as output to ostream.
Definition: ncbiexpt.hpp:719
virtual bool Remove(TRemoveFlags flags=eRecursive) const
Remove a directory entry.
Definition: ncbifile.cpp:2595
EJobStatus
Job status codes.
static ENetScheduleWarningType ExtractWarningType(string &warn_msg)
static const char * WarningTypeToString(ENetScheduleWarningType warning_type)
static EJobStatus StringToStatus(const CTempString &status_str)
Parse status string into enumerator value.
@ eJobNotFound
No such job.
@ fNST_NoMetaData
Do not use NetStorage relational database to track ownership & changes.
Definition: netstorage.hpp:140
@ fNST_Persistent
Definition: netstorage.hpp:135
@ fNST_Cacheable
Has no effect at the moment.
Definition: netstorage.hpp:139
@ fNST_Fast
Definition: netstorage.hpp:134
@ fNST_Movable
Allow the object to move between storages.
Definition: netstorage.hpp:138
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
virtual bool HasEntry(const string &section, const string &name=kEmptyStr, TFlags flags=0) const
Definition: ncbireg.cpp:290
bool Set(const string &section, const string &name, const string &value, TFlags flags=0, const string &comment=kEmptyStr)
Set the configuration parameter value.
Definition: ncbireg.cpp:826
#define NcbiCin
Definition: ncbistre.hpp:542
#define NcbiCerr
Definition: ncbistre.hpp:544
#define kEmptyStr
Definition: ncbistr.hpp:123
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
Definition: ncbistr.cpp:219
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
static size_t StringToSizet(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to size_t.
Definition: ncbistr.cpp:1769
static Uint8 StringToUInt8(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to Uint8.
Definition: ncbistr.cpp:873
static unsigned int StringToUInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to unsigned int.
Definition: ncbistr.cpp:642
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.
Definition: ncbistr.hpp:673
static const char label[]
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
@ eRaw
Definition: types.hpp:81
while(yy_chk[yy_base[yy_current_state]+yy_c] !=yy_current_state)
int i
const TYPE & Get(const CNamedParameterList *param)
int strcmp(const char *str1, const char *str2)
Definition: odbc_utils.hpp:160
@ eVoid
To create a void (uninitialized) instance of a component.
static Format format
Definition: njn_ioutil.cpp:53
#define memmove(a, b, c)
char * strerror(int n)
Definition: pcregrep.c:835
#define NcbiSysChar_putenv
Definition: ncbisys.hpp:167
struct CGridCommandLineInterfaceApp::SOptions::SNCID ncid
char option_flags[eNumberOfOptions]
Definition: grid_cli.hpp:373
const char * name_variants
Definition: grid_cli.cpp:572
const char * synopsis
Definition: grid_cli.cpp:573
int(CGridCommandLineInterfaceApp::* cmd_proc)()
Definition: grid_cli.cpp:571
int options[eNumberOfOptions+1]
Definition: grid_cli.cpp:575
int output_formats[eNumberOfOutputFormats+1]
Definition: grid_cli.cpp:576
const char * usage
Definition: grid_cli.cpp:574
CCommandLineParser::EOptionType type
Definition: grid_cli.cpp:73
int required_options[2]
Definition: grid_cli.cpp:79
const char * name_variants
Definition: grid_cli.cpp:77
const char * description
Definition: grid_cli.cpp:78
#define _ASSERT
Modified on Fri Apr 12 17:16:36 2024 by modify_doxy.py rev. 669887