Search in sources :

Example 6 with AWSDeferredResultAsyncHandler

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"));
    });
}
Also used : DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult) AWSDeferredResultAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler) LoadBalancerDescription(com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest)

Example 7 with AWSDeferredResultAsyncHandler

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);
}
Also used : AWSDeferredResultAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler) DeregisterInstancesFromLoadBalancerResult(com.amazonaws.services.elasticloadbalancing.model.DeregisterInstancesFromLoadBalancerResult) DeregisterInstancesFromLoadBalancerRequest(com.amazonaws.services.elasticloadbalancing.model.DeregisterInstancesFromLoadBalancerRequest)

Example 8 with AWSDeferredResultAsyncHandler

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);
}
Also used : AWSDeferredResultAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler) DeleteLoadBalancerRequest(com.amazonaws.services.elasticloadbalancing.model.DeleteLoadBalancerRequest) DeleteLoadBalancerResult(com.amazonaws.services.elasticloadbalancing.model.DeleteLoadBalancerResult)

Example 9 with AWSDeferredResultAsyncHandler

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;
    });
}
Also used : CreateLoadBalancerResult(com.amazonaws.services.elasticloadbalancing.model.CreateLoadBalancerResult) CreateLoadBalancerRequest(com.amazonaws.services.elasticloadbalancing.model.CreateLoadBalancerRequest) AWSDeferredResultAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler)

Example 10 with AWSDeferredResultAsyncHandler

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);
}
Also used : AWSDeferredResultAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler) ConfigureHealthCheckRequest(com.amazonaws.services.elasticloadbalancing.model.ConfigureHealthCheckRequest) ConfigureHealthCheckResult(com.amazonaws.services.elasticloadbalancing.model.ConfigureHealthCheckResult)

Aggregations

AWSDeferredResultAsyncHandler (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler)10 Filter (com.amazonaws.services.ec2.model.Filter)3 DeferredResult (com.vmware.xenon.common.DeferredResult)3 ArrayList (java.util.ArrayList)3 DescribeSubnetsRequest (com.amazonaws.services.ec2.model.DescribeSubnetsRequest)2 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)2 DescribeVpcsRequest (com.amazonaws.services.ec2.model.DescribeVpcsRequest)2 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)1 CreateSubnetRequest (com.amazonaws.services.ec2.model.CreateSubnetRequest)1 CreateSubnetResult (com.amazonaws.services.ec2.model.CreateSubnetResult)1 DescribeAvailabilityZonesRequest (com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest)1 DescribeAvailabilityZonesResult (com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult)1 InstanceNetworkInterfaceSpecification (com.amazonaws.services.ec2.model.InstanceNetworkInterfaceSpecification)1 Subnet (com.amazonaws.services.ec2.model.Subnet)1 Tag (com.amazonaws.services.ec2.model.Tag)1 Vpc (com.amazonaws.services.ec2.model.Vpc)1 ConfigureHealthCheckRequest (com.amazonaws.services.elasticloadbalancing.model.ConfigureHealthCheckRequest)1 ConfigureHealthCheckResult (com.amazonaws.services.elasticloadbalancing.model.ConfigureHealthCheckResult)1