Skip to content

Commit f1862bd

Browse files
committed
Add support for Cloud Load Balancers (fixes #217)
1 parent 00bb43a commit f1862bd

82 files changed

Lines changed: 14745 additions & 5 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/corelib/Providers/Rackspace/CloudLoadBalancerProvider.cs

Lines changed: 2396 additions & 0 deletions
Large diffs are not rendered by default.

src/corelib/Providers/Rackspace/ILoadBalancerService.cs

Lines changed: 1415 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
namespace net.openstack.Providers.Rackspace.Objects.LoadBalancers
2+
{
3+
using System;
4+
using System.Collections.Concurrent;
5+
using net.openstack.Core;
6+
using Newtonsoft.Json;
7+
8+
/// <summary>
9+
/// Represents an network access type in the load balancers service.
10+
/// </summary>
11+
/// <remarks>
12+
/// This class functions as a strongly-typed enumeration of known access types,
13+
/// with added support for unknown types returned by a server extension.
14+
/// </remarks>
15+
/// <seealso href="http://docs.rackspace.com/loadbalancers/api/v1.0/clb-devguide/content/Manage_Access_Lists-d1e3187.html">Manage Access Lists (Rackspace Cloud Load Balancers Developer Guide - API v1.0)</seealso>
16+
/// <threadsafety static="true" instance="false"/>
17+
/// <preliminary/>
18+
[JsonConverter(typeof(AccessType.Converter))]
19+
public sealed class AccessType : ExtensibleEnum<AccessType>
20+
{
21+
private static readonly ConcurrentDictionary<string, AccessType> _types =
22+
new ConcurrentDictionary<string, AccessType>(StringComparer.OrdinalIgnoreCase);
23+
private static readonly AccessType _allow = FromName("ALLOW");
24+
private static readonly AccessType _deny = FromName("DENY");
25+
26+
/// <summary>
27+
/// Initializes a new instance of the <see cref="AccessType"/> class with the specified name.
28+
/// </summary>
29+
/// <inheritdoc/>
30+
private AccessType(string name)
31+
: base(name)
32+
{
33+
}
34+
35+
/// <summary>
36+
/// Gets the <see cref="AccessType"/> instance with the specified name.
37+
/// </summary>
38+
/// <param name="name">The name.</param>
39+
/// <exception cref="ArgumentNullException">If <paramref name="name"/> is <c>null</c>.</exception>
40+
/// <exception cref="ArgumentException">If <paramref name="name"/> is empty.</exception>
41+
public static AccessType FromName(string name)
42+
{
43+
if (name == null)
44+
throw new ArgumentNullException("name");
45+
if (string.IsNullOrEmpty(name))
46+
throw new ArgumentException("name cannot be empty");
47+
48+
return _types.GetOrAdd(name, i => new AccessType(i));
49+
}
50+
51+
/// <summary>
52+
/// Gets an <see cref="AccessType"/> representing an item to which traffic should be allowed.
53+
/// The <see cref="Allow"/> access type takes priority over the <see cref="Deny"/> access type.
54+
/// </summary>
55+
public static AccessType Allow
56+
{
57+
get
58+
{
59+
return _allow;
60+
}
61+
}
62+
63+
/// <summary>
64+
/// Gets an <see cref="AccessType"/> representing an item to which traffic can be denied.
65+
/// </summary>
66+
public static AccessType Deny
67+
{
68+
get
69+
{
70+
return _deny;
71+
}
72+
}
73+
74+
/// <summary>
75+
/// Provides support for serializing and deserializing <see cref="AccessType"/>
76+
/// objects to JSON string values.
77+
/// </summary>
78+
/// <threadsafety static="true" instance="false"/>
79+
/// <preliminary/>
80+
private sealed class Converter : ConverterBase
81+
{
82+
/// <inheritdoc/>
83+
protected override AccessType FromName(string name)
84+
{
85+
return AccessType.FromName(name);
86+
}
87+
}
88+
}
89+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
namespace net.openstack.Providers.Rackspace.Objects.LoadBalancers
2+
{
3+
using System;
4+
using Newtonsoft.Json;
5+
6+
/// <summary>
7+
/// This class models the JSON object used to represent a <see cref="HealthMonitor"/> for
8+
/// simple connection monitoring.
9+
/// </summary>
10+
/// <threadsafety static="true" instance="false"/>
11+
/// <preliminary/>
12+
[JsonObject(MemberSerialization.OptIn)]
13+
public class ConnectionHealthMonitor : HealthMonitor
14+
{
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="ConnectionHealthMonitor"/> class
17+
/// during JSON deserialization.
18+
/// </summary>
19+
[JsonConstructor]
20+
protected ConnectionHealthMonitor()
21+
{
22+
}
23+
24+
/// <summary>
25+
/// Initializes a new instance of the <see cref="ConnectionHealthMonitor"/> class
26+
/// with the specified values.
27+
/// </summary>
28+
/// <param name="attemptsBeforeDeactivation">The number of permissible monitor failures before removing a node from rotation.</param>
29+
/// <param name="timeout">The maximum number of seconds to wait for a connection to be established before timing out.</param>
30+
/// <param name="delay">The minimum time to wait before executing the health monitor.</param>
31+
/// <exception cref="ArgumentOutOfRangeException">
32+
/// If <paramref name="attemptsBeforeDeactivation"/> is less than or equal to 0.
33+
/// <para>-or-</para>
34+
/// <para>If <paramref name="timeout"/> is negative or <see cref="TimeSpan.Zero"/>.</para>
35+
/// <para>-or-</para>
36+
/// <para>If <paramref name="delay"/> is negative or <see cref="TimeSpan.Zero"/>.</para>
37+
/// </exception>
38+
public ConnectionHealthMonitor(int attemptsBeforeDeactivation, TimeSpan timeout, TimeSpan delay)
39+
: base(HealthMonitorType.Connect, attemptsBeforeDeactivation, timeout, delay)
40+
{
41+
}
42+
}
43+
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
namespace net.openstack.Providers.Rackspace.Objects.LoadBalancers
2+
{
3+
using System;
4+
using Newtonsoft.Json;
5+
6+
/// <summary>
7+
/// This class represents a connection throttling configuration for a load
8+
/// balancer in the load balancer service.
9+
/// </summary>
10+
/// <threadsafety static="true" instance="false"/>
11+
/// <preliminary/>
12+
[JsonObject(MemberSerialization.OptIn)]
13+
public class ConnectionThrottles
14+
{
15+
/// <summary>
16+
/// This is the backing field for the <see cref="MaxConnectionRate"/> property.
17+
/// </summary>
18+
[JsonProperty("maxConnectionRate", DefaultValueHandling = DefaultValueHandling.Ignore)]
19+
private int? _maxConnectionRate;
20+
21+
/// <summary>
22+
/// This is the backing field for the <see cref="MaxConnections"/> property.
23+
/// </summary>
24+
[JsonProperty("maxConnections", DefaultValueHandling = DefaultValueHandling.Ignore)]
25+
private int? _maxConnections;
26+
27+
/// <summary>
28+
/// This is the backing field for the <see cref="MinConnections"/> property.
29+
/// </summary>
30+
[JsonProperty("minConnections", DefaultValueHandling = DefaultValueHandling.Ignore)]
31+
private int? _minConnections;
32+
33+
/// <summary>
34+
/// This is the backing field for the <see cref="RateInterval"/> property.
35+
/// </summary>
36+
[JsonProperty("rateInterval", DefaultValueHandling = DefaultValueHandling.Ignore)]
37+
private int? _rateInterval;
38+
39+
/// <summary>
40+
/// Initializes a new instance of the <see cref="ConnectionThrottles"/> class during
41+
/// JSON deserialization.
42+
/// </summary>
43+
[JsonConstructor]
44+
protected ConnectionThrottles()
45+
{
46+
}
47+
48+
/// <summary>
49+
/// Initializes a new instance of the <see cref="ConnectionThrottles"/> class with
50+
/// the specified configuration.
51+
/// </summary>
52+
/// <param name="maxConnectionRate">The maximum number of connections per rate interval to allow from a single IP address, or <c>0</c> to not limit the connection rate. If this value is <c>null</c>, the value for this throttle will not be changed during a call to <see cref="ILoadBalancerService.UpdateThrottlesAsync"/>.</param>
53+
/// <param name="maxConnections">The maximum number of connections to allow from a single IP address, or <c>0</c> to not limit the number connections. If this value is <c>null</c>, the value for this throttle will not be changed during a call to <see cref="ILoadBalancerService.UpdateThrottlesAsync"/>.</param>
54+
/// <param name="minConnections">The minimum number of connections to allow from an IP address before applying throttling restrictions. If this value is <c>null</c>, the value for this throttle will not be changed during a call to <see cref="ILoadBalancerService.UpdateThrottlesAsync"/>.</param>
55+
/// <param name="rateInterval">The time period for which the connection rate limit is evaluated. If this value is <c>null</c>, the value for this throttle will not be changed during a call to <see cref="ILoadBalancerService.UpdateThrottlesAsync"/>.</param>
56+
/// <exception cref="ArgumentOutOfRangeException">
57+
/// If <paramref name="maxConnectionRate"/> is less than 0.
58+
/// <para>-or-</para>
59+
/// <para>If <paramref name="maxConnections"/> is less than 0.</para>
60+
/// <para>-or-</para>
61+
/// <para>If <paramref name="minConnections"/> is less than 0.</para>
62+
/// <para>-or-</para>
63+
/// <para>If <paramref name="rateInterval"/> is negative or <see cref="TimeSpan.Zero"/>.</para>
64+
/// </exception>
65+
public ConnectionThrottles(int? maxConnectionRate, int? maxConnections, int? minConnections, TimeSpan? rateInterval)
66+
{
67+
if (maxConnectionRate < 0)
68+
throw new ArgumentOutOfRangeException("maxConnectionRate");
69+
if (maxConnections < 0)
70+
throw new ArgumentOutOfRangeException("maxConnections");
71+
if (minConnections < 0)
72+
throw new ArgumentOutOfRangeException("minConnections");
73+
if (rateInterval <= TimeSpan.Zero)
74+
throw new ArgumentOutOfRangeException("rateInterval");
75+
76+
_maxConnectionRate = maxConnectionRate;
77+
_maxConnections = maxConnections;
78+
_minConnections = minConnections;
79+
_rateInterval = rateInterval != null ? (int?)rateInterval.Value.TotalSeconds : default(int?);
80+
}
81+
82+
/// <summary>
83+
/// Gets the maximum number of connections allowed from a single IP address in the defined <see cref="RateInterval"/>.
84+
/// A value of 0 indicates an unlimited connection rate. A value of <c>null</c> indicates this connection limit is
85+
/// not configured.
86+
/// </summary>
87+
/// <value>
88+
/// The maximum number of connections allowed from a single IP address in the defined <see cref="RateInterval"/>,
89+
/// or one of the following values:
90+
///
91+
/// <list type="bullet">
92+
/// <item>0, if the connection rate is configured but unlimited.</item>
93+
/// <item><c>null</c>, if the connection rate limit is not configured.</item>
94+
/// </list>
95+
/// </value>
96+
public int? MaxConnectionRate
97+
{
98+
get
99+
{
100+
return _maxConnectionRate;
101+
}
102+
}
103+
104+
/// <summary>
105+
/// Gets the maximum number of connections allowed for a single IP address. A value of 0 indicates
106+
/// an unlimited number of connections. A value of <c>null</c> indicates this connection limit is
107+
/// not configured.
108+
/// </summary>
109+
public int? MaxConnections
110+
{
111+
get
112+
{
113+
return _maxConnections;
114+
}
115+
}
116+
117+
/// <summary>
118+
/// Gets the minimum number of connections to allow from an IP address before applying throttling restrictions.
119+
/// A value of <c>null</c> indicates this connection limit is not configured.
120+
/// </summary>
121+
public int? MinConnections
122+
{
123+
get
124+
{
125+
return _minConnections;
126+
}
127+
}
128+
129+
/// <summary>
130+
/// Gets the time period for which <see cref="MaxConnectionRate"/> is evaluated. For example, a <see cref="MaxConnectionRate"/>
131+
/// of 30 with a <see cref="RateInterval"/> of 60 seconds would allow a maximum of 30 connections per minute from a single IP
132+
/// address. A value of <c>null</c> indicates this connection limit is not configured.
133+
/// </summary>
134+
public TimeSpan? RateInterval
135+
{
136+
get
137+
{
138+
if (_rateInterval == null)
139+
return null;
140+
141+
return TimeSpan.FromSeconds(_rateInterval.Value);
142+
}
143+
}
144+
}
145+
}

0 commit comments

Comments
 (0)