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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2