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

Go to the SVN repository for this file.

1 #ifndef NETSTORAGE_SERVER__HPP
2 #define NETSTORAGE_SERVER__HPP
3 
4 /* $Id: nst_server.hpp 92137 2020-12-22 16:51:30Z grichenk $
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: Denis Vakatov
30  *
31  * File Description: NetStorage threaded server
32  *
33  */
34 
35 #include <string>
37 #include <connect/server.hpp>
38 
39 
41 #include "nst_precise_time.hpp"
42 #include "nst_alert.hpp"
43 #include "nst_database.hpp"
45 #include "nst_clients.hpp"
46 #include "nst_users.hpp"
47 
48 
50 
51 
53 
54 
55 class CNetStorageServer : public CServer
56 {
57 public:
59  virtual ~CNetStorageServer();
60 
63  bool reconfigure);
64 
65  virtual bool ShutdownRequested(void);
66  void SetShutdownFlag(int signum = 0);
67 
68  const bool & IsLog() const
69  { return m_Log; }
70  bool IsLogTimingNSTAPI() const
71  { return m_LogTimingNSTAPI; }
73  { return m_LogTimingClientSocket; }
74 
75  unsigned int GetNetworkTimeout(void) const
76  { return m_NetworkTimeout; }
77  unsigned short GetPort() const
78  { return m_Port; }
79  unsigned int GetHostNetAddr() const
80  { return m_HostNetAddr; }
81  const CNSTPreciseTime & GetStartTime(void) const
82  { return m_StartTime; }
83  string GetSessionID(void) const
84  { return m_SessionID; }
85  void SaveCommandLine(const string & cmd_line)
86  { m_CommandLine = cmd_line; }
87  string GetCommandLine(void) const
88  { return m_CommandLine; }
90  { return m_CompoundIDPool; }
91  string GetRAMConfigFileChecksum(void) const
92  { return m_RAMConfigFileChecksum; }
93  string GetDiskConfigFileChecksum(void) const
94  { return m_DiskConfigFileChecksum; }
95  void SetDiskConfigFileChecksum(const string & checksum)
96  { m_DiskConfigFileChecksum = checksum; }
97  void SetRAMConfigFileChecksum(const string & checksum)
98  { m_RAMConfigFileChecksum = checksum; }
100  { return m_ClientRegistry; }
102  { return m_UserCache; }
105  bool AnybodyCanReconfigure(void) const
106  { return m_AnybodyCanReconfigure; }
108  { return m_BackendConfiguration; }
110  { m_BackendConfiguration = conf; }
111 
112  void UpdateBackendConfiguration(const IRegistry & reg,
113  vector<string> & config_warnings);
114  CJsonNode GetBackendConfDiff(const CJsonNode & conf) const;
115 
116  bool IsAdminClientName(const string & name) const;
117 
118  enum EAlertAckResult AcknowledgeAlert(const string & id,
119  const string & user);
121  const string & user);
122  void RegisterAlert(EAlertType alert_type,
123  const string & messge);
124  CJsonNode SerializeAlerts(void) const;
125  CNSTDatabase & GetDb(void);
126 
127  // Metainfo support
128  EServiceMetadataPresence InMetadataServices(const string & service) const;
129  bool GetServiceTTL(const string & service,
130  TNSTDBValue<CTimeSpan> & ttl) const;
132  const string & service,
133  const TNSTDBValue<Int8> & individual_obj_ttl,
134  TNSTDBValue<CTimeSpan> & prolong_on_read) const;
136  const string & service,
137  const TNSTDBValue<Int8> & individual_obj_ttl,
138  TNSTDBValue<CTimeSpan> & prolong_on_write) const;
139  bool GetServiceProperties(const string & service,
140  CNSTServiceProperties & service_props) const;
142  CJsonNode SerializeMetadataInfo(void) const;
143 
144  void RunServiceThread(void);
145  void StopServiceThread(void);
146 
147  static CNetStorageServer * GetInstance(void);
148 
149 protected:
150  virtual void Exit();
151 
152 private:
153  unsigned short m_Port;
154  unsigned int m_HostNetAddr;
155  mutable bool m_Shutdown;
156  int m_SigNum;
157  bool m_Log;
160  string m_SessionID;
161  unsigned int m_NetworkTimeout;
162  string m_DataPath;
167  unique_ptr<CNSTDatabase> m_Db; // Access to NST attributes DB
168 
170 
171  // Administrators
174 
175  // Metadata services support
177 
180 
183 
186 
188 
190 
191  // Filetrack API keys support - decrypt may fail
192 private:
195 
196 public:
197  void ResetDecryptCacheIfNeed(void);
198  void RegisterNetStorageAPIDecryptError(const string & message);
200 
201  void CheckStartAfterCrash(void);
202  string CreateCrashFlagFile(void);
203  string RemoveCrashFlagFile(void);
204 
205 private:
206  string x_GenerateGUID(void) const;
207  set<string> x_GetAdminClientNames(const string & client_names);
208  CJsonNode x_diffInJson(const vector<string> & added,
209  const vector<string> & deleted) const;
210  string x_GetCrashFlagFileName(void) const;
211  bool x_DoesCrashFlagFileExist(void) const;
212 };
213 
214 
216 
217 #endif
218 
Pool of recycled CCompoundID objects.
CFastMutex –.
Definition: ncbimtx.hpp:667
JSON node abstraction.
CNSTServiceRegistry m_MetadataServiceRegistry
Definition: nst_server.hpp:176
CJsonNode SetParameters(const SNetStorageServerParameters &new_params, bool reconfigure)
Definition: nst_server.cpp:80
string m_DiskConfigFileChecksum
Definition: nst_server.hpp:179
CJsonNode GetBackendConfDiff(const CJsonNode &conf) const
Definition: nst_server.cpp:285
void SetRAMConfigFileChecksum(const string &checksum)
Definition: nst_server.hpp:97
unsigned int m_NetworkTimeout
Definition: nst_server.hpp:161
string GetDiskConfigFileChecksum(void) const
Definition: nst_server.hpp:93
unique_ptr< CNSTDatabase > m_Db
Definition: nst_server.hpp:167
CNSTDatabase & GetDb(void)
Definition: nst_server.cpp:401
CCompoundIDPool m_CompoundIDPool
Definition: nst_server.hpp:165
CJsonNode x_diffInJson(const vector< string > &added, const vector< string > &deleted) const
Definition: nst_server.cpp:490
bool AnybodyCanReconfigure(void) const
Definition: nst_server.hpp:105
unsigned short m_Port
Definition: nst_server.hpp:153
void ResetDecryptCacheIfNeed(void)
Definition: nst_server.cpp:237
CNSTUserCache m_UserCache
Definition: nst_server.hpp:185
string x_GetCrashFlagFileName(void) const
Definition: nst_server.cpp:515
virtual ~CNetStorageServer()
Definition: nst_server.cpp:68
CNSTPreciseTime m_StartTime
Definition: nst_server.hpp:163
void RunServiceThread(void)
Definition: nst_server.cpp:471
enum EAlertAckResult AcknowledgeAlert(const string &id, const string &user)
Definition: nst_server.cpp:374
CRef< CNetStorageServiceThread > m_ServiceThread
Definition: nst_server.hpp:182
string GetSessionID(void) const
Definition: nst_server.hpp:83
unsigned int GetNetworkTimeout(void) const
Definition: nst_server.hpp:75
void RegisterNetStorageAPIDecryptError(const string &message)
Definition: nst_server.cpp:251
void SetAnybodyCanReconfigure(bool val)
Definition: nst_server.hpp:103
bool x_DoesCrashFlagFileExist(void) const
Definition: nst_server.cpp:521
bool m_AnybodyCanReconfigure
Definition: nst_server.hpp:187
void AddDefaultListener(IServer_ConnectionFactory *factory)
Definition: nst_server.cpp:73
void SaveCommandLine(const string &cmd_line)
Definition: nst_server.hpp:85
unsigned short GetPort() const
Definition: nst_server.hpp:77
bool m_NeedDecryptCacheReset
Definition: nst_server.hpp:193
CJsonNode SerializeAlerts(void) const
Definition: nst_server.cpp:395
void ReportNetStorageAPIDecryptSuccess(void)
Definition: nst_server.cpp:259
void RegisterAlert(EAlertType alert_type, const string &messge)
Definition: nst_server.cpp:388
CNSTClientRegistry & GetClientRegistry(void)
Definition: nst_server.hpp:99
CNSTAlerts m_Alerts
Definition: nst_server.hpp:166
virtual void Exit()
Cleanup the server.
Definition: nst_server.cpp:232
string m_RAMConfigFileChecksum
Definition: nst_server.hpp:178
bool IsAdminClientName(const string &name) const
Definition: nst_server.cpp:354
CJsonNode GetBackendConfiguration(void) const
Definition: nst_server.hpp:107
void StopServiceThread(void)
Definition: nst_server.cpp:479
static CNetStorageServer * GetInstance(void)
Definition: nst_server.cpp:226
string CreateCrashFlagFile(void)
Definition: nst_server.cpp:603
set< string > m_AdminClientNames
Definition: nst_server.hpp:173
virtual bool ShutdownRequested(void)
Runs synchronously between iterations.
Definition: nst_server.cpp:211
const CNSTPreciseTime & GetStartTime(void) const
Definition: nst_server.hpp:81
CFastMutex m_AdminClientNamesLock
Definition: nst_server.hpp:172
void CheckStartAfterCrash(void)
Definition: nst_server.cpp:527
void SetBackendConfiguration(const CJsonNode &conf)
Definition: nst_server.hpp:109
set< string > x_GetAdminClientNames(const string &client_names)
Definition: nst_server.cpp:365
CNSTPreciseTime m_LastDecryptCacheReset
Definition: nst_server.hpp:194
bool m_LogTimingClientSocket
Definition: nst_server.hpp:159
EServiceMetadataPresence InMetadataServices(const string &service) const
Definition: nst_server.cpp:412
string GetRAMConfigFileChecksum(void) const
Definition: nst_server.hpp:91
bool GetServiceProperties(const string &service, CNSTServiceProperties &service_props) const
Definition: nst_server.cpp:448
bool GetServiceTTL(const string &service, TNSTDBValue< CTimeSpan > &ttl) const
Definition: nst_server.cpp:418
CJsonNode m_BackendConfiguration
Definition: nst_server.hpp:189
string GetCommandLine(void) const
Definition: nst_server.hpp:87
static CNetStorageServer * sm_netstorage_server
Definition: nst_server.hpp:169
CJsonNode ReadMetadataConfiguration(const IRegistry &reg)
Definition: nst_server.cpp:457
string x_GenerateGUID(void) const
Definition: nst_server.cpp:265
unsigned int m_HostNetAddr
Definition: nst_server.hpp:154
string RemoveCrashFlagFile(void)
Definition: nst_server.cpp:625
CCompoundIDPool GetCompoundIDPool(void) const
Definition: nst_server.hpp:89
CNSTClientRegistry m_ClientRegistry
Definition: nst_server.hpp:184
void SetDiskConfigFileChecksum(const string &checksum)
Definition: nst_server.hpp:95
bool IsLogTimingClientSocket() const
Definition: nst_server.hpp:72
const bool & IsLog() const
Definition: nst_server.hpp:68
bool GetServiceProlongOnRead(const string &service, const TNSTDBValue< Int8 > &individual_obj_ttl, TNSTDBValue< CTimeSpan > &prolong_on_read) const
Definition: nst_server.cpp:426
bool IsLogTimingNSTAPI() const
Definition: nst_server.hpp:70
CJsonNode SerializeMetadataInfo(void) const
Definition: nst_server.cpp:464
CNSTUserCache & GetUserCache(void)
Definition: nst_server.hpp:101
void SetShutdownFlag(int signum=0)
Definition: nst_server.cpp:217
unsigned int GetHostNetAddr() const
Definition: nst_server.hpp:79
void UpdateBackendConfiguration(const IRegistry &reg, vector< string > &config_warnings)
Definition: nst_server.cpp:276
bool GetServiceProlongOnWrite(const string &service, const TNSTDBValue< Int8 > &individual_obj_ttl, TNSTDBValue< CTimeSpan > &prolong_on_write) const
Definition: nst_server.cpp:437
CServer::
Definition: server.hpp:97
IRegistry –.
Definition: ncbireg.hpp:73
IServer_ConnectionFactory::
Definition: server.hpp:388
Declarations of CCompoundIDPool, CCompoundID, and CCompoundIDField.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
T signum(T x_)
EAlertAckResult
Definition: ns_alert.hpp:63
EAlertType
Definition: ns_alert.hpp:46
EServiceMetadataPresence
Framework to create multithreaded network servers with thread-per-request scheduling.
Modified on Mon Apr 22 04:02:56 2024 by modify_doxy.py rev. 669887