Ejemplo n.º 1
0
        /// <summary>
        /// Init with a storage account
        /// </summary>
        /// <param name="account">Cloud Storage Account</param>
        public static ElasticsearchServiceSettings FromStorage(CloudStorageAccount account)
        {
            var settings = new ElasticsearchServiceSettings()
            {
                _StorageAccount               = account,
                _NodeName                     = RoleEnvironment.CurrentRoleInstance.Id,
                _UseElasticLocalDataFolder    = CloudConfigurationManager.GetSetting("UseElasticLocalDataFolder"),
                _JavaInstaller                = CloudConfigurationManager.GetSetting("JavaInstallerName"),
                _JavaDownloadURL              = CloudConfigurationManager.GetSetting("JavaDownloadURL"),
                _JavaDownloadType             = CloudConfigurationManager.GetSetting("JavaDownloadType"),
                _ElasticsearchInstaller       = CloudConfigurationManager.GetSetting("ElasticsearchZip"),
                _ElasticsearchDownloadURL     = CloudConfigurationManager.GetSetting("ElasticsearchDownloadURL"),
                _ElasticsearchDownloadType    = CloudConfigurationManager.GetSetting("ElasticsearchDownloadType"),
                _ElasticsearchPluginContainer = CloudConfigurationManager.GetSetting("ElasticsearchPluginContainer"),
                _DataShareName                = CloudConfigurationManager.GetSetting("ShareName"),
                _DataShareDrive               = CloudConfigurationManager.GetSetting("ShareDrive"),
                _EndpointName                 = CloudConfigurationManager.GetSetting("EndpointName"),
                _DownloadDirectory            = RoleEnvironment.GetLocalResource("ArchiveRoot").RootPath,
                _LogDirectory                 = RoleEnvironment.GetLocalResource("LogRoot").RootPath,
                _DataDirectory                = RoleEnvironment.GetLocalResource("ElasticDataRoot").RootPath,
                _ElasticsearchDirectory       = RoleEnvironment.GetLocalResource("ElasticRoot").RootPath,
                _RootDirectory                = Environment.GetEnvironmentVariable("ROLEROOT"),
                _TempDirectory                = RoleEnvironment.GetLocalResource("CustomTempRoot").RootPath,
                _DataBootstrapDirectory       = RoleEnvironment.GetLocalResource("DataBootstrapDirectory").RootPath,
            };

            bool.TryParse(CloudConfigurationManager.GetSetting("EnableDataBootstrap"), out settings._EnableDataBootstrap);

            if (string.IsNullOrWhiteSpace(settings._DataBootstrapDirectory) && settings._EnableDataBootstrap)
            {
                settings._EnableDataBootstrap = false;
            }


            if (!settings._RootDirectory.EndsWith(@"\"))
            {
                settings._RootDirectory += @"\";
            }

            //Set root to approot=App directory
            settings._RootDirectory = Path.Combine(settings._RootDirectory, "approot");

            //Emulator does not copy webrole files to approot
            if (RoleEnvironment.IsEmulated && IsWebRole)
            {
                settings._RootDirectory = Path.Combine(settings._RootDirectory, "bin");
            }

            //Calculate heap size
            MEMORYSTATUSEX memoryStatus = new MEMORYSTATUSEX();

            GlobalMemoryStatusEx(memoryStatus);

            var totalPhycialBytesInMB = memoryStatus.ullTotalPhys / 1024L / 1024L;

            //TODO: calculate the lost result which could cause this to throw;
            settings._ComputedHeapSize = Convert.ToInt32(totalPhycialBytesInMB / 2);

            return(settings);
        }
        /// <summary>
        /// Init with a storage account
        /// </summary>
        /// <param name="account">Cloud Storage Account</param>
        public static ElasticsearchServiceSettings FromStorage(CloudStorageAccount account)
        {
            var settings = new ElasticsearchServiceSettings()
            {
                _StorageAccount = account,
                _NodeName = RoleEnvironment.CurrentRoleInstance.Id,
                _UseElasticLocalDataFolder = CloudConfigurationManager.GetSetting("UseElasticLocalDataFolder"),
                _JavaInstaller = CloudConfigurationManager.GetSetting("JavaInstallerName"),
                _JavaDownloadURL = CloudConfigurationManager.GetSetting("JavaDownloadURL"),
                _JavaDownloadType = CloudConfigurationManager.GetSetting("JavaDownloadType"),
                _ElasticsearchInstaller = CloudConfigurationManager.GetSetting("ElasticsearchZip"),
                _ElasticsearchDownloadURL = CloudConfigurationManager.GetSetting("ElasticsearchDownloadURL"),
                _ElasticsearchDownloadType = CloudConfigurationManager.GetSetting("ElasticsearchDownloadType"),
                _ElasticsearchPluginContainer = CloudConfigurationManager.GetSetting("ElasticsearchPluginContainer"),
                _DataShareName = CloudConfigurationManager.GetSetting("ShareName"),
                _DataShareDrive = CloudConfigurationManager.GetSetting("ShareDrive"),
                _EndpointName = CloudConfigurationManager.GetSetting("EndpointName"),
                _DownloadDirectory = RoleEnvironment.GetLocalResource("ArchiveRoot").RootPath,
                _LogDirectory = RoleEnvironment.GetLocalResource("LogRoot").RootPath,
                _DataDirectory = RoleEnvironment.GetLocalResource("ElasticDataRoot").RootPath,
                _ElasticsearchDirectory = RoleEnvironment.GetLocalResource("ElasticRoot").RootPath,
                _RootDirectory = Environment.GetEnvironmentVariable("ROLEROOT"),
                _TempDirectory = RoleEnvironment.GetLocalResource("CustomTempRoot").RootPath,
                _DataBootstrapDirectory = RoleEnvironment.GetLocalResource("DataBootstrapDirectory").RootPath,

            };

            bool.TryParse(CloudConfigurationManager.GetSetting("EnableDataBootstrap"), out settings._EnableDataBootstrap);

            if (string.IsNullOrWhiteSpace(settings._DataBootstrapDirectory) && settings._EnableDataBootstrap)
            {
                settings._EnableDataBootstrap = false;
            }

            if (!settings._RootDirectory.EndsWith(@"\"))
            {
                settings._RootDirectory += @"\";
            }

            //Set root to approot=App directory
            settings._RootDirectory = Path.Combine(settings._RootDirectory, "approot");

            //Emulator does not copy webrole files to approot
            if (RoleEnvironment.IsEmulated && IsWebRole)
            {
                settings._RootDirectory = Path.Combine(settings._RootDirectory, "bin");
            }

            //Calculate heap size
            MEMORYSTATUSEX memoryStatus = new MEMORYSTATUSEX();
            GlobalMemoryStatusEx(memoryStatus);

            var totalPhycialBytesInMB = memoryStatus.ullTotalPhys / 1024L / 1024L;

            //TODO: calculate the lost result which could cause this to throw;
            settings._ComputedHeapSize = Convert.ToInt32(totalPhycialBytesInMB / 2);

            return settings;
        }