(file) Return to StressTestControllerMain.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / test / StressTestController

  1 j.alex 1.2 //%2006////////////////////////////////////////////////////////////////////////
  2            //
  3            // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4            // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5            // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6            // IBM Corp.; EMC Corporation, The Open Group.
  7            // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8            // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9            // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10            // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11            // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12            // EMC Corporation; Symantec Corporation; The Open Group.
 13            //
 14            // Permission is hereby granted, free of charge, to any person obtaining a copy
 15            // of this software and associated documentation files (the "Software"), to
 16            // deal in the Software without restriction, including without limitation the
 17            // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18            // sell copies of the Software, and to permit persons to whom the Software is
 19            // furnished to do so, subject to the following conditions:
 20            //
 21            // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22 j.alex 1.2 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23            // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24            // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25            // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26            // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27            // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28            // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29            //
 30            //==============================================================================
 31            //
 32            //%/////////////////////////////////////////////////////////////////////////////
 33            
 34            #include <iostream>
 35            #include <Pegasus/getoopt/getoopt.h>
 36            #include <Clients/cliutils/CommandException.h>
 37            #include "StressTestController.h"
 38            #include <Pegasus/Common/TimeValue.h>
 39            #include <Pegasus/Common/FileSystem.h>
 40            
 41            //#define DEBUG
 42            #include <time.h>
 43 j.alex 1.2 
 44            //
 45            // For Windows
 46            //
 47            #ifdef PEGASUS_OS_TYPE_WINDOWS
 48             // for DWORD etc.
 49 kumpf  1.5 # include <windows.h>
 50 j.alex 1.2  // getpid() and others
 51             typedef DWORD pid_t;
 52 kumpf  1.5 # include <process.h>
 53 ouyang.jian 1.4 #else
 54 kumpf       1.5 # include <unistd.h>
 55 j.alex      1.2 #endif
 56                 
 57                 
 58                 /**
 59                    Signal handler set up SIGALARM.
 60                 */
 61                 static Boolean useDefaults = false;
 62                 
 63                 
 64                 /**
 65                    Message resource name
 66                  */
 67                 
 68                 static const char ERR_OPTION_NOT_SUPPORTED [] =
 69 mike        1.6.4.1     "Invalid option. Use '--help' to obtain command syntax.";
 70 j.alex      1.2     
 71                     static const char ERR_USAGE [] =
 72 mike        1.6.4.1     "Incorrect usage. Use '--help' to obtain command syntax.";
 73 j.alex      1.2     
 74                     
 75                     //
 76                     // exclude main from the Pegasus Namespace
 77                     //
 78                     PEGASUS_USING_PEGASUS;
 79                     PEGASUS_USING_STD;
 80                     
 81                     
 82                     int main (int argc, char* argv [])
 83                     {
 84                         char strTime[256];
 85                         struct tm tmTime;
 86                         int rc;
 87 kumpf       1.6         String fileName;
 88 j.alex      1.2         ofstream log_file;
 89                     
 90                     
 91                         tmTime = getCurrentActualTime();
 92                         strftime(strTime,256,"%d%m%Y%H%M%S.",&tmTime);
 93                        
 94 kumpf       1.3         StressTestControllerCommand command;
 95 j.alex      1.2         
 96                         //
 97                         // Generate log files and PID files
 98                         //
 99                         if (!command.generateRequiredFileNames(strTime))
100                         {
101                             cout<<StressTestControllerCommand::COMMAND_NAME\
102                                 <<"::Failed to generate required files for tests. "<<endl;
103                             command.removeUnusedFiles();
104 kumpf       1.6             return Command::RC_ERROR;
105 j.alex      1.2         }
106                     
107                         //
108                         // open the log file
109                         //
110                         OpenAppend(log_file,command.getStressTestLogFile());
111                     
112                         if (!log_file)
113                         {
114                            log_file.close();
115                            cout<<"Cannot get file "<<command.getStressTestLogFile()<<endl;
116                            command.removeUnusedFiles();
117 kumpf       1.6            return Command::RC_ERROR;
118 j.alex      1.2         }
119                         strftime(strTime,256,"%d/%m/%Y at %H:%M:%S\n",&tmTime);
120                         log_file<<StressTestControllerCommand::COMMAND_NAME\
121                             <<"::Initiated on "<<strTime<<endl;
122                         log_file<<StressTestControllerCommand::COMMAND_NAME\
123                             <<"::Process ID: "<<getpid()<<endl;
124                     
125                         try
126                         {
127                             log_file<<StressTestControllerCommand::COMMAND_NAME;
128                             log_file<<"::Geting Command Options."<<endl;
129                             if(verboseEnabled)
130                             {
131                                cout<<StressTestControllerCommand::COMMAND_NAME;
132                                cout<<"::Getting Command options."<<endl;
133                             }
134                             //
135                             // validate and set command arguments
136                             //
137                             command.setCommand (argc, argv);
138                         }
139 j.alex      1.2         catch (const CommandFormatException& cfe)
140                         {
141                             String msg(cfe.getMessage());
142                     
143                             log_file<< StressTestControllerCommand::COMMAND_NAME << "::" \
144                                 << msg <<  endl;
145                             cerr<< StressTestControllerCommand::COMMAND_NAME << "::"\
146                                 << msg <<  endl;
147                     
148                             if (msg.find(String("Unknown flag")) != PEG_NOT_FOUND)
149                             {
150                                 
151                                 cerr<< StressTestControllerCommand::COMMAND_NAME <<
152                                     "::" << ERR_OPTION_NOT_SUPPORTED << endl;
153                                 log_file<< StressTestControllerCommand::COMMAND_NAME <<
154                                     "::" << ERR_OPTION_NOT_SUPPORTED << endl;
155                             }
156                             else
157                             {
158                                 cerr<< StressTestControllerCommand::COMMAND_NAME <<
159                                     "::" << ERR_USAGE << endl;
160 j.alex      1.2                 log_file<< StressTestControllerCommand::COMMAND_NAME <<
161                                     "::" << ERR_USAGE << endl;
162                             }
163                     
164                             log_file.close();
165                             command.removeUnusedFiles();
166 kumpf       1.6             return Command::RC_ERROR;
167 j.alex      1.2         }
168                         catch (...)
169                         {
170                             log_file<<StressTestControllerCommand::COMMAND_NAME<<
171                                 "::Unknown exception caught when setting commands."<<endl;
172                             cerr<<StressTestControllerCommand::COMMAND_NAME<<
173                                 "::Unknown exception caught when setting commands."<<endl;
174                             log_file.close();
175                             command.removeUnusedFiles();
176 kumpf       1.6             return Command::RC_ERROR;
177 j.alex      1.2         }
178                     
179                         //
180                         // For help or version options execute usage/version and 
181                         // exit
182                         //
183                         if ((command.getOperationType() == OPERATION_TYPE_HELP)
184                            ||(command.getOperationType() == OPERATION_TYPE_VERSION))
185                         {
186                             rc = command.execute (cout, cerr);
187                             log_file.close();
188                             // 
189                             // Log file not required when help or verbose is opted.
190                             //
191                             FileSystem::removeFile(command.getStressTestLogFile());
192 kumpf       1.6             return rc;
193 j.alex      1.2         }
194                     
195                         String filename;
196                     
197                         //
198                         // If a configuration file is specified then:
199                         //    Check if it exists as indicated, if not 
200                         //    also look for it in the default config dir.
201                         //
202                         if (command.IsConfigFilePathSpecified())
203                         {
204                             filename = command.getConfigFilePath();
205                             FileSystem::translateSlashes(filename);
206                             //
207                             // Check whether the file exists or not
208                             //
209                             if (!FileSystem::exists(filename))
210                             {
211                                 //
212                                 // Check for file in default directory as well
213                                 //
214 kumpf       1.6                 fileName = StressTestControllerCommand::DEFAULT_CFGDIR;
215 j.alex      1.2                 fileName.append(filename);
216                     
217                                 if (!FileSystem::exists(fileName))
218                                 {
219                                     cerr << StressTestControllerCommand::COMMAND_NAME ;
220                                     cerr << "::Specified Configuration file \""<<filename;
221                                     cerr << "\" does not exist."<<endl;
222                                     log_file.close();
223                                     command.removeUnusedFiles();
224 kumpf       1.6                     return Command::RC_ERROR;
225 j.alex      1.2                 }
226                                 log_file<<StressTestControllerCommand::COMMAND_NAME<<
227                                     "::Using config file: "<<fileName<<endl;
228                             } 
229                             else
230 kumpf       1.6             {
231 j.alex      1.2                 fileName = filename;
232                             }
233                     
234                             log_file<<StressTestControllerCommand::COMMAND_NAME<<
235                                 "::Using config file: "<<fileName<<endl;
236                             cout<<StressTestControllerCommand::COMMAND_NAME<<
237                                "::Using config file: "<<fileName<<endl;
238                         } 
239                         else
240                         {
241                             //
242                             // Use default file in default dir.
243                             //
244 kumpf       1.6             fileName = StressTestControllerCommand::DEFAULT_CFGDIR;
245 j.alex      1.2             fileName.append(StressTestControllerCommand::FILENAME);
246                             //
247                             // Use hard coded default configuration values if default conf. file 
248                             // was not found.
249                             if (!FileSystem::exists(fileName))
250                             {
251                                 //
252                                 // Use Hard-coded default values
253                                 //
254                                 useDefaults = true;
255                             }
256                             else
257                             {
258                                 log_file << StressTestControllerCommand::COMMAND_NAME <<
259                                     "::Using default file: " << fileName<<endl;
260                                 cout << StressTestControllerCommand::COMMAND_NAME <<
261                                     "::Using default file: " << fileName<<endl;
262                             }
263                         }
264                        
265                         //
266 j.alex      1.2         // Read the contents of the file
267                         //
268                         try
269                         {
270                             //
271                             // Use Hard-coded default values
272                             //
273                             if (useDefaults)
274                             {
275                                 log_file<<StressTestControllerCommand::COMMAND_NAME<<
276                                     "::Using hard coded default config values."<<endl;
277                                 cout<<StressTestControllerCommand::COMMAND_NAME<<
278                                     "::Using hard coded default config values."<<endl;
279                                 command.getDefaultClients(log_file);
280                             }
281                             else
282                             {
283                                 log_file << StressTestControllerCommand::COMMAND_NAME <<
284                                     "::Reading config file: " << fileName<<endl;
285                                 if (verboseEnabled)
286                                 {
287 j.alex      1.2                     cout<< StressTestControllerCommand::COMMAND_NAME <<
288                                         "::Reading config file: " << fileName<<endl;
289                                 }
290                                 command.getFileContent(fileName,log_file);
291                             }
292                         }
293                         catch (NoSuchFile& e)
294                         {
295                             String msg(e.getMessage());
296                     
297                             log_file << StressTestControllerCommand::COMMAND_NAME << 
298                                 ": " << msg <<  endl;
299                             cerr << StressTestControllerCommand::COMMAND_NAME <<
300                                 ": " << msg <<  endl;
301                             log_file.close();
302                             command.removeUnusedFiles();
303 kumpf       1.6             return Command::RC_ERROR;
304 j.alex      1.2         }
305                         catch (Exception& e )
306                         {
307                             String msg(e.getMessage());
308                             log_file << StressTestControllerCommand::COMMAND_NAME << 
309                                 "::" << msg <<  endl;
310                             cerr << StressTestControllerCommand::COMMAND_NAME << 
311                                 "::Invalid Configuration ";
312                             cerr << "in File: " << fileName <<  endl;
313                             cerr << msg <<  endl;
314                             log_file.close();
315                             command.removeUnusedFiles();
316 kumpf       1.6             return Command::RC_ERROR;
317 j.alex      1.2         }
318                         catch (...)
319                         {
320                             log_file<<StressTestControllerCommand::COMMAND_NAME<<
321                                 "::Unknown exception caught when acquiring configuration."<<endl;
322                             cerr<<StressTestControllerCommand::COMMAND_NAME<<
323                                 "::Unknown exception caught when acquiring configuration."<<endl;
324                             log_file.close();
325                             command.removeUnusedFiles();
326 kumpf       1.6             return Command::RC_ERROR;
327 j.alex      1.2         }
328                     
329                         log_file << StressTestControllerCommand::COMMAND_NAME << 
330                             "::Generating Client Commands"<<  endl;
331                         if(verboseEnabled)
332                         {
333                             cout << StressTestControllerCommand::COMMAND_NAME <<
334                                 "::Generating Client Commands"<<  endl;
335                         }
336                     
337                         // 
338                         // TimeStamp 
339                         //
340                         log_file<<StressTestControllerCommand::COMMAND_NAME<<
341                             "::Initiated on "<<strTime<<endl;
342                         log_file<<StressTestControllerCommand::COMMAND_NAME<<
343                             "::Process ID: "<<getpid()<<endl;
344                         cout<<StressTestControllerCommand::COMMAND_NAME<<
345                             "::Initiated on "<<strTime<<endl;
346                         cout<<StressTestControllerCommand::COMMAND_NAME<<
347                             "::Process ID: "<<getpid()<<endl;
348 j.alex      1.2     
349                         if(!command.generateClientCommands(log_file))
350                         {
351                             cerr << StressTestControllerCommand::COMMAND_NAME <<
352                                 "::Failed to Generate Client Commands."<<  endl;
353                             log_file << StressTestControllerCommand::COMMAND_NAME <<
354                                 "::Failed to Generate Client Commands."<<  endl;
355                             log_file.close();
356                             command.removeUnusedFiles();
357 kumpf       1.6             return Command::RC_ERROR;
358 j.alex      1.2         }
359                         
360                         //
361                         // Getting current time
362                         //
363                         tmTime = getCurrentActualTime();
364                         strftime(strTime,256,"%d/%m/%Y at %H:%M:%S\n",&tmTime);
365                         log_file << StressTestControllerCommand::COMMAND_NAME <<endl;
366                         log_file << "   Preparing to execute Clients on "<<strTime<<endl;
367                         
368                         //
369                         // Begin to run stress Tests 
370                         //
371                         rc = command.execute (cout, cerr);
372                         
373                         //
374                         // Getting current time after stress Tests are completed
375                         //
376                         tmTime = getCurrentActualTime();
377                         
378                         strftime(strTime,256,"%d/%m/%Y at %H:%M:%S\n",&tmTime);
379 j.alex      1.2         
380                         //
381                         // Check overall status of tests
382                         //
383                         if(rc)
384                         {
385                            log_file << StressTestControllerCommand::COMMAND_NAME;
386                            log_file << "::execution interrupted on "<<strTime<<endl;
387                            cout << StressTestControllerCommand::COMMAND_NAME;
388                            cout << "::execution interrupted on "<<strTime<<endl;
389                         } else {
390                            log_file << StressTestControllerCommand::COMMAND_NAME;
391                            log_file << "::successfully completed on "<<strTime<<endl;
392                            cout << StressTestControllerCommand::COMMAND_NAME;
393                            cout << "::successfully completed on "<<strTime<<endl;
394                         }
395                         cout <<"IMPORTANT: ";
396                         cout <<"Please check the Controller log file for additional info and the" 
397                              << endl;
398                         cout <<"           Client log file for individual errors which may or may "
399                              <<"not have "<< endl;
400 j.alex      1.2         cout <<"           caused a stress test failure. "<< endl;
401                         cout <<" Log Directory:"<<endl;
402                         cout <<"     "<<
403                             FileSystem::extractFilePath(command.getStressTestLogFile())<<endl;
404                         cout <<"\n Controller log: "<<
405                             FileSystem::extractFileName(command.getStressTestLogFile())<<endl;
406                         cout <<" Client log:     "<<
407                             FileSystem::extractFileName(command.getStressClientLogFile())<<endl;
408                         log_file.close();
409                         return rc;
410                     } /* main */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2