Search in sources :

Example 1 with TargetGroupConfigDbWrapper

use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper 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 2 with TargetGroupConfigDbWrapper

use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper in project cloudbreak by hortonworks.

the class LoadBalancerConfigConverter method buildAzureConfig.

private TargetGroupConfigDbWrapper buildAzureConfig(AzureLoadBalancerMetadataView azureMetadata, TargetGroup targetGroup) {
    Set<Integer> trafficPorts = getTrafficPorts(targetGroup);
    TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = new TargetGroupConfigDbWrapper();
    AzureTargetGroupConfigDb azureTargetGroupConfigDb = new AzureTargetGroupConfigDb();
    for (Integer port : trafficPorts) {
        String availabilitySetName = azureMetadata.getAvailabilitySetByPort(port);
        List<String> availabilitySetNames = List.of(StringUtils.isEmpty(availabilitySetName) ? MISSING_CLOUD_RESOURCE : availabilitySetName);
        azureTargetGroupConfigDb.addPortAvailabilitySetMapping(port, availabilitySetNames);
    }
    targetGroupConfigDbWrapper.setAzureConfig(azureTargetGroupConfigDb);
    return targetGroupConfigDbWrapper;
}
Also used : TargetGroupConfigDbWrapper(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper) AzureTargetGroupConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.azure.AzureTargetGroupConfigDb)

Example 3 with TargetGroupConfigDbWrapper

use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper in project cloudbreak by hortonworks.

the class LoadBalancerConfigConverter method buildAwsConfig.

private TargetGroupConfigDbWrapper buildAwsConfig(AwsLoadBalancerMetadataView awsMetadata, TargetGroup targetGroup) {
    Set<Integer> trafficPorts = getTrafficPorts(targetGroup);
    TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = new TargetGroupConfigDbWrapper();
    AwsTargetGroupConfigDb awsTargetGroupConfigDb = new AwsTargetGroupConfigDb();
    for (Integer port : trafficPorts) {
        AwsTargetGroupArnsDb targetGroupArns = new AwsTargetGroupArnsDb();
        String listenerArn = awsMetadata.getListenerArnByPort(port);
        String targetGroupArn = awsMetadata.getTargetGroupArnByPort(port);
        targetGroupArns.setListenerArn(StringUtils.isEmpty(listenerArn) ? MISSING_CLOUD_RESOURCE : listenerArn);
        targetGroupArns.setTargetGroupArn(StringUtils.isEmpty(targetGroupArn) ? MISSING_CLOUD_RESOURCE : targetGroupArn);
        awsTargetGroupConfigDb.addPortArnMapping(port, targetGroupArns);
    }
    targetGroupConfigDbWrapper.setAwsConfig(awsTargetGroupConfigDb);
    return targetGroupConfigDbWrapper;
}
Also used : TargetGroupConfigDbWrapper(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper) AwsTargetGroupConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsTargetGroupConfigDb) AwsTargetGroupArnsDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsTargetGroupArnsDb)

Example 4 with TargetGroupConfigDbWrapper

use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper in project cloudbreak by hortonworks.

the class LoadBalancerToLoadBalancerResponseConverterTest method createAwsTargetGroups.

private Set<TargetGroup> createAwsTargetGroups() {
    AwsTargetGroupArnsDb awsTargetGroupArnsDb = new AwsTargetGroupArnsDb();
    awsTargetGroupArnsDb.setListenerArn(LISTENER_ARN);
    awsTargetGroupArnsDb.setTargetGroupArn(TG_ARN);
    AwsTargetGroupConfigDb awsTargetGroupConfigDb = new AwsTargetGroupConfigDb();
    awsTargetGroupConfigDb.setPortArnMapping(Map.of(PORT, awsTargetGroupArnsDb));
    TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = new TargetGroupConfigDbWrapper();
    targetGroupConfigDbWrapper.setAwsConfig(awsTargetGroupConfigDb);
    TargetGroup targetGroup = new TargetGroup();
    targetGroup.setProviderConfig(targetGroupConfigDbWrapper);
    return Set.of(targetGroup);
}
Also used : TargetGroupConfigDbWrapper(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper) AwsTargetGroupConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsTargetGroupConfigDb) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) AwsTargetGroupArnsDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsTargetGroupArnsDb)

Example 5 with TargetGroupConfigDbWrapper

use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper in project cloudbreak by hortonworks.

the class LoadBalancerConfigConverterTest method testConvertAwsTargetGroupExtraPortsInMetadata.

@Test
public void testConvertAwsTargetGroupExtraPortsInMetadata() {
    CloudLoadBalancerMetadata cloudLoadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withParameters(createAwsParams(3)).build();
    TargetGroup targetGroup = new TargetGroup();
    targetGroup.setType(TargetGroupType.KNOX);
    TargetGroupPortPair portPair1 = new TargetGroupPortPair(PORT1, PORT1);
    TargetGroupPortPair portPair2 = new TargetGroupPortPair(PORT2, PORT2);
    when(loadBalancerConfigService.getTargetGroupPortPairs(eq(targetGroup))).thenReturn(Set.of(portPair1, portPair2));
    TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = underTest.convertTargetGroup(AWS, cloudLoadBalancerMetadata, targetGroup);
    assertNotNull(targetGroupConfigDbWrapper.getAwsConfig());
    AwsTargetGroupConfigDb awsTargetGroupConfigDb = targetGroupConfigDbWrapper.getAwsConfig();
    assertEquals(2, awsTargetGroupConfigDb.getPortArnMapping().size());
    assertEquals(Set.of(PORT1, PORT2), awsTargetGroupConfigDb.getPortArnMapping().keySet());
}
Also used : TargetGroupConfigDbWrapper(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) AwsTargetGroupConfigDb(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsTargetGroupConfigDb) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) CloudLoadBalancerMetadata(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata) Test(org.junit.Test)

Aggregations

TargetGroupConfigDbWrapper (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroupConfigDbWrapper)13 TargetGroup (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup)10 TargetGroupPortPair (com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair)7 CloudLoadBalancerMetadata (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancerMetadata)6 AwsTargetGroupConfigDb (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsTargetGroupConfigDb)6 Test (org.junit.Test)6 AwsTargetGroupArnsDb (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.aws.AwsTargetGroupArnsDb)5 AzureTargetGroupConfigDb (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.azure.AzureTargetGroupConfigDb)5 GcpLoadBalancerNamesDb (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.gcp.GcpLoadBalancerNamesDb)4 GcpTargetGroupConfigDb (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.gcp.GcpTargetGroupConfigDb)4 AwsLoadBalancerResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AwsLoadBalancerResponse)1 AwsTargetGroupResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AwsTargetGroupResponse)1 AzureLoadBalancerResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AzureLoadBalancerResponse)1 AzureTargetGroupResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.AzureTargetGroupResponse)1 GcpLoadBalancerResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.GcpLoadBalancerResponse)1 GcpTargetGroupResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.GcpTargetGroupResponse)1 LoadBalancerResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.LoadBalancerResponse)1 TargetGroupResponse (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.loadbalancer.TargetGroupResponse)1 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)1 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)1