(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            // 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.2 #include <Pegasus/Common/FileSystem.h>
 44            
 45            //#define DEBUG
 46            #include <time.h>
 47            
 48            //
 49            // For Windows
 50            //
 51            #ifdef PEGASUS_OS_TYPE_WINDOWS
 52             // for DWORD etc.
 53             #include <windows.h>
 54             // getpid() and others
 55             typedef DWORD pid_t;
 56             #include <process.h>
 57            #elif !defined(PEGASUS_OS_OS400)
 58             #include <unistd.h>
 59            #endif
 60            
 61            
 62            /**
 63               Signal handler set up SIGALARM.
 64 j.alex 1.2 */
 65            static Boolean useDefaults = false;
 66            
 67            
 68            /**
 69               Message resource name
 70             */
 71            
 72            static const char REQUIRED_ARGS_MISSING [] =
 73                                 "Required arguments missing.";
 74            static const char REQUIRED_ARGS_MISSING_KEY [] =
 75                                 "Clients.cimuser.CIMUserCommand.REQUIRED_ARGS_MISSING";
 76            
 77            static const char ERR_OPTION_NOT_SUPPORTED [] =
 78                                 "Invalid option. Use '--help' to obtain command syntax.";
 79            
 80            static const char ERR_OPTION_NOT_SUPPORTED_KEY[] =
 81                                 "Clients.cimuser.CIMUserCommand..ERR_OPTION_NOT_SUPPORTED";
 82            
 83            static const char ERR_USAGE [] =
 84                                 "Incorrect usage. Use '--help' to obtain command syntax.";
 85 j.alex 1.2 
 86            static const char ERR_USAGE_KEY [] =
 87                                 "Clients.cimuser.CIMUserCommand..ERR_USAGE";
 88            
 89            
 90            //
 91            // exclude main from the Pegasus Namespace
 92            //
 93            PEGASUS_USING_PEGASUS;
 94            PEGASUS_USING_STD;
 95            
 96            
 97            int main (int argc, char* argv [])
 98            {
 99                char strTime[256];
100                struct tm tmTime;
101                int rc;
102                String fileName = String::EMPTY;
103                ofstream log_file;
104            
105            
106 j.alex 1.2     tmTime = getCurrentActualTime();
107                strftime(strTime,256,"%d%m%Y%H%M%S.",&tmTime);
108               
109                StressTestControllerCommand command=StressTestControllerCommand();
110                
111                //
112                // Generate log files and PID files
113                //
114                if (!command.generateRequiredFileNames(strTime))
115                {
116                    cout<<StressTestControllerCommand::COMMAND_NAME\
117                        <<"::Failed to generate required files for tests. "<<endl;
118                    command.removeUnusedFiles();
119                    exit (Command::RC_ERROR);
120                }
121            
122                //
123                // open the log file
124                //
125                OpenAppend(log_file,command.getStressTestLogFile());
126            
127 j.alex 1.2     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                log_file<<StressTestControllerCommand::COMMAND_NAME\
136                    <<"::Initiated on "<<strTime<<endl;
137                log_file<<StressTestControllerCommand::COMMAND_NAME\
138                    <<"::Process ID: "<<getpid()<<endl;
139            
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 j.alex 1.2         }
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                    log_file<< StressTestControllerCommand::COMMAND_NAME << "::" \
159                        << msg <<  endl;
160                    cerr<< StressTestControllerCommand::COMMAND_NAME << "::"\
161                        << msg <<  endl;
162            
163                    if (msg.find(String("Unknown flag")) != PEG_NOT_FOUND)
164                    {
165                        
166                        cerr<< StressTestControllerCommand::COMMAND_NAME <<
167                            "::" << ERR_OPTION_NOT_SUPPORTED << endl;
168                        log_file<< StressTestControllerCommand::COMMAND_NAME <<
169 j.alex 1.2                 "::" << ERR_OPTION_NOT_SUPPORTED << endl;
170                    }
171                    else
172                    {
173                        cerr<< StressTestControllerCommand::COMMAND_NAME <<
174                            "::" << ERR_USAGE << endl;
175                        log_file<< StressTestControllerCommand::COMMAND_NAME <<
176                            "::" << ERR_USAGE << endl;
177                    }
178            
179                    log_file.close();
180                    command.removeUnusedFiles();
181                    exit (Command::RC_ERROR);
182                }
183                catch (...)
184                {
185                    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                    log_file.close();
190 j.alex 1.2         command.removeUnusedFiles();
191                    exit (Command::RC_ERROR);
192                }
193            
194                //
195                // For help or version options execute usage/version and 
196                // exit
197                //
198                if ((command.getOperationType() == OPERATION_TYPE_HELP)
199                   ||(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 j.alex 1.2 
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                if (command.IsConfigFilePathSpecified())
218                {
219                    filename = command.getConfigFilePath();
220                    FileSystem::translateSlashes(filename);
221                    //
222                    // Check whether the file exists or not
223                    //
224                    if (!FileSystem::exists(filename))
225                    {
226                        //
227                        // Check for file in default directory as well
228                        //
229                        fileName = String::EMPTY;
230                        fileName.append(StressTestControllerCommand::DEFAULT_CFGDIR);
231                        fileName.append(filename);
232 j.alex 1.2 
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            
250                    log_file<<StressTestControllerCommand::COMMAND_NAME<<
251                        "::Using config file: "<<fileName<<endl;
252                    cout<<StressTestControllerCommand::COMMAND_NAME<<
253 j.alex 1.2            "::Using config file: "<<fileName<<endl;
254                } 
255                else
256                {
257                    //
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                        //
269                        // Use Hard-coded default values
270                        //
271                        useDefaults = true;
272                    }
273                    else
274 j.alex 1.2         {
275                        log_file << StressTestControllerCommand::COMMAND_NAME <<
276                            "::Using default file: " << fileName<<endl;
277                        cout << StressTestControllerCommand::COMMAND_NAME <<
278                            "::Using default file: " << fileName<<endl;
279                    }
280                }
281               
282                //
283                // Read the contents of the file
284                //
285                try
286                {
287                    //
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 j.alex 1.2                 "::Using hard coded default config values."<<endl;
296                        command.getDefaultClients(log_file);
297                    }
298                    else
299                    {
300                        log_file << StressTestControllerCommand::COMMAND_NAME <<
301                            "::Reading config file: " << fileName<<endl;
302                        if (verboseEnabled)
303                        {
304                            cout<< StressTestControllerCommand::COMMAND_NAME <<
305                                "::Reading config file: " << fileName<<endl;
306                        }
307                        command.getFileContent(fileName,log_file);
308                    }
309                }
310                catch (NoSuchFile& e)
311                {
312                    String msg(e.getMessage());
313            
314                    log_file << StressTestControllerCommand::COMMAND_NAME << 
315                        ": " << msg <<  endl;
316 j.alex 1.2         cerr << StressTestControllerCommand::COMMAND_NAME <<
317                        ": " << msg <<  endl;
318                    log_file.close();
319                    command.removeUnusedFiles();
320                    exit (Command::RC_ERROR);
321            
322                }
323                catch (Exception& e )
324                {
325                    String msg(e.getMessage());
326                    log_file << StressTestControllerCommand::COMMAND_NAME << 
327                        "::" << msg <<  endl;
328                    cerr << StressTestControllerCommand::COMMAND_NAME << 
329                        "::Invalid Configuration ";
330                    cerr << "in File: " << fileName <<  endl;
331                    cerr << msg <<  endl;
332                    log_file.close();
333                    command.removeUnusedFiles();
334                    exit (Command::RC_ERROR);
335                }
336                catch (...)
337 j.alex 1.2     {
338                    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                    log_file.close();
343                    command.removeUnusedFiles();
344                    exit (Command::RC_ERROR);
345                }
346            
347                log_file << StressTestControllerCommand::COMMAND_NAME << 
348                    "::Generating Client Commands"<<  endl;
349                if(verboseEnabled)
350                {
351                    cout << StressTestControllerCommand::COMMAND_NAME <<
352                        "::Generating Client Commands"<<  endl;
353                }
354            
355                // 
356                // TimeStamp 
357                //
358 j.alex 1.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            
367                if(!command.generateClientCommands(log_file))
368                {
369                    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                }
377                
378                //
379 j.alex 1.2     // 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                
386                //
387                // Begin to run stress Tests 
388                //
389                rc = command.execute (cout, cerr);
390                
391                //
392                // Getting current time after stress Tests are completed
393                //
394                tmTime = getCurrentActualTime();
395                
396                strftime(strTime,256,"%d/%m/%Y at %H:%M:%S\n",&tmTime);
397                
398                //
399                // Check overall status of tests
400 j.alex 1.2     //
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                cout <<"IMPORTANT: ";
414                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                cout <<" Log Directory:"<<endl;
420                cout <<"     "<<
421 j.alex 1.2         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                log_file.close();
427                exit (rc);
428                return rc;
429            } /* main */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2