Search in sources :

Example 11 with CloudLoadBalancer

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());
}
Also used : AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Test(org.junit.jupiter.api.Test)

Example 12 with CloudLoadBalancer

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);
}
Also used : AwsNetworkView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) Test(org.junit.jupiter.api.Test)

Example 13 with CloudLoadBalancer

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());
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) List(java.util.List) AzureLoadBalancer(com.sequenceiq.cloudbreak.cloud.azure.loadbalancer.AzureLoadBalancer) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) Collections.emptyMap(java.util.Collections.emptyMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 14 with CloudLoadBalancer

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));
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) RegionBackendServices(com.google.api.services.compute.Compute.RegionBackendServices) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) Test(org.junit.jupiter.api.Test)

Example 15 with CloudLoadBalancer

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));
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) RegionBackendServices(com.google.api.services.compute.Compute.RegionBackendServices) List(java.util.List) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) Test(org.junit.jupiter.api.Test)

Aggregations

CloudLoadBalancer (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer)47 TargetGroupPortPair (com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair)27 Group (com.sequenceiq.cloudbreak.cloud.model.Group)24 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)21 ArrayList (java.util.ArrayList)21 Test (org.junit.jupiter.api.Test)20 List (java.util.List)15 AwsNetworkView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsNetworkView)13 LoadBalancerType (com.sequenceiq.common.api.type.LoadBalancerType)13 HashMap (java.util.HashMap)13 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)13 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)12 Set (java.util.Set)12 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)10 GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)10 Network (com.sequenceiq.cloudbreak.cloud.model.Network)10 Map (java.util.Map)10 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)9