public static string Mount() { CloudStorageAccount storageAccount; if (RoleEnvironment.IsEmulated) { storageAccount = CloudStorageAccount.DevelopmentStorageAccount; } else { storageAccount = CloudStorageAccount.Parse(connectionString); } LocalResource localCache = RoleEnvironment.GetLocalResource("InstanceDriveCache"); CloudDrive.InitializeCache(localCache.RootPath, localCache.MaximumSizeInMegabytes); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); blobClient.GetContainerReference("drives").CreateIfNotExist(); myCloudDrive = storageAccount.CreateCloudDrive( blobClient .GetContainerReference("drives") .GetPageBlobReference("mysupercooldrive.vhd") .Uri.ToString() ); myCloudDrive.CreateIfNotExist(64); return myCloudDrive.Mount(25, DriveMountOptions.None); }
public static string Mount() { CloudStorageAccount storageAccount; if (RoleEnvironment.IsEmulated) { storageAccount = CloudStorageAccount.DevelopmentStorageAccount; } else { storageAccount = CloudStorageAccount.Parse(connectionString); } LocalResource localCache = RoleEnvironment.GetLocalResource("InstanceDriveCache"); CloudDrive.InitializeCache(localCache.RootPath, localCache.MaximumSizeInMegabytes); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); blobClient.GetContainerReference("drives").CreateIfNotExist(); myCloudDrive = storageAccount.CreateCloudDrive( blobClient .GetContainerReference("drives") .GetPageBlobReference("mysupercooldrive.vhd") .Uri.ToString() ); myCloudDrive.CreateIfNotExist(64); return(myCloudDrive.Mount(25, DriveMountOptions.None)); }
public override bool OnStart() { Trace.WriteLine("WebRole.OnStart", "Error"); CloudStorageAccount storageAccount; try { FUSE.Weld.Azure.Configuration.SetConfigurationSettingPublisher(); storageAccount = Utility.GetStorageAccount(); Trace.WriteLine("WebRole.OnStart: Initializing Cache","Verbose"); var localCache = RoleEnvironment.GetLocalResource("DriveCache"); CloudDrive.InitializeCache(localCache.RootPath, localCache.MaximumSizeInMegabytes); Trace.WriteLine("WebRole.OnStart: Creating Drive", "Verbose"); drive = new CloudDrive(new Uri(storageAccount.BlobEndpoint + "root/proxy.vhd"), storageAccount.Credentials); drive.CreateIfNotExist(10 * 1000); Trace.WriteLine("WebRole.OnStart: Mounting Drive", "Verbose"); var cloudDriveLetter = drive.Mount(localCache.MaximumSizeInMegabytes, DriveMountOptions.Force); } catch (Exception x) { Trace.TraceError("WebRole.OnStart:\n" + x.ToString()); } return base.OnStart(); }
public override bool OnStart() { Trace.WriteLine("WebRole.OnStart", "Error"); CloudStorageAccount storageAccount; try { FUSE.Weld.Azure.Configuration.SetConfigurationSettingPublisher(); storageAccount = Utility.GetStorageAccount(); Trace.WriteLine("WebRole.OnStart: Initializing Cache", "Verbose"); var localCache = RoleEnvironment.GetLocalResource("DriveCache"); CloudDrive.InitializeCache(localCache.RootPath, localCache.MaximumSizeInMegabytes); Trace.WriteLine("WebRole.OnStart: Creating Drive", "Verbose"); drive = new CloudDrive(new Uri(storageAccount.BlobEndpoint + "root/proxy.vhd"), storageAccount.Credentials); drive.CreateIfNotExist(10 * 1000); Trace.WriteLine("WebRole.OnStart: Mounting Drive", "Verbose"); var cloudDriveLetter = drive.Mount(localCache.MaximumSizeInMegabytes, DriveMountOptions.Force); } catch (Exception x) { Trace.TraceError("WebRole.OnStart:\n" + x.ToString()); } return(base.OnStart()); }
public void CreateDrive() { try { _cloudDrive = _account.CreateCloudDrive(_vhdName); _logger.Log("using account " + _account.BlobEndpoint + " to create " + _vhdName); var rv = _cloudDrive.CreateIfNotExist(DISK_SIZE); _logger.Log("done create drive"); } catch (Exception ex) { _logger.Log("error on CreateDrive", ex); } }
public string MountDrive(string storageConnectionString, string blobRelativePath, string localResourceName, int sizeInMb) { var account = CloudStorageAccount.FromConfigurationSetting(storageConnectionString.Replace("DefaultEndpointsProtocol=https", "DefaultEndpointsProtocol=http")); var blobUri = GetBlobUri(account, blobRelativePath); var localCache = _localResourceManager.GetByConfigName(localResourceName); CloudDrive.InitializeCache(localCache.RootPath, localCache.MaximumSizeInMegabytes); var drive = new CloudDrive(blobUri, account.Credentials); drive.CreateIfNotExist(sizeInMb); var driveRootPath = drive.Mount(localCache.MaximumSizeInMegabytes, DriveMountOptions.Force); return driveRootPath; }
private void OnInitialize() { var selfInstance = InstanceEnumerator.EnumerateInstances().First(i => i.IsSelf); cloudStorageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(ConfigurationSettingsKeys.StorageConnectionString)); log.Info("Storage account selected: {0}",cloudStorageAccount.BlobEndpoint); cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient(); log.Info("Storage client created"); var containerName = ConfigurationProvider.GetSetting(ConfigurationSettingsKeys.StorageContainerName,"ravendb"); // In order to force a connection we just enumerate all available containers: var availableContainers = cloudBlobClient.ListContainers().ToArray(); foreach (var container in availableContainers) { log.Info("Available container: {0}",container.Name); } if (!availableContainers.Any(c => c.Name.Equals(containerName))) { log.Info("Container {0} does not exist, creating",containerName); // Container does not exist: cloudBlobClient.GetContainerReference(containerName).Create(); } cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName); log.Info("Container {0} selected",cloudBlobContainer.Name); localCache = RoleEnvironment.GetLocalResource(ConfigurationSettingsKeys.StorageCacheResource); log.Info("Cache resource retrieved: {0}, path: {1}",localCache.Name,localCache.RootPath); CloudDrive.InitializeCache(localCache.RootPath, localCache.MaximumSizeInMegabytes); log.Info("Cache initialized: {0} mb",localCache.MaximumSizeInMegabytes); var driveName = string.Format("{0}{1}.vhd", selfInstance.InstanceType, selfInstance.InstanceIndex).ToLowerInvariant(); log.Info("Virtual drive name: {0}",driveName); var pageBlob = cloudBlobContainer.GetPageBlobReference(driveName); log.Info("Virtual drive blob: {0}",pageBlob.Uri); cloudDrive = cloudStorageAccount.CreateCloudDrive(pageBlob.Uri.ToString()); log.Info("Virtual drive created: {0}",cloudDrive.Uri); var storageSize = ConfigurationProvider.GetSetting(ConfigurationSettingsKeys.StorageSize, 50000); log.Info("Storage size: {0} mb",storageSize); cloudDrive.CreateIfNotExist(storageSize); log.Info("Virtual drive initialized: {0}",cloudDrive.Uri); var mountedDirectoryPath = cloudDrive.Mount(storageSize, DriveMountOptions.None); log.Info("Virtual drive mounted at: {0}",mountedDirectoryPath); mountedDirectory = new DirectoryInfo(mountedDirectoryPath); log.Info("Ensuring drive is available: {0}",mountedDirectoryPath); UpdateTestFile(); log.Info("Storage initialization succeeded"); }
private void MountCloudDrive() { Trace.TraceInformation("Cloud Drive: Mounting..."); CloudStorageAccount storageAccount = CloudStorageAccount.FromConfigurationSetting("StorageAccount"); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); LocalResource localCache = RoleEnvironment.GetLocalResource("RavenCache"); CloudDrive.InitializeCache(localCache.RootPath.TrimEnd('\\'), localCache.MaximumSizeInMegabytes); var containerName = RoleEnvironment.GetConfigurationSettingValue("CloudDriveContainer"); Trace.TraceInformation("Cloud Drive: Container = {0}", containerName); blobClient.GetContainerReference(containerName).CreateIfNotExist(); var vhdName = RoleEnvironment.CurrentRoleInstance.Id + ".vhd"; Trace.TraceInformation("Cloud Drive: VHD = {0}", vhdName); var vhdUrl = blobClient.GetContainerReference(containerName).GetPageBlobReference(vhdName).Uri.ToString(); _dataDrive = storageAccount.CreateCloudDrive(vhdUrl); _dataDrive.CreateIfNotExist(localCache.MaximumSizeInMegabytes); var localPath = _dataDrive.Mount(localCache.MaximumSizeInMegabytes, DriveMountOptions.Force); Trace.TraceInformation("Cloud Drive mounted to {0}", localPath); }
internal static string GetMountedPathFromBlob( string localCachePath, string cloudDir, string containerName, string blobName, int driveSize, out CloudDrive mongoDrive) { DiagnosticsHelper.TraceInformation( "In mounting cloud drive for dir {0} on {1} with {2}", cloudDir, containerName, blobName); CloudStorageAccount storageAccount = CloudStorageAccount.FromConfigurationSetting(cloudDir); var blobClient = storageAccount.CreateCloudBlobClient(); DiagnosticsHelper.TraceInformation("Get container"); // this should be the name of your replset var driveContainer = blobClient.GetContainerReference(containerName); // create blob container (it has to exist before creating the cloud drive) try { driveContainer.CreateIfNotExist(); } catch (StorageException e) { DiagnosticsHelper.TraceInformation( "Container creation failed with {0} {1}", e.Message, e.StackTrace); } var mongoBlobUri = blobClient.GetContainerReference(containerName).GetPageBlobReference(blobName).Uri.ToString(); DiagnosticsHelper.TraceInformation("Blob uri obtained {0}", mongoBlobUri); // create the cloud drive mongoDrive = storageAccount.CreateCloudDrive(mongoBlobUri); try { mongoDrive.CreateIfNotExist(driveSize); } catch (CloudDriveException e) { DiagnosticsHelper.TraceInformation( "Drive creation failed with {0} {1}", e.Message, e.StackTrace); } DiagnosticsHelper.TraceInformation("Initialize cache"); var localStorage = RoleEnvironment.GetLocalResource(localCachePath); CloudDrive.InitializeCache(localStorage.RootPath.TrimEnd('\\'), localStorage.MaximumSizeInMegabytes); // mount the drive and get the root path of the drive it's mounted as try { DiagnosticsHelper.TraceInformation( "Trying to mount blob as azure drive"); var driveLetter = mongoDrive.Mount(localStorage.MaximumSizeInMegabytes, DriveMountOptions.None); DiagnosticsHelper.TraceInformation( "Write lock acquired on azure drive, mounted as {0}", driveLetter); return driveLetter; } catch (CloudDriveException e) { DiagnosticsHelper.TraceCritical( "Failed to mount cloud drive with {0} {1}", e.Message, e.StackTrace); throw; } }
public void CreateDriveEx() { try { CloudBlobClient client = _account.CreateCloudBlobClient(); // Create the container for the drive if it does not already exist. CloudBlobContainer container = new CloudBlobContainer("mydrives", client); container.CreateIfNotExist(); // Get a reference to the page blob that will back the drive. CloudPageBlob pageBlob = container.GetPageBlobReference(_vhdName); _cloudDrive = new CloudDrive(pageBlob.Uri, _account.Credentials); //_cloudDrive = _account.CreateCloudDrive(_vhdName); _logger.Log("using account " + _account.BlobEndpoint + " to create " + _vhdName); var rv = _cloudDrive.CreateIfNotExist(DISK_SIZE); _logger.Log("done create drive"); } catch (Exception ex) { _logger.Log("error on CreateDrive", ex); } }
internal static string GetMountedPathFromBlob( string localCachePath, string containerName, string blobName, int driveSize, out CloudDrive elasticDrive) { DiagnosticsHelper.TraceInformation( "In mounting cloud drive for on {0} with {1}", containerName, blobName); var connectionString = RoleEnvironment.GetConfigurationSettingValue("DataConnectionString"); connectionString = connectionString.Replace("DefaultEndpointsProtocol=https", "DefaultEndpointsProtocol=http"); var storageAccount = CloudStorageAccount.Parse(connectionString); var blobClient = storageAccount.CreateCloudBlobClient(); DiagnosticsHelper.TraceInformation("Get container"); // this should be the name of your replset var driveContainer = blobClient.GetContainerReference(containerName); // create blob container (it has to exist before creating the cloud drive) try { driveContainer.CreateIfNotExist(); } catch (StorageException e) { DiagnosticsHelper.TraceInformation( "Container creation failed with {0} {1}", e.Message, e.StackTrace); } var blobUri = blobClient.GetContainerReference(containerName).GetPageBlobReference(blobName).Uri.ToString(); DiagnosticsHelper.TraceInformation("Blob uri obtained {0}", blobUri); // create the cloud drive elasticDrive = storageAccount.CreateCloudDrive(blobUri); try { elasticDrive.CreateIfNotExist(driveSize); } catch (CloudDriveException e) { DiagnosticsHelper.TraceInformation( "Drive creation failed with {0} {1}", e.Message, e.StackTrace); } DiagnosticsHelper.TraceInformation("Initialize cache"); var localStorage = RoleEnvironment.GetLocalResource(localCachePath); CloudDrive.InitializeCache(localStorage.RootPath.TrimEnd('\\'), localStorage.MaximumSizeInMegabytes); // mount the drive and get the root path of the drive it's mounted as try { DiagnosticsHelper.TraceInformation( "Trying to mount blob as azure drive"); var driveLetter = elasticDrive.Mount(localStorage.MaximumSizeInMegabytes, DriveMountOptions.None); DiagnosticsHelper.TraceInformation( "Write lock acquired on azure drive, mounted as {0}", driveLetter); return driveLetter; } catch (CloudDriveException e) { DiagnosticsHelper.TraceCritical( "Failed to mount cloud drive with {0} {1}", e.Message, e.StackTrace); throw; } }
private void OnInitialize() { var selfInstance = InstanceEnumerator.EnumerateInstances().First(i => i.IsSelf); cloudStorageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(ConfigurationSettingsKeys.StorageConnectionString)); log.Info("Storage account selected: {0}", cloudStorageAccount.BlobEndpoint); cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient(); log.Info("Storage client created"); var containerName = ConfigurationProvider.GetSetting(ConfigurationSettingsKeys.StorageContainerName, "ravendb"); // In order to force a connection we just enumerate all available containers: var availableContainers = cloudBlobClient.ListContainers().ToArray(); foreach (var container in availableContainers) { log.Info("Available container: {0}", container.Name); } if (!availableContainers.Any(c => c.Name.Equals(containerName))) { log.Info("Container {0} does not exist, creating", containerName); // Container does not exist: cloudBlobClient.GetContainerReference(containerName).Create(); } cloudBlobContainer = cloudBlobClient.GetContainerReference(containerName); log.Info("Container {0} selected", cloudBlobContainer.Name); localCache = RoleEnvironment.GetLocalResource(ConfigurationSettingsKeys.StorageCacheResource); log.Info("Cache resource retrieved: {0}, path: {1}", localCache.Name, localCache.RootPath); CloudDrive.InitializeCache(localCache.RootPath, localCache.MaximumSizeInMegabytes); log.Info("Cache initialized: {0} mb", localCache.MaximumSizeInMegabytes); var driveName = string.Format("{0}{1}.vhd", selfInstance.InstanceType, selfInstance.InstanceIndex).ToLowerInvariant(); log.Info("Virtual drive name: {0}", driveName); var pageBlob = cloudBlobContainer.GetPageBlobReference(driveName); log.Info("Virtual drive blob: {0}", pageBlob.Uri); cloudDrive = cloudStorageAccount.CreateCloudDrive(pageBlob.Uri.ToString()); log.Info("Virtual drive created: {0}", cloudDrive.Uri); var storageSize = ConfigurationProvider.GetSetting(ConfigurationSettingsKeys.StorageSize, 50000); log.Info("Storage size: {0} mb", storageSize); cloudDrive.CreateIfNotExist(storageSize); log.Info("Virtual drive initialized: {0}", cloudDrive.Uri); var mountedDirectoryPath = cloudDrive.Mount(storageSize, DriveMountOptions.None); log.Info("Virtual drive mounted at: {0}", mountedDirectoryPath); mountedDirectory = new DirectoryInfo(mountedDirectoryPath); log.Info("Ensuring drive is available: {0}", mountedDirectoryPath); UpdateTestFile(); log.Info("Storage initialization succeeded"); }
private void MountCloudDrive() { Trace.TraceInformation("Cloud Drive: Mounting..."); CloudStorageAccount storageAccount = CloudStorageAccount.FromConfigurationSetting("StorageAccount"); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); LocalResource localCache = RoleEnvironment.GetLocalResource("RavenCache"); CloudDrive.InitializeCache(localCache.RootPath.TrimEnd('\\'), localCache.MaximumSizeInMegabytes); var containerName = RoleEnvironment.GetConfigurationSettingValue("CloudDriveContainer"); Trace.TraceInformation("Cloud Drive: Container = {0}", containerName); blobClient.GetContainerReference(containerName).CreateIfNotExist(); var vhdName = RoleEnvironment.CurrentRoleInstance.Id.Replace(RoleEnvironment.DeploymentId + ".", "") + ".ravendata.vhd"; Trace.TraceInformation("Cloud Drive: VHD = {0}", vhdName); var indexvhdName = RoleEnvironment.CurrentRoleInstance.Id.Replace(RoleEnvironment.DeploymentId + ".", "") + ".ravenindex.vhd"; Trace.TraceInformation("Cloud Drive: VHD = {0}", indexvhdName); var vhdUrl = blobClient.GetContainerReference(containerName).GetPageBlobReference(vhdName).Uri.ToString(); _dataDrive = storageAccount.CreateCloudDrive(vhdUrl); _dataDrive.CreateIfNotExist(localCache.MaximumSizeInMegabytes); // TODO Size var indexvhdUrl = blobClient.GetContainerReference(containerName).GetPageBlobReference(indexvhdName).Uri.ToString(); _indexDrive = storageAccount.CreateCloudDrive(indexvhdUrl); _indexDrive.CreateIfNotExist(localCache.MaximumSizeInMegabytes); //TODO Size var localPath = _dataDrive.Mount(localCache.MaximumSizeInMegabytes / 2, DriveMountOptions.Force); Trace.TraceInformation("Cloud Drive mounted to {0}", localPath); var indexPath = _indexDrive.Mount(localCache.MaximumSizeInMegabytes / 2, DriveMountOptions.Force); Trace.TraceInformation("Cloud Drive mounted to {0}", indexPath); var dataPath = _dataDrive.LocalPath.EndsWith("\\") ? _dataDrive.LocalPath + "Data" : _dataDrive.LocalPath + "\\Data"; if (!System.IO.Directory.Exists(dataPath)) System.IO.Directory.CreateDirectory(dataPath); var indexFullPath = _indexDrive.LocalPath.EndsWith("\\") ? _indexDrive.LocalPath + "Index" : _indexDrive.LocalPath + "\\Index"; if (!System.IO.Directory.Exists(indexFullPath)) System.IO.Directory.CreateDirectory(indexFullPath); }
private string GetMountedPathFromBlob( string localCachePath, string cloudDir, string containerName, string blobName, int driveSize, bool waitOnMount, out CloudDrive bermudaDrive) { Trace.TraceInformation(string.Format("In mounting cloud drive for dir {0}", cloudDir)); var storageAccount = CloudStorageAccount; var blobClient = CloudBlobClient; Trace.TraceInformation("Get container"); var driveContainer = blobClient.GetContainerReference(containerName); // create blob container (it has to exist before creating the cloud drive) try { driveContainer.CreateIfNotExist(); } catch (Exception e) { Trace.TraceInformation("Exception when creating container"); Trace.TraceInformation(e.Message); Trace.TraceInformation(e.StackTrace); } var bermudaBlobUri = blobClient.GetContainerReference(containerName).GetPageBlobReference(blobName).Uri.ToString(); Trace.TraceInformation(string.Format("Blob uri obtained {0}", bermudaBlobUri)); // create the cloud drive bermudaDrive = storageAccount.CreateCloudDrive(bermudaBlobUri); try { bermudaDrive.CreateIfNotExist(driveSize); } catch (Exception e) { // exception is thrown if all is well but the drive already exists Trace.TraceInformation("Exception when creating cloud drive. safe to ignore"); Trace.TraceInformation(e.Message); Trace.TraceInformation(e.StackTrace); } //Trace.TraceInformation("Initialize cache"); //var localStorage = RoleEnvironment.GetLocalResource(localCachePath); //CloudDrive.InitializeCache(localStorage.RootPath.TrimEnd('\\'), // localStorage.MaximumSizeInMegabytes); // mount the drive and get the root path of the drive it's mounted as if (!waitOnMount) { try { Trace.TraceInformation(string.Format("Trying to mount blob as azure drive on {0}", RoleEnvironment.CurrentRoleInstance.Id)); var driveLetter = bermudaDrive.Mount(0, DriveMountOptions.None); Trace.TraceInformation(string.Format("Write lock acquired on azure drive, mounted as {0}, on role instance", driveLetter, RoleEnvironment.CurrentRoleInstance.Id)); return driveLetter; } catch (Exception e) { Trace.TraceWarning("could not acquire blob lock."); Trace.TraceWarning(e.Message); Trace.TraceWarning(e.StackTrace); throw; } } else { string driveLetter; Trace.TraceInformation(string.Format("Trying to mount blob as azure drive on {0}", RoleEnvironment.CurrentRoleInstance.Id)); while (true) { try { driveLetter = bermudaDrive.Mount(0,DriveMountOptions.None); Trace.TraceInformation(string.Format("Write lock acquired on azure drive, mounted as {0}, on role instance", driveLetter, RoleEnvironment.CurrentRoleInstance.Id)); return driveLetter; } catch { } Thread.Sleep(MountSleep); } } }
private string GetMountedPathFromBlob( string localCachePath, string cloudDir, string containerName, string blobName, int driveSize, bool waitOnMount, out CloudDrive bermudaDrive) { Trace.TraceInformation(string.Format("In mounting cloud drive for dir {0}", cloudDir)); var storageAccount = CloudStorageAccount; var blobClient = CloudBlobClient; Trace.TraceInformation("Get container"); var driveContainer = blobClient.GetContainerReference(containerName); // create blob container (it has to exist before creating the cloud drive) try { driveContainer.CreateIfNotExist(); } catch (Exception e) { Trace.TraceInformation("Exception when creating container"); Trace.TraceInformation(e.Message); Trace.TraceInformation(e.StackTrace); } var bermudaBlobUri = blobClient.GetContainerReference(containerName).GetPageBlobReference(blobName).Uri.ToString(); Trace.TraceInformation(string.Format("Blob uri obtained {0}", bermudaBlobUri)); // create the cloud drive bermudaDrive = storageAccount.CreateCloudDrive(bermudaBlobUri); try { bermudaDrive.CreateIfNotExist(driveSize); } catch (Exception e) { // exception is thrown if all is well but the drive already exists Trace.TraceInformation("Exception when creating cloud drive. safe to ignore"); Trace.TraceInformation(e.Message); Trace.TraceInformation(e.StackTrace); } //Trace.TraceInformation("Initialize cache"); //var localStorage = RoleEnvironment.GetLocalResource(localCachePath); //CloudDrive.InitializeCache(localStorage.RootPath.TrimEnd('\\'), // localStorage.MaximumSizeInMegabytes); // mount the drive and get the root path of the drive it's mounted as if (!waitOnMount) { try { Trace.TraceInformation(string.Format("Trying to mount blob as azure drive on {0}", RoleEnvironment.CurrentRoleInstance.Id)); var driveLetter = bermudaDrive.Mount(0, DriveMountOptions.None); Trace.TraceInformation(string.Format("Write lock acquired on azure drive, mounted as {0}, on role instance", driveLetter, RoleEnvironment.CurrentRoleInstance.Id)); return(driveLetter); } catch (Exception e) { Trace.TraceWarning("could not acquire blob lock."); Trace.TraceWarning(e.Message); Trace.TraceWarning(e.StackTrace); throw; } } else { string driveLetter; Trace.TraceInformation(string.Format("Trying to mount blob as azure drive on {0}", RoleEnvironment.CurrentRoleInstance.Id)); while (true) { try { driveLetter = bermudaDrive.Mount(0, DriveMountOptions.None); Trace.TraceInformation(string.Format("Write lock acquired on azure drive, mounted as {0}, on role instance", driveLetter, RoleEnvironment.CurrentRoleInstance.Id)); return(driveLetter); } catch { } Thread.Sleep(MountSleep); } } }
private string MountDrive(string localCacheName, string blobName) { //Trace.TraceInformation("MountDrive - Creating drive " + blobName); string path = ""; try { // Get the local cache for the cloud drive LocalResource localCache = RoleEnvironment.GetLocalResource(localCacheName); // we'll use all the cache space we can (note: InitializeCache doesn't work with trailing slash) CloudDrive.InitializeCache(localCache.RootPath.TrimEnd('\\'), localCache.MaximumSizeInMegabytes); // the container that our dive is going to live in CloudBlobContainer drives = blobClient.GetContainerReference(RoleEnvironment.GetConfigurationSettingValue("ContainerName")); // create blob container (it has to exist before creating the cloud drive) try { drives.CreateIfNotExist(); } catch (Exception driveEx) { if (IsVerbose) Trace.TraceInformation(driveEx.ToString()); } // get the url to the vhd page blob we'll be using var blob = blobClient.GetContainerReference(RoleEnvironment.GetConfigurationSettingValue("ContainerName")).GetPageBlobReference(blobName); var vhdUrl = blob.Uri.ToString(); mongoDrive = storageAccount.CreateCloudDrive(vhdUrl); try { if (mongoDrive.CreateIfNotExist(localCache.MaximumSizeInMegabytes)) { //mongoDrive.Create(localCache.MaximumSizeInMegabytes); Trace.TraceInformation("MountDrive - Drive created"); } } catch (CloudDriveException cloudEx) { // this exception can be thrown if the drive already exists if (IsVerbose) Trace.TraceInformation(cloudEx.Message); } path = mongoDrive.Mount(0, DriveMountOptions.None) + @"\"; try { if (!path.ToLower().Contains("m:")) { char letter = path.Split(':')[0].First(); Trace.TraceInformation("Azure Drive is mounted on {0}, will run diskpart to mount it on M:", letter); MongoDriverHelper.RunDiskPart('M', letter); } } catch (Exception ex) { Trace.TraceError("Error in diskpart failed for {0}\r\n{1}" + path, ex); return string.Empty; } } catch (Exception exception) { if (IsVerbose) { Trace.TraceError("MountDrive Exception : " + exception.ToString()); } return string.Empty; } return path; }