use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.
the class LoadBalancerToLoadBalancerResponseConverterTest method testConvertAws.
@Test
public void testConvertAws() {
LoadBalancer source = getSource();
// GIVEN
getSource().setProviderConfig(createAwsLoadBalancerConfig());
given(targetGroupService.findByLoadBalancerId(any())).willReturn(createAwsTargetGroups());
// WHEN
LoadBalancerResponse response = underTest.convert(source);
// THEN
assertAllFieldsNotNull(response, List.of("azureResourceId", "gcpResourceId"));
assertEquals(LB_ARN, response.getAwsResourceId().getArn());
assertEquals(1, response.getTargets().size());
TargetGroupResponse targetGroupResponse = response.getTargets().get(0);
assertEquals(PORT, targetGroupResponse.getPort());
assertEquals(Set.of(INSTANCE_ID), targetGroupResponse.getTargetInstances());
AwsTargetGroupResponse awsTargetGroupResponse = targetGroupResponse.getAwsResourceIds();
assertNotNull(awsTargetGroupResponse);
assertEquals(LISTENER_ARN, awsTargetGroupResponse.getListenerArn());
assertEquals(TG_ARN, awsTargetGroupResponse.getTargetGroupArn());
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.
the class LoadBalancerToLoadBalancerResponseConverterTest method testConvertAzure.
@Test
public void testConvertAzure() {
LoadBalancer source = getSource();
// GIVEN
getSource().setProviderConfig(createAzureLoadBalancerConfig());
given(targetGroupService.findByLoadBalancerId(any())).willReturn(createAzureTargetGroups());
// WHEN
LoadBalancerResponse response = underTest.convert(source);
// THEN
assertAllFieldsNotNull(response, List.of("awsResourceId", "gcpResourceId"));
assertEquals(AZURE_LB_NAME, response.getAzureResourceId().getName());
assertEquals(1, response.getTargets().size());
TargetGroupResponse targetGroupResponse = response.getTargets().get(0);
assertEquals(PORT, targetGroupResponse.getPort());
assertEquals(Set.of(INSTANCE_ID), targetGroupResponse.getTargetInstances());
AzureTargetGroupResponse azureTargetGroupResponse = targetGroupResponse.getAzureResourceId();
assertNotNull(azureTargetGroupResponse);
assertEquals(List.of(AZURE_AS_NAME), azureTargetGroupResponse.getAvailabilitySet());
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.
the class LoadBalancerToLoadBalancerResponseConverterTest method testConvertGcp.
@Test
public void testConvertGcp() {
LoadBalancer source = getSource();
// GIVEN
getSource().setProviderConfig(createGcpLoadBalancerConfig());
given(targetGroupService.findByLoadBalancerId(any())).willReturn(creatGcpTargetGroups());
// WHEN
LoadBalancerResponse response = underTest.convert(source);
// THEN
assertAllFieldsNotNull(response, List.of("awsResourceId", "azureResourceId"));
assertEquals(GCP_LB_NAME, response.getGcpResourceId().getName());
assertEquals(1, response.getTargets().size());
TargetGroupResponse targetGroupResponse = response.getTargets().get(0);
assertEquals(PORT, targetGroupResponse.getPort());
assertEquals(Set.of(INSTANCE_ID), targetGroupResponse.getTargetInstances());
GcpTargetGroupResponse gcpTargetGroupResponse = targetGroupResponse.getGcpResourceId();
assertNotNull(gcpTargetGroupResponse);
assertEquals(GCP_INSTANCE_GROUP_NAME, gcpTargetGroupResponse.getGcpInstanceGroupName());
assertEquals(GCP_BACKEND_SERVICE_NAME, gcpTargetGroupResponse.getGcpBackendServiceName());
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer in project cloudbreak by hortonworks.
the class LoadBalancerToLoadBalancerResponseConverterTest method createSource.
@Override
public LoadBalancer createSource() {
LoadBalancer loadBalancer = new LoadBalancer();
loadBalancer.setType(LoadBalancerType.PRIVATE);
loadBalancer.setFqdn(LB_FQDN);
loadBalancer.setIp(LB_IP);
loadBalancer.setDns(LB_DNS);
return loadBalancer;
}
use of com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer 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);
}
Aggregations