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;
}
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;
}
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;
});
}
Aggregations