summaryrefslogtreecommitdiffstats
path: root/rasmgr/rasmgr_rascontrol_help.cc
blob: 3ed170a49ef78fa451fe967baf52792de394d004 (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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
/*
* 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_rascontrol_help.hh
 *
 * MODULE: rasmgr
 * CLASS:  RasControl
 *
 * PURPOSE:
 *   Decodes, verifies and executes the help commands
 *    
 * COMMENTS:
 *  Logicaly it's part of rasmgr_rascontrol.cc, but compilation unit was split
 *
*/

// this file is a temporary file, used to keep rasmgr_rascontrol things as long as we check each one
// here are the unchecked things!!

#include "debug.hh"
#include "rasmgr_rascontrol.hh"


void RasControl::helpCommand()
  {
    const char *what = argc==1 ? RASMGRCMD_HELP:token[1].take();
    
    if     (strcasecmp(what,RASMGRCMD_LIST)==0)       listHelp();
    else if(strcasecmp(what,RASMGRCMD_DEFINE   )==0)  defineHelp();
    else if(strcasecmp(what,RASMGRCMD_REMOVE)==0)     removeHelp();
    else if(strcasecmp(what,RASMGRCMD_CHANGE)==0)     changeHelp();
    else if(strcasecmp(what,RASMGRCMD_UP)==0)         upHelp();
    else if(strcasecmp(what,RASMGRCMD_DOWN)==0)       downHelp();
    else if(strcasecmp(what,RASMGRCMD_SAVE)==0)       saveHelp();
    else if(strcasecmp(what,RASMGRCMD_CHECK)==0)      checkHelp();
    else if(strcasecmp(what,RASMGRCMD_EXIT)==0)       exitHelp();
    else if(strcasecmp(what,RASMGRCMD_QUIT)==0)       exitHelp();
    else if(strcasecmp(what,RASMGRCMD_BYE)==0)        exitHelp();
    else helpHelp();

    // no help for version and licence - they have no further params
  }
    
    
void RasControl::helpHelp()
  {
    sprintf(answBuffer,"Help for rascontrol command language\r\n"
    		       "rasdaman uses the following terms:\r\n"
		       "  host (server host)    - a computer running a RasManager (rasmgr), with or without currently active servers\r\n"
		       "  srv  (server)         - the rasdaman server (rasserver)\r\n"
		       "  dbh  (data base host) - a computer running the database software\r\n"
		       "  db   (database)       - the rasdaman database, hosted by the underlying database instance\r\n"
		       "  user                  - a person registered by rasdaman through user name and password\r\n"
		       "\r\nThe rascontrol utility allows to configure and do run-time administration work for the rasdaman system\r\n"
                       "Commands:\r\n"
                       "   >help       ...this help\r\n"
                       "   >exit       ...exit rascontrol\r\n"
		       "   >list       ...list information about the current status of the system\r\n"
		       "   >up         ...start servers\r\n"
		       "   >down       ...stop servers and rasmanagers\r\n"
		       "   >define     ...define a new object\r\n"
		       "   >remove     ...remove an object\r\n"
		       "   >change     ...change parameters of objects\r\n"
		       "   >save       ...make changes permanent\r\n"
		       "   >check      ...checks the current status of a slave rasmgr\r\n"
		       "Type 'help command' to get specific information about command\r\n"
		       
		       );
   }

void RasControl::listHelp()         
  {
    checkPermission(admR_info);
    
    sprintf(answBuffer,"   The list command:\r\n"
                       "list srv [ s | -host h | -all ] [-p] \r\n"
    		       "       - list information about 'server s' or 'all servers on host h' or 'all defined servers' (default)\r\n"
    		       "         '-p' prints configuration information; default: runtime status information\r\n"
    		       "list host\r\n"
    		       "       - list information about server hosts\r\n"
    		       "list dbh\r\n"
    		       "       - list information about database hosts\r\n"
    		       "list db [ d | -dbh h | -all ] \r\n"
    		       "       - list information about 'database s' or all 'databases on database host h' or 'all defined databases'\r\n"
    		       "list user [ -rights]\r\n"
    		       "       - list the defined users\r\n"
    		       "         '-rights' additionally lists each user's rights\r\n"
		       "list [ license | licencce ]\r\n"
		       "       - lists license information\r\n"
    		       "list version\r\n"
    		       "       - list version information"
            );
    
   }
   
void RasControl::defineHelp()
  { sprintf(answBuffer,"  The define command:\r\n"
    		       "define dbh 'dbhname' -connect 'connectstring'\r\n"
    		       "       - define database host with symbolic name 'dbhname'\r\n"
    		       "         'connectstring' is the string used to connect a client to the underlying database instance\r\n"
    		       "         (example: user/passwd@hostaddress)\r\n"
    		       "define db 'dbname' -dbh 'dbhname'\r\n"
    		       "       - define database 'dbname' on database host 'dbhname'\r\n"
		       "         ('dbname' is not a symbolic name, it is the real name of the rasdaman database)\r\n"
    		       "define host 'hostname' -net 'netaddress' [-port 'portnumber']\r\n"
    		       "       - define server host with symbolic name 'hostname', located at address 'netaddress:portnumber'\r\n"
    		       "         ('portnumber' defaults to 7001)\r\n"
    		       "define srv 'srvname' -host 'hostname' -dbh 'dbhname' -type 'servertype' -port 'portnumber' \r\n"
		       "                                [-autorestart on|off] [-countdown 'number'] [-xp 'options']\r\n"
    		       "       - define server with symbolic name 'srvname' on server host 'hostname' connected to database host 'dbhname'\r\n"
    		       "         'servertype' can be 'r' (RPC) or 'h' (HTTP) or 'n' (RNP)\r\n"
		       "         'portnumber' is the IP port number for HTTP servers / the 'prognum' for RPC/RNP servers\r\n"           
		       "         -autorestart (default: on): the server will autorestart after an unexpected termination\r\n"           
		       "         -countdown 'number' (default: 1000): the server will be restarted after 'number' transactions\r\n"           
		       "         -xp 'options': extra parameter string 'options' that will be passed to the server at startup \r\n"
		       "          (default: \"\", see documentation for valid 'options')\r\n"
		       "          this option has to be the last, because anything after it and until end of line is considered to be 'options'\r\n"
		       "define user 'username' [-passwd 'password'] [-rights 'rightsstring']\r\n"           
		       "       - define user account with symbolic name 'username'\r\n"           
		       "         'password' defaults to 'username' (use the raspasswd utility to change)\r\n"           
		       "         -rights 'rightsstring': the rights granted to the user (default: none; see documentation for valid rights)\r\n"
	   );
   }
void RasControl::removeHelp()
  {
    sprintf(answBuffer,"   The remove command:\r\n"
		       "remove dbh 'dbhname'\r\n"           
		       "       - remove database host 'dbhname'\r\n"           
		       "remove db 'dbname' -dbh 'dbhname'\r\n"           
		       "       - remove database 'dbname' from database host 'dbhname'\r\n"
		       "         (the database itself is not deleted, only the name is removed from the config tables)\r\n"
		       "remove host 'hostname' \r\n"           
		       "       - remove server host 'hostname'\r\n"           
		       "remove srv 'srvname'\r\n"           
		       "       - remove server 'srvname'\r\n"           
       		       "remove user 'username'\r\n"           
		       "       - remove the user 'username'\r\n"           
	   );
   }
   
void RasControl::changeHelp()
  { sprintf(answBuffer,"   The change command:\r\n"
		       "change dbh 'dbhname' [-name 'newname'] [-connect 'newconnectstring']\r\n"           
		       "change db 'dbname' [-name 'newname']\r\n"           
		       "change host 'hostname' [-name 'newname'] [-net 'newnetaddress'] [-port 'newportnumber']\r\n"           
		       "change srv 'servername' [-name 'newname'][-dbh 'newdbhname'] [-type 'newservertype'] [-port 'newportnumber'] [-autorestart on|off] [-countdown 'newnumber'] [-xp 'newoptions']\r\n"           
		       "change user 'username' [-name 'newname'] [-passwd 'newpasswd] [-rights 'rightsstring']\r\n"           
		       "       - see the help for the define command for option description\r\n"                       
	    
	    );
   }
   
void RasControl::upHelp()
  { sprintf(answBuffer,"   The up command:\r\n"
       		       "up srv [ s | -host h | -all]\r\n"           
		       "       - start 'server s' or 'all servers on host h' or 'all defined servers'\r\n"           
	    );
   }

   
void RasControl::downHelp()
  {sprintf(answBuffer,"   The down command:\r\n"
                       "down srv [ s | -host h | -all] [ -force] [-kill]\r\n"           
		       "       - stops 'server s' or 'all started servers on host h' or 'all started servers'\r\n"
		       "         -force: stops the 'server s' without waiting to complete the current transaction (using SIGTERM)\r\n"           
		       "         -kill:  instantly stops the 'server s' (using SIGKILL)\r\n"
		       "          (without -force or -kill the server completes the current transaction and exits)\r\n"           
                       "down host [ h | -all]\r\n"           
                       "       - stops the rasmgr on 'host h' or all started rasmgr\r\n"
	  );           
   }
      
void RasControl::checkHelp()
  {
    sprintf(answBuffer,"   The check command\r\n"
                       "check host 'hostname'\r\n"
	   	       "        - checks the status of the slave rasmgr located on server host 'hostname'\r\n"
	   	       "        (use this command if the master rasmgr started after the slave rasmgr for synchronising them)\r\n"
	   );
   }

void RasControl::saveHelp()
  {
    sprintf(answBuffer,"   The save command\r\n"
                       "save\r\n"
	   	       "    - saves the current configuration information\r\n"
	   	       "      (upon changes the files will be saved automatically to rescue files next to the config files when exiting rasmgr)\r\n"
	   );
   }
   
void RasControl::exitHelp()
  {
    sprintf(answBuffer,"   The exit command\r\n"
                       "exit | quit | bye\r\n"
	   	       "    - finish this rascontrol session\r\n"
	   );
   }
      

	   
//###       ###########    ############# ################ ##############


/* obsolete in v1.1, but who knows, in future	 
void RasControl::disconnectCommand()
  {
    const char *what = argc==1 ? RASMGRCMD_HELP:token[1].take();
    
    if     (strcasecmp(what,"srv")==0)  disconnectRasServerFromDBH();
    
    else if(strcasecmp(what,"db")==0)   disconnectDatabaseFromDBH();
    
    else if(strcasecmp(what,RASMGRCMD_HELP)==0) disconnectHelp();

    else errorInCommand("Wrong DISCONNECT command");
     
   }
void RasControl::disconnectRasServerFromDBH()
  {
    CHECK(admR_config);

    const char *serverName=getValueOf("srv");
    
    if(!serverName)
      { errorInCommand("Server name missing.");
	return;
       }
    RasServer    &r=rasManager[serverName];
    
    if(!r.isValid())   
      { errorInCommand("Invalid server name.");
        return;
       }
    if(r.isUp())
      { errorInCommand("Cannot disconnet a running server.");
        return;
       }
       
    const char *dbHost=r.getDBHostName();
    
    if(strcasecmp(dbHost,"noDBHost!")!=0)
      { sprintf(answBuffer,"Server %s isn't connected to any database host",serverName);
        return;	
       }
    if(r.disconnectFromDBHost())
      { sprintf(answBuffer,"Disconnecting server %s from database host %s",serverName,dbHost);
       }
    errorInCommand("Internal error during disconnect.");
   }
void RasControl::disconnectDatabaseFromDBH()
  {
    CHECK(admR_config);

    const char *dbName=getValueOf("db");
    
    if(!dbName)
      { errorInCommand("Database name missing.");
	return;
       }
    const char *dbHost=getValueOf("-dbh");
    
    if(!dbHost)
      { errorInCommand("Database host name missing.");
	return;
       }
       
    Database     &r=dbManager[dbName];
    DatabaseHost &d=dbHostManager[dbHost];
    
    if(!r.isValid())   
      { errorInCommand("Invalid database name.");
        return;
       }
    if(!d.isValid())   
      { errorInCommand("Invalid database host name.");
        return;
       }
       
    if(r.disconnectFromDBHost(dbHost))
      { sprintf(answBuffer,"Disconnecting database %s from database host %s",dbName,dbHost);
       }
     else
      { sprintf(answBuffer,"Database %s is not connected to database host %s",dbName,dbHost);
       }	
   }
void RasControl::disconnectHelp()	 
  { 
    sprintf(answBuffer,"Disconnect usage: -sorry, help not available yet");
   }
	 
//--------------------------------------------------------------  

void RasControl::connectCommand()
  {
    const char *what = argc==1 ? RASMGRCMD_HELP:token[1].take();
    
    if     (strcasecmp(what,"srv")==0)  connectRasServerToDBH();
    
    else if(strcasecmp(what,"db")==0)   connectDatabaseToDBH();
    
    else if(strcasecmp(what,RASMGRCMD_HELP)==0) connectHelp();

    else errorInCommand("Wrong CONNECT command");
     
   }
void RasControl::connectRasServerToDBH()
  {
    CHECK(admR_config);

    const char *serverName=getValueOf("srv");
    
    if(!serverName)
      { errorInCommand("Server name missing.");
	return;
       }
    const char *dbHost=getValueOf("-dbh");
    
    if(!dbHost)
      { errorInCommand("Database host name missing.");
	return;
       }
    RasServer    &r=rasManager[serverName];
    DatabaseHost &d=dbHostManager[dbHost];
    
    if(!r.isValid())   
      { errorInCommand("Invalid server name.");
        return;
       }
    if(!d.isValid())   
      { errorInCommand("Invalid database host name.");
        return;
       }
    
   // const char *connStr=getValueOf("-conn");
   // if(!connStr) connStr="\\";
    
    if(r.connectToDBHost(dbHost))//,connStr))
      { sprintf(answBuffer,"Connecting server %s to database host %s",serverName,dbHost);
       }
     else
      { sprintf(answBuffer,"Server %s already connected to database host %s",serverName,dbHost);
       }	
    
   }
void RasControl::connectDatabaseToDBH()
  {
    CHECK(admR_config);
    
    const char *dbName=getValueOf("db");
    
    if(!dbName)
      { errorInCommand("Database name missing.");
	return;
       }
    const char *dbHost=getValueOf("-dbh");
    
    if(!dbHost)
      { errorInCommand("Database host name missing.");
	return;
       }
       
    Database     &r=dbManager[dbName];
    DatabaseHost &d=dbHostManager[dbHost];
    
    if(!r.isValid())   
      { errorInCommand("Invalid database name.");
       }
    if(!d.isValid())   
      { errorInCommand("Invalid database host name.");
       }
       
    if(r.connectToDBHost(dbHost))
      { sprintf(answBuffer,"Connecting database %s to database host %s",dbName,dbHost);
       }
     else
      { sprintf(answBuffer,"Database %s already connected to database host %s",dbName,dbHost);
       }	
   }
void RasControl::connectHelp()	 
  { 
    sprintf(answBuffer,"Connect usage: -sorry, help not available yet");
   }
	 
void RasControl::listRasServersDatabase(const char *dbName)
  {
    CHECK(admR_info);

    if(dbName)
      { sprintf(answBuffer,"List of servers connected to database %s:",dbName);
               
	Database &db = dbManager[dbName];
	if(db.isValid()==false) 
	  { sprintf(answBuffer+strlen(answBuffer),"\r\nNo such database");
	    return;
	   } 
	int crnt=0;
	for(int i=0;i<db.countConnectionsToRasServers();i++)
          { 
	    sprintf(answBuffer+strlen(answBuffer),"\r\n%2d. %s",crnt++,db.getRasServerName(i));
	   } 
       }
    else
      { 
         errorInCommand("Database name missing.");        
       }   	  
   }
   
void RasControl::listRasServersOnDBH(const char *dbhName)
  {
    CHECK(admR_info);
    
    if(dbhName)
      { sprintf(answBuffer,"List of servers connected to database host %s:",dbhName);
               
	int crnt=0;
	for(int i=0;i<rasManager.countServers();i++)
          { 
	    RasServer &r=rasManager[i];
	    if(strcmp(dbhName,r.getDBHostName())!=0) continue;
	     
            sprintf(answBuffer+strlen(answBuffer),"\r\n%2d. %s (%s)",crnt++,r.getName(),r.getHostName());        
	   } 
       }
     else
       { sprintf(answBuffer,"List of servers with connected database host:");
             
         int crnt=0;
	 for(int i=0;i<rasManager.countServers();i++)
           { 
	     RasServer &r=rasManager[i];
	     sprintf(answBuffer+strlen(answBuffer),"\r\n%2d. %-20s %s",crnt++,r.getName(),r.getDBHostName());        
	    } 
	}   	
   }
   
*/
   
   

/* no, out
void RasControl::stopCommand()
  {
    CHECK(admR_sysup);

   // sprintf(answBuffer,RASMGRCMD_EXIT);
   // masterCommunicator.shouldExit();
    if(rasManager.countUpServers()==0) 
      {
        sprintf(answBuffer,RASMGRCMD_EXIT);
	masterCommunicator.shouldExit();
       }
    else
      {
        sprintf(answBuffer,"Please shut down all servers first.");
       }     
   }


void RasControl::listConnections()
  {
    CHECK(admR_info);
    bool full = isFlag("-full");
    
    checkUnexpectedTokens();
    
    int answLen=0;
    int maxAnswLen=MAXMSGOUTBUFF-100; // if there are many servers, we could get an overflow
    
    bool overflow=false;  
    sprintf(answBuffer,"List connections\r\n  Database      Database host         Server");
    for(int i=0;i<dbManager.countDatabases();i++)
      {
        Database&db = dbManager[i];
        const char *dbName = db.getName();
	
	for(int j=0;j<db.countConnectionsToDBHosts();j++)
	  {
	    const char *dbhName = db.getDBHostName(j);
	    const char* writtenDbhName = dbhName;

	    for(int k=0;k < rasManager.countServers();k++)
	      {
	        RasServer &srv = rasManager[k];
		           
	        if(strcmp(srv.getDBHostName(),dbhName) == 0)
		  {
		    int len = strlen(answBuffer);
		    
		    if(len < maxAnswLen)
		      { sprintf(answBuffer+len,"\r\n  %-15s %-20s %-20s",dbName,writtenDbhName,srv.getName());
		        if(full==false) dbName = writtenDbhName ="  -\"-";
		       }
		    else overflow=true;   
		   }
	       }
 	   }
        }
     if(overflow) sprintf(answBuffer+strlen(answBuffer),"\r\n(Answer too long, overflow!)");		        
   }          

*/