public static async Task <IActionResult> Run(
            // Using /a/p/i route prefix, to let Functions Host distinguish api methods from statics
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "a/p/i/delete-task-hub")] HttpRequest req
            )
        {
            // Checking that the call is authenticated properly
            try
            {
                Globals.ValidateIdentity(req.HttpContext.User, req.Headers);
            }
            catch (UnauthorizedAccessException ex)
            {
                return(new OkObjectResult(ex.Message)
                {
                    StatusCode = 401
                });
            }

            string hubName          = Environment.GetEnvironmentVariable(EnvVariableNames.DFM_HUB_NAME);
            string connectionString = Environment.GetEnvironmentVariable(EnvVariableNames.AzureWebJobsStorage);

            var orcService = new AzureStorageOrchestrationService(new AzureStorageOrchestrationServiceSettings
            {
                StorageConnectionString = connectionString,
                TaskHubName             = hubName,
            });

            await orcService.DeleteAsync();

            return(new OkResult());
        }
        public async Task DeleteTaskHub(string connectionStringKey, string taskHubName)
        {
            Initialize(out _orchestrationService, out _client, connectionStringKey, taskHubName);

            await _orchestrationService.DeleteAsync();

            ColoredConsole.Write(Green($"Task hub '{_taskHubName}' successfully deleted."));
        }
Ejemplo n.º 3
0
        public async Task MonitorIdleTaskHubDisconnected()
        {
            var settings = new AzureStorageOrchestrationServiceSettings
            {
                StorageConnectionString = TestHelpers.GetTestStorageAccountConnectionString(),
                TaskHubName             = nameof(MonitorIdleTaskHubDisconnected),
                PartitionCount          = 4,
            };

            var service = new AzureStorageOrchestrationService(settings);
            var monitor = new DisconnectedPerformanceMonitor(settings.StorageConnectionString, settings.TaskHubName);

            await service.DeleteAsync();

            // A null heartbeat is expected when the task hub does not exist.
            PerformanceHeartbeat heartbeat = await monitor.PulseAsync(currentWorkerCount : 0);

            Assert.IsNull(heartbeat);

            await service.CreateAsync();

            ScaleRecommendation recommendation;

            for (int i = 0; i < 10; i++)
            {
                heartbeat = await monitor.PulseAsync(currentWorkerCount : 0);

                Assert.IsNotNull(heartbeat);
                Assert.AreEqual(settings.PartitionCount, heartbeat.PartitionCount);
                Assert.AreEqual(settings.PartitionCount, heartbeat.ControlQueueLengths.Count);
                Assert.AreEqual(settings.PartitionCount, heartbeat.ControlQueueLatencies.Count);
                Assert.AreEqual(0, heartbeat.ControlQueueLengths.Count(l => l != 0));
                Assert.AreEqual(0, heartbeat.ControlQueueLatencies.Count(l => l != TimeSpan.Zero));
                Assert.AreEqual(0, heartbeat.WorkItemQueueLength);
                Assert.AreEqual(0.0, heartbeat.WorkItemQueueLatencyTrend);
                Assert.AreEqual(TimeSpan.Zero, heartbeat.WorkItemQueueLatency);

                recommendation = heartbeat.ScaleRecommendation;
                Assert.IsNotNull(recommendation);
                Assert.AreEqual(ScaleAction.None, recommendation.Action);
                Assert.AreEqual(false, recommendation.KeepWorkersAlive);
                Assert.IsNotNull(recommendation.Reason);
            }

            // If any workers are assigned, the recommendation should be to have them removed.
            heartbeat = await monitor.PulseAsync(currentWorkerCount : 1);

            recommendation = heartbeat.ScaleRecommendation;
            Assert.IsNotNull(recommendation);
            Assert.AreEqual(ScaleAction.RemoveWorker, recommendation.Action);
            Assert.AreEqual(false, recommendation.KeepWorkersAlive);
            Assert.IsNotNull(recommendation.Reason);
        }
        public static Task DeleteTaskHubResources(string testName, bool enableExtendedSessions)
        {
            string hubName  = GetTaskHubNameFromTestName(testName, enableExtendedSessions);
            var    settings = new AzureStorageOrchestrationServiceSettings
            {
                TaskHubName             = hubName,
                StorageConnectionString = GetStorageConnectionString(),
            };

            var service = new AzureStorageOrchestrationService(settings);

            return(service.DeleteAsync());
        }
Ejemplo n.º 5
0
        public static async Task <IActionResult> DfmDeleteTaskHubFunction(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = Globals.ApiRoutePrefix + "/delete-task-hub")] HttpRequest req,
            string taskHubName,
            ILogger log
            )
        {
            // Checking that the call is authenticated properly
            try
            {
                await Auth.ValidateIdentityAsync(req.HttpContext.User, req.Headers, taskHubName);
            }
            catch (Exception ex)
            {
                log.LogError(ex, "Failed to authenticate request");
                return(new UnauthorizedResult());
            }

            // Checking that we're not in ReadOnly mode
            if (DfmEndpoint.Settings.Mode == DfmMode.ReadOnly)
            {
                log.LogError("Endpoint is in ReadOnly mode");
                return(new StatusCodeResult(403));
            }

            string connectionString = Environment.GetEnvironmentVariable(EnvVariableNames.AzureWebJobsStorage);

            var orcService = new AzureStorageOrchestrationService(new AzureStorageOrchestrationServiceSettings
            {
                StorageConnectionString = connectionString,
                TaskHubName             = taskHubName,
            });

            // .DeleteAsync() tends to throw "The requested operation cannot be performed on this container because of a concurrent operation"
            // (though still seems to do its job). So just wrapping with try-catch
            try
            {
                await orcService.DeleteAsync();
            }
            catch (Exception ex)
            {
                log.LogError(ex, "AzureStorageOrchestrationService.DeleteAsync() failed");
            }

            return(new OkResult());
        }
        private async Task DeleteTaskHub(string taskHub, string connectionString)
        {
            var settings = new AzureStorageOrchestrationServiceSettings()
            {
                TaskHubName             = taskHub,
                StorageConnectionString = connectionString,
            };

            var service = new AzureStorageOrchestrationService(settings);
            await service.StartAsync();

            this.output.WriteLine($"Deleting task hub : {taskHub}");
            try
            {
                await service.DeleteAsync();
            }
            catch (Exception ex)
            {
                // Log error, but don't fail the test, as it can be cleaned up later.
                this.output.WriteLine($"Encountered exception deleting task hub: : {ex.ToString()}");
            }
        }
Ejemplo n.º 7
0
        public static async Task <IActionResult> DeleteTaskHubFunction(
            // Using /a/p/i route prefix, to let Functions Host distinguish api methods from statics
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "a/p/i/delete-task-hub")] HttpRequest req,
            ILogger log
            )
        {
            // Checking that the call is authenticated properly
            try
            {
                await Auth.ValidateIdentityAsync(req.HttpContext.User, req.Headers);
            }
            catch (Exception ex)
            {
                log.LogError(ex, "Failed to authenticate request");
                return(new UnauthorizedResult());
            }

            string hubName          = Environment.GetEnvironmentVariable(EnvVariableNames.DFM_HUB_NAME);
            string connectionString = Environment.GetEnvironmentVariable(EnvVariableNames.AzureWebJobsStorage);

            var orcService = new AzureStorageOrchestrationService(new AzureStorageOrchestrationServiceSettings
            {
                StorageConnectionString = connectionString,
                TaskHubName             = hubName,
            });

            // .DeleteAsync() tends to throw "The requested operation cannot be performed on this container because of a concurrent operation"
            // (though still seems to do its job). So just wrapping with try-catch
            try
            {
                await orcService.DeleteAsync();
            }
            catch (Exception ex)
            {
                log.LogError(ex, "AzureStorageOrchestrationService.DeleteAsync() failed");
            }

            return(new OkResult());
        }
Ejemplo n.º 8
0
        public Task <IActionResult> DfmDeleteTaskHubFunction(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = Globals.ApiRoutePrefix + "/delete-task-hub")] HttpRequest req,
            [DurableClient(TaskHub = Globals.HubNameRouteParamName)] IDurableClient defaultDurableClient,
            string connName,
            string hubName,
            ILogger log
            )
        {
            return(this.HandleAuthAndErrors(defaultDurableClient, req, connName, hubName, log, async(_) => {
                // Checking that we're not in ReadOnly mode
                if (DfmEndpoint.Settings.Mode == DfmMode.ReadOnly)
                {
                    log.LogError("Endpoint is in ReadOnly mode");
                    return new StatusCodeResult(403);
                }

                string connectionString = Environment.GetEnvironmentVariable(Globals.GetFullConnectionStringEnvVariableName(connName));

                var orcService = new AzureStorageOrchestrationService(new AzureStorageOrchestrationServiceSettings
                {
                    StorageConnectionString = connectionString,
                    TaskHubName = hubName,
                });

                // .DeleteAsync() tends to throw "The requested operation cannot be performed on this container because of a concurrent operation"
                // (though still seems to do its job). So just wrapping with try-catch
                try
                {
                    await orcService.DeleteAsync();
                }
                catch (Exception ex)
                {
                    log.LogError(ex, "AzureStorageOrchestrationService.DeleteAsync() failed");
                }

                return new OkResult();
            }));
        }
Ejemplo n.º 9
0
        static async Task Main(string[] args)
        {
            var listener = new CustomEventListener();

            listener.EnableEvents(DefaultEventSource.Log, EventLevel.Warning);

            string storageConnectionString = Storage.StorageConnectionString;
            var    settings = new AzureStorageOrchestrationServiceSettings
            {
                StorageConnectionString = storageConnectionString,
                //TaskHubName = "PartitionTest",
                TaskHubName    = "PartitionTest",
                PartitionCount = 1,
                //MaxConcurrentTaskOrchestrationWorkItems = 100,
                //MaxConcurrentTaskActivityWorkItems = 10,
                //MaxStorageOperationConcurrency = Environment.ProcessorCount * 25,
            };

            var orchestrationServiceAndClient = new AzureStorageOrchestrationService(settings);
            //just for test
            await orchestrationServiceAndClient.DeleteAsync();

            //await Task.Delay(TimeSpan.FromSeconds(60));
            await orchestrationServiceAndClient.CreateIfNotExistsAsync();

            var taskHubClient = new TaskHubClient(orchestrationServiceAndClient);
            var taskHubWorker = new TaskHubWorker(orchestrationServiceAndClient);

            //1.create 1000** instance
            await Test.CreateMockOrchestrationInstancesAsync(40, 5, taskHubClient);

            //
            await Test.StartWorker(taskHubWorker);

            Console.WriteLine("Press any key to quit.");
            Console.ReadLine();
        }
Ejemplo n.º 10
0
        async Task <AzureStorageOrchestrationService> EnsureTaskHubAsync(
            string testName,
            bool testDeletion,
            bool deleteBeforeCreate = true,
            string workerId         = "test")
        {
            string storageConnectionString = TestHelpers.GetTestStorageAccountConnectionString();
            var    storageAccount          = CloudStorageAccount.Parse(storageConnectionString);

            string taskHubName = testName;
            var    settings    = new AzureStorageOrchestrationServiceSettings
            {
                TaskHubName             = taskHubName,
                StorageConnectionString = storageConnectionString,
                WorkerId = workerId,
            };

            Trace.TraceInformation($"Task Hub name: {taskHubName}");

            var service = new AzureStorageOrchestrationService(settings);

            if (deleteBeforeCreate)
            {
                await service.CreateAsync();
            }
            else
            {
                await service.CreateIfNotExistsAsync();
            }

            // Control queues
            Assert.IsNotNull(service.AllControlQueues, "Control queue collection was not initialized.");
            ControlQueue[] controlQueues = service.AllControlQueues.ToArray();
            Assert.AreEqual(4, controlQueues.Length, "Expected to see the default four control queues created.");
            foreach (ControlQueue queue in controlQueues)
            {
                Assert.IsTrue(await queue.InnerQueue.ExistsAsync(), $"Queue {queue.Name} was not created.");
            }

            // Work-item queue
            WorkItemQueue workItemQueue = service.WorkItemQueue;

            Assert.IsNotNull(workItemQueue, "Work-item queue client was not initialized.");
            Assert.IsTrue(await workItemQueue.InnerQueue.ExistsAsync(), $"Queue {workItemQueue.Name} was not created.");

            // TrackingStore
            ITrackingStore trackingStore = service.TrackingStore;

            Assert.IsNotNull(trackingStore, "Tracking Store was not initialized.");

            try
            {
                Assert.IsTrue(trackingStore.ExistsAsync().Result, $"Tracking Store was not created.");
            }
            catch (NotSupportedException)
            { }

            string             expectedContainerName = taskHubName.ToLowerInvariant() + "-leases";
            CloudBlobContainer taskHubContainer      = storageAccount.CreateCloudBlobClient().GetContainerReference(expectedContainerName);

            Assert.IsTrue(await taskHubContainer.ExistsAsync(), $"Task hub blob container {expectedContainerName} was not created.");

            // Task Hub config blob
            CloudBlob infoBlob = taskHubContainer.GetBlobReference("taskhub.json");

            Assert.IsTrue(await infoBlob.ExistsAsync(), $"The blob {infoBlob.Name} was not created.");

            // Task Hub lease container
            CloudBlobDirectory leaseDirectory = taskHubContainer.GetDirectoryReference("default");

            IListBlobItem[] leaseBlobs = (await this.ListBlobsAsync(leaseDirectory)).ToArray();
            Assert.AreEqual(controlQueues.Length, leaseBlobs.Length, "Expected to see the same number of control queues and lease blobs.");

            foreach (IListBlobItem blobItem in leaseBlobs)
            {
                string path = blobItem.Uri.AbsolutePath;
                Assert.IsTrue(
                    controlQueues.Where(q => path.Contains(q.Name)).Any(),
                    $"Could not find any known control queue name in the lease name {path}");
            }

            if (testDeletion)
            {
                await service.DeleteAsync();

                foreach (ControlQueue queue in controlQueues)
                {
                    Assert.IsFalse(await queue.InnerQueue.ExistsAsync(), $"Queue {queue.Name} was not deleted.");
                }

                Assert.IsFalse(await workItemQueue.InnerQueue.ExistsAsync(), $"Queue {workItemQueue.Name} was not deleted.");

                try
                {
                    Assert.IsFalse(trackingStore.ExistsAsync().Result, $"Tracking Store was not deleted.");
                }
                catch (NotSupportedException)
                { }

                Assert.IsFalse(await taskHubContainer.ExistsAsync(), $"Task hub blob container {taskHubContainer.Name} was not deleted.");
            }

            return(service);
        }