51 virtual void Init(
void);
52 virtual int Run(
void);
61 return "SampleNodeClient version 1.0.1";
66 void ShowBlob(
const string& blob_key);
82 arg_desc->SetUsageContext(
GetArguments().GetProgramBasename(),
83 "Remote app client sample");
85 arg_desc->AddOptionalKey(
"jobs",
87 "Number of jobs to submit",
90 arg_desc->AddOptionalKey(
"jobinfo",
95 arg_desc->AddOptionalKey(
"showblob",
108 "!====================================================================================================!";
109 const size_t kDataSize = strlen(kData);
113 if (args[
"showblob"]) {
114 ShowBlob(args[
"showblob"].AsString());
120 if (args[
"jobinfo"]) {
125 int jobs_number = 10;
127 jobs_number = args[
"jobs"].AsInteger();
130 cout <<
"Submitting jobs..." << jobs_number << endl;
132 typedef list<string> TJobKeys;
136 for (
int i = 0;
i < jobs_number; ++
i) {
140 os.write(kData, kDataSize);
141 os << endl <<
i << endl;
142 os.write(kData, kDataSize);
143 os.write(kData, kDataSize);
144 os.write(kData, kDataSize);
145 os.write(kData, kDataSize);
147 os <<
"Request data";
159 job_keys.push_back(grid_client.
Submit());
161 cout << endl <<
"Done." << endl;
163 cout <<
"Waiting for jobs..." << endl;
166 TJobKeys failed_jobs;
168 unsigned int cnt = 0;
172 typedef list<TJobKeys::iterator> TDoneJobs;
175 for(
auto it = job_keys.begin(); it != job_keys.end(); ++it) {
187 cout <<
"Job : " << *it << endl;
188 cout <<
"Return code: " <<
result.GetRetCode() << endl;
189 if (
result.GetRetCode()==-1)
190 failed_jobs.push_back(*it);
191 cout <<
"StdOut : " << endl;
192 cout <<
result.GetStdOut().rdbuf();
194 cout << endl <<
"StdErr : " << endl;
195 cout <<
result.GetStdErr().rdbuf();
197 cout << endl <<
"----------------------" << endl;
198 done_jobs.push_back(it);
203 ERR_POST(
"Job " << *it <<
" failed : "
205 failed_jobs.push_back(*it);
206 done_jobs.push_back(it);
212 done_jobs.push_back(it);
215 for (
const auto& job : done_jobs) {
218 if (job_keys.empty())
222 if (++
cnt % 1000 == 0) {
223 cout <<
"Still waiting..." << endl;
228 <<
"==================== All finished ==================");
229 for (
const auto& job : job_keys) {
239 unique_ptr<CNcbiIstream> is(nc_api.
GetIStream(blob_key));
255 cout <<
"Job : " << job_key << endl;
256 cout <<
"Input : " << grid_client.
GetJobInput() << endl;
257 cout <<
"Output : " << grid_client.
GetJobOutput() << endl;
258 cout <<
"======================================" << endl;
261 cout <<
"Return code: " <<
result.GetRetCode() << endl;
262 cout <<
"StdOut : " << endl;
263 cout <<
result.GetStdOut().rdbuf();
265 cout << endl <<
"StdErr : " << endl;
266 cout <<
result.GetStdErr().rdbuf();
272 ERR_POST(
"Job " << job_key <<
" failed : "
Grid Client (the submitter).
Client API for NetCache server.
virtual int Run(void)
Run the application.
virtual string GetProgramVersion(void) const
Get program version (like: MyProgram v.
virtual bool UseAutomaticCleanup() const
virtual bool UseProgressMessage() const
virtual void Init(void)
If you override this method, do call CGridClientApp::Init() from inside your overriding method.
void ShowBlob(const string &blob_key)
void PrintJobInfo(const string &job_key, CNetCacheAPI::TInstance netcache_api)
Remote Application Request (both client side and application executor side)
void Send(CNcbiOstream &os)
Serialize a request to a given stream.
void AddFileForTransfer(const string &fname, EStdOutErrStorageType tt=eBlobStorage)
Transfer a file to an application executor side.
CNcbiOstream & GetStdIn()
Get an output stream to write data to a remote application stdin.
void SetCmdLine(const string &cmdline)
Set the command line for the remote application.
Remote Application Result (both client side and application executor side)
NetSchedule Framework specs.
NetSchedule Framework specs.
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
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.
virtual void SetupArgDescriptions(CArgDescriptions *arg_desc)
Setup the command line argument descriptions.
const CNcbiArguments & GetArguments(void) const
Get the application's cached unprocessed command-line arguments.
@ eString
An arbitrary string.
@ eInteger
Convertible into an integer number (int or Int8)
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
void Warning(CExceptionArgs_Base &args)
void Info(CExceptionArgs_Base &args)
CNcbiIstream * GetIStream(const string &key, size_t *blob_size=NULL, const CNamedParameterList *optional=NULL)
Create an istream object for reading blob data.
EJobStatus
Job status codes.
const string & GetJobInput()
Get a job's input sting.
void SetJobKey(const string &job_key)
const string & GetErrorMessage()
If something bad has happened this method will return an explanation.
virtual void Init(void)
If you override this method, do call CGridClientApp::Init() from inside your overriding method.
CNetScheduleAPI::EJobStatus GetStatus()
Get a job status.
CNcbiIstream & GetIStream()
Get a stream with a job's result.
string Submit(const string &affinity=kEmptyStr)
Submit a job to the queue.
CNcbiOstream & GetOStream()
Get a stream where a client can write an input data for the remote job.
const string & GetJobOutput()
Get a job's output string.
CGridClient & GetGridClient()
Get a grid client.
@ eDone
Job is ready (computed successfully)
@ eCanceled
Explicitly canceled.
@ eFailed
Failed to run (execution timeout)
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
bool NcbiStreamCopy(CNcbiOstream &os, CNcbiIstream &is)
Copy the entire contents of stream "is" to stream "os".
where both of them are integers Note
void SleepMilliSec(unsigned long ml_sec, EInterruptOnSignal onsignal=eRestartOnSignal)
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Miscellaneous common-use basic types and functionality.
int NcbiSys_main(int argc, ncbi::TXChar *argv[])