⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 repositoryupgrade.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	           localizeMessage ( MSG_PATH,                                  REPOSITORY_DOES_NOT_EXIST_KEY,                                  REPOSITORY_DOES_NOT_EXIST,                                  _newRepositoryPath )                   );	throw RepositoryUpgradeException("");#endif        return 1;    }    //    // Options HELP and VERSION    //    if (_optionType == _OPTION_TYPE_HELP)    {        outPrintWriter << _usage << endl;        return (RC_SUCCESS);    }    else if(_optionType == _OPTION_TYPE_VERSION)    {        outPrintWriter << "Version " << PEGASUS_PRODUCT_VERSION << endl;        return (RC_SUCCESS);    }    try    {#ifdef ENABLE_MODULE_PROCESSING        //        // Load the Special Processing Modules.        //        _initSSPModule();#endif        _modulesInitialized = true;        //        // Upgrade the Repository.        //        upgradeRepository();    }    catch (RepositoryUpgradeException& rue)    {        errPrintWriter << rue.getMessage() << endl;#ifdef PEGASUS_OS_OS400        Logger::put(Logger::STANDARD_LOG,"cimserver repupgrade",Logger::SEVERE,rue.getMessage());	throw rue;#endif        return 1;    }    catch (Exception &e)    {        errPrintWriter << e.getMessage() << endl;#ifdef PEGASUS_OS_OS400        Logger::put(Logger::STANDARD_LOG,"cimserver repupgrade",Logger::SEVERE,e.getMessage());	throw e;#endif        return 1;    }    catch (...)    {        errPrintWriter << localizeMessage ( MSG_PATH,                                  REPOSITORY_UPGRADE_UNKNOWN_ERROR_KEY,                                  REPOSITORY_UPGRADE_UNKNOWN_ERROR )             << localizeMessage ( MSG_PATH,                                  REPOSITORY_UPGRADE_FAILURE_KEY,                                  REPOSITORY_UPGRADE_FAILURE );#ifdef PEGASUS_OS_OS400        Logger::put(Logger::STANDARD_LOG,"cimserver repupgrade",Logger::SEVERE,	           localizeMessage ( MSG_PATH,                                  REPOSITORY_UPGRADE_UNKNOWN_ERROR_KEY,                                  REPOSITORY_UPGRADE_UNKNOWN_ERROR ));        Logger::put(Logger::STANDARD_LOG,"cimserver repupgrade",Logger::SEVERE,                localizeMessage ( MSG_PATH,                                  REPOSITORY_UPGRADE_FAILURE_KEY,                                  REPOSITORY_UPGRADE_FAILURE ));                  	throw RepositoryUpgradeException("");#endif        return 1;    }    return 0;}void RepositoryUpgrade::upgradeRepository(){    Array<CIMNamespaceName> 		oldNamespaces;    Array<CIMNamespaceName> 		newNamespaces;    Array<CIMNamespaceName> 		missingNamespaces;    CIMName				className;    //    // Create the old and new Repository instances.    //    _oldRepository = new CIMRepository (_oldRepositoryPath);    _newRepository = new CIMRepository (_newRepositoryPath);    //    // Get Namespace information for old Repository.    //    oldNamespaces = _oldRepository->enumerateNameSpaces();    //    // Get Namespace information for new Repository.    //    newNamespaces = _newRepository->enumerateNameSpaces();    //    // Check if the namespaces in the old repository exist in the new.    // If they don't exist, create them and populate.    //    missingNamespaces = _compareNamespaces( oldNamespaces, newNamespaces );    if ( missingNamespaces.size() > 0 )    {        //        // Need to add the missing namespaces (includes classes &        // qualifiers) to the new repository.        //        _addNamespaces(missingNamespaces);        //        // Since the missing namespaces have been processed, remove        // them from the old Namespaces list. That way we will process only        // the pre-existing namespaces that existed in both the repositories        // when we look for qualifiers and classes to be added.        //        for (Uint32 i=0; i < missingNamespaces.size(); i++)        {            // find the namespace and remove it from list of old namespaces.            Uint32 n = oldNamespaces.size();            for (Uint32 j = 0; j < n; j++)            {                if (oldNamespaces[j] == missingNamespaces[i])                {                    oldNamespaces.remove(j);                    break;                }            }        }    }    //    // Get the class information for pre-existing namespaces    // in the old and new repositories.    //    Uint32 n = oldNamespaces.size();    Array<CIMName> 			oldClassNames;    Array<CIMName> 			newClassNames;    for ( Uint32 i=0; i < n;  i++)    {        oldClassNames.clear();        newClassNames.clear();        // Add qualifiers.        _addQualifiers (oldNamespaces[i]);#ifdef REPUPGRADE_DEBUG        cout << "Now processing namespace : "                << oldNamespaces[i] << " i=" << i << endl;#endif        //        // Gather class information for each namespace.        //        oldClassNames = _oldRepository->enumerateClassNames(                           oldNamespaces[i],                           className,                           true);        newClassNames = _newRepository->enumerateClassNames(                                 oldNamespaces[i],                                 className,                                 true);        //        // Process the class list.        //        if ( oldClassNames.size() > 0 )        {            _processClasses(            oldNamespaces[i],            oldClassNames,            newClassNames);        }    }    // Create Instances.#ifdef REPUPGRADE_DEBUG    cout << "Checking for instances..." << endl;#endif    _addInstances ();}Array<CIMNamespaceName> RepositoryUpgrade::_compareNamespaces(                           const Array<CIMNamespaceName>& oldNamespaces,                           const Array<CIMNamespaceName>& newNamespaces){    Array<CIMNamespaceName>     namespaceNames;    Uint32 n = oldNamespaces.size();    for ( Uint32 i=0; i < n; i++ )    {        if (! Contains (newNamespaces,oldNamespaces[i]))        {            namespaceNames.append( oldNamespaces[i] );        }    }    return namespaceNames;}void RepositoryUpgrade::_addQualifiers (const CIMNamespaceName namespaceName){    //    // Retrieve qualifiers.    //    Array<CIMQualifierDecl> qualifiers =                  _oldRepository->enumerateQualifiers(namespaceName);    Uint32 n = qualifiers.size();    for (Uint32 j=0 ; j<n ; j++)    {        try        {            // Check if the qualifier exists in the new repository.            CIMQualifierDecl qual =               _newRepository->getQualifier(namespaceName,                               qualifiers[j].getName());            if ( qual.getName() == qualifiers[j].getName() )            {                 // Qualifier already exists, do not create.                 continue;            }        }        catch (CIMException& ce)        {            //            // Check if the error returned was that the qualifier does not            // exist. If not propagate the error.            //            if (ce.getCode() != CIM_ERR_NOT_FOUND)            {                throw;            }        }        //        // Check if the qualifier has to be created. If true, use the        // processed qualifier. If an SSP Module have chosen to        // to ignore the qualifier then skip the qualifier creation.        //        CIMQualifierDecl processedQual = qualifiers[j].clone();#ifdef ENABLE_MODULE_PROCESSING        if (!_invokeModules (qualifiers[j], processedQual))        {#ifdef REPUPGRADE_DEBUG            cerr << "Ignoring qualifier creation : "                 << qualifiers[j].getName() << endl;#endif            continue;        }#endif        try        {#ifdef REPUPGRADE_DEBUG        cout << "Now creating qualifier :" << processedQual.getName()             << endl;#endif            _newRepository->setQualifier (namespaceName, processedQual);#ifdef REPUPGRADE_DEBUG        cout << "Qualifier created:" << processedQual.getName()             << endl;#endif        }        catch (Exception& e)        {            _logSetQualifierError (namespaceName,                                           qualifiers[j],                                           (e.getMessage()+". "));        }        catch (...)        {            _logSetQualifierError (namespaceName,                                           qualifiers[j],                                           String::EMPTY);        }    }}void RepositoryUpgrade::_addNamespaces(                         const Array<CIMNamespaceName>& namespaces){    Array<CIMName> 			oldClassNames;    Array<CIMName> 			newClassNames;    CIMName				className;    Uint32 count = namespaces.size();    for ( Uint32 i=0; i < count;  i++)    {#ifdef REPUPGRADE_DEBUG        cout << "Now creating namespace : " << namespaces[i] << endl;#endif        try        {            _newRepository->createNameSpace(namespaces[i]);        }        catch (Exception& e)        {            String message = localizeMessage (MSG_PATH,                               REPOSITORY_UPGRADE_FAILURE_KEY,                               REPOSITORY_UPGRADE_FAILURE) +                             e.getMessage() +                             localizeMessage (MSG_PATH,                               NAMESPACE_CREATION_ERROR_KEY,                               NAMESPACE_CREATION_ERROR,                               namespaces[i].getString());            throw RepositoryUpgradeException(message);        }        catch (...)        {            String message = localizeMessage (MSG_PATH,                               REPOSITORY_UPGRADE_FAILURE_KEY,                               REPOSITORY_UPGRADE_FAILURE) +                             localizeMessage (MSG_PATH,                               NAMESPACE_CREATION_ERROR_KEY,                               NAMESPACE_CREATION_ERROR,                               namespaces[i].getString());            throw RepositoryUpgradeException(message);        }        //        // 1. Add qualifiers        //        _addQualifiers (namespaces[i]);        //        // 2. Add classes        //        // Get classnames from old repository.        oldClassNames = _oldRepository->enumerateClassNames(                           namespaces[i],                           className,                           true);        if (oldClassNames.size() > 0)        {            _processNewClasses (namespaces[i],                            oldClassNames,                            newClassNames);        }        oldClassNames.clear();	newClassNames.clear();    }}void RepositoryUpgrade::_processClasses(                      const CIMNamespaceName& namespaceName,                      const Array<CIMName>&   oldClasses ,                      Array<CIMName>&   newClasses){    Array<CIMName>		missingClasses;    Array<CIMName>		existingClasses;    //    // Separate the existing and missing classes.    //    Uint32 oldCount = oldClasses.size();    Uint32 newCount = newClasses.size();    for ( Uint32 oldclasses = 0; oldclasses < oldCount ; oldclasses++)    {#ifdef REPUPGRADE_DEBUG        cout << "Checking for : " << oldClasses[oldclasses] << endl;#endif        if ( !Contains(newClasses, oldClasses[oldclasses]) )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -