use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.TargetGroupResponse in project cloudbreak by hortonworks.
the class LoadBalancerToLoadBalancerResponseConverter method mapPortPairToTargetGroup.
private TargetGroupResponse mapPortPairToTargetGroup(Set<String> instanceIds, TargetGroupConfigDbWrapper targetGroupConfig, TargetGroupPortPair portPair) {
TargetGroupResponse response = new TargetGroupResponse();
response.setPort(portPair.getTrafficPort());
response.setTargetInstances(instanceIds);
if (targetGroupConfig != null) {
response.setAwsResourceIds(convertAwsTargetGroup(targetGroupConfig.getAwsConfig(), portPair.getTrafficPort()));
response.setAzureResourceId(convertAzureTargetGroup(targetGroupConfig.getAzureConfig(), portPair.getTrafficPort()));
response.setGcpResourceId(convertGcpTargetGroup(targetGroupConfig.getGcpConfig(), portPair.getTrafficPort()));
}
return response;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.TargetGroupResponse in project cloudbreak by hortonworks.
the class LoadBalancerToLoadBalancerResponseConverter method convertTargetGroup.
public List<TargetGroupResponse> convertTargetGroup(TargetGroup targetGroup) {
Set<InstanceGroup> instanceGroups = instanceGroupService.findByTargetGroupId(targetGroup.getId());
Set<String> instanceIds = getInstanceMetadataForGroups(instanceGroups).stream().map(InstanceMetaData::getInstanceId).collect(Collectors.toSet());
TargetGroupConfigDbWrapper targetGroupConfig = targetGroup.getProviderConfig();
Set<TargetGroupPortPair> portPairs = loadBalancerConfigService.getTargetGroupPortPairs(targetGroup);
return portPairs.stream().map(portPair -> mapPortPairToTargetGroup(instanceIds, targetGroupConfig, portPair)).collect(Collectors.toList());
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.TargetGroupResponse in project cloudbreak by hortonworks.
the class LoadBalancerToLoadBalancerResponseConverterTest method testConvertAws.
@Test
public void testConvertAws() {
LoadBalancer source = getSource();
// GIVEN
getSource().setProviderConfig(createAwsLoadBalancerConfig());
given(targetGroupService.findByLoadBalancerId(any())).willReturn(createAwsTargetGroups());
// WHEN
LoadBalancerResponse response = underTest.convert(source);
// THEN
assertAllFieldsNotNull(response, List.of("azureResourceId", "gcpResourceId"));
assertEquals(LB_ARN, response.getAwsResourceId().getArn());
assertEquals(1, response.getTargets().size());
TargetGroupResponse targetGroupResponse = response.getTargets().get(0);
assertEquals(PORT, targetGroupResponse.getPort());
assertEquals(Set.of(INSTANCE_ID), targetGroupResponse.getTargetInstances());
AwsTargetGroupResponse awsTargetGroupResponse = targetGroupResponse.getAwsResourceIds();
assertNotNull(awsTargetGroupResponse);
assertEquals(LISTENER_ARN, awsTargetGroupResponse.getListenerArn());
assertEquals(TG_ARN, awsTargetGroupResponse.getTargetGroupArn());
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.TargetGroupResponse in project cloudbreak by hortonworks.
the class LoadBalancerToLoadBalancerResponseConverterTest method testConvertAzure.
@Test
public void testConvertAzure() {
LoadBalancer source = getSource();
// GIVEN
getSource().setProviderConfig(createAzureLoadBalancerConfig());
given(targetGroupService.findByLoadBalancerId(any())).willReturn(createAzureTargetGroups());
// WHEN
LoadBalancerResponse response = underTest.convert(source);
// THEN
assertAllFieldsNotNull(response, List.of("awsResourceId", "gcpResourceId"));
assertEquals(AZURE_LB_NAME, response.getAzureResourceId().getName());
assertEquals(1, response.getTargets().size());
TargetGroupResponse targetGroupResponse = response.getTargets().get(0);
assertEquals(PORT, targetGroupResponse.getPort());
assertEquals(Set.of(INSTANCE_ID), targetGroupResponse.getTargetInstances());
AzureTargetGroupResponse azureTargetGroupResponse = targetGroupResponse.getAzureResourceId();
assertNotNull(azureTargetGroupResponse);
assertEquals(List.of(AZURE_AS_NAME), azureTargetGroupResponse.getAvailabilitySet());
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.TargetGroupResponse in project cloudbreak by hortonworks.
the class LoadBalancerToLoadBalancerResponseConverterTest method testConvertGcp.
@Test
public void testConvertGcp() {
LoadBalancer source = getSource();
// GIVEN
getSource().setProviderConfig(createGcpLoadBalancerConfig());
given(targetGroupService.findByLoadBalancerId(any())).willReturn(creatGcpTargetGroups());
// WHEN
LoadBalancerResponse response = underTest.convert(source);
// THEN
assertAllFieldsNotNull(response, List.of("awsResourceId", "azureResourceId"));
assertEquals(GCP_LB_NAME, response.getGcpResourceId().getName());
assertEquals(1, response.getTargets().size());
TargetGroupResponse targetGroupResponse = response.getTargets().get(0);
assertEquals(PORT, targetGroupResponse.getPort());
assertEquals(Set.of(INSTANCE_ID), targetGroupResponse.getTargetInstances());
GcpTargetGroupResponse gcpTargetGroupResponse = targetGroupResponse.getGcpResourceId();
assertNotNull(gcpTargetGroupResponse);
assertEquals(GCP_INSTANCE_GROUP_NAME, gcpTargetGroupResponse.getGcpInstanceGroupName());
assertEquals(GCP_BACKEND_SERVICE_NAME, gcpTargetGroupResponse.getGcpBackendServiceName());
}
Aggregations