Search in sources :

Example 1 with AzureLoadBalancer

use of com.sequenceiq.cloudbreak.cloud.azure.loadbalancer.AzureLoadBalancer 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 2 with AzureLoadBalancer

use of com.sequenceiq.cloudbreak.cloud.azure.loadbalancer.AzureLoadBalancer in project cloudbreak by hortonworks.

the class AzureLoadBalancerModelBuilderTest method testGetModelWithOutboundLoadBalancer.

@Test
void testGetModelWithOutboundLoadBalancer() {
    CloudStack mockCloudStack = mock(CloudStack.class);
    CloudLoadBalancer privateLoadBalancer = createCloudLoadBalancer(LoadBalancerSku.STANDARD);
    CloudLoadBalancer outboundLoadBalancer = createOutboundCloudLoadBalancer();
    when(mockCloudStack.getLoadBalancers()).thenReturn(List.of(privateLoadBalancer, outboundLoadBalancer));
    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(2, loadBalancers.size());
    assertTrue(loadBalancers.stream().allMatch(lb -> LoadBalancerSku.STANDARD.equals(lb.getSku())));
    assertTrue(loadBalancers.stream().anyMatch(lb -> LoadBalancerType.PRIVATE.equals(lb.getType())));
    assertTrue(loadBalancers.stream().anyMatch(lb -> LoadBalancerType.OUTBOUND.equals(lb.getType())));
}
Also used : Collections.emptyMap(java.util.Collections.emptyMap) AzureLoadBalancer(com.sequenceiq.cloudbreak.cloud.azure.loadbalancer.AzureLoadBalancer) TargetGroupPortPair(com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair) Set(java.util.Set) HashMap(java.util.HashMap) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Mockito.when(org.mockito.Mockito.when) LoadBalancerSku(com.sequenceiq.common.api.type.LoadBalancerSku) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) List(java.util.List) Group(com.sequenceiq.cloudbreak.cloud.model.Group) GroupNetwork(com.sequenceiq.cloudbreak.cloud.model.GroupNetwork) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Map(java.util.Map) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) OutboundInternetTraffic(com.sequenceiq.common.api.type.OutboundInternetTraffic) Mockito.mock(org.mockito.Mockito.mock) CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) List(java.util.List) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) AzureLoadBalancer(com.sequenceiq.cloudbreak.cloud.azure.loadbalancer.AzureLoadBalancer) Test(org.junit.jupiter.api.Test)

Example 3 with AzureLoadBalancer

use of com.sequenceiq.cloudbreak.cloud.azure.loadbalancer.AzureLoadBalancer in project cloudbreak by hortonworks.

the class AzureLoadBalancerModelBuilderTest method testGetModelWithBasicSku.

@Test
void testGetModelWithBasicSku() {
    CloudStack mockCloudStack = mock(CloudStack.class);
    CloudLoadBalancer cloudLoadBalancer = createCloudLoadBalancer(LoadBalancerSku.BASIC);
    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(LoadBalancerSku.BASIC, lb.getSku());
}
Also used : CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) List(java.util.List) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) AzureLoadBalancer(com.sequenceiq.cloudbreak.cloud.azure.loadbalancer.AzureLoadBalancer) Test(org.junit.jupiter.api.Test)

Example 4 with AzureLoadBalancer

use of com.sequenceiq.cloudbreak.cloud.azure.loadbalancer.AzureLoadBalancer in project cloudbreak by hortonworks.

the class AzureLoadBalancerModelBuilderTest method testGetModelWithStandardSku.

@Test
void testGetModelWithStandardSku() {
    CloudStack mockCloudStack = mock(CloudStack.class);
    CloudLoadBalancer cloudLoadBalancer = createCloudLoadBalancer(LoadBalancerSku.STANDARD);
    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(LoadBalancerSku.STANDARD, lb.getSku());
}
Also used : CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) List(java.util.List) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) AzureLoadBalancer(com.sequenceiq.cloudbreak.cloud.azure.loadbalancer.AzureLoadBalancer) Test(org.junit.jupiter.api.Test)

Example 5 with AzureLoadBalancer

use of com.sequenceiq.cloudbreak.cloud.azure.loadbalancer.AzureLoadBalancer in project cloudbreak by hortonworks.

the class AzureLoadBalancerModelBuilderTest method testGetModelWithDefaultSku.

@Test
void testGetModelWithDefaultSku() {
    CloudStack mockCloudStack = mock(CloudStack.class);
    CloudLoadBalancer cloudLoadBalancer = createCloudLoadBalancer();
    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(LoadBalancerSku.getDefault(), lb.getSku());
}
Also used : CloudLoadBalancer(com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer) List(java.util.List) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) AzureLoadBalancer(com.sequenceiq.cloudbreak.cloud.azure.loadbalancer.AzureLoadBalancer) Test(org.junit.jupiter.api.Test)

Aggregations

AzureLoadBalancer (com.sequenceiq.cloudbreak.cloud.azure.loadbalancer.AzureLoadBalancer)6 CloudLoadBalancer (com.sequenceiq.cloudbreak.cloud.model.CloudLoadBalancer)5 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)5 List (java.util.List)5 Test (org.junit.jupiter.api.Test)5 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)2 Group (com.sequenceiq.cloudbreak.cloud.model.Group)2 TargetGroupPortPair (com.sequenceiq.cloudbreak.cloud.model.TargetGroupPortPair)2 Collections.emptyMap (java.util.Collections.emptyMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 GroupNetwork (com.sequenceiq.cloudbreak.cloud.model.GroupNetwork)1 InstanceGroupType (com.sequenceiq.common.api.type.InstanceGroupType)1 LoadBalancerSku (com.sequenceiq.common.api.type.LoadBalancerSku)1 LoadBalancerType (com.sequenceiq.common.api.type.LoadBalancerType)1 OutboundInternetTraffic (com.sequenceiq.common.api.type.OutboundInternetTraffic)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1