Search in sources :

Example 1 with CreateLoadBalancerRequest

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

the class AWSLoadBalancerService method buildCreationRequest.

private CreateLoadBalancerRequest buildCreationRequest(AWSLoadBalancerContext context) {
    // Combine all security groups associated with the LB to a single list
    Collection<SecurityGroupState> securityGroupsToUse = new ArrayList<>();
    if (context.provisionedSecurityGroupState != null) {
        securityGroupsToUse.add(context.provisionedSecurityGroupState);
    }
    if (context.securityGroupStates != null && !context.securityGroupStates.isEmpty()) {
        securityGroupsToUse.addAll(context.securityGroupStates);
    }
    CreateLoadBalancerRequest request = new CreateLoadBalancerRequest().withLoadBalancerName(context.loadBalancerStateExpanded.name).withListeners(buildListeners(context)).withSubnets(context.loadBalancerStateExpanded.subnets.stream().map(subnet -> subnet.id).collect(Collectors.toList())).withSecurityGroups(securityGroupsToUse.stream().map(sg -> sg.id).collect(Collectors.toList()));
    // created
    if (!Boolean.TRUE.equals(context.loadBalancerStateExpanded.internetFacing)) {
        request.setScheme("internal");
    }
    return request;
}
Also used : CreateLoadBalancerResult(com.amazonaws.services.elasticloadbalancing.model.CreateLoadBalancerResult) Protocol(com.vmware.photon.controller.model.resources.SecurityGroupService.Protocol) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) RegisterInstancesWithLoadBalancerRequest(com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerRequest) ServiceTypeCluster(com.vmware.photon.controller.model.util.ClusterUtil.ServiceTypeCluster) CreateLoadBalancerRequest(com.amazonaws.services.elasticloadbalancing.model.CreateLoadBalancerRequest) AWSClientManagerFactory.returnClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory.returnClientManager) LoadBalancerState(com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerState) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) URI(java.net.URI) AWSClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager) HealthCheckConfiguration(com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription.HealthCheckConfiguration) StatelessService(com.vmware.xenon.common.StatelessService) DeleteLoadBalancerRequest(com.amazonaws.services.elasticloadbalancing.model.DeleteLoadBalancerRequest) Instance(com.amazonaws.services.elasticloadbalancing.model.Instance) Collection(java.util.Collection) TaskManager(com.vmware.photon.controller.model.adapters.util.TaskManager) Collectors(java.util.stream.Collectors) AmazonElasticLoadBalancingAsyncClient(com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancingAsyncClient) List(java.util.List) DeferredResult(com.vmware.xenon.common.DeferredResult) UriUtils(com.vmware.xenon.common.UriUtils) DeregisterInstancesFromLoadBalancerResult(com.amazonaws.services.elasticloadbalancing.model.DeregisterInstancesFromLoadBalancerResult) AWSDeferredResultAsyncHandler(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler) FACTORY_LINK(com.vmware.photon.controller.model.resources.SecurityGroupService.FACTORY_LINK) SecurityGroupInstanceRequest(com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest) ConfigureHealthCheckResult(com.amazonaws.services.elasticloadbalancing.model.ConfigureHealthCheckResult) ComputeProperties(com.vmware.photon.controller.model.ComputeProperties) ConfigureHealthCheckRequest(com.amazonaws.services.elasticloadbalancing.model.ConfigureHealthCheckRequest) NETWORK_STATE_ID_PROP_NAME(com.vmware.photon.controller.model.tasks.ProvisionSecurityGroupTaskService.NETWORK_STATE_ID_PROP_NAME) HashMap(java.util.HashMap) DescribeLoadBalancersRequest(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest) RegisterInstancesWithLoadBalancerResult(com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerResult) HealthCheck(com.amazonaws.services.elasticloadbalancing.model.HealthCheck) ArrayList(java.util.ArrayList) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) Rule(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState.Rule) HashSet(java.util.HashSet) LoadBalancerDescription(com.vmware.photon.controller.model.resources.LoadBalancerDescriptionService.LoadBalancerDescription) Listener(com.amazonaws.services.elasticloadbalancing.model.Listener) InstanceRequestType(com.vmware.photon.controller.model.adapterapi.SecurityGroupInstanceRequest.InstanceRequestType) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) DeregisterInstancesFromLoadBalancerRequest(com.amazonaws.services.elasticloadbalancing.model.DeregisterInstancesFromLoadBalancerRequest) LoadBalancerStateExpanded(com.vmware.photon.controller.model.resources.LoadBalancerService.LoadBalancerStateExpanded) Operation(com.vmware.xenon.common.Operation) DeleteLoadBalancerResult(com.amazonaws.services.elasticloadbalancing.model.DeleteLoadBalancerResult) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) DescribeLoadBalancersResult(com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult) LoadBalancerInstanceRequest(com.vmware.photon.controller.model.adapterapi.LoadBalancerInstanceRequest) AWSClientManagerFactory(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Collections(java.util.Collections) PhotonModelUriUtils.createInventoryUri(com.vmware.photon.controller.model.util.PhotonModelUriUtils.createInventoryUri) CreateLoadBalancerRequest(com.amazonaws.services.elasticloadbalancing.model.CreateLoadBalancerRequest) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) ArrayList(java.util.ArrayList)

Example 2 with CreateLoadBalancerRequest

use of com.amazonaws.services.elasticloadbalancing.model.CreateLoadBalancerRequest 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 3 with CreateLoadBalancerRequest

use of com.amazonaws.services.elasticloadbalancing.model.CreateLoadBalancerRequest 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)3 CreateLoadBalancerResult (com.amazonaws.services.elasticloadbalancing.model.CreateLoadBalancerResult)3 Listener (com.amazonaws.services.elasticloadbalancing.model.Listener)2 AWSDeferredResultAsyncHandler (com.vmware.photon.controller.model.adapters.awsadapter.util.AWSDeferredResultAsyncHandler)2 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)1 AmazonElasticLoadBalancingAsyncClient (com.amazonaws.services.elasticloadbalancing.AmazonElasticLoadBalancingAsyncClient)1 ConfigureHealthCheckRequest (com.amazonaws.services.elasticloadbalancing.model.ConfigureHealthCheckRequest)1 ConfigureHealthCheckResult (com.amazonaws.services.elasticloadbalancing.model.ConfigureHealthCheckResult)1 DeleteLoadBalancerRequest (com.amazonaws.services.elasticloadbalancing.model.DeleteLoadBalancerRequest)1 DeleteLoadBalancerResult (com.amazonaws.services.elasticloadbalancing.model.DeleteLoadBalancerResult)1 DeregisterInstancesFromLoadBalancerRequest (com.amazonaws.services.elasticloadbalancing.model.DeregisterInstancesFromLoadBalancerRequest)1 DeregisterInstancesFromLoadBalancerResult (com.amazonaws.services.elasticloadbalancing.model.DeregisterInstancesFromLoadBalancerResult)1 DescribeLoadBalancersRequest (com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersRequest)1 DescribeLoadBalancersResult (com.amazonaws.services.elasticloadbalancing.model.DescribeLoadBalancersResult)1 HealthCheck (com.amazonaws.services.elasticloadbalancing.model.HealthCheck)1 Instance (com.amazonaws.services.elasticloadbalancing.model.Instance)1 RegisterInstancesWithLoadBalancerRequest (com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerRequest)1 RegisterInstancesWithLoadBalancerResult (com.amazonaws.services.elasticloadbalancing.model.RegisterInstancesWithLoadBalancerResult)1 ComputeProperties (com.vmware.photon.controller.model.ComputeProperties)1 LoadBalancerInstanceRequest (com.vmware.photon.controller.model.adapterapi.LoadBalancerInstanceRequest)1