use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.
the class CloudFormationStackUtil method addLoadBalancerTargets.
public void addLoadBalancerTargets(AuthenticatedContext ac, CloudLoadBalancer loadBalancer, List<CloudResource> resourcesToAdd) {
String region = ac.getCloudContext().getLocation().getRegion().value();
AmazonElasticLoadBalancingClient amazonElbClient = awsClient.createElasticLoadBalancingClient(new AwsCredentialView(ac.getCloudCredential()), region);
for (Map.Entry<TargetGroupPortPair, Set<Group>> entry : loadBalancer.getPortToTargetGroupMapping().entrySet()) {
// Get a list of the new instances in the target groups
Set<String> updatedInstanceIds = getInstanceIdsForGroups(resourcesToAdd, entry.getValue());
// Find target group ARN
AwsLoadBalancerScheme scheme = loadBalancerTypeConverter.convert(loadBalancer.getType());
String targetGroupArn = getResourceArnByLogicalId(ac, AwsTargetGroup.getTargetGroupName(entry.getKey().getTrafficPort(), scheme), region);
// Use ARN to fetch a list of current targets
DescribeTargetHealthResult targetHealthResult = amazonElbClient.describeTargetHealth(new DescribeTargetHealthRequest().withTargetGroupArn(targetGroupArn));
List<TargetDescription> targetDescriptions = targetHealthResult.getTargetHealthDescriptions().stream().map(TargetHealthDescription::getTarget).collect(Collectors.toList());
Set<String> alreadyRegisteredInstanceIds = targetDescriptions.stream().map(TargetDescription::getId).collect(Collectors.toSet());
// Remove any targets that have already been registered from the list being processed
updatedInstanceIds.removeAll(alreadyRegisteredInstanceIds);
// Register any new instances
if (!updatedInstanceIds.isEmpty()) {
List<TargetDescription> targetsToAdd = updatedInstanceIds.stream().map(instanceId -> new TargetDescription().withId(instanceId)).collect(Collectors.toList());
RegisterTargetsResult registerTargetsResult = amazonElbClient.registerTargets(new RegisterTargetsRequest().withTargetGroupArn(targetGroupArn).withTargets(targetsToAdd));
}
}
}
use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.
the class AwsLoadBalancerCommonServiceTest method createCloudLoadBalancer.
private CloudLoadBalancer createCloudLoadBalancer(LoadBalancerType type, List<String> instanceGroupNetworkSubnetIds) {
Group group = new Group(INSTANCE_NAME, GATEWAY, List.of(), null, null, null, null, null, null, 100, null, createGroupNetwork(instanceGroupNetworkSubnetIds), emptyMap());
CloudLoadBalancer cloudLoadBalancer = new CloudLoadBalancer(type);
cloudLoadBalancer.addPortToTargetGroupMapping(new TargetGroupPortPair(PORT, PORT), Set.of(group));
return cloudLoadBalancer;
}
use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.
the class AzureLoadBalancerModelBuilderTest method testGetModel.
@Test
void testGetModel() {
CloudStack mockCloudStack = mock(CloudStack.class);
Group targetGroup = new Group(INSTANCE_GROUP_NAME, InstanceGroupType.GATEWAY, List.of(new CloudInstance(INSTANCE_NAME, null, null, "subnet-1", "az1")), null, null, null, null, null, 64, null, createGroupNetwork(), emptyMap());
CloudLoadBalancer cloudLoadBalancer = new CloudLoadBalancer(LoadBalancerType.PRIVATE);
cloudLoadBalancer.addPortToTargetGroupMapping(new TargetGroupPortPair(443, 443), Set.of(targetGroup));
when(mockCloudStack.getLoadBalancers()).thenReturn(List.of(cloudLoadBalancer));
underTest = new AzureLoadBalancerModelBuilder(mockCloudStack, STACK_NAME);
Map<String, Object> result = underTest.buildModel();
assertTrue(result.containsKey(LOAD_BALANCERS_KEY));
assertTrue(result.get(LOAD_BALANCERS_KEY) instanceof List);
List<AzureLoadBalancer> loadBalancers = (List<AzureLoadBalancer>) result.get(LOAD_BALANCERS_KEY);
assertEquals(1, loadBalancers.size());
AzureLoadBalancer lb = loadBalancers.get(0);
assertEquals(LOAD_BALANCER_STACK_NAME, lb.getName());
assertEquals(LoadBalancerType.PRIVATE, lb.getType());
assertTrue(result.containsKey(LOAD_BALANCER_MAPPING_KEY));
assertTrue(result.get(LOAD_BALANCER_MAPPING_KEY) instanceof Map);
Map<String, List<AzureLoadBalancer>> mapping = (Map<String, List<AzureLoadBalancer>>) result.get(LOAD_BALANCER_MAPPING_KEY);
List<AzureLoadBalancer> mappingList = mapping.get(INSTANCE_GROUP_NAME);
assertEquals(1, mappingList.size());
assertEquals(LOAD_BALANCER_STACK_NAME, mappingList.get(0).getName());
}
use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.
the class GcpBackendServiceResourceBuilderTest method testCreateWhereEverythingGoesFine.
@Test
public void testCreateWhereEverythingGoesFine() {
when(gcpContext.getName()).thenReturn("name");
when(cloudLoadBalancer.getType()).thenReturn(LoadBalancerType.PUBLIC);
Map<TargetGroupPortPair, Set<Group>> targetGroupPortPairSetHashMap = new HashMap<>();
targetGroupPortPairSetHashMap.put(new TargetGroupPortPair(80, 8080), Collections.emptySet());
when(cloudLoadBalancer.getPortToTargetGroupMapping()).thenReturn(targetGroupPortPairSetHashMap);
List<CloudResource> cloudResources = underTest.create(gcpContext, authenticatedContext, cloudLoadBalancer);
Assertions.assertTrue(cloudResources.get(0).getName().startsWith("name-public-8080"));
Assertions.assertEquals(1, cloudResources.size());
Assertions.assertEquals(8080, cloudResources.get(0).getParameter("hcport", Integer.class));
Assertions.assertEquals(80, cloudResources.get(0).getParameter("trafficport", Integer.class));
}
use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.
the class GcpBackendServiceResourceBuilderTest method testBuildWithSeperateHCPort.
@Test
public void testBuildWithSeperateHCPort() throws Exception {
Map<String, Object> parameters = new HashMap<>();
parameters.put("hcport", 8080);
parameters.put("trafficport", 80);
CloudResource hcResource = new CloudResource.Builder().type(ResourceType.GCP_HEALTH_CHECK).status(CommonStatus.CREATED).group("master").name("hcsuper").params(parameters).persistent(true).build();
CloudResource resource = new CloudResource.Builder().type(ResourceType.GCP_BACKEND_SERVICE).status(CommonStatus.CREATED).group("master").name("super").params(parameters).persistent(true).build();
when(group.getName()).thenReturn("master");
Compute.RegionBackendServices.Insert insert = mock(Compute.RegionBackendServices.Insert.class);
Map<TargetGroupPortPair, Set<Group>> targetGroupPortPairSetHashMap = new HashMap<>();
targetGroupPortPairSetHashMap.put(new TargetGroupPortPair(80, 8080), Set.of(group));
when(cloudLoadBalancer.getPortToTargetGroupMapping()).thenReturn(targetGroupPortPairSetHashMap);
when(cloudLoadBalancer.getType()).thenReturn(LoadBalancerType.PRIVATE);
when(gcpContext.getCompute()).thenReturn(compute);
when(gcpContext.getProjectId()).thenReturn("id");
when(gcpContext.getLoadBalancerResources(any())).thenReturn(List.of(hcResource));
when(gcpContext.getLocation()).thenReturn(location);
when(location.getAvailabilityZone()).thenReturn(availabilityZone);
when(availabilityZone.value()).thenReturn("us-west2");
when(location.getRegion()).thenReturn(region);
when(region.getRegionName()).thenReturn("us-west2");
when(compute.regionBackendServices()).thenReturn(regionBackendServices);
when(regionBackendServices.insert(anyString(), anyString(), any())).thenReturn(insert);
when(insert.execute()).thenReturn(operation);
when(operation.getName()).thenReturn("name");
when(operation.getHttpErrorStatusCode()).thenReturn(null);
when(gcpLoadBalancerTypeConverter.getScheme(any(CloudLoadBalancer.class))).thenCallRealMethod();
List<CloudResource> cloudResources = underTest.build(gcpContext, authenticatedContext, Collections.singletonList(resource), cloudLoadBalancer, cloudStack);
Assert.assertEquals("super", cloudResources.get(0).getName());
Assertions.assertEquals(8080, cloudResources.get(0).getParameter("hcport", Integer.class));
Assertions.assertEquals(80, cloudResources.get(0).getParameter("trafficport", Integer.class));
}
Aggregations