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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2