コード例 #1
0
        public async Task TestListNodeServiceEvents()
        {
            ILoadBalancerService provider = CreateProvider();
            using (CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TestTimeout(TimeSpan.FromSeconds(60))))
            {
                IPHostEntry entry = await Task.Factory.FromAsync<IPHostEntry>(Dns.BeginGetHostEntry("docs.rackspace.com", null, null), Dns.EndGetHostEntry);

                IEnumerable<LoadBalancingProtocol> protocols = await provider.ListProtocolsAsync(cancellationTokenSource.Token);
                LoadBalancingProtocol httpProtocol = protocols.First(i => i.Name.Equals("HTTP", StringComparison.OrdinalIgnoreCase));

                string loadBalancerName = CreateRandomLoadBalancerName();

                LoadBalancerConfiguration configuration = new LoadBalancerConfiguration(
                    name: loadBalancerName,
                    nodes: new[] { new NodeConfiguration(entry.AddressList[0], 80, NodeCondition.Enabled, NodeType.Primary, null) },
                    protocol: httpProtocol,
                    virtualAddresses: new[] { new LoadBalancerVirtualAddress(LoadBalancerVirtualAddressType.ServiceNet) },
                    algorithm: LoadBalancingAlgorithm.RoundRobin);
                LoadBalancer tempLoadBalancer = await provider.CreateLoadBalancerAsync(configuration, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null);
                Node node = tempLoadBalancer.Nodes.Single();
                Assert.AreEqual(LoadBalancerStatus.Active, tempLoadBalancer.Status);

                NodeUpdate updatedNodeConfiguration = new NodeUpdate(condition: NodeCondition.Draining);
                await provider.UpdateNodeAsync(tempLoadBalancer.Id, node.Id, updatedNodeConfiguration, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null);

                NodeServiceEvent[] serviceEvents = ListAllNodeServiceEvents(provider, tempLoadBalancer.Id, null, cancellationTokenSource.Token).ToArray();
                if (!serviceEvents.Any())
                    Assert.Inconclusive("The load balancer did not report any node service events.");

                /* Cleanup
                 */

                await provider.RemoveLoadBalancerAsync(tempLoadBalancer.Id, AsyncCompletionOption.RequestCompleted, cancellationTokenSource.Token, null);
            }
        }
コード例 #2
0
        public static void UpdateNode(this ILoadBalancerService service, LoadBalancerId loadBalancerId, NodeId nodeId, NodeUpdate configuration)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                service.UpdateNodeAsync(loadBalancerId, nodeId, configuration, AsyncCompletionOption.RequestSubmitted, CancellationToken.None, null).Wait();
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }