use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.
the class AwsLoadBalancerCommonServiceTest method testSelectLoadBalancerSubnetIdsMissingPrivateSubnet.
@Test
public void testSelectLoadBalancerSubnetIdsMissingPrivateSubnet() {
AwsNetworkView awsNetworkView = createNetworkView(null, null);
String expectedError = "Unable to configure load balancer: Could not identify subnets.";
CloudConnectorException exception = assertThrows(CloudConnectorException.class, () -> underTest.selectLoadBalancerSubnetIds(LoadBalancerType.PRIVATE, awsNetworkView, new CloudLoadBalancer(LoadBalancerType.PRIVATE)));
assertEquals(expectedError, exception.getMessage());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.
the class AwsLoadBalancerCommonServiceTest method testSelectLoadBalancerSubnetIdsPrivate.
@Test
public void testSelectLoadBalancerSubnetIdsPrivate() {
AwsNetworkView awsNetworkView = createNetworkView(PRIVATE_ID_1, null);
LoadBalancerType loadBalancerType = LoadBalancerType.PRIVATE;
CloudLoadBalancer cloudLoadBalancer = createCloudLoadBalancer(loadBalancerType);
Set<String> subnetIds = underTest.selectLoadBalancerSubnetIds(loadBalancerType, awsNetworkView, cloudLoadBalancer);
assertEquals(Set.of(PRIVATE_ID_1), subnetIds);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.
the class AzureLoadBalancerModelBuilderTest method testGetModel.
@Test
void testGetModel() {
CloudStack mockCloudStack = mock(CloudStack.class);
Group targetGroup = new Group(INSTANCE_GROUP_NAME, InstanceGroupType.GATEWAY, List.of(new CloudInstance(INSTANCE_NAME, null, null, "subnet-1", "az1")), null, null, null, null, null, 64, null, createGroupNetwork(), emptyMap());
CloudLoadBalancer cloudLoadBalancer = new CloudLoadBalancer(LoadBalancerType.PRIVATE);
cloudLoadBalancer.addPortToTargetGroupMapping(new TargetGroupPortPair(443, 443), Set.of(targetGroup));
when(mockCloudStack.getLoadBalancers()).thenReturn(List.of(cloudLoadBalancer));
underTest = new AzureLoadBalancerModelBuilder(mockCloudStack, STACK_NAME);
Map<String, Object> result = underTest.buildModel();
assertTrue(result.containsKey(LOAD_BALANCERS_KEY));
assertTrue(result.get(LOAD_BALANCERS_KEY) instanceof List);
List<AzureLoadBalancer> loadBalancers = (List<AzureLoadBalancer>) result.get(LOAD_BALANCERS_KEY);
assertEquals(1, loadBalancers.size());
AzureLoadBalancer lb = loadBalancers.get(0);
assertEquals(LOAD_BALANCER_STACK_NAME, lb.getName());
assertEquals(LoadBalancerType.PRIVATE, lb.getType());
assertTrue(result.containsKey(LOAD_BALANCER_MAPPING_KEY));
assertTrue(result.get(LOAD_BALANCER_MAPPING_KEY) instanceof Map);
Map<String, List<AzureLoadBalancer>> mapping = (Map<String, List<AzureLoadBalancer>>) result.get(LOAD_BALANCER_MAPPING_KEY);
List<AzureLoadBalancer> mappingList = mapping.get(INSTANCE_GROUP_NAME);
assertEquals(1, mappingList.size());
assertEquals(LOAD_BALANCER_STACK_NAME, mappingList.get(0).getName());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.
the class GcpBackendServiceResourceBuilderTest method testBuildWithSeperateHCPort.
@Test
public void testBuildWithSeperateHCPort() throws Exception {
Map<String, Object> parameters = new HashMap<>();
parameters.put("hcport", 8080);
parameters.put("trafficport", 80);
CloudResource hcResource = new CloudResource.Builder().type(ResourceType.GCP_HEALTH_CHECK).status(CommonStatus.CREATED).group("master").name("hcsuper").params(parameters).persistent(true).build();
CloudResource resource = new CloudResource.Builder().type(ResourceType.GCP_BACKEND_SERVICE).status(CommonStatus.CREATED).group("master").name("super").params(parameters).persistent(true).build();
when(group.getName()).thenReturn("master");
Compute.RegionBackendServices.Insert insert = mock(Compute.RegionBackendServices.Insert.class);
Map<TargetGroupPortPair, Set<Group>> targetGroupPortPairSetHashMap = new HashMap<>();
targetGroupPortPairSetHashMap.put(new TargetGroupPortPair(80, 8080), Set.of(group));
when(cloudLoadBalancer.getPortToTargetGroupMapping()).thenReturn(targetGroupPortPairSetHashMap);
when(cloudLoadBalancer.getType()).thenReturn(LoadBalancerType.PRIVATE);
when(gcpContext.getCompute()).thenReturn(compute);
when(gcpContext.getProjectId()).thenReturn("id");
when(gcpContext.getLoadBalancerResources(any())).thenReturn(List.of(hcResource));
when(gcpContext.getLocation()).thenReturn(location);
when(location.getAvailabilityZone()).thenReturn(availabilityZone);
when(availabilityZone.value()).thenReturn("us-west2");
when(location.getRegion()).thenReturn(region);
when(region.getRegionName()).thenReturn("us-west2");
when(compute.regionBackendServices()).thenReturn(regionBackendServices);
when(regionBackendServices.insert(anyString(), anyString(), any())).thenReturn(insert);
when(insert.execute()).thenReturn(operation);
when(operation.getName()).thenReturn("name");
when(operation.getHttpErrorStatusCode()).thenReturn(null);
when(gcpLoadBalancerTypeConverter.getScheme(any(CloudLoadBalancer.class))).thenCallRealMethod();
List<CloudResource> cloudResources = underTest.build(gcpContext, authenticatedContext, Collections.singletonList(resource), cloudLoadBalancer, cloudStack);
Assert.assertEquals("super", cloudResources.get(0).getName());
Assertions.assertEquals(8080, cloudResources.get(0).getParameter("hcport", Integer.class));
Assertions.assertEquals(80, cloudResources.get(0).getParameter("trafficport", Integer.class));
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer in project cloudbreak by hortonworks.
the class GcpBackendServiceResourceBuilderTest method testBuildWithMultipleTrafficPorts.
@Test
public void testBuildWithMultipleTrafficPorts() throws Exception {
Map<String, Object> parameters = new HashMap<>();
parameters.put("hcport", 8443);
parameters.put("trafficports", List.of(443, 11443));
CloudResource hcResource = new CloudResource.Builder().type(ResourceType.GCP_HEALTH_CHECK).status(CommonStatus.CREATED).group("master").name("hcsuper").params(parameters).persistent(true).build();
CloudResource resource = new CloudResource.Builder().type(ResourceType.GCP_BACKEND_SERVICE).status(CommonStatus.CREATED).group("master").name("super").params(parameters).persistent(true).build();
when(group.getName()).thenReturn("master");
Compute.RegionBackendServices.Insert insert = mock(Compute.RegionBackendServices.Insert.class);
Map<TargetGroupPortPair, Set<Group>> targetGroupPortPairSetHashMap = new HashMap<>();
targetGroupPortPairSetHashMap.put(new TargetGroupPortPair(443, 8443), Set.of(group));
targetGroupPortPairSetHashMap.put(new TargetGroupPortPair(11443, 8443), Set.of(group));
when(cloudLoadBalancer.getPortToTargetGroupMapping()).thenReturn(targetGroupPortPairSetHashMap);
when(cloudLoadBalancer.getType()).thenReturn(LoadBalancerType.PRIVATE);
when(gcpContext.getCompute()).thenReturn(compute);
when(gcpContext.getProjectId()).thenReturn("id");
when(gcpContext.getLoadBalancerResources(any())).thenReturn(List.of(hcResource));
when(gcpContext.getLocation()).thenReturn(location);
when(location.getAvailabilityZone()).thenReturn(availabilityZone);
when(availabilityZone.value()).thenReturn("us-west2");
when(location.getRegion()).thenReturn(region);
when(region.getRegionName()).thenReturn("us-west2");
when(compute.regionBackendServices()).thenReturn(regionBackendServices);
when(regionBackendServices.insert(anyString(), anyString(), any())).thenReturn(insert);
when(insert.execute()).thenReturn(operation);
when(operation.getName()).thenReturn("name");
when(operation.getHttpErrorStatusCode()).thenReturn(null);
when(gcpLoadBalancerTypeConverter.getScheme(any(CloudLoadBalancer.class))).thenCallRealMethod();
List<CloudResource> cloudResources = underTest.build(gcpContext, authenticatedContext, Collections.singletonList(resource), cloudLoadBalancer, cloudStack);
Assert.assertEquals("super", cloudResources.get(0).getName());
Assertions.assertEquals(8443, cloudResources.get(0).getParameter("hcport", Integer.class));
List<Integer> ports = (List<Integer>) cloudResources.get(0).getParameters().get("trafficports");
Assertions.assertTrue(ports.contains(443));
Assertions.assertTrue(ports.contains(11443));
}
Aggregations