use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair in project cloudbreak by hortonworks.
the class LoadBalancerConfigConverterTest method testConvertAwsTargetGroupMissingPortInMetadata.
@Test
public void testConvertAwsTargetGroupMissingPortInMetadata() {
CloudLoadBalancerMetadata cloudLoadBalancerMetadata = new CloudLoadBalancerMetadata.Builder().withParameters(createAwsParams(1)).build();
TargetGroup targetGroup = new TargetGroup();
targetGroup.setType(TargetGroupType.KNOX);
TargetGroupPortPair portPair1 = new TargetGroupPortPair(PORT1, PORT1);
TargetGroupPortPair portPair2 = new TargetGroupPortPair(PORT2, PORT2);
when(loadBalancerConfigService.getTargetGroupPortPairs(eq(targetGroup))).thenReturn(Set.of(portPair1, portPair2));
TargetGroupConfigDbWrapper targetGroupConfigDbWrapper = underTest.convertTargetGroup(AWS, cloudLoadBalancerMetadata, targetGroup);
assertNotNull(targetGroupConfigDbWrapper.getAwsConfig());
AwsTargetGroupConfigDb awsTargetGroupConfigDb = targetGroupConfigDbWrapper.getAwsConfig();
assertEquals(2, awsTargetGroupConfigDb.getPortArnMapping().size());
assertEquals(Set.of(PORT1, PORT2), awsTargetGroupConfigDb.getPortArnMapping().keySet());
AwsTargetGroupArnsDb targetGroupArns = awsTargetGroupConfigDb.getPortArnMapping().get(PORT1);
assertEquals(LISTENER_ARN, targetGroupArns.getListenerArn());
assertEquals(TARGET_ARN, targetGroupArns.getTargetGroupArn());
targetGroupArns = awsTargetGroupConfigDb.getPortArnMapping().get(PORT2);
assertEquals(MISSING_CLOUD_RESOURCE, targetGroupArns.getListenerArn());
assertEquals(MISSING_CLOUD_RESOURCE, targetGroupArns.getTargetGroupArn());
}
use of com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair 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.cloud.model.TargetGroupPortPair 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.cloud.model.TargetGroupPortPair 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.cloud.model.TargetGroupPortPair 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());
}
Aggregations