summaryrefslogtreecommitdiffstats
path: root/rasmgr/rasmgr_srv.hh
blob: 2e67520afb0c93d9a16fcd44cbff8c84030d81cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
/
/**
 * SOURCE: rasmgr_srv.hh
 *
 * MODULE: rasmgr
 * CLASS:  RasServer, RasServerManager
 *
 * COMMENTS:
 *   		None
 *
*/

#ifndef RASMGR_SRV_HH
#define RASMGR_SRV_HH

#include "rasmgr.hh"
#include "rasmgr_config.hh"
#include "rasmgr_host.hh"
#include "rasmgr_dbm.hh"

//#define RASEXECUTABLE "rst"
#define RASEXECUTABLE BINDIR"rasserver"
#define MAXREGULARCOUNTER 3

/// return codes
const unsigned int RASSERVER_OK             =  0;
const unsigned int RASSERVER_NODATABASEHOST = -1;
const unsigned int RASSERVER_CANNOTSTARTSRV = -2;
const unsigned int RASSERVER_NOREMOTERASMGR = -3;
const unsigned int RASSERVER_INCOMPLETESEND = -4;
const unsigned int RASSERVER_SRVNOTUP       = -5;
const unsigned int RASSERVER_CMDLINEOFLO    = -6;


/**
  * \ingroup Rasmgrs
  */
class RasServer
  {
    public:
      RasServer();
      ~RasServer();
      void  init(const char *srvName,const char* hostName,char serverType,long listenPort);      
      const char *getName();
      const char *getHostName();
      const char *getHostNetwName();
      long  getPort();
      char  getType();
      void  changeName(const char *newName);
      void  changeType(const char newType); // char not char*!!

      void  changePort(long newPort);
      void  changeExtraParam(const char *extraParam);
      void  changeCountDown(int);
      void  changeAutoRestart(bool);
      const char *getExtraParams();
      int   getCountDown();
      
      bool connectToDBHost(const char *dbHostName);//,const char *connString); 
      bool disconnectFromDBHost(); 
      const char *getDBHostName();
       
      static char* getDescriptionHeader(char *destBuffer);
      char* getDescription(char *destBuffer);
      static char* getDescriptionExecHeader(char *destBuffer);
      char* getDescriptionExec(char *destBuffer);
      static char* getDescriptionPortHeader(char *destBuffer);
      char* getDescriptionPort(char *destBuffer);
      
      int  startServer();
      int  startServerInDebugger(char *command); // test modus only
      
      int  downServer(bool forced);
      int  killServer();

      void changeStatus(int,long);
      bool isUp();
      bool isStarting();	
      bool isValid();
      bool isAvailable();
      	bool forceAvailable();

      bool isConnectedToDBHost();
      bool isAutoRestart();

      void setNotAvailable();
      void startWriteTransaction(Database& dataBase);
      void startReadTransaction(Database& dataBase);
      void changeExecutableName(const char*);
      const char* getExecutableName();
    private:
      int          downNow();
      void         clearPendingTransaction();
      
      char         serverName[ARG_MAX];
      ServerHost   *ptrServerHost;
      bool         isinternal;
      char         serverType;     //'r','h'
      long         listenPort; // 'r' ->rpc prognum; 'h' ->TCP/IP port
      char         extraParam[ARG_MAX];

      char         executableName[ARG_MAX];

      DatabaseHost *ptrDatabaseHost;
      //char         connStr[100];
      
      bool downReq;
      bool available;
      bool isup;
      bool isstarting;
      bool activityExpected; // to avoid the possibility of starting rasserver by hand
      
      int  regularSignalCounter; // how namy times should a nonavailable server signal before we put it available again
      unsigned long activityCounter; // counts "activities" per server, i.e., actions that are noticeable by the server
      
      int  initialCountDown;
      int  currentCountDown;
      int  crashCount;
      bool autorestart;
      
      bool     writeTransaction;
      bool     readTransaction;
      Database *connDatabase;
      
      bool valid;
   };

/**
  * \ingroup Rasmgrs
  */
class RasServerManager
  { 
    public:
      RasServerManager();
      ~RasServerManager();
      bool insertNewServer(const char *srvName,const char* hostName,char serverType,long listenPort);      
      bool removeServer(const char *srvName);
      int  countServers();
      RasServer& operator[](int);
      RasServer& operator[](const char*srvName);
      RasServer& last();
      
      int changeServerStatus(char *reqMessage);
      void disconnectAllServersFromDBH(const char *dbhName);

      int  countUpServers();
      void printStatus();
      bool reset(); // test modus only
      bool acceptChangeName(const char *oldName,const char *newName);
    private:
      bool testUniqueness(const char* srvName);
      list<RasServer> srvList;
      RasServer       protElem;       
   };
   
extern RasServerManager rasManager;

#endif