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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2