use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup in project cloudbreak by hortonworks.
the class LoadBalancerConfigConverterTest method testConvertGcpTargetGroup.
@Test
public void testConvertGcpTargetGroup() {
CloudLoadBalancerMetadata cloudLoadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withParameters(creatGcpParams(1)).build();
TargetGroup targetGroup = new TargetGroup();
targetGroup.setType(TargetGroupType.KNOX);
TargetGroupPortPair portPair = new TargetGroupPortPair(PORT1, PORT2);
when(loadBalancerConfigService.getTargetGroupPortPairs(eq(targetGroup))).thenReturn(Set.of(portPair));
TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = underTest.convertTargetGroup(GCP, cloudLoadBalancerMetadata, targetGroup);
assertNotNull(targetGroupConfigDbWrapper.getGcpConfig());
GcpTargetGroupConfigDb gcpTargetGroupConfigDb = targetGroupConfigDbWrapper.getGcpConfig();
assertEquals(1, gcpTargetGroupConfigDb.getPortMapping().size());
assertEquals(PORT1, gcpTargetGroupConfigDb.getPortMapping().keySet().iterator().next());
GcpLoadBalancerNamesDb gcpLoadBalancerNamesDb = gcpTargetGroupConfigDb.getPortMapping().get(PORT1);
assertEquals(BACKEND_SERVICE_NAME, gcpLoadBalancerNamesDb.getBackendServiceName());
assertEquals(INSTANCE_GROUP_NAME, gcpLoadBalancerNamesDb.getInstanceGroupName());
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup in project cloudbreak by hortonworks.
the class StackToCloudStackConverter method buildLoadBalancers.
private List<CloudLoadBalancer> buildLoadBalancers(Stack stack, List<Group> instanceGroups) {
List<CloudLoadBalancer> cloudLoadBalancers = new ArrayList<>();
for (LoadBalancer loadBalancer : loadBalancerPersistenceService.findByStackId(stack.getId())) {
CloudLoadBalancer cloudLoadBalancer = new CloudLoadBalancer(loadBalancer.getType(), loadBalancer.getSku());
for (TargetGroup targetGroup : targetGroupPersistenceService.findByLoadBalancerId(loadBalancer.getId())) {
Set<TargetGroupPortPair> portPairs = loadBalancerConfigService.getTargetGroupPortPairs(targetGroup);
Set<String> targetInstanceGroupName = instanceGroupService.findByTargetGroupId(targetGroup.getId()).stream().map(InstanceGroup::getGroupName).collect(Collectors.toSet());
for (TargetGroupPortPair portPair : portPairs) {
cloudLoadBalancer.addPortToTargetGroupMapping(portPair, instanceGroups.stream().filter(ig -> targetInstanceGroupName.contains(ig.getName())).collect(Collectors.toSet()));
}
}
cloudLoadBalancers.add(cloudLoadBalancer);
}
return cloudLoadBalancers;
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup in project cloudbreak by hortonworks.
the class LoadBalancerConfigService method setupOozieHATargetGroup.
private Optional<TargetGroup> setupOozieHATargetGroup(Stack stack, boolean dryRun) {
Optional<InstanceGroup> oozieInstanceGroup = getOozieHAInstanceGroup(stack);
if (oozieInstanceGroup.isPresent()) {
LOGGER.info("Oozie HA instance group found; enabling Oozie load balancer configuration.");
TargetGroup oozieTargetGroup = new TargetGroup();
if (CloudPlatform.GCP.equalsIgnoreCase(stack.getCloudPlatform())) {
oozieTargetGroup.setType(TargetGroupType.OOZIE_GCP);
} else {
oozieTargetGroup.setType(TargetGroupType.OOZIE);
}
oozieTargetGroup.setInstanceGroups(Set.of(oozieInstanceGroup.get()));
if (!dryRun) {
LOGGER.debug("Adding target group to Oozie HA instance group.");
oozieInstanceGroup.get().addTargetGroup(oozieTargetGroup);
} else {
LOGGER.debug("Dry run, skipping instance group/target group linkage for Oozie.");
}
return Optional.of(oozieTargetGroup);
} else {
LOGGER.info("Oozie HA instance group not found; not enabling Oozie load balancer configuration.");
return Optional.empty();
}
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup in project cloudbreak by hortonworks.
the class LoadBalancerToLoadBalancerResponseConverterTest method creatGcpTargetGroups.
private Set<TargetGroup> creatGcpTargetGroups() {
GcpTargetGroupConfigDb gcpTargetGroupConfigDb = new GcpTargetGroupConfigDb();
GcpLoadBalancerNamesDb gcpLoadBalancerNamesDb = new GcpLoadBalancerNamesDb();
gcpLoadBalancerNamesDb.setBackendServiceName(GCP_BACKEND_SERVICE_NAME);
gcpLoadBalancerNamesDb.setInstanceGroupName(GCP_INSTANCE_GROUP_NAME);
gcpTargetGroupConfigDb.addPortNameMapping(PORT, gcpLoadBalancerNamesDb);
TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = new TargetGroupConfigDbWrapper();
targetGroupConfigDbWrapper.setGcpConfig(gcpTargetGroupConfigDb);
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 LoadBalancerToLoadBalancerResponseConverterTest method createAzureTargetGroups.
private Set<TargetGroup> createAzureTargetGroups() {
AzureTargetGroupConfigDb azureTargetGroupConfigDb = new AzureTargetGroupConfigDb();
azureTargetGroupConfigDb.setPortAvailabilitySetMapping(Map.of(PORT, List.of(AZURE_AS_NAME)));
TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = new TargetGroupConfigDbWrapper();
targetGroupConfigDbWrapper.setAzureConfig(azureTargetGroupConfigDb);
TargetGroup targetGroup = new TargetGroup();
targetGroup.setProviderConfig(targetGroupConfigDbWrapper);
return Set.of(targetGroup);
}
Aggregations