(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 REQUIRED_ARGS_MISSING [] =
 69                                      "Required arguments missing.";
 70                 static const char REQUIRED_ARGS_MISSING_KEY [] =
 71                                      "Clients.cimuser.CIMUserCommand.REQUIRED_ARGS_MISSING";
 72                 
 73                 static const char ERR_OPTION_NOT_SUPPORTED [] =
 74                                      "Invalid option. Use '--help' to obtain command syntax.";
 75                 
 76 j.alex      1.2 static const char ERR_OPTION_NOT_SUPPORTED_KEY[] =
 77                                      "Clients.cimuser.CIMUserCommand..ERR_OPTION_NOT_SUPPORTED";
 78                 
 79                 static const char ERR_USAGE [] =
 80                                      "Incorrect usage. Use '--help' to obtain command syntax.";
 81                 
 82                 static const char ERR_USAGE_KEY [] =
 83                                      "Clients.cimuser.CIMUserCommand..ERR_USAGE";
 84                 
 85                 
 86                 //
 87                 // exclude main from the Pegasus Namespace
 88                 //
 89                 PEGASUS_USING_PEGASUS;
 90                 PEGASUS_USING_STD;
 91                 
 92                 
 93                 int main (int argc, char* argv [])
 94                 {
 95                     char strTime[256];
 96                     struct tm tmTime;
 97 j.alex      1.2     int rc;
 98 kumpf       1.6     String fileName;
 99 j.alex      1.2     ofstream log_file;
100                 
101                 
102                     tmTime = getCurrentActualTime();
103                     strftime(strTime,256,"%d%m%Y%H%M%S.",&tmTime);
104                    
105 kumpf       1.3     StressTestControllerCommand command;
106 j.alex      1.2     
107                     //
108                     // Generate log files and PID files
109                     //
110                     if (!command.generateRequiredFileNames(strTime))
111                     {
112                         cout<<StressTestControllerCommand::COMMAND_NAME\
113                             <<"::Failed to generate required files for tests. "<<endl;
114                         command.removeUnusedFiles();
115 kumpf       1.6         return Command::RC_ERROR;
116 j.alex      1.2     }
117                 
118                     //
119                     // open the log file
120                     //
121                     OpenAppend(log_file,command.getStressTestLogFile());
122                 
123                     if (!log_file)
124                     {
125                        log_file.close();
126                        cout<<"Cannot get file "<<command.getStressTestLogFile()<<endl;
127                        command.removeUnusedFiles();
128 kumpf       1.6        return Command::RC_ERROR;
129 j.alex      1.2     }
130                     strftime(strTime,256,"%d/%m/%Y at %H:%M:%S\n",&tmTime);
131                     log_file<<StressTestControllerCommand::COMMAND_NAME\
132                         <<"::Initiated on "<<strTime<<endl;
133                     log_file<<StressTestControllerCommand::COMMAND_NAME\
134                         <<"::Process ID: "<<getpid()<<endl;
135                 
136                     try
137                     {
138                         log_file<<StressTestControllerCommand::COMMAND_NAME;
139                         log_file<<"::Geting Command Options."<<endl;
140                         if(verboseEnabled)
141                         {
142                            cout<<StressTestControllerCommand::COMMAND_NAME;
143                            cout<<"::Getting Command options."<<endl;
144                         }
145                         //
146                         // validate and set command arguments
147                         //
148                         command.setCommand (argc, argv);
149                     }
150 j.alex      1.2     catch (const CommandFormatException& cfe)
151                     {
152                         String msg(cfe.getMessage());
153                 
154                         log_file<< StressTestControllerCommand::COMMAND_NAME << "::" \
155                             << msg <<  endl;
156                         cerr<< StressTestControllerCommand::COMMAND_NAME << "::"\
157                             << msg <<  endl;
158                 
159                         if (msg.find(String("Unknown flag")) != PEG_NOT_FOUND)
160                         {
161                             
162                             cerr<< StressTestControllerCommand::COMMAND_NAME <<
163                                 "::" << ERR_OPTION_NOT_SUPPORTED << endl;
164                             log_file<< StressTestControllerCommand::COMMAND_NAME <<
165                                 "::" << ERR_OPTION_NOT_SUPPORTED << endl;
166                         }
167                         else
168                         {
169                             cerr<< StressTestControllerCommand::COMMAND_NAME <<
170                                 "::" << ERR_USAGE << endl;
171 j.alex      1.2             log_file<< StressTestControllerCommand::COMMAND_NAME <<
172                                 "::" << ERR_USAGE << endl;
173                         }
174                 
175                         log_file.close();
176                         command.removeUnusedFiles();
177 kumpf       1.6         return Command::RC_ERROR;
178 j.alex      1.2     }
179                     catch (...)
180                     {
181                         log_file<<StressTestControllerCommand::COMMAND_NAME<<
182                             "::Unknown exception caught when setting commands."<<endl;
183                         cerr<<StressTestControllerCommand::COMMAND_NAME<<
184                             "::Unknown exception caught when setting commands."<<endl;
185                         log_file.close();
186                         command.removeUnusedFiles();
187 kumpf       1.6         return Command::RC_ERROR;
188 j.alex      1.2     }
189                 
190                     //
191                     // For help or version options execute usage/version and 
192                     // exit
193                     //
194                     if ((command.getOperationType() == OPERATION_TYPE_HELP)
195                        ||(command.getOperationType() == OPERATION_TYPE_VERSION))
196                     {
197                         rc = command.execute (cout, cerr);
198                         log_file.close();
199                         // 
200                         // Log file not required when help or verbose is opted.
201                         //
202                         FileSystem::removeFile(command.getStressTestLogFile());
203 kumpf       1.6         return rc;
204 j.alex      1.2     }
205                 
206                     String filename;
207                 
208                     //
209                     // If a configuration file is specified then:
210                     //    Check if it exists as indicated, if not 
211                     //    also look for it in the default config dir.
212                     //
213                     if (command.IsConfigFilePathSpecified())
214                     {
215                         filename = command.getConfigFilePath();
216                         FileSystem::translateSlashes(filename);
217                         //
218                         // Check whether the file exists or not
219                         //
220                         if (!FileSystem::exists(filename))
221                         {
222                             //
223                             // Check for file in default directory as well
224                             //
225 kumpf       1.6             fileName = StressTestControllerCommand::DEFAULT_CFGDIR;
226 j.alex      1.2             fileName.append(filename);
227                 
228                             if (!FileSystem::exists(fileName))
229                             {
230                                 cerr << StressTestControllerCommand::COMMAND_NAME ;
231                                 cerr << "::Specified Configuration file \""<<filename;
232                                 cerr << "\" does not exist."<<endl;
233                                 log_file.close();
234                                 command.removeUnusedFiles();
235 kumpf       1.6                 return Command::RC_ERROR;
236 j.alex      1.2             }
237                             log_file<<StressTestControllerCommand::COMMAND_NAME<<
238                                 "::Using config file: "<<fileName<<endl;
239                         } 
240                         else
241 kumpf       1.6         {
242 j.alex      1.2             fileName = filename;
243                         }
244                 
245                         log_file<<StressTestControllerCommand::COMMAND_NAME<<
246                             "::Using config file: "<<fileName<<endl;
247                         cout<<StressTestControllerCommand::COMMAND_NAME<<
248                            "::Using config file: "<<fileName<<endl;
249                     } 
250                     else
251                     {
252                         //
253                         // Use default file in default dir.
254                         //
255 kumpf       1.6         fileName = StressTestControllerCommand::DEFAULT_CFGDIR;
256 j.alex      1.2         fileName.append(StressTestControllerCommand::FILENAME);
257                         //
258                         // Use hard coded default configuration values if default conf. file 
259                         // was not found.
260                         if (!FileSystem::exists(fileName))
261                         {
262                             //
263                             // Use Hard-coded default values
264                             //
265                             useDefaults = true;
266                         }
267                         else
268                         {
269                             log_file << StressTestControllerCommand::COMMAND_NAME <<
270                                 "::Using default file: " << fileName<<endl;
271                             cout << StressTestControllerCommand::COMMAND_NAME <<
272                                 "::Using default file: " << fileName<<endl;
273                         }
274                     }
275                    
276                     //
277 j.alex      1.2     // Read the contents of the file
278                     //
279                     try
280                     {
281                         //
282                         // Use Hard-coded default values
283                         //
284                         if (useDefaults)
285                         {
286                             log_file<<StressTestControllerCommand::COMMAND_NAME<<
287                                 "::Using hard coded default config values."<<endl;
288                             cout<<StressTestControllerCommand::COMMAND_NAME<<
289                                 "::Using hard coded default config values."<<endl;
290                             command.getDefaultClients(log_file);
291                         }
292                         else
293                         {
294                             log_file << StressTestControllerCommand::COMMAND_NAME <<
295                                 "::Reading config file: " << fileName<<endl;
296                             if (verboseEnabled)
297                             {
298 j.alex      1.2                 cout<< StressTestControllerCommand::COMMAND_NAME <<
299                                     "::Reading config file: " << fileName<<endl;
300                             }
301                             command.getFileContent(fileName,log_file);
302                         }
303                     }
304                     catch (NoSuchFile& e)
305                     {
306                         String msg(e.getMessage());
307                 
308                         log_file << StressTestControllerCommand::COMMAND_NAME << 
309                             ": " << msg <<  endl;
310                         cerr << StressTestControllerCommand::COMMAND_NAME <<
311                             ": " << msg <<  endl;
312                         log_file.close();
313                         command.removeUnusedFiles();
314 kumpf       1.6         return Command::RC_ERROR;
315 j.alex      1.2     }
316                     catch (Exception& e )
317                     {
318                         String msg(e.getMessage());
319                         log_file << StressTestControllerCommand::COMMAND_NAME << 
320                             "::" << msg <<  endl;
321                         cerr << StressTestControllerCommand::COMMAND_NAME << 
322                             "::Invalid Configuration ";
323                         cerr << "in File: " << fileName <<  endl;
324                         cerr << msg <<  endl;
325                         log_file.close();
326                         command.removeUnusedFiles();
327 kumpf       1.6         return Command::RC_ERROR;
328 j.alex      1.2     }
329                     catch (...)
330                     {
331                         log_file<<StressTestControllerCommand::COMMAND_NAME<<
332                             "::Unknown exception caught when acquiring configuration."<<endl;
333                         cerr<<StressTestControllerCommand::COMMAND_NAME<<
334                             "::Unknown exception caught when acquiring configuration."<<endl;
335                         log_file.close();
336                         command.removeUnusedFiles();
337 kumpf       1.6         return Command::RC_ERROR;
338 j.alex      1.2     }
339                 
340                     log_file << StressTestControllerCommand::COMMAND_NAME << 
341                         "::Generating Client Commands"<<  endl;
342                     if(verboseEnabled)
343                     {
344                         cout << StressTestControllerCommand::COMMAND_NAME <<
345                             "::Generating Client Commands"<<  endl;
346                     }
347                 
348                     // 
349                     // TimeStamp 
350                     //
351                     log_file<<StressTestControllerCommand::COMMAND_NAME<<
352                         "::Initiated on "<<strTime<<endl;
353                     log_file<<StressTestControllerCommand::COMMAND_NAME<<
354                         "::Process ID: "<<getpid()<<endl;
355                     cout<<StressTestControllerCommand::COMMAND_NAME<<
356                         "::Initiated on "<<strTime<<endl;
357                     cout<<StressTestControllerCommand::COMMAND_NAME<<
358                         "::Process ID: "<<getpid()<<endl;
359 j.alex      1.2 
360                     if(!command.generateClientCommands(log_file))
361                     {
362                         cerr << StressTestControllerCommand::COMMAND_NAME <<
363                             "::Failed to Generate Client Commands."<<  endl;
364                         log_file << StressTestControllerCommand::COMMAND_NAME <<
365                             "::Failed to Generate Client Commands."<<  endl;
366                         log_file.close();
367                         command.removeUnusedFiles();
368 kumpf       1.6         return Command::RC_ERROR;
369 j.alex      1.2     }
370                     
371                     //
372                     // Getting current time
373                     //
374                     tmTime = getCurrentActualTime();
375                     strftime(strTime,256,"%d/%m/%Y at %H:%M:%S\n",&tmTime);
376                     log_file << StressTestControllerCommand::COMMAND_NAME <<endl;
377                     log_file << "   Preparing to execute Clients on "<<strTime<<endl;
378                     
379                     //
380                     // Begin to run stress Tests 
381                     //
382                     rc = command.execute (cout, cerr);
383                     
384                     //
385                     // Getting current time after stress Tests are completed
386                     //
387                     tmTime = getCurrentActualTime();
388                     
389                     strftime(strTime,256,"%d/%m/%Y at %H:%M:%S\n",&tmTime);
390 j.alex      1.2     
391                     //
392                     // Check overall status of tests
393                     //
394                     if(rc)
395                     {
396                        log_file << StressTestControllerCommand::COMMAND_NAME;
397                        log_file << "::execution interrupted on "<<strTime<<endl;
398                        cout << StressTestControllerCommand::COMMAND_NAME;
399                        cout << "::execution interrupted on "<<strTime<<endl;
400                     } else {
401                        log_file << StressTestControllerCommand::COMMAND_NAME;
402                        log_file << "::successfully completed on "<<strTime<<endl;
403                        cout << StressTestControllerCommand::COMMAND_NAME;
404                        cout << "::successfully completed on "<<strTime<<endl;
405                     }
406                     cout <<"IMPORTANT: ";
407                     cout <<"Please check the Controller log file for additional info and the" 
408                          << endl;
409                     cout <<"           Client log file for individual errors which may or may "
410                          <<"not have "<< endl;
411 j.alex      1.2     cout <<"           caused a stress test failure. "<< endl;
412                     cout <<" Log Directory:"<<endl;
413                     cout <<"     "<<
414                         FileSystem::extractFilePath(command.getStressTestLogFile())<<endl;
415                     cout <<"\n Controller log: "<<
416                         FileSystem::extractFileName(command.getStressTestLogFile())<<endl;
417                     cout <<" Client log:     "<<
418                         FileSystem::extractFileName(command.getStressClientLogFile())<<endl;
419                     log_file.close();
420                     return rc;
421                 } /* main */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2