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

   1 martin 1.12 //%LICENSE////////////////////////////////////////////////////////////////
   2 martin 1.13 //
   3 martin 1.12 // 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.13 //
  10 martin 1.12 // 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.13 //
  17 martin 1.12 // The above copyright notice and this permission notice shall be included
  18             // in all copies or substantial portions of the Software.
  19 martin 1.13 //
  20 martin 1.12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  21 martin 1.13 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22 martin 1.12 // 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.13 //
  28 martin 1.12 //////////////////////////////////////////////////////////////////////////
  29 j.alex 1.2  //
  30             //%/////////////////////////////////////////////////////////////////////////////
  31             
  32             #include <iostream>
  33             #include <Pegasus/Common/Config.h>
  34             #include <Pegasus/Common/Constants.h>
  35             #include <Pegasus/Common/System.h>
  36             #include <Pegasus/Common/PegasusVersion.h>
  37             #include <Pegasus/Common/SSLContext.h>
  38             #include <Pegasus/getoopt/getoopt.h>
  39             #include <Pegasus/Common/String.h>
  40             #include <Pegasus/Client/CIMClient.h>
  41             #include <Pegasus/Common/FileSystem.h>
  42             #include <Pegasus/Common/TimeValue.h>
  43             #include <time.h>
  44             #include <signal.h>
  45             #include "StressTestController.h"
  46             #include "StressTestControllerException.h"
  47             //
  48             //Windows
  49             //
  50 j.alex 1.2  #ifdef PEGASUS_OS_TYPE_WINDOWS
  51              // for DWORD etc.
  52 kumpf  1.7  # include <windows.h>
  53 kamal.locahana 1.5   // getpid() and others
  54                      typedef DWORD pid_t;
  55 kumpf          1.7  # include <process.h>
  56 ouyang.jian    1.6  #else
  57 kumpf          1.7  # include <unistd.h>
  58 j.alex         1.2  #endif
  59                     
  60 j.alex         1.3  //#define STRESSTEST_DEBUG
  61 j.alex         1.2  
  62                     #define SIXTYSECONDS 60
  63                     #define MILLISECONDS 1000
  64                     #define CHECKUP_INTERVAL 1
  65 kamal.locahana 1.5  #define STOP_DELAY 1
  66                     #define SHUTDOWN_DELAY 5
  67                     #define RUN_DELAY 1
  68 j.alex         1.2  #define DEFAULT_INSTANCE "5"
  69                     
  70                     #define convertmin2millisecs(x) (x * SIXTYSECONDS * MILLISECONDS)
  71                     #define getToleranceInPercent(x,y) (100 - (((y-x)/y) * 100))
  72                     
  73                     
  74                     
  75                     static void endAllTests(int signum);
  76                     
  77                     static void cleanupProcess();
  78                     
  79                     static String convertUint64toString(Uint64 x);
  80                     
  81                     
  82                     PEGASUS_NAMESPACE_BEGIN
  83                     PEGASUS_USING_PEGASUS;
  84                     PEGASUS_USING_STD;
  85                     
  86                     
  87                     
  88                     /**
  89 j.alex         1.2    Log file descripter
  90                     */
  91                     
  92                     /**
  93 kamal.locahana 1.5     variable for Signal handler
  94 j.alex         1.2  */
  95                     static Boolean Quit = false;
  96                     
  97                     /**
  98                         The command name.
  99                      */
 100 kamal.locahana 1.5  const char StressTestControllerCommand::COMMAND_NAME [] =
 101 j.alex         1.2                "TestStressTestController";
 102                     
 103                     
 104                     /**
 105 kamal.locahana 1.5     StressTest Configuration file details
 106 j.alex         1.2  */
 107                     char StressTestControllerCommand::FILENAME[] = "default_stresstest.conf";
 108                     char StressTestControllerCommand::TESTDIR[] = "/test/";
 109                     char StressTestControllerCommand::STRESSTESTDIR[] = "StressTestController/";
 110                     char StressTestControllerCommand::LOGDIR[] = "log/";
 111                     char StressTestControllerCommand::BINDIR[] = "/bin/";
 112 kamal.locahana 1.5  char StressTestControllerCommand::DEFAULT_CFGDIR[] =
 113 j.alex         1.2        STRESSTEST_DEFAULTCFGDIR;
 114                     char StressTestControllerCommand::DEFAULT_LOGDIR[] =
 115                              "/test/StressTestController/log/";
 116                     char StressTestControllerCommand::DEFAULT_TMPDIR[] =
 117                              "/test/StressTestController/tmp/";
 118                     
 119                     String DEFAULT_BINDIR = String::EMPTY;
 120                     
 121                     static Uint32 DEFAULT_CLIENTS = 2;
 122                     static Uint32 Total_Clients = DEFAULT_CLIENTS;
 123                     static Uint32 NEW_CLIENTS = 5;
 124                     
 125                     static char MODELWALK_CLIENT[] = "TestModelWalkStressClient";
 126                     static char WRAPPER_CLIENT[] = "TestWrapperStressClient";
 127                     
 128                     /**
 129                       StressTest Client Status types
 130                     */
 131                     enum CStatus{
 132                         VALID_RESPONSE,
 133                         INVALID_RESPONSE,
 134 j.alex         1.2      NO_RESPONSE};
 135                     
 136                     
 137                     /**
 138                       Temporary arrays to store client information
 139                     */
 140                     
 141                     /**
 142                       Client PID's
 143                     */
 144                     static pid_t *clientPIDs;
 145                     
 146                     /**
 147                       Client Status
 148                     */
 149                     static int *clientStatus;
 150                     
 151                     
 152                     /**
 153                       Client Status
 154                     */
 155 j.alex         1.2  static int *prev_clientStatus;
 156                     
 157                     /**
 158                       Client Instance
 159                     */
 160 kumpf          1.11 static Uint32* clientInstance;
 161 j.alex         1.2  
 162                     /**
 163                       Indicates if client is Active
 164                     */
 165                     static Boolean *clientActive;
 166                     
 167                     /**
 168 kamal.locahana 1.5    Client status time stamp
 169 j.alex         1.2  */
 170                     static Uint64 *clientTimeStamp;
 171                     
 172                     /**
 173 kamal.locahana 1.5    Previous client status time stamp
 174 j.alex         1.2  */
 175                     static Uint64 *prev_clientTimeStamp;
 176                     
 177                     /**
 178                         DEFAULT VALUES:
 179                     */
 180                     
 181                     /**
 182                         Default duration for the stress tests
 183                     */
 184                     double StressTestControllerCommand::_duration = 180;
 185                     
 186                     /**
 187                         Label for the usage string for this command.
 188                      */
 189                     const char StressTestControllerCommand::_USAGE [] = "Usage: ";
 190                     
 191                     /**
 192                         The option character used to specify the hostname.
 193                      */
 194                     const char StressTestControllerCommand::_OPTION_HOSTNAME = 'h';
 195 j.alex         1.2  
 196                     /**
 197                         The option character used to specify the port number.
 198                      */
 199                     const char StressTestControllerCommand::_OPTION_PORTNUMBER = 'p';
 200                     
 201                     /**
 202                         The option character used to specify SSL usage.
 203                      */
 204                     const char StressTestControllerCommand::_OPTION_SSL = 's';
 205                     
 206                     /**
 207                         The option character used to specify the username.
 208                      */
 209                     const char StressTestControllerCommand::_OPTION_USERNAME = 'u';
 210                     
 211                     /**
 212                         The option character used to specify the password.
 213                      */
 214                     const char StressTestControllerCommand::_OPTION_PASSWORD = 'w';
 215                     
 216 j.alex         1.2  /**
 217                         The minimum valid portnumber.
 218                      */
 219                     const Uint32 StressTestControllerCommand::_MIN_PORTNUMBER = 0;
 220                     
 221                     /**
 222                         The maximum valid portnumber.
 223                      */
 224                     const Uint32 StressTestControllerCommand::_MAX_PORTNUMBER = 65535;
 225                     
 226                     /**
 227                         The minimum Duration.
 228                      */
 229                     const Uint32 StressTestControllerCommand::_MIN_DURATION = 0;
 230                     
 231                     /**
 232                         The minimum valid Tolerance Level.
 233                      */
 234                     const Uint32 StressTestControllerCommand::_MIN_TOLERANCE = 0;
 235                     
 236                     /**
 237 j.alex         1.2      The maximum valid Tolerance Level.
 238                      */
 239                     const Uint32 StressTestControllerCommand::_MAX_TOLERANCE = 100;
 240                     
 241                     /**
 242                         The variable used to specify the hostname.
 243                      */
 244                     static const char HOSTNAME[] = "hostname";
 245                     
 246                     /**
 247                         The variable used to specify the port number.
 248                      */
 249                     static const char PORTNUMBER[] = "port";
 250                     
 251                     /**
 252                         The variable used to specify SSL usage.
 253                      */
 254                     static const char SSL [] = "ssl";
 255                     
 256                     /**
 257                         The variable used to specify the username.
 258 j.alex         1.2   */
 259                     static const char USERNAME[] = "username";
 260                     
 261                     /**
 262                         The variable used to specify the password.
 263                      */
 264                     static const char PASSWORD[] = "password";
 265                     
 266                     /**
 267                         The variable used to specify the duration of the tests.
 268                      */
 269                     static const char DURATION[] = "duration";
 270                     
 271                     /**
 272                         The variable used to specify the duration of the Client tests.
 273                      */
 274                     static const char CLIENTDURATION[] = "ClientDuration";
 275                     
 276                     /**
 277                         The variable used to specify the ToleranceLevel for the tests.
 278                      */
 279 j.alex         1.2  static const char TOLERANCELEVEL[] = "TOLERANCELEVEL";
 280                     
 281                     /**
 282                         The variable used to specify the NameSpace for the tests.
 283                      */
 284                     static const char NAMESPACE[] = "namespace";
 285                     
 286                     /**
 287                         The variable used to specify the ClassName for the tests.
 288                      */
 289                     static const char CLASSNAME[] = "classname";
 290                     
 291                     /**
 292                         The variable used to specify the Name for the tests.
 293                      */
 294                     static const char NAME[] = "NAME";
 295                     
 296                     /**
 297                         The variable used to specify the Clientname for the tests.
 298                      */
 299                     static const char CLIENTNAME[] = "clientname";
 300 j.alex         1.2  
 301                     /**
 302                         The variable used to specify the Clientname for the tests.
 303                      */
 304                     static const char OPTIONS[] = "options";
 305                     
 306                     /**
 307                         The variable used to specify the Clientname for the tests.
 308                      */
 309                     static const char INSTANCE[] = "INSTANCE";
 310                     
 311                     /**
 312                         The variable used to specify the Clientname for the tests.
 313                      */
 314                     static const char CLIENTWAIT[] = "CLIENTWAIT";
 315                     
 316                     
 317                     
 318                     /**
 319                      * Message resource name
 320                      */
 321 j.alex         1.2  static const char LONG_HELP[] = "help";
 322                     static const char LONG_VERSION[] = "version";
 323                     static const char LONG_VERBOSE[] = "verbose";
 324                     
 325                     static Boolean IsAClient = false;
 326                     
 327                     static Boolean IsClientOptions = false;
 328                     
 329                     static Boolean IgnoreLine = false;
 330                     
 331                     /**
 332                     
 333                         Constructs a StressTestControllerCommand and initializes instance variables.
 334                     
 335                      */
 336                     StressTestControllerCommand::StressTestControllerCommand ()
 337                     {
 338                     
 339                         _hostName = String ();
 340                         _hostNameSpecified = false;
 341                         _portNumber = WBEM_DEFAULT_HTTP_PORT;
 342 j.alex         1.2      _portNumberSpecified = false;
 343                     
 344                         char buffer[32];
 345                         sprintf(buffer, "%lu", (unsigned long) _portNumber);
 346                     
 347                         _portNumberStr = buffer;
 348                     
 349                         _timeout = DEFAULT_TIMEOUT_MILLISECONDS;
 350                         _userName = String ();
 351                         _userNameSpecified = false;
 352                         _password = String ();
 353                         _passwordSpecified = false;
 354                         _useSSL = false;
 355                     
 356                         //
 357                         // initialize
 358                         //
 359                         _clientCount = 0;
 360                         _currClientCount = 0;
 361 kamal.locahana 1.5  
 362 j.alex         1.2      //
 363                         // Set up tables for client properties.
 364                         //
 365 kumpf          1.4      _clientTable.reset(new Table[Total_Clients]);
 366 j.alex         1.2  
 367                         //
 368                         // Get environment variables:
 369                         //
 370                         pegasusHome = getenv("PEGASUS_HOME");
 371                     
 372                         DEFAULT_BINDIR = String(pegasusHome);
 373                         DEFAULT_BINDIR.append(BINDIR);
 374                     
 375                         _stressTestLogFile = String::EMPTY;
 376                     
 377                         _stressTestClientPIDFile = String::EMPTY;
 378                     
 379                         _stressTestClientLogFile = String::EMPTY;
 380                     
 381                         _tmpStressTestClientPIDFile = String::EMPTY;
 382                     
 383                     
 384                     
 385                         _usage = String (_USAGE);
 386                     
 387 j.alex         1.2      _usage.append (COMMAND_NAME);
 388                     #ifndef DISABLE_SUPPORT_FOR_REMOTE_CONNECTIONS
 389                         _usage.append (" [ -");
 390                         _usage.append (_OPTION_SSL);
 391                         _usage.append (" ] [ -");
 392                         _usage.append (_OPTION_HOSTNAME);
 393                         _usage.append (" hostname ] [ -");
 394                         _usage.append (_OPTION_PORTNUMBER);
 395                         _usage.append (" portnumber ]\n                            [ -");
 396                         _usage.append (_OPTION_USERNAME);
 397                         _usage.append (" username ] [ -");
 398                         _usage.append (_OPTION_PASSWORD);
 399                         _usage.append (" password ]");
 400                     #endif
 401                         _usage.append (" [ --");
 402                         _usage.append (LONG_HELP);
 403                         _usage.append(" ]\n");
 404                         _usage.append("                            ");
 405                         _usage.append("[ --").append(LONG_VERSION).append(" ]");
 406                         _usage.append(" [ --").append(LONG_VERBOSE).append(" ]").append(\
 407                             " [<config_filename>] \n");
 408 j.alex         1.2  
 409                         _usage.append("Options : \n");
 410                         _usage.append("    -h         - Connect to CIM Server on specified ");
 411                         _usage.append("hostname. \n");
 412                         _usage.append("    --help     - Display this help message.\n");
 413                         _usage.append("    -p         - Connect to CIM Server on specified ");
 414                         _usage.append("portnumber.\n");
 415                         _usage.append("    -s         - Use SSL protocol between Stress Test ");
 416                         _usage.append("Client\n");
 417                         _usage.append("                 and the CIM Server\n");
 418                         _usage.append("    -u         - Connect to CIM Server using the specified");
 419                         _usage.append(" username\n");
 420                         _usage.append("    --version  - Display CIM Server version number\n");
 421                         _usage.append("    --verbose  - Display verbose information\n");
 422                         _usage.append("    -w         - Connect to CIM Server using the specified");
 423                         _usage.append(" password\n");
 424                         _usage.append("\nOperands : \n");
 425                         _usage.append("   <config_filename>\n");
 426                         _usage.append("               - Specifies the name of the configuration ");
 427                         _usage.append("file that is to be used \n");
 428                         _usage.append("                 for the tests.\n");
 429 j.alex         1.2  
 430                         setUsage(_usage);
 431                     
 432                     } /* StressTestControllerCommand  */
 433                     
 434                     /**
 435                     
 436                         Parses the command line, validates the options, and sets instance
 437                         variables based on the option arguments.
 438                     
 439                         @param   argc  the number of command line arguments
 440                         @param   argv  the string vector of command line arguments
 441                     
 442                         @exception  CommandFormatException  if an error is encountered in parsing
 443                                                             the command line
 444                     
 445                      */
 446                     void StressTestControllerCommand::setCommand (Uint32 argc, char* argv [])
 447                     {
 448                         Uint32 i = 0;
 449                         Uint32 c = 0;
 450 j.alex         1.2      String GetOptString = String ();
 451                         getoopt getOpts;
 452                         _toleranceLevel = 0;
 453                         _configFilePath = String ();
 454                         _configFilePathSpecified = false;
 455                     
 456                         _operationType = OPERATION_TYPE_UNINITIALIZED;
 457                     
 458                     
 459                         ofstream log_file;
 460                     
 461                         //
 462                         // opens  the log file
 463                         //
 464                         OpenAppend(log_file,_stressTestLogFile);
 465                     
 466                         if (!log_file)
 467                         {
 468                             if(verboseEnabled)
 469                             {
 470                                 cout<<StressTestControllerCommand::COMMAND_NAME<<
 471 j.alex         1.2                  "::Cannot get file "<<_stressTestLogFile<<endl;
 472                             }
 473 kamal.locahana 1.5  
 474 j.alex         1.2      }
 475                         log_file<<StressTestControllerCommand::COMMAND_NAME<<
 476                             ":: Preparing to set up parameters: "<<endl;
 477                     
 478                         //
 479                         //  Construct GetOptString
 480                         //
 481                         GetOptString.append (_OPTION_HOSTNAME);
 482                         GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 483                         GetOptString.append (_OPTION_PORTNUMBER);
 484                         GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 485                         GetOptString.append (_OPTION_SSL);
 486                         GetOptString.append (_OPTION_USERNAME);
 487                         GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 488                         GetOptString.append (_OPTION_PASSWORD);
 489                         GetOptString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 490                     
 491                         //
 492                         //  Initialize and parse getOpts
 493                         //
 494                         getOpts = getoopt ();
 495 j.alex         1.2      getOpts.addFlagspec (GetOptString);
 496                     
 497                         //
 498                         // per PEP#167
 499                         //
 500                         getOpts.addLongFlagspec(LONG_HELP,getoopt::NOARG);
 501                         getOpts.addLongFlagspec(LONG_VERSION,getoopt::NOARG);
 502                         getOpts.addLongFlagspec(LONG_VERBOSE,getoopt::NOARG);
 503                     
 504                         getOpts.parse (argc, argv);
 505                     
 506                         if (getOpts.hasErrors ())
 507                         {
 508                             log_file.close();
 509                             CommandFormatException e(getOpts.getErrorStrings () [0]);
 510                             throw e;
 511                         }
 512                     
 513                         //
 514                         //  Get options and arguments from the command line
 515                         //
 516 j.alex         1.2      for (i = getOpts.first(); i <  getOpts.last (); i++)
 517                         {
 518                             if (getOpts[i].getType() == Optarg::LONGFLAG)
 519                             {
 520                                 if (getOpts[i].getopt() == LONG_HELP)
 521                                 {
 522                                    _operationType = OPERATION_TYPE_HELP;
 523                                 }
 524                                 else if (getOpts[i].getopt() == LONG_VERSION)
 525                                 {
 526                                     _operationType = OPERATION_TYPE_VERSION;
 527                                 }
 528                                 if (getOpts[i].getopt() == LONG_VERBOSE)
 529                                 {
 530                                     verboseEnabled = true;
 531                                 }
 532                             }
 533                             else if (getOpts [i].getType() == Optarg::REGULAR)
 534                             {
 535                                 //
 536                                 // _configFilePath is the only non-option argument
 537 j.alex         1.2              //
 538                                 if (_configFilePathSpecified)
 539                                 {
 540                                     //
 541                                     // more than one _configFilePath argument was found
 542                                     //
 543                                     log_file<<StressTestControllerCommand::COMMAND_NAME<<
 544                                         "::More than one arguement was found "<<endl;
 545                                     log_file.close();
 546                                     UnexpectedArgumentException e(getOpts[i].Value());
 547                                     throw e;
 548                                 }
 549                                 _configFilePath = getOpts[i].Value();
 550                                 _configFilePathSpecified = true;
 551                             }
 552                             else /* getOpts[i].getType() == FLAG */
 553                             {
 554                                 c = getOpts[i].getopt()[0];
 555                                 switch(c)
 556                                 {
 557                                     case _OPTION_HOSTNAME:
 558 j.alex         1.2                  {
 559                                         if (getOpts.isSet(_OPTION_HOSTNAME) > 1)
 560                                         {
 561                                             //
 562                                             // More than one hostname option was found
 563                                             //
 564                                             log_file.close();
 565                                             DuplicateOptionException e(_OPTION_HOSTNAME);
 566                                             throw e;
 567                                         }
 568                                         _hostName = getOpts [i].Value ();
 569                                         _hostNameSpecified = true;
 570 kumpf          1.4                      if (!_propertyTable.insert("hostname", _hostName))
 571 j.alex         1.2                      {
 572                                              // shouldn't get here
 573                                              if(verboseEnabled)
 574                                              {
 575                                                  cout<<StressTestControllerCommand::COMMAND_NAME;
 576                                                  cout<<"::Property Name name already saved: "<<
 577                                                      "hostname"<<endl;
 578                                              }
 579                                         }
 580                                         break;
 581                                     }
 582                                     case _OPTION_PORTNUMBER:
 583                                     {
 584                                         if (getOpts.isSet(_OPTION_PORTNUMBER) > 1)
 585                                         {
 586                                             //
 587                                             // More than one portNumber option was found
 588                                             //
 589                                             log_file.close();
 590                                             DuplicateOptionException e(_OPTION_PORTNUMBER);
 591                                             throw e;
 592 j.alex         1.2                      }
 593                                         _portNumberStr = getOpts [i].Value ();
 594                                         try
 595                                         {
 596                                             getOpts[i].Value(_portNumber);
 597                                         }
 598                                         catch (const TypeMismatchException&)
 599                                         {
 600                                             log_file.close();
 601                                             InvalidOptionArgumentException e(
 602                                                 _portNumberStr,
 603                                                 _OPTION_PORTNUMBER);
 604                                             throw e;
 605                                         }
 606                                         _portNumberSpecified = true;
 607 kumpf          1.4                      if (!_propertyTable.insert("port", _portNumberStr))
 608 j.alex         1.2                      {
 609                                             if(verboseEnabled)
 610                                             {
 611                                                cout<<StressTestControllerCommand::COMMAND_NAME;
 612                                                cout<<"::Property Name:duplicate name already saved:"
 613                                                    <<"port"<<endl;
 614                                             }
 615                                         }
 616                                         break;
 617                                     }
 618                                     case _OPTION_SSL:
 619                                     {
 620                                         //
 621                                         // Use port 5989 as the default port for SSL
 622                                         //
 623                                         _useSSL = true;
 624                                         if (!_portNumberSpecified)
 625                                         {
 626                                            _portNumber = 5989;
 627                                            _portNumberStr = "5989";
 628 kumpf          1.4                         if (!_propertyTable.insert("port", _portNumberStr))
 629 j.alex         1.2                         {
 630 kamal.locahana 1.5                             if(verboseEnabled)
 631 j.alex         1.2                             {
 632                                                   cout<<StressTestControllerCommand::COMMAND_NAME;
 633                                                   cout<<"::Property Name already saved: "<<"port"<<
 634                                                       endl;
 635                                                }
 636                                            }
 637                                         }
 638 kumpf          1.4                      if (!_propertyTable.insert("ssl", ""))
 639 j.alex         1.2                      {
 640                                             if(verboseEnabled)
 641                                             {
 642                                                 cout<<StressTestControllerCommand::COMMAND_NAME;
 643                                                 cout<<"::Property Name already saved: "<<"ssl"<<
 644                                                     endl;
 645                                             }
 646                                         }
 647                                         break;
 648                                     }
 649                                     case _OPTION_USERNAME:
 650                                     {
 651                                         if (getOpts.isSet(_OPTION_USERNAME) > 1)
 652                                         {
 653                                             //
 654                                             // More than one username option was found
 655                                             //
 656                                             log_file.close();
 657                                             DuplicateOptionException e(_OPTION_USERNAME);
 658                                             throw e;
 659                                         }
 660 j.alex         1.2                      _userName = getOpts[i].Value();
 661                                         _userNameSpecified = true;
 662 kumpf          1.4                      if (!_propertyTable.insert("username", _userName))
 663 j.alex         1.2                      {
 664                                             if(verboseEnabled)
 665                                             {
 666                                                 cout<<StressTestControllerCommand::COMMAND_NAME;
 667                                                 cout<< "::Property Name already saved: "<<
 668                                                     "username"<<endl;
 669                                             }
 670                                         }
 671                                         break;
 672                                     }
 673                                     case _OPTION_PASSWORD:
 674                                     {
 675                                         if (getOpts.isSet(_OPTION_PASSWORD) > 1)
 676                                         {
 677                                             //
 678                                             // More than one password option was found
 679                                             //
 680                                             log_file.close();
 681                                             DuplicateOptionException e(_OPTION_PASSWORD);
 682                                             throw e;
 683                                         }
 684 j.alex         1.2                      _password = getOpts[i].Value();
 685                                         _passwordSpecified = true;
 686 kumpf          1.4                      if (!_propertyTable.insert("password", _password))
 687 j.alex         1.2                      {
 688                                             if(verboseEnabled)
 689                                             {
 690                                                 cout<<StressTestControllerCommand::COMMAND_NAME;
 691                                                 cout<<"::Property Name already saved: "<<
 692                                                     "password"<<endl;
 693                                             }
 694                                         }
 695                                         break;
 696                                     }
 697                     
 698                                     default:
 699                                     {
 700                                         //
 701                                         //  This path should not be hit
 702                                         //  PEP#167 unless an empty '-' is specified
 703                                         //
 704                                         log_file.close();
 705 kamal.locahana 1.5                      String ErrReport =
 706 j.alex         1.2                          String(StressTestControllerCommand::COMMAND_NAME);
 707                                         ErrReport.append("::Invalid or unknown option specified");
 708                                         throw StressTestControllerException(ErrReport);
 709                     
 710                                         break;
 711                                    }
 712                                 }
 713                             }
 714                         }
 715                         //
 716                         //  More validation:
 717                         //    No portNumber specified
 718                         //    Default to WBEM_DEFAULT_PORT
 719                         //    Already done in constructor
 720                         //
 721                         if (getOpts.isSet(_OPTION_PORTNUMBER) == 1)
 722                         {
 723                             if (_portNumber > _MAX_PORTNUMBER)
 724                             {
 725                                 //
 726                                 //  Portnumber out of valid range
 727 j.alex         1.2              //
 728                                 log_file.close();
 729                                 InvalidOptionArgumentException e(_portNumberStr,
 730                                     _OPTION_PORTNUMBER);
 731                                 throw e;
 732                             }
 733                         }
 734                         log_file.close();
 735                     } /* setCommand  */
 736                     
 737                     /**
 738                     
 739 kamal.locahana 1.5      Generates commands and its options for each of the clients.
 740 j.alex         1.2      The client table is traversed to generate each of the client commands.
 741                         The Commands, Duration and Delays for each client are saved in
 742                         the following array's respectively:
 743 kamal.locahana 1.5         _clientCommands
 744 j.alex         1.2         _clientDurations
 745 kamal.locahana 1.5         _clientDelays
 746                     
 747                         @param   log_file           The log file.
 748 j.alex         1.2  
 749                         @return  0                  if the command is successfully generated
 750                                  1                  if the command cannot be generated.
 751                      */
 752                     Boolean StressTestControllerCommand::generateClientCommands(ostream& log_file)
 753                     {
 754                     
 755                         String client_command = String::EMPTY;
 756                         double duration = _duration;
 757                         double delay = 0;
 758                     
 759 kamal.locahana 1.5      //
 760 j.alex         1.2      // Array's to store client specific information
 761                         //
 762 kumpf          1.4      _clientCommands.reset(new String[_clientCount]);
 763                         _clientDurations.reset(new Uint64[_clientCount]);
 764                         _clientDelays.reset(new Uint64[_clientCount]);
 765 j.alex         1.2  
 766                         //
 767                         // Retrieve all the client options from the client table
 768 kamal.locahana 1.5      // and build commands for respective clients.
 769                         // Add appropriate options to command string  as required
 770 j.alex         1.2      //
 771                         for (Uint32 j=0; j< _clientCount; j++)
 772                         {
 773                             delay = 0;
 774                             String clientName = String::EMPTY;
 775                             String clientInst = String::EMPTY;
 776 kamal.locahana 1.5          //
 777                             //  Stress Client Name must exist for each client/client table
 778 j.alex         1.2          //
 779 kumpf          1.4          if (!_clientTable.get()[j].lookup(NAME, clientName))
 780 j.alex         1.2          {
 781                                 log_file<<StressTestControllerCommand::COMMAND_NAME<<
 782                                      "::Required property NAME not found."<<endl;
 783                                 return false;
 784                             }
 785                             //
 786                             // Start the command string with the client name.
 787                             //
 788                             client_command = clientName;
 789                     
 790 kamal.locahana 1.5          //
 791 j.alex         1.2          // Generate the commands for each client from each client table.
 792                             //
 793 kumpf          1.4          for (Table::Iterator i = _clientTable.get()[j].start(); i; i++)
 794 j.alex         1.2          {
 795                                 if (String::equalNoCase(i.key(),HOSTNAME))
 796                                 {
 797                                     client_command.append(" -hostname ");
 798                                     if (_hostNameSpecified)
 799                                     {
 800                                         client_command.append(_hostName);
 801                                     }
 802                                     else
 803 kamal.locahana 1.5                  {
 804 j.alex         1.2                      client_command.append(i.value());
 805                                     }
 806 kamal.locahana 1.5              }
 807 j.alex         1.2              else if (String::equalNoCase(i.key(),NAME))
 808                                 {
 809                                     //
 810                                     // should be ignored - already saved using clientName
 811                                     //
 812 kamal.locahana 1.5              }
 813 j.alex         1.2              else if (String::equalNoCase(i.key(),PORTNUMBER))
 814                                 {
 815                                     client_command.append(" -");
 816                                     client_command.append(PORTNUMBER);
 817                                     client_command.append(" ");
 818                                     if (_portNumberSpecified)
 819                                     {
 820                                         client_command.append(_portNumberStr);
 821 kamal.locahana 1.5                  }
 822 j.alex         1.2                  else
 823 kamal.locahana 1.5                  {
 824 j.alex         1.2                      client_command.append(i.value());
 825                                     }
 826                                 }
 827                                 else if (String::equalNoCase(i.key(),SSL))
 828                                 {
 829                                     client_command.append(" -");
 830                                     client_command.append(SSL);
 831 kamal.locahana 1.5              }
 832 j.alex         1.2              else if (String::equalNoCase(i.key(),USERNAME))
 833                                 {
 834                                     client_command.append(" -");
 835                                     client_command.append(USERNAME);
 836                                     client_command.append(" ");
 837                                     client_command.append(i.value());
 838 kamal.locahana 1.5              }
 839 j.alex         1.2              else if (String::equalNoCase(i.key(),PASSWORD))
 840                                 {
 841                                     client_command.append(" -");
 842                                     client_command.append(PASSWORD);
 843                                     client_command.append(" ");
 844                                     client_command.append(i.value());
 845                                 }
 846                                 else if (String::equalNoCase(i.key(),CLIENTNAME))
 847                                 {
 848                                     client_command.append(" -");
 849                                     client_command.append(CLIENTNAME);
 850                                     client_command.append(" ");
 851                                     client_command.append(i.value());
 852                                 }
 853                                 else if (String::equalNoCase(i.key(),OPTIONS))
 854                                 {
 855                                     client_command.append(" -");
 856                                     client_command.append(OPTIONS);
 857                                     client_command.append(" ");
 858                                     client_command.append(i.value());
 859                                 }
 860 j.alex         1.2              else if (String::equalNoCase(i.key(),NAMESPACE))
 861                                 {
 862                                     client_command.append(" -");
 863                                     client_command.append(NAMESPACE);
 864                                     client_command.append(" ");
 865                                     client_command.append(i.value());
 866 kamal.locahana 1.5              }
 867 j.alex         1.2              else if (String::equalNoCase(i.key(),CLASSNAME))
 868                                 {
 869                                     client_command.append(" -");
 870                                     client_command.append(CLASSNAME);
 871                                     client_command.append(" ");
 872                                     client_command.append(i.value());
 873 kamal.locahana 1.5              }
 874 j.alex         1.2              else if ((String::equalNoCase(i.key(),INSTANCE))
 875                                           ||(String::equalNoCase(i.key(),CLIENTWAIT))
 876                                           ||(String::equalNoCase(i.key(),CLIENTDURATION)))
 877                                 {
 878                                     //
 879 kamal.locahana 1.5                  // do nothing here
 880 j.alex         1.2                  //   will be utilized to run the clients later.
 881                                     //
 882 kamal.locahana 1.5              }
 883                                 else
 884                                 {
 885 j.alex         1.2                  //
 886                                     // Save all other options for the commands
 887                                     //
 888                                     client_command.append(" -");
 889                                     client_command.append(i.key());
 890                                     client_command.append(" ");
 891                                     client_command.append(i.value());
 892                                 }
 893                             }
 894                             //
 895                             // Include verbose if enabled to clients
 896                             //
 897                             if (verboseEnabled)
 898                             {
 899                                 client_command.append(" -verbose ");
 900                             }
 901                     
 902                             //
 903 kamal.locahana 1.5          // Acquire all the common properties listed in the property table
 904                             // from config file and include it as part of the client command
 905 j.alex         1.2          // as required.
 906                             //
 907 kumpf          1.4          for (Table::Iterator k = _propertyTable.start(); k; k++)
 908 j.alex         1.2          {
 909                                 String propertyValue = String::EMPTY;
 910                                 //
 911                                 // Only include the common properties that are not already
 912                                 // listed for the clients.
 913                                 //
 914 kumpf          1.4              if (!_clientTable.get()[j].lookup(k.key(), propertyValue))
 915 j.alex         1.2              {
 916                                     //
 917                                     // Include options other than ToleranceLevel
 918                                     // clientDuration,clientwait and Duration
 919 kamal.locahana 1.5                  // in the command string for the clients.
 920 j.alex         1.2                  //
 921                                     if ((!String::equalNoCase(k.key(),TOLERANCELEVEL))
 922                                          && (!String::equalNoCase(k.key(),CLIENTDURATION))
 923                                          && (!String::equalNoCase(k.key(),CLIENTWAIT))
 924                                          && (!String::equalNoCase(k.key(),DURATION)))
 925                                     {
 926                                         client_command.append(" -");
 927                                         client_command.append(k.key());
 928 kamal.locahana 1.5                      //
 929 j.alex         1.2                      // No values required for SSL
 930 kamal.locahana 1.5                      //
 931 j.alex         1.2                      if (!String::equalNoCase(k.key(),SSL))
 932                                         {
 933                                             client_command.append(" ");
 934                                             client_command.append(k.value());
 935                                         }
 936                                     }
 937                                 }
 938                                 //
 939                                 // Use default duration if one was not specified in the Config file.
 940                                 //
 941                                 if (String::equalNoCase(k.key(),DURATION))
 942                                 {
 943                                     duration = atof(k.value().getCString());
 944 kamal.locahana 1.5              }
 945                                 else
 946 j.alex         1.2              {
 947                                     duration = _duration;
 948                                 }
 949 kumpf          1.4          } /* for (Table::Iterator k = _propertyTable.start(); k; k++) */
 950 j.alex         1.2  
 951                             //
 952                             // Looking up table while ignoring cases for Client Duration/Wait.
 953                             //
 954 kumpf          1.4          for (Table::Iterator k = _clientTable.get()[j].start(); k; k++)
 955 j.alex         1.2          {
 956                                 //
 957                                 // Overwrite duration if client duration set
 958                                 //
 959                                 if (String::equalNoCase(k.key(),CLIENTDURATION))
 960                                 {
 961                                     duration = atof(k.value().getCString());
 962                                 }
 963                                 if (String::equalNoCase(k.key(),CLIENTWAIT))
 964                                 {
 965                                     delay = atof(k.value().getCString());
 966                                 }
 967                             }
 968                     
 969                             //
 970 kamal.locahana 1.5          // Save the generated command to corresponding element in the
 971 j.alex         1.2          // clientCommand array.
 972                             //
 973 kumpf          1.4          _clientCommands.get()[j] = client_command;
 974 j.alex         1.2  
 975                             //
 976                             // Converting minutes to milliseconds
 977                             //
 978 kumpf          1.4          _clientDurations.get()[j] = (Uint64)convertmin2millisecs(duration);
 979                             _clientDelays.get()[j] = (Uint64)convertmin2millisecs(delay);
 980 kamal.locahana 1.5  
 981 j.alex         1.2          //
 982                             // Saving logs
 983                             //
 984 kumpf          1.4          log_file << StressTestControllerCommand::COMMAND_NAME <<
 985                                 "::Client Command[" << j << "]" << endl;
 986                             log_file << "  " << _clientCommands.get()[j] << endl;
 987                             log_file << "   Client Duration: " <<
 988                                 convertUint64toString(_clientDurations.get()[j]) << endl;
 989                             log_file << "   Client Delay: " <<
 990                                 convertUint64toString(_clientDelays.get()[j]) << endl;
 991 j.alex         1.2  
 992                             //
 993 kamal.locahana 1.5          // Verbose
 994 j.alex         1.2          //
 995                             if (verboseEnabled)
 996                             {
 997 kumpf          1.4              cout << StressTestControllerCommand::COMMAND_NAME <<
 998                                     "::Client Command[" << j << "]" << endl;
 999                                 cout << "  " << _clientCommands.get()[j] << endl;
1000                                 cout << "   Client Duration: " <<
1001                                     convertUint64toString(_clientDurations.get()[j]) << endl;
1002                                 cout << "   Client Delay: " <<
1003                                     convertUint64toString(_clientDelays.get()[j]) << endl;
1004 j.alex         1.2          }
1005                         } /* for(Uint32 j=0; j< _clientCount; j++) */
1006                         return true;
1007                     } /* generateClientCommands */
1008                     
1009                     /*
1010                         Executes the command and writes the results to the PrintWriters.
1011                         This method is where the clients are intiated.
1012                         The clients are kept running until its duration is met
1013                         or the controller is interrupted by a SIGINT or SIGABRT signal
1014                         or if the controller failed to acquire the clientPIDs when needed.
1015                     
1016 kamal.locahana 1.5      Clients with clientWait,  will be stopped when its duration is met and
1017                         then restarted after its wait period is completed. This will continue
1018                         until the end of the overall duration.
1019 j.alex         1.2      When the overall duration has ended or the controller is interupted then
1020 kamal.locahana 1.5      the controller will read the PID file to update its clients PID and
1021 j.alex         1.2      request all the clients to end its processes.
1022                     
1023                         @param   outPrintWriter     the ostream to which output should be
1024                                                     written
1025                         @param   errPrintWriter     the ostream to which error output should be
1026                                                     written
1027                     
1028                         @return  0                  if the command is successful
1029                                  1                  if an error occurs in executing the command
1030                     
1031                      */
1032                     Uint32 StressTestControllerCommand::execute (
1033                         ostream& outPrintWriter,
1034                         ostream& errPrintWriter)
1035                     {
1036                         int actual_client = 0;
1037                         Uint64 startMilliseconds = 0;
1038                         Uint64 nowMilliseconds = 0;
1039                         Uint64 stopMilliseconds = 0;
1040                         Uint64 timeoutMilliseconds = 0;
1041 kumpf          1.4      AutoArrayPtr<Uint64> clientStartMilliseconds;
1042                         AutoArrayPtr<Uint64> clientStopMilliseconds;
1043                         AutoArrayPtr<Uint64> clientDelayMilliseconds;
1044                         AutoArrayPtr<Boolean> clientStopped;
1045                         AutoArrayPtr<Boolean> clientDelayed;
1046                         String act_command;
1047 j.alex         1.2      Boolean TestFailed = false;
1048                         char str[15];
1049                         char strTime[256];
1050                         struct tm tmTime;
1051                     
1052                         //
1053                         // log file
1054 kamal.locahana 1.5      //
1055 j.alex         1.2      ofstream log_file;
1056                     
1057 kamal.locahana 1.5      //
1058 j.alex         1.2      // open the file
1059 kamal.locahana 1.5      //
1060 j.alex         1.2      OpenAppend(log_file,_stressTestLogFile);
1061                     
1062 kamal.locahana 1.5      //
1063 j.alex         1.2      // Failed to read log file.
1064                         //
1065                         if (!log_file)
1066                         {
1067                             log_file.close();
1068                             if (verboseEnabled)
1069                             {
1070                                 outPrintWriter<<StressTestControllerCommand::COMMAND_NAME;
1071                                 outPrintWriter<<"Cannot read file "<<_stressTestLogFile<<endl;
1072                             }
1073                             return RC_ERROR;
1074                         }
1075                     
1076 kamal.locahana 1.5      //
1077 j.alex         1.2      // Display usage message if help was specified
1078                         //
1079                         if ( _operationType == OPERATION_TYPE_HELP )
1080                         {
1081                             outPrintWriter << _usage << endl;
1082                             log_file<<StressTestControllerCommand::COMMAND_NAME<<
1083                                 "::Listing usage information "<<endl;
1084                             log_file.close();
1085                             //
1086                             //  No need for the client pid and log file.
1087                             //
1088                             FileSystem::removeFile(_stressTestClientPIDFile);
1089                             FileSystem::removeFile(_stressTestClientLogFile);
1090                             return (RC_SUCCESS);
1091                         }
1092 kamal.locahana 1.5      //
1093 j.alex         1.2      // Display PEGASUS version if version was specified
1094                         //
1095                         else if ( _operationType == OPERATION_TYPE_VERSION )
1096                         {
1097                             outPrintWriter << "Version " << PEGASUS_PRODUCT_VERSION << endl;
1098                             log_file<<StressTestControllerCommand::COMMAND_NAME<<
1099                                 "::Listing version information "<<endl;
1100                             log_file<<"Version " << PEGASUS_PRODUCT_VERSION << endl;
1101                             log_file.close();
1102                             //
1103                             //  No need for the client pid and log file.
1104                             //
1105                             FileSystem::removeFile(_stressTestClientPIDFile);
1106                             FileSystem::removeFile(_stressTestClientLogFile);
1107                             return (RC_SUCCESS);
1108                         }
1109                     
1110                         //
1111                         // gracefully shutdown when interrupted
1112                         //
1113                         signal(SIGABRT, endAllTests);
1114 j.alex         1.2      signal(SIGINT, endAllTests);
1115                     
1116 kamal.locahana 1.5      //
1117                         // Allocate variables necessary to run clients.
1118 j.alex         1.2      //
1119                         if(_clientCount > 0)
1120                         {
1121 kumpf          1.11         clientInstance = new Uint32[_clientCount];
1122 kumpf          1.4          clientStartMilliseconds.reset(new Uint64[_clientCount]);
1123                             clientStopMilliseconds.reset(new Uint64[_clientCount]);
1124                             clientDelayMilliseconds.reset(new Uint64[_clientCount]);
1125                             clientStopped.reset(new Boolean[_clientCount]);
1126                             clientDelayed.reset(new Boolean[_clientCount]);
1127 kamal.locahana 1.5      }
1128                         else
1129                         {
1130 j.alex         1.2          errPrintWriter << "Stress Tests must have at least one Client." << endl;
1131                             log_file<<StressTestControllerCommand::COMMAND_NAME<<
1132                                 "::Stress Tests must have at least one Client."<<endl;
1133                             log_file.close();
1134                             return (RC_ERROR);
1135                         }
1136 kamal.locahana 1.5  
1137 j.alex         1.2      try
1138                         {
1139                             //
1140                             // Initializing the Boolean array's to false.
1141                             //
1142                             for (Uint32 i=0;i<_clientCount;i++)
1143                             {
1144 kumpf          1.4              clientStopped.get()[i] = false;
1145                                 clientDelayed.get()[i] = false;
1146 j.alex         1.2          }
1147                             //
1148                             // Set up duration of the tests
1149                             //
1150                             startMilliseconds   = TimeValue::getCurrentTime().toMilliseconds();
1151                             nowMilliseconds     = startMilliseconds;
1152                             timeoutMilliseconds = (Uint64)convertmin2millisecs(_duration);
1153                             stopMilliseconds    = nowMilliseconds + timeoutMilliseconds;
1154 kamal.locahana 1.5  
1155 j.alex         1.2          log_file<<StressTestControllerCommand::COMMAND_NAME<<
1156                                 ":: Test Duration information "<<endl;
1157                             log_file<<"  Start Time in milliseconds: "<<
1158                                 convertUint64toString(startMilliseconds)<<endl;
1159                             log_file<<"  Total duration in milliseconds: "<<
1160                                 convertUint64toString(timeoutMilliseconds)<<endl;
1161                             log_file<<"  Actual Stop Time in milliseconds: "<<
1162                                 convertUint64toString(stopMilliseconds)<<endl;
1163 kamal.locahana 1.5          //
1164                             //  Verbose details for Stress Test duration
1165 j.alex         1.2          //
1166                             if (verboseEnabled)
1167                             {
1168                                 outPrintWriter<<StressTestControllerCommand::COMMAND_NAME<<
1169                                     ":: Test Duration information "<<endl;
1170                                 outPrintWriter<<"  Start Time in milliseconds: "<<
1171                                     convertUint64toString(startMilliseconds)<<endl;
1172                                 outPrintWriter<<"  Total duration in milliseconds: "<<
1173                                     convertUint64toString(timeoutMilliseconds)<<endl;
1174                                 outPrintWriter<<
1175                                     "  Actual Stop Time in milliseconds: "<<
1176                                     convertUint64toString(stopMilliseconds)<<endl;
1177                             }
1178                     
1179                             //
1180 kamal.locahana 1.5          //  First Tolerance check up interval is set up to be twice
1181 j.alex         1.2          //  the CHECKUP_INTERVAL. This should give the clients enough time
1182                             //  to update its PID, status  etc.
1183 kamal.locahana 1.5          //
1184                             Uint64 nextCheckupInMillisecs =
1185 j.alex         1.2             (Uint64)convertmin2millisecs(2 * CHECKUP_INTERVAL) + nowMilliseconds;
1186                             //
1187 kamal.locahana 1.5          //  Main "while" loop where the clients are initiated.
1188 j.alex         1.2          //
1189                             while(stopMilliseconds > nowMilliseconds)
1190 kamal.locahana 1.5          {
1191 j.alex         1.2  
1192 kamal.locahana 1.5              //
1193                                 // Small delay in the while loop seemed to reduce the CPU usage
1194 j.alex         1.2              // considerably  in Windows. (From 80% to 1%)
1195                                 //
1196                     #ifndef PEGASUS_OS_TYPE_WINDOWS
1197 kamal.locahana 1.5              sleep(RUN_DELAY);
1198 j.alex         1.2  #else
1199                                 Sleep(RUN_DELAY * 1000);
1200                     #endif
1201                     
1202                                 //
1203                                 // Quit if SIGINT, SIGABRT is caught
1204                                 // So the clients can be gracefully shutdown.
1205                                 //
1206                                 if(Quit)
1207                                 {
1208                                     log_file<<
1209 kamal.locahana 1.5                      "Test interrupted by either SIGINT or SIGABORT."<<endl;
1210 j.alex         1.2                  TestFailed = true;
1211                                     break;
1212                                 }
1213                                 //
1214                                 // The following block will be where clients are executed initially.
1215                                 //
1216                                 if(!actual_client)
1217                                 {
1218                                     log_file<<StressTestControllerCommand::COMMAND_NAME<<
1219                                         "::Running the following tests: "<<endl;
1220                                     outPrintWriter<<StressTestControllerCommand::COMMAND_NAME<<
1221                                         "::Running the following tests: "<<endl;
1222                                     for (Uint32 j=0; j< _clientCount; j++)
1223                                     {
1224                                         String clientInst = String::EMPTY;
1225                                         //
1226                                         // Acquire the client Instance for each clients
1227                                         //
1228 kumpf          1.4                      if (!_clientTable.get()[j].lookup(INSTANCE, clientInst))
1229 j.alex         1.2                      {
1230                                             String ErrReport = String("Invalid Property Value: ");
1231                                             ErrReport.append(INSTANCE);
1232                                             ErrReport.append("=");
1233                                             ErrReport.append(clientInst);
1234                                             throw StressTestControllerException(ErrReport);
1235                                         }
1236 kumpf          1.11                     clientInstance[j] = (Uint32)atoi(clientInst.getCString());
1237 j.alex         1.2  
1238                                         //
1239                                         // Acquire and set client specific duration
1240                                         //
1241 kamal.locahana 1.5                      clientStartMilliseconds.get()[j] =
1242 j.alex         1.2                          TimeValue::getCurrentTime().toMilliseconds();
1243 kamal.locahana 1.5                      clientStopMilliseconds.get()[j] =
1244 kumpf          1.4                          clientStartMilliseconds.get()[j] +
1245                                                 _clientDurations.get()[j];
1246 j.alex         1.2  
1247 kamal.locahana 1.5                      //
1248 j.alex         1.2                      // for verbose only
1249                                         //
1250                                         if (verboseEnabled)
1251                                         {
1252 kumpf          1.4                          outPrintWriter << "Client:" << "[" << j<< "]" << endl;
1253                                             log_file << "Client:" << "[" << j << "]" << endl;
1254                                             outPrintWriter << "ClientStart:" <<
1255                                                 convertUint64toString(
1256                                                     clientStartMilliseconds.get()[j]) <<
1257                                                 endl;
1258                                             outPrintWriter << "ClientStop:" <<
1259                                                 convertUint64toString(
1260                                                     clientStopMilliseconds.get()[j]) <<
1261 j.alex         1.2                              endl;
1262 kumpf          1.4                          outPrintWriter << "ClientDuration:" <<
1263                                                 convertUint64toString(_clientDurations.get()[j]) <<
1264 j.alex         1.2                              endl;
1265 kumpf          1.4                          log_file << "ClientStart:" <<
1266                                                 convertUint64toString(
1267                                                     clientStartMilliseconds.get()[j]) <<
1268 j.alex         1.2                              endl;
1269 kumpf          1.4                          log_file << "ClientStop:" <<
1270                                                 convertUint64toString(
1271                                                     clientStopMilliseconds.get()[j]) <<
1272                                                 endl;
1273                                             log_file << "ClientDuration:" <<
1274                                                 convertUint64toString(_clientDurations.get()[j]) <<
1275 j.alex         1.2                              endl;
1276                                         }
1277                                         log_file<<
1278                                             "Number of instances of this client: "<<
1279                                             clientInstance[j]<<endl;
1280                                         if(verboseEnabled)
1281                                         {
1282                                             outPrintWriter<<
1283                                                 "Number of instances of this client:"<<
1284                                                 clientInstance[j]<<endl;
1285                                         }
1286 kamal.locahana 1.5                      //
1287 j.alex         1.2                      // Execute each instance of the client.
1288 kamal.locahana 1.5                      //   - Additional required parameters are added to the
1289 j.alex         1.2                      //     commands.
1290                                         //     like, -clientid, -pidfile, -clientlog
1291                                         //
1292 kumpf          1.9                      for (Uint32 instanceID = 0; instanceID<clientInstance[j];
1293 j.alex         1.2                           instanceID++)
1294                                         {
1295                                             outPrintWriter<<
1296                                                 "Running Client("<<actual_client<<")"<<endl;
1297                                             log_file<<
1298                                                 "Running Client("<<actual_client<<")"<<endl;
1299                                             act_command=String::EMPTY;
1300                     #ifdef PEGASUS_OS_TYPE_WINDOWS
1301                                             act_command.append("start ");
1302                     #endif
1303                                             //
1304                                             // Adding all the required parameters for the command.
1305                                             //
1306 kumpf          1.4                          act_command.append(_clientCommands.get()[j]);
1307 j.alex         1.2                          act_command.append(" -clientid ");
1308 kamal.locahana 1.5                          sprintf(str,"%d",actual_client);
1309 j.alex         1.2                          act_command.append(str);
1310                                             act_command.append(" -pidfile ");
1311                                             act_command.append(" \"");
1312                                             act_command.append(_stressTestClientPIDFile);
1313                                             act_command.append("\"");
1314                                             act_command.append(" -clientlog");
1315                                             act_command.append(" \"");
1316                                             act_command.append(_stressTestClientLogFile);
1317                                             act_command.append("\"");
1318                                             act_command.append("&");
1319                                             if (verboseEnabled)
1320                                             {
1321                                                 outPrintWriter<<"  "<<act_command<<endl;
1322                                                 tmTime = getCurrentActualTime();
1323                                                 strftime(
1324                                                     strTime,
1325                                                     256,
1326                                                     "%d/%m/%Y at %H:%M:%S\n",
1327                                                     &tmTime);
1328                                                 log_file<<
1329                                                     StressTestControllerCommand::COMMAND_NAME<<
1330 j.alex         1.2                                  "::Running following command on "<<
1331                                                     strTime<<endl;
1332                                                 log_file<<"     ("<<actual_client<<") \n"<<
1333                                                     act_command<<endl;
1334                                             }
1335                     
1336                                             //
1337                                             // Executing the Client
1338                                             //
1339 kumpf          1.10                         int commandRc = system(act_command.getCString());
1340 j.alex         1.2                          //
1341                                             // Continue even if the client failed to Execute
1342                                             // This failure is validated with Tolerance level later
1343 kamal.locahana 1.5                          //
1344 kumpf          1.10                         if (commandRc)
1345 j.alex         1.2                          {
1346                                                 log_file<<"Command failed to Execute."<<endl;
1347                                                 if (verboseEnabled)
1348                                                 {
1349                                                     outPrintWriter<<
1350                                                         "Command failed to Execute."<<endl;
1351                                                 }
1352                                             }
1353                                             //
1354                                             // Increment the actual number of clients
1355                                             //
1356                                             ++actual_client;
1357                                         } /* for(int instanceID =0;instanceID<clientInstance[j]...*/
1358 kamal.locahana 1.5  
1359 j.alex         1.2                  }/* for(Uint32 j=0; j< _clientCount; j++) */
1360                     
1361                                     //
1362                                     //retrieve all PIDs and status;
1363                                     //
1364 kamal.locahana 1.5                  clientPIDs = new pid_t[actual_client];
1365                                     clientStatus = new int[actual_client];
1366                                     prev_clientStatus = new int[actual_client];
1367                                     clientTimeStamp = new Uint64[actual_client];
1368                                     prev_clientTimeStamp = new Uint64[actual_client];
1369                                     clientActive = new Boolean[actual_client];
1370 j.alex         1.2                  nowMilliseconds = TimeValue::getCurrentTime().toMilliseconds();
1371                                     for (int i=0;i<actual_client;i++)
1372                                     {
1373                                         clientPIDs[i] = 9999999;
1374                                         clientStatus[i] = NO_RESPONSE;
1375                                         clientActive[i] = true;
1376                                         clientTimeStamp[i] = nowMilliseconds;
1377                                         prev_clientTimeStamp[i] = nowMilliseconds;
1378                                     }
1379                                     log_file<<StressTestControllerCommand::COMMAND_NAME<<
1380                                         "::Getting client PID's and status. "<<endl;
1381                                     if (verboseEnabled)
1382                                     {
1383                                         outPrintWriter<<StressTestControllerCommand::COMMAND_NAME<<
1384                                             "::Getting client PID's and status. "<<endl;
1385                                     }
1386 kumpf          1.10                 int getClientPidRc = _getClientPIDs(actual_client,log_file);
1387                                     if (!getClientPidRc)
1388 j.alex         1.2                  {
1389                                         outPrintWriter<<
1390                                             "Failed to communicate with clients."<<endl;
1391                                         log_file<<StressTestControllerCommand::COMMAND_NAME<<
1392                                             "::Failed to communicate with clients. "<<endl;
1393                                         log_file<<
1394                                         "                    ::Failed to get client PID & status. "
1395                                             <<endl;
1396                                         TestFailed = true;
1397                                         break;
1398                                     }
1399 kamal.locahana 1.5              }/* if (!actual_client) */
1400                                 else
1401                                 {
1402 j.alex         1.2                  /**
1403                                      Every CHECKUP_INTERVAL minutes check to see if tests are
1404                                      within tolerance. Tests will cease to run if they
1405                                      are not within tolerance. The controller will stop
1406                                      all the clients and then exit.
1407                                     */
1408 kamal.locahana 1.5  
1409 j.alex         1.2                  //
1410                                     // Retreive all the client PIDs
1411                                     //
1412 kumpf          1.10                 int getClientPidRc = _getClientPIDs(actual_client,log_file);
1413 kamal.locahana 1.5  
1414 j.alex         1.2                  //
1415                                     // Get Current Time
1416                                     //
1417                                     nowMilliseconds = TimeValue::getCurrentTime().toMilliseconds();
1418                     
1419                                     //
1420                                     // Check tolerance level if its time
1421                                     //
1422                                     if (nowMilliseconds >= nextCheckupInMillisecs)
1423                                     {
1424                                         //
1425                                         //  Set up the next tolerance time
1426                                         //
1427 kamal.locahana 1.5                      nextCheckupInMillisecs =
1428 j.alex         1.2                             (Uint64)convertmin2millisecs(CHECKUP_INTERVAL) +
1429 kamal.locahana 1.5                             nowMilliseconds;
1430                                         //
1431                                         //  End tests when failed to acquire the Client PID  or
1432 j.alex         1.2                      //  status.
1433                                         //
1434 kumpf          1.10                     if (!getClientPidRc)
1435 j.alex         1.2                      {
1436                                             outPrintWriter<<
1437                                                 "Failed to communicate with clients."<<endl;
1438                                             log_file<<StressTestControllerCommand::COMMAND_NAME<<
1439                                                 "::Failed to communicate with clients. "<<endl;
1440                                             log_file<<StressTestControllerCommand::COMMAND_NAME<<
1441                                                 "::Get Client PID FAILED. "<<endl;
1442                                             TestFailed = true;
1443                                             break;
1444                                         }
1445                                         log_file<<StressTestControllerCommand::COMMAND_NAME<<
1446                                             "::Checking current tolerance level. "<<endl;
1447                                         //
1448                                         // Output Client info if verbose is enabled.
1449                                         //
1450                                         if (verboseEnabled)
1451                                         {
1452                                             outPrintWriter<<
1453                                                 StressTestControllerCommand::COMMAND_NAME<<
1454                                                 "::Checking current tolerance level. "<<endl;
1455                                             for (int i=0;i< actual_client; i++)
1456 j.alex         1.2                          {
1457                                                 outPrintWriter <<" Client: "<<i;
1458                                                 outPrintWriter <<" PID: "<<clientPIDs[i]<<", ";
1459                                                 outPrintWriter <<" Status: "<<clientStatus[i]<<endl;
1460                                                 log_file <<" Client: "<<i;
1461                                                 log_file <<" PID: "<<clientPIDs[i]<<", ";
1462                                                 log_file <<" Status: "<<clientStatus[i]<<", ";
1463                                                 log_file<<"   TimeStamp: "<<
1464                                                     convertUint64toString(clientTimeStamp[i])<<
1465                                                     endl;
1466                                             }
1467                                         }
1468 kamal.locahana 1.5                      //
1469 j.alex         1.2                      // Check the actual tolerance level
1470                                         //
1471                                         Boolean withinTolerance = _checkToleranceLevel(
1472                                                                       actual_client,
1473                                                                       nowMilliseconds,
1474                                                                       log_file);
1475 kamal.locahana 1.5                      //
1476 j.alex         1.2                      //  End tests if not within tolerance
1477                                         //
1478                                         if (!withinTolerance)
1479                                         {
1480                                             log_file<<"FAILED::Tests NOT within tolerance."<<endl;
1481                                             errPrintWriter<<"FAILED::Tests NOT within tolerance."
1482                                                           <<endl;
1483                                             TestFailed = true;
1484                                             break;
1485                                         }
1486 kamal.locahana 1.5                      //
1487                                         //  Within Tolerance - Continue tests.
1488 j.alex         1.2                      //
1489                                         log_file<<"********Tests are within tolerance.********* "<<
1490 kamal.locahana 1.5                              endl;
1491 j.alex         1.2                      if (verboseEnabled)
1492                                         {
1493                                             outPrintWriter<<
1494                                                " ********Tests are within tolerance.**********"<<
1495                                                endl;
1496                                         }
1497                                     } /* if (nowMilliseconds >= nextCheckupInMillisecs)*/
1498                                     //
1499 kamal.locahana 1.5                  // Stop clients with delay
1500 j.alex         1.2                  //
1501                                     for (Uint32 clientID=0; clientID < _clientCount; clientID++)
1502 kamal.locahana 1.5                  {
1503 j.alex         1.2                      //
1504                                         // Get Current time
1505                                         //
1506 kamal.locahana 1.5                      nowMilliseconds =
1507 j.alex         1.2                          TimeValue::getCurrentTime().toMilliseconds();
1508                     
1509 kamal.locahana 1.5                      //
1510 j.alex         1.2                      // Stop only running clients as required.
1511                                         //
1512 kumpf          1.4                      if (!clientStopped.get()[clientID])
1513 j.alex         1.2                      {
1514 kamal.locahana 1.5                          //
1515 j.alex         1.2                          // If Client's duration is up
1516                                             //
1517 kumpf          1.4                          if (clientStopMilliseconds.get()[clientID] <=
1518                                                     nowMilliseconds)
1519 j.alex         1.2                          {
1520 kamal.locahana 1.5                              //
1521 j.alex         1.2                              // Stop all the instances of this client
1522                                                 //
1523 kumpf          1.9                              for (Uint32 instanceID = 0;
1524 j.alex         1.2                                   instanceID<clientInstance[clientID];
1525                                                      instanceID++)
1526                                                 {
1527                                                     log_file<<"Stopping client:("<<
1528                                                         clientID+instanceID<<")"<<endl;
1529                                                     log_file<<"  with PID = "<<
1530                                                         clientPIDs[clientID+instanceID]<<endl;
1531                                                     outPrintWriter<<"Stopping client:("<<
1532                                                         clientID+instanceID<<")"<<endl;
1533                                                     outPrintWriter<<"  with PID = "<<
1534                                                         clientPIDs[clientID+instanceID]<<endl;
1535                                                     if (verboseEnabled)
1536                                                     {
1537                                                         tmTime = getCurrentActualTime();
1538                                                         strftime(
1539                                                             strTime,
1540                                                             256,
1541                                                             "%d/%m/%Y at %H:%M:%S\n",
1542                                                             &tmTime);
1543                                                         log_file<<"    Stopped on "<<strTime<<endl;
1544                                                     }
1545 kamal.locahana 1.5                                  String stopClientFile = String::EMPTY;
1546 j.alex         1.2                                  stopClientFile.append(pegasusHome);
1547                                                     stopClientFile.append(DEFAULT_TMPDIR);
1548                                                     stopClientFile.append("STOP_");
1549                                                     sprintf(
1550                                                         str,
1551                                                         "%d",
1552 kamal.locahana 1.5                                      clientPIDs[clientID+instanceID]);
1553 j.alex         1.2                                  stopClientFile.append(str);
1554                                                     //
1555                                                     // Required for Windows
1556                                                     //
1557                                                     ofstream stop_file(
1558                                                         stopClientFile.getCString(),
1559                                                         ios::out);
1560                                                     stop_file << "Stop Client PID : "<<
1561                                                               clientPIDs[clientID + instanceID]<<
1562                                                               endl;
1563                                                     stop_file.close();
1564                     #ifndef PEGASUS_OS_TYPE_WINDOWS
1565                                                     // one more way to stop the clients.
1566 kumpf          1.10                                 int killRc =
1567 j.alex         1.2                                    kill(clientPIDs[clientID+instanceID], SIGINT);
1568 kumpf          1.10                                 if (killRc)
1569 j.alex         1.2                                  {
1570                                                         outPrintWriter<<"FAILED to stop client:("<<
1571                                                             clientID+instanceID<<")"<<endl;
1572                                                         log_file<<"FAILED to stop client:("<<
1573                                                             clientID + instanceID<<")"<<endl;
1574                                                     }
1575                     #endif
1576                                                     //
1577                                                     // Set the client as inactive.
1578                                                     //
1579                                                     clientActive[clientID + instanceID] = false;
1580                                                 }/* for (int instanceID =0;instanceID<clientInst..*/
1581                                                 //
1582 kamal.locahana 1.5                              // indicate that the client was stopped.
1583 j.alex         1.2                              //
1584 kumpf          1.4                              clientStopped.get()[clientID] = true;
1585 kamal.locahana 1.5                              //
1586 j.alex         1.2                              // If the Client has a Wait time
1587                                                 //
1588 kumpf          1.4                              if (_clientDelays.get()[clientID] !=0)
1589 j.alex         1.2                              {
1590 kamal.locahana 1.5                                  clientDelayMilliseconds.get()[clientID] =
1591 kumpf          1.4                                      nowMilliseconds +
1592                                                             _clientDelays.get()[clientID];
1593                                                     clientDelayed.get()[clientID] = true;
1594 j.alex         1.2                              }
1595                                             } /* if (clientStopMilliseconds[clientID]<= nowMilli..*/
1596 kumpf          1.4                      }  /*  if (!clientStopped.get()[clientID]) */
1597 kamal.locahana 1.5                      else
1598 j.alex         1.2                      {
1599                                             //
1600                                             // Only restart clients that are waiting.
1601                                             //
1602 kumpf          1.4                          if (clientDelayed.get()[clientID])
1603 j.alex         1.2                          {
1604                                                 //
1605                                                 // When waiting period is consumed.
1606                                                 //
1607 kumpf          1.4                              if (clientDelayMilliseconds.get()[clientID] <=
1608 j.alex         1.2                                  nowMilliseconds)
1609                                                 {
1610                                                     //
1611                                                     //  Restart all the instances of the client.
1612                                                     //
1613 kumpf          1.9                                  for (Uint32 instanceID = 0;
1614 j.alex         1.2                                      instanceID<clientInstance[clientID];
1615                                                         instanceID++)
1616                                                     {
1617                                                         act_command=String::EMPTY;
1618                     #ifdef PEGASUS_OS_TYPE_WINDOWS
1619                                                         act_command.append("start ");
1620                     #endif
1621                                                         act_command.append(
1622 kumpf          1.4                                          _clientCommands.get()[clientID]);
1623 j.alex         1.2                                      act_command.append(" -clientid ");
1624 kumpf          1.9                                      sprintf(str,"%u",clientID+instanceID);
1625 j.alex         1.2                                      act_command.append(str);
1626                                                         act_command.append(" -pidfile ");
1627                                                         act_command.append(" \"");
1628 kumpf          1.4                                      act_command.append(
1629                                                             _stressTestClientPIDFile);
1630 j.alex         1.2                                      act_command.append("\"");
1631                                                         act_command.append(" -clientlog");
1632                                                         act_command.append(" \"");
1633 kumpf          1.4                                      act_command.append(
1634                                                             _stressTestClientLogFile);
1635 j.alex         1.2                                      act_command.append("\"");
1636                                                         act_command.append("&");
1637                                                         log_file<<"Restarting client:("<<
1638                                                             clientID+instanceID<<")"<<endl;
1639                                                         outPrintWriter<<"Restarting client:("<<
1640                                                             clientID+instanceID<<")"<<endl;
1641                                                         if (verboseEnabled)
1642                                                         {
1643                                                             outPrintWriter<<"  "<<act_command<<endl;
1644                                                             log_file<<"     ("<<
1645                                                                 clientID+instanceID<<
1646                                                                 ") \n"<<act_command<<endl;
1647                                                             tmTime = getCurrentActualTime();
1648                                                             strftime(
1649                                                                 strTime,
1650                                                                 256,
1651                                                                 "%d/%m/%Y at %H:%M:%S\n",
1652                                                                 &tmTime);
1653                                                             log_file<<"   Restarted on "<<
1654                                                                 strTime<<endl;
1655                                                         }
1656 kumpf          1.10                                     int commandRc =
1657                                                             system(act_command.getCString());
1658                                                         if (commandRc)
1659 kamal.locahana 1.5                                      {
1660 j.alex         1.2                                          log_file<<"Command failed to Execute."<<
1661                                                                 endl;
1662                                                             if (verboseEnabled)
1663                                                             {
1664 kamal.locahana 1.5                                              outPrintWriter<<act_command<<
1665 j.alex         1.2                                                  "Command failed to Execute."<<
1666                                                                     endl;
1667                                                             }
1668                                                         }
1669                                                         clientActive[clientID+instanceID] = true;
1670 kumpf          1.9                                  } /* for (Uint32 instanceID =0;instanceID .. */
1671 kamal.locahana 1.5                                  clientStopMilliseconds.get()[clientID] =
1672                                                         nowMilliseconds +
1673 kumpf          1.4                                          _clientDurations.get()[clientID];
1674                                                     clientStopped.get()[clientID] = false;
1675                                                     clientDelayed.get()[clientID] = false;
1676 j.alex         1.2                              }/* if(clientDelayMilliseconds[clientID]<=nowMi.. */
1677 kumpf          1.4                          } /* if(clientDelayed.get()[clientID]) */
1678 j.alex         1.2                      } /* else ..*/
1679                                     } /* for(Uint32 clientID=0;clientID < _clientCount;clientID++)*/
1680                                 } /* else for if(!actual_client) */
1681                                 //
1682                                 // Get Current time
1683                                 //
1684                                 nowMilliseconds = TimeValue::getCurrentTime().toMilliseconds();
1685                     
1686                             } /* while(stopMilliseconds > nowMilliseconds) */
1687 kamal.locahana 1.5  
1688 j.alex         1.2      }//try
1689 kamal.locahana 1.5  
1690 j.alex         1.2      catch (const StressTestControllerException& e)
1691                         {
1692 kamal.locahana 1.5          errPrintWriter << StressTestControllerCommand::COMMAND_NAME <<
1693 j.alex         1.2              ": " << e.getMessage () << endl;
1694                             return (RC_ERROR);
1695                         }
1696                     
1697 kamal.locahana 1.5      //
1698 j.alex         1.2      //  Stress Tests should be stopped.
1699                         //
1700                         outPrintWriter<<"Ending tests::Preparing to stop all the clients."<<endl;
1701                         log_file<<"Ending tests::Preparing to stop all the clients."<<endl;
1702                     
1703 kamal.locahana 1.5      // Waiting to allow any clients that might have been re-started
1704                         // just before the tests were ended to add
1705 j.alex         1.2      // its pid to the pid file.
1706                     
1707                     #ifndef PEGASUS_OS_TYPE_WINDOWS
1708 kamal.locahana 1.5      sleep(STOP_DELAY);
1709 j.alex         1.2  #else
1710                         Sleep(STOP_DELAY * 1000);
1711                     #endif
1712                     
1713                         //
1714                         // get all the clientPIDs before it is stopped.
1715                         //
1716 kumpf          1.10     int getClientPidRc = _getClientPIDs(actual_client,log_file);
1717                         if (!getClientPidRc)
1718 j.alex         1.2      {
1719                             outPrintWriter<<"Failed to communicate with clients."<<endl;
1720                             log_file<<StressTestControllerCommand::COMMAND_NAME<<
1721                                 "::Failed to communicate with clients. "<<endl;
1722                             log_file<<"                    ::Failed to get client PID & status. "<<
1723                                 endl;
1724                             TestFailed = true;
1725                         }
1726                         tmTime = getCurrentActualTime();
1727                         strftime(strTime,256,"%d/%m/%Y at %H:%M:%S\n",&tmTime);
1728                         log_file<<"Ending tests:: Stopping all the clients on "<<strTime <<endl;
1729                         for (int i=0;i<actual_client;i++)
1730                         {
1731                             if(verboseEnabled)
1732                             {
1733                                 outPrintWriter<<"Stopping Client("<<i<<") with PID:"<<
1734                                     clientPIDs[i]<<endl;
1735                             }
1736                             log_file<<"Stopping Client("<<i<<") with PID:"<<clientPIDs[i]<<endl;
1737                             //
1738                             // Required for Windows
1739 j.alex         1.2          //
1740 kamal.locahana 1.5          String stopClientFile = String::EMPTY;
1741 j.alex         1.2          stopClientFile.append(pegasusHome);
1742                             stopClientFile.append(DEFAULT_TMPDIR);
1743                             stopClientFile.append("STOP_");
1744 kamal.locahana 1.5          sprintf(str,"%d",clientPIDs[i]);
1745 j.alex         1.2          stopClientFile.append(str);
1746                             ofstream stop_file(stopClientFile.getCString(),ios::out);
1747                             stop_file << "Stop Client PID : "<<clientPIDs[i]<<endl;
1748                             stop_file.close();
1749                     #ifndef PEGASUS_OS_TYPE_WINDOWS
1750                             // Another way to stop the client
1751 kumpf          1.10         int killRc = kill(clientPIDs[i], SIGINT);
1752                             if (killRc)
1753 j.alex         1.2          {
1754                                if (verboseEnabled)
1755                                {
1756                                    outPrintWriter<<"Failed to stop client:("<<i<<")"<<endl;
1757                                }
1758                                log_file<<"Failed to stop client:("<<i<<")"<<endl;
1759                             }
1760                     #endif
1761                         }
1762                         if (verboseEnabled)
1763                         {
1764                           outPrintWriter<<"Cleaning all resources"<<endl;
1765                         }
1766                         log_file<<"Cleaning all resources."<<endl;
1767                         cleanupProcess();
1768 kamal.locahana 1.5  
1769 j.alex         1.2      //
1770 kamal.locahana 1.5      // Waiting to allow clients to shutdown
1771 j.alex         1.2      //
1772                     #ifndef PEGASUS_OS_TYPE_WINDOWS
1773 kamal.locahana 1.5      sleep(SHUTDOWN_DELAY);
1774 j.alex         1.2  #else
1775                         Sleep(SHUTDOWN_DELAY * 1000);
1776                     #endif
1777 kamal.locahana 1.5      //
1778 j.alex         1.2      // If the test did not run to completition
1779                         //
1780                         if (TestFailed)
1781                             return(RC_ERROR);
1782                     
1783                         return (RC_SUCCESS);
1784                     } /* execute */
1785                     
1786                     
1787                     /*
1788 kamal.locahana 1.5      Retrieves the contents of the config file if specified or uses default
1789 j.alex         1.2      values from either the default config file
1790                     
1791                         @param   fileName           The specified or default config file for the
1792 kamal.locahana 1.5                                  tests.
1793 j.alex         1.2      @param   log_file           The log file.
1794                     
1795                         @return  true               if the file was read successfully
1796                                  false              if file was not read successfully.
1797                     
1798                      */
1799                     Boolean StressTestControllerCommand::getFileContent(
1800                         String fileName,
1801                         ostream& log_file)
1802                     {
1803                         String configData = String::EMPTY;
1804                         String line;
1805                         int lineNumber = 0;
1806                         Boolean isSuccess = true;
1807                         String name = String::EMPTY;
1808                         String value = String::EMPTY;
1809                         String ErrReports = String::EMPTY;
1810                     
1811                         ifstream ifs;
1812                     
1813                         //
1814 j.alex         1.2      // Open the config file and read the stress test configuration data
1815                         //
1816                         Open(ifs,fileName);
1817                         if (!ifs)
1818                         {
1819                             log_file<<StressTestControllerCommand::COMMAND_NAME<<
1820                                 "::Cannot read config file: "<<fileName<<endl;
1821                             throw NoSuchFile(fileName);
1822                         }
1823                     
1824                         log_file<<StressTestControllerCommand::COMMAND_NAME <<
1825                             "::Storing client details. "<<endl;
1826                         if (verboseEnabled)
1827                         {
1828                             cout<<StressTestControllerCommand::COMMAND_NAME<<
1829                                 "::Storing config details. "<<endl;
1830                         }
1831                         //
1832                         // Get each line of the file.
1833                         //
1834                         while (GetLine(ifs, line))
1835 j.alex         1.2      {
1836                             ++lineNumber;
1837                             IsAClient = false;
1838                             name = String::EMPTY;
1839                             value = String::EMPTY;
1840 kamal.locahana 1.5          try
1841 j.alex         1.2          {
1842                                 //
1843                                 // Parse each line of Config file
1844                                 //
1845                                 _parseLine(line,lineNumber,name,value,log_file);
1846 kamal.locahana 1.5          }
1847 j.alex         1.2          //
1848                             // catch all the exceptions if any thrown from parseLine
1849 kamal.locahana 1.5          //   - Accumulate all the errors from the config file
1850                             //   - Report all errors if found when complete.
1851 j.alex         1.2          //
1852                             catch (Exception& e)
1853                             {
1854                                 char line_num[10];
1855                                 sprintf(line_num, "%d", lineNumber);
1856                                 String msg(e.getMessage());
1857                                 ErrReports.append("\n    ");
1858                                 ErrReports.append("line#");
1859                                 ErrReports.append(line_num);
1860                                 ErrReports.append(":: ");
1861                                 ErrReports.append(msg.getCString());
1862                                 log_file<<StressTestControllerCommand::COMMAND_NAME<<"::"
1863                                     <<msg<<endl;
1864                                 isSuccess = false;
1865                             }
1866                             catch(...)
1867                             {
1868                                 char line_num[10];
1869                                 sprintf(line_num, "%d", lineNumber);
1870                                 ErrReports.append("\n    ");
1871                                 ErrReports.append("line#");
1872 j.alex         1.2              ErrReports.append(line_num);
1873                                 ErrReports.append(":: ");
1874                                 ErrReports.append("Unknown exception caught.");
1875                                 log_file<<StressTestControllerCommand::COMMAND_NAME<<
1876                                     ":Unknown exception caught when parsing line."<<endl;
1877                                 cerr<<StressTestControllerCommand::COMMAND_NAME <<
1878                                    ":Unknown exception caught when parsing line."<<endl;
1879 kamal.locahana 1.5              return false;
1880 j.alex         1.2          }
1881                     
1882                             if ((IsClientOptions)||(IgnoreLine))
1883                             {
1884                                 IsClientOptions = false;
1885                                 IgnoreLine = false;
1886                                 continue;
1887                             }
1888                             //
1889                             // If its a client Update the table
1890                             //
1891                             if (IsAClient)
1892                             {
1893                                 _currClient=name;
1894                                 _currClientCount=_clientCount;
1895                                 //
1896                                 // save the client details in a table
1897                                 //
1898                                 if (!_storeClientDetails(name,value))
1899                                 {
1900                                     log_file<<StressTestControllerCommand::COMMAND_NAME<<
1901 j.alex         1.2                      "::Syntax error found in line#"<<lineNumber<<
1902                                         " of config file: "<<fileName<<endl;
1903                                     isSuccess = false;
1904                                 }
1905 kamal.locahana 1.5          }
1906                             else
1907                             {
1908 j.alex         1.2              //
1909                                 // Common properties are updated only if they are valid.
1910                                 //
1911                                 if (isSuccess)
1912 kamal.locahana 1.5              {
1913 j.alex         1.2                  //
1914                                     // Store the property name and value in the table
1915                                     //
1916                                     if (verboseEnabled)
1917                                     {
1918                                         cout<<"     "<<name<<"\t= "<<value<<endl;
1919                                     }
1920 kumpf          1.4                  if (!_propertyTable.insert(name, value))
1921 j.alex         1.2                  {
1922                                         //
1923                                         // Duplicate property, ignore the new property value.
1924                                         //
1925 j.alex         1.3  #ifdef STRESSTEST_DEBUG
1926 j.alex         1.2                      cout<< "Property Name:duplicate name already saved: "<<
1927                                             name<<endl;
1928                     #endif
1929                                         log_file<<StressTestControllerCommand::COMMAND_NAME<<
1930                                             "::Duplicate property name "<<name<<" already saved."<<
1931                                             endl;
1932                                     }
1933                                 }
1934                             }
1935                     
1936                         }
1937                         ifs.close();
1938                         //
1939 kamal.locahana 1.5      // If a client is not read from the config file
1940 j.alex         1.2      //
1941                         if ((lineNumber==0)||(!_clientCount))
1942                         {
1943                             ErrReports.append("\n    ");
1944                             ErrReports.append(StressTestControllerCommand::COMMAND_NAME);
1945                             ErrReports.append("::No clients found.");
1946                             log_file<<StressTestControllerCommand::COMMAND_NAME <<
1947                                 "::No clients found in"<<" config file: "<<fileName<<endl;
1948                             isSuccess = false;
1949                         }
1950                         //
1951                         // Error was found.
1952                         //
1953                         if (!isSuccess)
1954                         {
1955 kamal.locahana 1.5         //
1956 j.alex         1.2         // cleanup allocated memory
1957                            //
1958                            cleanupProcess();
1959 kamal.locahana 1.5         throw StressTestControllerException(ErrReports);
1960 j.alex         1.2      }
1961                     
1962                         log_file<<StressTestControllerCommand::COMMAND_NAME<<
1963                             "::Common Properties:"<<endl;
1964                         if (verboseEnabled)
1965                         {
1966                             cout<<StressTestControllerCommand::COMMAND_NAME<<
1967                                 "::Common Properties:"<<endl;
1968                         }
1969 kumpf          1.4      for (Table::Iterator i = _propertyTable.start(); i; i++)
1970 j.alex         1.2      {
1971                             log_file<<"      "<<i.key()<<"\t= "<<i.value()<<endl;
1972                             if (verboseEnabled)
1973                             {
1974                                 cout<<"      "<<i.key()<<"\t= "<<i.value()<<endl;
1975                             }
1976                         }
1977                         if (verboseEnabled)
1978                         {
1979                             cout<<"Total clients found:"<<_clientCount<<endl;
1980                             cout<<"CLIENT TABLE CONTENTS:"<<endl;
1981                         }
1982                         log_file<<StressTestControllerCommand::COMMAND_NAME<<
1983                             "::Client Properties:"<<endl;
1984                         for (Uint32 j = 0; j < _clientCount; j++)
1985                         {
1986                             log_file<<"Client information #"<<j+1<<" from config file:"<<endl;
1987                             if (verboseEnabled)
1988                             {
1989                                 cout<<"Client("<<j<<")"<<endl;
1990                             }
1991 kumpf          1.4          for (Table::Iterator i = _clientTable.get()[j].start(); i; i++)
1992 j.alex         1.2          {
1993                                 log_file<<"    "<<i.key()<<"    = "<<i.value()<<endl;
1994                                 if (verboseEnabled)
1995                                 {
1996                                     cout<<"   "<< i.key() << "=" << i.value() << endl;
1997                                 }
1998                             }
1999                         }
2000 kamal.locahana 1.5  
2001                     
2002 j.alex         1.2      if (isSuccess)
2003                         {
2004                            log_file<<StressTestControllerCommand::COMMAND_NAME<<
2005                                "::Successfully retreived config values from" <<
2006                                " config file: "<<fileName<<endl;
2007                         }
2008                         return isSuccess;
2009                     }/* getFileContent */
2010                     
2011 kamal.locahana 1.5  
2012 j.alex         1.2  /*
2013 kamal.locahana 1.5      Validates the configuration data found in the specified config file or
2014 j.alex         1.2      the default config file.
2015                         Will validate known common/client specific properties in configuration.
2016 kamal.locahana 1.5      Will validate valid client names.
2017 j.alex         1.2        (Clients are excepted to  exist in the $PEGASUS_HOME/bin directory)
2018                     
2019                         @param   vars               The property name to be validated
2020                         @param   value              The property value associated to the above name
2021                     
2022                         @return  true               if the property was validated successfully
2023                                  false              if the property failed validation.
2024                     
2025                      */
2026                     
2027                     
2028                     Boolean StressTestControllerCommand::_validateConfiguration(
2029                         String & vars,
2030                         const String & value,
2031                         ostream& log_file)
2032                     {
2033                         Boolean IsValid = false;
2034                     
2035 kamal.locahana 1.5  
2036 j.alex         1.2      if (String::equalNoCase(vars,HOSTNAME))
2037                         {
2038                             vars=String::EMPTY;
2039                             vars.append(HOSTNAME);
2040                             if(!IsAClient)
2041                             {
2042                                 if (!_hostNameSpecified)
2043                                 {
2044                                     _hostName = value;
2045                                 }
2046 kamal.locahana 1.5          }
2047 j.alex         1.2          else
2048                             {
2049 kamal.locahana 1.5  
2050 j.alex         1.2              if(_hostName != String::EMPTY)
2051                                 {
2052                                     if (!String::equalNoCase(value,_hostName))
2053                                     {
2054                                         log_file<<StressTestControllerCommand::COMMAND_NAME<<
2055                                             "::Multiple hostnames were found. "<<endl;
2056                                         if (verboseEnabled)
2057                                         {
2058                                             cout<<StressTestControllerCommand::COMMAND_NAME <<
2059                                                 "::Multiple hostnames were found. "<<endl;
2060                                         }
2061                                         return false;
2062                                     }
2063                                 }
2064                                 else
2065 kamal.locahana 1.5              {
2066 j.alex         1.2                  _hostName = value;
2067                                 }
2068                             }
2069                         }
2070                         else if (String::equalNoCase(vars,PORTNUMBER))
2071                         {
2072                             vars=String::EMPTY;
2073                             vars.append(PORTNUMBER);
2074                             Uint32 vPortNumber = atoi(value.getCString());
2075 kamal.locahana 1.5  
2076 j.alex         1.2          log_file<<StressTestControllerCommand::COMMAND_NAME <<
2077                                 "::Portnumber  specified in config = "<<vPortNumber<<endl;
2078                             if (verboseEnabled)
2079                             {
2080                                 cout<<StressTestControllerCommand::COMMAND_NAME <<
2081                                     "::Portnumber  specified in config = "<<vPortNumber<<endl;
2082                             }
2083                             if (vPortNumber > _MAX_PORTNUMBER)
2084                             {
2085                                 //
2086                                 //  Portnumber out of valid range
2087                                 //
2088                                 if (verboseEnabled)
2089                                 {
2090                                     cout<<StressTestControllerCommand::COMMAND_NAME <<
2091                                         "::Invalid portnumber  was found. "<<endl;
2092                                 }
2093                                 log_file<<StressTestControllerCommand::COMMAND_NAME<<
2094                                     "::Invalid portnumber  was found. "<<endl;
2095                                 return false;
2096                             }
2097 j.alex         1.2          if (!_portNumberSpecified)
2098                             {
2099                                 _portNumber = atoi(value.getCString());
2100                             }
2101                     
2102                         }/* else if (String::equalNoCase ... */
2103                         else if (String::equalNoCase(vars,SSL))
2104                         {
2105                             log_file<<StressTestControllerCommand::COMMAND_NAME<<
2106                                 "::SSL enabled in config. "<<endl;
2107                             if (!_useSSL)
2108                             {
2109                                 _useSSL = true;
2110                             }
2111                         }
2112                         else if (String::equalNoCase(vars,USERNAME))
2113                         {
2114                             vars=String::EMPTY;
2115                             vars.append(USERNAME);
2116                             log_file<<StressTestControllerCommand::COMMAND_NAME<<
2117                                 "::UserName  specified in config = "<<value<<endl;
2118 j.alex         1.2          if (!_userNameSpecified)
2119                             {
2120                                _userName = value;
2121                             }
2122                         }
2123                         else if (String::equalNoCase(vars,PASSWORD))
2124                         {
2125                             vars=String::EMPTY;
2126                             vars.append(PASSWORD);
2127                             if(!_passwordSpecified)
2128                             {
2129                                 _password = value;
2130                             }
2131                             log_file<<StressTestControllerCommand::COMMAND_NAME<<
2132                                 "::Password  specified in config = "<<value<<endl;
2133                         }
2134                         else if (String::equalNoCase(vars,DURATION))
2135                         {
2136                             vars=String::EMPTY;
2137                             vars.append(DURATION);
2138                             //
2139 j.alex         1.2          // converting to a double
2140                             //
2141                             if (!IsAClient)
2142                             {
2143                                 _duration = atof(value.getCString());
2144                                 if (_duration > _MIN_DURATION)
2145                                 {
2146                                     log_file<<StressTestControllerCommand::COMMAND_NAME<<
2147                                         "::Duration  specified in config = "<<value<<endl;
2148 kamal.locahana 1.5              }
2149 j.alex         1.2              else
2150                                 {
2151                                     log_file<<StressTestControllerCommand::COMMAND_NAME<<
2152                                         "::Invalid Duration  was specified. "<<endl;
2153                                     return false;
2154                                 }
2155                             }
2156                         }
2157                         else if (String::equalNoCase(vars,TOLERANCELEVEL))
2158                         {
2159                             _toleranceLevel =  atoi(value.getCString());
2160                             log_file<<StressTestControllerCommand::COMMAND_NAME<<
2161                                 "::ToleranceLevel  specified in config = "<<value<<endl;
2162 kamal.locahana 1.5          if (_toleranceLevel > _MAX_TOLERANCE)
2163 j.alex         1.2          {
2164                                 if(verboseEnabled)
2165                                 {
2166                                     cout<<StressTestControllerCommand::COMMAND_NAME <<
2167                                         "::Invalid Tolerance level  was specified. "<<endl;
2168                                 }
2169                                 log_file<<StressTestControllerCommand::COMMAND_NAME<<
2170                                     "::Invalid Tolerance level  was specified. "<<endl;
2171                     
2172                                 return false;
2173                             }
2174                         }
2175                         else if (String::equalNoCase(vars,NAMESPACE))
2176                         {
2177                             _nameSpace = value;
2178                             log_file<<StressTestControllerCommand::COMMAND_NAME <<
2179                                 "::NameSpace  specified in config = "<<value<<endl;
2180                         }
2181                         else if (String::equalNoCase(vars,CLASSNAME))
2182                         {
2183                             _className = value;
2184 j.alex         1.2          log_file<<StressTestControllerCommand::COMMAND_NAME<<
2185                                 "::Class name  specified in config = "<<value<<endl;
2186                         }
2187                         else
2188 kamal.locahana 1.5      {
2189 j.alex         1.2         if (!IsAClient)
2190                            {
2191                                IsAClient=true;
2192                                int instance = atoi(value.getCString());
2193                                //
2194                                // Check if the instances are set correctly
2195 kamal.locahana 1.5             // Must be greater than 0
2196 j.alex         1.2             //
2197                                if (instance <=0)
2198                                {
2199                                   //
2200 kamal.locahana 1.5                // Invalid Instance value
2201 j.alex         1.2                //
2202                                   return false;
2203                                }
2204                                //
2205                                // Check if client exists or is valid.
2206                                // Clients are expected to be in the $PEGASUS_HOME/bin directory
2207                                //
2208                                String clientName = String(DEFAULT_BINDIR);
2209                                clientName.append(vars.getCString());
2210 john.eisenbraun 1.14 #if defined(PEGASUS_OS_TYPE_WINDOWS) || defined(PEGASUS_OS_VMS)
2211 j.alex          1.2             clientName.append(".exe");
2212                      #endif
2213                                 if (!FileSystem::exists(clientName))
2214                                 {
2215                                     String testString = String::EMPTY;
2216                                     testString.append("Test");
2217                                     Uint32 Index = vars.find(testString);
2218                                     if (Index != 0)
2219                                     {
2220                                         clientName = String(DEFAULT_BINDIR);
2221                                         testString.append(vars.getCString());
2222                                         clientName.append(testString.getCString());
2223 john.eisenbraun 1.14 #if defined(PEGASUS_OS_TYPE_WINDOWS) || defined(PEGASUS_OS_VMS)
2224 j.alex          1.2                     clientName.append(".exe");
2225                      #endif
2226                                         if (!FileSystem::exists(clientName))
2227                                         {
2228                                             //
2229                                             // Invalid client name
2230                                             //
2231 kamal.locahana  1.5                         IsValid = false;
2232 j.alex          1.2                     }
2233 kamal.locahana  1.5                     else
2234 j.alex          1.2                     {
2235 kamal.locahana  1.5                         IsValid = true;
2236 j.alex          1.2                         vars=String::EMPTY;
2237                                             vars.append(testString.getCString());
2238                                         }
2239                                     }
2240                                     else
2241                                     {
2242 kamal.locahana  1.5  
2243 j.alex          1.2                     //
2244                                         // Invalid client name
2245                                         //
2246                                         IsValid = false;
2247 kamal.locahana  1.5                 }
2248                                 }
2249                                 else
2250 j.alex          1.2             {
2251                                     IsValid = true;
2252                                 }
2253                                 if (!IsValid)
2254                                 {
2255                                    if (verboseEnabled)
2256                                    {
2257                                        cout<<StressTestControllerCommand::COMMAND_NAME <<
2258                                            "::Invalid Client Name = "<<vars<<endl;
2259                                    }
2260                                    String ErrReport = String("Invalid Client Name:");
2261                                    ErrReport.append(vars.getCString());
2262 kamal.locahana  1.5                throw StressTestControllerException(ErrReport);
2263 j.alex          1.2             }
2264                                 return IsValid;
2265                             }
2266                              log_file<<StressTestControllerCommand::COMMAND_NAME<<"::"<<vars<<
2267                                  " = "<<value<<endl;
2268                             //
2269                             // otherwise accept the properties listed with the clients.
2270                             //
2271                          }
2272                          return true;
2273                      
2274                      } /* _validateConfiguration */
2275                      
2276                      /*
2277                          Retrieves the client specific options from the config file.
2278                          Will check for syntax errors with the client options.
2279                          - Will retrieve all the client options in the line until ']'
2280 kamal.locahana  1.5      - Client options/properties in Config file are
2281 j.alex          1.2        represented as follows:
2282 kamal.locahana  1.5           -   "[" indicates start of client options.
2283                               -   "]" indicates end of client options.
2284 j.alex          1.2           -   Client properties and values are seperated by commas.
2285                               Example:
2286 kamal.locahana  1.5                [clientName=cimcli,Options=niall]
2287 j.alex          1.2      - This method will throw appropriate exceptions.
2288                      
2289                          @param   p               The pointer to the char in the concerned line
2290                      
2291                      
2292                       */
2293                      void StressTestControllerCommand::_getClientOptions(
2294                          const Char16* p,
2295                          ostream& log_file)
2296                      {
2297                          //
2298                          // Get the property name
2299                          //
2300                          String name = String::EMPTY;
2301                          String value = String::EMPTY;
2302                      
2303                          while (*p != ']')
2304 kamal.locahana  1.5      {
2305 j.alex          1.2          //
2306                              // Skip whitespace after property name
2307                              //
2308                              while (*p && isspace(*p))
2309                              {
2310                                  p++;
2311                              }
2312                              if (!(isalpha(*p) || *p == '_'))
2313                              {
2314 kumpf           1.4              throw StressTestControllerException(
2315 kamal.locahana  1.5                  StressTestControllerException::INVALID_OPTION);
2316 j.alex          1.2          }
2317                      
2318                              name.append(*p++);
2319                      
2320                      
2321                              while (isalnum(*p) || *p == '_')
2322                              {
2323                                  name.append(*p++);
2324                              }
2325                      
2326                              //
2327                              // Skip whitespace after property name
2328                              //
2329                              while (*p && isspace(*p))
2330                              {
2331                                  p++;
2332                              }
2333 kamal.locahana  1.5  
2334 j.alex          1.2          //
2335                              // Expect an equal sign
2336                              //
2337                              if (*p != '=')
2338                              {
2339 kumpf           1.4              throw StressTestControllerException(
2340 kamal.locahana  1.5                  StressTestControllerException::INVALID_OPERATOR);
2341 j.alex          1.2          }
2342                      
2343                              p++;
2344                      
2345                              //
2346                              // Skip whitespace after equal sign
2347                              //
2348                              while (*p && isspace(*p))
2349                              {
2350                                  p++;
2351                              }
2352                      
2353                              //
2354                              // Get the value
2355                              //
2356                      
2357                              while (*p && *p != ']' && *p != ',')
2358                              {
2359                                  value.append(*p++);
2360                              }
2361                              //
2362 kamal.locahana  1.5          // Skip whitespace after value
2363 j.alex          1.2          //
2364                              while (*p && isspace(*p))
2365                              {
2366                                  cout << "got space after value\n";
2367                                  p++;
2368                              }
2369                      
2370                              if(*p !=']' && *p != ',')
2371                              {
2372 kumpf           1.4              throw StressTestControllerException(
2373 kamal.locahana  1.5                  StressTestControllerException::MISSING_BRACE);
2374 j.alex          1.2          }
2375                              if(value == String::EMPTY)
2376                              {
2377 kumpf           1.4              throw StressTestControllerException(
2378 kamal.locahana  1.5                  StressTestControllerException::MISSING_VALUE);
2379 j.alex          1.2          }
2380 kamal.locahana  1.5  
2381 j.alex          1.3  #ifdef STRESSTEST_DEBUG
2382 j.alex          1.2          cout<<"name="<<name<<endl;
2383                              cout<<"Before validate config: value="<<value<<endl;
2384                      #endif
2385                              //
2386                              // validate client property
2387 kamal.locahana  1.5          //
2388 j.alex          1.2          Boolean IsValid=_validateConfiguration(name,value,log_file);
2389                              if(!IsValid)
2390                              {
2391                                  String ErrReport = String("Invalid Client property value: ");
2392                                  ErrReport.append(name);
2393                                  ErrReport.append("=");
2394                                  ErrReport.append(value);
2395 kamal.locahana  1.5              throw StressTestControllerException(ErrReport);
2396 j.alex          1.2          }
2397                              //
2398                              // Save client property in client table if valid.
2399                              //
2400 kumpf           1.4          if (!_clientTable.get()[_currClientCount].insert(name,value))
2401 j.alex          1.2          {
2402                                  //
2403                                  // Duplicate property, ignore the new property value.
2404                                  // Log this message in a log file.
2405                                  //
2406                                 log_file<< "duplicate name already saved: "<<name<<endl;
2407                                 if (verboseEnabled)
2408                                 {
2409                                    cout<< "duplicate name already saved: "<<name<<endl;
2410                                 }
2411                              }
2412                              if (*p ==',')
2413                              {
2414                                  name = String::EMPTY;
2415                                  value = String::EMPTY;
2416                                  p++;
2417                                  continue;
2418                              }
2419                          }
2420 kamal.locahana  1.5  
2421 j.alex          1.2      if ((name == String::EMPTY)||(value == String::EMPTY))
2422 kamal.locahana  1.5      {
2423 j.alex          1.2          String ErrReport = String("Missing Name & Value for client option:");
2424 kamal.locahana  1.5          throw StressTestControllerException(ErrReport);
2425 j.alex          1.2      }
2426                      } /* _getClientOptions */
2427                      
2428                      
2429                      /*
2430 kamal.locahana  1.5      Retrieves the Client PIDs and the corresponding status of the
2431                          clients started by the Controller from the PID file.
2432 j.alex          1.2      Each line in the PID file if not a comment is expected to
2433                          have the following format:
2434                             <clientid>::<client_pid>::<client_status>::<timeStampInMillisec>
2435                          Example:
2436                               1::7582::0::4119329327
2437                      
2438                          Client PID, status and Time Stamp from the PID file will be saved
2439 kamal.locahana  1.5      in the following global array's for each client.
2440 j.alex          1.2        clientPIDs
2441                            clientStatus
2442                            clientTimeStamp
2443 kamal.locahana  1.5  
2444                      
2445                          @param   actual_clients  The actual number of clients executed by the
2446 j.alex          1.2                               Controller.
2447                          @param   log_file        The log file.
2448                      
2449                          @return  true            if the status and PIDs were read successfully
2450                                   false           Failed to read the status & PIDs of clients.
2451                      
2452                       */
2453                      Boolean StressTestControllerCommand::_getClientPIDs(
2454                          int actual_clients,
2455                          ostream& log_file)
2456                      {
2457                      
2458                          ifstream ifs;
2459                      
2460                          //
2461                          // Make a temp copy of the file
2462                          //
2463                          Boolean cTempFile = FileSystem::copyFile(
2464                              _stressTestClientPIDFile,
2465                              _tmpStressTestClientPIDFile);
2466                      
2467 j.alex          1.2      if(!cTempFile)
2468                          {
2469                              cout<<"Cannot copy file "<<_stressTestClientPIDFile<<endl;
2470                              log_file<<StressTestControllerCommand::COMMAND_NAME<<
2471                                  "::Cannot copy PID file: "<<_stressTestClientPIDFile<<endl;
2472                              return (false);
2473                          }
2474                          //
2475                          // Open the temp PID file and retreive all the client PIDs and status
2476                          //
2477                          Open(ifs,_tmpStressTestClientPIDFile);
2478                      
2479                          String line;
2480                      
2481                          const Char16* p;
2482                          int lineNumber= 0;
2483                          Boolean isSuccess=false;
2484                          //
2485                          // get each line until end of file.
2486                          //
2487                          while (GetLine(ifs, line))
2488 j.alex          1.2      {
2489                              ++lineNumber;
2490 j.alex          1.3  #ifdef STRESSTEST_DEBUG
2491 j.alex          1.2          log_file<<" Line number:"<<lineNumber<<endl;
2492                              log_file<<"      "<<line<<endl;
2493                      #endif
2494                              p = line.getChar16Data();
2495                      
2496                              while (*p && isspace(*p))
2497                              {
2498                                  p++;
2499                              }
2500                      
2501                              //
2502                              // Skip comment lines
2503                              //
2504                              if ((!*p)||(*p == '#'))
2505                              {
2506                                  continue;
2507                              }
2508                      
2509                              //
2510                              // Get the client ID
2511                              //
2512 j.alex          1.2          String client = String::EMPTY;
2513                              while (isalnum(*p) || *p == '_')
2514                              {
2515                                  client.append(*p++);
2516                              }
2517                      
2518                              //
2519                              // Skip whitespace after property name
2520                              //
2521                              while (*p && isspace(*p))
2522                              {
2523                                  p++;
2524                              }
2525                      
2526                              //
2527 kamal.locahana  1.5          // Expecting a colon
2528 j.alex          1.2          //
2529                              if (*p != ':')
2530                              {
2531                                  ifs.close();
2532                                  log_file<<StressTestControllerCommand::COMMAND_NAME<<
2533                                      "::Syntax Error in PID file line number:"<<lineNumber<<endl;
2534                                  FileSystem::removeFile(_tmpStressTestClientPIDFile);
2535                                  return(isSuccess = false);
2536                              }
2537                      
2538                              //
2539                              // point to next character in line.
2540                              //
2541                              p++;
2542                      
2543                              //
2544 kamal.locahana  1.5          // Expecting a colon
2545 j.alex          1.2          //
2546                              if (*p != ':')
2547                              {
2548                                  ifs.close();
2549                                  log_file<<StressTestControllerCommand::COMMAND_NAME<<
2550                                      "::Syntax Error in PID file line number:"<<lineNumber<<endl;
2551                                  FileSystem::removeFile(_tmpStressTestClientPIDFile);
2552                                  return(isSuccess = false);
2553                              }
2554 kamal.locahana  1.5  
2555 j.alex          1.2          //
2556                              // point to next character in line.
2557                              //
2558                              p++;
2559                      
2560                              //
2561 kamal.locahana  1.5          // Skip whitespace after colon
2562 j.alex          1.2          //
2563                              while (*p && isspace(*p))
2564                              {
2565                                  p++;
2566                              }
2567                      
2568                              //
2569 kamal.locahana  1.5          // Get the client PID
2570 j.alex          1.2          //
2571                              String clntPID = String::EMPTY;
2572                              while (isalnum(*p) || *p == '_')
2573                              {
2574                                  clntPID.append(*p++);
2575                              }
2576 kamal.locahana  1.5  
2577 j.alex          1.2          //
2578                              // Skip whitespace after property name
2579                              //
2580                              while (*p && isspace(*p))
2581                              {
2582                                  p++;
2583                              }
2584                      
2585                              //
2586 kamal.locahana  1.5          // Expecting a colon
2587 j.alex          1.2          //
2588                              if (*p != ':')
2589                              {
2590                                  ifs.close();
2591                                  log_file<<StressTestControllerCommand::COMMAND_NAME <<
2592                                      "::Syntax Error in PID file line number:"<<lineNumber<<endl;
2593                                  FileSystem::removeFile(_tmpStressTestClientPIDFile);
2594                                  return(isSuccess = false);
2595                              }
2596                      
2597                              //
2598                              // point to next character in line.
2599                              //
2600                              p++;
2601                      
2602                              //
2603 kamal.locahana  1.5          // Expecting a colon
2604 j.alex          1.2          //
2605                              if (*p != ':')
2606                              {
2607                                  ifs.close();
2608                                  log_file<<StressTestControllerCommand::COMMAND_NAME <<
2609                                      "::Syntax Error in PID file line number:"<<lineNumber<<endl;
2610                                  FileSystem::removeFile(_tmpStressTestClientPIDFile);
2611                                  return(isSuccess = false);
2612                              }
2613                              p++;
2614                      
2615                              //
2616 kamal.locahana  1.5          // Skip whitespace after the colon if any
2617 j.alex          1.2          //
2618                              while (*p && isspace(*p))
2619 kamal.locahana  1.5          {
2620 j.alex          1.2              p++;
2621                              }
2622                      
2623                              String clntStatus = String::EMPTY;
2624                              while (isalnum(*p) || *p == '_')
2625                              {
2626                                  clntStatus.append(*p++);
2627                              }
2628                      
2629                              //
2630                              // Skip whitespace after property name
2631                              //
2632                              while (*p && isspace(*p))
2633                              {
2634                                  p++;
2635                              }
2636                      
2637                              //
2638 kamal.locahana  1.5          // Expecting a colon
2639 j.alex          1.2          //
2640                              if (*p != ':')
2641                              {
2642                                  ifs.close();
2643                                  log_file<<StressTestControllerCommand::COMMAND_NAME <<
2644                                      "::Syntax Error in PID file line number:"<<lineNumber<<endl;
2645                                  FileSystem::removeFile(_tmpStressTestClientPIDFile);
2646                                  return(isSuccess = false);
2647                              }
2648                      
2649                              //
2650                              // next character in line.
2651                              //
2652                              p++;
2653                      
2654                              if (*p != ':')
2655                              {
2656                                  ifs.close();
2657                                  log_file<<StressTestControllerCommand::COMMAND_NAME<<
2658                                      "::Syntax Error in PID file line number:"<<lineNumber<<endl;
2659                                  FileSystem::removeFile(_tmpStressTestClientPIDFile);
2660 j.alex          1.2              return(isSuccess = false);
2661                              }
2662                              //
2663                              // next character in line.
2664                              //
2665                              p++;
2666                              //
2667 kamal.locahana  1.5          // Skip whitespace after the colon if any
2668 j.alex          1.2          //
2669                              while (*p && isspace(*p))
2670                              {
2671                                  p++;
2672                              }
2673                      
2674                              //
2675 kamal.locahana  1.5          // Get the client timestamp
2676 j.alex          1.2          //
2677                              String clntTmStmp = String::EMPTY;
2678                              while (isalnum(*p))
2679                              {
2680                                  clntTmStmp.append(*p++);
2681                              }
2682                      
2683                              //
2684 kamal.locahana  1.5          // Store the PID, Status and TimeStamp for each client
2685 j.alex          1.2          //
2686                              if(atoi(client.getCString()) <= actual_clients)
2687                              {
2688 kamal.locahana  1.5              clientPIDs[atoi(client.getCString())] =
2689 j.alex          1.2                  (pid_t)atoi(clntPID.getCString());
2690 kamal.locahana  1.5              clientStatus[atoi(client.getCString())] =
2691 j.alex          1.2                  (pid_t)atoi(clntStatus.getCString());
2692                                  sscanf(
2693                                      (const char*)clntTmStmp.getCString(),
2694                                      "%" PEGASUS_64BIT_CONVERSION_WIDTH "u",
2695                                      &clientTimeStamp[atoi(client.getCString())]);
2696                              }
2697                              else
2698                              {
2699                                  if (verboseEnabled)
2700                                  {
2701                                      log_file<<StressTestControllerCommand::COMMAND_NAME<<
2702                                          "::Unknown client PID for client#"<<
2703                                          atoi(client.getCString())<<
2704                                          " read at line number:"<<lineNumber<<endl;
2705                                      cout<<"Unknown Client PID recieved"<<endl;
2706                                  }
2707 kamal.locahana  1.5          }
2708 j.alex          1.2      }
2709                          //
2710                          // remove the temporary file.
2711                          //
2712                          FileSystem::removeFile(_tmpStressTestClientPIDFile);
2713                          return(isSuccess = true);
2714                      }/* _getClientPIDs */
2715                      
2716                      /*
2717 kamal.locahana  1.5     Parses specified line to retrieve valid config data for the stress tests.
2718 j.alex          1.2     - Identifies client specific properties from common properties in config file
2719                         - Saves all the client specific data from the config file into appropriate
2720                           client tables.
2721                         - Saves all the common properties in the property table
2722                         - This method will throw appropriate exceptions.
2723                         Config File Format:
2724                           - All comments begin with "#"
2725                           - Properties in Config file are represented as follows:
2726                                <property> = <property value>
2727 kamal.locahana  1.5       - Client options/properties in Config file are
2728 j.alex          1.2         represented as follows:
2729 kamal.locahana  1.5           -   "[" indicates start of client options.
2730 j.alex          1.2           -   Client properties and values are seperated by commas.
2731                               Example:
2732 kamal.locahana  1.5                [clientName=cimcli,Options=niall]
2733 j.alex          1.2  
2734                          @param   line            The line that will be parsed.
2735                          @parm    lineNumber      The line number of the line.
2736                          @parm    name            The property name that will be retrieved.
2737                          @parm    value           The property value of the name.
2738 kamal.locahana  1.5      @parm    log_file        The log file.
2739 j.alex          1.2  
2740                          @return  true            Succesfully parsed the line.
2741 kamal.locahana  1.5               false           Failed to parse the lines successfully.
2742 j.alex          1.2   */
2743                      Boolean StressTestControllerCommand::_parseLine(
2744                          const String & line,
2745                          int lineNumber,
2746                          String &name,
2747                          String &value,
2748                          ostream& log_file)
2749                      {
2750                      
2751                          const Char16* p;
2752                          p = line.getChar16Data();
2753                      
2754                          //
2755                          // Skip whitespace
2756                          //
2757                          while (*p && isspace(*p))
2758                          {
2759                             p++;
2760                          }
2761                      
2762 kamal.locahana  1.5      //
2763 j.alex          1.2      //  Ignore empty lines
2764                          //
2765                          if (!*p)
2766                          {
2767                             IgnoreLine = true;
2768                             return IgnoreLine;
2769                          }
2770                      
2771                          //
2772                          // Skip comment lines
2773                          //
2774                          if (*p == '#')
2775                          {
2776                             IgnoreLine = true;
2777                             return IgnoreLine;
2778                          }
2779                      
2780                          //
2781 kamal.locahana  1.5      // Retreive all the Client Options
2782 j.alex          1.2      //   "[" indicates start of client options.
2783                          //
2784                          if (*p == '[')
2785                          {
2786                             IsAClient = true;
2787                             IsClientOptions = true;
2788                             p++;
2789 kamal.locahana  1.5         //
2790 j.alex          1.2         // Ignore spaces before client property
2791                             //
2792                             while (*p && isspace(*p))
2793                             {
2794                               p++;
2795                             }
2796                             //
2797                             // Invalid Client property name
2798                             //
2799                             if (!(isalpha(*p) || *p == '_'))
2800                             {
2801                                  String ErrReport = String("Syntax Error with client options:");
2802                                  ErrReport.append(line.getCString());
2803 kamal.locahana  1.5              throw StressTestControllerException(ErrReport);
2804 j.alex          1.2         }
2805 kamal.locahana  1.5         //
2806 j.alex          1.2         // Retrieve client options
2807                             //
2808                             try
2809                             {
2810                                 //
2811 kamal.locahana  1.5             //  get and validate client options
2812 j.alex          1.2             //
2813                                 _getClientOptions(p,log_file);
2814                             }
2815                             catch (Exception& e)
2816                             {
2817                                 String msg(e.getMessage());
2818                                 if ((name == String::EMPTY)
2819                                    ||(value == String::EMPTY))
2820                                 {
2821                                     msg.append(" in ");
2822                                     msg.append(line.getCString());
2823                                 }
2824 kamal.locahana  1.5             throw StressTestControllerException(msg);
2825 j.alex          1.2         }
2826                             catch (...)
2827                             {
2828                                 String msg = String(
2829                                     "Unknown exception caught when geting client options.");
2830                                 log_file<<StressTestControllerCommand::COMMAND_NAME <<
2831                                     ":Unknown exception caught when geting client options."<<endl;
2832                                 cerr<<StressTestControllerCommand::COMMAND_NAME <<
2833                                     ":Unknown exception caught when geting client options."<<endl;
2834 kamal.locahana  1.5             throw StressTestControllerException(msg);
2835 j.alex          1.2          }
2836                      
2837                              //
2838                              // Successfully retrieved all the client options.
2839                              //
2840                              return true;
2841                          }
2842                      
2843                          //
2844 kamal.locahana  1.5      // Get Common Properties
2845 j.alex          1.2      //
2846                          name = String::EMPTY;
2847                      
2848                          //
2849                          // Invalid Common Property name
2850                          //
2851                          if (!(isalpha(*p) || *p == '_'))
2852                          {
2853                             String ErrReport = String("Invalid Property Value: ");
2854                             ErrReport.append(name);
2855                             ErrReport.append("=");
2856                             ErrReport.append(value);
2857                             throw StressTestControllerException(ErrReport);
2858                          }
2859                      
2860                          //
2861                          // Save the property Name
2862                          //
2863                          name.append(*p++);
2864                          while (isalnum(*p) || *p == '_')
2865                          {
2866 j.alex          1.2          name.append(*p++);
2867                          }
2868                      
2869                          //
2870                          // Skip whitespace after property name
2871                          //
2872                          while (*p && isspace(*p))
2873                          {
2874                              p++;
2875                          }
2876                      
2877                          //
2878                          // Expect an equal sign
2879                          //
2880                          if (*p != '=')
2881                          {
2882                             String ErrReport = String("Invalid Property Value: ");
2883                             ErrReport.append(name);
2884                             ErrReport.append("=");
2885                             ErrReport.append(value);
2886                             throw StressTestControllerException(ErrReport);
2887 j.alex          1.2      }
2888                      
2889                          //
2890                          // go to next
2891 kamal.locahana  1.5      //
2892 j.alex          1.2      p++;
2893                      
2894                          //
2895 kamal.locahana  1.5      // Retrive the property value
2896 j.alex          1.2      //   Skip whitespace after equal sign
2897                          //
2898                          while (*p && isspace(*p))
2899                          {
2900                              p++;
2901                          }
2902                      
2903                          //
2904                          // Get the value
2905                          //
2906                          value = String::EMPTY;
2907                          while (*p)
2908                          {
2909                              value.append(*p++);
2910                          }
2911 j.alex          1.3  #ifdef STRESSTEST_DEBUG
2912 j.alex          1.2      cout<<"name="<<name<<endl;
2913                          cout<<"value="<<value<<endl;
2914                      #endif
2915                          IsAClient = false;
2916                          Boolean IsValid = false;
2917 kamal.locahana  1.5      //
2918 j.alex          1.2      // Validate property and its value
2919                          //
2920                          try
2921                          {
2922                              IsValid=_validateConfiguration(name,value,log_file);
2923                          }
2924                          catch (Exception& e)
2925                          {
2926                              String msg(e.getMessage());
2927 kamal.locahana  1.5          throw StressTestControllerException(msg);
2928 j.alex          1.2      }
2929                          if (!IsValid)
2930                          {
2931                             String ErrReport = String("Invalid Property Value: ");
2932                             ErrReport.append(name);
2933                             ErrReport.append("=");
2934                             ErrReport.append(value);
2935                             throw StressTestControllerException(ErrReport);
2936                          }
2937                          return true;
2938                      } /* _parseLine */
2939                      
2940                      /*
2941                          Storing client details in a table.
2942 kamal.locahana  1.5      - Stores the Client name  and instance for specific clients in their
2943 j.alex          1.2        respective client table for later use.
2944                      
2945                          @parm    name            The client name that will be stored.
2946                          @parm    value           The number of instances of the client.
2947                      
2948                          @return  true            Succesfully stored the name or instance.
2949                                   false           Failed to store the name or instance.
2950                       */
2951                      Boolean StressTestControllerCommand::_storeClientDetails(
2952                          String name,
2953                          String value)
2954                      {
2955 kamal.locahana  1.5  
2956                          //
2957 j.alex          1.2      // Expand the client table as required.
2958                          //
2959                          if (_clientCount >= Total_Clients)
2960                          {
2961                              Total_Clients += NEW_CLIENTS;
2962 kamal.locahana  1.5          Table* tempClientTable = new Table[Total_Clients];
2963 kumpf           1.4          for (Uint32 i = 0; i < _clientCount; i++)
2964 j.alex          1.2          {
2965 kumpf           1.4              tempClientTable[i] = _clientTable.get()[i];
2966 j.alex          1.2          }
2967 kumpf           1.4          _clientTable.reset(tempClientTable);
2968                          }
2969 j.alex          1.2  
2970 kamal.locahana  1.5      //
2971 j.alex          1.2      // Store the client Name in the table
2972 kamal.locahana  1.5      //
2973 kumpf           1.4      if (!_clientTable.get()[_clientCount].insert(NAME, name))
2974 j.alex          1.2      {
2975                              //
2976                              // Duplicate property, ignore the new property value.
2977                              //
2978                              if (verboseEnabled)
2979                              {
2980                                  cout<< "Duplicate Client already saved: "<<endl;
2981                              }
2982                              return false;
2983                          }
2984                      
2985 kamal.locahana  1.5      //
2986 j.alex          1.2      // Store the number of instances for the client in the table
2987 kamal.locahana  1.5      //
2988 kumpf           1.4      if (!_clientTable.get()[_clientCount].insert(INSTANCE, value))
2989 j.alex          1.2      {
2990                      
2991                             //
2992                             // Duplicate property, ignore the new property value.
2993                             //
2994                             if(verboseEnabled)
2995                             {
2996                                cout<< "Duplicate Instance already saved: "<<endl;
2997                             }
2998                             return false;
2999                          }
3000                          ++_clientCount;
3001                          return true;
3002                      } /* _storeClientDetails */
3003                      
3004                      /*
3005                          Will check the current tolerance level of the running clients with
3006                          respect to the expected tolerance level.
3007 kamal.locahana  1.5      @parm    actual_client     The total number of executed clients.
3008 j.alex          1.2      @parm    nowMilliseconds   The current time in milliseconds.
3009                          @parm    log_file          The log_file.
3010                      
3011                          @return  true            Clients with tolerance.
3012                                   false           Clients failed tolerance.
3013                       */
3014                      Boolean StressTestControllerCommand::_checkToleranceLevel(
3015                          int actual_client,
3016                          Uint64 nowMilliseconds,
3017 kamal.locahana  1.5      ostream& log_file)
3018 j.alex          1.2  {
3019                          int count = 0;
3020                          int failed_count = 0;
3021 kamal.locahana  1.5      Uint64 lastUpdateinMilliSec =0;
3022 j.alex          1.2      Boolean withinTolerance = false;
3023                      
3024                          for (int i=0;i<actual_client;i++)
3025                          {
3026 kamal.locahana  1.5          //
3027 j.alex          1.2          //Observe only the status of running clients
3028                              //
3029                              if (clientActive[i])
3030                              {
3031                                  ++count;
3032                                  //
3033                                  //  Validate the timestamps:
3034 kamal.locahana  1.5              //  The timestamps on the status is compared to the previous
3035                                  //  timestamp to ensure that the status has been updated within
3036 j.alex          1.2              //  the previous 2 updates.
3037                                  //
3038                                  if(clientStatus[i]== VALID_RESPONSE)
3039                                  {
3040                                      //
3041                                      //check with the last timestamp
3042                                      //
3043                                      lastUpdateinMilliSec = nowMilliseconds - clientTimeStamp[i];
3044                                      //
3045                                      // Assume failure if status update is
3046 kamal.locahana  1.5                  // longer than 2 * checkup interval
3047 j.alex          1.2                  //
3048                                      if ((clientTimeStamp[i] == prev_clientTimeStamp[i])
3049                                         && (lastUpdateinMilliSec >=
3050                                         (2 * (Uint64)convertmin2millisecs(CHECKUP_INTERVAL))))
3051 kamal.locahana  1.5                  {
3052 j.alex          1.2                      if (verboseEnabled)
3053                                          {
3054                                              log_file <<" Status not updated for client (" <<i<<
3055                                                  ")pid :"<<clientPIDs[i]<<endl;
3056 kamal.locahana  1.5                          log_file << "        for the past " <<
3057 j.alex          1.2                              2*(CHECKUP_INTERVAL) << " minutes." << endl;
3058                                              cout<<" Status not updated for client ("<<i<<")pid :"<<
3059                                                  clientPIDs[i]<<endl;
3060                                              cout<<"        for the past " << 2*(CHECKUP_INTERVAL)<<
3061                                                  " minutes." << endl;
3062                                          }
3063 kamal.locahana  1.5                      ++failed_count;
3064 j.alex          1.2                  }
3065                                  }
3066                                  //
3067                                  // If unknown status - server or client may be hung.
3068                                  // Two consective failures on the same client will be counted
3069 kamal.locahana  1.5              // as a failed client.
3070 j.alex          1.2              //
3071                                  if (((clientStatus[i]== NO_RESPONSE)
3072                                     ||(clientStatus[i]== INVALID_RESPONSE))
3073                                     &&((prev_clientStatus[i]== NO_RESPONSE)
3074                                       ||(prev_clientStatus[i]== INVALID_RESPONSE)))
3075                                  {
3076                                      if (verboseEnabled)
3077                                      {
3078                                          if (clientStatus[i]== INVALID_RESPONSE)
3079                                          {
3080                                              log_file<<
3081                                                  "Recieved an Invalid response Status from client("<<
3082                                                  i <<") pid :"<<clientPIDs[i]<<endl;
3083                                          }
3084                                          else
3085 kamal.locahana  1.5                      {
3086 j.alex          1.2                          log_file<<"Recieved a no response Status from client("<<
3087                                                  i <<") pid :"<<clientPIDs[i]<<endl;
3088                                          }
3089                                      }
3090 kamal.locahana  1.5                  ++failed_count;
3091 j.alex          1.2              } /* if (((clientStatus[i]== NO_RESPONSE) ... */
3092                                  //
3093                                  // Save previous time stamp of client
3094                                  //
3095                                  prev_clientTimeStamp[i] = clientTimeStamp[i];
3096                                  prev_clientStatus[i] = clientStatus[i];
3097                              } /* if (clientActive[i]) */
3098                          }
3099                          //
3100                          // check actual tolerance
3101                          //
3102                          if(count > 0)
3103                          {
3104                              double curr_tolerancePercent = getToleranceInPercent(
3105                                                                 failed_count,
3106                                                                 (double)count);
3107                              if (verboseEnabled)
3108                              {
3109                                  cout<<" total running clients ="<<count<<endl;
3110                                  cout<<" failed clients ="<<failed_count<<endl;
3111                                  cout<<"Actual Tolerance % ="<<curr_tolerancePercent<<endl;
3112 j.alex          1.2              cout<<"Expected Tolerance % ="<<_toleranceLevel<<endl;
3113                                  log_file<<"Total Running clients:"<<count<<endl;
3114                                  log_file<<"Actual Failed clients:"<<failed_count<<endl;
3115                                  log_file<<"::Expected Tolerance:"<<_toleranceLevel<<endl;
3116                                  log_file<<"::Actual Tolerance:"<<curr_tolerancePercent<<endl;
3117                              }
3118                              if ((double)_toleranceLevel >= curr_tolerancePercent)
3119                              {
3120                                  withinTolerance = true;
3121                              }
3122                              return(withinTolerance);
3123                          }
3124                          //
3125                          // All process are stopped.
3126                          //
3127                          return(withinTolerance = true);
3128                      } /* _checkToleranceLevel */
3129                      
3130                      
3131                      /*
3132                          This will populate the client table with the hard coded
3133 j.alex          1.2      values for the stress tests.
3134 kamal.locahana  1.5      This method is only used if the default configuration
3135 j.alex          1.2      file does not exist.
3136 kamal.locahana  1.5      Default clients are 5 instances of
3137 j.alex          1.2      "TestWrapperStressClient" and "TestModelWalkStressClient".
3138                      
3139 kamal.locahana  1.5      @parm    log_file      The log_file.
3140                      
3141 j.alex          1.2   */
3142                      void StressTestControllerCommand::getDefaultClients(ostream& log_file)
3143                      {
3144                          //
3145                          // Setting the client count to default client value
3146                          //
3147 kamal.locahana  1.5      _clientCount = DEFAULT_CLIENTS;
3148 j.alex          1.2  
3149 kamal.locahana  1.5      log_file << "Populating default configuration for stress Tests." << endl;
3150 j.alex          1.2      if (verboseEnabled)
3151                          {
3152 kamal.locahana  1.5          cout << "Populating default configuration for stress Tests." << endl;
3153 j.alex          1.2      }
3154                          //
3155                          // Populating default client attributes
3156                          //
3157                          for (Uint32 i=0;i<_clientCount; i++)
3158                          {
3159                              //
3160                              // Adding the default instance value to each client table
3161                              //
3162 kumpf           1.4          if (!_clientTable.get()[i].insert(INSTANCE, DEFAULT_INSTANCE))
3163 j.alex          1.2          {
3164                                  log_file <<  "Duplicate name already saved: "<<INSTANCE<<endl;
3165                                  if (verboseEnabled)
3166                                  {
3167                                      cout<< "duplicate name already saved: "<<INSTANCE<<endl;
3168                                  }
3169                              }
3170                              switch(i)
3171 kamal.locahana  1.5          {
3172 j.alex          1.2              case 0:
3173                                  {
3174 kumpf           1.4                  if (!_clientTable.get()[i].insert(NAME, MODELWALK_CLIENT))
3175 j.alex          1.2                  {
3176                                          log_file <<  "Duplicate name already saved: "<<NAME<<endl;
3177                                          if (verboseEnabled)
3178                                          {
3179                                              cout<< "Duplicate name already saved: "<<NAME<<endl;
3180                                          }
3181                                      }
3182 kumpf           1.4                  log_file << "Stress Test Client Name:" << MODELWALK_CLIENT <<
3183                                          endl;
3184 j.alex          1.2                  if (verboseEnabled)
3185                                      {
3186 kamal.locahana  1.5                      cout<< "Stress Test Client Name:"<<MODELWALK_CLIENT<< endl;
3187 j.alex          1.2                  }
3188                      
3189                                      break;
3190                                  }
3191                                  case 1:
3192                                  {
3193 kumpf           1.4                  if (!_clientTable.get()[i].insert(NAME, WRAPPER_CLIENT))
3194 j.alex          1.2                  {
3195                                          log_file <<  "Duplicate name already saved: "<<NAME<<endl;
3196                                          if (verboseEnabled)
3197                                          {
3198                                              cout<< "Duplicate name already saved: "<<NAME<<endl;
3199                                          }
3200                                      }
3201 kamal.locahana  1.5                  log_file << "Stress Test Client Name:" <<WRAPPER_CLIENT<< endl;
3202 j.alex          1.2                  if (verboseEnabled)
3203                                      {
3204 kamal.locahana  1.5                      cout << "Stress Test Client Name:" <<WRAPPER_CLIENT<< endl;
3205 j.alex          1.2                  }
3206 kamal.locahana  1.5                  if (!_clientTable.get()[i].insert(CLIENTNAME, "cimcli"))
3207 j.alex          1.2                  {
3208                                          log_file<< "Duplicate name already saved: "<<
3209                                              CLIENTNAME<<endl;
3210 kamal.locahana  1.5                      if (verboseEnabled)
3211                                          {
3212 j.alex          1.2                          cout<< "Duplicate name already saved: "<<
3213                                                  CLIENTNAME<<endl;
3214                                          }
3215                                      }
3216 kumpf           1.4                  if (!_clientTable.get()[i].insert(OPTIONS, "niall"))
3217 j.alex          1.2                  {
3218                                          log_file<< "Duplicate name already saved: "<<OPTIONS<<endl;
3219                                          if (verboseEnabled)
3220                                          {
3221                                              cout<< "Duplicate name already saved: "<<OPTIONS<<endl;
3222 kamal.locahana  1.5                      }
3223 j.alex          1.2                  }
3224 kumpf           1.7                  log_file <<
3225                                          "            Client Command &  options: cimcli niall" <<
3226 kamal.locahana  1.5                      endl;
3227 j.alex          1.2                  if (verboseEnabled)
3228                                      {
3229 kumpf           1.7                      cout <<
3230                                              "            Client Command &  options: cimcli niall" <<
3231                                              endl;
3232 j.alex          1.2                  }
3233                                      break;
3234                                  } /* case 1: */
3235                              } /* switch(i) */
3236                          } /* for(Uint32 i=0;i<_clientCount; i++) */
3237                      
3238                      } /* getDefaultClients */
3239                      
3240                      
3241                      
3242                      
3243                      /**
3244                          Will generate or create all the required files for the tests.
3245 kamal.locahana  1.5      - Required log files, pid files, client log file are created here.
3246 j.alex          1.2  
3247 kamal.locahana  1.5      @parm    strTime         The time stamp for the tests.
3248 j.alex          1.2                               This is used in the naming of the log file.
3249                      
3250                          @return  true            The files were successfully created.
3251                                   false           Failed to create one or more of the required
3252                                                   files.
3253                      
3254                       */
3255                      Boolean StressTestControllerCommand::generateRequiredFileNames(char *strTime)
3256                      {
3257                          char pid_str[15];
3258                          ofstream log_file;
3259                          ofstream pid_file;
3260                          ofstream clntlog_file;
3261                      
3262                          sprintf(pid_str, "%d", getpid());
3263 kamal.locahana  1.5  
3264 j.alex          1.2      //
3265                          // Stress Controller Log file
3266                          //
3267                          _stressTestLogFile.append(pegasusHome);
3268                          _stressTestLogFile.append(TESTDIR);
3269                          FileSystem::makeDirectory(_stressTestLogFile);
3270                          _stressTestLogFile.append(STRESSTESTDIR);
3271                          FileSystem::makeDirectory(_stressTestLogFile);
3272                          _stressTestLogFile.append(LOGDIR);
3273                          FileSystem::makeDirectory(_stressTestLogFile);
3274                          _stressTestLogFile.append(pid_str);
3275                          _stressTestLogFile.append("_stressTest_");
3276                          _stressTestLogFile.append(strTime);
3277                          _stressTestLogFile.append("log");
3278                      
3279                          //
3280                          // StressClient PID  file
3281                          //
3282                          _stressTestClientPIDFile.append(pegasusHome);
3283                          _stressTestClientPIDFile.append(DEFAULT_TMPDIR);
3284                          FileSystem::makeDirectory(_stressTestClientPIDFile);
3285 j.alex          1.2      _stressTestClientPIDFile.append(pid_str);
3286                          _stressTestClientPIDFile.append("_StressTestClients");
3287                          _stressTestClientPIDFile.append(strTime);
3288                          _stressTestClientPIDFile.append("pid");
3289                      
3290                          //
3291                          // StressClient Log  file
3292                          //
3293                          _stressTestClientLogFile.append(pegasusHome);
3294                          _stressTestClientLogFile.append(DEFAULT_LOGDIR);
3295                          _stressTestClientLogFile.append(pid_str);
3296                          _stressTestClientLogFile.append("_StressTestClients");
3297                          _stressTestClientLogFile.append(".log");
3298 kamal.locahana  1.5  
3299 j.alex          1.2      //
3300                          // Temporary StressClient PID/status  file
3301                          //
3302                          _tmpStressTestClientPIDFile.append(pegasusHome);
3303                          _tmpStressTestClientPIDFile.append(DEFAULT_TMPDIR);
3304                          _tmpStressTestClientPIDFile.append(pid_str);
3305                          _tmpStressTestClientPIDFile.append("TEMP");
3306                          _tmpStressTestClientPIDFile.append("_Clients");
3307                          _tmpStressTestClientPIDFile.append(".pid");
3308                      
3309                          //
3310                          // Translate slashed for appropriate OS
3311                          //
3312                          FileSystem::translateSlashes(_stressTestClientPIDFile);
3313                          FileSystem::translateSlashes(_stressTestClientLogFile);
3314                          FileSystem::translateSlashes(_stressTestLogFile);
3315                          FileSystem::translateSlashes(_tmpStressTestClientPIDFile);
3316                      
3317                          //
3318                          // open the file
3319                          //
3320 j.alex          1.2      OpenAppend(log_file,_stressTestLogFile);
3321                          Open(pid_file,_stressTestClientPIDFile);
3322                          Open(clntlog_file,_stressTestClientLogFile);
3323                      
3324                          //
3325                          //  Failed to open the log file
3326                          //
3327                          if (!log_file)
3328                          {
3329                             log_file.close();
3330                             pid_file.close();
3331                             clntlog_file.close();
3332                             cout<<"Cannot get file "<<_stressTestLogFile<<endl;
3333                             return false;
3334                      
3335                          }
3336                          //
3337                          //  Failed to open the pid file
3338                          //
3339                          if (!pid_file)
3340                          {
3341 j.alex          1.2         cout<<"Cannot get file "<<_stressTestClientPIDFile<<endl;
3342                             log_file<<StressTestControllerCommand::COMMAND_NAME<<
3343                                 "Cannot read file "<<_stressTestClientPIDFile<<endl;
3344                             log_file.close();
3345                             clntlog_file.close();
3346                             return false;
3347                          }
3348                          //
3349                          //  Failed to open the clntlog file
3350                          //
3351                          if (!clntlog_file)
3352                          {
3353                             log_file<<StressTestControllerCommand::COMMAND_NAME<<
3354                                 "Cannot read file "<<_stressTestClientLogFile<<endl;
3355                             log_file.close();
3356                             pid_file.close();
3357                             return false;
3358                          }
3359                      
3360                          //
3361                          // Successfully opened all the files.
3362 j.alex          1.2      //
3363                          pid_file<<"#"<<StressTestControllerCommand::COMMAND_NAME<<
3364                              " has the following clients:: \n";
3365                          clntlog_file<<"#"<<StressTestControllerCommand::COMMAND_NAME<<
3366                              "::Process ID:"<<getpid()<<endl;
3367                          clntlog_file.close();
3368                          pid_file.close();
3369                          return true;
3370                      
3371                      } /* generateRequiredFileNames */
3372                      
3373                      /**
3374                          Will remove all the unused files for the tests.
3375 kamal.locahana  1.5      - Unused log files & pid files are removed here.
3376 j.alex          1.2  
3377                       */
3378                      void StressTestControllerCommand::removeUnusedFiles()
3379                      {
3380                          FileSystem::removeFile(_stressTestClientPIDFile);
3381                          FileSystem::removeFile(_stressTestClientLogFile);
3382                      }
3383                      
3384                      PEGASUS_NAMESPACE_END
3385                      
3386                      /**
3387                          Cleanup function for stressTestController to free allocated
3388                          memory used to execute clients.
3389                       */
3390                      void cleanupProcess()
3391                      {
3392                      
3393                          delete [] clientPIDs;
3394                          delete [] clientStatus;
3395                          delete [] clientInstance;
3396                          delete [] clientActive;
3397 j.alex          1.2      delete [] clientTimeStamp;
3398                          delete [] prev_clientTimeStamp;
3399                          delete [] prev_clientStatus;
3400                      }
3401                      
3402                      /*
3403                          This will generate the current time.
3404                       */
3405                      struct tm getCurrentActualTime()
3406                      {
3407                          struct tm tmTime;
3408                          time_t inTime=time(NULL);
3409                      #ifdef PEGASUS_OS_TYPE_WINDOWS
3410                          tmTime=*localtime(&inTime);
3411                      #else
3412                          localtime_r(&inTime,&tmTime);
3413                      #endif
3414                          return tmTime;
3415                      }
3416                      
3417                      /**
3418 j.alex          1.2      Signal handler for SIGINT, SIGABRT.
3419                      
3420                          @param   signum  the signal identifier
3421                      */
3422                      void endAllTests(int signum)
3423                      {
3424                          if (verboseEnabled)
3425                          {
3426                              switch(signum)
3427                              {
3428                                  case SIGINT:
3429                                  {
3430                                      cout<<StressTestControllerCommand::COMMAND_NAME<<
3431                                          "::Recieved interupt signal SIGINT!"<<endl;
3432                                      break;
3433                                  }
3434                                  case SIGABRT:
3435                                  {
3436                                      cout<<StressTestControllerCommand::COMMAND_NAME<<
3437                                          "::Recieved signal SIGABRT!"<<endl;
3438                                      break;
3439 j.alex          1.2              }
3440                                  default:
3441                                  {
3442                                      cout<<StressTestControllerCommand::COMMAND_NAME<<
3443                                          "::Recieved Signal ( "<<signum<<"!" <<endl;
3444                                      break;
3445                                  }
3446                              }
3447                          }
3448                          //
3449                          // Sets the variable that will interupt stress tests
3450                          //
3451                          Quit = true;
3452                      } /* endAllTests */
3453                      
3454                      /**
3455                          This function will convert a Uint64
3456                          to a string.
3457                      
3458                          @param   x       The Uint64 integer
3459                      
3460 j.alex          1.2      @return  String  Returns the converted string.
3461                      */
3462                      String convertUint64toString(Uint64 x)
3463                      {
3464                          char buffer[32];
3465                          sprintf(buffer, "%" PEGASUS_64BIT_CONVERSION_WIDTH "u", x);
3466                          return(String(buffer));
3467                      }/* convertUint64toString(..) */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2