version 1.1.2.3, 2006/04/24 19:15:09
|
version 1.1.2.4, 2006/04/27 15:08:33
|
|
|
//Windows | //Windows |
// | // |
#ifdef PEGASUS_OS_TYPE_WINDOWS | #ifdef PEGASUS_OS_TYPE_WINDOWS |
#include <windows.h> /* for DWORD etc. */ |
// for DWORD etc. |
typedef DWORD pid_t; /* getpid() and others */ |
#include <windows.h> |
|
// getpid() and others |
|
typedef DWORD pid_t; |
#include <process.h> | #include <process.h> |
#elif !defined(PEGASUS_OS_OS400) | #elif !defined(PEGASUS_OS_OS400) |
#include <unistd.h> | #include <unistd.h> |
|
|
| |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
|
PEGASUS_USING_PEGASUS; |
|
PEGASUS_USING_STD; |
|
|
| |
| |
/** | /** |
|
|
/** | /** |
Temporary arrays to store client information | Temporary arrays to store client information |
*/ | */ |
|
|
/** | /** |
Client PID's | Client PID's |
*/ | */ |
|
|
_passwordSpecified = false; | _passwordSpecified = false; |
_useSSL = false; | _useSSL = false; |
| |
|
// |
// initialize | // initialize |
|
// |
_clientCount = 0; | _clientCount = 0; |
_currClientCount = 0; | _currClientCount = 0; |
| |
|
|
// | // |
_propertyTable = new Table; | _propertyTable = new Table; |
| |
|
// |
// Client Information | // Client Information |
|
// |
_clientCommands = 0; | _clientCommands = 0; |
_clientDurations = 0; | _clientDurations = 0; |
_clientDelays = 0; | _clientDelays = 0; |
| |
|
// |
// Get environment variables: | // Get environment variables: |
// | // |
pegasusHome = getenv("PEGASUS_HOME"); | pegasusHome = getenv("PEGASUS_HOME"); |
|
|
| |
ofstream log_file; | ofstream log_file; |
| |
|
// |
// opens the log file | // opens the log file |
|
// |
OpenAppend(log_file,_stressTestLogFile); | OpenAppend(log_file,_stressTestLogFile); |
| |
if (!log_file) | if (!log_file) |
|
|
getOpts = getoopt (); | getOpts = getoopt (); |
getOpts.addFlagspec (GetOptString); | getOpts.addFlagspec (GetOptString); |
| |
|
// |
// per PEP#167 | // per PEP#167 |
|
// |
getOpts.addLongFlagspec(LONG_HELP,getoopt::NOARG); | getOpts.addLongFlagspec(LONG_HELP,getoopt::NOARG); |
getOpts.addLongFlagspec(LONG_VERSION,getoopt::NOARG); | getOpts.addLongFlagspec(LONG_VERSION,getoopt::NOARG); |
getOpts.addLongFlagspec(LONG_VERBOSE,getoopt::NOARG); | getOpts.addLongFlagspec(LONG_VERBOSE,getoopt::NOARG); |
|
|
_clientDurations = new Uint64[_clientCount]; | _clientDurations = new Uint64[_clientCount]; |
_clientDelays = new Uint64[_clientCount]; | _clientDelays = new Uint64[_clientCount]; |
| |
|
// |
// Retrieve all the client options from the client table | // Retrieve all the client options from the client table |
// and build commands for respective clients. | // and build commands for respective clients. |
// Add appropriate options to command string as required | // Add appropriate options to command string as required |
|
// |
for (Uint32 j=0; j< _clientCount; j++) | for (Uint32 j=0; j< _clientCount; j++) |
{ | { |
delay = 0; | delay = 0; |
|
|
} | } |
else if (String::equalNoCase(i.key(),NAME)) | else if (String::equalNoCase(i.key(),NAME)) |
{ | { |
|
// |
// should be ignored - already saved using clientName | // should be ignored - already saved using clientName |
|
// |
} | } |
else if (String::equalNoCase(i.key(),PORTNUMBER)) | else if (String::equalNoCase(i.key(),PORTNUMBER)) |
{ | { |
|
|
||(String::equalNoCase(i.key(),CLIENTWAIT)) | ||(String::equalNoCase(i.key(),CLIENTWAIT)) |
||(String::equalNoCase(i.key(),CLIENTDURATION))) | ||(String::equalNoCase(i.key(),CLIENTDURATION))) |
{ | { |
|
// |
// do nothing here | // do nothing here |
// will be utilized to run the clients later. | // will be utilized to run the clients later. |
|
// |
} | } |
else | else |
{ | { |
|
// |
// Save all other options for the commands | // Save all other options for the commands |
|
// |
client_command.append(" -"); | client_command.append(" -"); |
client_command.append(i.key()); | client_command.append(i.key()); |
client_command.append(" "); | client_command.append(" "); |
|
|
// Acquire all the common properties listed in the property table | // Acquire all the common properties listed in the property table |
// from config file and include it as part of the client command | // from config file and include it as part of the client command |
// as required. | // as required. |
|
// |
for (Table::Iterator k = _propertyTable->start(); k; k++) | for (Table::Iterator k = _propertyTable->start(); k; k++) |
{ | { |
String propertyValue = String::EMPTY; | String propertyValue = String::EMPTY; |
|
// |
// Only include the common properties that are not already | // Only include the common properties that are not already |
// listed for the clients. | // listed for the clients. |
|
// |
if (!_clientTable[j].lookup(k.key(), propertyValue)) | if (!_clientTable[j].lookup(k.key(), propertyValue)) |
{ | { |
|
// |
// Include options other than ToleranceLevel | // Include options other than ToleranceLevel |
// clientDuration,clientwait and Duration | // clientDuration,clientwait and Duration |
// in the command string for the clients. | // in the command string for the clients. |
|
// |
if ((!String::equalNoCase(k.key(),TOLERANCELEVEL)) | if ((!String::equalNoCase(k.key(),TOLERANCELEVEL)) |
&& (!String::equalNoCase(k.key(),CLIENTDURATION)) | && (!String::equalNoCase(k.key(),CLIENTDURATION)) |
&& (!String::equalNoCase(k.key(),CLIENTWAIT)) | && (!String::equalNoCase(k.key(),CLIENTWAIT)) |
|
|
// | // |
for (Table::Iterator k = _clientTable[j].start(); k; k++) | for (Table::Iterator k = _clientTable[j].start(); k; k++) |
{ | { |
|
// |
// Overwrite duration if client duration set | // Overwrite duration if client duration set |
|
// |
if (String::equalNoCase(k.key(),CLIENTDURATION)) | if (String::equalNoCase(k.key(),CLIENTDURATION)) |
{ | { |
duration = atof(k.value().getCString()); | duration = atof(k.value().getCString()); |
|
|
return (RC_SUCCESS); | return (RC_SUCCESS); |
} | } |
| |
// graceful shutdown when interrupted |
// |
|
// gracefully shutdown when interrupted |
|
// |
signal(SIGABRT, endAllTests); | signal(SIGABRT, endAllTests); |
signal(SIGINT, endAllTests); | signal(SIGINT, endAllTests); |
| |
|
|
| |
try | try |
{ | { |
|
// |
// Initializing the Boolean array's to false. | // Initializing the Boolean array's to false. |
|
// |
for (Uint32 i=0;i<_clientCount;i++) | for (Uint32 i=0;i<_clientCount;i++) |
{ | { |
clientStopped[i] = false; | clientStopped[i] = false; |
clientDelayed[i] = false; | clientDelayed[i] = false; |
} | } |
|
// |
// Set up duration of the tests | // Set up duration of the tests |
|
// |
startMilliseconds = TimeValue::getCurrentTime().toMilliseconds(); | startMilliseconds = TimeValue::getCurrentTime().toMilliseconds(); |
nowMilliseconds = startMilliseconds; | nowMilliseconds = startMilliseconds; |
timeoutMilliseconds = (Uint64)convertmin2millisecs(_duration); | timeoutMilliseconds = (Uint64)convertmin2millisecs(_duration); |
|
|
Sleep(RUN_DELAY * 1000); | Sleep(RUN_DELAY * 1000); |
#endif | #endif |
| |
|
// |
// Quit if SIGINT, SIGABRT is caught | // Quit if SIGINT, SIGABRT is caught |
// So the clients can be gracefully shutdown. | // So the clients can be gracefully shutdown. |
|
// |
if(Quit) | if(Quit) |
{ | { |
log_file<< | log_file<< |
|
|
// - Additional required parameters are added to the | // - Additional required parameters are added to the |
// commands. | // commands. |
// like, -clientid, -pidfile, -clientlog | // like, -clientid, -pidfile, -clientlog |
|
// |
for (int instanceID =0;instanceID<clientInstance[j]; | for (int instanceID =0;instanceID<clientInstance[j]; |
instanceID++) | instanceID++) |
{ | { |
|
|
"Command failed to Execute."<<endl; | "Command failed to Execute."<<endl; |
} | } |
} | } |
|
// |
// Increment the actual number of clients | // Increment the actual number of clients |
|
// |
++actual_client; | ++actual_client; |
} /* for(int instanceID =0;instanceID<clientInstance[j]...*/ | } /* for(int instanceID =0;instanceID<clientInstance[j]...*/ |
| |
|
|
all the clients and then exit. | all the clients and then exit. |
*/ | */ |
| |
|
// |
// Retreive all the client PIDs | // Retreive all the client PIDs |
|
// |
int rc = _getClientPIDs(actual_client,log_file); | int rc = _getClientPIDs(actual_client,log_file); |
| |
// | // |
|
|
// | // |
for (Uint32 clientID=0; clientID < _clientCount; clientID++) | for (Uint32 clientID=0; clientID < _clientCount; clientID++) |
{ | { |
|
// |
// Get Current time | // Get Current time |
|
// |
nowMilliseconds = | nowMilliseconds = |
TimeValue::getCurrentTime().toMilliseconds(); | TimeValue::getCurrentTime().toMilliseconds(); |
| |
|
|
"%d", | "%d", |
clientPIDs[clientID+instanceID]); | clientPIDs[clientID+instanceID]); |
stopClientFile.append(str); | stopClientFile.append(str); |
|
// |
// Required for Windows | // Required for Windows |
|
// |
ofstream stop_file( | ofstream stop_file( |
stopClientFile.getCString(), | stopClientFile.getCString(), |
ios::out); | ios::out); |
|
|
clientID + instanceID<<")"<<endl; | clientID + instanceID<<")"<<endl; |
} | } |
#endif | #endif |
|
// |
// Set the client as inactive. | // Set the client as inactive. |
|
// |
clientActive[clientID + instanceID] = false; | clientActive[clientID + instanceID] = false; |
}/* for (int instanceID =0;instanceID<clientInst..*/ | }/* for (int instanceID =0;instanceID<clientInst..*/ |
|
// |
// indicate that the client was stopped. | // indicate that the client was stopped. |
|
// |
clientStopped[clientID] = true; | clientStopped[clientID] = true; |
// | // |
// If the Client has a Wait time | // If the Client has a Wait time |
|
|
// | // |
if (clientDelayed[clientID]) | if (clientDelayed[clientID]) |
{ | { |
|
// |
// When waiting period is consumed. | // When waiting period is consumed. |
|
// |
if (clientDelayMilliseconds[clientID]<= | if (clientDelayMilliseconds[clientID]<= |
nowMilliseconds) | nowMilliseconds) |
{ | { |
|
|
clientPIDs[i]<<endl; | clientPIDs[i]<<endl; |
} | } |
log_file<<"Stopping Client("<<i<<") with PID:"<<clientPIDs[i]<<endl; | log_file<<"Stopping Client("<<i<<") with PID:"<<clientPIDs[i]<<endl; |
|
// |
// Required for Windows | // Required for Windows |
|
// |
String stopClientFile = String::EMPTY; | String stopClientFile = String::EMPTY; |
stopClientFile.append(pegasusHome); | stopClientFile.append(pegasusHome); |
stopClientFile.append(DEFAULT_TMPDIR); | stopClientFile.append(DEFAULT_TMPDIR); |
|
|
{ | { |
_currClient=name; | _currClient=name; |
_currClientCount=_clientCount; | _currClientCount=_clientCount; |
|
// |
// save the client details in a table | // save the client details in a table |
|
// |
if (!_storeClientDetails(name,value)) | if (!_storeClientDetails(name,value)) |
{ | { |
log_file<<StressTestControllerCommand::COMMAND_NAME<< | log_file<<StressTestControllerCommand::COMMAND_NAME<< |
|
|
{ | { |
vars=String::EMPTY; | vars=String::EMPTY; |
vars.append(DURATION); | vars.append(DURATION); |
|
// |
// converting to a double | // converting to a double |
|
// |
if (!IsAClient) | if (!IsAClient) |
{ | { |
_duration = atof(value.getCString()); | _duration = atof(value.getCString()); |
|
|
// | // |
if (instance <=0) | if (instance <=0) |
{ | { |
|
// |
// Invalid Instance value | // Invalid Instance value |
|
// |
return false; | return false; |
} | } |
// | // |
|
|
#endif | #endif |
if (!FileSystem::exists(clientName)) | if (!FileSystem::exists(clientName)) |
{ | { |
|
// |
// Invalid client name | // Invalid client name |
|
// |
IsValid = false; | IsValid = false; |
} | } |
else | else |
|
|
else | else |
{ | { |
| |
|
// |
// Invalid client name | // Invalid client name |
|
// |
IsValid = false; | IsValid = false; |
} | } |
} | } |
|
|
continue; | continue; |
} | } |
| |
|
// |
// Get the client ID | // Get the client ID |
|
// |
String client = String::EMPTY; | String client = String::EMPTY; |
while (isalnum(*p) || *p == '_') | while (isalnum(*p) || *p == '_') |
{ | { |
client.append(*p++); | client.append(*p++); |
} | } |
| |
|
// |
// Skip whitespace after property name | // Skip whitespace after property name |
|
// |
while (*p && isspace(*p)) | while (*p && isspace(*p)) |
{ | { |
p++; | p++; |
} | } |
| |
|
// |
// Expecting a colon | // Expecting a colon |
|
// |
if (*p != ':') | if (*p != ':') |
{ | { |
ifs.close(); | ifs.close(); |
|
|
// | // |
p++; | p++; |
| |
|
// |
// Expecting a colon | // Expecting a colon |
|
// |
if (*p != ':') | if (*p != ':') |
{ | { |
ifs.close(); | ifs.close(); |
|
|
p++; | p++; |
} | } |
| |
|
// |
// Get the client PID | // Get the client PID |
|
// |
String clntPID = String::EMPTY; | String clntPID = String::EMPTY; |
while (isalnum(*p) || *p == '_') | while (isalnum(*p) || *p == '_') |
{ | { |
clntPID.append(*p++); | clntPID.append(*p++); |
} | } |
| |
|
// |
// Skip whitespace after property name | // Skip whitespace after property name |
|
// |
while (*p && isspace(*p)) | while (*p && isspace(*p)) |
{ | { |
p++; | p++; |
|
|
} | } |
p++; | p++; |
| |
|
// |
// Skip whitespace after the colon if any | // Skip whitespace after the colon if any |
|
// |
while (*p && isspace(*p)) | while (*p && isspace(*p)) |
{ | { |
p++; | p++; |
|
|
clntStatus.append(*p++); | clntStatus.append(*p++); |
} | } |
| |
|
// |
// Skip whitespace after property name | // Skip whitespace after property name |
|
// |
while (*p && isspace(*p)) | while (*p && isspace(*p)) |
{ | { |
p++; | p++; |
|
|
// next character in line. | // next character in line. |
// | // |
p++; | p++; |
|
// |
// Skip whitespace after the colon if any | // Skip whitespace after the colon if any |
|
// |
while (*p && isspace(*p)) | while (*p && isspace(*p)) |
{ | { |
p++; | p++; |
} | } |
| |
|
// |
// Get the client timestamp | // Get the client timestamp |
|
// |
String clntTmStmp = String::EMPTY; | String clntTmStmp = String::EMPTY; |
while (isalnum(*p)) | while (isalnum(*p)) |
{ | { |
|
|
} | } |
catch (...) | catch (...) |
{ | { |
// throw what was caught |
|
String msg = String( | String msg = String( |
"Unknown exception caught when geting client options."); | "Unknown exception caught when geting client options."); |
log_file<<StressTestControllerCommand::COMMAND_NAME << | log_file<<StressTestControllerCommand::COMMAND_NAME << |
|
|
// | // |
if(clientStatus[i]== VALID_RESPONSE) | if(clientStatus[i]== VALID_RESPONSE) |
{ | { |
|
// |
//check with the last timestamp | //check with the last timestamp |
|
// |
lastUpdateinMilliSec = nowMilliseconds - clientTimeStamp[i]; | lastUpdateinMilliSec = nowMilliseconds - clientTimeStamp[i]; |
// | // |
// Assume failure if status update is | // Assume failure if status update is |
|
|
} | } |
++failed_count; | ++failed_count; |
} /* if (((clientStatus[i]== NO_RESPONSE) ... */ | } /* if (((clientStatus[i]== NO_RESPONSE) ... */ |
|
// |
// Save previous time stamp of client | // Save previous time stamp of client |
|
// |
prev_clientTimeStamp[i] = clientTimeStamp[i]; | prev_clientTimeStamp[i] = clientTimeStamp[i]; |
prev_clientStatus[i] = clientStatus[i]; | prev_clientStatus[i] = clientStatus[i]; |
} /* if (clientActive[i]) */ | } /* if (clientActive[i]) */ |
} | } |
|
// |
// check actual tolerance | // check actual tolerance |
|
// |
if(count > 0) | if(count > 0) |
{ | { |
double curr_tolerancePercent = getToleranceInPercent( | double curr_tolerancePercent = getToleranceInPercent( |
|
|
} | } |
return(withinTolerance); | return(withinTolerance); |
} | } |
|
// |
// All process are stopped. | // All process are stopped. |
|
// |
return(withinTolerance = true); | return(withinTolerance = true); |
} /* _checkToleranceLevel */ | } /* _checkToleranceLevel */ |
| |
|
|
{ | { |
cout << "Populating default configuration for stress Tests." << endl; | cout << "Populating default configuration for stress Tests." << endl; |
} | } |
|
// |
// Populating default client attributes | // Populating default client attributes |
|
// |
for (Uint32 i=0;i<_clientCount; i++) | for (Uint32 i=0;i<_clientCount; i++) |
{ | { |
// | // |
// Adding the default instance value to each client table | // Adding the default instance value to each client table |
|
// |
if (!_clientTable[i].insert(INSTANCE, DEFAULT_INSTANCE)) | if (!_clientTable[i].insert(INSTANCE, DEFAULT_INSTANCE)) |
{ | { |
log_file << "Duplicate name already saved: "<<INSTANCE<<endl; | log_file << "Duplicate name already saved: "<<INSTANCE<<endl; |
|
|
| |
sprintf(pid_str, "%d", getpid()); | sprintf(pid_str, "%d", getpid()); |
| |
|
// |
// Stress Controller Log file | // Stress Controller Log file |
|
// |
_stressTestLogFile.append(pegasusHome); | _stressTestLogFile.append(pegasusHome); |
_stressTestLogFile.append(TESTDIR); | _stressTestLogFile.append(TESTDIR); |
FileSystem::makeDirectory(_stressTestLogFile); | FileSystem::makeDirectory(_stressTestLogFile); |
|
|
_stressTestLogFile.append(strTime); | _stressTestLogFile.append(strTime); |
_stressTestLogFile.append("log"); | _stressTestLogFile.append("log"); |
| |
|
// |
// StressClient PID file | // StressClient PID file |
|
// |
_stressTestClientPIDFile.append(pegasusHome); | _stressTestClientPIDFile.append(pegasusHome); |
_stressTestClientPIDFile.append(DEFAULT_TMPDIR); | _stressTestClientPIDFile.append(DEFAULT_TMPDIR); |
FileSystem::makeDirectory(_stressTestClientPIDFile); | FileSystem::makeDirectory(_stressTestClientPIDFile); |
|
|
_stressTestClientPIDFile.append(strTime); | _stressTestClientPIDFile.append(strTime); |
_stressTestClientPIDFile.append("pid"); | _stressTestClientPIDFile.append("pid"); |
| |
|
// |
// StressClient Log file | // StressClient Log file |
|
// |
_stressTestClientLogFile.append(pegasusHome); | _stressTestClientLogFile.append(pegasusHome); |
_stressTestClientLogFile.append(DEFAULT_LOGDIR); | _stressTestClientLogFile.append(DEFAULT_LOGDIR); |
_stressTestClientLogFile.append(pid_str); | _stressTestClientLogFile.append(pid_str); |
_stressTestClientLogFile.append("_StressTestClients"); | _stressTestClientLogFile.append("_StressTestClients"); |
_stressTestClientLogFile.append(".log"); | _stressTestClientLogFile.append(".log"); |
| |
|
// |
// Temporary StressClient PID/status file | // Temporary StressClient PID/status file |
|
// |
_tmpStressTestClientPIDFile.append(pegasusHome); | _tmpStressTestClientPIDFile.append(pegasusHome); |
_tmpStressTestClientPIDFile.append(DEFAULT_TMPDIR); | _tmpStressTestClientPIDFile.append(DEFAULT_TMPDIR); |
_tmpStressTestClientPIDFile.append(pid_str); | _tmpStressTestClientPIDFile.append(pid_str); |
|
|
_tmpStressTestClientPIDFile.append("_Clients"); | _tmpStressTestClientPIDFile.append("_Clients"); |
_tmpStressTestClientPIDFile.append(".pid"); | _tmpStressTestClientPIDFile.append(".pid"); |
| |
|
// |
// Translate slashed for appropriate OS | // Translate slashed for appropriate OS |
|
// |
FileSystem::translateSlashes(_stressTestClientPIDFile); | FileSystem::translateSlashes(_stressTestClientPIDFile); |
FileSystem::translateSlashes(_stressTestClientLogFile); | FileSystem::translateSlashes(_stressTestClientLogFile); |
FileSystem::translateSlashes(_stressTestLogFile); | FileSystem::translateSlashes(_stressTestLogFile); |
FileSystem::translateSlashes(_tmpStressTestClientPIDFile); | FileSystem::translateSlashes(_tmpStressTestClientPIDFile); |
| |
|
// |
// open the file | // open the file |
|
// |
OpenAppend(log_file,_stressTestLogFile); | OpenAppend(log_file,_stressTestLogFile); |
Open(pid_file,_stressTestClientPIDFile); | Open(pid_file,_stressTestClientPIDFile); |
Open(clntlog_file,_stressTestClientLogFile); | Open(clntlog_file,_stressTestClientLogFile); |