use of com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler in project photon-model by vmware.
the class AWSLoadBalancerService method getAWSLoadBalancer.
private DeferredResult<AWSLoadBalancerContext> getAWSLoadBalancer(AWSLoadBalancerContext context) {
DescribeLoadBalancersRequest describeRequest = new DescribeLoadBalancersRequest().withLoadBalancerNames(context.loadBalancerStateExpanded.name);
String message = "Describing AWS load balancer [" + context.loadBalancerStateExpanded.name + "].";
AWSDeferredResultAsyncHandler<DescribeLoadBalancersRequest, DescribeLoadBalancersResult> handler = new AWSDeferredResultAsyncHandler<>(this, message);
context.client.describeLoadBalancersAsync(describeRequest, handler);
return handler.toDeferredResult().thenCompose(result -> {
List<com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription> lbs = result.getLoadBalancerDescriptions();
if (lbs != null && !lbs.isEmpty() && lbs.size() == 1) {
context.registeredInstances = lbs.iterator().next().getInstances();
return DeferredResult.completed(context);
}
return DeferredResult.failed(new IllegalStateException("Unable to describe load balancer with name '" + context.loadBalancerStateExpanded.name + "' for update"));
});
}
use of com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler in project photon-model by vmware.
the class AWSLoadBalancerService method deregisterInstances.
private DeferredResult<AWSLoadBalancerContext> deregisterInstances(AWSLoadBalancerContext context) {
// Do not try to deregister instances if there aren't any
if (context.instanceIdsToDeregister.isEmpty()) {
return DeferredResult.completed(context);
}
DeregisterInstancesFromLoadBalancerRequest request = buildInstanceDeregistrationRequest(context);
String message = "Deregistering instances to AWS Load Balancer with name [" + context.loadBalancerStateExpanded.name + "]";
AWSDeferredResultAsyncHandler<DeregisterInstancesFromLoadBalancerRequest, DeregisterInstancesFromLoadBalancerResult> handler = new AWSDeferredResultAsyncHandler<>(this, message);
context.client.deregisterInstancesFromLoadBalancerAsync(request, handler);
return handler.toDeferredResult().thenApply(ignore -> context);
}
use of com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler in project photon-model by vmware.
the class AWSLoadBalancerService method deleteLoadBalancer.
private DeferredResult<AWSLoadBalancerContext> deleteLoadBalancer(AWSLoadBalancerContext context) {
DeleteLoadBalancerRequest request = new DeleteLoadBalancerRequest().withLoadBalancerName(context.loadBalancerStateExpanded.name);
String message = "Delete AWS Load Balancer with name [" + context.loadBalancerStateExpanded.name + "]";
AWSDeferredResultAsyncHandler<DeleteLoadBalancerRequest, DeleteLoadBalancerResult> handler = new AWSDeferredResultAsyncHandler<>(this, message);
context.client.deleteLoadBalancerAsync(request, handler);
return handler.toDeferredResult().thenApply(ignore -> context);
}
use of com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler in project photon-model by vmware.
the class AWSLoadBalancerService method createLoadBalancer.
private DeferredResult<AWSLoadBalancerContext> createLoadBalancer(AWSLoadBalancerContext context) {
CreateLoadBalancerRequest request = buildCreationRequest(context);
String message = "Create a new AWS Load Balancer with name [" + context.loadBalancerStateExpanded.name + "].";
AWSDeferredResultAsyncHandler<CreateLoadBalancerRequest, CreateLoadBalancerResult> handler = new AWSDeferredResultAsyncHandler<>(this, message);
context.client.createLoadBalancerAsync(request, handler);
return handler.toDeferredResult().thenApply(result -> {
context.loadBalancerStateExpanded.address = result.getDNSName();
return context;
});
}
use of com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler in project photon-model by vmware.
the class AWSLoadBalancerService method configureHealthCheck.
private DeferredResult<AWSLoadBalancerContext> configureHealthCheck(AWSLoadBalancerContext context) {
ConfigureHealthCheckRequest request = buildHealthCheckRequest(context);
if (request == null) {
return DeferredResult.completed(context);
}
String message = "Configure a health check to AWS Load Balancer with name [" + context.loadBalancerStateExpanded.name + "].";
AWSDeferredResultAsyncHandler<ConfigureHealthCheckRequest, ConfigureHealthCheckResult> handler = new AWSDeferredResultAsyncHandler<>(this, message);
context.client.configureHealthCheckAsync(request, handler);
return handler.toDeferredResult().thenApply(ignore -> context);
}
Aggregations