2008-10-24 23:51:28 +02:00
|
|
|
// dbgrid/request.cpp
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copyright (C) 2008 10gen Inc.
|
2008-12-29 02:28:49 +01:00
|
|
|
*
|
2008-10-24 23:51:28 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
2008-12-29 02:28:49 +01:00
|
|
|
*
|
2008-10-24 23:51:28 +02:00
|
|
|
* This program 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 Affero General Public License for more details.
|
2008-12-29 02:28:49 +01:00
|
|
|
*
|
2008-10-24 23:51:28 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* TODO
|
|
|
|
_ concurrency control.
|
|
|
|
_ connection pool
|
|
|
|
_ hostbyname_nonreentrant() problem
|
|
|
|
_ gridconfig object which gets config from the grid db.
|
|
|
|
connect to iad-sb-grid
|
|
|
|
_ limit() works right?
|
|
|
|
_ KillCursors
|
|
|
|
|
|
|
|
later
|
|
|
|
_ secondary indexes
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2009-02-03 19:30:28 +01:00
|
|
|
#include "../util/message.h"
|
2008-10-24 23:51:28 +02:00
|
|
|
#include "../db/dbmessage.h"
|
2008-11-01 01:17:54 +01:00
|
|
|
#include "../client/connpool.h"
|
2008-10-24 23:51:28 +02:00
|
|
|
#include "../db/commands.h"
|
|
|
|
#include "gridconfig.h"
|
2009-02-04 03:45:27 +01:00
|
|
|
#include "configserver.h"
|
2008-10-24 23:51:28 +02:00
|
|
|
|
2009-01-14 23:09:51 +01:00
|
|
|
namespace mongo {
|
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
extern string ourHostname;
|
2009-02-05 22:45:58 +01:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
namespace dbgrid_cmds {
|
2009-02-05 22:45:58 +01:00
|
|
|
|
|
|
|
// --- internal commands ---
|
2008-10-24 23:51:28 +02:00
|
|
|
|
2009-02-05 22:45:58 +01:00
|
|
|
class GridAdminCmd : public Command {
|
2009-01-15 16:17:11 +01:00
|
|
|
public:
|
2009-02-05 22:45:58 +01:00
|
|
|
GridAdminCmd( const char * n ) : Command( n ){}
|
|
|
|
virtual bool slaveOk(){
|
2009-01-15 16:17:11 +01:00
|
|
|
return true;
|
|
|
|
}
|
2009-02-05 22:45:58 +01:00
|
|
|
virtual bool adminOnly() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class NetStatCmd : public GridAdminCmd {
|
|
|
|
public:
|
|
|
|
NetStatCmd() : GridAdminCmd("netstat") { }
|
|
|
|
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){
|
2009-02-03 23:10:44 +01:00
|
|
|
result.append("griddb", configServer.toString());
|
2009-01-15 16:17:11 +01:00
|
|
|
result.append("isdbgrid", 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} netstat;
|
2009-02-06 22:25:14 +01:00
|
|
|
|
2009-02-05 22:45:58 +01:00
|
|
|
class ListDatabaseCommand : public GridAdminCmd {
|
|
|
|
public:
|
|
|
|
ListDatabaseCommand() : GridAdminCmd("listdatabases") { }
|
|
|
|
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){
|
|
|
|
// TODO
|
|
|
|
result.append("not done", 1);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} gridListDatabase;
|
|
|
|
|
2009-02-06 22:25:14 +01:00
|
|
|
|
|
|
|
class ListServers : public GridAdminCmd {
|
|
|
|
public:
|
|
|
|
ListServers() : GridAdminCmd("listservers") { }
|
|
|
|
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){
|
|
|
|
DBClientWithCommands * conn = configServer.conn();
|
2009-02-05 22:45:58 +01:00
|
|
|
|
2009-02-06 22:25:14 +01:00
|
|
|
vector<BSONObj> all;
|
|
|
|
auto_ptr<DBClientCursor> cursor = conn->query( "grid.servers" , emptyObj );
|
|
|
|
while ( cursor->more() ){
|
|
|
|
BSONObj o = cursor->next();
|
|
|
|
all.push_back( o );
|
|
|
|
}
|
|
|
|
|
|
|
|
result.append("servers" , all );
|
|
|
|
result.append("ok" , 1 );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} listServers;
|
|
|
|
|
|
|
|
|
|
|
|
class AddServer : public GridAdminCmd {
|
|
|
|
public:
|
|
|
|
AddServer() : GridAdminCmd("addserver") { }
|
|
|
|
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){
|
|
|
|
DBClientWithCommands * conn = configServer.conn();
|
|
|
|
|
|
|
|
BSONObj server = BSON( "host" << cmdObj["addserver"].valuestrsafe() );
|
|
|
|
|
|
|
|
BSONObj old = conn->findOne( "grid.servers" , server );
|
|
|
|
if ( ! old.isEmpty() ){
|
|
|
|
result.append( "ok" , 0.0 );
|
|
|
|
result.append( "msg" , "already exists" );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
conn->insert( "grid.servers" , server );
|
|
|
|
result.append( "ok", 1 );
|
|
|
|
result.append( "added" , server["host"].valuestrsafe() );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} listMachines;
|
|
|
|
|
|
|
|
|
2009-02-05 22:45:58 +01:00
|
|
|
// --- public commands ---
|
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
class IsDbGridCmd : public Command {
|
|
|
|
public:
|
|
|
|
virtual bool slaveOk() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
IsDbGridCmd() : Command("isdbgrid") { }
|
|
|
|
bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool) {
|
|
|
|
result.append("isdbgrid", 1);
|
|
|
|
result.append("hostname", ourHostname);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} isdbgrid;
|
2008-10-24 23:51:28 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
class CmdIsMaster : public Command {
|
|
|
|
public:
|
2009-01-19 02:37:17 +01:00
|
|
|
virtual bool requiresAuth() { return false; }
|
2009-01-15 16:17:11 +01:00
|
|
|
virtual bool slaveOk() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
CmdIsMaster() : Command("ismaster") { }
|
|
|
|
virtual bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool) {
|
|
|
|
result.append("ismaster", 0.0);
|
|
|
|
result.append("msg", "isdbgrid");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} ismaster;
|
2008-10-24 23:51:28 +02:00
|
|
|
|
2009-01-15 16:17:11 +01:00
|
|
|
}
|
2009-01-14 23:09:51 +01:00
|
|
|
|
|
|
|
} // namespace mongo
|