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

Go to the SVN repository for this file.

1 #ifndef CONNECT_SERVICES___GRID_GLOBALS__HPP
2 #define CONNECT_SERVICES___GRID_GLOBALS__HPP
3 
4 /* $Id: grid_globals.hpp 84368 2018-11-05 16:55:15Z sadyrovr $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Maxim Didenko, Dmitry Kazimirov
30  *
31  */
32 
35 
36 #include <corelib/ncbimisc.hpp>
37 
38 
40 
41 
42 /// Grid worker global varialbles
43 ///
44 /// @sa CNetScheduleAPI
45 ///
46 
47 
48 /// @internal
49 class CGridGlobals;
51 {
52 public:
53  CWNJobWatcher();
54  virtual ~CWNJobWatcher();
55 
56  virtual void Notify(const CWorkerNodeJobContext& job, EEvent event);
57 
58  void Print(CNcbiOstream& os) const;
59  unsigned GetJobsRunningNumber() const
60  { return (unsigned) m_ActiveJobs.size(); }
61 
62  void SetMaxJobsAllowed(unsigned int max_jobs_allowed)
63  { m_MaxJobsAllowed = max_jobs_allowed; }
64  void SetMaxFailuresAllowed(unsigned int max_failures_allowed)
65  { m_MaxFailuresAllowed = max_failures_allowed; }
66  void SetInfiniteLoopTime(unsigned int infinite_loop_time)
67  { m_InfiniteLoopTime = infinite_loop_time; }
68 
69 
70  void CheckForInfiniteLoop();
71 
72 private:
73  unsigned int m_JobsStarted;
74  unsigned int m_JobsSucceeded;
75  unsigned int m_JobsFailed;
76  unsigned int m_JobsReturned;
77  unsigned int m_JobsRescheduled;
78  unsigned int m_JobsCanceled;
79  unsigned int m_JobsLost;
80  unsigned int m_MaxJobsAllowed;
81  unsigned int m_MaxFailuresAllowed;
82  unsigned int m_InfiniteLoopTime;
83  struct SJobActivity {
85  bool is_stuck;
86  SJobActivity(CStopWatch et, bool is) : elasped_time(et), is_stuck(is) {}
87  SJobActivity() : elasped_time(CStopWatch(CStopWatch::eStart)), is_stuck(false) {}
88  };
89 
93 
94  friend class CGridGlobals;
95  void x_KillNode(CGridWorkerNode);
96 
97 private:
100 };
101 
102 
103 /// @internal
105 {
106 public:
107  CGridGlobals();
108  ~CGridGlobals();
109 
110  static CGridGlobals& GetInstance();
111 
112  unsigned int GetNewJobNumber();
113 
114  bool ReuseJobObject() const {return m_ReuseJobObject;}
115  void SetReuseJobObject(bool value) {m_ReuseJobObject = value;}
116  void SetWorker(SGridWorkerNodeImpl* worker) {m_Worker = worker;}
117  void SetUDPPort(unsigned short udp_port) {m_UDPPort = udp_port;}
118 
119  /// Request node shutdown
121  {
122  m_ShutdownLevel = level;
123  InterruptUDPPortListening();
124  }
126  int exit_code)
127  {
128  m_ShutdownLevel = level;
129  m_ExitCode = exit_code;
130  InterruptUDPPortListening();
131  }
132  bool IsShuttingDown();
133 
134  /// Check if shutdown was requested.
135  ///
137  { return m_ShutdownLevel; }
138 
139  void SetExitCode(int exit_code) { m_ExitCode = exit_code; }
140  int GetExitCode() const { return m_ExitCode; }
141 
142  CWNJobWatcher& GetJobWatcher();
143 
144  const CTime& GetStartTime() const { return m_StartTime; }
145 
146  void KillNode();
147 
148  void InterruptUDPPortListening();
149 
150 private:
153 
155  volatile int m_ExitCode;
156  unique_ptr<CWNJobWatcher> m_JobWatcher;
159  unsigned short m_UDPPort;
160 
163 };
164 
166 {
168 }
169 
171 
172 #endif // CONNECT_SERVICES___GRID_GLOBALS__HPP
CAtomicCounter_WithAutoInit –.
Definition: ncbicntr.hpp:120
CGridGlobals(const CGridGlobals &)
volatile int m_ExitCode
void RequestShutdown(CNetScheduleAdmin::EShutdownLevel level, int exit_code)
void SetWorker(SGridWorkerNodeImpl *worker)
CNetScheduleAdmin::EShutdownLevel GetShutdownLevel(void)
Check if shutdown was requested.
CGridGlobals & operator=(const CGridGlobals &)
CAtomicCounter_WithAutoInit m_JobsStarted
const CTime m_StartTime
unsigned short m_UDPPort
void SetUDPPort(unsigned short udp_port)
void SetExitCode(int exit_code)
bool IsShuttingDown()
void RequestShutdown(CNetScheduleAdmin::EShutdownLevel level)
Request node shutdown.
void SetReuseJobObject(bool value)
SGridWorkerNodeImpl * m_Worker
volatile CNetScheduleAdmin::EShutdownLevel m_ShutdownLevel
unique_ptr< CWNJobWatcher > m_JobWatcher
int GetExitCode() const
const CTime & GetStartTime() const
bool ReuseJobObject() const
Grid Worker Node.
CMutex –.
Definition: ncbimtx.hpp:749
EShutdownLevel
Shutdown level.
@ eNoShutdown
No Shutdown was requested.
CStopWatch –.
Definition: ncbitime.hpp:1937
CTime –.
Definition: ncbitime.hpp:296
CMutex m_ActiveJobsMutex
CWNJobWatcher & operator=(const CWNJobWatcher &)
map< CWorkerNodeJobContext *, SJobActivity > TActiveJobs
void SetInfiniteLoopTime(unsigned int infinite_loop_time)
unsigned int m_JobsStarted
void SetMaxFailuresAllowed(unsigned int max_failures_allowed)
unsigned int m_MaxFailuresAllowed
unsigned int m_InfiniteLoopTime
unsigned int m_JobsLost
unsigned int m_JobsFailed
CWNJobWatcher(const CWNJobWatcher &)
unsigned int m_JobsRescheduled
unsigned int m_JobsSucceeded
unsigned int m_JobsCanceled
unsigned int m_JobsReturned
unsigned GetJobsRunningNumber() const
unsigned int m_MaxJobsAllowed
void SetMaxJobsAllowed(unsigned int max_jobs_allowed)
TActiveJobs m_ActiveJobs
Worker Node job context.
Jobs watcher interface.
void Print(const CCompactSAMApplication::AlignInfo &ai)
#define false
Definition: bool.h:36
Grid Framework specs.
virtual void Notify(const CWorkerNodeJobContext &job, EEvent event)=0
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define NCBI_XCONNECT_EXPORT
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Miscellaneous common-use basic types and functionality.
NetSchedule client specs.
SJobActivity(CStopWatch et, bool is)
Modified on Tue May 07 08:16:26 2024 by modify_doxy.py rev. 669887