Search in sources :

Example 1 with TargetGroupPortPair

use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.

the class AzureLoadBalancerModelBuilderTest method createCloudLoadBalancer.

private CloudLoadBalancer createCloudLoadBalancer(LoadBalancerSku sku) {
    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, sku);
    cloudLoadBalancer.addPortToTargetGroupMapping(new TargetGroupPortPair(443, 443), Set.of(targetGroup));
    return cloudLoadBalancer;
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair)

Example 2 with TargetGroupPortPair

use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair 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 TargetGroupPortPair

use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.

the class GcpBackendServiceResourceBuilder method build.

@Override
public List<CloudResource> build(GcpContext context, AuthenticatedContext auth, List<CloudResource> buildableResources, CloudLoadBalancer loadBalancer, CloudStack cloudStack) throws Exception {
    List<CloudResource> results = new ArrayList<>();
    String projectId = context.getProjectId();
    String zone = context.getLocation().getAvailabilityZone().value();
    List<CloudResource> healthResources = filterResourcesByType(context.getLoadBalancerResources(loadBalancer.getType()), ResourceType.GCP_HEALTH_CHECK);
    for (CloudResource buildableResource : buildableResources) {
        LOGGER.info("Building backend service {} for {}", buildableResource.getName(), projectId);
        Optional<String> name = healthResources.stream().filter(healthResource -> buildableResource.getParameter(HCPORT, Integer.class).equals(healthResource.getParameter(HCPORT, Integer.class))).findFirst().map(CloudResource::getName);
        if (!name.isPresent()) {
            LOGGER.info("Health check resource not found for port {}", buildableResource.getParameter(HCPORT, Integer.class));
        }
        BackendService backendService = new BackendService();
        backendService.setHealthChecks(Collections.singletonList(String.format(GCP_HEALTH_CHECK_FORMAT, projectId, context.getLocation().getRegion().getRegionName(), name.get())));
        List<Backend> backends = new ArrayList<>();
        Map<String, Object> portMap = buildableResource.getParameters();
        Integer hcPort = buildableResource.getParameter(HCPORT, Integer.class);
        Set<Group> groups = new HashSet<>();
        if (portMap.containsKey(TRAFFICPORTS)) {
            for (Integer trafficPort : (List<Integer>) portMap.get(TRAFFICPORTS)) {
                TargetGroupPortPair targetGroupPortPair = new TargetGroupPortPair(trafficPort, hcPort);
                groups.addAll(loadBalancer.getPortToTargetGroupMapping().get(targetGroupPortPair));
            }
        } else {
            Integer trafficPort = buildableResource.getParameter(TRAFFICPORT, Integer.class);
            TargetGroupPortPair targetGroupPortPair = new TargetGroupPortPair(trafficPort, hcPort);
            groups.addAll(loadBalancer.getPortToTargetGroupMapping().get(targetGroupPortPair));
        }
        makeBackendForTargetGroup(context, loadBalancer, projectId, zone, groups, backends);
        backendService.setBackends(backends);
        backendService.setName(buildableResource.getName());
        backendService.setLoadBalancingScheme(gcpLoadBalancerTypeConverter.getScheme(loadBalancer).getGcpType());
        backendService.setProtocol("TCP");
        String regionName = context.getLocation().getRegion().getRegionName();
        Insert insert = context.getCompute().regionBackendServices().insert(projectId, regionName, backendService);
        results.add(doOperationalRequest(buildableResource, insert));
    }
    return results;
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) ArrayList(java.util.ArrayList) Insert(com.google.api.services.compute.Compute.RegionBackendServices.Insert) BackendService(com.google.api.services.compute.model.BackendService) Backend(com.google.api.services.compute.model.Backend) ArrayList(java.util.ArrayList) List(java.util.List) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) HashSet(java.util.HashSet)

Example 4 with TargetGroupPortPair

use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.

the class StackToCloudStackConverterTest method testConvertWithMultipleKnoxLoadBalancers.

@Test
public void testConvertWithMultipleKnoxLoadBalancers() {
    Set<InstanceGroup> instanceGroups = new LinkedHashSet<>();
    InstanceGroup instanceGroup1 = mock(InstanceGroup.class);
    InstanceGroup instanceGroup2 = mock(InstanceGroup.class);
    when(instanceGroup1.getGroupName()).thenReturn("group1");
    when(instanceGroup2.getGroupName()).thenReturn("group2");
    instanceGroups.add(instanceGroup1);
    instanceGroups.add(instanceGroup2);
    when(stack.getInstanceGroupsAsList()).thenReturn(new ArrayList<>(instanceGroups));
    Template template = new Template();
    template.setVolumeTemplates(Set.of());
    when(instanceGroup1.getTemplate()).thenReturn(template);
    when(instanceGroup1.getNotDeletedInstanceMetaDataSet()).thenReturn(Set.of());
    when(instanceGroup1.getStack()).thenReturn(stack);
    when(instanceGroup2.getTemplate()).thenReturn(template);
    when(instanceGroup2.getNotDeletedInstanceMetaDataSet()).thenReturn(Set.of());
    when(instanceGroup2.getStack()).thenReturn(stack);
    TargetGroup targetGroup = mock(TargetGroup.class);
    when(targetGroup.getType()).thenReturn(TargetGroupType.KNOX);
    LoadBalancer internalLoadBalancer = mock(LoadBalancer.class);
    when(internalLoadBalancer.getType()).thenReturn(LoadBalancerType.PRIVATE);
    when(internalLoadBalancer.getId()).thenReturn(1L);
    LoadBalancer externalLoadBalancer = mock(LoadBalancer.class);
    when(externalLoadBalancer.getType()).thenReturn(LoadBalancerType.PUBLIC);
    when(externalLoadBalancer.getId()).thenReturn(2L);
    when(loadBalancerPersistenceService.findByStackId(anyLong())).thenReturn(Set.of(internalLoadBalancer, externalLoadBalancer));
    when(targetGroupPersistenceService.findByLoadBalancerId(anyLong())).thenReturn(Set.of(targetGroup));
    when(instanceGroupService.findByTargetGroupId(anyLong())).thenReturn(Set.of(instanceGroup1, instanceGroup2));
    when(loadBalancerConfigService.getTargetGroupPortPairs(any(TargetGroup.class))).thenReturn(Set.of(new TargetGroupPortPair(443, 8443)));
    CloudStack result = underTest.convert(stack);
    assertEquals(2, result.getLoadBalancers().size());
    Optional<CloudLoadBalancer> internalCloudLoadBalancer = result.getLoadBalancers().stream().filter(lb -> lb.getType() == LoadBalancerType.PRIVATE).findFirst();
    assertTrue(internalCloudLoadBalancer.isPresent());
    Optional<CloudLoadBalancer> externalCloudLoadBalancer = result.getLoadBalancers().stream().filter(lb -> lb.getType() == LoadBalancerType.PUBLIC).findFirst();
    assertTrue(externalCloudLoadBalancer.isPresent());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BeforeEach(org.junit.jupiter.api.BeforeEach) ResourceGroupUsage(com.sequenceiq.environment.api.v1.environment.model.request.azure.ResourceGroupUsage) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) ComponentConfigProviderService(com.sequenceiq.cloudbreak.service.ComponentConfigProviderService) PlatformParametersConsts(com.sequenceiq.cloudbreak.cloud.PlatformParametersConsts) InstanceMetadataToImageIdConverter(com.sequenceiq.cloudbreak.converter.InstanceMetadataToImageIdConverter) InstanceGroupService(com.sequenceiq.cloudbreak.service.stack.InstanceGroupService) AzureEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureEnvironmentParameters) CmTemplateProcessorFactory(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessorFactory) ImageService(com.sequenceiq.cloudbreak.service.image.ImageService) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) Map(java.util.Map) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) TargetGroupPersistenceService(com.sequenceiq.cloudbreak.service.stack.TargetGroupPersistenceService) MethodSource(org.junit.jupiter.params.provider.MethodSource) LoadBalancerPersistenceService(com.sequenceiq.cloudbreak.service.stack.LoadBalancerPersistenceService) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Collection(java.util.Collection) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) StackTags(com.sequenceiq.cloudbreak.cloud.model.StackTags) Set(java.util.Set) LoadBalancerSku(com.sequenceiq.common.api.type.LoadBalancerSku) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) SecurityRule(com.sequenceiq.cloudbreak.domain.SecurityRule) RESOURCE_GROUP_USAGE_PARAMETER(com.sequenceiq.cloudbreak.cloud.PlatformParametersConsts.RESOURCE_GROUP_USAGE_PARAMETER) Test(org.junit.jupiter.api.Test) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Json(com.sequenceiq.cloudbreak.common.json.Json) EncryptionType(com.sequenceiq.common.api.type.EncryptionType) FileSystem(com.sequenceiq.cloudbreak.domain.FileSystem) Group(com.sequenceiq.cloudbreak.cloud.model.Group) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) SecurityRuleService(com.sequenceiq.cloudbreak.service.securityrule.SecurityRuleService) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor) NetworkConstants(com.sequenceiq.cloudbreak.common.network.NetworkConstants) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Strictness(org.mockito.quality.Strictness) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) LoadBalancerConfigService(com.sequenceiq.cloudbreak.service.LoadBalancerConfigService) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) Mock(org.mockito.Mock) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) ArrayList(java.util.ArrayList) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) DefaultRootVolumeSizeProvider(com.sequenceiq.cloudbreak.service.stack.DefaultRootVolumeSizeProvider) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) LinkedHashSet(java.util.LinkedHashSet) InjectMocks(org.mockito.InjectMocks) AzureResourceGroup(com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceGroup) TargetGroupType(com.sequenceiq.common.api.type.TargetGroupType) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) StackAuthentication(com.sequenceiq.cloudbreak.domain.StackAuthentication) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Template(com.sequenceiq.cloudbreak.domain.Template) SecurityGroup(com.sequenceiq.cloudbreak.domain.SecurityGroup) Mockito(org.mockito.Mockito) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) RESOURCE_GROUP_NAME_PARAMETER(com.sequenceiq.cloudbreak.cloud.PlatformParametersConsts.RESOURCE_GROUP_NAME_PARAMETER) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) TargetGroup(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Template(com.sequenceiq.cloudbreak.domain.Template) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with TargetGroupPortPair

use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.

the class AwsDownscaleService method getTargetGroupArns.

private List<String> getTargetGroupArns(List<CloudLoadBalancer> loadBalancers, AuthenticatedContext auth) {
    List<String> targetGroupArns = new ArrayList<>();
    for (CloudLoadBalancer loadBalancer : loadBalancers) {
        for (Map.Entry<TargetGroupPortPair, Set<Group>> entry : loadBalancer.getPortToTargetGroupMapping().entrySet()) {
            String region = auth.getCloudContext().getLocation().getRegion().value();
            AwsLoadBalancerScheme scheme = loadBalancerTypeConverter.convert(loadBalancer.getType());
            String targetGroupArn = cfStackUtil.getResourceArnByLogicalId(auth, AwsTargetGroup.getTargetGroupName(entry.getKey().getTrafficPort(), scheme), region);
            targetGroupArns.add(targetGroupArn);
        }
    }
    return targetGroupArns;
}
Also used : CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) Set(java.util.Set) ArrayList(java.util.ArrayList) Map(java.util.Map) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) AwsLoadBalancerScheme(com.sequenceiq.cloudbreak.cloud.aws.common.loadbalancer.AwsLoadBalancerScheme)

Aggregations

TargetGroupPortPair (com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair)36 CloudLoadBalancer (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer)24 Group (com.sequenceiq.cloudbreak.cloud.model.Group)19 ArrayList (java.util.ArrayList)17 HashMap (java.util.HashMap)14 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 TargetGroup (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup)11 Set (java.util.Set)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)9 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)8 AzureStackView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView)8 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)8 GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)8 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)8 Network (com.sequenceiq.cloudbreak.cloud.model.Network)8 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)8 List (java.util.List)7