Exemplo n.º 1
0
        private IEnumerable <Task> DeleteAllQueues()
        {
            CloudQueueClient         queueClient = _storageAccount.CreateCloudQueueClient();
            IEnumerable <CloudQueue> allQueues   = queueClient.ListQueues();

            return(allQueues.Select(q => Task.Run(() => q.DeleteAndWaitForCompletion())));
        }
Exemplo n.º 2
0
            private void Clean()
            {
                CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

                foreach (var queue in queueClient.ListQueues(TestArtifactsPrefix))
                {
                    queue.Delete();
                }

                CloudBlobClient    blobClient    = storageAccount.CreateCloudBlobClient();
                CloudBlobContainer hostContainer = blobClient.GetContainerReference("azure-webjobs-hosts");

                foreach (CloudBlockBlob lockBlob in hostContainer.ListBlobs(string.Format("locks/{0}", TestHostId), useFlatBlobListing: true))
                {
                    try
                    {
                        lockBlob.Delete();
                    }
                    catch (StorageException)
                    {
                        // best effort - might fail if there is an active
                        // lease on the blob
                    }
                }
            }
Exemplo n.º 3
0
 public void Dispose()
 {
     foreach (var testqueue in _queueClient.ListQueues(TestArtifactPrefix))
     {
         testqueue.Delete();
     }
 }
Exemplo n.º 4
0
        public static IEnumerable <string> GetAll(string account, string key)
        {
            CloudQueueClient queueClient = Client.GetQueueClient(account, key);

            foreach (CloudQueue queue in queueClient.ListQueues())
            {
                yield return(queue.Name);
            }
        }
Exemplo n.º 5
0
        // Get all queues
        public static IEnumerable <CloudQueue> getQueues()
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                CloudConfigurationManager.GetSetting("StorageConnectionString"));

            // Create the queue client
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

            return(queueClient.ListQueues());
        }
Exemplo n.º 6
0
        public void Drop()
        {
            CloudQueueClient queueClient = account.CreateCloudQueueClient();

            if (queueClient.ListQueues().Select(c => c.Name).Contains(queueName))
            {
                CloudQueue queue = queueClient.GetQueueReference(queueName);
                queue.Delete();
            }
        }
Exemplo n.º 7
0
 public void Dispose()
 {
     if (storageAccount != null)
     {
         CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
         foreach (var queue in queueClient.ListQueues(TestArtifactsPrefix))
         {
             queue.Delete();
         }
     }
 }
Exemplo n.º 8
0
        // List
        public void Listqueue()
        {
            CloudStorageAccount storageAccount = CreateStorageAccountFromConnectionString(CloudConfigurationManager.GetSetting("StorageConnectionString"));
            CloudQueueClient    queueClient    = storageAccount.CreateCloudQueueClient();

            Console.WriteLine("Create a list for queue ");


            foreach (var queue in queueClient.ListQueues())
            {
                Console.WriteLine(queue.Uri + "======" + queue.Name);
            }
        }
        // Queues
        public string[] GetQueueNames()
        {
            CloudQueueClient queueClient = new CloudQueueClient(queueURI, creds);

            try
            {
                return(queueClient.ListQueues().Select(x => x.Name).ToArray());
            }
            catch (Exception e)
            {
                throw new StorageAccountException("Unable to retrieve queue names.", e);
            }
        }
        public void Dispose()
        {
            _functionStarted.Dispose();
            _functionCompleted.Dispose();

            if (_storageAccount != null)
            {
                CloudQueueClient queueClient = _storageAccount.CreateCloudQueueClient();
                foreach (var testQueue in queueClient.ListQueues(TestArtifactPrefix))
                {
                    testQueue.Delete();
                }
            }
        }
Exemplo n.º 11
0
            public void Dispose()
            {
                CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient();

                foreach (var testContainer in blobClient.ListContainers(TestArtifactsPrefix))
                {
                    testContainer.Delete();
                }

                CloudQueueClient queueClient = StorageAccount.CreateCloudQueueClient();

                foreach (var testQueue in queueClient.ListQueues(TestArtifactsPrefix))
                {
                    testQueue.Delete();
                }
            }
Exemplo n.º 12
0
        private void CreateMissingQueues(CloudQueueClient cloudQueueClient)
        {
            var shards = cloudQueueClient.ListQueues()
                         .Where(q => q.Name.StartsWith(queueName, StringComparison.InvariantCulture))
                         .Select(q => q.Name);

            var queueNames = Enumerable.Range(0, queueCount)
                             .Select(i => queueName + i)
                             .Where(n => !shards.Contains(n))
                             .ToList();

            foreach (var name in queueNames)
            {
                var q = cloudQueueClient.GetQueueReference(name);
                q.CreateIfNotExists();
            }
        }
Exemplo n.º 13
0
        public static void DeleteAllQueue()
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                CloudConfigurationManager.GetSetting("StorageConnectionString"));

            // Create the queue client.
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();


            // Retrieve reference to a previously created container.
            IEnumerable <CloudQueue> queueList = queueClient.ListQueues();
            int count = queueList.Count();

            foreach (CloudQueue queue in queueList)
            {
                queue.Delete();
                Console.Write("\r{0} - Queue Remaining to delete   ", count--);
            }
        }
Exemplo n.º 14
0
        public void QueueTest()
        {
            AzureService azureService = new AzureService(Settings.Default.AzureAccountName, Settings.Default.AzureAccountKey);

            CloudQueueClient cloudQueueClient = azureService.GetCloudQueueClient();

            IEnumerable <CloudQueue> queues = cloudQueueClient.ListQueues();

            foreach (var queue in queues)
            {
                testContextInstance.WriteLine("{0}", queue.Name);
            }

            CloudQueue queue1 = cloudQueueClient.GetQueueReference("testqueue");

            //Check whether the queue exists, and create it if it does not.
            if (!queue1.Exists())
            {
                queue1.Create();
            }

            CloudQueueMessage message = new CloudQueueMessage("This is a test");

            queue1.AddMessage(message);

            String songInfo = String.Format("{0},{1}", @"c:\music\song.mp3", 34);

            message = new CloudQueueMessage(songInfo);
            queue1.AddMessage(message);

            while (true)
            {
                CloudQueueMessage message1 = queue1.GetMessage();
                if (null == message1)
                {
                    break;
                }
                testContextInstance.WriteLine("{0}", message1.AsString);
                queue1.DeleteMessage(message1);
            }
        }
        //https://msazure.visualstudio.com/One/_git/AzureStack-Services-Storage?path=%2Fsrc%2Fsdx%2Fbase%2Fwoss%2Ftest%2Ftests%2FWFE%2FHorizontalBVT%2FAccountKeyTests.cs&version=GBmaster&_a=contents
        /// <summary>
        /// Make a couple of requests to the blob, queue, and table services, expecting success.
        /// </summary>
        /// <param name="account">The account through which the services will be accessed.</param>
        internal void MakeServiceRequestsExpectSuccess(CloudStorageAccount account)
        {
            // Make blob service requests
            CloudBlobClient blobClient = account.CreateCloudBlobClient();

            //   blobClient.ListContainersSegmentedAsync();
            blobClient.ListContainers().Count();
            blobClient.GetServiceProperties();

            // Make queue service requests
            CloudQueueClient queueClient = account.CreateCloudQueueClient();

            queueClient.ListQueues().Count();
            queueClient.GetServiceProperties();

            // Make table service requests
            CloudTableClient tableClient = account.CreateCloudTableClient();

            tableClient.ListTables().Count();
            tableClient.GetServiceProperties();
        }
        public static bool ClearAllQueues()
        {
            try
            {
                CloudStorageAccount account =
                    CloudStorageAccount.Parse(Microsoft.Azure.CloudConfigurationManager.GetSetting("StorageConnectionString"));
                CloudQueueClient queueClient = account.CreateCloudQueueClient();

                foreach (var item in queueClient.ListQueues())
                {
                    string     strQueueName = item.Name;
                    CloudQueue queue        = queueClient.GetQueueReference(strQueueName);
                    queue.Delete();
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private static void Clean(CloudStorageAccount account)
        {
            CloudBlobClient blobClient = account.CreateCloudBlobClient();

            foreach (var testContainer in blobClient.ListContainers(TestArtifactPrefix))
            {
                testContainer.Delete();
            }

            CloudTableClient tableClient = account.CreateCloudTableClient();

            foreach (var table in tableClient.ListTables(TestArtifactPrefix))
            {
                table.Delete();
            }

            CloudQueueClient queueClient = account.CreateCloudQueueClient();

            foreach (var queue in queueClient.ListQueues(TestArtifactPrefix))
            {
                queue.Delete();
            }
        }
Exemplo n.º 18
0
        // List queues.
        // Return true on success, false if not found, throw exception on error.

        public bool ListQueues(out List <CloudQueue> queueList)
        {
            queueList = new List <CloudQueue>();

            try
            {
                IEnumerable <CloudQueue> queues = QueueClient.ListQueues();
                if (queues != null)
                {
                    queueList.AddRange(queues);
                }
                return(true);
            }
            catch (StorageClientException ex)
            {
                if ((int)ex.StatusCode == 404)
                {
                    return(false);
                }

                throw;
            }
        }
Exemplo n.º 19
0
 public IEnumerable <CloudQueue> ListQueues()
 {
     return(cloudQueueClient.ListQueues());
 }
 /// <summary>
 /// List storage queues
 /// </summary>
 /// <param name="prefix">Queue name prefix</param>
 /// <param name="queueListingDetails">Queue listing details</param>
 /// <param name="options">Queue request options</param>
 /// <param name="operationContext">Operation context</param>
 /// <returns>An enumerable collection of the queues in the storage account.</returns>
 public IEnumerable <CloudQueue> ListQueues(string prefix, QueueListingDetails queueListingDetails,
                                            QueueRequestOptions options, OperationContext operationContext)
 {
     return(queueClient.ListQueues(prefix, queueListingDetails, options, operationContext));
 }
Exemplo n.º 21
0
 public IEnumerable <IAzureQueue> ListQueues()
 {
     return(_cloudQueueClient.ListQueues()
            .Select(q => new HostedAzureQueue(q))
            .ToArray());
 }
Exemplo n.º 22
0
        /// <summary>
        /// Cleanup the Azure storage including both queue and blob.
        /// </summary>
        private async Task Cleanup()
        {
            BrokerTracing.TraceVerbose(
                "[AzureStorageCleaner].Cleanup: Try to cleanup the Azure storage.");
            ClusterInfoContract clusterInfo = await this.helper.GetClusterInfoAsync();

            string clusterName = clusterInfo.ClusterName;
            Guid   clusterId;

            if (!Guid.TryParse(clusterInfo.ClusterId, out clusterId))
            {
                BrokerTracing.TraceError(
                    "[AzureStorageCleaner].Cleanup: clusterInfo.ClusterId is not a valid GUID string.");
                throw new ArgumentException("clusterInfo.ClusterId", "clusterInfo.ClusterId is not a valid GUID string.");
            }
            var connectionString = clusterInfo.AzureStorageConnectionString;

            if (string.IsNullOrEmpty(connectionString))
            {
                BrokerTracing.TraceVerbose(
                    "[AzureStorageCleaner].Cleanup: Azure storage connection string is not set.");

                // no need to do anything if the connection string is not set
                return;
            }

            string prefix   = SoaHelper.GetResponseStoragePrefix(clusterId.ToString());
            string prefixAQ = SoaHelper.GetAzureQueueStoragePrefix(clusterId.ToString().ToLower().GetHashCode());

            CloudStorageAccount account     = CloudStorageAccount.Parse(connectionString);
            CloudQueueClient    queueClient = account.CreateCloudQueueClient();

            queueClient.DefaultRequestOptions.RetryPolicy = DefaultRetryPolicy;

            var queues   = queueClient.ListQueues(prefix);
            var queuesAQ = queueClient.ListQueues(prefixAQ);

            CloudBlobClient blobClient = account.CreateCloudBlobClient();

            blobClient.DefaultRequestOptions.RetryPolicy = DefaultRetryPolicy;
            var containers   = blobClient.ListContainers(prefix, ContainerListingDetails.None, null, null);
            var containersAQ = blobClient.ListContainers(prefixAQ, ContainerListingDetails.None, null, null);
            Dictionary <int, int> nonTerminatedSession;

            if (queues.Count <CloudQueue>() > 0 || containers.Count <CloudBlobContainer>() > 0 ||
                queuesAQ.Count <CloudQueue>() > 0 || containersAQ.Count <CloudBlobContainer>() > 0)
            {
                // if there are queue/container candidates for deleting, get
                // following info from session service
                nonTerminatedSession = await this.helper.GetNonTerminatedSession();
            }
            else
            {
                return;
            }

            // cleanup storage queue
            foreach (CloudQueue queue in queues)
            {
                BrokerTracing.TraceVerbose(
                    "[AzureStorageCleaner].Cleanup: Azure storage queue name is {0}",
                    queue.Name);

                if (this.IsSessionTerminated(nonTerminatedSession, prefix, queue.Name))
                {
                    try
                    {
                        queue.Delete();
                    }
                    catch (Exception e)
                    {
                        BrokerTracing.TraceError(
                            "[AzureStorageCleaner].Cleanup: Deleting queue {0} failed, {1}",
                            queue.Name,
                            e);
                    }
                }
            }

            // cleanup storage blob container
            foreach (CloudBlobContainer container in containers)
            {
                BrokerTracing.TraceVerbose(
                    "[AzureStorageCleaner].Cleanup: Azure storage container name is {0}",
                    container.Name);

                if (this.IsSessionTerminated(nonTerminatedSession, prefix, container.Name))
                {
                    try
                    {
                        container.Delete();
                    }
                    catch (Exception e)
                    {
                        BrokerTracing.TraceError(
                            "[AzureStorageCleaner].Cleanup: Deleting container {0} failed, {1}",
                            container.Name,
                            e);
                    }
                }
            }

            // cleanup storage queue for the http clients
            foreach (CloudQueue queue in queuesAQ)
            {
                BrokerTracing.TraceVerbose(
                    "[AzureStorageCleaner].Cleanup: Azure storage queue name is {0}",
                    queue.Name);

                if (this.IsSessionTerminatedAQ(nonTerminatedSession, prefixAQ, queue.Name))
                {
                    try
                    {
                        queue.Delete();
                    }
                    catch (Exception e)
                    {
                        BrokerTracing.TraceError(
                            "[AzureStorageCleaner].Cleanup: Deleting queue {0} failed, {1}",
                            queue.Name,
                            e);
                    }
                }
            }

            // cleanup storage blob container for the http clients
            foreach (CloudBlobContainer container in containersAQ)
            {
                BrokerTracing.TraceVerbose(
                    "[AzureStorageCleaner].Cleanup: Azure storage container name is {0}",
                    container.Name);

                if (this.IsSessionTerminatedAQ(nonTerminatedSession, prefixAQ, container.Name))
                {
                    try
                    {
                        container.Delete();
                    }
                    catch (Exception e)
                    {
                        BrokerTracing.TraceError(
                            "[AzureStorageCleaner].Cleanup: Deleting container {0} failed, {1}",
                            container.Name,
                            e);
                    }
                }
            }
        }
Exemplo n.º 23
0
 public IEnumerable <String> ListQueues()
 {
     return(cloudQueueClient.ListQueues().Select(cq => cq.Name));
 }
Exemplo n.º 24
0
 public System.Collections.Generic.IEnumerable <CloudQueue> ListAllQueues()
 {
     return(_cloudQueueClient.ListQueues());
 }
Exemplo n.º 25
0
        /// <summary>
        /// Check if the Azure storage connection string is valid.
        /// </summary>
        private async Task ValidateConnectionString()
        {
            int sessionId = this.sharedData.BrokerInfo.SessionId;

            string sessionNode = await this.context.ResolveSessionLauncherNodeAsync();

            string certThrumbprint = await this.context.GetSSLThumbprint();

            string storageConnectionString = this.sharedData.BrokerInfo.AzureStorageConnectionString; // CommonClusterManagerHelper.GetAzureStorageConnectionString(scheduler);

            if (string.IsNullOrEmpty(storageConnectionString))
            {
                this.connectionStringValid = false;

                BrokerTracing.TraceError(
                    "[DispatcherManager].ValidateConnectionString: Azure storage connection string is missed.");

                // set job's progress message if Azure connection string is missed
                using (HpcSchedulerAdapterInternalClient client = new HpcSchedulerAdapterInternalClient(sessionNode, certThrumbprint))
                {
                    await client.SetJobProgressMessage(sessionId, SR.MissAzureStorageConnectionString);
                }
            }
            else
            {
                try
                {
                    this.azureQueueManager.StorageConnectionString = storageConnectionString;

                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);

                    CloudQueueClient client = storageAccount.CreateCloudQueueClient();

                    client.ListQueues().Any <CloudQueue>();

                    this.connectionStringValid = true;
                }
                catch (StorageException e)
                {
                    string errorCode = BurstUtility.GetStorageErrorCode(e);

                    if (errorCode == StorageErrorCodeStrings.AuthenticationFailed)
                    {
                        this.connectionStringValid = false;

                        BrokerTracing.TraceError(
                            "[DispatcherManager].ValidateConnectionString: Access key in Azure storage connection string is invalid.");

                        // set job's progress message if Azure connection string is invalid
                        using (HpcSchedulerAdapterInternalClient client = new HpcSchedulerAdapterInternalClient(sessionNode, certThrumbprint))
                        {
                            await client.SetJobProgressMessage(sessionId, SR.InvalidAzureStorageConnectionString);
                        }
                    }
                    else if (e.RequestInformation.HttpStatusCode == (int)HttpStatusCode.BadGateway)
                    {
                        this.connectionStringValid = false;

                        BrokerTracing.TraceError(
                            "[DispatcherManager].ValidateConnectionString: Account name in Azure storage connection string is invalid.");

                        // set job's progress message if Azure connection string is invalid
                        using (HpcSchedulerAdapterInternalClient client = new HpcSchedulerAdapterInternalClient(sessionNode, certThrumbprint))
                        {
                            await client.SetJobProgressMessage(sessionId, SR.InvalidAzureStorageConnectionString);
                        }
                    }
                    else
                    {
                        this.connectionStringValid = true;

                        BrokerTracing.TraceWarning(
                            "[DispatcherManager].ValidateConnectionString: Error occurs when check storage connection string, {0}", e);
                    }
                }
            }
        }
Exemplo n.º 26
0
        public async Task <bool> Start(ConfigurationOptions config, CancellationToken cancellationToken)
        {
            CloudStorageAccount storageAccount;

            try
            {
                storageAccount = CloudStorageAccount.Parse(config.ConnectionString);
            }
            catch (FormatException ex)
            {
                _console.ColoredWriteLine($"<r>Error parsing the connection string: <w>{ex.Message}</w></r>");
                return(false);
            }

            Console.Clear();
            Console.Title         = $"Azure Storage Queue Monitor{(!string.IsNullOrWhiteSpace(config.Title) ? $" -- {config.Title}" : "")}";
            Console.CursorVisible = false;

            Dictionary <string, QueueInfo> queueInfos = new Dictionary <string, QueueInfo>();

            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            int       iterations         = 0;
            Stopwatch sw = new Stopwatch();

            while (true)
            {
                await Task.Yield();

                if (cancellationToken.IsCancellationRequested)
                {
                    return(true);
                }

                sw.Restart();
                iterations++;
                if (iterations == 50)
                {
                    iterations = 0;
                    queueInfos.Clear();
                }
                List <CloudQueue> queues = queueClient.ListQueues().ToList();
                foreach (var queue in queues)
                {
                    try
                    {
                        queue.FetchAttributes();
                    }
                    catch (StorageException sex) when(sex.Message.Contains("The specified queue does not exist"))
                    {
                        if (queueInfos.ContainsKey(queue.Name))
                        {
                            queueInfos.Remove(queue.Name);
                        }
                    }

                    string name = queue.Name;
                    if (config.IgnoredQueues?.Any(i => Regex.IsMatch(name, i)) ?? false)
                    {
                        continue;
                    }

                    int count = queue.ApproximateMessageCount ?? 0;
                    if (!queueInfos.ContainsKey(name))
                    {
                        bool isImportant = false;
                        if (config.ImportantQueues?.Any(i => Regex.IsMatch(name, i)) ?? false)
                        {
                            isImportant = true;
                        }

                        string groupName  = "NOT GROUPED";
                        int    groupOrder = int.MaxValue;
                        if (config.GroupQueues)
                        {
                            foreach (var queueGroup in config.QueueGroups)
                            {
                                if (queueGroup.Queues.Any(q => Regex.IsMatch(name, q)))
                                {
                                    groupName  = queueGroup.GroupName;
                                    groupOrder = queueGroup.Order;
                                    continue;
                                }
                            }
                        }

                        queueInfos.Add(name, new QueueInfo {
                            Name         = name,
                            FirstCount   = count,
                            CurrentCount = count,
                            IsImportant  = isImportant,
                            GroupName    = groupName,
                            GroupOrder   = groupOrder
                        });
                    }
                    else
                    {
                        var info = queueInfos[name];
                        if (count > info.FirstCount)
                        {
                            info.FirstCount     = count;
                            info.IncreasedCount = true;
                        }
                        else
                        {
                            info.IncreasedCount = false;
                        }
                        info.DecreasedCount = count < info.CurrentCount;
                        info.CurrentCount   = count;
                    }
                }
                PrintQueues(config, queueInfos, iterations);
                if (config.ExportCountData)
                {
                    if (_previousQueueCount != queueInfos.Count)
                    {
                        _exportFullPath = null;
                    }
                    ExportCountData(config, queueInfos);
                }
                _previousQueueCount = queueInfos.Count;
                sw.Stop();
                long sleepInterval = config.Interval - sw.ElapsedMilliseconds;
                if (sleepInterval > 0)
                {
                    await Task.Delay(config.Interval, cancellationToken);
                }
            }
        }
        /// <summary>
        /// Test some of the queue storage operations.
        /// </summary>
        public async Task RunQueueStorageAdvancedOpsAsync()
        {
            try
            {
                //***** Setup *****//
                Console.WriteLine("Getting reference to the storage account.");

                // Retrieve storage account information from connection string
                // How to create a storage connection string - http://msdn.microsoft.com/en-us/library/azure/ee758697.aspx
                CloudStorageAccount storageAccount = Common.CreateStorageAccountFromConnectionString(CloudConfigurationManager.GetSetting("StorageConnectionString"));

                Console.WriteLine("Instantiating queue client.");
                Console.WriteLine(string.Empty);

                // Create a queue client for interacting with the queue service.
                CloudQueueClient cloudQueueClient = storageAccount.CreateCloudQueueClient();

                // Create 3 queues.

                // Create the queue name -- use a guid in the name so it's unique.
                string baseQueueName = "demotest-" + System.Guid.NewGuid().ToString();

                // Keep a list of the queues so you can compare this list
                //   against the list of queues that we retrieve.
                List <string> queueNames = new List <string>();

                for (int i = 0; i < 3; i++)
                {
                    // Set the name of the queue, then add it to the generic list.
                    string queueName = baseQueueName + "-0" + i;
                    queueNames.Add(queueName);

                    // Create the queue with this name.
                    Console.WriteLine("Creating queue with name {0}", queueName);
                    CloudQueue cloudQueue = cloudQueueClient.GetQueueReference(queueName);
                    try
                    {
                        await cloudQueue.CreateIfNotExistsAsync();

                        Console.WriteLine("    Queue created successfully.");
                    }
                    catch (StorageException exStorage)
                    {
                        Common.WriteException(exStorage);
                        Console.WriteLine("Please make sure your storage account is specified correctly in the app.config - then restart the sample.");
                        Console.WriteLine("Press any key to exit");
                        Console.ReadLine();
                        throw;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("    Exception thrown creating queue.");
                        Common.WriteException(ex);
                        throw;
                    }
                }

                Console.WriteLine(string.Empty);
                Console.WriteLine("List of queues in the storage account:");

                // List the queues for this storage account
                IEnumerable <CloudQueue> cloudQueueList = cloudQueueClient.ListQueues();
                try
                {
                    foreach (CloudQueue cloudQ in cloudQueueList)
                    {
                        Console.WriteLine("Cloud Queue name = {0}", cloudQ.Name);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("    Exception thrown listing queues.");
                    Common.WriteException(ex);
                    throw;
                }

                // Now clean up after yourself, using the list of queues that you created in case there were other queues in the account.
                foreach (string oneQueueName in queueNames)
                {
                    CloudQueue cloudQueue = cloudQueueClient.GetQueueReference(oneQueueName);
                    cloudQueue.DeleteIfExists();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("    Exception thrown. Message = {0}{1}    Strack Trace = {2}", ex.Message, Environment.NewLine, ex.StackTrace);
            }
        }
Exemplo n.º 28
0
        // The Azure Functions runtime uses this storage account connection string for all functions
        // except for HTTP triggered functions.
        // The storage account must be a general-purpose one that supports blobs, queues, and tables.
        // See Storage account and Storage account requirements.

        // AzureWebJobsDashboard
        // Optional storage account connection string for storing logs and displaying them in the Monitor tab in the portal.
        // The storage account must be a general-purpose one that supports blobs, queues, and tables.
        // See Storage account and Storage account requirements.

        //Functions uses Storage for operations such as managing triggers and logging function executions.
        internal StorageAccountsValidation MakeServiceRequestsExpectSuccess(string connectionKey, string connectionString)
        {
            string storageSymptoms  = String.Empty;
            int    status           = 0;
            string postfixStatement = "Please make sure this is a general-purpose storage account.";

            //if (connectionKey.Equals("AzureWebJobsStorage", StringComparison.OrdinalIgnoreCase))
            //{

            //}

            try
            {
                if (string.IsNullOrWhiteSpace(connectionString))
                {
                    //  return Task.FromResult<StorageAccountsValidation> (new StorageAccountsValidation { });
                    return(new StorageAccountsValidation {
                    });
                }


                CloudStorageAccount account = CloudStorageAccount.Parse(connectionString);

                // Make blob service requests
                try
                {
                    CloudBlobClient blobClient = account.CreateCloudBlobClient();
                    //   blobClient.ListContainersSegmentedAsync();
                    // blobClient.ListContainers().Count();
                    blobClient.GetServiceProperties();
                }
                catch (Exception ex)
                {
                    storageSymptoms += "Blob endpoint is not reachable. Make sure the firewall on this storage account is not misconfigured.";
                    throw ex;
                }

                try
                {
                    // Make queue service requests
                    CloudQueueClient queueClient = account.CreateCloudQueueClient();
                    queueClient.ListQueues().Count();
                    queueClient.GetServiceProperties();
                }
                catch (Exception ex)
                {
                    storageSymptoms += "Queue is not enabled. ";
                    throw ex;
                }

                try
                {
                    // Make table service requests
                    CloudTableClient tableClient = account.CreateCloudTableClient();
                    tableClient.ListTables().Count();
                    tableClient.GetServiceProperties();
                }
                catch (Exception ex)
                {
                    storageSymptoms += "Table is not enabled.";
                    throw ex;
                }

                try
                {
                    // Not sure if this is only required for consumption
                    //  When using a Consumption plan function definitions are stored in File Storage.
                    CloudFileClient fileClient = account.CreateCloudFileClient();
                    fileClient.ListShares().Count();
                    fileClient.GetServiceProperties();
                }
                catch (Exception ex)
                {
                    storageSymptoms += "File is not enabled.";
                    throw ex;
                }

                storageSymptoms = "Storage connection string validation passed!";
            }
            catch (Exception ex)
            {
                storageSymptoms += "\n";
                storageSymptoms += postfixStatement;
                status           = 1;
            }


            StorageAccountsValidation result = new StorageAccountsValidation
            {
                AppSettingsKey = connectionKey,
                Mandatory      = false,
                AccountName    = connectionString.Split(new string[] { "AccountName=", ";AccountKey=" }, StringSplitOptions.RemoveEmptyEntries)[1],
                Message        = storageSymptoms,
                Status         = status
            };

            //return Task.FromResult(result);
            return(result);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Acts upon command line arguments.
        /// </summary>
        /// <param name="args">Command line arguments.</param>
        private static void Main(string[] args)
        {
            // Create our CloudQueueClient object.
            // REVIEW: Hard-coded connection string index "Ironclad".
            string connectionString           = null;
            ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["Ironclad"];

            if (settings != null)
            {
                connectionString = settings.ConnectionString;
            }

            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ConfigurationException("Azure connection string missing from your .exe.config file!");
            }

            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

            switch (args.Length)
            {
            case 0:
                Status(queueClient.ListQueues());
                break;

            case 2:
            {
                CloudQueue queue = queueClient.GetQueueReference(args[1]);
                if (!queue.Exists())
                {
                    Console.WriteLine("No such queue '{0}'", args[1]);
                    return;
                }

                queue.FetchAttributes();

                switch (args[0])
                {
                case "clear":
                case "Clear":
                    queue.Clear();
                    Console.WriteLine("Queue '{0}' cleared.", queue.Name);
                    break;

                case "peek":
                case "Peek":
                    int numberToPeekAt = (queue.ApproximateMessageCount != null) ? (int)queue.ApproximateMessageCount : 0;
                    Console.WriteLine("Queue '{0}' contains {1} messages:", queue.Name, numberToPeekAt);
                    if (numberToPeekAt != 0)
                    {
                        // Peek API only allows a maximum of 32 messages to be peeked at.
                        numberToPeekAt = Math.Min(numberToPeekAt, 32);

                        foreach (CloudQueueMessage message in queue.PeekMessages(numberToPeekAt))
                        {
                            Console.WriteLine(
                                "\t{0} {1} {2}",
                                message.Id,
                                message.InsertionTime,
                                message.ExpirationTime);
                        }
                    }

                    break;

                case "status":
                case "Status":
                    Status(new CloudQueue[] { queue });
                    break;

                default:
                    Usage();
                    break;
                }
            }
            break;

            default:
                Usage();
                break;
            }
        }
Exemplo n.º 30
0
        public int GetExistingQueueCount()
        {
            List <CloudQueue> queues = client.ListQueues().ToList();

            return(queues.Count);
        }