37 #include <misc/error_codes.hpp>
42 #define NCBI_USE_ERRCODE_X Misc_GridCgi
54 auto message =
m_Registry->
GetString(
"CGI",
"Exception_Message",
"Some exception was thrown (not shown for safety reasons)");
55 return message.empty() ? what : message;
64 : m_Page(page), m_CgiContext(
ctx), m_NeedRenderPage(
true)
82 const string& name = it->first;
83 const string&
value = it->second;
84 if (!name.empty() && !
value.empty()) {
103 const string& name = it->first;
104 const string&
value = it->second;
105 ret +=
"<INPUT TYPE=\"HIDDEN\" NAME=\"" + name
106 +
"\" VALUE=\"" +
value +
"\">\n";
134 string v = eit->second;
143 string v = eit->second;
200 if (!
config.HasEntry(
"netservice_api",
"error_on_unexpected_reply")) {
201 config.Set(
"netservice_api",
"error_on_unexpected_reply",
"true");
211 bool automatic_cleanup =
238 const string kGridCgiForm =
"<FORM METHOD=\"GET\" ACTION=\"<@SELF_URL@>\">\n"
239 "<@HIDDEN_FIELDS@>\n<@STAT_VIEW@>\n"
254 unique_ptr<CHTMLPage> page;
258 page->AddTagMap(
"VIEW", stat_view);
259 }
catch (exception& e) {
261 <<
" HTML page: " << e.what());
272 if (!job_key.empty()) {
285 bool finished =
false;
290 job_key = grid_client.
Submit();
294 unsigned long sleep_time = 6;
295 unsigned long total_sleep_time = 0;
296 while ( total_sleep_time < wait_time) {
300 total_sleep_time += sleep_time;
301 sleep_time += sleep_time/3;
316 catch (exception& ex) {
329 catch ( exception& ex) {
330 OnJobFailed(exception_message(ex.what()), grid_ctx);
334 page->AddTagMap(
"SELF_URL", self_url);
337 page->AddTagMap(
"HIDDEN_FIELDS", hidden_fields);
341 catch (exception& e) {
343 <<
" HTML page: " << e.what());
353 }
catch (exception& e) {
355 <<
" HTML page: " << e.what());
367 if (!
ctx.GetEntryValue(
"Cancel").empty())
378 "<META HTTP-EQUIV=Refresh "
379 "CONTENT=\"<@REDIRECT_DELAY@>; URL=<@REDIRECT_URL@>\">");
403 bool finished =
false;
404 bool save_result =
false;
Grid CGI Context Context in which a request is processed.
Grid Client (the submitter).
Client API for NetCache server.
Client API for NCBI NetSchedule server.
NetSchedule internal exception.
container_type::const_iterator const_iterator
container_type::iterator iterator
const_iterator begin() const
const_iterator end() const
const_iterator find(const key_type &key) const
The NCBI C++ standard methods for dealing with std::string.
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
const string kGridCgiForm
NetSchedule Framework specs.
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
CNcbiRegistry & GetRWConfig(void)
Get the application's cached configuration parameters, accessible for read-write for an application's...
const CCgiResponse & GetResponse(void) const
const CCgiRequest & GetRequest(void) const
void Init(void) override
This method is called on the CGI application initialization – before starting to process a HTTP reque...
void SetRequestId(const string &rid, bool is_done)
const string & GetSelfURL(ESelfUrlPort) const
Using HTTP environment variables, compose the CGI's own URL as: SCHEME://SERVER_NAME[:SERVER_PORT]/SC...
const TCgiEntries & GetEntries(void) const
Get a set of entries(decoded) received from the client.
static SIZE_TYPE ParseEntries(const string &str, TCgiEntries &entries)
Decode the URL-encoded(FORM or ISINDEX) string "str" into a set of entries <"name",...
void SetHeaderValue(const string &name, const string &value)
CNcbiOstream & out(void) const
Get output stream. Throw exception if GetOutput() is NULL.
const string & GetProperty(ECgiProp prop) const
Get value of a "standard" property (return empty string if not defined)
CNcbiOstream & WriteHeader(void) const
Write HTTP response header to the output stream.
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
TErrCode GetErrCode(void) const
Get error code.
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
virtual void AddTagMap(const string &name, BaseTagMapper *mapper)
Tag mappers.
CCgiContext & m_CgiContext
TPersistedEntries m_PersistedEntries
CNcbiRegistry * m_Registry
EJobStatus
Job status codes.
TCgiEntries m_ParsedQueryString
virtual void OnJobCanceled(CGridCgiContext &)
This method is called if job was canceled during its execution.
void SetJobProgressMessage(const string &msg)
CNetScheduleSubmitter GetSubmitter()
Create an instance of CNetScheduleSubmitter.
void SetCompleteResponse(CNcbiIstream &is)
virtual void PrepareJobData(CGridClient &grid_client)=0
This method is called when a job is ready to be send to a the queue.
void DefinePersistentEntry(const string &entry_name, const string &value)
void PullUpPersistentEntry(const string &entry_name)
Save this entry as a cookie add it to serf url.
void Clear()
Remove all persisted entries from cookie and self url.
const string & GetJobInput()
Get a job's input sting.
void SetJobInput(const string &input)
bool x_JobStopRequested(const CGridCgiContext &) const
virtual void Init(void)
This method is called on the CGI application initialization – before starting to process a HTTP reque...
virtual void OnQueueIsBusy(CGridCgiContext &)
This method is call when a job couldn't be submitted because of NetSchedule queue is full.
const string & GetEntryValue(const string &entry_name) const
Get a value from a CGI request.
void SetJobKey(const string &job_key)
virtual int ProcessRequest(CCgiContext &ctx)
Do not override this method yourself! – it includes all the GRIDCGI specific machinery.
virtual void OnBeginProcessRequest(CGridCgiContext &)
This method is call at the very beginning of the request processing.
virtual bool JobStopRequested(void) const
When job is still running this method is called to check if cancel has been requested via the user in...
const string & GetErrorMessage()
If something bad has happened this method will return an explanation.
CNetScheduleAPI::EJobStatus GetStatus()
Get a job status.
virtual string GetPageTitle(void) const =0
Return page name.
CCgiContext & GetCGIContext()
Get CGI Context.
virtual void OnJobPending(CGridCgiContext &)
This method is call when a job is in NetSchedule queue and is waiting for a worker node.
virtual void OnJobDone(CGridClient &grid_client, CGridCgiContext &ctx)=0
This method is call when a worker node finishes its job and result is ready to be retrieved.
bool x_CheckJobStatus(CGridCgiContext &grid_ctx)
unique_ptr< CGridClient > m_GridClient
virtual void ShowParamsPage(CGridCgiContext &ctx) const =0
Show a page with input data.
void InitGridClient()
Initialize grid client.
string GetSelfURL(void) const
Get Self URL.
string GetProgressMessage()
Get a job interim message.
CCgiResponse * m_Response
static string StatusToString(EJobStatus status)
Printable status type.
virtual void OnJobRunning(CGridCgiContext &)
This method is call when a job is taken by a worker node to be processed.
bool NeedRenderPage() const
void RenderRefresh(CHTMLPage &page, const string &url, int delay)
virtual bool CollectParams(CGridCgiContext &ctx)=0
Collect parameters from HTML form If this method returns false that means that input parameters were ...
void CancelJob(const string &job_key)
Cancel Job.
void SetJobKey(const string &job_key)
string Submit(const string &affinity=kEmptyStr)
Submit a job to the queue.
const string & GetJobKey(void) const
Get Current job key.
CGridClient & GetGridClient(void)
Get a Grid Client.
virtual void OnJobSubmitted(CGridCgiContext &)
This method is called just after a job has been submitted.
virtual void OnJobFailed(const string &, CGridCgiContext &)
This method is called when worker node reported a failure.
virtual string GetProgramVersion(void) const =0
Get program version (like: MyProgram v.
const string & GetJobOutput()
Get a job's output string.
void SetProgramVersion(const string &pv)
Set program version (like: MyProgram v.
virtual void OnEndProcessRequest(CGridCgiContext &)
This method is call at the very end of the request processing.
void SetJobOutput(const string &output)
CNetScheduleAPI m_NSClient
virtual string GetPageTemplate(void) const =0
Return a name of a file this HTML page template.
string GetHiddenFields() const
virtual bool IsCachingNeeded(const CCgiRequest &request) const
CNetCacheAPI m_NetCacheAPI
CGridCgiContext(CHTMLPage &page, CCgiContext &ctx)
@ eDone
Job is ready (computed successfully)
@ eCanceled
Explicitly canceled.
@ eRunning
Running on a worker node.
@ eJobNotFound
No such job.
@ ePending
Waiting for execution.
@ eFailed
Failed to run (execution timeout)
virtual bool GetBool(const string §ion, const string &name, bool default_value, TFlags flags=0, EErrAction err_action=eThrow) const
Get boolean value of specified parameter name.
virtual int GetInt(const string §ion, const string &name, int default_value, TFlags flags=0, EErrAction err_action=eThrow) const
Get integer value of specified parameter name.
virtual string GetString(const string §ion, const string &name, const string &default_value, TFlags flags=0) const
Get the parameter string value.
@ eReturn
Return default value.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
static string URLEncode(const CTempString str, EUrlEncode flag=eUrlEnc_SkipMarkChars)
URL-encode string.
const GenericPointer< typename T::ValueType > T2 value
void SleepMilliSec(unsigned long ml_sec, EInterruptOnSignal onsignal=eRestartOnSignal)
SExceptionMessage(CNcbiRegistry *registry=nullptr)
string operator()(const string &what)
static wxAcceleratorEntry entries[3]