int main(int argc, char** argv) { OptionManager om; TestModelWalkStressClient tmsc; Uint32 validArg = 0; struct OptionRow *newOptionsTable = 0; Uint32 newOptionsCount = 0; Uint32 cOptionCount = 0; // // Variables need to connect to server. // Boolean useSSL; String host; Uint32 portNumber = 0; String portStr; String userName; String password; String help; Boolean connectedToHost = false; // // Variables needed to do loging and status checking. // String pidFile; String clientId; pid_t clientPid; String clientLog, stopClient; char pid_str[15]; // // Number of times the command succeeded. // Uint32 successCount=0; // // Number of iterations after which logErrorPercentage() is called. // Uint32 iteration=0; // // Total number of times the command was executed. // Uint32 totalCount=0; // // timeout. // Uint32 timeout = 30000; // // This try block includes all the options gathering function. // try { // // client specific options if any. // struct OptionRow *cOptionTable = 0; newOptionsCount = cOptionCount; try { // // Generate new option table for this client using // the OptionManager. // newOptionsTable = tmsc.generateClientOptions(cOptionTable, cOptionCount,newOptionsCount); validArg = tmsc.GetOptions(om, argc, argv, newOptionsTable, newOptionsCount); } catch (Exception& e) { PEGASUS_STD(cerr) << argv[0] << ": " << e.getMessage() << PEGASUS_STD(endl); exit(1); } catch (...) { PEGASUS_STD(cerr) << argv[0] << ": Error in Options operation " << PEGASUS_STD(endl); exit(1); } verboseTest = om.isTrue("verbose"); om.lookupValue("username", userName); om.lookupValue("password", password); om.lookupIntegerValue("timeout",timeout); useSSL = om.isTrue("ssl"); om.lookupValue("hostname",host); om.lookupValue("port",portStr); if (portStr.getCString()) { sscanf (portStr.getCString (), "%u", &portNumber); } // // Setting default ports. // if (!portNumber) { if (useSSL) { portNumber = 5989; } else { portNumber = 5988; } } // // default host is localhost. // if (host == String::EMPTY) { host = String("localhost"); } // // Signal Handling - SIGINT // signal(SIGINT, endTest); om.lookupValue("clientid", clientId); om.lookupValue("pidfile", pidFile); clientPid = getpid(); om.lookupValue("clientlog", clientLog); om.lookupValue("help", help); }// end of option Try block catch (Exception& e) { PEGASUS_STD(cerr) << argv[0] << ": " << e.getMessage() << PEGASUS_STD(endl); exit(1); } catch (...) { PEGASUS_STD(cerr) << argv[0] << ": Unknown Error gathering options " << PEGASUS_STD(endl); exit(1); } /* Checking whether the user asked for HELP Info... if (om.valueEquals("help", "true")) { String header = "Usage "; header.append(argv[0]); header.append(" -parameters -n [namespace] -c [classname] "); header.append(" -clientId [clientId] -pidFile [pidFile] "); header.append(" -clientLog [clientLog]"); String trailer = "Assumes localhost:5988 if host not specified"; trailer.append("\nHost may be of the form name or name:port"); trailer.append("\nPort 5988 assumed if port number missing."); om.printOptionsHelpTxt(header, trailer); exit(0); } */ try { // // Timer Start. // tmsc.startTime(); tmsc.logInfo(clientId, clientPid, globalStatus, pidFile); // // connect the client. // CIMClient* client = new CIMClient(); sprintf(pid_str, "%d", clientPid); stopClient = String::EMPTY; stopClient.append(FileSystem::extractFilePath(pidFile)); stopClient.append("STOP_"); stopClient.append(pid_str); // // This loop executes till the client gets stop signal from // controller. // while (!quit) { if (FileSystem::exists(stopClient)) { if (verboseTest) { String mes("Ending client. "); tmsc.errorLog(clientPid, clientLog, mes); } break; } if (!verboseTest) { #ifdef PEGASUS_OS_TYPE_WINDOWS freopen("nul","w",stdout); #else freopen("/dev/null","w",stdout); #endif } if (!connectedToHost) { try { tmsc.connectClient( client, host, portNumber, userName, password, useSSL, timeout, verboseTest); connectedToHost = true; // // Client has successfully connected to server. // update status if previously not Success. // if (globalStatus != CLIENT_PASS) { globalStatus = CLIENT_PASS; tmsc.logInfo(clientId, clientPid, globalStatus, pidFile); } } catch (CannotConnectException) { globalStatus = CLIENT_UNKNOWN; tmsc.logInfo(clientId, clientPid, globalStatus, pidFile); connectedToHost = false; } catch (CIMException &e) { globalStatus = CLIENT_UNKNOWN; tmsc.logInfo(clientId, clientPid, globalStatus, pidFile); connectedToHost = false; String mes(e.getMessage()); tmsc.errorLog(clientPid, clientLog, mes); } catch (Exception &e) { globalStatus = CLIENT_UNKNOWN; tmsc.logInfo(clientId, clientPid, globalStatus, pidFile); connectedToHost = false; String mes(e.getMessage()); tmsc.errorLog(clientPid, clientLog, mes); } catch (...) { globalStatus = CLIENT_UNKNOWN; tmsc.logInfo(clientId, clientPid, globalStatus, pidFile); connectedToHost = false; String mes("Error connencting to server in ModleWalk"); mes.append(" client "); tmsc.errorLog(clientPid, clientLog,mes); } }/* end of if (!connectedToHost). */ iteration++; totalCount++; if (connectedToHost) { try { Array<CIMNamespaceName> nameSpacesArray; // // Enumerate all the namespaces here. // nameSpacesArray = getNameSpaces( tmsc, client, om, clientPid, clientLog, clientId, globalStatus, pidFile); // // Enumerate all qualifiers in the namespaces. // enumerateAllQualifiers( tmsc, client, nameSpacesArray, clientPid, clientLog, clientId, globalStatus, pidFile); // // Enumerate all the class related info here. // enumerateClassRelatedInfo( tmsc, client, om, nameSpacesArray, clientPid, clientLog, clientId, globalStatus, pidFile); successCount++; } // // This specail catch block in needed so that we will know if // the connenction was lost. We then connect on the next time // through the loop. // catch (CannotConnectException) { globalStatus = CLIENT_UNKNOWN; tmsc.logInfo(clientId, clientPid, globalStatus, pidFile); connectedToHost = false; } catch (CIMException &cimE) { globalStatus = CLIENT_FAIL; tmsc.logInfo(clientId, clientPid, globalStatus, pidFile); String mes(cimE.getMessage()); tmsc.errorLog(clientPid, clientLog, mes); } catch (Exception &exp) { globalStatus = CLIENT_FAIL; tmsc.logInfo(clientId, clientPid, globalStatus, pidFile); String mes(exp.getMessage()); tmsc.errorLog(clientPid, clientLog, mes); } catch (...) { globalStatus = CLIENT_FAIL; tmsc.logInfo(clientId, clientPid, globalStatus, pidFile); String mes("Unknown Error during ModelWalk Execution"); tmsc.errorLog(clientPid, clientLog, mes); } nextCheck = tmsc.checkTime(); if (nextCheck) { tmsc.logInfo(clientId, clientPid, globalStatus, pidFile); nextCheck = false; } // // If verbose is set, log success percentage for every 100 // iterations. If verbose is not set, log success percentage // for every 10000 iterations. // if (verboseTest) { if (iteration == 100) { tmsc.logErrorPercentage( successCount, totalCount, clientPid, clientLog, clientName); iteration = 0; } } else { if (iteration == 1000) { tmsc.logErrorPercentage( successCount, totalCount, clientPid, clientLog, clientName); iteration = 0; } } } } // end of while (!quit). } catch (Exception &exp) { String expStr("Exception in ModelWalk client, causing it to exit: "); expStr.append(exp.getMessage()); tmsc.errorLog(clientPid, clientLog, expStr); if (verboseTest) { PEGASUS_STD(cerr) << expStr.getCString() << PEGASUS_STD(endl); } } catch (...) { String expStr("General Exception in ModelWalk, causing it to exit"); tmsc.errorLog(clientPid, clientLog, expStr); if (verboseTest) { PEGASUS_STD(cerr) << expStr.getCString() << PEGASUS_STD(endl); } } // // One second delay before shutdown. // #ifndef PEGASUS_OS_TYPE_WINDOWS sleep(1); #else Sleep(1000); #endif if (FileSystem::exists(stopClient)) { // // Remove STOP file here. // FileSystem::removeFile(stopClient); } if (verboseTest) { errorInfo.clear(); errorInfo.append("+++++ TestModelWalkStressClient Terminated "); errorInfo.append("Normally +++++"); tmsc.errorLog(clientPid, clientLog, errorInfo); errorInfo.clear(); } return 0; }
/** MAIN */ int main(int argc, char** argv) { OptionManager om; TestWrapperStressClient wc; pid_t clientPid = getpid(); Uint32 validArg = 0; Boolean verboseTest; // // Varriables needed for loging and status checking. // String clientId; String pidFile; String clientLog, stopClient; char pid_str[15]; int status = CLIENT_UNKNOWN; // // Number of times the client command succeeded. // Uint32 successCount = 0; // // Number of iterations after which logErrorPercentage() is called. // Uint32 iteration = 0; // // Total number of times the client command was executed. // Uint32 totalCount = 0; // // Variables needed for Command operation. // String command; String options; String help; try { struct OptionRow *newOptionsTable = 0; Uint32 newOptionsCount; struct OptionRow cOptionTable[] = { {"clientname", "", true, Option::STRING, 0, 0, "clientname", "Client name" }, {"options", "", true, Option::STRING, 0, 0, "options", "Corresponding Client program's options" } }; Uint32 cOptionCount = sizeof(cOptionTable) / sizeof(cOptionTable[0]); newOptionsCount = cOptionCount; try { // // Generate new option table for this client using OptionManager // newOptionsTable = wc.generateClientOptions( cOptionTable, cOptionCount, newOptionsCount); validArg = wc.GetOptions( om, argc, argv, newOptionsTable, newOptionsCount); } catch (Exception& e) { cerr << argv[0] << ": " << e.getMessage() << endl; exit(1); } catch (...) { cerr << argv[0] << ": Error in Options operations "<< endl; exit(1); } verboseTest = om.isTrue("verbose"); om.lookupValue("clientid", clientId); om.lookupValue("pidfile", pidFile); om.lookupValue("clientlog", clientLog); om.lookupValue("clientname", command); om.lookupValue("options", options); om.lookupValue("help", help); } /** end of option Try block. */ catch (Exception& e) { cerr << argv[0] << ": " << e.getMessage() <<endl; exit(1); } catch (...) { cerr << argv[0] << ": Unknown Error gathering options " << "in Wrapper Client " << endl; exit(1); } /** Checking whether the user asked for HELP Info... if (om.valueEquals("help", "true")) { String header = "Usage "; header.append(argv[0]); header.append(" -parameters -clientName [clientName] header.append(" -options [options] -clientid [clientId] "); header.append(" -pidfile [pidFile] -clientlog [clientLog]"); String trailer = "Assumes localhost:5988 if host not specified"; trailer.append("\nHost may be of the form name or name:port"); trailer.append("\nPort 5988 assumed if port number missing."); om.printOptionsHelpTxt(header, trailer); exit(0); } */ try { if (options.getCString()) { command.append(" " + options); } if (verboseTest) { errorInfo.append("client command : "); errorInfo.append(command); wc.errorLog(clientPid, clientLog, errorInfo); errorInfo.clear(); } // // Signal Handling - SIGINT. // signal(SIGINT, endTest); // // Timer Start. // wc.startTime(); wc.logInfo(clientId, clientPid, status, pidFile); sprintf(pid_str, "%d", clientPid); stopClient = String::EMPTY; stopClient.append(FileSystem::extractFilePath(pidFile)); stopClient.append("STOP_"); stopClient.append(pid_str); // // This loop executes till the client gets stop signal from // controller. // while (!quit) { if (FileSystem::exists(stopClient)) { if (verboseTest) { String mes("Ending client. "); wc.errorLog(clientPid, clientLog, mes); } break; } if (!verboseTest) { #ifdef PEGASUS_OS_TYPE_WINDOWS freopen("nul","w",stdout); #else FILE * file = freopen("/dev/null","w",stdout); if (0 == file) { // ignore possible error, not having stdout redirected // to /dev/null doesn't hurt the test continue; } #endif } int i = system(command.getCString()); iteration++; totalCount++; switch (i) { case 0: if (status != CLIENT_PASS) { status = CLIENT_PASS; wc.logInfo(clientId, clientPid, status, pidFile); } successCount++; break; case 1: status = CLIENT_UNKNOWN; wc.logInfo(clientId, clientPid, status, pidFile); break; default: status = CLIENT_FAIL; wc.logInfo(clientId, clientPid, status, pidFile); break; } nextCheck = wc.checkTime(); if (nextCheck) { wc.logInfo(clientId, clientPid, status, pidFile); nextCheck = false; } // // If verbose is set, log success percentage for every 100 // iterations. If verbose is not set, log success percentage // for every 1000 iterations. // if (verboseTest) { if (iteration == 100) { wc.logErrorPercentage( successCount, totalCount, clientPid, clientLog, thisClient); iteration = 0; } } else { if (iteration == 1000) { wc.logErrorPercentage( successCount, totalCount, clientPid, clientLog, thisClient); iteration = 0; } } } /** end of while(!quit). */ } /** end of command execution try block. */ catch (Exception &exp) { String expStr("Exception in WrapperClient causing it to exit: "); expStr.append(exp.getMessage()); wc.errorLog(clientPid, clientLog, expStr); if (verboseTest) { cerr << expStr.getCString() << endl; } } catch (...) { String expStr("General Exception in WrapperClient causing it to exit"); wc.errorLog(clientPid, clientLog, expStr); if (verboseTest) { cerr << expStr.getCString() << endl; } } // // second delay before shutdown. // #ifndef PEGASUS_OS_TYPE_WINDOWS sleep(1); #else Sleep(1000); #endif if(FileSystem::exists(stopClient)) { // // Remove STOP file here. // FileSystem::removeFile(stopClient); } if (verboseTest) { errorInfo.append( "++++ TestWrapperStressClient Terminated Normally +++++"); wc.errorLog(clientPid, clientLog, errorInfo); errorInfo.clear(); } return 0; }
int main(int argc, char** argv) { // char connection[50] = "localhost:5988"; char *address_string = NULL; Uint32 repetitions = 1; // Get environment variables: String pegasusHome; pegasusHome = "/"; // GetEnvironmentVariables(argv[0], pegasusHome); // Get options (from command line and from configuration file); this // removes corresponding options and their arguments fromt he command // line. // Get options (from command line and from configuration file); this // removes corresponding options and their arguments fromt he command // line. OptionManager om; try { GetOptions(om, argc, argv, pegasusHome); } catch (Exception& e) { cerr << argv[0] << ": " << e.getMessage() << endl; exit(1); } // Check to see if user asked for help (-h otpion): if (om.valueEquals("help", "true")) { String header = "Usage "; header.append(argv[0]); header.append(" -parameters host [host]"); String trailer = "Assumes localhost:5988 if host not specified"; trailer.append("\nHost may be of the form name or name:port"); trailer.append("\nPort 5988 assumed if port number missing."); om.printOptionsHelpTxt(header, trailer); exit(0); } String localNameSpace; om.lookupValue("namespace", localNameSpace); globalNamespace = localNameSpace; cout << "Namespace = " << localNameSpace << endl; String userName; om.lookupValue("user", userName); if (userName != String::EMPTY) { cout << "Username = "******"verbose"); String password; om.lookupValue("password", password); if (password != String::EMPTY) { cout << "password = "******"repeat", repeatTestCount)) repeatTestCount = 1; /* if (om.lookupValue("repeat", repeats)) { repeatTestCount = atol(repeats.getCString()); } else repeatTestCount = 1; */ if(verboseTest) cout << "Test repeat count " << repeatTestCount << endl; // Setup the active test flag. Determines if we change repository. Boolean activeTest = false; if (om.valueEquals("active", "true")) activeTest = true; // here we determine the list of systems to test. // All arguments remaining in argv go into list. Boolean localConnection = (om.valueEquals("local", "true"))? true: false; cout << "localConnection " << (localConnection ? "true" : "false") << endl; Array<String> connectionList; if (argc > 1 && !localConnection) for (Sint32 i = 1; i < argc; i++) connectionList.append(argv[i]); // substitute the default if no params if(argc < 2) connectionList.append("localhost:5988"); // Expand host to add port if not defined Boolean useSSL = om.isTrue("ssl"); // Show the connectionlist cout << "Connection List size " << connectionList.size() << endl; for (Uint32 i = 0; i < connectionList.size(); i++) cout << "Connection " << i << " address " << connectionList[i] << endl; for(Uint32 numTests = 1; numTests <= repeatTestCount; numTests++) { cout << "Test Repetition # " << numTests << endl; for (Uint32 i = 0; i < connectionList.size(); i++) { cout << "Start Try Block" << endl; try { cout << "Set Stopwatch" << endl; Stopwatch elapsedTime; cout << "Create client" << endl; CIMClient client; client.setTimeout(60 * 1000); cout << "Client created" << endl; // // Get host and port number from connection list entry // Uint32 index = connectionList[i].find (':'); String host = connectionList[i].subString (0, index); Uint32 portNumber = 0; if (index != PEG_NOT_FOUND) { String portStr = connectionList[i].subString (index + 1, connectionList[i].size ()); sscanf (portStr.getCString (), "%u", &portNumber); } if (useSSL) { // // Get environment variables: // const char* pegasusHome = getenv("PEGASUS_HOME"); String certpath = FileSystem::getAbsolutePath( pegasusHome, PEGASUS_SSLCLIENT_CERTIFICATEFILE); String randFile; #ifdef PEGASUS_SSL_RANDOMFILE randFile = FileSystem::getAbsolutePath( pegasusHome, PEGASUS_SSLCLIENT_RANDOMFILE); #endif SSLContext sslcontext(certpath,verifyServerCertificate, randFile); if (om.isTrue("local")) { cout << "Using local SSL connection mechanism " << endl; client.connectLocal(); } else { cout << "connecting to " << connectionList[i] << " using SSL" << endl; client.connect (host, portNumber, sslcontext, userName, password); } } else { if (om.isTrue("local")) { cout << "Using local connection mechanism " << endl; client.connectLocal(); } else { cout << "Connecting to " << connectionList[i] << endl; client.connect (host, portNumber, userName, password); } } cout << "Client Connected" << endl; testStart("Test NameSpace Operations - Relative Name"); elapsedTime.reset(); elapsedTime.start(); TestNamespaceHierarchy1(client, activeTest, verboseTest); elapsedTime.stop(); testEnd(elapsedTime.getElapsed()); testStart("Test NameSpace Operations - Absolute Name"); elapsedTime.reset(); elapsedTime.start(); TestNamespaceHierarchy2(client, activeTest, verboseTest); elapsedTime.stop(); testEnd(elapsedTime.getElapsed()); client.disconnect(); } catch(Exception& e) { PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl); exit(1); } } } PEGASUS_STD(cout) << "+++++ "<< argv[0] << " Terminated Normally" << PEGASUS_STD(endl); return 0; }