Commit 77c905f7 authored by unknown's avatar unknown

removed more duplicated commands for management server

parent ed24ebe6
......@@ -110,7 +110,6 @@ class CommandInterpreter {
void executeRestart(int processId, const char* parameters, bool all);
void executeLogLevel(int processId, const char* parameters, bool all);
void executeError(int processId, const char* parameters, bool all);
void executeTrace(int processId, const char* parameters, bool all);
void executeLog(int processId, const char* parameters, bool all);
void executeLogIn(int processId, const char* parameters, bool all);
void executeLogOut(int processId, const char* parameters, bool all);
......@@ -729,7 +728,6 @@ static const CommandInterpreter::CommandFunctionPair commands[] = {
#ifdef ERROR_INSERT
,{ "ERROR", &CommandInterpreter::executeError }
#endif
,{ "TRACE", &CommandInterpreter::executeTrace }
,{ "LOG", &CommandInterpreter::executeLog }
,{ "LOGIN", &CommandInterpreter::executeLogIn }
,{ "LOGOUT", &CommandInterpreter::executeLogOut }
......@@ -1676,42 +1674,6 @@ void CommandInterpreter::executeError(int processId,
ndb_mgm_insert_error(m_mgmsrv, processId, errorNo, NULL);
}
//*****************************************************************************
//*****************************************************************************
void
CommandInterpreter::executeTrace(int /*processId*/,
const char* /*parameters*/, bool /*all*/)
{
#if 0
if (emptyString(parameters)) {
ndbout << "Missing trace number." << endl;
return;
}
char* newpar = my_strdup(parameters,MYF(MY_WME));
My_auto_ptr<char> ap1(newpar);
char* firstParameter = strtok(newpar, " ");
int traceNo;
if (! convert(firstParameter, traceNo)) {
ndbout << "Expected an integer." << endl;
return;
}
char* allAfterFirstParameter = strtok(NULL, "\0");
if (! emptyString(allAfterFirstParameter)) {
ndbout << "Nothing expected after trace number." << endl;
return;
}
int result = _mgmtSrvr.setTraceNo(processId, traceNo);
if (result != 0) {
ndbout << get_error_text(result) << endl;
}
#endif
}
//*****************************************************************************
//*****************************************************************************
......
......@@ -104,7 +104,6 @@ int CommandInterpreter::readAndExecute() {
int processId;
if (! convert(firstToken, processId)) {
ndbout << "Invalid command: " << _line << "." << endl;
ndbout << "Type HELP for help." << endl << endl;
return true;
}
if (processId < 0) {
......@@ -120,20 +119,9 @@ int CommandInterpreter::readAndExecute() {
static const CommandInterpreter::CommandFunctionPair commands[] = {
{ "START", &CommandInterpreter::executeStart }
,{ "RESTART", &CommandInterpreter::executeRestart }
,{ "STOP", &CommandInterpreter::executeStop }
#ifdef ERROR_INSERT
,{ "ERROR", &CommandInterpreter::executeError }
#endif
,{ "TRACE", &CommandInterpreter::executeTrace }
,{ "LOG", &CommandInterpreter::executeLog }
,{ "LOGIN", &CommandInterpreter::executeLogIn }
{ "LOGIN", &CommandInterpreter::executeLogIn }
,{ "LOGOUT", &CommandInterpreter::executeLogOut }
,{ "LOGOFF", &CommandInterpreter::executeLogOff }
,{ "TESTON", &CommandInterpreter::executeTestOn }
,{ "TESTOFF", &CommandInterpreter::executeTestOff }
,{ "DUMP", &CommandInterpreter::executeDumpState }
};
......@@ -170,16 +158,14 @@ CommandInterpreter::analyseAfterFirstToken(int processId,
if(fun == 0){
ndbout << "Invalid command: " << secondToken << "." << endl;
ndbout << "Type HELP for help." << endl << endl;
return;
}
if(processId == -1){
executeForAll(command, fun, allAfterSecondToken);
} else {
if(strcmp(command, "STATUS") != 0)
ndbout << "Executing " << command << " on node: "
<< processId << endl << endl;
ndbout << "Executing " << command << " on node: "
<< processId << endl << endl;
(this->*fun)(processId, allAfterSecondToken, false);
ndbout << endl;
}
......@@ -190,18 +176,11 @@ CommandInterpreter::executeForAll(const char * cmd, ExecuteFunction fun,
const char * allAfterSecondToken){
NodeId nodeId = 0;
if(strcmp(cmd, "STOP") == 0 ||
strcmp(cmd, "RESTART") == 0){
ndbout << "Executing " << cmd << " on all nodes" << endl << "\n";
while(_mgmtSrvr.getNextNodeId(&nodeId, NDB_MGM_NODE_TYPE_NDB)){
ndbout << "Executing " << cmd << " on node: "
<< nodeId << endl << endl;
(this->*fun)(nodeId, allAfterSecondToken, true);
} else {
while(_mgmtSrvr.getNextNodeId(&nodeId, NDB_MGM_NODE_TYPE_NDB)){
if(strcmp(cmd, "STATUS") != 0)
ndbout << "Executing " << cmd << " on node: "
<< nodeId << endl << endl;
(this->*fun)(nodeId, allAfterSecondToken, true);
ndbout << endl;
} // for
ndbout << endl;
}
}
......@@ -271,233 +250,6 @@ bool CommandInterpreter::parseBlockSpecification(const char* allAfterLog,
return true;
}
//*****************************************************************************
//*****************************************************************************
void
stopCallback(int nodeId, void * anyData, int errCode){
if(errCode == 0){
if(nodeId == 0)
ndbout << "\nCluster has shutdown" << endl;
else
ndbout << "\nNode " << nodeId << " has shutdown" << endl;
} else {
MgmtSrvr * mgm = (MgmtSrvr *)anyData;
char err_str[1024];
ndbout << "Node " << nodeId << " has not shutdown: "
<< mgm->getErrorText(errCode,err_str,sizeof(err_str)) << endl;
}
}
//*****************************************************************************
//*****************************************************************************
void CommandInterpreter::executeStop(int processId,
const char* parameters, bool all) {
(void)parameters; // Don't want compiler warning
int result = 0;
if(all)
result = _mgmtSrvr.stop((int *)0, false, stopCallback, this);
else
result = _mgmtSrvr.stopNode(processId, false, stopCallback, this);
if(result != 0)
ndbout << get_error_text(result) << endl;
}
void CommandInterpreter::executeStart(int processId, const char* parameters,
bool all) {
(void)all; // Don't want compiler warning
if (! emptyString(parameters)) {
ndbout << "No parameters expected to this command." << endl;
return;
}
int result = _mgmtSrvr.start(processId);
if (result != 0) {
ndbout << get_error_text(result) << endl;
}
}
void
CommandInterpreter::executeRestart(int processId, const char* parameters,
bool all) {
bool nostart = false;
bool initialstart = false;
if(parameters != 0 && strlen(parameters) != 0){
char * tmpString = strdup(parameters);
char * tmpPtr = 0;
char * item = strtok_r(tmpString, " ", &tmpPtr);
while(item != NULL){
if(strcmp(item, "-N") == 0)
nostart = true;
if(strcmp(item, "-I") == 0)
initialstart = true;
item = strtok_r(NULL, " ", &tmpPtr);
}
free(tmpString);
}
int result;
if(all)
result = _mgmtSrvr.restart(nostart, initialstart, false,
0, stopCallback, this);
else
result = _mgmtSrvr.restartNode(processId, nostart, initialstart, false,
stopCallback,
this);
if (result != 0) {
ndbout << get_error_text(result) << endl;
}
}
void
CommandInterpreter::executeDumpState(int processId, const char* parameters,
bool all) {
(void)all; // Don't want compiler warning
if(parameters == 0 || strlen(parameters) == 0){
ndbout << "Expected argument" << endl;
return;
}
Uint32 no = 0;
Uint32 pars[25];
char * tmpString = strdup(parameters);
char * tmpPtr = 0;
char * item = strtok_r(tmpString, " ", &tmpPtr);
int error;
while(item != NULL){
if (0x0 <= my_strtoll10(item, NULL, &error) && my_strtoll10(item, NULL, &error) <= 0xffffffff) {
pars[no] = my_strtoll10(item, NULL, &error);
} else {
ndbout << "Illegal value in argument to signal." << endl
<< "(Value must be between 0 and 0xffffffff.)"
<< endl;
return;
}
no++;
item = strtok_r(NULL, " ", &tmpPtr);
}
ndbout << "Sending dump signal with data:" << endl;
for (Uint32 i=0; i<no; i++) {
ndbout.setHexFormat(1) << pars[i] << " ";
if (!(i+1 & 0x3)) ndbout << endl;
}
free(tmpString);
int result = _mgmtSrvr.dumpState(processId, pars, no);
if (result != 0) {
ndbout << get_error_text(result) << endl;
}
}
//*****************************************************************************
//*****************************************************************************
void CommandInterpreter::executeError(int processId,
const char* parameters, bool all) {
(void)all; // Don't want compiler warning
if (emptyString(parameters)) {
ndbout << "Missing error number." << endl;
return;
}
// Copy parameters since strtok will modify it
char* newpar = strdup(parameters);
char* firstParameter = strtok(newpar, " ");
int errorNo;
if (! convert(firstParameter, errorNo)) {
ndbout << "Expected an integer." << endl;
free(newpar);
return;
}
char* allAfterFirstParameter = strtok(NULL, "\0");
if (! emptyString(allAfterFirstParameter)) {
ndbout << "Nothing expected after error number." << endl;
free(newpar);
return;
}
int result = _mgmtSrvr.insertError(processId, errorNo);
if (result != 0) {
ndbout << get_error_text(result) << endl;
}
free(newpar);
}
//******************************************************************************
//******************************************************************************
void CommandInterpreter::executeTrace(int processId,
const char* parameters, bool all) {
(void)all; // Don't want compiler warning
if (emptyString(parameters)) {
ndbout << "Missing trace number." << endl;
return;
}
char* newpar = strdup(parameters);
char* firstParameter = strtok(newpar, " ");
int traceNo;
if (! convert(firstParameter, traceNo)) {
ndbout << "Expected an integer." << endl;
free(newpar);
return;
}
char* allAfterFirstParameter = strtok(NULL, "\0");
if (! emptyString(allAfterFirstParameter)) {
ndbout << "Nothing expected after trace number." << endl;
free(newpar);
return;
}
int result = _mgmtSrvr.setTraceNo(processId, traceNo);
if (result != 0) {
ndbout << get_error_text(result) << endl;
}
free(newpar);
}
//******************************************************************************
//******************************************************************************
void CommandInterpreter::executeLog(int processId,
const char* parameters, bool all) {
(void)all; // Don't want compiler warning
Vector<BaseString> blocks;
if (! parseBlockSpecification(parameters, blocks)) {
return;
}
int result = _mgmtSrvr.setSignalLoggingMode(processId, MgmtSrvr::InOut, blocks);
if (result != 0) {
ndbout << get_error_text(result) << endl;
}
}
//******************************************************************************
//******************************************************************************
void CommandInterpreter::executeLogIn(int processId,
const char* parameters, bool all) {
......@@ -554,41 +306,3 @@ void CommandInterpreter::executeLogOff(int processId,
}
}
//******************************************************************************
//******************************************************************************
void CommandInterpreter::executeTestOn(int processId,
const char* parameters, bool all) {
(void)all; // Don't want compiler warning
if (! emptyString(parameters)) {
ndbout << "No parameters expected to this command." << endl;
return;
}
int result = _mgmtSrvr.startSignalTracing(processId);
if (result != 0) {
ndbout << get_error_text(result) << endl;
}
}
//******************************************************************************
//******************************************************************************
void CommandInterpreter::executeTestOff(int processId,
const char* parameters, bool all) {
(void)all; // Don't want compiler warning
if (! emptyString(parameters)) {
ndbout << "No parameters expected to this command." << endl;
return;
}
int result = _mgmtSrvr.stopSignalTracing(processId);
if (result != 0) {
ndbout << get_error_text(result) << endl;
}
}
......@@ -17,52 +17,21 @@
#ifndef CommandInterpreter_H
#define CommandInterpreter_H
//*****************************************************************************
// Author: Peter Lind
//*****************************************************************************
#include <ndb_global.h>
#include <Vector.hpp>
#include <BaseString.hpp>
class MgmtSrvr;
/**
* @class CommandInterpreter
* @brief Reads command line in management client
*
* This class has one public method which reads a command line
* from a stream. It then interpret that commmand line and calls a suitable
* method in the MgmtSrvr class which executes the command.
*
* For command syntax, see the HELP command.
*/
class CommandInterpreter {
public:
/**
* Constructor
* @param mgmtSrvr: Management server to use when executing commands
*/
CommandInterpreter(MgmtSrvr& mgmtSrvr);
/**
* Reads one line from the stream, parse the line to find
* a command and then calls a suitable method which executes
* the command.
*
* @return true until quit/bye/exit has been typed
*/
int readAndExecute();
private:
char m_err_str[1024];
const char *get_error_text(int err_no);
/**
* Read a string, and return a pointer to it.
*
* @return NULL on EOF.
*/
char *readline_gets ()
{
static char linebuffer[254];
......@@ -89,61 +58,15 @@ private:
return (line_read);
}
/**
* Analyse the command line, after the first token.
*
* @param processId: DB process id to send command to or -1 if
* command will be sent to all DB processes.
* @param allAfterFirstToken: What the client gave after the
* first token on the command line
*/
void analyseAfterFirstToken(int processId, char* allAfterFirstTokenCstr);
/**
* Parse the block specification part of the LOG* commands,
* things after LOG*: [BLOCK = {ALL|<blockName>+}]
*
* @param allAfterLog: What the client gave after the second token
* (LOG*) on the command line
* @param blocks, OUT: ALL or name of all the blocks
* @return: true if correct syntax, otherwise false
*/
bool parseBlockSpecification(const char* allAfterLog,
Vector<BaseString>& blocks);
/**
* A bunch of execute functions: Executes one of the commands
*
* @param processId: DB process id to send command to
* @param parameters: What the client gave after the command name
* on the command line.
* For example if complete input from user is: "1 LOGLEVEL 22" then the
* parameters argument is the string with everything after LOGLEVEL, in this
* case "22". Each function is responsible to check the parameters argument.
*/
void executeHelp(char* parameters);
void executeShow(char* parameters);
void executeRun(char* parameters);
void executeInfo(char* parameters);
public:
void executeStop(int processId, const char* parameters, bool all);
void executeStart(int processId, const char* parameters, bool all);
void executeRestart(int processId, const char* parameters, bool all);
void executeError(int processId, const char* parameters, bool all);
void executeTrace(int processId, const char* parameters, bool all);
void executeLog(int processId, const char* parameters, bool all);
void executeLogIn(int processId, const char* parameters, bool all);
void executeLogOut(int processId, const char* parameters, bool all);
void executeLogOff(int processId, const char* parameters, bool all);
void executeTestOn(int processId, const char* parameters, bool all);
void executeTestOff(int processId, const char* parameters, bool all);
void executeStatus(int processId, const char* parameters, bool all);
void executeDumpState(int processId, const char* parameters, bool all);
/**
* A execute function definition
*/
public:
typedef void (CommandInterpreter::* ExecuteFunction)(int processId,
const char * param,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment