Search in sources :

Example 1 with TargetGroupResponse

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;
}
Also used : AzureTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AzureTargetGroupResponse) AwsTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AwsTargetGroupResponse) GcpTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.GcpTargetGroupResponse) TargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.TargetGroupResponse)

Example 2 with TargetGroupResponse

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());
}
Also used : TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) LoadBalancerConfigService(com.sequenceiq.cloudbreak.service.LoadBalancerConfigService) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) AwsTargetGroupConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsTargetGroupConfigDb) GcpLoadBalancerConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.gcp.GcpLoadBalancerConfigDb) AzureTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AzureTargetGroupResponse) AwsTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AwsTargetGroupResponse) InstanceGroupService(com.sequenceiq.cloudbreak.service.stack.InstanceGroupService) GcpTargetGroupConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.gcp.GcpTargetGroupConfigDb) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) Map(java.util.Map) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) AwsLoadBalancerConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsLoadBalancerConfigDb) TargetGroupPersistenceService(com.sequenceiq.cloudbreak.service.stack.TargetGroupPersistenceService) LoadBalancerResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.LoadBalancerResponse) GcpTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.GcpTargetGroupResponse) TargetGroupConfigDbWrapper(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper) AzureTargetGroupConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.azure.AzureTargetGroupConfigDb) Set(java.util.Set) AwsTargetGroupArnsDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsTargetGroupArnsDb) AzureLoadBalancerResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AzureLoadBalancerResponse) Collectors(java.util.stream.Collectors) AwsLoadBalancerResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AwsLoadBalancerResponse) AzureLoadBalancerConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.azure.AzureLoadBalancerConfigDb) List(java.util.List) Component(org.springframework.stereotype.Component) GcpLoadBalancerResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.GcpLoadBalancerResponse) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Optional(java.util.Optional) TargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.TargetGroupResponse) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) GcpLoadBalancerNamesDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.gcp.GcpLoadBalancerNamesDb) TargetGroupConfigDbWrapper(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)

Example 3 with TargetGroupResponse

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());
}
Also used : LoadBalancerResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.LoadBalancerResponse) AwsTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AwsTargetGroupResponse) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) AzureTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AzureTargetGroupResponse) AwsTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AwsTargetGroupResponse) GcpTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.GcpTargetGroupResponse) TargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.TargetGroupResponse) AbstractEntityConverterTest(com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest) Test(org.junit.Test)

Example 4 with TargetGroupResponse

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());
}
Also used : LoadBalancerResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.LoadBalancerResponse) AzureTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AzureTargetGroupResponse) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) AzureTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AzureTargetGroupResponse) AwsTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AwsTargetGroupResponse) GcpTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.GcpTargetGroupResponse) TargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.TargetGroupResponse) AbstractEntityConverterTest(com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest) Test(org.junit.Test)

Example 5 with TargetGroupResponse

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());
}
Also used : LoadBalancerResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.LoadBalancerResponse) GcpTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.GcpTargetGroupResponse) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) AzureTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AzureTargetGroupResponse) AwsTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AwsTargetGroupResponse) GcpTargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.GcpTargetGroupResponse) TargetGroupResponse(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.TargetGroupResponse) AbstractEntityConverterTest(com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest) Test(org.junit.Test)

Aggregations

AwsTargetGroupResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AwsTargetGroupResponse)5 AzureTargetGroupResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AzureTargetGroupResponse)5 GcpTargetGroupResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.GcpTargetGroupResponse)5 TargetGroupResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.TargetGroupResponse)5 LoadBalancerResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.LoadBalancerResponse)4 LoadBalancer (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer)4 AbstractEntityConverterTest (com.sequenceiq.cloudbreak.converter.AbstractEntityConverterTest)3 Test (org.junit.Test)3 AwsLoadBalancerResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AwsLoadBalancerResponse)1 AzureLoadBalancerResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AzureLoadBalancerResponse)1 GcpLoadBalancerResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.GcpLoadBalancerResponse)1 TargetGroupPortPair (com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair)1 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)1 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)1 TargetGroup (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup)1 TargetGroupConfigDbWrapper (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper)1 AwsLoadBalancerConfigDb (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsLoadBalancerConfigDb)1 AwsTargetGroupArnsDb (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsTargetGroupArnsDb)1 AwsTargetGroupConfigDb (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsTargetGroupConfigDb)1 AzureLoadBalancerConfigDb (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.azure.AzureLoadBalancerConfigDb)1