Search in sources :

Example 1 with CreateLoadBalancerResult

use of com.amazonaws.services.elasticloadbalancing.model.CreateLoadBalancerResult in project photon-model by vmware.

the class TestAWSSetupUtils method provisionAWSLoadBalancerWithEC2Client.

public static String provisionAWSLoadBalancerWithEC2Client(VerificationHost host, AmazonElasticLoadBalancingAsyncClient client, String name, String subnetId, String securityGroupId, List<String> instanceIds) {
    if (name == null) {
        name = LOAD_BALANCER_NAME_PREFIX + System.currentTimeMillis();
    }
    Listener defaultListener = new Listener().withInstancePort(80).withInstanceProtocol("HTTP").withLoadBalancerPort(80).withProtocol("HTTP");
    CreateLoadBalancerRequest request = new CreateLoadBalancerRequest().withLoadBalancerName(name).withSubnets(Collections.singletonList(subnetId)).withSecurityGroups(Collections.singleton(securityGroupId)).withListeners(Collections.singleton(defaultListener));
    CreateLoadBalancerResult result = null;
    try {
        result = client.createLoadBalancer(request);
    } catch (Exception e) {
        host.log(Level.SEVERE, "Error encountered in provisioning load balancer on AWS: %s", Utils.toString(e));
    }
    assertNotNull(result);
    assertNotNull(result.getDNSName());
    if (instanceIds != null) {
        registerAWSInstancesToLoadBalancer(host, client, name, instanceIds);
    }
    return name;
}
Also used : CreateLoadBalancerResult(com.amazonaws.services.elasticloadbalancing.model.CreateLoadBalancerResult) Listener(com.amazonaws.services.elasticloadbalancing.model.Listener) CreateLoadBalancerRequest(com.amazonaws.services.elasticloadbalancing.model.CreateLoadBalancerRequest) UnknownHostException(java.net.UnknownHostException) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) TimeoutException(java.util.concurrent.TimeoutException)

Example 2 with CreateLoadBalancerResult

use of com.amazonaws.services.elasticloadbalancing.model.CreateLoadBalancerResult 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)

Aggregations

CreateLoadBalancerRequest (com.amazonaws.services.elasticloadbalancing.model.CreateLoadBalancerRequest)2 CreateLoadBalancerResult (com.amazonaws.services.elasticloadbalancing.model.CreateLoadBalancerResult)2 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)1 Listener (com.amazonaws.services.elasticloadbalancing.model.Listener)1 AWSDeferredResultAsyncHandler (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler)1 UnknownHostException (java.net.UnknownHostException)1 TimeoutException (java.util.concurrent.TimeoutException)1