(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             #include <windows.h>
 50             // getpid() and others
 51             typedef DWORD pid_t;
 52             #include <process.h>
 53            #elif !defined(PEGASUS_OS_OS400)
 54             #include <unistd.h>
 55            #endif
 56            
 57            
 58            /**
 59               Signal handler set up SIGALARM.
 60            */
 61            static Boolean useDefaults = false;
 62            
 63            
 64 j.alex 1.2 /**
 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            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 j.alex 1.2 
 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                int rc;
 98                String fileName = String::EMPTY;
 99                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                    exit (Command::RC_ERROR);
116                }
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 j.alex 1.2        command.removeUnusedFiles();
128                   exit (Command::RC_ERROR);
129                }
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 j.alex 1.2         command.setCommand (argc, argv);
149                }
150                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 j.alex 1.2             cerr<< StressTestControllerCommand::COMMAND_NAME <<
170                            "::" << ERR_USAGE << endl;
171                        log_file<< StressTestControllerCommand::COMMAND_NAME <<
172                            "::" << ERR_USAGE << endl;
173                    }
174            
175                    log_file.close();
176                    command.removeUnusedFiles();
177                    exit (Command::RC_ERROR);
178                }
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                    exit (Command::RC_ERROR);
188                }
189            
190 j.alex 1.2     //
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                    exit (rc);
204                }
205            
206                String filename;
207            
208                //
209                // If a configuration file is specified then:
210                //    Check if it exists as indicated, if not 
211 j.alex 1.2     //    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                        fileName = String::EMPTY;
226                        fileName.append(StressTestControllerCommand::DEFAULT_CFGDIR);
227                        fileName.append(filename);
228            
229                        if (!FileSystem::exists(fileName))
230                        {
231                            cerr << StressTestControllerCommand::COMMAND_NAME ;
232 j.alex 1.2                 cerr << "::Specified Configuration file \""<<filename;
233                            cerr << "\" does not exist."<<endl;
234                            log_file.close();
235                            command.removeUnusedFiles();
236                            exit (Command::RC_ERROR);
237                        }
238                        log_file<<StressTestControllerCommand::COMMAND_NAME<<
239                            "::Using config file: "<<fileName<<endl;
240                    } 
241                    else
242                    { 
243                        fileName = filename;
244                    }
245            
246                    log_file<<StressTestControllerCommand::COMMAND_NAME<<
247                        "::Using config file: "<<fileName<<endl;
248                    cout<<StressTestControllerCommand::COMMAND_NAME<<
249                       "::Using config file: "<<fileName<<endl;
250                } 
251                else
252                {
253 j.alex 1.2         //
254                    // Use default file in default dir.
255                    //
256                    fileName = String::EMPTY;
257                    fileName.append(StressTestControllerCommand::DEFAULT_CFGDIR);
258                    fileName.append(StressTestControllerCommand::FILENAME);
259                    //
260                    // Use hard coded default configuration values if default conf. file 
261                    // was not found.
262                    if (!FileSystem::exists(fileName))
263                    {
264                        //
265                        // Use Hard-coded default values
266                        //
267                        useDefaults = true;
268                    }
269                    else
270                    {
271                        log_file << StressTestControllerCommand::COMMAND_NAME <<
272                            "::Using default file: " << fileName<<endl;
273                        cout << StressTestControllerCommand::COMMAND_NAME <<
274 j.alex 1.2                 "::Using default file: " << fileName<<endl;
275                    }
276                }
277               
278                //
279                // Read the contents of the file
280                //
281                try
282                {
283                    //
284                    // Use Hard-coded default values
285                    //
286                    if (useDefaults)
287                    {
288                        log_file<<StressTestControllerCommand::COMMAND_NAME<<
289                            "::Using hard coded default config values."<<endl;
290                        cout<<StressTestControllerCommand::COMMAND_NAME<<
291                            "::Using hard coded default config values."<<endl;
292                        command.getDefaultClients(log_file);
293                    }
294                    else
295 j.alex 1.2         {
296                        log_file << StressTestControllerCommand::COMMAND_NAME <<
297                            "::Reading config file: " << fileName<<endl;
298                        if (verboseEnabled)
299                        {
300                            cout<< StressTestControllerCommand::COMMAND_NAME <<
301                                "::Reading config file: " << fileName<<endl;
302                        }
303                        command.getFileContent(fileName,log_file);
304                    }
305                }
306                catch (NoSuchFile& e)
307                {
308                    String msg(e.getMessage());
309            
310                    log_file << StressTestControllerCommand::COMMAND_NAME << 
311                        ": " << msg <<  endl;
312                    cerr << StressTestControllerCommand::COMMAND_NAME <<
313                        ": " << msg <<  endl;
314                    log_file.close();
315                    command.removeUnusedFiles();
316 j.alex 1.2         exit (Command::RC_ERROR);
317            
318                }
319                catch (Exception& e )
320                {
321                    String msg(e.getMessage());
322                    log_file << StressTestControllerCommand::COMMAND_NAME << 
323                        "::" << msg <<  endl;
324                    cerr << StressTestControllerCommand::COMMAND_NAME << 
325                        "::Invalid Configuration ";
326                    cerr << "in File: " << fileName <<  endl;
327                    cerr << msg <<  endl;
328                    log_file.close();
329                    command.removeUnusedFiles();
330                    exit (Command::RC_ERROR);
331                }
332                catch (...)
333                {
334                    log_file<<StressTestControllerCommand::COMMAND_NAME<<
335                        "::Unknown exception caught when acquiring configuration."<<endl;
336                    cerr<<StressTestControllerCommand::COMMAND_NAME<<
337 j.alex 1.2             "::Unknown exception caught when acquiring configuration."<<endl;
338                    log_file.close();
339                    command.removeUnusedFiles();
340                    exit (Command::RC_ERROR);
341                }
342            
343                log_file << StressTestControllerCommand::COMMAND_NAME << 
344                    "::Generating Client Commands"<<  endl;
345                if(verboseEnabled)
346                {
347                    cout << StressTestControllerCommand::COMMAND_NAME <<
348                        "::Generating Client Commands"<<  endl;
349                }
350            
351                // 
352                // TimeStamp 
353                //
354                log_file<<StressTestControllerCommand::COMMAND_NAME<<
355                    "::Initiated on "<<strTime<<endl;
356                log_file<<StressTestControllerCommand::COMMAND_NAME<<
357                    "::Process ID: "<<getpid()<<endl;
358 j.alex 1.2     cout<<StressTestControllerCommand::COMMAND_NAME<<
359                    "::Initiated on "<<strTime<<endl;
360                cout<<StressTestControllerCommand::COMMAND_NAME<<
361                    "::Process ID: "<<getpid()<<endl;
362            
363                if(!command.generateClientCommands(log_file))
364                {
365                    cerr << StressTestControllerCommand::COMMAND_NAME <<
366                        "::Failed to Generate Client Commands."<<  endl;
367                    log_file << StressTestControllerCommand::COMMAND_NAME <<
368                        "::Failed to Generate Client Commands."<<  endl;
369                    log_file.close();
370                    command.removeUnusedFiles();
371                    exit (Command::RC_ERROR);
372                }
373                
374                //
375                // Getting current time
376                //
377                tmTime = getCurrentActualTime();
378                strftime(strTime,256,"%d/%m/%Y at %H:%M:%S\n",&tmTime);
379 j.alex 1.2     log_file << StressTestControllerCommand::COMMAND_NAME <<endl;
380                log_file << "   Preparing to execute Clients on "<<strTime<<endl;
381                
382                //
383                // Begin to run stress Tests 
384                //
385                rc = command.execute (cout, cerr);
386                
387                //
388                // Getting current time after stress Tests are completed
389                //
390                tmTime = getCurrentActualTime();
391                
392                strftime(strTime,256,"%d/%m/%Y at %H:%M:%S\n",&tmTime);
393                
394                //
395                // Check overall status of tests
396                //
397                if(rc)
398                {
399                   log_file << StressTestControllerCommand::COMMAND_NAME;
400 j.alex 1.2        log_file << "::execution interrupted on "<<strTime<<endl;
401                   cout << StressTestControllerCommand::COMMAND_NAME;
402                   cout << "::execution interrupted on "<<strTime<<endl;
403                } else {
404                   log_file << StressTestControllerCommand::COMMAND_NAME;
405                   log_file << "::successfully completed on "<<strTime<<endl;
406                   cout << StressTestControllerCommand::COMMAND_NAME;
407                   cout << "::successfully completed on "<<strTime<<endl;
408                }
409                cout <<"IMPORTANT: ";
410                cout <<"Please check the Controller log file for additional info and the" 
411                     << endl;
412                cout <<"           Client log file for individual errors which may or may "
413                     <<"not have "<< endl;
414                cout <<"           caused a stress test failure. "<< endl;
415                cout <<" Log Directory:"<<endl;
416                cout <<"     "<<
417                    FileSystem::extractFilePath(command.getStressTestLogFile())<<endl;
418                cout <<"\n Controller log: "<<
419                    FileSystem::extractFileName(command.getStressTestLogFile())<<endl;
420                cout <<" Client log:     "<<
421 j.alex 1.2         FileSystem::extractFileName(command.getStressClientLogFile())<<endl;
422                log_file.close();
423                exit (rc);
424                return rc;
425            } /* main */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2