use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup 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.domain.stack.loadbalancer.TargetGroup in project cloudbreak by hortonworks.
the class LoadBalancerConfigService method createLoadBalancers.
public Set<LoadBalancer> createLoadBalancers(Stack stack, DetailedEnvironmentResponse environment, StackV4Request source) {
LoadBalancerSku sku = getLoadBalancerSku(source);
boolean azureLoadBalancerDisabled = CloudPlatform.AZURE.toString().equalsIgnoreCase(stack.getCloudPlatform()) && LoadBalancerSku.NONE.equals(sku);
if (azureLoadBalancerDisabled) {
Optional<TargetGroup> oozieTargetGroup = setupOozieHATargetGroup(stack, true);
if (oozieTargetGroup.isPresent()) {
throw new CloudbreakServiceException("Unsupported setup: Load balancers are disabled, but Oozie HA is configured. " + "Either enable Azure load balancers, or use a non-HA Oozie setup.");
}
LOGGER.debug("Azure load balancers have been explicitly disabled.");
return Collections.emptySet();
}
boolean loadBalancerFlagEnabled = source != null && source.isEnableLoadBalancer();
Set<LoadBalancer> loadBalancers = setupLoadBalancers(stack, environment, false, loadBalancerFlagEnabled, sku);
if (stack.getCloudPlatform().equalsIgnoreCase(CloudPlatform.AZURE.toString())) {
configureLoadBalancerAvailabilitySets(stack.getName(), loadBalancers);
configureLoadBalancerSku(source, loadBalancers);
}
return loadBalancers;
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup in project cloudbreak by hortonworks.
the class LoadBalancerConfigService method setupKnoxTargetGroup.
private Optional<TargetGroup> setupKnoxTargetGroup(Stack stack, boolean dryRun) {
TargetGroup knoxTargetGroup = null;
Set<String> knoxGatewayGroupNames = getKnoxGatewayGroups(stack);
Set<InstanceGroup> knoxGatewayInstanceGroups = stack.getInstanceGroups().stream().filter(ig -> knoxGatewayGroupNames.contains(ig.getGroupName())).collect(Collectors.toSet());
if (AZURE.equalsIgnoreCase(stack.getCloudPlatform()) && knoxGatewayInstanceGroups.size() > 1) {
throw new CloudbreakServiceException("For Azure load balancers, Knox must be defined in a single instance group.");
} else if (!knoxGatewayInstanceGroups.isEmpty()) {
LOGGER.info("Knox gateway instance found; enabling Knox load balancer configuration.");
knoxTargetGroup = new TargetGroup();
knoxTargetGroup.setType(TargetGroupType.KNOX);
knoxTargetGroup.setInstanceGroups(knoxGatewayInstanceGroups);
if (!dryRun) {
LOGGER.debug("Adding target group to Knox gateway instances groups.");
TargetGroup finalKnoxTargetGroup = knoxTargetGroup;
knoxGatewayInstanceGroups.forEach(ig -> ig.addTargetGroup(finalKnoxTargetGroup));
} else {
LOGGER.debug("Dry run, skipping instance group/target group linkage.");
}
}
return Optional.ofNullable(knoxTargetGroup);
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup 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);
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup 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());
}
Aggregations