|
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 |
|
@@ -1337,19 +1338,108 @@ public Task ClearAccessListAsync(LoadBalancerId loadBalancerId, AsyncCompletionO |
1337 | 1338 | /// <inheritdoc/> |
1338 | 1339 | public Task<HealthMonitor> GetHealthMonitorAsync(LoadBalancerId loadBalancerId, CancellationToken cancellationToken) |
1339 | 1340 | { |
1340 | | - 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); |
1341 | 1373 | } |
1342 | 1374 |
|
1343 | 1375 | /// <inheritdoc/> |
1344 | 1376 | public Task SetHealthMonitorAsync(LoadBalancerId loadBalancerId, HealthMonitor monitor, AsyncCompletionOption completionOption, CancellationToken cancellationToken, IProgress<LoadBalancer> progress) |
1345 | 1377 | { |
1346 | | - 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(); |
1347 | 1409 | } |
1348 | 1410 |
|
1349 | 1411 | /// <inheritdoc/> |
1350 | 1412 | public Task RemoveHealthMonitorAsync(LoadBalancerId loadBalancerId, AsyncCompletionOption completionOption, CancellationToken cancellationToken, IProgress<LoadBalancer> progress) |
1351 | 1413 | { |
1352 | | - 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(); |
1353 | 1443 | } |
1354 | 1444 |
|
1355 | 1445 | /// <inheritdoc/> |
|
0 commit comments