|
14 | 14 | using net.openstack.Providers.Rackspace.Objects.LoadBalancers.Request; |
15 | 15 | using net.openstack.Providers.Rackspace.Objects.LoadBalancers.Response; |
16 | 16 | using net.openstack.Providers.Rackspace.Validators; |
| 17 | + using Newtonsoft.Json.Linq; |
17 | 18 | using CancellationToken = System.Threading.CancellationToken; |
18 | 19 | using JsonRestServices = JSIStudios.SimpleRESTServices.Client.Json.JsonRestServices; |
19 | 20 |
|
@@ -945,25 +946,119 @@ public Task<IEnumerable<string>> ListAllowedDomainsAsync(CancellationToken cance |
945 | 946 | /// <inheritdoc/> |
946 | 947 | public Task<IEnumerable<LoadBalancer>> ListBillableLoadBalancersAsync(DateTimeOffset? startTime, DateTimeOffset? endTime, int? offset, int? limit, CancellationToken cancellationToken) |
947 | 948 | { |
948 | | - throw new NotImplementedException(); |
| 949 | + if (endTime < startTime) |
| 950 | + throw new ArgumentOutOfRangeException("endTime"); |
| 951 | + if (offset < 0) |
| 952 | + throw new ArgumentOutOfRangeException("offset"); |
| 953 | + if (limit <= 0) |
| 954 | + throw new ArgumentOutOfRangeException("limit"); |
| 955 | + |
| 956 | + UriTemplate template = new UriTemplate("/loadbalancers/billable?startTime={startTime}&endTime={endTime}&offset={offset}&limit={limit}"); |
| 957 | + var parameters = new Dictionary<string, string>(); |
| 958 | + if (startTime != null) |
| 959 | + parameters.Add("startTime", startTime.Value.ToString("yyyy-MM-dd")); |
| 960 | + if (endTime != null) |
| 961 | + parameters.Add("endTime", endTime.Value.ToString("yyyy-MM-dd")); |
| 962 | + if (offset != null) |
| 963 | + parameters.Add("offset", offset.ToString()); |
| 964 | + if (limit != null) |
| 965 | + parameters.Add("limit", limit.ToString()); |
| 966 | + |
| 967 | + Func<Task<Tuple<IdentityToken, Uri>>, HttpWebRequest> prepareRequest = |
| 968 | + PrepareRequestAsyncFunc(HttpMethod.GET, template, parameters); |
| 969 | + |
| 970 | + Func<Task<HttpWebRequest>, Task<ListLoadBalancersResponse>> requestResource = |
| 971 | + GetResponseAsyncFunc<ListLoadBalancersResponse>(cancellationToken); |
| 972 | + |
| 973 | + Func<Task<ListLoadBalancersResponse>, IEnumerable<LoadBalancer>> resultSelector = |
| 974 | + task => (task.Result != null ? task.Result.LoadBalancers : null) ?? Enumerable.Empty<LoadBalancer>(); |
| 975 | + |
| 976 | + return AuthenticateServiceAsync(cancellationToken) |
| 977 | + .ContinueWith(prepareRequest) |
| 978 | + .ContinueWith(requestResource).Unwrap() |
| 979 | + .ContinueWith(resultSelector); |
949 | 980 | } |
950 | 981 |
|
951 | 982 | /// <inheritdoc/> |
952 | 983 | public Task<IEnumerable<LoadBalancerUsage>> ListAccountLevelUsageAsync(DateTimeOffset? startTime, DateTimeOffset? endTime, CancellationToken cancellationToken) |
953 | 984 | { |
954 | | - throw new NotImplementedException(); |
| 985 | + if (endTime < startTime) |
| 986 | + throw new ArgumentOutOfRangeException("endTime"); |
| 987 | + |
| 988 | + UriTemplate template = new UriTemplate("/loadbalancers/usage?startTime={startTime}&endTime={endTime}"); |
| 989 | + var parameters = new Dictionary<string, string>(); |
| 990 | + if (startTime != null) |
| 991 | + parameters.Add("startTime", startTime.Value.ToString("yyyy-MM-dd")); |
| 992 | + if (endTime != null) |
| 993 | + parameters.Add("endTime", endTime.Value.ToString("yyyy-MM-dd")); |
| 994 | + |
| 995 | + Func<Task<Tuple<IdentityToken, Uri>>, HttpWebRequest> prepareRequest = |
| 996 | + PrepareRequestAsyncFunc(HttpMethod.GET, template, parameters); |
| 997 | + |
| 998 | + Func<Task<HttpWebRequest>, Task<ListLoadBalancerUsageResponse>> requestResource = |
| 999 | + GetResponseAsyncFunc<ListLoadBalancerUsageResponse>(cancellationToken); |
| 1000 | + |
| 1001 | + Func<Task<ListLoadBalancerUsageResponse>, IEnumerable<LoadBalancerUsage>> resultSelector = |
| 1002 | + task => (task.Result != null ? task.Result.UsageRecords : null) ?? Enumerable.Empty<LoadBalancerUsage>(); |
| 1003 | + |
| 1004 | + return AuthenticateServiceAsync(cancellationToken) |
| 1005 | + .ContinueWith(prepareRequest) |
| 1006 | + .ContinueWith(requestResource).Unwrap() |
| 1007 | + .ContinueWith(resultSelector); |
955 | 1008 | } |
956 | 1009 |
|
957 | 1010 | /// <inheritdoc/> |
958 | | - public Task<IEnumerable<LoadBalancerUsage>> ListHistoricalUsageAsync(LoadBalancerId loadBalancerId, DateTimeOffset? startTime, DateTimeOffset? endTime, CancellationToken cancellationToken1) |
| 1011 | + public Task<IEnumerable<LoadBalancerUsage>> ListHistoricalUsageAsync(LoadBalancerId loadBalancerId, DateTimeOffset? startTime, DateTimeOffset? endTime, CancellationToken cancellationToken) |
959 | 1012 | { |
960 | | - throw new NotImplementedException(); |
| 1013 | + if (loadBalancerId == null) |
| 1014 | + throw new ArgumentNullException("loadBalancerId"); |
| 1015 | + if (endTime < startTime) |
| 1016 | + throw new ArgumentOutOfRangeException("endTime"); |
| 1017 | + |
| 1018 | + UriTemplate template = new UriTemplate("/loadbalancers/{loadBalancerId}/usage?startTime={startTime}&endTime={endTime}"); |
| 1019 | + var parameters = new Dictionary<string, string> { { "loadBalancerId", loadBalancerId.Value } }; |
| 1020 | + if (startTime != null) |
| 1021 | + parameters.Add("startTime", startTime.Value.ToString("yyyy-MM-dd")); |
| 1022 | + if (endTime != null) |
| 1023 | + parameters.Add("endTime", endTime.Value.ToString("yyyy-MM-dd")); |
| 1024 | + |
| 1025 | + Func<Task<Tuple<IdentityToken, Uri>>, HttpWebRequest> prepareRequest = |
| 1026 | + PrepareRequestAsyncFunc(HttpMethod.GET, template, parameters); |
| 1027 | + |
| 1028 | + Func<Task<HttpWebRequest>, Task<ListLoadBalancerUsageResponse>> requestResource = |
| 1029 | + GetResponseAsyncFunc<ListLoadBalancerUsageResponse>(cancellationToken); |
| 1030 | + |
| 1031 | + Func<Task<ListLoadBalancerUsageResponse>, IEnumerable<LoadBalancerUsage>> resultSelector = |
| 1032 | + task => (task.Result != null ? task.Result.UsageRecords : null) ?? Enumerable.Empty<LoadBalancerUsage>(); |
| 1033 | + |
| 1034 | + return AuthenticateServiceAsync(cancellationToken) |
| 1035 | + .ContinueWith(prepareRequest) |
| 1036 | + .ContinueWith(requestResource).Unwrap() |
| 1037 | + .ContinueWith(resultSelector); |
961 | 1038 | } |
962 | 1039 |
|
963 | 1040 | /// <inheritdoc/> |
964 | 1041 | public Task<IEnumerable<LoadBalancerUsage>> ListCurrentUsageAsync(LoadBalancerId loadBalancerId, CancellationToken cancellationToken) |
965 | 1042 | { |
966 | | - throw new NotImplementedException(); |
| 1043 | + if (loadBalancerId == null) |
| 1044 | + throw new ArgumentNullException("loadBalancerId"); |
| 1045 | + |
| 1046 | + UriTemplate template = new UriTemplate("/loadbalancers/{loadBalancerId}/usage/current"); |
| 1047 | + var parameters = new Dictionary<string, string> { { "loadBalancerId", loadBalancerId.Value } }; |
| 1048 | + |
| 1049 | + Func<Task<Tuple<IdentityToken, Uri>>, HttpWebRequest> prepareRequest = |
| 1050 | + PrepareRequestAsyncFunc(HttpMethod.GET, template, parameters); |
| 1051 | + |
| 1052 | + Func<Task<HttpWebRequest>, Task<ListLoadBalancerUsageResponse>> requestResource = |
| 1053 | + GetResponseAsyncFunc<ListLoadBalancerUsageResponse>(cancellationToken); |
| 1054 | + |
| 1055 | + Func<Task<ListLoadBalancerUsageResponse>, IEnumerable<LoadBalancerUsage>> resultSelector = |
| 1056 | + task => (task.Result != null ? task.Result.UsageRecords : null) ?? Enumerable.Empty<LoadBalancerUsage>(); |
| 1057 | + |
| 1058 | + return AuthenticateServiceAsync(cancellationToken) |
| 1059 | + .ContinueWith(prepareRequest) |
| 1060 | + .ContinueWith(requestResource).Unwrap() |
| 1061 | + .ContinueWith(resultSelector); |
967 | 1062 | } |
968 | 1063 |
|
969 | 1064 | /// <inheritdoc/> |
@@ -1243,19 +1338,108 @@ public Task ClearAccessListAsync(LoadBalancerId loadBalancerId, AsyncCompletionO |
1243 | 1338 | /// <inheritdoc/> |
1244 | 1339 | public Task<HealthMonitor> GetHealthMonitorAsync(LoadBalancerId loadBalancerId, CancellationToken cancellationToken) |
1245 | 1340 | { |
1246 | | - throw new NotImplementedException(); |
| 1341 | + if (loadBalancerId == null) |
| 1342 | + throw new ArgumentNullException("loadBalancerId"); |
| 1343 | + |
| 1344 | + UriTemplate template = new UriTemplate("/loadbalancers/{loadBalancerId}/healthmonitor"); |
| 1345 | + var parameters = new Dictionary<string, string>() |
| 1346 | + { |
| 1347 | + { "loadBalancerId", loadBalancerId.Value } |
| 1348 | + }; |
| 1349 | + |
| 1350 | + Func<Task<Tuple<IdentityToken, Uri>>, HttpWebRequest> prepareRequest = |
| 1351 | + PrepareRequestAsyncFunc(HttpMethod.GET, template, parameters); |
| 1352 | + |
| 1353 | + Func<Task<HttpWebRequest>, Task<JObject>> requestResource = |
| 1354 | + GetResponseAsyncFunc<JObject>(cancellationToken); |
| 1355 | + |
| 1356 | + Func<Task<JObject>, HealthMonitor> resultSelector = |
| 1357 | + task => |
| 1358 | + { |
| 1359 | + if (task.Result == null) |
| 1360 | + return null; |
| 1361 | + |
| 1362 | + JObject healthMonitorObject = task.Result["healthMonitor"] as JObject; |
| 1363 | + if (healthMonitorObject == null) |
| 1364 | + return null; |
| 1365 | + |
| 1366 | + return HealthMonitor.FromJObject(healthMonitorObject); |
| 1367 | + }; |
| 1368 | + |
| 1369 | + return AuthenticateServiceAsync(cancellationToken) |
| 1370 | + .ContinueWith(prepareRequest) |
| 1371 | + .ContinueWith(requestResource).Unwrap() |
| 1372 | + .ContinueWith(resultSelector); |
1247 | 1373 | } |
1248 | 1374 |
|
1249 | 1375 | /// <inheritdoc/> |
1250 | 1376 | public Task SetHealthMonitorAsync(LoadBalancerId loadBalancerId, HealthMonitor monitor, AsyncCompletionOption completionOption, CancellationToken cancellationToken, IProgress<LoadBalancer> progress) |
1251 | 1377 | { |
1252 | | - throw new NotImplementedException(); |
| 1378 | + if (loadBalancerId == null) |
| 1379 | + throw new ArgumentNullException("loadBalancerId"); |
| 1380 | + if (monitor == null) |
| 1381 | + throw new ArgumentNullException("monitor"); |
| 1382 | + |
| 1383 | + UriTemplate template = new UriTemplate("/loadbalancers/{loadBalancerId}/healthmonitor"); |
| 1384 | + var parameters = new Dictionary<string, string>() |
| 1385 | + { |
| 1386 | + { "loadBalancerId", loadBalancerId.Value } |
| 1387 | + }; |
| 1388 | + |
| 1389 | + Func<Task<Tuple<IdentityToken, Uri>>, Task<HttpWebRequest>> prepareRequest = |
| 1390 | + PrepareRequestAsyncFunc(HttpMethod.PUT, template, parameters, monitor); |
| 1391 | + |
| 1392 | + Func<Task<HttpWebRequest>, Task<string>> requestResource = |
| 1393 | + GetResponseAsyncFunc(cancellationToken); |
| 1394 | + |
| 1395 | + Func<Task<string>, Task<LoadBalancer>> resultSelector = |
| 1396 | + task => |
| 1397 | + { |
| 1398 | + task.PropagateExceptions(); |
| 1399 | + if (completionOption == AsyncCompletionOption.RequestCompleted) |
| 1400 | + return WaitForLoadBalancerToLeaveStateAsync(loadBalancerId, LoadBalancerStatus.PendingUpdate, cancellationToken, progress); |
| 1401 | + |
| 1402 | + return InternalTaskExtensions.CompletedTask(default(LoadBalancer)); |
| 1403 | + }; |
| 1404 | + |
| 1405 | + return AuthenticateServiceAsync(cancellationToken) |
| 1406 | + .ContinueWith(prepareRequest).Unwrap() |
| 1407 | + .ContinueWith(requestResource).Unwrap() |
| 1408 | + .ContinueWith(resultSelector).Unwrap(); |
1253 | 1409 | } |
1254 | 1410 |
|
1255 | 1411 | /// <inheritdoc/> |
1256 | 1412 | public Task RemoveHealthMonitorAsync(LoadBalancerId loadBalancerId, AsyncCompletionOption completionOption, CancellationToken cancellationToken, IProgress<LoadBalancer> progress) |
1257 | 1413 | { |
1258 | | - throw new NotImplementedException(); |
| 1414 | + if (loadBalancerId == null) |
| 1415 | + throw new ArgumentNullException("loadBalancerId"); |
| 1416 | + |
| 1417 | + UriTemplate template = new UriTemplate("/loadbalancers/{loadBalancerId}/healthmonitor"); |
| 1418 | + var parameters = new Dictionary<string, string>() |
| 1419 | + { |
| 1420 | + { "loadBalancerId", loadBalancerId.Value }, |
| 1421 | + }; |
| 1422 | + |
| 1423 | + Func<Task<Tuple<IdentityToken, Uri>>, HttpWebRequest> prepareRequest = |
| 1424 | + PrepareRequestAsyncFunc(HttpMethod.DELETE, template, parameters); |
| 1425 | + |
| 1426 | + Func<Task<HttpWebRequest>, Task<string>> requestResource = |
| 1427 | + GetResponseAsyncFunc(cancellationToken); |
| 1428 | + |
| 1429 | + Func<Task<string>, Task<LoadBalancer>> resultSelector = |
| 1430 | + task => |
| 1431 | + { |
| 1432 | + task.PropagateExceptions(); |
| 1433 | + if (completionOption == AsyncCompletionOption.RequestCompleted) |
| 1434 | + return WaitForLoadBalancerToLeaveStateAsync(loadBalancerId, LoadBalancerStatus.PendingUpdate, cancellationToken, progress); |
| 1435 | + |
| 1436 | + return InternalTaskExtensions.CompletedTask(default(LoadBalancer)); |
| 1437 | + }; |
| 1438 | + |
| 1439 | + return AuthenticateServiceAsync(cancellationToken) |
| 1440 | + .ContinueWith(prepareRequest) |
| 1441 | + .ContinueWith(requestResource).Unwrap() |
| 1442 | + .ContinueWith(resultSelector).Unwrap(); |
1259 | 1443 | } |
1260 | 1444 |
|
1261 | 1445 | /// <inheritdoc/> |
|
0 commit comments