コード例 #1
0
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterOpenAuth();

            if (imageStorePath == null)
            {
                ImageStorePath = WebConfigurationManager.AppSettings["ImageStorePath"];
            }

            // initialize storage account configuration setting publisher
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                string connectionString = RoleEnvironment.GetConfigurationSettingValue(configName);
                configSetter(connectionString);
            });

            try
            {
                // initialize the local cache for the Azure drive
                LocalResource cache = RoleEnvironment.GetLocalResource("LocalDriveCache");
                CloudDrive.InitializeCache(cache.RootPath + "cache", cache.MaximumSizeInMegabytes);

                // retrieve storage account 
                CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

                // retrieve URI for the page blob that contains the cloud drive from configuration settings 
                string imageStoreBlobUri = RoleEnvironment.GetConfigurationSettingValue("ImageStoreBlobUri");
                
				// unmount any previously mounted drive.
				foreach (var drive in CloudDrive.GetMountedDrives())
				{
					var mountedDrive = new CloudDrive(drive.Value, account.Credentials);
					mountedDrive.Unmount();
				}
		
                // create the Windows Azure drive and its associated page blob
                CloudDrive imageStoreDrive = account.CreateCloudDrive(imageStoreBlobUri);

                if (CloudDrive.GetMountedDrives().Count == 0)
                {                  
                    try
                    {
                        imageStoreDrive.Create(16);
                    }
                    catch (CloudDriveException)
                    {
                        // drive already exists
                    }
                }

                // mount the drive and initialize the application with the path to the image store on the Azure drive
                Global.ImageStorePath = imageStoreDrive.Mount(cache.MaximumSizeInMegabytes / 2, DriveMountOptions.None);
            }
            catch (CloudDriveException driveException)
            {
                Trace.WriteLine("Error: " + driveException.Message);
            }
        }
コード例 #2
0
        public override void OnStop()
        {
            Log("SolrSlaveHostWorkerRole OnStop() called", "Information");

            if (_solrProcess != null)
            {
                try
                {
                    _solrProcess.Kill();
                    _solrProcess.WaitForExit(2000);
                }
                catch { }
            }

            if (_solrStorageDrive != null)
            {
                try
                {
                    _solrStorageDrive.Unmount();
                }
                catch { }
            }

            base.OnStop();
        }
コード例 #3
0
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterOpenAuth();

            if (imageStorePath == null)
            {
                ImageStorePath = WebConfigurationManager.AppSettings["ImageStorePath"];
            }

            // initialize storage account configuration setting publisher
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                string connectionString = RoleEnvironment.GetConfigurationSettingValue(configName);
                configSetter(connectionString);
            });

            try
            {
                // initialize the local cache for the Azure drive
                LocalResource cache = RoleEnvironment.GetLocalResource("LocalDriveCache");
                CloudDrive.InitializeCache(cache.RootPath + "cache", cache.MaximumSizeInMegabytes);

                // retrieve storage account
                CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

                // retrieve URI for the page blob that contains the cloud drive from configuration settings
                string imageStoreBlobUri = RoleEnvironment.GetConfigurationSettingValue("ImageStoreBlobUri");

                // unmount any previously mounted drive.
                foreach (var drive in CloudDrive.GetMountedDrives())
                {
                    var mountedDrive = new CloudDrive(drive.Value, account.Credentials);
                    mountedDrive.Unmount();
                }

                // create the Windows Azure drive and its associated page blob
                CloudDrive imageStoreDrive = account.CreateCloudDrive(imageStoreBlobUri);

                if (CloudDrive.GetMountedDrives().Count == 0)
                {
                    try
                    {
                        imageStoreDrive.Create(16);
                    }
                    catch (CloudDriveException)
                    {
                        // drive already exists
                    }
                }

                // mount the drive and initialize the application with the path to the image store on the Azure drive
                Global.ImageStorePath = imageStoreDrive.Mount(cache.MaximumSizeInMegabytes / 2, DriveMountOptions.None);
            }
            catch (CloudDriveException driveException)
            {
                Trace.WriteLine("Error: " + driveException.Message);
            }
        }
コード例 #4
0
        public override void OnStop()
        {
            DiagnosticsHelper.TraceInformation("MongoWorkerRole onstop called");
            try
            {
                // should we instead call Process.stop?
                if ((mongodProcess != null) &&
                    !(mongodProcess.HasExited))
                {
                    DatabaseHelper.StepdownIfNeeded(mongodPort);
                }
            }
            catch (Exception e)
            {
                //Ignore exceptions caught on unmount
                DiagnosticsHelper.TraceWarning("Exception in onstop - stepdown failed");
                DiagnosticsHelper.TraceWarning(e.Message);
                DiagnosticsHelper.TraceWarning(e.StackTrace);
            }

            try
            {
                // should we instead call Process.stop?
                DiagnosticsHelper.TraceInformation("Shutdown called on mongod");
                if ((mongodProcess != null) &&
                    !(mongodProcess.HasExited))
                {
                    ShutdownMongo();
                }
                DiagnosticsHelper.TraceInformation("Shutdown completed on mongod");
            }
            catch (Exception e)
            {
                //Ignore exceptions caught on unmount
                DiagnosticsHelper.TraceWarning("Exception in onstop - mongo shutdown");
                DiagnosticsHelper.TraceWarning(e.Message);
                DiagnosticsHelper.TraceWarning(e.StackTrace);
            }

            try
            {
                DiagnosticsHelper.TraceInformation("Unmount called on data drive");
                if (mongoDataDrive != null)
                {
                    mongoDataDrive.Unmount();
                }
                DiagnosticsHelper.TraceInformation("Unmount completed on data drive");
            }
            catch (Exception e)
            {
                //Ignore exceptions caught on unmount
                DiagnosticsHelper.TraceWarning("Exception in onstop - unmount of data drive");
                DiagnosticsHelper.TraceWarning(e.Message);
                DiagnosticsHelper.TraceWarning(e.StackTrace);
            }

            DiagnosticsHelper.TraceInformation("Calling diagnostics shutdown");
            // DiagnosticsHelper.ShutdownDiagnostics();
            base.OnStop();
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: smonteil/azuremongospare
        static void Main(string[] args)
        {
            try
            {

                string BlobURL = "deploy/Testdrivesnapshot.vhd";

                CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=http;AccountName=mongodbwest2;AccountKey=wZcR60wAy+zltHPV7CXJsvBo/rnZHV2FIqg+UA+H1pIhkYl4j0qRZ+GgI5V8IJhngh2DOxI+sS46KddPFWg0Xw==");
                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

                //Get a reference to a blob.
                CloudBlob blob = blobClient.GetBlobReference(BlobURL);

                //Take a snapshot of the blob.
                CloudBlob snapshot = blob.CreateSnapshot();

                //Get the snapshot timestamp.
                DateTime timestamp = (DateTime)snapshot.Attributes.Snapshot;

                //Use the timestamp to get a second reference to the snapshot.
                CloudBlob snapshot2 = new CloudBlob(BlobURL, timestamp, blobClient);

                CloudDrive Snapshotdrive = new CloudDrive(snapshot2.Uri, storageAccount.Credentials);
                string path = Snapshotdrive.Mount(0, DriveMountOptions.None);

                Console.WriteLine("Mounted on " + path);
                Console.ReadLine();

                Snapshotdrive.Unmount();
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format("Exception : {0} ({1}) at {2}", ex.Message, ex.InnerException == null ? "" : ex.InnerException.Message, ex.StackTrace));
            }
        }
コード例 #6
0
        public override void OnStop()
        {
            DiagnosticsHelper.TraceInformation("MongoWorkerRole onstop called");
            try
            {
                // should we instead call Process.stop?
                if ((mongodProcess != null) &&
                    !(mongodProcess.HasExited))
                {
                    DiagnosticsHelper.TraceInformation("Stepdown called on mongod");
                    DatabaseHelper.StepdownIfNeeded(mongodPort);
                }
            }
            catch (Exception e)
            {
                //Ignore any and all exceptions here since we want the rest
                // of the cleanup actions to happen
                DiagnosticsHelper.TraceWarning(
                    "Exception in onstop - stepdown failed with {0}, {1}",
                    e.Message, e.StackTrace);
            }

            try
            {
                // should we instead call Process.stop?
                if ((mongodProcess != null) &&
                    !(mongodProcess.HasExited))
                {
                    DiagnosticsHelper.TraceInformation("Shutdown called on mongod");
                    ShutdownMongo();
                }
                DiagnosticsHelper.TraceInformation("Shutdown completed on mongod");
            }
            catch (Exception e)
            {
                //Ignore any and all exceptions here since we want the rest
                // of the cleanup actions to happen
                DiagnosticsHelper.TraceWarning(
                    "Exception in onstop - shutdown failed with {0} {1}",
                    e.Message, e.StackTrace);
            }

            try
            {
                if (mongoDataDrive != null)
                {
                    DiagnosticsHelper.TraceInformation("Unmount called on data drive");
                    mongoDataDrive.Unmount();
                }
                DiagnosticsHelper.TraceInformation("Unmount completed on data drive");
            }
            catch (Exception e)
            {
                //Ignore any and all exceptions here
                DiagnosticsHelper.TraceWarning(
                    "Exception in onstop - unmount failed with {0} {1}",
                    e.Message, e.StackTrace);
            }
        }
コード例 #7
0
        public static void UnmountDrive(string containerName, string vhdName)
        {
            var client = GetCloudClientInstance();
            var vhdBlob = client.GetContainerReference(containerName).GetPageBlobReference(vhdName);

            var cloudDrive = new CloudDrive(vhdBlob.Uri, client.Credentials);
            cloudDrive.Unmount();
        }
コード例 #8
0
 private void UnmountCloudDrive()
 {
     if (cloudDrive != null)
     {
         Tracer.WriteLine(string.Format("Unmounting {0} from {1}", cloudDrive.Uri, cloudDrive.LocalPath), "Information");
         cloudDrive.Unmount();
     }
 }
コード例 #9
0
        void Application_End(object sender, EventArgs e)
        {
            // obtain a reference to the cloud drive and unmount it
            CloudStorageAccount account  = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");
            string     imageStoreBlobUri = RoleEnvironment.GetConfigurationSettingValue("ImageStoreBlobUri");
            CloudDrive imageStoreDrive   = account.CreateCloudDrive(imageStoreBlobUri);

            imageStoreDrive.Unmount();
        }
コード例 #10
0
        public static void UnmountDrive(string containerName, string vhdName)
        {
            var client  = GetCloudClientInstance();
            var vhdBlob = client.GetContainerReference(containerName).GetPageBlobReference(vhdName);

            var cloudDrive = new CloudDrive(vhdBlob.Uri, client.Credentials);

            cloudDrive.Unmount();
        }
コード例 #11
0
        public override void OnStop()
        {
            _ravenHttpServer.StopTcp();

            if (_ravenDataDrive != null)
            {
                _ravenDataDrive.Unmount();
            }

            base.OnStop();
        }
コード例 #12
0
 public void Unmount()
 {
     if (_elasticStorageDrive != null)
     {
         try
         {
             _elasticStorageDrive.Unmount();
         }
         catch { }
     }
 }
コード例 #13
0
 /// <summary>
 /// Unmounts the specified drive
 /// </summary>
 /// <param name="drive"></param>
 public static void UnmountAzureDrive(CloudDrive drive)
 {
     try
     {
         if (drive != null)
         {
             drive.Unmount();
         }
     }
     catch (Exception ex)
     {
         WindowsAzureSystemHelper.LogError(String.Format("Error unmounting drive {0} ", ex.Message));
     }
 }
コード例 #14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="csa"></param>
 /// <param name="uriString"></param>
 public static void UnmountAzureDrive(CloudStorageAccount csa, string uriString)
 {
     try
     {
         CloudDrive drive = new CloudDrive(new Uri(uriString), csa.Credentials);
         if (drive != null)
         {
             drive.Unmount();
         }
     }
     catch (Exception ex)
     {
         WindowsAzureSystemHelper.LogError(String.Format("Error unmounting drive with Uri {0} - {1}", uriString, ex.Message));
     }
 }
コード例 #15
0
 public override void OnStop()
 {
     Trace.Write("WebRole.OnStop", "Error");
     try
     {
         Trace.WriteLine("WebRole.OnStop: Unmounting drive", "Verbose");
         drive.Unmount();
         Trace.WriteLine("WebRole.OnStop: Removing node from traffic manager", "Verbose");
         base.OnStop();
         Trace.WriteLine("WebRole.OnStop: Done", "Verbose");
     }
     catch (Exception x)
     {
         Trace.TraceError(x.ToString());
     }
 }
コード例 #16
0
        protected void NewDrive_Click(object sender, EventArgs e)
        {
            if (RoleEnvironment.IsAvailable)
            {
                // retrieve storage account
                CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

                // build page blob URI for the new cloud drive by changing the extension in the original URI
                string imageStoreBlobUri = RoleEnvironment.GetConfigurationSettingValue("ImageStoreBlobUri");
                string cloneStoreBlobUri = Path.ChangeExtension(imageStoreBlobUri, "bak");

                // create drive and its associated page blob
                CloudDrive clonedDrive = account.CreateCloudDrive(cloneStoreBlobUri);
                if (this.MountedDrives.Items.Count < 2)
                {
                    try
                    {
                        clonedDrive.Create(16);
                    }
                    catch (CloudDriveException)
                    {
                        // cloud drive already exists
                    }

                    // mount the drive and retrieve its path
                    LocalResource cache           = RoleEnvironment.GetLocalResource("LocalDriveCache");
                    string        clonedStorePath = clonedDrive.Mount(cache.MaximumSizeInMegabytes / 2, DriveMountOptions.None);

                    // copy the contents from the original drive to the new drive
                    foreach (string sourceFileName in Directory.GetFiles(Global.ImageStorePath, "*.*").Where(name => name.EndsWith(".jpg") || name.EndsWith(".png")))
                    {
                        string destinationFileName = Path.Combine(clonedStorePath, Path.GetFileName(sourceFileName));
                        File.Copy(sourceFileName, destinationFileName, true);
                    }

                    this.SelectImageStore(clonedStorePath);
                }
                else
                {
                    clonedDrive.Unmount();
                    clonedDrive.Delete();
                    this.SelectImageStore(Global.ImageStorePath);
                }
            }
        }
コード例 #17
0
 public void Dispose()
 {
     try
     {
         if (_elasticStorageDrive != null)
         {
             DiagnosticsHelper.TraceInformation("Unmount called on data drive");
             _elasticStorageDrive.Unmount();
         }
         DiagnosticsHelper.TraceInformation("Unmount completed on data drive");
     }
     catch (Exception e)
     {
         //Ignore any and all exceptions here
         DiagnosticsHelper.TraceWarning(
             "Exception in onstop - unmount failed with {0} {1}",
             e.Message, e.StackTrace);
     }
 }
コード例 #18
0
        /// <summary>
        /// Unmounts the drive
        /// </summary>
        /// <param name="accountName"></param>
        /// <param name="accountKey"></param>
        /// <param name="azureDriveContainerName"></param>
        /// <param name="azureDrivePageBlobName"></param>
        public static void UnmountAzureDrive(string accountName, string accountKey, string azureDriveContainerName, string azureDrivePageBlobName)
        {
            try
            {
                CloudStorageAccount csa = WAStorageHelper.GetCloudStorageAccount(accountName, accountKey, false);
                // Create the blob client

                CloudBlobClient client = csa.CreateCloudBlobClient();
                // Create the blob container which will contain the pageblob corresponding to the azure drive.
                CloudBlobContainer container = client.GetContainerReference(azureDriveContainerName);
                // Get the page blob reference which will be used by the azure drive.
                CloudPageBlob blob = container.GetPageBlobReference(azureDrivePageBlobName);

                CloudDrive drive = new CloudDrive(blob.Uri, csa.Credentials);
                if (drive != null)
                {
                    drive.Unmount();
                }
            }
            catch (Exception ex)
            {
                WindowsAzureSystemHelper.LogError(String.Format("Error unmounting drive with blob {0} - {1}", azureDrivePageBlobName, ex.Message));
            }
        }
コード例 #19
0
 private void UnmountDrive(CloudDrive drive)
 {
     drive.Unmount();
     this.EventLog.WriteEntry(string.Format("{0} unmounted", drive.Uri));
 }
コード例 #20
0
 public static void UnMount()
 {
     myCloudDrive.Unmount();
 }
コード例 #21
0
 internal void Unmount()
 {
     _cloudDrive.Unmount();
 }
コード例 #22
0
ファイル: CloudDriveSupport.cs プロジェクト: kallex/Caloom
 public static void UnmountDrive(CloudDrive cloudDrive)
 {
     cloudDrive.Unmount();
 }
コード例 #23
0
ファイル: CloudDriveSupport.cs プロジェクト: kallex/Caloom
 private static void unmountDrive(CloudDrive drive)
 {
     drive.Unmount();
 }
コード例 #24
0
ファイル: BackupJob.cs プロジェクト: nishanperera/mongo-azure
        //=================================================================================
        //
        //  PRIVATE METHODS
        //
        //=================================================================================
        /// <summary>
        /// The actual backup logic itself.
        /// We mount the VHD snapshot, then TAR and copy the contents to a new blob.
        /// </summary>
        private void Run()
        {
            CloudDrive snapshottedDrive = null;
            bool mountedSnapshot = false;

            try
            {
                Log("Backup started for " + UriToBackup + "...");

                // Set up the cache, storage account, and blob client.
                Log("Getting the cache...");
                var localResource = RoleEnvironment.GetLocalResource(Constants.BackupLocalStorageName);
                Log("Initializing the cache...");
                CloudDrive.InitializeCache(localResource.RootPath, localResource.MaximumSizeInMegabytes);
                Log("Setting up storage account...");
                var storageAccount = CloudStorageAccount.Parse(Credential);
                var client = storageAccount.CreateCloudBlobClient();

                // Mount the snapshot.
                Log("Mounting the snapshot...");
                snapshottedDrive = new CloudDrive(UriToBackup, storageAccount.Credentials);
                string driveLetter = snapshottedDrive.Mount(0, DriveMountOptions.None);
                mountedSnapshot = true;
                Log("...snapshot mounted to " + driveLetter);

                // Create the destination blob.
                Log("Opening (or creating) the backup container...");
                CloudBlobContainer backupContainer = client.GetContainerReference(BackupContainerName);
                backupContainer.CreateIfNotExist();
                var blobFileName = String.Format(Constants.BackupFormatString, DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute);
                var blob = backupContainer.GetBlobReference(blobFileName);

                // Write everything in the mounted snapshot, to the TarWriter stream, to the BlobStream, to the blob.
                Log("Backing up:\n\tpath: " + driveLetter + "\n\tto blob: " + blobFileName + "\n");
                using (var outputStream = blob.OpenWrite())
                {
                    using (var tar = new TarWriter(outputStream))
                    {
                        Log("Writing to the blob/tar...");
                        AddAllToTar(driveLetter, tar);
                    }
                }

                // Set the blob's metadata.
                Log("Setting the blob's metadata...");
                blob.Metadata["FileName"] = blobFileName;
                blob.Metadata["Submitter"] = "BlobBackup";
                blob.SetMetadata();

                Log("Unmounting the drive..."); // Keep this here because we want "terminating now" to be the last log event in a failure.
            }
            catch (Exception e)
            {
                Log("=========================");
                Log("FAILURE: " + e.Message);
                Log(e.StackTrace);
                Log("");
                Log("Terminating now.");
            }
            finally
            {
                // Unmount the drive.
                if (mountedSnapshot)
                {
                    snapshottedDrive.Unmount();
                }

                DateFinished = DateTime.Now;
            }
        }
コード例 #25
0
 public void Dispose()
 {
     cloudDrive.Unmount();
 }
コード例 #26
0
ファイル: BackupJob.cs プロジェクト: waqashaneef/mongo-azure
        //=================================================================================
        //
        //  PRIVATE METHODS
        //
        //=================================================================================

        /// <summary>
        /// The actual backup logic itself.
        /// We mount the VHD snapshot, then TAR and copy the contents to a new blob.
        /// </summary>
        private void Run()
        {
            CloudDrive snapshottedDrive = null;
            bool       mountedSnapshot  = false;

            try
            {
                Log("Backup started for " + UriToBackup + "...");

                // Set up the cache, storage account, and blob client.
                Log("Getting the cache...");
                var localResource = RoleEnvironment.GetLocalResource(Constants.BackupLocalStorageName);
                Log("Initializing the cache...");
                CloudDrive.InitializeCache(localResource.RootPath, localResource.MaximumSizeInMegabytes);
                Log("Setting up storage account...");
                var storageAccount = CloudStorageAccount.Parse(Credential);
                var client         = storageAccount.CreateCloudBlobClient();

                // Mount the snapshot.
                Log("Mounting the snapshot...");
                snapshottedDrive = new CloudDrive(UriToBackup, storageAccount.Credentials);
                string driveLetter = snapshottedDrive.Mount(0, DriveMountOptions.None);
                mountedSnapshot = true;
                Log("...snapshot mounted to " + driveLetter);

                // Create the destination blob.
                Log("Opening (or creating) the backup container...");
                CloudBlobContainer backupContainer = client.GetContainerReference(BackupContainerName);
                backupContainer.CreateIfNotExist();
                var blobFileName = String.Format(Constants.BackupFormatString, DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute);
                var blob         = backupContainer.GetBlobReference(blobFileName);

                // Write everything in the mounted snapshot, to the TarWriter stream, to the BlobStream, to the blob.
                Log("Backing up:\n\tpath: " + driveLetter + "\n\tto blob: " + blobFileName + "\n");
                using (var outputStream = blob.OpenWrite())
                {
                    using (var tar = new TarWriter(outputStream))
                    {
                        Log("Writing to the blob/tar...");
                        AddAllToTar(driveLetter, tar);
                    }
                }

                // Set the blob's metadata.
                Log("Setting the blob's metadata...");
                blob.Metadata["FileName"]  = blobFileName;
                blob.Metadata["Submitter"] = "BlobBackup";
                blob.SetMetadata();

                Log("Unmounting the drive..."); // Keep this here because we want "terminating now" to be the last log event in a failure.
            }
            catch (Exception e)
            {
                Log("=========================");
                Log("FAILURE: " + e.Message);
                Log(e.StackTrace);
                Log("");
                Log("Terminating now.");
            }
            finally
            {
                // Unmount the drive.
                if (mountedSnapshot)
                {
                    snapshottedDrive.Unmount();
                }

                DateFinished = DateTime.Now;
            }
        }