(file) Return to RepositoryUpgrade.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Clients / repupgrade

   1 karl  1.15 //%2006////////////////////////////////////////////////////////////////////////
   2 sushma.fernandes 1.1  //
   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 karl             1.15 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
  12                       // EMC Corporation; Symantec Corporation; The Open Group.
  13 sushma.fernandes 1.1  //
  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 karl             1.15 // 
  21 sushma.fernandes 1.1  // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
  22                       // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
  23                       // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
  24                       // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  25                       // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  26                       // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  27                       // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28                       // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29                       //
  30                       //==============================================================================
  31                       //
  32                       // Author : Sushma Fernandes, Hewlett-Packard Company
  33                       //         (sushma_fernandes@hp.com)
  34                       //
  35 david.dillard    1.5  // Modified By: David Dillard, VERITAS Software Corp.
  36                       //                  (david.dillard@veritas.com)
  37 aruran.ms        1.11 //              Aruran, IBM (ashanmug@in.ibm.com) for Bug# 4114
  38 sushma.fernandes 1.1  //
  39                       //%/////////////////////////////////////////////////////////////////////////////
  40                       
  41                       
  42                       #include <iostream>
  43                       
  44                       #include <Pegasus/Common/Config.h>
  45                       #include <Pegasus/Common/CIMName.h>
  46                       #include <Pegasus/Common/Constants.h>
  47                       #include <Pegasus/Common/String.h>
  48                       #include <Pegasus/Common/PegasusVersion.h>
  49                       #include <Pegasus/Common/XmlWriter.h>
  50                       #include <Pegasus/Common/TimeValue.h>
  51                       #include <Pegasus/Common/Exception.h>
  52                       #include <Pegasus/Common/FileSystem.h>
  53                       #include <Pegasus/Common/System.h>
  54                       #include <Pegasus/getoopt/getoopt.h>
  55                       #include <Clients/cliutils/CommandException.h>
  56 david            1.14 #ifdef PEGASUS_OS_OS400
  57                       #include <Pegasus/Common/Logger.h>
  58                       #endif
  59 sushma.fernandes 1.1  #include "RepositoryUpgrade.h"
  60                       
  61 w.otsuka         1.18 #if defined(PEGASUS_USE_RELEASE_DIRS) && defined (PEGASUS_OVERRIDE_DEFAULT_RELEASE_DIRS)
  62                       # include <Pegasus/Config/ProductDirectoryStructure.h>
  63                       #endif
  64                       
  65 sushma.fernandes 1.1  // Enables debug information.
  66 sushma.fernandes 1.2  // #define REPUPGRADE_DEBUG 1
  67 sushma.fernandes 1.1  
  68                       PEGASUS_NAMESPACE_BEGIN
  69                       
  70                       // Constant initializations.
  71                       
  72                       //l10n
  73                       /**
  74                        * The CLI message resource name
  75                        */
  76                       static const char MSG_PATH []                  = "pegasus/pegasusCLI";
  77                       
  78                       /**
  79                           The command name.
  80                        */
  81                       const char   RepositoryUpgrade::COMMAND_NAME []      = "repupgrade";
  82                       
  83                       /**
  84                           Label for the usage string for this command.
  85                        */
  86                       const char   RepositoryUpgrade::_USAGE []            = "Usage: ";
  87                       
  88 sushma.fernandes 1.1  /**
  89                           This constant signifies that an option has not
  90                           been recorded
  91                       */
  92                       const Uint32 RepositoryUpgrade::_OPTION_TYPE_UNINITIALIZED = 0;
  93                       
  94                       /**
  95                           This constant signifies that an old repository path option has been
  96                           been recorded
  97                       */
  98                       const Uint32 RepositoryUpgrade::_OPTION_TYPE_OLD_REPOSITORY_PATH = 1;
  99                       
 100                       /**
 101                           This constant signifies that an new repository path option has been
 102                           been recorded
 103                       */
 104                       const Uint32 RepositoryUpgrade::_OPTION_TYPE_NEW_REPOSITORY_PATH = 2;
 105                       
 106                       /**
 107                           The constant representing a help operation
 108                       */
 109 sushma.fernandes 1.1  const Uint32 RepositoryUpgrade::_OPTION_TYPE_HELP = 3;
 110                       
 111                       /**
 112                           The constant representing a version display operation
 113                       */
 114                       const Uint32 RepositoryUpgrade::_OPTION_TYPE_VERSION = 4;
 115                       
 116                       /**
 117                           The option character used to specify the old Repository path.
 118                        */
 119                       const char   RepositoryUpgrade::_OPTION_OLD_REPOSITORY_PATH     = 'o';
 120                       
 121                       /**
 122                           The option character used to specify the new Repository path.
 123                        */
 124                       const char   RepositoryUpgrade::_OPTION_NEW_REPOSITORY_PATH     = 'n';
 125                       
 126                       /**
 127                           The option character used to display help info.
 128                       */
 129                       const char   RepositoryUpgrade::_OPTION_HELP         = 'h';
 130 sushma.fernandes 1.1  
 131                       static const char   LONG_HELP []  = "help";
 132                       
 133 david            1.14 #ifdef PEGASUS_OS_OS400
 134                       /**
 135                           The option character used to suppress output.
 136                       */
 137                       const char   RepositoryUpgrade::_OPTION_QUIET     = 'q';
 138                       #endif
 139                       
 140 sushma.fernandes 1.1  /**
 141                           The option character used to display version info.
 142                       */
 143                       const char   RepositoryUpgrade::_OPTION_VERSION      = 'v';
 144                       
 145                       static const char   LONG_VERSION []  = "version";
 146                       
 147                       /**
 148                           Display messages.
 149                       */
 150                       static const char REQUIRED_ARGS_MISSING [] =
 151                                       "Required arguments missing.";
 152                       
 153                       static const char REQUIRED_ARGS_MISSING_KEY [] =
 154                                       "Clients.repupgrade.RepositoryUpgrade.REQUIRED_ARGS_MISSING";
 155                       
 156                       static const char REPOSITORY_UPGRADE_FAILURE []    =
 157                                       "Failed to upgrade repository. ";
 158                       
 159                       static const char REPOSITORY_UPGRADE_FAILURE_KEY []    =
 160                                   "Clients.repupgrade.RepositoryUpgrade.REPOSITORY_UPGRADE_FAILURE";
 161 sushma.fernandes 1.1  
 162                       static const char REPOSITORY_UPGRADE_UNKNOWN_ERROR []    =
 163                                       "Unknown error encountered during upgrade. ";
 164                       
 165                       static const char REPOSITORY_UPGRADE_UNKNOWN_ERROR_KEY []    =
 166 sushma.fernandes 1.16    "Clients.repupgrade.RepositoryUpgrade.REPOSITORY_UPGRADE_UNKNOWN_ERROR";
 167 sushma.fernandes 1.1  
 168                       static const char REPOSITORY_DOES_NOT_EXIST [] =
 169                                       "The specified location $0 does not exist. ";
 170                       
 171                       static const char REPOSITORY_DOES_NOT_EXIST_KEY [] =
 172                                 "Clients.repupgrade.RepositoryUpgrade.REPOSITORY_DOES_NOT_EXIST";
 173                       
 174                       static const char NAMESPACE_CREATION_ERROR [] =
 175                                       "Error creating namespace $0.";
 176                       
 177                       static const char NAMESPACE_CREATION_ERROR_KEY [] =
 178 sushma.fernandes 1.16            "Clients.repupgrade.RepositoryUpgrade.NAMESPACE_CREATION_ERROR";
 179 sushma.fernandes 1.1  
 180                       static const char CLASS_CREATION_ERROR [] =
 181                                       "Error creating class $0 in namespace $1.";
 182                       
 183                       static const char CLASS_CREATION_ERROR_KEY [] =
 184 sushma.fernandes 1.16                 "Clients.repupgrade.RepositoryUpgrade.CLASS_CREATION_ERROR";
 185 sushma.fernandes 1.1  
 186                       static const char INSTANCE_CREATION_ERROR [] =
 187                                       "Error creating instance in namespace $0. ";
 188                       
 189                       static const char INSTANCE_CREATION_ERROR_KEY [] =
 190 sushma.fernandes 1.16              "Clients.repupgrade.RepositoryUpgrade.INSTANCE_CREATION_ERROR";
 191 sushma.fernandes 1.1  
 192                       static const char QUALIFIER_CREATION_ERROR [] =
 193                                       "Error creating qualifier $0 in namespace $1.";
 194                       
 195                       static const char QUALIFIER_CREATION_ERROR_KEY [] =
 196 sushma.fernandes 1.16             "Clients.repupgrade.RepositoryUpgrade.QUALIFIER_CREATION_ERROR";
 197 sushma.fernandes 1.1  
 198                       static const char OLD_CLASS_RETRIEVAL_ERROR [] =
 199                                       "Error reading old repository class $0 in namespace $1.";
 200                       
 201                       static const char OLD_CLASS_RETRIEVAL_ERROR_KEY [] =
 202 sushma.fernandes 1.16             "Clients.repupgrade.RepositoryUpgrade.OLDCLASS_RETRIEVAL_ERROR";
 203                       
 204                       static const char OLD_DEPENDENT_CLASS_RETRIEVAL_ERROR [] =
 205                                       "Error reading old repository dependent class $0 in namespace $1.";
 206                       
 207                       static const char OLD_DEPENDENT_CLASS_RETRIEVAL_ERROR_KEY [] =
 208                             "Clients.repupgrade.RepositoryUpgrade.OLD_DEPENDENT_CLASS_RETRIEVAL_ERROR";
 209 sushma.fernandes 1.1  
 210                       static const char NEW_CLASS_RETRIEVAL_ERROR [] =
 211                                       "Error reading new repository class $0 in namespace $1.";
 212                       
 213                       static const char NEW_CLASS_RETRIEVAL_ERROR_KEY [] =
 214 sushma.fernandes 1.16            "Clients.repupgrade.RepositoryUpgrade.NEW_CLASS_RETRIEVAL_ERROR";
 215 sushma.fernandes 1.1  
 216                       static const char LIBRARY_LOAD_ERROR [] =
 217                                       "Error loading special handling library $0.";
 218                       
 219                       static const char LIBRARY_LOAD_ERROR_KEY [] =
 220 sushma.fernandes 1.16                 "Clients.repupgrade.RepositoryUpgrade.LIBRARY_LOAD_ERROR";
 221 sushma.fernandes 1.1  
 222                       static const char LIBRARY_ENTRY_POINT_ERROR [] =
 223                                       "Error trying to get entry point symbol in library $0.";
 224                       
 225                       static const char LIBRARY_ENTRY_POINT_ERROR_KEY [] =
 226 sushma.fernandes 1.16                 "Clients.repupgrade.RepositoryUpgrade.LIBRARY_ENTRY_POINT_ERROR";
 227 sushma.fernandes 1.1  
 228                       static const char CLASS_XML_OUTPUT_FILE [] =
 229                                     "CIM/XML request for this class has been logged to file $0 ";
 230                       
 231                       static const char CLASS_XML_OUTPUT_FILE_KEY [] =
 232 sushma.fernandes 1.16               "Clients.repupgrade.RepositoryUpgrade.CLASS_XML_OUTPUT_FILE";
 233 sushma.fernandes 1.1  
 234                       static const char INSTANCE_XML_OUTPUT_FILE [] =
 235                                    "CIM/XML request for this instance has been logged to file $0.";
 236                       
 237                       static const char INSTANCE_XML_OUTPUT_FILE_KEY [] =
 238 sushma.fernandes 1.16           "Clients.repupgrade.RepositoryUpgrade.INSTANCE_XML_OUTPUT_FILE";
 239 sushma.fernandes 1.1  
 240                       static const char QUALIFIER_XML_OUTPUT_FILE [] =
 241                                   "CIM/XML request for this qualifier has been logged to file $0.";
 242                       
 243                       static const char QUALIFIER_XML_OUTPUT_FILE_KEY [] =
 244 sushma.fernandes 1.16           "Clients.repupgrade.RepositoryUpgrade.QUALIFIER_XML_OUTPUT_FILE";
 245 sushma.fernandes 1.1  
 246                       static const char HIGHER_VERSION_OLD_CLASS [] =
 247                                "Warning: The old repository contains a class $0 in namespace $1 that has a higher version number than the new repository class. This class may have to be manually imported.";
 248                       
 249                       
 250                       static const char HIGHER_VERSION_OLD_CLASS_KEY [] =
 251 sushma.fernandes 1.16          "Clients.repupgrade.RepositoryUpgrade.HIGHER_VERSION_OLD_CLASS";
 252 sushma.fernandes 1.1  
 253                       const String RepositoryUpgrade::_FILE_EXTENSION
 254                                                                     = ".xml";
 255                       
 256                       /**
 257                           Constant representing the name of the Version Qualifier.
 258                        */
 259                       const String   RepositoryUpgrade::_VERSION_QUALIFIER_NAME = "VERSION";
 260                       
 261 sushma.fernandes 1.2  #ifdef ENABLE_MODULE_PROCESSING
 262 sushma.fernandes 1.1  /**
 263                          Defines that the Special Processing Module is interested in
 264                          processing classes.
 265                       */
 266                       const char* RepositoryUpgrade::_CLASS_ONLY = "c";
 267                       
 268                       /**
 269                          Defines that the Special Processing Module is interested in
 270                          processing instances.
 271                       */
 272                       const char* RepositoryUpgrade::_INSTANCE_ONLY = "i";
 273                       
 274                       /**
 275                          Defines that the Special Processing Module is interested in
 276                          processing qualifiers.
 277                       */
 278                       const char* RepositoryUpgrade::_QUALIFIER_ONLY = "q";
 279                       
 280                       /**
 281                          Defines that the Special Processing Module is interested in
 282                          processing all types (includes class, instance and qualifier).
 283 sushma.fernandes 1.1  */
 284                       const char* RepositoryUpgrade::_ALL = "a";
 285 sushma.fernandes 1.2  #endif
 286 sushma.fernandes 1.1  
 287                       //
 288 sushma.fernandes 1.2  // Make the repository paths fixed for HPUX, if PEGASUS_USE_RELEASE_DIRS is set.
 289 sushma.fernandes 1.1  // Also defines the directory path to store CIMXML file for a failed request.
 290                       //
 291 w.otsuka         1.18 #ifdef PEGASUS_USE_RELEASE_DIRS
 292                       # define REPUPGRADE_USE_RELEASE_DIRS true
 293                       # ifdef PEGASUS_OVERRIDE_DEFAULT_RELEASE_DIRS
 294                           const String OLD_REPOSITORY_PATH = PEGASUS_PREV_REPOSITORY_DIR;
 295                           const String NEW_REPOSITORY_PATH = PEGASUS_REPOSITORY_DIR;
 296                           const String RepositoryUpgrade::_LOG_PATH  = PEGASUS_LOG_DIR"/upgrade";
 297                       # elif defined(PEGASUS_OS_HPUX)
 298 sushma.fernandes 1.1      const String OLD_REPOSITORY_PATH = "/var/opt/wbem/prev_repository";
 299                           const String NEW_REPOSITORY_PATH = "/var/opt/wbem/repository";
 300 david.dillard    1.5      const String RepositoryUpgrade::_LOG_PATH  = "/var/opt/wbem/upgrade";
 301 w.otsuka         1.18 # elif defined(PEGASUS_OS_VMS)
 302 gs.keenan        1.10     const String OLD_REPOSITORY_PATH = "/wbem_var/opt/wbem/prev_repository";
 303                           const String NEW_REPOSITORY_PATH = "/wbem_var/opt/wbem/repository";
 304                           const String RepositoryUpgrade::_LOG_PATH  = "/wbem_var/opt/wbem/upgrade";
 305 w.otsuka         1.18 # elif defined(PEGASUS_OS_LINUX)
 306 w.otsuka         1.13     const String OLD_REPOSITORY_PATH = "/var/opt/tog-pegasus/prev_repository";
 307                           const String NEW_REPOSITORY_PATH = "/var/opt/tog-pegasus/repository";
 308                           const String RepositoryUpgrade::_LOG_PATH  = "/var/opt/tog-pegasus/log/upgrade";
 309 w.otsuka         1.18 # endif
 310 sushma.fernandes 1.1  #else
 311                           const String RepositoryUpgrade::_LOG_PATH
 312                                                                     = "./";
 313                       #endif
 314                       
 315                       RepositoryUpgrade::RepositoryUpgrade ()
 316                                  : MessageQueue(PEGASUS_QUEUENAME_INTERNALCLIENT), _requestEncoder(0)
 317                       {
 318                           //
 319                           // Initialize data members.
 320                           //
 321                           _authenticator.clear();
 322                           _authenticator.setAuthType(ClientAuthenticator::NONE);
 323                       
 324 david            1.14 #ifdef PEGASUS_OS_OS400
 325                           logFileName = "/QIBM/USERDATA/OS400/CIM/qycmRepositoryUpgrade.log";
 326                       #endif
 327                       
 328 sushma.fernandes 1.1      //
 329                           // Create request encoder:
 330                           //
 331                           _requestEncoder = new CIMOperationRequestEncoder(
 332                               this, "localhost", &_authenticator, 0);
 333                       
 334                           instanceCount=0;
 335                           qualifierCount=0;
 336 sushma.fernandes 1.2      _modulesInitialized=false;
 337 sushma.fernandes 1.1  
 338                           //
 339 sushma.fernandes 1.2      // Get environment variable PEGASUS_HOME
 340 sushma.fernandes 1.1      //
 341 sushma.fernandes 1.2  #ifdef PEGASUS_PLATFORM_OS400_ISERIES_IBM
 342 sushma.fernandes 1.1  #pragma convert(37)
 343                           const char* tmp = getenv("PEGASUS_HOME");
 344                       #pragma convert(0)
 345 sushma.fernandes 1.2      // Set pegasusHome to the env var,if it is set.  Otherwise,
 346                           // use the OS/400 default path.
 347                           if (tmp != NULL)
 348                           {
 349                               char home[256] = {0};
 350                               if (strlen(tmp) < 256)
 351                               {
 352                                   strcpy(home, tmp);
 353                                   EtoA(home);
 354                                   _pegasusHome=home;
 355                               }
 356 sushma.fernandes 1.1      }
 357 sushma.fernandes 1.2      else
 358                               _pegasusHome = OS400_DEFAULT_PEGASUS_HOME;
 359 sushma.fernandes 1.1  #else
 360                           const char* tmp = getenv("PEGASUS_HOME");
 361 sushma.fernandes 1.2  #endif
 362 sushma.fernandes 1.1  
 363                           if (tmp)
 364                           {
 365                               _pegasusHome = tmp;
 366                           }
 367 sushma.fernandes 1.2  
 368                           FileSystem::translateSlashes(_pegasusHome);
 369                       
 370 sushma.fernandes 1.1  #ifdef REPUPGRADE_DEBUG
 371                          cout << "Pegasus HOME : " << _pegasusHome << endl;
 372                       #endif
 373                       
 374                           //
 375                           // build Usage string.
 376                           //
 377                           _usage = String (_USAGE);
 378                           _usage.append (COMMAND_NAME);
 379                       
 380 w.otsuka         1.13 #if !(defined(REPUPGRADE_USE_RELEASE_DIRS))
 381 sushma.fernandes 1.1      _usage.append (" -").append (_OPTION_OLD_REPOSITORY_PATH);
 382                           _usage.append (" old_repository_path");
 383                           _usage.append (" -").append (_OPTION_NEW_REPOSITORY_PATH);
 384                           _usage.append (" new_repository_path\n");
 385                       #endif
 386                       
 387                           //
 388                           // Version options
 389                           //
 390                           _usage.append("       ").append (COMMAND_NAME);
 391                           _usage.append (" -").append (_OPTION_VERSION)
 392                                .append(" |");
 393                           _usage.append (" --").append (LONG_VERSION)
 394                                .append("\n");
 395                       
 396                           //
 397                           // Help option
 398                           //
 399                           _usage.append("       ").append (COMMAND_NAME);
 400                           _usage.append (" -").append (_OPTION_HELP)
 401                                .append(" |");
 402 sushma.fernandes 1.1      _usage.append (" --").append (LONG_HELP)
 403                                .append("\n");
 404                       
 405                           //
 406                           // Options description
 407                           //
 408                           _usage.append("Options : \n");
 409 w.otsuka         1.13 #if !(defined(REPUPGRADE_USE_RELEASE_DIRS))
 410 sushma.fernandes 1.1      _usage.append("    -o              ");
 411                           _usage.append("- Specifies the old repository path\n");
 412                       
 413                           _usage.append("    -n              ");
 414                           _usage.append("- Specifies the new repository path\n");
 415                       #endif
 416                       
 417                           _usage.append("    -h, --help      - Display this help message\n");
 418                           _usage.append("    -v, --version   - Display CIM Server version number\n");
 419                       
 420                           //l10n localize usage
 421 w.otsuka         1.13 #if (defined(REPUPGRADE_USE_RELEASE_DIRS))
 422 sushma.fernandes 1.1      MessageLoaderParms menuparms(
 423                               "Clients.repupgrade.RepositoryUpgradeRelease.MENU.STANDARD", _usage);
 424 w.otsuka         1.13 # else
 425 sushma.fernandes 1.1  
 426                           MessageLoaderParms menuparms(
 427                               "Clients.repupgrade.RepositoryUpgrade.MENU.STANDARD", _usage);
 428                       #endif
 429                       
 430                           menuparms.msg_src_path = MSG_PATH;
 431                           _usage = MessageLoader::getMessage(menuparms);
 432                       
 433                           setUsage (_usage);
 434                       
 435 sushma.fernandes 1.2     _oldRepositoryPathSet = false;
 436                          _newRepositoryPathSet = false;
 437                       
 438 david.dillard    1.5     //
 439 sushma.fernandes 1.1     // If the PEGASUS_USE_RELEASE_DIRS is set make the old and new
 440                          // repository paths fixed.
 441                          //
 442 w.otsuka         1.13 #if (defined(REPUPGRADE_USE_RELEASE_DIRS))
 443 sushma.fernandes 1.2         _oldRepositoryPath = OLD_REPOSITORY_PATH;
 444                              _newRepositoryPath = NEW_REPOSITORY_PATH;
 445                              _oldRepositoryPathSet = true;
 446                              _newRepositoryPathSet = true;
 447 sushma.fernandes 1.1  #endif
 448 sushma.fernandes 1.2  
 449                          _oldRepository = 0;
 450                          _newRepository = 0;
 451 david.dillard    1.5  
 452 mateus.baur      1.19     // Construct the ignore class list.
 453                           _interopIgnoreClasses.append ( "PG_IndicationFilter" );
 454                           _interopIgnoreClasses.append ( "PG_IndicationHandler" );
 455                           _interopIgnoreClasses.append ( "PG_IndicationHandlerCIMXML" );
 456                           _interopIgnoreClasses.append ( "PG_IndicationHandlerSNMPMapper" );
 457                           _interopIgnoreClasses.append ( "PG_IndicationSubscription" ); 
 458                       
 459 sushma.fernandes 1.1  }
 460                       
 461                       RepositoryUpgrade::~RepositoryUpgrade ()
 462                       {
 463 kumpf            1.17     delete _requestEncoder;
 464                           delete _oldRepository;
 465                           delete _newRepository;
 466 sushma.fernandes 1.1  
 467 sushma.fernandes 1.2  #ifdef ENABLE_MODULE_PROCESSING
 468                           if (_modulesInitialized)
 469                           {
 470                               _cleanupSSPModule();
 471                           }
 472                       #endif
 473 sushma.fernandes 1.1  }
 474                       
 475 david            1.14 #ifdef PEGASUS_OS_OS400
 476                       Uint32 RepositoryUpgrade::invokeRepositoryUpgrade(Uint32 argc, char* argv[])
 477                       {
 478                           RepositoryUpgrade 	command;
 479                           Uint32		retCode;
 480                       
 481                           try
 482                           {
 483                               command.setCommand (argc, argv);
 484                           }
 485                           catch (CommandFormatException& cfe)
 486                           {
 487                       
 488                               throw cfe;
 489                         
 490                           }
 491                       
 492                         
 493                           ofstream logFile(logFileName.getCString(), ios::app, PEGASUS_STD(_CCSID_T(1208)));
 494                           retCode = command.execute (logFile, logFile);
 495                       
 496 david            1.14 
 497                           return (retCode);
 498                       
 499                       }
 500                       #endif
 501                       
 502                       
 503 sushma.fernandes 1.1  /**
 504                           Parses the command line, validates the options, and sets instance
 505                           variables based on the option arguments.
 506                       
 507                           @param   argc  the number of command line arguments
 508                       
 509                           @param   argv  the string vector of command line arguments
 510                       
 511                           @exception  CommandFormatException  if an error is encountered in parsing
 512                                                               the command line
 513                        */
 514                       void RepositoryUpgrade::setCommand (Uint32 argc, char* argv [])
 515                       {
 516                           Uint32         i               = 0;
 517                           Uint32         c               = 0;
 518                           String         optString       = String ();
 519                           getoopt        getOpts;
 520                       
 521                           //
 522                           //  Construct optString
 523                           //
 524 w.otsuka         1.13 #if !(defined(REPUPGRADE_USE_RELEASE_DIRS))
 525 sushma.fernandes 1.1      optString.append (_OPTION_OLD_REPOSITORY_PATH);
 526                           optString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 527                           optString.append (_OPTION_NEW_REPOSITORY_PATH);
 528                           optString.append (getoopt::GETOPT_ARGUMENT_DESIGNATOR);
 529                       #endif
 530                       
 531                           optString.append (_OPTION_HELP);
 532                           optString.append (getoopt::NOARG);
 533                           optString.append (_OPTION_VERSION);
 534                           optString.append (getoopt::NOARG);
 535 david            1.14 #ifdef PEGASUS_OS_OS400
 536                           optString.append (_OPTION_QUIET);
 537                           optString.append (getoopt::NOARG);
 538                       #endif
 539 sushma.fernandes 1.1  
 540                           //
 541                           //  Initialize and parse getOpts
 542                           //
 543                           getOpts = getoopt ();
 544                           getOpts.addFlagspec (optString);
 545                       
 546                           //
 547                           // Add long flag options for 'help' and 'version'
 548                           //
 549                           getOpts.addLongFlagspec (LONG_HELP, getoopt::NOARG);
 550                           getOpts.addLongFlagspec (LONG_VERSION, getoopt::NOARG);
 551                       
 552                           getOpts.parse (argc, argv);
 553                       
 554                           if (getOpts.hasErrors ())
 555                           {
 556                               CommandFormatException e (getOpts.getErrorStrings () [0]);
 557                               throw e;
 558                           }
 559                           _optionType = _OPTION_TYPE_UNINITIALIZED;
 560 sushma.fernandes 1.1  
 561                           //
 562                           //  Get options and arguments from the command line
 563                           //
 564                           for (i =  getOpts.first (); i <  getOpts.last (); i++)
 565                           {
 566                               if (getOpts [i].getType () == Optarg::LONGFLAG)
 567                               {
 568                                   if (getOpts [i].getopt () == LONG_HELP)
 569                                   {
 570                                       if (_optionType != _OPTION_TYPE_UNINITIALIZED)
 571                                       {
 572                                           String param = String (LONG_HELP);
 573                                           //
 574                                           // More than one operation option was found
 575                                           //
 576                                           UnexpectedOptionException e (param);
 577                                           throw e;
 578                                       }
 579                       
 580 david.dillard    1.5                 _optionType = _OPTION_TYPE_HELP;
 581 sushma.fernandes 1.1              }
 582                                   else if (getOpts [i].getopt () == LONG_VERSION)
 583                                   {
 584                                       if (_optionType != _OPTION_TYPE_UNINITIALIZED)
 585                                       {
 586                                           String param = String (LONG_VERSION);
 587                                           //
 588                                           // More than one operation option was found
 589                                           //
 590                                           UnexpectedOptionException e (param);
 591                                           throw e;
 592                                       }
 593                       
 594                                      _optionType = _OPTION_TYPE_VERSION;
 595                                   }
 596                               }
 597                               else if (getOpts [i].getType () == Optarg::REGULAR)
 598                               {
 599                                   //
 600                                   //  The repupgrade command has no non-option argument options
 601                                   //
 602 sushma.fernandes 1.1              UnexpectedArgumentException e (getOpts [i].Value ());
 603                                   throw e;
 604                               }
 605                               else /* getOpts [i].getType () == FLAG */
 606                               {
 607                                   c = getOpts [i].getopt () [0];
 608                       
 609                                   switch (c)
 610                                   {
 611 w.otsuka         1.13 #if !(defined(REPUPGRADE_USE_RELEASE_DIRS))
 612 sushma.fernandes 1.1                  case _OPTION_OLD_REPOSITORY_PATH:
 613                                       {
 614                                           if (getOpts.isSet (_OPTION_OLD_REPOSITORY_PATH) > 1)
 615                                           {
 616                                               //
 617                                               // More than one old repository path option was found
 618                                               //
 619                                               DuplicateOptionException
 620                                                    e (_OPTION_OLD_REPOSITORY_PATH);
 621                                               throw e;
 622                                           }
 623                       
 624                                           if (_optionType != _OPTION_TYPE_UNINITIALIZED &&
 625                                               _optionType != _OPTION_TYPE_NEW_REPOSITORY_PATH)
 626                                           {
 627                                               //
 628                                               // More than one operation option was found
 629                                               //
 630 david.dillard    1.5                          UnexpectedOptionException
 631 sushma.fernandes 1.1                               e (_OPTION_OLD_REPOSITORY_PATH);
 632                                               throw e;
 633                                           }
 634                       
 635                                           _optionType = _OPTION_TYPE_OLD_REPOSITORY_PATH;
 636                                           _oldRepositoryPath = getOpts [i].Value ();
 637                                           _oldRepositoryPathSet = true;
 638                                           break;
 639                                       }
 640                                       case _OPTION_NEW_REPOSITORY_PATH:
 641                                       {
 642                       
 643                                           if (getOpts.isSet (_OPTION_NEW_REPOSITORY_PATH) > 1)
 644                                           {
 645                                               //
 646                                               // More than one new repository option was found
 647                                               //
 648                                               DuplicateOptionException
 649                                                     e (_OPTION_NEW_REPOSITORY_PATH);
 650                                               throw e;
 651                                           }
 652 sushma.fernandes 1.1  
 653                                           if (_optionType != _OPTION_TYPE_UNINITIALIZED &&
 654                                               _optionType != _OPTION_TYPE_OLD_REPOSITORY_PATH)
 655                                           {
 656                                               //
 657                                               // More than one operation option was found
 658                                               //
 659 david.dillard    1.5                          UnexpectedOptionException
 660 sushma.fernandes 1.1                               e (_OPTION_NEW_REPOSITORY_PATH);
 661                                               throw e;
 662                                           }
 663                       
 664                                           _optionType = _OPTION_TYPE_NEW_REPOSITORY_PATH;
 665                                           _newRepositoryPath = getOpts [i].Value ();
 666                                           _newRepositoryPathSet = true;
 667                                           break;
 668                                       }
 669                       #endif
 670                                       case _OPTION_HELP:
 671                                       {
 672                                           if (getOpts.isSet (_OPTION_HELP) > 1)
 673                                           {
 674                                               //
 675                                               // More than one help option was found
 676                                               //
 677                                               DuplicateOptionException e (_OPTION_HELP);
 678                                               throw e;
 679                                           }
 680                       
 681 sushma.fernandes 1.1                      if (_optionType != _OPTION_TYPE_UNINITIALIZED)
 682                                           {
 683                                               //
 684                                               // More than one operation option was found
 685                                               //
 686                                               UnexpectedOptionException e (_OPTION_HELP);
 687                                               throw e;
 688                                           }
 689                       
 690                                           _optionType = _OPTION_TYPE_HELP;
 691                                           break;
 692                                       }
 693                       
 694                                       case _OPTION_VERSION:
 695                                       {
 696                                           if (getOpts.isSet (_OPTION_VERSION) > 1)
 697                                           {
 698                                               //
 699                                               // More than one version option was found
 700                                               //
 701                                               DuplicateOptionException e (_OPTION_VERSION);
 702 sushma.fernandes 1.1                          throw e;
 703                                           }
 704                       
 705                                           if (_optionType != _OPTION_TYPE_UNINITIALIZED)
 706                                           {
 707                                               //
 708                                               // More than one operation option was found
 709                                               //
 710                                               UnexpectedOptionException e (_OPTION_VERSION);
 711                                               throw e;
 712                                           }
 713                       
 714                                           _optionType = _OPTION_TYPE_VERSION;
 715                                           break;
 716                                       }
 717 david            1.14 #ifdef PEGASUS_OS_OS400
 718                       		case _OPTION_QUIET:
 719                       		{
 720                       			// Suppress output. Redirect to /dev/null.
 721                       			freopen(logFileName.getCString(),"a",stdout);
 722                       			freopen(logFileName.getCString(),"a",stderr);
 723                       		}
 724                       #endif
 725 sushma.fernandes 1.1                  default:
 726                                       {
 727                                           //
 728                                           //  This path should not be hit
 729                                           //
 730                                           break;
 731                                       }
 732                                   }
 733                               }
 734                           }
 735                       
 736                           // Check if an operation type was not specified.
 737 w.otsuka         1.13 #if !(defined(REPUPGRADE_USE_RELEASE_DIRS))
 738 sushma.fernandes 1.1      if ( _optionType == _OPTION_TYPE_UNINITIALIZED )
 739                           {
 740                               //
 741                               // No operation type was specified
 742                               // Show the usage
 743                               //
 744                               CommandFormatException e ( localizeMessage ( MSG_PATH,
 745                                   REQUIRED_ARGS_MISSING_KEY, REQUIRED_ARGS_MISSING ) );
 746                       
 747                               throw e;
 748                           }
 749                       #endif
 750                       }
 751                       
 752                       /**
 753                       
 754                           Executes the command and writes the results to the PrintWriters.
 755                       
 756                           @param   outPrintWriter     the ostream to which output should be
 757                                                       written
 758                           @param   errPrintWriter     the ostream to which error output should be
 759 sushma.fernandes 1.1                                  written
 760                       
 761                           @return  0                  if the command is successful
 762                                    1                  if an error occurs in executing the command
 763                       
 764                        */
 765                       Uint32 RepositoryUpgrade::execute (
 766                           ostream& outPrintWriter,
 767                           ostream& errPrintWriter)
 768                       {
 769                       
 770                           //
 771                           // Check if the old and new repository paths exist.
 772                           //
 773                           if ( _oldRepositoryPathSet && !FileSystem::exists (_oldRepositoryPath))
 774                           {
 775 david.dillard    1.5          cerr << localizeMessage ( MSG_PATH,
 776 sushma.fernandes 1.1                                    REPOSITORY_DOES_NOT_EXIST_KEY,
 777                                                         REPOSITORY_DOES_NOT_EXIST,
 778                                                         _oldRepositoryPath ) << endl;
 779 david            1.14 #ifdef PEGASUS_OS_OS400
 780 yi.zhou          1.23         Logger::put(Logger::STANDARD_LOG,"cimserver repupgrade",Logger::SEVERE,
 781 david            1.14 	           localizeMessage ( MSG_PATH,
 782                                                         REPOSITORY_DOES_NOT_EXIST_KEY,
 783                                                         REPOSITORY_DOES_NOT_EXIST,
 784                                                         _oldRepositoryPath )
 785                                          );
 786                       	throw RepositoryUpgradeException("");
 787                       #endif
 788 sushma.fernandes 1.1          return 1;
 789                           }
 790                       
 791                           if ( _newRepositoryPathSet && !FileSystem::exists (_newRepositoryPath))
 792                           {
 793                               cerr << localizeMessage (MSG_PATH,
 794                                                        REPOSITORY_DOES_NOT_EXIST_KEY,
 795                                                        REPOSITORY_DOES_NOT_EXIST,
 796 sushma.fernandes 1.2                                   _newRepositoryPath ) << endl;
 797 david            1.14 #ifdef PEGASUS_OS_OS400
 798 yi.zhou          1.23 	Logger::put(Logger::STANDARD_LOG,"cimserver repupgrade",Logger::SEVERE,
 799 david            1.14 	           localizeMessage ( MSG_PATH,
 800                                                         REPOSITORY_DOES_NOT_EXIST_KEY,
 801                                                         REPOSITORY_DOES_NOT_EXIST,
 802                                                         _newRepositoryPath )
 803                                          );
 804                       	throw RepositoryUpgradeException("");
 805                       #endif
 806 sushma.fernandes 1.1          return 1;
 807                           }
 808                       
 809                           //
 810                           // Options HELP and VERSION
 811                           //
 812                           if (_optionType == _OPTION_TYPE_HELP)
 813                           {
 814                               outPrintWriter << _usage << endl;
 815                               return (RC_SUCCESS);
 816                           }
 817                           else if(_optionType == _OPTION_TYPE_VERSION)
 818                           {
 819                               outPrintWriter << "Version " << PEGASUS_PRODUCT_VERSION << endl;
 820                               return (RC_SUCCESS);
 821                           }
 822                       
 823                           try
 824                           {
 825 sushma.fernandes 1.2  #ifdef ENABLE_MODULE_PROCESSING
 826 sushma.fernandes 1.1          //
 827                               // Load the Special Processing Modules.
 828                               //
 829                               _initSSPModule();
 830 sushma.fernandes 1.2  #endif
 831                       
 832                               _modulesInitialized = true;
 833 sushma.fernandes 1.1  
 834                               //
 835                               // Upgrade the Repository.
 836                               //
 837                               upgradeRepository();
 838                           }
 839                           catch (RepositoryUpgradeException& rue)
 840                           {
 841                               errPrintWriter << rue.getMessage() << endl;
 842 david            1.14 #ifdef PEGASUS_OS_OS400
 843 yi.zhou          1.23         Logger::put(Logger::STANDARD_LOG,"cimserver repupgrade",Logger::SEVERE,rue.getMessage());
 844 david            1.14 	throw rue;
 845                       #endif
 846 sushma.fernandes 1.1          return 1;
 847                           }
 848                           catch (Exception &e)
 849                           {
 850                               errPrintWriter << e.getMessage() << endl;
 851 david            1.14 #ifdef PEGASUS_OS_OS400
 852 yi.zhou          1.23         Logger::put(Logger::STANDARD_LOG,"cimserver repupgrade",Logger::SEVERE,e.getMessage());
 853 david            1.14 	throw e;
 854                       #endif
 855 sushma.fernandes 1.1          return 1;
 856                           }
 857                           catch (...)
 858                           {
 859 david.dillard    1.5          errPrintWriter << localizeMessage ( MSG_PATH,
 860 sushma.fernandes 1.1                                    REPOSITORY_UPGRADE_UNKNOWN_ERROR_KEY,
 861                                                         REPOSITORY_UPGRADE_UNKNOWN_ERROR )
 862 david.dillard    1.5               << localizeMessage ( MSG_PATH,
 863 sushma.fernandes 1.1                                    REPOSITORY_UPGRADE_FAILURE_KEY,
 864                                                         REPOSITORY_UPGRADE_FAILURE );
 865 david            1.14 #ifdef PEGASUS_OS_OS400
 866 yi.zhou          1.23         Logger::put(Logger::STANDARD_LOG,"cimserver repupgrade",Logger::SEVERE,
 867 david            1.14 	           localizeMessage ( MSG_PATH,
 868                                                         REPOSITORY_UPGRADE_UNKNOWN_ERROR_KEY,
 869                                                         REPOSITORY_UPGRADE_UNKNOWN_ERROR ));
 870                       
 871 yi.zhou          1.23         Logger::put(Logger::STANDARD_LOG,"cimserver repupgrade",Logger::SEVERE,
 872 david            1.14                 localizeMessage ( MSG_PATH,
 873                                                         REPOSITORY_UPGRADE_FAILURE_KEY,
 874                                                         REPOSITORY_UPGRADE_FAILURE ));
 875                                         
 876                       	throw RepositoryUpgradeException("");
 877                       #endif
 878 sushma.fernandes 1.1          return 1;
 879                           }
 880                       
 881                           return 0;
 882                       }
 883                       
 884                       void RepositoryUpgrade::upgradeRepository()
 885                       {
 886                           Array<CIMNamespaceName> 		oldNamespaces;
 887                           Array<CIMNamespaceName> 		newNamespaces;
 888                           Array<CIMNamespaceName> 		missingNamespaces;
 889                           CIMName				className;
 890                       
 891                           //
 892                           // Create the old and new Repository instances.
 893                           //
 894                           _oldRepository = new CIMRepository (_oldRepositoryPath);
 895                           _newRepository = new CIMRepository (_newRepositoryPath);
 896 david.dillard    1.5  
 897 sushma.fernandes 1.1      //
 898                           // Get Namespace information for old Repository.
 899                           //
 900                           oldNamespaces = _oldRepository->enumerateNameSpaces();
 901                       
 902                           //
 903                           // Get Namespace information for new Repository.
 904                           //
 905                           newNamespaces = _newRepository->enumerateNameSpaces();
 906 david.dillard    1.5  
 907 sushma.fernandes 1.1      //
 908                           // Check if the namespaces in the old repository exist in the new.
 909                           // If they don't exist, create them and populate.
 910                           //
 911                           missingNamespaces = _compareNamespaces( oldNamespaces, newNamespaces );
 912 david.dillard    1.5  
 913 sushma.fernandes 1.1      if ( missingNamespaces.size() > 0 )
 914                           {
 915 david.dillard    1.5          //
 916 sushma.fernandes 1.1          // Need to add the missing namespaces (includes classes &
 917                               // qualifiers) to the new repository.
 918                               //
 919 david.dillard    1.5          _addNamespaces(missingNamespaces);
 920 sushma.fernandes 1.1  
 921                               //
 922                               // Since the missing namespaces have been processed, remove
 923                               // them from the old Namespaces list. That way we will process only
 924                               // the pre-existing namespaces that existed in both the repositories
 925                               // when we look for qualifiers and classes to be added.
 926                               //
 927                               for (Uint32 i=0; i < missingNamespaces.size(); i++)
 928                               {
 929                                   // find the namespace and remove it from list of old namespaces.
 930                                   Uint32 n = oldNamespaces.size();
 931                       
 932                                   for (Uint32 j = 0; j < n; j++)
 933                                   {
 934                                       if (oldNamespaces[j] == missingNamespaces[i])
 935                                       {
 936                                           oldNamespaces.remove(j);
 937                                           break;
 938                                       }
 939                                   }
 940                               }
 941 sushma.fernandes 1.1      }
 942                       
 943                           //
 944 david.dillard    1.5      // Get the class information for pre-existing namespaces
 945 sushma.fernandes 1.1      // in the old and new repositories.
 946 david.dillard    1.5      //
 947                       
 948 sushma.fernandes 1.1      Uint32 n = oldNamespaces.size();
 949                       
 950                           Array<CIMName> 			oldClassNames;
 951                           Array<CIMName> 			newClassNames;
 952                       
 953                           for ( Uint32 i=0; i < n;  i++)
 954                           {
 955                       
 956                               oldClassNames.clear();
 957                               newClassNames.clear();
 958                       
 959                               // Add qualifiers.
 960                               _addQualifiers (oldNamespaces[i]);
 961                       
 962                       #ifdef REPUPGRADE_DEBUG
 963 david.dillard    1.5          cout << "Now processing namespace : "
 964 sushma.fernandes 1.1                  << oldNamespaces[i] << " i=" << i << endl;
 965                       #endif
 966                       
 967                               //
 968                               // Gather class information for each namespace.
 969                               //
 970                               oldClassNames = _oldRepository->enumerateClassNames(
 971                                                  oldNamespaces[i],
 972                                                  className,
 973                                                  true);
 974                       
 975 david.dillard    1.5          newClassNames = _newRepository->enumerateClassNames(
 976                                                        oldNamespaces[i],
 977                                                        className,
 978 sushma.fernandes 1.1                                   true);
 979 david.dillard    1.5  
 980 sushma.fernandes 1.1          //
 981                               // Process the class list.
 982                               //
 983                               if ( oldClassNames.size() > 0 )
 984                               {
 985                                   _processClasses(
 986 david.dillard    1.5              oldNamespaces[i],
 987                                   oldClassNames,
 988                                   newClassNames);
 989 sushma.fernandes 1.1          }
 990                           }
 991                       
 992                           // Create Instances.
 993                       #ifdef REPUPGRADE_DEBUG
 994                           cout << "Checking for instances..." << endl;
 995                       #endif
 996                           _addInstances ();
 997                       }
 998                       
 999                       Array<CIMNamespaceName> RepositoryUpgrade::_compareNamespaces(
1000 david.dillard    1.5                             const Array<CIMNamespaceName>& oldNamespaces,
1001 sushma.fernandes 1.1                             const Array<CIMNamespaceName>& newNamespaces)
1002                       {
1003                           Array<CIMNamespaceName>     namespaceNames;
1004                       
1005                           Uint32 n = oldNamespaces.size();
1006                           for ( Uint32 i=0; i < n; i++ )
1007                           {
1008                               if (! Contains (newNamespaces,oldNamespaces[i]))
1009                               {
1010                                   namespaceNames.append( oldNamespaces[i] );
1011                               }
1012                           }
1013                           return namespaceNames;
1014                       }
1015                       
1016                       void RepositoryUpgrade::_addQualifiers (const CIMNamespaceName namespaceName)
1017                       {
1018                       
1019                           //
1020                           // Retrieve qualifiers.
1021                           //
1022 sushma.fernandes 1.1      Array<CIMQualifierDecl> qualifiers =
1023                                         _oldRepository->enumerateQualifiers(namespaceName);
1024                       
1025                           Uint32 n = qualifiers.size();
1026                       
1027                           for (Uint32 j=0 ; j<n ; j++)
1028                           {
1029 david.dillard    1.5          try
1030 sushma.fernandes 1.1          {
1031                                   // Check if the qualifier exists in the new repository.
1032 david.dillard    1.5              CIMQualifierDecl qual =
1033 sushma.fernandes 1.1                 _newRepository->getQualifier(namespaceName,
1034                                                      qualifiers[j].getName());
1035                       
1036                                   if ( qual.getName() == qualifiers[j].getName() )
1037                                   {
1038                                        // Qualifier already exists, do not create.
1039                                        continue;
1040                                   }
1041                               }
1042                               catch (CIMException& ce)
1043                               {
1044 david.dillard    1.5              //
1045 sushma.fernandes 1.1              // Check if the error returned was that the qualifier does not
1046                                   // exist. If not propagate the error.
1047                                   //
1048                                   if (ce.getCode() != CIM_ERR_NOT_FOUND)
1049                                   {
1050                                       throw;
1051                                   }
1052                               }
1053                       
1054                               //
1055                               // Check if the qualifier has to be created. If true, use the
1056                               // processed qualifier. If an SSP Module have chosen to
1057                               // to ignore the qualifier then skip the qualifier creation.
1058                               //
1059                               CIMQualifierDecl processedQual = qualifiers[j].clone();
1060 sushma.fernandes 1.2  
1061                       #ifdef ENABLE_MODULE_PROCESSING
1062 sushma.fernandes 1.1          if (!_invokeModules (qualifiers[j], processedQual))
1063                               {
1064                       #ifdef REPUPGRADE_DEBUG
1065                                   cerr << "Ignoring qualifier creation : "
1066                                        << qualifiers[j].getName() << endl;
1067                       #endif
1068                                   continue;
1069                               }
1070 sushma.fernandes 1.2  #endif
1071 sushma.fernandes 1.1  
1072                               try
1073                               {
1074                       #ifdef REPUPGRADE_DEBUG
1075                               cout << "Now creating qualifier :" << processedQual.getName()
1076                                    << endl;
1077                       #endif
1078                                   _newRepository->setQualifier (namespaceName, processedQual);
1079                       #ifdef REPUPGRADE_DEBUG
1080                               cout << "Qualifier created:" << processedQual.getName()
1081                                    << endl;
1082                       #endif
1083                       
1084                               }
1085                               catch (Exception& e)
1086                               {
1087                                   _logSetQualifierError (namespaceName,
1088                                                                  qualifiers[j],
1089 sushma.fernandes 1.2                                             (e.getMessage()+". "));
1090 sushma.fernandes 1.1          }
1091                               catch (...)
1092                               {
1093                                   _logSetQualifierError (namespaceName,
1094                                                                  qualifiers[j],
1095                                                                  String::EMPTY);
1096                               }
1097                           }
1098                       }
1099                       
1100                       void RepositoryUpgrade::_addNamespaces(
1101                                                const Array<CIMNamespaceName>& namespaces)
1102                       {
1103 david.dillard    1.5  
1104 sushma.fernandes 1.1      Array<CIMName> 			oldClassNames;
1105                           Array<CIMName> 			newClassNames;
1106                           CIMName				className;
1107                       
1108                           Uint32 count = namespaces.size();
1109                           for ( Uint32 i=0; i < count;  i++)
1110                           {
1111                       #ifdef REPUPGRADE_DEBUG
1112                               cout << "Now creating namespace : " << namespaces[i] << endl;
1113                       #endif
1114                               try
1115                               {
1116 david.dillard    1.5              _newRepository->createNameSpace(namespaces[i]);
1117 sushma.fernandes 1.1          }
1118                               catch (Exception& e)
1119                               {
1120                                   String message = localizeMessage (MSG_PATH,
1121                                                      REPOSITORY_UPGRADE_FAILURE_KEY,
1122                                                      REPOSITORY_UPGRADE_FAILURE) +
1123                       
1124                                                    e.getMessage() +
1125 david.dillard    1.5  
1126 sushma.fernandes 1.1                               localizeMessage (MSG_PATH,
1127                                                      NAMESPACE_CREATION_ERROR_KEY,
1128                                                      NAMESPACE_CREATION_ERROR,
1129                                                      namespaces[i].getString());
1130                       
1131                                   throw RepositoryUpgradeException(message);
1132                               }
1133                               catch (...)
1134                               {
1135                                   String message = localizeMessage (MSG_PATH,
1136                                                      REPOSITORY_UPGRADE_FAILURE_KEY,
1137                                                      REPOSITORY_UPGRADE_FAILURE) +
1138 david.dillard    1.5  
1139 sushma.fernandes 1.1                               localizeMessage (MSG_PATH,
1140                                                      NAMESPACE_CREATION_ERROR_KEY,
1141                                                      NAMESPACE_CREATION_ERROR,
1142                                                      namespaces[i].getString());
1143                       
1144                                   throw RepositoryUpgradeException(message);
1145                               }
1146                       
1147                               //
1148                               // 1. Add qualifiers
1149                               //
1150                       
1151                               _addQualifiers (namespaces[i]);
1152                       
1153                               //
1154                               // 2. Add classes
1155                               //
1156                       
1157                               // Get classnames from old repository.
1158                       
1159                               oldClassNames = _oldRepository->enumerateClassNames(
1160 sushma.fernandes 1.1                             namespaces[i],
1161                                                  className,
1162                                                  true);
1163                       
1164                               if (oldClassNames.size() > 0)
1165                               {
1166 david.dillard    1.5              _processNewClasses (namespaces[i],
1167                                                   oldClassNames,
1168 sushma.fernandes 1.1                              newClassNames);
1169                               }
1170                       
1171                               oldClassNames.clear();
1172                       	newClassNames.clear();
1173 david.dillard    1.5  
1174 sushma.fernandes 1.1      }
1175                       }
1176                       
1177                       void RepositoryUpgrade::_processClasses(
1178 david.dillard    1.5                        const CIMNamespaceName& namespaceName,
1179                                             const Array<CIMName>&   oldClasses ,
1180 sushma.fernandes 1.1                        Array<CIMName>&   newClasses)
1181                       {
1182                           Array<CIMName>		missingClasses;
1183                           Array<CIMName>		existingClasses;
1184                       
1185 david.dillard    1.5      //
1186 sushma.fernandes 1.1      // Separate the existing and missing classes.
1187                           //
1188                       
1189                           Uint32 oldCount = oldClasses.size();
1190                           Uint32 newCount = newClasses.size();
1191                       
1192                           for ( Uint32 oldclasses = 0; oldclasses < oldCount ; oldclasses++)
1193                           {
1194                       #ifdef REPUPGRADE_DEBUG
1195                               cout << "Checking for : " << oldClasses[oldclasses] << endl;
1196                       #endif
1197                               if ( !Contains(newClasses, oldClasses[oldclasses]) )
1198                               {
1199 mateus.baur      1.19 
1200                                   /** This check is required to ignore PG_Ind* classes
1201 karl             1.21                 in the interop namespace. These classes were
1202 mateus.baur      1.19                 replaced with CIM_Ind* in CIM 2.7
1203                                   */
1204 karl             1.21             if ( namespaceName == PEGASUS_NAMESPACENAME_INTEROP &&
1205 mateus.baur      1.19                 Contains( _interopIgnoreClasses, oldClasses[oldclasses] ) )
1206                                   {
1207                       #ifdef REPUPGRADE_DEBUG
1208                                       cout << "Now ignoring: " << oldClasses[oldclasses] << endl;
1209                       #endif
1210                                       continue;
1211                                   }
1212                       
1213                                   /** Ignore any "CIM_" classes in pegasus namespaces, except root/cimv2. 
1214                                       Since they don't exist in 2.7 they must have been renamed or deleted.
1215                                   */
1216 karl             1.21             if ( ( (namespaceName == PEGASUS_NAMESPACENAME_INTEROP) ||
1217                                          (namespaceName == "root/PG_Internal")) &&
1218 mateus.baur      1.19                    (oldClasses[oldclasses].getString().subString(0,4))=="CIM_")
1219                                   {
1220                       #ifdef REPUPGRADE_DEBUG
1221                                       cout << "Now ignoring: " << oldClasses[oldclasses] << endl;
1222                       #endif
1223                                       continue;
1224                                   }
1225                       
1226 sushma.fernandes 1.1  #ifdef REPUPGRADE_DEBUG
1227 david.dillard    1.5              cout << "Now appending to missing: "
1228 sushma.fernandes 1.1                   << oldClasses[oldclasses] << endl;
1229                       #endif
1230                                   missingClasses.append(oldClasses[oldclasses]);
1231                               }
1232                               else
1233                               {
1234                       #ifdef REPUPGRADE_DEBUG
1235 david.dillard    1.5          cout << "Now appending to existing: "
1236 sushma.fernandes 1.1               << oldClasses[oldclasses] << endl;
1237                       #endif
1238                                   existingClasses.append(oldClasses[oldclasses]);
1239 david.dillard    1.5          }
1240 sushma.fernandes 1.1      }
1241 david.dillard    1.5  
1242 sushma.fernandes 1.1      // Check if any missing classes existed and add them.
1243                           if (missingClasses.size() > 0)
1244                           {
1245                               _processNewClasses (namespaceName, missingClasses, newClasses);
1246                           }
1247                       
1248                           // Check for existing classes and process them.
1249                           if (existingClasses.size() > 0)
1250                           {
1251                               _processExistingClasses (namespaceName, existingClasses);
1252                           }
1253                       
1254                           newClasses.clear();
1255                       }
1256                       
1257                       void RepositoryUpgrade::_processExistingClasses(
1258                                             const CIMNamespaceName& namespaceName,
1259                                             const Array<CIMName>&   existingClasses)
1260                       {
1261                           Uint32 			idx;
1262                           Uint32 			existingClassCount = existingClasses.size();
1263 sushma.fernandes 1.1  
1264                           for ( Uint32 i=0; i < existingClassCount; i++)
1265                           {
1266                               CIMClass		oldClass;
1267                       	CIMClass 		newClass;
1268                       	String 			oldVersion;
1269                       	String 			newVersion;
1270                       	Boolean 		oldVersionFound=false;
1271                       	Boolean 		newVersionFound=false;
1272 david.dillard    1.5  
1273 sushma.fernandes 1.1  #ifdef REPUPGRADE_DEBUG
1274 david.dillard    1.5          cout << "In Namespace: " << namespaceName
1275 sushma.fernandes 1.1               << "Existing Classname: " << existingClasses[i] << endl;
1276                       #endif
1277                       
1278                               try
1279                               {
1280                                   oldClass = _oldRepository->getClass(namespaceName,
1281                                                                   existingClasses[i],
1282                       					    true,
1283                       					    true,
1284                       					    true);
1285                               }
1286                               catch (Exception& e)
1287                               {
1288                                   String message = localizeMessage (MSG_PATH,
1289                                                      REPOSITORY_UPGRADE_FAILURE_KEY,
1290                                                      REPOSITORY_UPGRADE_FAILURE) +
1291                       
1292                                                    e.getMessage() +
1293                       
1294                                                    localizeMessage (MSG_PATH,
1295                                                      OLD_CLASS_RETRIEVAL_ERROR_KEY,
1296 sushma.fernandes 1.1                                 OLD_CLASS_RETRIEVAL_ERROR,
1297                                                      existingClasses[i].getString(),
1298                                                      namespaceName.getString());
1299                               }
1300                               catch (...)
1301                               {
1302 david.dillard    1.5              String errMsg = localizeMessage ( MSG_PATH,
1303 sushma.fernandes 1.1                                                REPOSITORY_UPGRADE_FAILURE_KEY,
1304                                                                     REPOSITORY_UPGRADE_FAILURE )
1305 david.dillard    1.5                              + localizeMessage ( MSG_PATH,
1306 sushma.fernandes 1.1                                                  OLD_CLASS_RETRIEVAL_ERROR_KEY,
1307 david.dillard    1.5                                                  OLD_CLASS_RETRIEVAL_ERROR,
1308 sushma.fernandes 1.1                                                  existingClasses[i].getString(),
1309                                                                       namespaceName.getString());
1310                       
1311                                   throw RepositoryUpgradeException (errMsg);
1312                               }
1313 david.dillard    1.5  
1314 sushma.fernandes 1.1          try
1315                               {
1316                                   newClass = _newRepository->getClass(namespaceName,
1317                                                                   existingClasses[i],
1318                       					    true,
1319                       					    true,
1320                       					    true);
1321                               }
1322                               catch (Exception& e)
1323                               {
1324                                   String message = localizeMessage (MSG_PATH,
1325                                                      REPOSITORY_UPGRADE_FAILURE_KEY,
1326                                                      REPOSITORY_UPGRADE_FAILURE) +
1327                                                    e.getMessage() +
1328                                                    localizeMessage (MSG_PATH,
1329                                                      NEW_CLASS_RETRIEVAL_ERROR_KEY,
1330                                                      NEW_CLASS_RETRIEVAL_ERROR,
1331                                                      existingClasses[i].getString(),
1332                                                      namespaceName.getString());
1333                               }
1334                               catch (...)
1335 sushma.fernandes 1.1          {
1336 david.dillard    1.5              String errMsg = localizeMessage ( MSG_PATH,
1337 sushma.fernandes 1.1                                                REPOSITORY_UPGRADE_FAILURE_KEY,
1338                                                                     REPOSITORY_UPGRADE_FAILURE )
1339 david.dillard    1.5                              + localizeMessage ( MSG_PATH,
1340 sushma.fernandes 1.1                                                  NEW_CLASS_RETRIEVAL_ERROR_KEY,
1341                                                                       NEW_CLASS_RETRIEVAL_ERROR,
1342                                                                       existingClasses[i].getString(),
1343                                                                       namespaceName.getString());
1344                       
1345                                   throw RepositoryUpgradeException (errMsg);
1346                               }
1347                       
1348                               // Get the version qualifier from the old Class.
1349                               idx = oldClass.findQualifier(_VERSION_QUALIFIER_NAME);
1350                               if (idx != PEG_NOT_FOUND)
1351                               {
1352                                   CIMQualifier rVer = oldClass.getQualifier(idx);
1353                                   CIMValue rVal = rVer.getValue();
1354                                   rVal.get(oldVersion);
1355                                   oldVersionFound = true;
1356                               }
1357                       
1358                               // Get the version qualifier from the new Class.
1359                               idx = newClass.findQualifier(_VERSION_QUALIFIER_NAME);
1360                               if (idx != PEG_NOT_FOUND)
1361 sushma.fernandes 1.1          {
1362                                   CIMQualifier rVer = newClass.getQualifier(idx);
1363                                   CIMValue rVal = rVer.getValue();
1364                                   rVal.get(newVersion);
1365                                   newVersionFound = true;
1366                               }
1367                       
1368                               //
1369                               // 1. If the class in old Repository contains a version number
1370                               //    and the new Repository class does not have a version number then
1371 david.dillard    1.5          //    print a warning message
1372 sushma.fernandes 1.1          // 2. If the class in old Repository contains a higher version number
1373 david.dillard    1.5          //    than the new Repository class then print a warning message
1374 sushma.fernandes 1.1          //
1375                               if ( oldVersionFound && !newVersionFound )
1376                               {
1377 david.dillard    1.5              //
1378 sushma.fernandes 1.1              // The old Repository has a higher version of the class.
1379                                   // Log a warning message and ignore the class.
1380                                   //
1381                                   cerr << localizeMessage (MSG_PATH,
1382                                                            HIGHER_VERSION_OLD_CLASS_KEY,
1383                                                            HIGHER_VERSION_OLD_CLASS,
1384 david.dillard    1.5                                       oldClass.getClassName().getString(),
1385 sushma.fernandes 1.1                                       namespaceName.getString()) << endl;
1386                               }
1387                               else if ( oldVersionFound && newVersionFound )
1388                               {
1389                                   // Compare the version
1390                                   if (_compareVersion (oldVersion, newVersion) == true)
1391                                   {
1392                                       //
1393                                       // The old Repository has a higher version of the class.
1394                                       // Log a warning message and ignore the class.
1395                                       //
1396                                       cerr << localizeMessage (MSG_PATH,
1397                                                                HIGHER_VERSION_OLD_CLASS_KEY,
1398                                                                HIGHER_VERSION_OLD_CLASS,
1399 david.dillard    1.5                                           oldClass.getClassName().getString(),
1400 sushma.fernandes 1.1                                           namespaceName.getString()) << endl;
1401 david.dillard    1.5  
1402 sushma.fernandes 1.1              }
1403                               }
1404                           }
1405                       }
1406 david.dillard    1.5  
1407 sushma.fernandes 1.1  //
1408                       // Return true if old repository class has a higher version, else return false.
1409                       //
1410                       Boolean RepositoryUpgrade::_compareVersion(const String& oldVersion,
1411                                                                  const String& newVersion)
1412                       {
1413                           Sint32 			iMinorOld = -1;
1414                           Sint32 			iMajorOld = -1;
1415                           Sint32			iUpdateOld = -1;
1416                           Sint32 			iMinorNew = -1;
1417                           Sint32 			iMajorNew = -1;
1418                           Sint32			iUpdateNew = -1;
1419                           Boolean			retVal = false;
1420                       
1421                           retVal = _parseVersion (oldVersion, iMajorOld, iMinorOld, iUpdateOld);
1422                       
1423                           // cimmof compiler rejects invalid versions.
1424                           // ATTN-SF-P3-20050209: Need to identify invalid version formats and assert
1425                           // here.
1426                           // PEGASUS_ASSERT(retVal != false);
1427                       
1428 sushma.fernandes 1.1      retVal = _parseVersion (newVersion, iMajorNew, iMinorNew, iUpdateNew);
1429                       
1430                           // cimmof compiler rejects invalid versions.
1431                           // ATTN-SF-P3-20050209: Need to identify invalid version formats and assert
1432                           // here.
1433                           // PEGASUS_ASSERT(retVal != false);
1434                       
1435                       #ifdef REPUPGRADE_DEBUG
1436 david.dillard    1.5      cout << "old Version : " << iMajorOld << "."
1437                                                    << iMinorOld << "."
1438 sushma.fernandes 1.1                               << iUpdateOld << endl;
1439 david.dillard    1.5      cout << "new Version : " << iMajorNew << "."
1440                                                    << iMinorNew << "."
1441 sushma.fernandes 1.1                               << iUpdateNew << endl;
1442                       #endif
1443                       
1444                           retVal = false;
1445                           if ( iMajorOld > iMajorNew )
1446                           {
1447                               retVal = true;
1448                           }
1449                           else if ( iMajorOld == iMajorNew )
1450                           {
1451                               if ( iMinorOld > iMinorNew )
1452 david.dillard    1.5          {
1453 sushma.fernandes 1.1              retVal = true;
1454                               }
1455                               else if ( iMinorOld == iMinorNew )
1456                               {
1457                                   if ( iUpdateOld > iUpdateNew )
1458                                   {
1459                                       retVal = true;
1460                                   }
1461                               }
1462                           }
1463                           return retVal;
1464                       }
1465                       
1466                       //
1467                       // ATTN-SF-P3-20050209: The following needs to be consolidated with
1468                       //                      cimmofParser::verifyVersion method.
1469 david.dillard    1.5  //
1470 sushma.fernandes 1.1  Boolean RepositoryUpgrade::_parseVersion(const String& version,
1471                                                                      Sint32& iMajor,
1472                                                                      Sint32& iMinor,
1473                                                                      Sint32& iUpdate)
1474                       {
1475                           Boolean ret = true;
1476                       
1477                           Sint32 pos   = -1;
1478                           Sint32 pos1  = -1;
1479                           Sint32 pos2  = -1;
1480                       
1481                           const char CHAR_PERIOD = '.';
1482                       
1483                           // Parse the input version
1484                           if (version.size())
1485                           {
1486                               // If "V" specified as first character go ahead and ignore
1487 kumpf            1.9          if ((version[0] >= '0') && (version[0] <= '9'))
1488 sushma.fernandes 1.1          {
1489                                   pos = 0;
1490                                   iMajor = version.find(0, CHAR_PERIOD);
1491                               }
1492                               else
1493                               {
1494                                   pos = 1;
1495                                   if (String::equalNoCase(version.subString(0,1), "V"))
1496                                   {
1497                                       iMajor = version.find(1, CHAR_PERIOD);
1498                                   }
1499                                   else
1500                                   {
1501                                       // First character is unknown.
1502                                       // Examples of invalid version:  ".2.7", ".", "..", "...", "AB"
1503                                       return false;
1504                                   }
1505                               }
1506                       
1507                               // Find the second and possible third period
1508                               if (iMajor >=0)
1509 sushma.fernandes 1.1          {
1510                                   iMinor = version.find(iMajor+1, CHAR_PERIOD);
1511                               }
1512                               if (iMinor >= 0)
1513                               {
1514                                   iUpdate = version.find(iMinor+1, CHAR_PERIOD);
1515                               }
1516                       
1517                               // There should be no additional identifiers after the update identifier
1518                               if (iUpdate >= 0 && iUpdate != (Sint32)PEG_NOT_FOUND)
1519                               {
1520 david.dillard    1.5              // Examples of invalid version:  "2.7.0.", "2.7.0.1",
1521 sushma.fernandes 1.1              //                               "2.7.0.a", "2.7.0.1."
1522                                   return false;
1523                               }
1524                       
1525                               // Check for trailing period
1526                               if ((iMajor >=0 && iMajor+1 == (int)version.size()) ||
1527                                   (iMinor >=0 && iMinor+1 == (int)version.size()) ||
1528                                   (iUpdate >=0 && iUpdate+1 == (int)version.size()))
1529                               {
1530                                   // Examples of invalid version:  "2.", "2.7.", "V.", "9.."
1531                                   return false;
1532                               }
1533                               // Major identifier is not specified
1534                               if (((pos > 0) && (iMajor < 0) && (!version.subString(pos).size())) ||
1535                                   ((pos > 0) && (iMajor >= 0) && (iMajor <= pos)))
1536                               {
1537                                   // Examples of invalid version: "V.2.7", "V"
1538                                   return false;
1539                               }
1540                       
1541                               // Check Major identifier for invalid format
1542 sushma.fernandes 1.1          int endM = iMajor;
1543                               if (iMajor < 0)
1544                               {
1545                                  endM = version.size();
1546                               }
1547                               for (int i = pos; i < endM; i++)
1548                               {
1549 kumpf            1.9               if (!((version[i] >= '0') && (version[i] <= '9')))
1550 sushma.fernandes 1.1               {
1551                                        // Example of invalid version:  "1B.2D.3F"
1552                                        return false;
1553                                    }
1554                               }
1555                       
1556                               // Minor identifier is not specified
1557                               if (iMajor+1 == iMinor)
1558                               {
1559                                   // Example of invalid version:  "2..9"
1560                                   return false;
1561                               }
1562                       
1563                               // Check Minor identifier for invalid format
1564                               if (iMajor > 0)
1565                               {
1566                                   int endN = iMinor;
1567                                   if (iMinor < 0)
1568                                   {
1569                                       endN = version.size();
1570                                   }
1571 sushma.fernandes 1.1              for (int i = iMajor+1; i < endN; i++)
1572                                   {
1573 kumpf            1.9                   if (!((version[i] >= '0') && (version[i] <= '9')))
1574 sushma.fernandes 1.1                   {
1575                                            // Example of invalid version:  "99.CD", "11.2D.3F"
1576                                            return false;
1577                                        }
1578                                   }
1579                               }
1580 david.dillard    1.5  
1581 sushma.fernandes 1.1          // Check Update identifier for invalid format
1582                               if (iMinor > 0)
1583                               {
1584                                   for (int i = iMinor+1; i < (int)version.size(); i++)
1585                                   {
1586 kumpf            1.9                   if (!((version[i] >= '0') && (version[i] <= '9')))
1587 sushma.fernandes 1.1                   {
1588                                             // Example of invalid version: "99.88.EF", "11.22.3F"
1589                                             return false;
1590                                        }
1591                                   }
1592                               }
1593 david.dillard    1.5  
1594 sushma.fernandes 1.1          // Set major, minor, and update values as integers
1595                               if (iMajor >= 0)
1596                               {
1597                                   pos1 = iMajor;
1598                                   iMajor = atoi((const char*)
1599                                             (version.subString(pos, iMajor).getCString()));
1600                                   if (iMinor >= 0)
1601                                   {
1602                                       pos2 = iMinor;
1603                                       iMinor = atoi((const char*)
1604                                                 (version.subString(pos1+1, iMinor).getCString()));
1605                                       iUpdate = atoi((const char*)
1606                                                 (version.subString(pos2+1).getCString()));
1607                                   }
1608                                   else
1609                                   {
1610                                       iMinor = atoi((const char*)
1611                                                 (version.subString(pos1+1).getCString()));
1612                                   }
1613                               }
1614                               else
1615 sushma.fernandes 1.1          {
1616                                   iMajor = atoi((const char*)(version.subString(pos).getCString()));
1617                               }
1618                           }
1619                       
1620                           return ret;
1621                       }
1622                       
1623                       void RepositoryUpgrade::_processNewClasses(
1624 david.dillard    1.5                            const CIMNamespaceName& namespaceName,
1625                                                 Array<CIMName>&   missingClasses,
1626 sushma.fernandes 1.1                            Array<CIMName>&   currClasses)
1627                       {
1628                           Boolean		allSuperClassesExist = true;
1629                           Uint32 		missingCount         = missingClasses.size();
1630                           Uint32 		superClassCount      = 0;
1631                           Uint32 		saveCount            = 0;
1632                           Array<CIMName>      superClassList;
1633 david.dillard    1.5  
1634 sushma.fernandes 1.1      while (missingCount > 0)
1635                           {
1636                               for ( Uint32 i=0; i < missingCount; i++)
1637                               {
1638 david.dillard    1.5              allSuperClassesExist 	= true;
1639 sushma.fernandes 1.1  
1640                                   //
1641                                   // Check if the class already exists in the new repository.
1642                                   //
1643                                   if (!Contains (currClasses,missingClasses[i]))
1644                                   {
1645                                       //
1646                                       // Check if this class has Super Classes.
1647                                       //
1648                                       _oldRepository->getSuperClassNames(
1649                       	    			namespaceName,
1650                       	    			missingClasses[i],
1651                       	    			superClassList);
1652                       
1653                                       superClassCount = superClassList.size();
1654                                       saveCount       = superClassCount;
1655                       
1656                                       while ( superClassCount > 0 && allSuperClassesExist)
1657                                       {
1658                                           //
1659 david.dillard    1.5                      // Check if all the super classes exist in the
1660 sushma.fernandes 1.1                      // new repository.
1661                                           //
1662 david.dillard    1.5                      if (!Contains(currClasses,
1663 sushma.fernandes 1.1                                       superClassList[superClassCount-1]))
1664                                           {
1665                                               allSuperClassesExist = false;
1666                                           }
1667                       
1668                                           --superClassCount;
1669                                       }
1670                       
1671                                       //
1672                                       // If all the super classes existed or if the class did not have
1673 david.dillard    1.5                  // any super classes then try to add the class to the
1674 sushma.fernandes 1.1                  // new Repository.
1675                                       //
1676                                       if (allSuperClassesExist || (saveCount==0))
1677                                       {
1678 david.dillard    1.5                      Uint32 retCode =
1679                                                 _addClassToRepository (namespaceName,
1680 sushma.fernandes 1.1                                               missingClasses[i],
1681                                                                    currClasses);
1682                       
1683                                           //
1684                                           // Check if the class was added successfully.
1685                                           //
1686                                           if (retCode == 0)
1687                                           {
1688                                                currClasses.append(missingClasses[i]);
1689                                                missingClasses.remove(i);
1690                                           }
1691                       
1692                                       }
1693                                   }
1694                       
1695                                   missingCount = missingClasses.size();
1696                                   superClassList.clear();
1697 david.dillard    1.5  
1698                               }
1699                           }
1700 sushma.fernandes 1.1  }
1701                       
1702 david.dillard    1.5  Uint32 RepositoryUpgrade::_addClassToRepository (
1703 sushma.fernandes 1.1                        const CIMNamespaceName& namespaceName,
1704                                             const CIMName&          className,
1705                                             const Array<CIMName>    existingClasses)
1706                       {
1707                           Uint32 retCode = 0;
1708                       
1709                           CIMClass                oldClass;
1710                       
1711                           // Get the missing class info from the old repository.
1712                           try
1713                           {
1714                               oldClass = _oldRepository->getClass(
1715                                                 namespaceName,
1716                                                 className,
1717                                                 true,
1718                                                 true,
1719                                                 true);
1720                           }
1721                           catch (Exception& e)
1722                           {
1723                               String message = localizeMessage (MSG_PATH,
1724 sushma.fernandes 1.1                             REPOSITORY_UPGRADE_FAILURE_KEY,
1725                                                  REPOSITORY_UPGRADE_FAILURE) +
1726                       
1727                                                e.getMessage() +
1728                       
1729                                                localizeMessage (MSG_PATH,
1730                                                  OLD_CLASS_RETRIEVAL_ERROR_KEY,
1731                                                  OLD_CLASS_RETRIEVAL_ERROR,
1732                                                  className.getString(),
1733                                                  namespaceName.getString());
1734                           }
1735                           catch (...)
1736                           {
1737 david.dillard    1.5          String message = localizeMessage ( MSG_PATH,
1738 sushma.fernandes 1.1                                             REPOSITORY_UPGRADE_FAILURE_KEY,
1739                                                                  REPOSITORY_UPGRADE_FAILURE ) +
1740 david.dillard    1.5                           localizeMessage ( MSG_PATH,
1741 sushma.fernandes 1.1                                             OLD_CLASS_RETRIEVAL_ERROR_KEY,
1742                                                                  OLD_CLASS_RETRIEVAL_ERROR,
1743                                                                  className.getString(),
1744                                                                  namespaceName.getString());
1745                               throw RepositoryUpgradeException (message);
1746                           }
1747                       
1748                           //
1749                           // Invoke the Special Processing modules.
1750                           //
1751                           //
1752                           // Check if the class must be created. If true, use the
1753                           // processed class. If the SSP Modules have chosen to
1754                           // to ignore the class then skip the class creation.
1755                           //
1756                           CIMClass processedClass = oldClass.clone();
1757 sushma.fernandes 1.2  
1758                       #ifdef ENABLE_MODULE_PROCESSING
1759 sushma.fernandes 1.1      if (!_invokeModules (oldClass, processedClass))
1760                           {
1761                       #ifdef REPUPGRADE_DEBUG
1762                               cerr << "Ignoring class creation : "
1763                               << oldClass.getClassName() << endl;
1764                       #endif
1765                           }
1766                           else
1767                           {
1768 sushma.fernandes 1.2  #endif
1769 sushma.fernandes 1.1          try
1770                               {
1771                       #ifdef REPUPGRADE_DEBUG
1772                                   cout << "Creating class : " << className.getString() << endl;
1773                       #endif
1774                                   _newRepository->createClass (namespaceName, processedClass);
1775                       #ifdef REPUPGRADE_DEBUG
1776                                   cout << "Class created : " << className.getString() << endl;
1777                       #endif
1778                               }
1779                               catch (CIMException& ce)
1780                               {
1781                                   if (ce.getCode() == CIM_ERR_NOT_FOUND)
1782                                   {
1783 sushma.fernandes 1.16                 CIMName dependentClassName(ce.getMessage());
1784 sushma.fernandes 1.1  
1785                                       //
1786                                       // Check if the error was due to a non-existent class, if so
1787 david.dillard    1.5                  // will try to create this class later. This error could be
1788                                       // because a dependent class of an Association class
1789 sushma.fernandes 1.1                  // has not yet been created.
1790                                       //
1791 sushma.fernandes 1.16                 if (! Contains( existingClasses, dependentClassName))
1792 sushma.fernandes 1.1                  {
1793 sushma.fernandes 1.16                     // 
1794                                           // Check if the class that we depend on exists in 
1795                                           // the old repository.
1796                                           // If it doesn't exist, error out.
1797                                           //
1798                                           try
1799                                           { 
1800                                               oldClass = _oldRepository->getClass(
1801                                                                   namespaceName,
1802                                                                   dependentClassName,
1803                                                                   true,
1804                                                                   true,
1805                                                                   true);
1806                       
1807                                           }
1808 kumpf            1.20                     catch (const CIMException&)
1809 sushma.fernandes 1.16                     {
1810                                               //
1811                                               // We have an exception case here.
1812                                               //
1813                                               String message = localizeMessage (MSG_PATH,
1814                                                      REPOSITORY_UPGRADE_FAILURE_KEY,
1815                                                      REPOSITORY_UPGRADE_FAILURE) + " " +
1816                       
1817                                                     localizeMessage ( MSG_PATH,
1818                                                     CLASS_CREATION_ERROR_KEY,
1819                                                     CLASS_CREATION_ERROR,
1820                                                     className.getString(),
1821                                                     namespaceName.getString()) + " " +
1822                       
1823                                                      localizeMessage (MSG_PATH,
1824                                                      OLD_DEPENDENT_CLASS_RETRIEVAL_ERROR_KEY,
1825                                                      OLD_DEPENDENT_CLASS_RETRIEVAL_ERROR,
1826                                                      dependentClassName.getString(),
1827                                                      namespaceName.getString());
1828                       
1829                                                throw RepositoryUpgradeException(message);
1830 sushma.fernandes 1.16                     }
1831 sushma.fernandes 1.1  #ifdef REPUPGRADE_DEBUG
1832                                           cout << "Adding to retry list Class name : "
1833                                                << ce.getMessage() << endl;
1834                       #endif
1835                                           retCode = 1;
1836                                       }
1837                                       else
1838                                       {
1839 david.dillard    1.5                      _logCreateClassError (namespaceName,
1840 sushma.fernandes 1.16                                       oldClass,
1841                                                             (ce.getMessage()+". "));
1842 sushma.fernandes 1.1                  }
1843                                   }
1844                                   else
1845                                   {
1846 david.dillard    1.5                  _logCreateClassError (namespaceName,
1847 sushma.fernandes 1.1                                            oldClass,
1848 david.dillard    1.5                                            (ce.getMessage()+". "));
1849 sushma.fernandes 1.1              }
1850                               }
1851                               catch (Exception& e)
1852                               {
1853 sushma.fernandes 1.16            _logCreateClassError (namespaceName,
1854 david.dillard    1.5                                        oldClass,
1855 sushma.fernandes 1.2                                        (e.getMessage()+". "));
1856 sushma.fernandes 1.1          }
1857                               catch (...)
1858                               {
1859 sushma.fernandes 1.16            _logCreateClassError (namespaceName,
1860                       
1861 david.dillard    1.5                                        oldClass,
1862 sushma.fernandes 1.1                                        String::EMPTY);
1863                               }
1864 sushma.fernandes 1.2  #ifdef ENABLE_MODULE_PROCESSING
1865 sushma.fernandes 1.1      }
1866 sushma.fernandes 1.2  #endif
1867 sushma.fernandes 1.1  
1868                           return retCode;
1869                       }
1870                       
1871                       void RepositoryUpgrade::_addInstances(void)
1872                       {
1873                           Array<CIMNamespaceName>                  oldNamespaces;
1874                       
1875                           oldNamespaces = _oldRepository->enumerateNameSpaces();
1876                       
1877                           if (oldNamespaces.size() > 0)
1878                           {
1879                               CIMName			className;
1880                       
1881                               for ( Uint32 i = 0; i < oldNamespaces.size(); i++)
1882                               {
1883 david.dillard    1.5              //
1884 sushma.fernandes 1.1              // Get the list of class names.
1885                                   //
1886                                   Array<CIMName>                  oldClassNames;
1887                       
1888                                   //
1889                                   // Gather class information for each namespace.
1890                                   //
1891                                   oldClassNames = _oldRepository->enumerateClassNames(
1892                                              oldNamespaces[i],
1893                                              className,
1894                                              true);
1895                       
1896                                   //
1897                                   // Enumerate the instances for each class.
1898                                   //
1899                                   if (oldClassNames.size() > 0)
1900                                   {
1901                                       for ( Uint32 ctr=0; ctr < oldClassNames.size(); ctr++)
1902                                       {
1903 sushma.fernandes 1.2  #ifdef REPUPGRADE_DEBUG
1904 david.dillard    1.5              cout << "Processing namespace : " << oldNamespaces[i]
1905 sushma.fernandes 1.2                   << "class name : " <<  oldClassNames[ctr] << endl;
1906                       #endif
1907 sushma.fernandes 1.1                      Array<CIMInstance>         instances;
1908                                           Uint32                     n = 0;
1909                                           Uint32                     ictr = 0;
1910                       
1911 kumpf            1.22                         instances = _oldRepository->enumerateInstancesForClass(
1912 david            1.14                                             oldNamespaces[i],
1913                                                                   oldClassNames[ctr],
1914 sushma.fernandes 1.1                                              true,
1915                                                                   true,
1916                                                                   true);
1917 david            1.14 
1918 sushma.fernandes 1.1                          if (instances.size() > 0)
1919                                               {
1920                       #ifdef REPUPGRADE_DEBUG
1921 david.dillard    1.5                              cout << "Found instances : "
1922                                                        << instances.size() << endl;
1923 sushma.fernandes 1.1  #endif
1924                                                   for ( ictr=0; ictr<instances.size(); ictr++)
1925                                                   {
1926 sushma.fernandes 1.3                                  try
1927                                                       {
1928                                                           //
1929 david.dillard    1.5                                      // Check if the instance must be created.
1930                                                           // If true, use the processed instance.
1931                                                           // If an SSP Module has chosen to ignore
1932                                                           // the instance then skip the
1933 sushma.fernandes 1.3                                      // instance creation.
1934                                                           //
1935 david.dillard    1.5                                      CIMInstance processedInstance =
1936 sushma.fernandes 1.1                                                 instances[ictr].clone();
1937                       
1938 sushma.fernandes 1.2  #ifdef ENABLE_MODULE_PROCESSING
1939 david.dillard    1.5                                      if (!_invokeModules(instances[ictr],
1940 sushma.fernandes 1.3                                                processedInstance))
1941                                                           {
1942 sushma.fernandes 1.1  #ifdef REPUPGRADE_DEBUG
1943 david.dillard    1.5                                          cerr << "Ignoring instance creation : "
1944                                                               << instances[ictr].getPath().toString()
1945 sushma.fernandes 1.3                                          << endl;
1946 sushma.fernandes 1.1  #endif
1947 sushma.fernandes 1.3                                          continue;
1948                                                           }
1949 sushma.fernandes 1.2  #endif
1950 sushma.fernandes 1.1  
1951 sushma.fernandes 1.3                                      //
1952                                                           // Create the instance.
1953                                                           //
1954 sushma.fernandes 1.1  #ifdef REPUPGRADE_DEBUG
1955 sushma.fernandes 1.3  				    cout << "Creating instance" << endl;
1956 sushma.fernandes 1.1  #endif
1957 sushma.fernandes 1.3                                      _newRepository->createInstance(
1958 sushma.fernandes 1.1                                                           oldNamespaces[i],
1959                                                                                processedInstance);
1960                       #ifdef REPUPGRADE_DEBUG
1961 sushma.fernandes 1.3  		                    cout << "Instance created" << endl;
1962 sushma.fernandes 1.1  #endif
1963 sushma.fernandes 1.3                                  }
1964                                                       catch (CIMException &ce)
1965                                                       {
1966                                                           if (ce.getCode() == CIM_ERR_ALREADY_EXISTS)
1967                                                           {
1968 sushma.fernandes 1.1  #ifdef REPUPGRADE_DEBUG
1969 david.dillard    1.5                                         cout <<
1970 sushma.fernandes 1.3                                         "Instance already exists." << endl;
1971 sushma.fernandes 1.1  #endif
1972 sushma.fernandes 1.3                                      }
1973                                                           else
1974                                                           {
1975                                                               _logCreateInstanceError(
1976                                                                oldNamespaces[i],
1977                                                                               instances[ictr],
1978 david.dillard    1.5                                           (ce.getMessage()+". "));
1979 sushma.fernandes 1.3                                      }
1980 david.dillard    1.5                                  }
1981 sushma.fernandes 1.3                                  catch (Exception& e)
1982                                                       {
1983                                                           _logCreateInstanceError(oldNamespaces[i],
1984                                                                          instances[ictr],
1985 david.dillard    1.5                                                     (e.getMessage()+". "));
1986                       
1987 sushma.fernandes 1.3                                  }
1988                                                       catch (...)
1989 sushma.fernandes 1.2                                  {
1990 sushma.fernandes 1.3                                      _logCreateInstanceError(oldNamespaces[i],
1991                                                                           instances[ictr],
1992 david.dillard    1.5                                                      String::EMPTY);
1993 sushma.fernandes 1.2                                  }
1994 sushma.fernandes 1.1                              }
1995                                               }
1996 david.dillard    1.5                     }
1997                                     }
1998                                }
1999                           }
2000 sushma.fernandes 1.1  }
2001                       
2002                       ////////////////////////////////////////////////////////////////////////////////
2003                       //
2004                       // _namespaceNameToDirName()
2005                       // Converts any "/"s in the Namespace name to "#".
2006                       //
2007                       ////////////////////////////////////////////////////////////////////////////////
2008                       
2009                       static String _namespaceNameToDirName(const CIMNamespaceName& namespaceName)
2010                       {
2011                           String dirName = namespaceName.getString();
2012                       
2013                           for (Uint32 i=0; i<dirName.size(); i++)
2014                           {
2015                               if (dirName[i] == '/')
2016                               {
2017                                   dirName[i] = '#';
2018                               }
2019                           }
2020                       
2021 sushma.fernandes 1.1      return dirName;
2022                       }
2023                       
2024 david.dillard    1.5  void RepositoryUpgrade::_logRequestToFile(
2025 sushma.fernandes 1.1                                const String&   fileName)
2026                       {
2027                           Uint64 				timeoutMilliseconds = 20;
2028                           Uint64 				startMilliseconds = 0;
2029                           Uint64 				nowMilliseconds = 0;
2030                           Uint64 				stopMilliseconds = 0;
2031                           String                       	startLine;
2032                           Array<HTTPHeader>            	headers;
2033                           Uint32  	                        contentLength = 0;
2034                           Uint32    	                        contentOffset = 0;
2035                           HTTPMessage* 			httpMessage;
2036 mike             1.12     Buffer 			data;
2037 sushma.fernandes 1.1  
2038                           startMilliseconds = TimeValue::getCurrentTime().toMilliseconds();
2039                           nowMilliseconds = startMilliseconds;
2040                           stopMilliseconds = nowMilliseconds + timeoutMilliseconds;
2041                       
2042                           // Loop till we get response or timeout.
2043                           while (nowMilliseconds < stopMilliseconds)
2044                           {
2045                               //
2046                               // Check to see if incoming queue has a message
2047                               //
2048                       
2049                               Message* response = dequeue();
2050                       
2051                               if (response)
2052                               {
2053                                   httpMessage = (HTTPMessage*)response;
2054 kumpf            1.6              data = httpMessage->message;
2055 sushma.fernandes 1.1              httpMessage->parse( startLine, headers, contentLength );
2056                       
2057                                   if( contentLength > 0 )
2058                                   {
2059                                       contentOffset = data.size() - contentLength;
2060                                   }
2061                                   else
2062                                   {
2063                                       contentOffset = data.size();
2064                                   }
2065                       
2066                                   //
2067                                   //  Get HTTP header
2068                                   //
2069                                   if (contentOffset < data.size())
2070                                   {
2071                                       //
2072                                       //  Print XML response to the ostream
2073                                       //
2074 kumpf            1.6                  data.append('\0');
2075                                       const char* content = data.getData() + contentOffset;
2076 david.dillard    1.5  
2077 sushma.fernandes 1.1                  ofstream outFile(fileName.getCString(), ios::app);
2078                                       if (!outFile)
2079                                       {
2080                       #ifdef REPUPGRADE_DEBUG
2081 david.dillard    1.5                      cerr << "Unable to open output file : "
2082 sushma.fernandes 1.1                           << fileName << endl;
2083                       #endif
2084                                           return;
2085                                       }
2086                                       XmlWriter::indentedPrint (outFile, content, 0);
2087                                       outFile.close();
2088                                   }
2089                               }
2090                               nowMilliseconds = TimeValue::getCurrentTime().toMilliseconds();
2091                           }
2092                       }
2093                       
2094 david.dillard    1.5  void RepositoryUpgrade::_logCreateClassError(
2095                                      const CIMNamespaceName& namespaceName,
2096 sushma.fernandes 1.1                 const CIMClass& oldClass,
2097 david.dillard    1.8                 const String&   message)
2098 sushma.fernandes 1.1  {
2099 david.dillard    1.8      CIMRequestMessage* request;
2100 sushma.fernandes 1.1  
2101                           // Create a CreateClass message.
2102                           request = new CIMCreateClassRequestMessage(
2103                                                                String::EMPTY,
2104                                                                namespaceName,
2105                                                                oldClass,
2106                                                                QueueIdStack());
2107                       
2108                           // Enqueue the request.
2109                           _requestEncoder->enqueue(request);
2110                       
2111                           // Build the output filepath.
2112 david.dillard    1.5      String outputFileName = String(_LOG_PATH +
2113                                                          _namespaceNameToDirName(namespaceName) +
2114                                                          "."+
2115                                                          oldClass.getClassName().getString() +
2116 sushma.fernandes 1.1                                     _FILE_EXTENSION);
2117                       
2118                           // Log the request to output filepath.
2119                           _logRequestToFile (outputFileName);
2120                       
2121 kumpf            1.17     delete request;
2122 sushma.fernandes 1.1  
2123                           String errMsg = localizeMessage ( MSG_PATH,
2124                                                     REPOSITORY_UPGRADE_FAILURE_KEY,
2125                                                     REPOSITORY_UPGRADE_FAILURE) +
2126 sushma.fernandes 1.2                      message +
2127 david.dillard    1.5                      localizeMessage ( MSG_PATH,
2128 sushma.fernandes 1.1                                CLASS_CREATION_ERROR_KEY,
2129                                                     CLASS_CREATION_ERROR,
2130                                                     oldClass.getClassName().getString(),
2131                                                     namespaceName.getString()) +
2132                                           localizeMessage ( MSG_PATH,
2133                                                             CLASS_XML_OUTPUT_FILE_KEY,
2134                                                             CLASS_XML_OUTPUT_FILE,
2135                                                             outputFileName);
2136                       
2137                           throw RepositoryUpgradeException (errMsg);
2138                       }
2139                       
2140 david.dillard    1.5  void RepositoryUpgrade::_logCreateInstanceError(
2141                                    const CIMNamespaceName& namespaceName,
2142 sushma.fernandes 1.1               const CIMInstance& instance,
2143 david.dillard    1.8               const String&      message)
2144 sushma.fernandes 1.1  {
2145 david.dillard    1.8      CIMRequestMessage* request;
2146 sushma.fernandes 1.1  
2147                           instanceCount++;
2148                       
2149                           // Create a CreateInstance message.
2150                           request = new CIMCreateInstanceRequestMessage(
2151                                                                String::EMPTY,
2152                                                                namespaceName,
2153                                                                instance,
2154                                                                QueueIdStack());
2155                       
2156                           // Enqueue the request.
2157                           _requestEncoder->enqueue(request);
2158                       
2159                           char buffer[34];
2160                           sprintf( buffer, "%u", instanceCount );
2161                           // Build the output filepath.
2162 david.dillard    1.5      String outputFileName = String(_LOG_PATH +
2163                                                          _namespaceNameToDirName(namespaceName) +
2164                                                          "."+
2165                                                          "instance." + buffer +
2166 sushma.fernandes 1.1                                     _FILE_EXTENSION);
2167                       
2168                           // Log the request to output filepath.
2169                           _logRequestToFile (outputFileName);
2170                       
2171 kumpf            1.17     delete request;
2172 sushma.fernandes 1.1  
2173                           String errMsg = localizeMessage ( MSG_PATH, REPOSITORY_UPGRADE_FAILURE_KEY,
2174 david.dillard    1.5                                         REPOSITORY_UPGRADE_FAILURE)
2175                                            + message
2176 sushma.fernandes 1.1                       + localizeMessage ( MSG_PATH, INSTANCE_CREATION_ERROR_KEY,
2177                                                                INSTANCE_CREATION_ERROR,
2178                                                                namespaceName.getString())
2179                                            + localizeMessage ( MSG_PATH, INSTANCE_XML_OUTPUT_FILE_KEY,
2180                                                                INSTANCE_XML_OUTPUT_FILE,
2181                                                                outputFileName);
2182                       
2183                           throw RepositoryUpgradeException (errMsg);
2184                       }
2185                       
2186 david.dillard    1.5  void RepositoryUpgrade::_logSetQualifierError(
2187                                 const CIMNamespaceName& namespaceName,
2188 sushma.fernandes 1.1            const CIMQualifierDecl& qualifier,
2189 david.dillard    1.8            const String&           message)
2190 sushma.fernandes 1.1  {
2191 david.dillard    1.8      CIMRequestMessage* request;
2192 sushma.fernandes 1.1  
2193                           qualifierCount++;
2194                       
2195                           // Create a SetQualifier message.
2196                           request = new CIMSetQualifierRequestMessage(
2197                                                                String::EMPTY,
2198                                                                namespaceName,
2199                                                                qualifier,
2200                                                                QueueIdStack());
2201                       
2202                           // Enqueue the request.
2203                           _requestEncoder->enqueue(request);
2204 david.dillard    1.5  
2205 sushma.fernandes 1.1      char buffer[34];
2206                           sprintf( buffer, "%u", qualifierCount );
2207                           // Build the output filepath.
2208 david.dillard    1.5      String outputFileName = String(_LOG_PATH +
2209                                                          _namespaceNameToDirName(namespaceName) +
2210                                                          "." +
2211 sushma.fernandes 1.1                                     "qualifier." + buffer +
2212                                                          _FILE_EXTENSION );
2213                       
2214                           // Log the request to output filepath.
2215                           _logRequestToFile (outputFileName);
2216                       
2217 kumpf            1.17     delete request;
2218 sushma.fernandes 1.1  
2219                           String errMsg =  localizeMessage ( MSG_PATH, REPOSITORY_UPGRADE_FAILURE_KEY,
2220                                                              REPOSITORY_UPGRADE_FAILURE)
2221 david.dillard    1.5                       + message
2222 sushma.fernandes 1.1                       + localizeMessage ( MSG_PATH, QUALIFIER_CREATION_ERROR_KEY,
2223                                                                QUALIFIER_CREATION_ERROR,
2224 david.dillard    1.5                                           namespaceName.getString(),
2225                                                                qualifier.getName().getString())
2226 sushma.fernandes 1.1                       + localizeMessage (MSG_PATH, QUALIFIER_XML_OUTPUT_FILE_KEY,
2227                                                                 QUALIFIER_XML_OUTPUT_FILE,
2228                                                                 outputFileName);
2229 david.dillard    1.5  
2230 sushma.fernandes 1.1      throw RepositoryUpgradeException (errMsg);
2231                       }
2232                       
2233 sushma.fernandes 1.2  #ifdef ENABLE_MODULE_PROCESSING
2234 sushma.fernandes 1.1  DynamicLibrary RepositoryUpgrade::_loadSSPModule(const String& moduleName)
2235                       {
2236                           String fileName;
2237                       
2238 david.dillard    1.5  //
2239 sushma.fernandes 1.3  // Get the Special Process Module location.
2240                       //
2241                       // ATTN-SF-P3-20050209: Platforms that use a different directory path other than
2242                       //                      $PEGASUS_HOME/lib must add to the code below.
2243                       //                      Also RELEASE_DIRS configurations must be appropriately
2244                       //                      updated.
2245                       //
2246                       
2247 sushma.fernandes 1.2  #if defined (PEGASUS_OS_TYPE_WINDOWS)
2248 david.dillard    1.5      fileName = _pegasusHome + "/bin/" +
2249                                         FileSystem::buildLibraryFileName(moduleName);
2250 david            1.14 #elif defined (PEGASUS_OS_OS400)
2251                           fileName = moduleName;
2252 sushma.fernandes 1.2  #else
2253 david.dillard    1.5      fileName = _pegasusHome + "/lib/" +
2254                                         FileSystem::buildLibraryFileName(moduleName);
2255 sushma.fernandes 1.2  #endif
2256 sushma.fernandes 1.1  
2257                           DynamicLibrary dl(fileName);
2258                       
2259                           if (!dl.load())
2260                           {
2261 sushma.fernandes 1.2  #ifdef REPUPGRADE_DEBUG
2262 sushma.fernandes 1.1          cout << "Error is : " << strerror(errno) << endl;
2263 sushma.fernandes 1.2  #endif
2264 david.dillard    1.5          String message =  localizeMessage ( MSG_PATH,
2265 sushma.fernandes 1.1                                              LIBRARY_LOAD_ERROR_KEY,
2266                                                                   LIBRARY_LOAD_ERROR,
2267 david.dillard    1.5                                              moduleName);
2268 sushma.fernandes 1.1  
2269                               throw RepositoryUpgradeException(message);
2270                           }
2271                       
2272                           return dl;
2273                       }
2274                       
2275                       SchemaSpecialProcessModule *  RepositoryUpgrade::_createSSPModule(
2276                                                          DynamicLibrary& library)
2277                       {
2278                           CREATE_SSPMODULE_FUNCTION sspModule;
2279                       
2280                           sspModule = (CREATE_SSPMODULE_FUNCTION)
2281                                            library.getSymbol(
2282                                            SchemaSpecialProcessModule::CREATE_SSPMODULE_ENTRY_POINT);
2283                       
2284                           if (!sspModule)
2285                           {
2286 david.dillard    1.5          String message =  localizeMessage ( MSG_PATH,
2287 sushma.fernandes 1.1                                              LIBRARY_ENTRY_POINT_ERROR_KEY,
2288                                                                   LIBRARY_ENTRY_POINT_ERROR,
2289                                                                   library.getFileName());
2290                       
2291                               throw RepositoryUpgradeException(message);
2292                           }
2293                       
2294                           return(sspModule());
2295                       }
2296                       
2297                       void RepositoryUpgrade::_initSSPModule()
2298                       {
2299                           for (Uint32 counter=0; counter < SSPModuleTable::NUM_MODULES; counter++)
2300                           {
2301                               //
2302                               // Load the SSPModule library.
2303                               //
2304                       #ifdef REPUPGRADE_DEBUG
2305 david.dillard    1.5          cout << "Loading library name : "
2306 sushma.fernandes 1.1               << schemaProcessingModules[counter].moduleName << endl;
2307                       #endif
2308 david.dillard    1.5          DynamicLibrary tmpLibrary
2309 sushma.fernandes 1.1                   = _loadSSPModule(schemaProcessingModules[counter].moduleName);
2310 david.dillard    1.5  
2311 sushma.fernandes 1.1          _library[counter] = tmpLibrary;
2312 david.dillard    1.5  
2313 sushma.fernandes 1.1          //
2314                               // Create the SSPModule object.
2315                               //
2316                               _sspModule[counter] = _createSSPModule (_library[counter]);
2317                          }
2318                       }
2319                       
2320                       void RepositoryUpgrade::_cleanupSSPModule()
2321                       {
2322                           for (Uint32 counter=0; counter < SSPModuleTable::NUM_MODULES; counter++)
2323                           {
2324                       #ifdef REPUPGRADE_DEBUG
2325                               cout << "Unloading library name : "
2326                                    << schemaProcessingModules[counter].moduleName << endl;
2327                       #endif
2328                               if (_library->isLoaded())
2329                               {
2330                                   // Unload the library.
2331                                   _library->unload();
2332                               }
2333                           }
2334 sushma.fernandes 1.1  }
2335                       
2336                       Boolean RepositoryUpgrade::_invokeModules(CIMQualifierDecl& inputQualifier,
2337                                                                 CIMQualifierDecl& outputQualifier)
2338                       {
2339                           Boolean createQualifier = true;
2340 david.dillard    1.5  
2341                           for (Uint32 counter=0; counter < SSPModuleTable::NUM_MODULES
2342 sushma.fernandes 1.1           && createQualifier==true ; counter++)
2343                           {
2344                               if ((strcmp(schemaProcessingModules[counter].moduleType, _ALL) == 0) ||
2345 david.dillard    1.5               (strcmp(schemaProcessingModules[counter].moduleType,
2346 sushma.fernandes 1.1                  _QUALIFIER_ONLY ) == 0 ))
2347                               {
2348                       #ifdef REPUPGRADE_DEBUG
2349 david.dillard    1.5              cout << "Invoking library name : "
2350 sushma.fernandes 1.1               << schemaProcessingModules[counter].moduleName << endl;
2351                       #endif
2352 david.dillard    1.5              createQualifier =
2353                                             _sspModule[counter]->processQualifier(inputQualifier,
2354 sushma.fernandes 1.1                                                             outputQualifier);
2355                                   inputQualifier = outputQualifier.clone();
2356                               }
2357                           }
2358                       
2359                           return createQualifier;
2360                       }
2361                       
2362 david.dillard    1.5  Boolean RepositoryUpgrade::_invokeModules(CIMClass& inputClass,
2363 sushma.fernandes 1.1                                            CIMClass& outputClass)
2364                       {
2365                          Boolean createClass = true;
2366                       
2367 david.dillard    1.5     for (Uint32 counter=0; counter < SSPModuleTable::NUM_MODULES
2368 sushma.fernandes 1.1          && createClass==true ; counter++)
2369                          {
2370                              if ((strcmp(schemaProcessingModules[counter].moduleType, _ALL) == 0) ||
2371 david.dillard    1.5               (strcmp(schemaProcessingModules[counter].moduleType,
2372 sushma.fernandes 1.1                  _CLASS_ONLY ) == 0 ))
2373                              {
2374                       #ifdef REPUPGRADE_DEBUG
2375 david.dillard    1.5             cout << "Invoking library name : "
2376 sushma.fernandes 1.1                  << schemaProcessingModules[counter].moduleName << endl;
2377                       #endif
2378 david.dillard    1.5             createClass =
2379 sushma.fernandes 1.1                 _sspModule[counter]->processClass(inputClass, outputClass);
2380                                  inputClass = outputClass.clone();
2381                              }
2382                          }
2383                       
2384                          return createClass;
2385                       }
2386                       
2387                       Boolean RepositoryUpgrade::_invokeModules(CIMInstance& inputInstance,
2388                                                                 CIMInstance& outputInstance)
2389                       {
2390                           Boolean createInstance = true;
2391                       
2392                           for (Uint32 counter=0; counter < SSPModuleTable::NUM_MODULES
2393                                 && createInstance==true; counter++)
2394                           {
2395                               if ((strcmp(schemaProcessingModules[counter].moduleType, _ALL) == 0) ||
2396 david.dillard    1.5               (strcmp(schemaProcessingModules[counter].moduleType,
2397 sushma.fernandes 1.1                  _INSTANCE_ONLY ) == 0 ))
2398                               {
2399                       #ifdef REPUPGRADE_DEBUG
2400 david.dillard    1.5              cout << "Invoking library name : "
2401 sushma.fernandes 1.1               << schemaProcessingModules[counter].moduleName << endl;
2402                       #endif
2403                                   createInstance =
2404                                   _sspModule[counter]->processInstance(inputInstance, outputInstance);
2405                       
2406                                   inputInstance = outputInstance.clone();
2407                               }
2408                           }
2409                       
2410                           return createInstance;
2411                       }
2412 sushma.fernandes 1.2  #endif
2413 sushma.fernandes 1.1  
2414                       /**
2415 david.dillard    1.5  
2416                           Parses the command line for old repository path, creates RepositoryUpgrade
2417                           instance and invokes upgradeRepository method.
2418                       
2419 sushma.fernandes 1.1      @param   argc  the number of command line arguments
2420                           @param   argv  the string vector of command line arguments
2421 david.dillard    1.5  
2422 sushma.fernandes 1.1      @return  0                  if the command is successful
2423                                    1                  if an error occurs in executing the command
2424 david.dillard    1.5  
2425 sushma.fernandes 1.1   */
2426                       PEGASUS_NAMESPACE_END
2427 david            1.14 #ifndef PEGASUS_OS_OS400
2428 sushma.fernandes 1.1  
2429                       // exclude main from the Pegasus Namespace
2430                       PEGASUS_USING_PEGASUS;
2431                       PEGASUS_USING_STD;
2432                       
2433 david.dillard    1.5  int main (int argc, char* argv [])
2434 sushma.fernandes 1.1  {
2435                           RepositoryUpgrade 	command;
2436                           Uint32		retCode;
2437                       
2438                           //l10n set message loading to process locale
2439                           MessageLoader::_useProcessLocale = true;
2440                       
2441                           try
2442                           {
2443                               command.setCommand (argc, argv);
2444                           }
2445                           catch (CommandFormatException& cfe)
2446                           {
2447                               cerr << RepositoryUpgrade::COMMAND_NAME << ": " << cfe.getMessage ()
2448                                    << endl;
2449                               cerr << "Use '-h' or '--help' to obtain command syntax." << endl;
2450                               return (Command::RC_ERROR);
2451                           }
2452                       
2453                           retCode = command.execute (cout, cerr);
2454                       
2455 sushma.fernandes 1.1      return (retCode);
2456                       }
2457 david            1.14 
2458                       #endif

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2