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;
}
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());
}
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;
}
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());
}
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;
}
Aggregations