use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup in project cloudbreak by hortonworks.
the class StackToCloudStackConverterTest method testConvertWithKnoxLoadBalancer.
@Test
public void testConvertWithKnoxLoadBalancer() {
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(Sets.newHashSet());
when(instanceGroup1.getTemplate()).thenReturn(template);
when(instanceGroup1.getNotDeletedInstanceMetaDataSet()).thenReturn(Collections.emptySet());
when(instanceGroup1.getStack()).thenReturn(stack);
when(instanceGroup2.getTemplate()).thenReturn(template);
when(instanceGroup2.getNotDeletedInstanceMetaDataSet()).thenReturn(Collections.emptySet());
when(instanceGroup2.getStack()).thenReturn(stack);
TargetGroup targetGroup = mock(TargetGroup.class);
when(targetGroup.getType()).thenReturn(TargetGroupType.KNOX);
LoadBalancer loadBalancer = mock(LoadBalancer.class);
when(loadBalancer.getType()).thenReturn(LoadBalancerType.PRIVATE);
when(loadBalancer.getId()).thenReturn(1L);
when(loadBalancerPersistenceService.findByStackId(anyLong())).thenReturn(Set.of(loadBalancer));
when(targetGroupPersistenceService.findByLoadBalancerId(anyLong())).thenReturn(Set.of(targetGroup));
when(instanceGroupService.findByTargetGroupId(anyLong())).thenReturn(Set.of(instanceGroup1, instanceGroup2));
TargetGroupPortPair targetGroupPortPair = new TargetGroupPortPair(443, 8443);
when(loadBalancerConfigService.getTargetGroupPortPairs(any(TargetGroup.class))).thenReturn(Set.of(targetGroupPortPair));
CloudStack result = underTest.convert(stack);
assertEquals(1, result.getLoadBalancers().size());
CloudLoadBalancer cloudLoadBalancer = result.getLoadBalancers().iterator().next();
assertEquals(LoadBalancerType.PRIVATE, cloudLoadBalancer.getType());
assertEquals(Set.of(targetGroupPortPair), cloudLoadBalancer.getPortToTargetGroupMapping().keySet());
Set<String> groupNames = cloudLoadBalancer.getPortToTargetGroupMapping().values().stream().flatMap(Collection::stream).collect(Collectors.toSet()).stream().map(Group::getName).collect(Collectors.toSet());
assertEquals(Set.of("group1", "group2"), groupNames);
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup in project cloudbreak by hortonworks.
the class StackToCloudStackConverterTest method testConvertWithLoadBalancerSkuSet.
@Test
public void testConvertWithLoadBalancerSkuSet() {
Set<InstanceGroup> instanceGroups = new LinkedHashSet<>();
InstanceGroup instanceGroup1 = mock(InstanceGroup.class);
instanceGroups.add(instanceGroup1);
Template template = new Template();
template.setVolumeTemplates(Sets.newHashSet());
TargetGroup targetGroup = mock(TargetGroup.class);
LoadBalancer loadBalancer = mock(LoadBalancer.class);
TargetGroupPortPair targetGroupPortPair = new TargetGroupPortPair(443, 8443);
when(instanceGroup1.getGroupName()).thenReturn("group1");
when(stack.getInstanceGroupsAsList()).thenReturn(new ArrayList<>(instanceGroups));
when(instanceGroup1.getTemplate()).thenReturn(template);
when(instanceGroup1.getNotDeletedInstanceMetaDataSet()).thenReturn(Collections.emptySet());
when(instanceGroup1.getStack()).thenReturn(stack);
when(targetGroup.getType()).thenReturn(TargetGroupType.KNOX);
when(loadBalancer.getType()).thenReturn(LoadBalancerType.PRIVATE);
when(loadBalancer.getId()).thenReturn(1L);
when(loadBalancer.getSku()).thenReturn(LoadBalancerSku.STANDARD);
when(loadBalancerPersistenceService.findByStackId(anyLong())).thenReturn(Set.of(loadBalancer));
when(targetGroupPersistenceService.findByLoadBalancerId(anyLong())).thenReturn(Set.of(targetGroup));
when(instanceGroupService.findByTargetGroupId(anyLong())).thenReturn(Set.of(instanceGroup1));
when(loadBalancerConfigService.getTargetGroupPortPairs(any(TargetGroup.class))).thenReturn(Set.of(targetGroupPortPair));
CloudStack result = underTest.convert(stack);
assertEquals(1, result.getLoadBalancers().size());
CloudLoadBalancer cloudLoadBalancer = result.getLoadBalancers().iterator().next();
assertEquals(LoadBalancerSku.STANDARD, cloudLoadBalancer.getSku());
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup in project cloudbreak by hortonworks.
the class StackV4RequestToStackConverterTest method testConvertWithKnoxLoadBalancer.
@Test
public void testConvertWithKnoxLoadBalancer() {
initMocks();
setDefaultRegions(AWS);
StackV4Request request = getRequest("stack-datalake-with-instancegroups.json");
ReflectionTestUtils.setField(underTest, "defaultRegions", "AWS:eu-west-2");
TargetGroup targetGroup = new TargetGroup();
targetGroup.setType(TargetGroupType.KNOX);
LoadBalancer loadBalancer = new LoadBalancer();
loadBalancer.setType(LoadBalancerType.PRIVATE);
loadBalancer.setTargetGroupSet(Set.of(targetGroup));
given(credentialClientService.getByCrn(anyString())).willReturn(credential);
given(credentialClientService.getByName(anyString())).willReturn(credential);
given(providerParameterCalculator.get(request)).willReturn(getMappable());
given(clusterV4RequestToClusterConverter.convert(any(ClusterV4Request.class))).willReturn(new Cluster());
given(telemetryConverter.convert(null, StackType.DATALAKE)).willReturn(new Telemetry());
given(loadBalancerConfigService.createLoadBalancers(any(), any(), eq(request))).willReturn(Set.of(loadBalancer));
// WHEN
Stack stack = underTest.convert(request);
// THEN
assertEquals(1, stack.getLoadBalancers().size());
assertEquals(1, stack.getLoadBalancers().iterator().next().getTargetGroupSet().size());
assertEquals(TargetGroupType.KNOX, stack.getLoadBalancers().iterator().next().getTargetGroupSet().iterator().next().getType());
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.TargetGroup in project cloudbreak by hortonworks.
the class MetadataSetupService method saveLoadBalancerMetadata.
public void saveLoadBalancerMetadata(Stack stack, Iterable<CloudLoadBalancerMetadata> cloudLoadBalancerMetadataList) {
try {
LOGGER.info("Save load balancer metadata for stack: {}", stack.getName());
Set<LoadBalancer> allLoadBalancerMetadata = loadBalancerPersistenceService.findByStackId(stack.getId());
for (CloudLoadBalancerMetadata cloudLoadBalancerMetadata : cloudLoadBalancerMetadataList) {
LoadBalancer loadBalancerEntry = createLoadBalancerMetadataIfAbsent(allLoadBalancerMetadata, stack, cloudLoadBalancerMetadata.getType());
loadBalancerEntry.setDns(cloudLoadBalancerMetadata.getCloudDns());
loadBalancerEntry.setHostedZoneId(cloudLoadBalancerMetadata.getHostedZoneId());
loadBalancerEntry.setIp(cloudLoadBalancerMetadata.getIp());
loadBalancerEntry.setType(cloudLoadBalancerMetadata.getType());
String endpoint = loadBalancerConfigService.generateLoadBalancerEndpoint(stack);
List<StackIdView> byEnvironmentCrnAndStackType = stackService.getByEnvironmentCrnAndStackType(stack.getEnvironmentCrn(), StackType.DATALAKE);
List<StackStatus> stoppedDatalakes = byEnvironmentCrnAndStackType.stream().map(s -> stackStatusService.findFirstByStackIdOrderByCreatedDesc(s.getId())).filter(Optional::isPresent).map(Optional::get).filter(status -> status.getStatus().isStopState()).collect(Collectors.toList());
if (!stoppedDatalakes.isEmpty()) {
/* Starts to check for a situation where we are resizing a datalake that did not previously have loadbalancers
so that we can use the same endpoint name for a seamless transistion
*/
LOGGER.info("Using old datalake endpoint name for resized datalake: {}, env: {}", stack.getName(), stack.getEnvironmentCrn());
if (stoppedDatalakes.size() > 1) {
String ids = stoppedDatalakes.stream().map(stackStatus -> stackStatus.getStack().getId()).map(Object::toString).collect(Collectors.joining(","));
LOGGER.warn("more than one datalake found to resize from: {}", ids);
}
Long oldId = stoppedDatalakes.get(0).getStack().getId();
Set<LoadBalancer> oldLoadbalancers = loadBalancerPersistenceService.findByStackId(oldId);
if (oldLoadbalancers.isEmpty()) {
Stack oldStack = stackService.getByIdWithGatewayInTransaction(oldId);
if (stack.getDisplayName().equals(oldStack.getDisplayName())) {
endpoint = oldStack.getPrimaryGatewayInstance().getShortHostname();
}
}
}
LOGGER.info("Saving load balancer endpoint as: {}", endpoint);
loadBalancerEntry.setEndpoint(endpoint);
loadBalancerEntry.setProviderConfig(loadBalancerConfigConverter.convertLoadBalancer(stack.getCloudPlatform(), cloudLoadBalancerMetadata));
loadBalancerPersistenceService.save(loadBalancerEntry);
Set<TargetGroup> targetGroups = targetGroupPersistenceService.findByLoadBalancerId(loadBalancerEntry.getId());
for (TargetGroup targetGroup : targetGroups) {
targetGroup.setProviderConfig(loadBalancerConfigConverter.convertTargetGroup(stack.getCloudPlatform(), cloudLoadBalancerMetadata, targetGroup));
targetGroupPersistenceService.save(targetGroup);
}
}
} catch (Exception ex) {
throw new CloudbreakServiceException("Load balancer metadata collection failed", ex);
}
}
Aggregations