void RpcConfigurator::getCurrentInitialSettings()

in host/config/rpcconfigurator.cpp [493:654]


void RpcConfigurator::getCurrentInitialSettings()
{
    InitialSettings CurrentCxSettings;

    bool initialsettingsChanged = false;
    bool hostVolumeSettingsChanged = false;
    bool prismSettingsChanged = false;
    bool ConfigurationChange = false;
    bool cdpSettingsChanged = false;
    std::string cachePath;
    LocalConfigurator::getConfigCachePathname(cachePath);
    if( !m_fileName.empty() )
    {
        cachePath = m_fileName ;
    }
    if(m_configSource == USE_ONLY_CACHE_SETTINGS)
    {
        // Retrieve the cached settings only when the file
        // config.dat is modified (to reduce disk i/o)

        time_t FetchedCacheTime;
        CurrentCxSettings = m_settings;

        ACE_stat stat = {0};
        ACE_OS::stat(cachePath.c_str(), &stat);
        FetchedCacheTime = stat.st_mtime;

        // Read cache settings when the fils is modified

        // Bug #9034
        // To take care when the system time moves backward

        if(FetchedCacheTime != m_lastTimeCacheUpdated)
        {
            CurrentCxSettings = getCachedInitialSettings(cachePath);
            m_lastTimeCacheUpdated = FetchedCacheTime;
        }
    }
    else if(m_configSource == FETCH_SETTINGS_FROM_CX
        || m_configSource == USE_CACHE_SETTINGS_IF_CX_NOT_AVAILABLE)
    {
        try
        {
            CurrentCxSettings = m_cx.getInitialSettings();
            m_lastTimeSettingsFetchedFromCx = ACE_OS::gettimeofday();
        }
        catch (ContextualException& e)
        {
          DebugPrintf(SV_LOG_ERROR, "Caught Exception:%s \n",e.what());
          if(m_configSource == USE_CACHE_SETTINGS_IF_CX_NOT_AVAILABLE)
          {
            CurrentCxSettings = getCachedInitialSettings(cachePath);
          }
          else
          {
            DebugPrintf(SV_LOG_ERROR,
              "Failed in retrieving current InitialSettings.\n");
            throw;
          }
        }
        catch ( ... )
        {
          DebugPrintf(SV_LOG_ERROR, "Caught unknown exception\n");
          if(m_configSource == USE_CACHE_SETTINGS_IF_CX_NOT_AVAILABLE)
          {
            CurrentCxSettings = getCachedInitialSettings(cachePath);
          }
          else
          {
            DebugPrintf(SV_LOG_ERROR,
              "Failed in retrieving current InitialSettings.\n");
            throw;
          }
        }
    }
    //15949: Retrieves the initial settings from the file provided.
    else if(m_configSource == USE_FILE_PROVIDED)
    {
        try
        {
            CurrentCxSettings = getInitialSettingsFromFile();
        }
        catch ( ... )
        {
            DebugPrintf(SV_LOG_ERROR, "Failed in retrieving "
                "current InitialSettings from the given file.\n");
            throw;
        }
    }

    if (!(m_settings == CurrentCxSettings) )
    {
        initialsettingsChanged = true;
        ConfigurationChange = true;
    }
    else if( !StrictCompare(m_settings, CurrentCxSettings) )
    {
        ConfigurationChange = true;
    }

    if (!(m_settings.hostVolumeSettings == CurrentCxSettings.hostVolumeSettings) )
    {
        hostVolumeSettingsChanged = true;
    }

    if (!(m_settings.prismSettings == CurrentCxSettings.prismSettings))
    {
        prismSettingsChanged = true;
    }

	if( !(m_settings.cdpSettings == CurrentCxSettings.cdpSettings) )
    {
        cdpSettingsChanged = true;
    }

    if(ConfigurationChange)
    {
        updateSettings(CurrentCxSettings);
    }


    // We fire all the appropriate signals after our state is updated
    if(ConfigurationChange)
    {
        m_ConfigurationChangeSignal( CurrentCxSettings );
    }

    if(initialsettingsChanged)
    {
        m_InitialSettingsSignal( CurrentCxSettings );
    }

    if(hostVolumeSettingsChanged)
    {
        m_HostVolumeGroupSettingsSignal( CurrentCxSettings.hostVolumeSettings );
    }

    if (prismSettingsChanged)
    {
        m_PrismSettingsSignal( CurrentCxSettings.prismSettings );
    }

	if (CurrentCxSettings.shouldRegisterOnDemand())
	{
		m_RegisterImmediatelySignal(CurrentCxSettings.getRequestIdForOnDemandRegistration(), 
                                    CurrentCxSettings.getDisksLayoutOption());
	}

    if (!IsAgentRunningOnAzureVm())
    {
        std::string currentCsAddrForAzComponents = CurrentCxSettings.getCsAddressForAzureComponents();
        if (!currentCsAddrForAzComponents.empty())
        {
            m_CsAddressForAzureComponentsChangeSignal(m_localConfigurator, currentCsAddrForAzComponents);
        }
    }

    if(cdpSettingsChanged)
    {
        m_CdpsettingsChangeSignal();
    }
}