public static RavenDriveConfiguration Get() { string containerName = RoleEnvironment.GetConfigurationSettingValue("Raven.Data.CloudContainerName"); string driveName = RoleEnvironment.GetConfigurationSettingValue("Raven.Data.CloudDriveName"); string driveSize = RoleEnvironment.GetConfigurationSettingValue("Raven.Data.CloudDriveSize"); string readCacheSize = RoleEnvironment.GetConfigurationSettingValue("Raven.Data.CloudDriveReadCacheSize"); int driveSizeValue; int readCacheSizeValue; if (string.IsNullOrWhiteSpace(containerName) || string.IsNullOrWhiteSpace(driveName) || !int.TryParse(driveSize, out driveSizeValue) || !int.TryParse(readCacheSize, out readCacheSizeValue)) { throw new ArgumentException("Raven drive settings were found, but some or all have empty/invalid values"); } var result = new RavenDriveConfiguration { CloudContainerName = containerName, CloudDriveName = driveName, CloudDriveReadCacheSize = readCacheSizeValue, CloudDriveSize = driveSizeValue }; return result; }
public override void OnStop() { try { Logger.Info("Raven stopping..."); try { Environment.SetEnvironmentVariable(RavenDriveConfiguration.AzureDriveEnvironmentVariableName, null, EnvironmentVariableTarget.Machine); if (!RoleEnvironment.IsEmulated) { var driveConfiguration = RavenDriveConfiguration.Get(); // Unmount to unlock the blob AzureCloudDrive.UnmountDrive(driveConfiguration.CloudContainerName, driveConfiguration.CloudDriveName); } } catch (Exception ex) { Logger.WarnException("Cloud drive couldn't be unmounted", ex); } _source.Cancel(true); base.OnStop(); } catch (Exception ex) { Logger.FatalException("Raven couldn't stop properly", ex); } }
public static RavenDriveConfiguration Get() { string containerName = RoleEnvironment.GetConfigurationSettingValue("Raven.Data.CloudContainerName"); string driveName = RoleEnvironment.GetConfigurationSettingValue("Raven.Data.CloudDriveName"); string driveSize = RoleEnvironment.GetConfigurationSettingValue("Raven.Data.CloudDriveSize"); string readCacheSize = RoleEnvironment.GetConfigurationSettingValue("Raven.Data.CloudDriveReadCacheSize"); int driveSizeValue; int readCacheSizeValue; if (string.IsNullOrWhiteSpace(containerName) || string.IsNullOrWhiteSpace(driveName) || !int.TryParse(driveSize, out driveSizeValue) || !int.TryParse(readCacheSize, out readCacheSizeValue)) { throw new ArgumentException("Raven drive settings were found, but some or all have empty/invalid values"); } var result = new RavenDriveConfiguration { CloudContainerName = containerName, CloudDriveName = driveName, CloudDriveReadCacheSize = readCacheSizeValue, CloudDriveSize = driveSizeValue }; return(result); }
public override bool OnStart() { Logger.Info("Raven starting..."); try { ValidateInstanceCount(); var driveConfiguration = RavenDriveConfiguration.Get(); string driveRoot; // In emulated environment Azure doesn't actually mount to drive letters and uses some hacky ways to redirect reads to location on disk if (!RoleEnvironment.IsEmulated) { // Allocate total read cache for all Azure drives to be mounted as part of this role (maximum cache size) // Provided value is the name of Local Storage from Azure's Role configuration AzureCloudDrive.PrepareLocalReadCache("CloudDriveLocalReadCache"); // Mount drive that will be stored in Container with certain blob Name, given drive size (in MB) and read cache size (subset of maximum cache size allocated above) driveRoot = AzureCloudDrive.MountDrive(driveConfiguration.CloudContainerName, driveConfiguration.CloudDriveName, driveConfiguration.CloudDriveSize, driveConfiguration.CloudDriveReadCacheSize); } else { // Use allocated read cache as if it was Azure drive driveRoot = RoleEnvironment.GetLocalResource("CloudDriveLocalReadCache").RootPath; } Environment.SetEnvironmentVariable(RavenDriveConfiguration.AzureDriveEnvironmentVariableName, driveRoot, EnvironmentVariableTarget.Machine); CloudIISConfiguration.Configure("Web", bindingWorksForAllUnassignedIPs: true); RoleEnvironment.Changed += RoleEnvironment_Changed; } catch (Exception e) { Logger.FatalException("Raven couldn't start properly", e); _startedProperly = false; } return(base.OnStart()); }