use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup in project cloudbreak by hortonworks.
the class AwsLoadBalancerCommonServiceTest method testConvertLoadBalancerExistingPrivate.
@Test
public void testConvertLoadBalancerExistingPrivate() {
AwsLoadBalancer existingLoadBalancer = new AwsLoadBalancer(AwsLoadBalancerScheme.INTERNAL);
when(loadBalancerTypeConverter.convert(eq(LoadBalancerType.PRIVATE))).thenReturn(AwsLoadBalancerScheme.INTERNAL);
AwsLoadBalancer awsLoadBalancer = setupAndRunConvertLoadBalancer(List.of(existingLoadBalancer), LoadBalancerType.PRIVATE, PRIVATE_ID_1);
assertNotNull(awsLoadBalancer);
assertEquals(existingLoadBalancer, awsLoadBalancer);
assertEquals(AwsLoadBalancerScheme.INTERNAL, awsLoadBalancer.getScheme());
assertEquals(Set.of(PRIVATE_ID_1), awsLoadBalancer.getSubnetIds());
assertEquals(1, awsLoadBalancer.getListeners().size());
AwsListener listener = awsLoadBalancer.getListeners().get(0);
assertEquals(PORT, listener.getPort());
assertNotNull(listener.getTargetGroup());
AwsTargetGroup targetGroup = listener.getTargetGroup();
assertEquals(PORT, targetGroup.getPort());
assertEquals(Set.of(INSTANCE_ID), targetGroup.getInstanceIds());
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup in project cloudbreak by hortonworks.
the class AwsLoadBalancerCommonServiceTest method testConvertLoadBalancerNewPrivate.
@Test
public void testConvertLoadBalancerNewPrivate() {
when(loadBalancerTypeConverter.convert(eq(LoadBalancerType.PRIVATE))).thenReturn(AwsLoadBalancerScheme.INTERNAL);
AwsLoadBalancer awsLoadBalancer = setupAndRunConvertLoadBalancer(List.of(), LoadBalancerType.PRIVATE, PRIVATE_ID_1);
assertNotNull(awsLoadBalancer);
assertEquals(AwsLoadBalancerScheme.INTERNAL, awsLoadBalancer.getScheme());
assertEquals(Set.of(PRIVATE_ID_1), awsLoadBalancer.getSubnetIds());
assertEquals(1, awsLoadBalancer.getListeners().size());
AwsListener listener = awsLoadBalancer.getListeners().get(0);
assertEquals(PORT, listener.getPort());
assertNotNull(listener.getTargetGroup());
AwsTargetGroup targetGroup = listener.getTargetGroup();
assertEquals(PORT, targetGroup.getPort());
assertEquals(Set.of(INSTANCE_ID), targetGroup.getInstanceIds());
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup in project cloudbreak by hortonworks.
the class AwsLoadBalancerCommonServiceTest method testConvertLoadBalancerNewPublic.
@Test
public void testConvertLoadBalancerNewPublic() {
when(loadBalancerTypeConverter.convert(eq(LoadBalancerType.PUBLIC))).thenReturn(AwsLoadBalancerScheme.INTERNET_FACING);
AwsLoadBalancer awsLoadBalancer = setupAndRunConvertLoadBalancer(List.of(), LoadBalancerType.PUBLIC, PUBLIC_ID_1);
assertNotNull(awsLoadBalancer);
assertEquals(AwsLoadBalancerScheme.INTERNET_FACING, awsLoadBalancer.getScheme());
assertEquals(Set.of(PUBLIC_ID_1), awsLoadBalancer.getSubnetIds());
assertEquals(1, awsLoadBalancer.getListeners().size());
AwsListener listener = awsLoadBalancer.getListeners().get(0);
assertEquals(PORT, listener.getPort());
assertNotNull(listener.getTargetGroup());
AwsTargetGroup targetGroup = listener.getTargetGroup();
assertEquals(PORT, targetGroup.getPort());
assertEquals(Set.of(INSTANCE_ID), targetGroup.getInstanceIds());
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup in project cloudbreak by hortonworks.
the class AwsLoadBalancerCommonServiceTest method testConvertLoadBalancerExistingPublic.
@Test
public void testConvertLoadBalancerExistingPublic() {
AwsLoadBalancer existingLoadBalancer = new AwsLoadBalancer(AwsLoadBalancerScheme.INTERNET_FACING);
when(loadBalancerTypeConverter.convert(eq(LoadBalancerType.PUBLIC))).thenReturn(AwsLoadBalancerScheme.INTERNET_FACING);
AwsLoadBalancer awsLoadBalancer = setupAndRunConvertLoadBalancer(List.of(existingLoadBalancer), LoadBalancerType.PUBLIC, PUBLIC_ID_1);
assertNotNull(awsLoadBalancer);
assertEquals(existingLoadBalancer, awsLoadBalancer);
assertEquals(AwsLoadBalancerScheme.INTERNET_FACING, awsLoadBalancer.getScheme());
assertEquals(Set.of(PUBLIC_ID_1), awsLoadBalancer.getSubnetIds());
assertEquals(1, awsLoadBalancer.getListeners().size());
AwsListener listener = awsLoadBalancer.getListeners().get(0);
assertEquals(PORT, listener.getPort());
assertNotNull(listener.getTargetGroup());
AwsTargetGroup targetGroup = listener.getTargetGroup();
assertEquals(PORT, targetGroup.getPort());
assertEquals(Set.of(INSTANCE_ID), targetGroup.getInstanceIds());
}
use of com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsTargetGroup in project cloudbreak by hortonworks.
the class AwsNativeLoadBalancerLaunchService method registerTarget.
private void registerTarget(AmazonElasticLoadBalancingClient loadBalancingClient, Long stackId, AwsTargetGroup targetGroup) {
LOGGER.debug("Registering targets to target group '{}'", targetGroup.getArn());
Set<TargetDescription> targetDescriptions = targetGroup.getInstanceIds().stream().map(privateId -> {
String instanceId = persistenceRetriever.notifyRetrieve(stackId, privateId, CommonStatus.CREATED, ResourceType.AWS_INSTANCE).orElseThrow(() -> {
String notFoundMsg = String.format("No AWS instance resource found with private id('%s') for stack('%s')", privateId, stackId);
return new CloudConnectorException(notFoundMsg);
}).getInstanceId();
return new TargetDescription().withPort(targetGroup.getPort()).withId(instanceId);
}).collect(toSet());
RegisterTargetsRequest registerTargetsRequest = new RegisterTargetsRequest().withTargetGroupArn(targetGroup.getArn()).withTargets(targetDescriptions);
LOGGER.info("Registering target group of load balancer('{}') to instances: '{}'", targetGroup.getArn(), String.join(",", targetGroup.getInstanceIds()));
loadBalancingClient.registerTargets(registerTargetsRequest);
}
Aggregations