Search in sources :

Example 1 with AZURE

use of com.sequenceiq.cloudbreak.common.type.CloudConstants.AZURE in project cloudbreak by hortonworks.

the class LoadBalancerConfigServiceTest method testCreateAzureLoadBalancerWithSkuSetToStandard.

@Test
public void testCreateAzureLoadBalancerWithSkuSetToStandard() {
    Stack stack = createAzureStack(StackType.DATALAKE, PRIVATE_ID_1, true);
    CloudSubnet subnet = getPrivateCloudSubnet(PRIVATE_ID_1, AZ_1);
    DetailedEnvironmentResponse environment = createEnvironment(subnet, false, "AZURE");
    AzureStackV4Parameters azureParameters = new AzureStackV4Parameters();
    azureParameters.setLoadBalancerSku(LoadBalancerSku.STANDARD);
    StackV4Request request = new StackV4Request();
    request.setEnableLoadBalancer(false);
    request.setAzure(azureParameters);
    when(entitlementService.azureDatalakeLoadBalancerEnabled(anyString())).thenReturn(true);
    when(blueprint.getBlueprintText()).thenReturn(getBlueprintText("input/clouderamanager-knox.bp"));
    when(subnetSelector.findSubnetById(any(), anyString())).thenReturn(Optional.of(subnet));
    when(availabilitySetNameService.generateName(any(), any())).thenReturn("");
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
        Set<LoadBalancer> loadBalancers = underTest.createLoadBalancers(stack, environment, request);
        assertEquals(2, loadBalancers.size());
        assert loadBalancers.stream().anyMatch(l -> LoadBalancerType.PRIVATE.equals(l.getType()));
        assert loadBalancers.stream().anyMatch(l -> LoadBalancerType.OUTBOUND.equals(l.getType()));
        InstanceGroup masterInstanceGroup = stack.getInstanceGroups().stream().filter(ig -> "master".equals(ig.getGroupName())).findFirst().get();
        assertEquals(1, masterInstanceGroup.getTargetGroups().size());
        assertTrue(loadBalancers.stream().allMatch(l -> LoadBalancerSku.STANDARD.equals(l.getSku())));
        checkAvailabilitySetAttributes(loadBalancers);
    });
}
Also used : AzureStackV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.stack.AzureStackV4Parameters) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) AZURE(com.sequenceiq.cloudbreak.common.type.CloudConstants.AZURE) AWS(com.sequenceiq.cloudbreak.common.type.CloudConstants.AWS) StringUtils(org.apache.commons.lang3.StringUtils) GCP(com.sequenceiq.cloudbreak.common.type.CloudConstants.GCP) MockitoAnnotations(org.mockito.MockitoAnnotations) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) ProviderParameterCalculator(com.sequenceiq.cloudbreak.common.mappable.ProviderParameterCalculator) PublicEndpointAccessGateway(com.sequenceiq.common.api.type.PublicEndpointAccessGateway) Map(java.util.Map) Spy(org.mockito.Spy) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Assert.fail(org.junit.Assert.fail) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Collectors.toSet(java.util.stream.Collectors.toSet) SubnetSelector(com.sequenceiq.cloudbreak.converter.v4.environment.network.SubnetSelector) AzureStackV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.stack.AzureStackV4Parameters) LoadBalancerPersistenceService(com.sequenceiq.cloudbreak.service.stack.LoadBalancerPersistenceService) Set(java.util.Set) UUID(java.util.UUID) LoadBalancerSku(com.sequenceiq.common.api.type.LoadBalancerSku) Json(com.sequenceiq.cloudbreak.common.json.Json) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) SubnetTest(com.sequenceiq.cloudbreak.core.network.SubnetTest) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Mock(org.mockito.Mock) Network(com.sequenceiq.cloudbreak.domain.Network) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) Assert.assertThrows(org.junit.Assert.assertThrows) HashMap(java.util.HashMap) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) HashSet(java.util.HashSet) FileReaderUtils(com.sequenceiq.cloudbreak.util.FileReaderUtils) AzureInstanceGroupParameters(com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceGroupParameters) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) LoadBalancerCreation(com.sequenceiq.common.api.type.LoadBalancerCreation) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) AvailabilitySetNameService(com.sequenceiq.cloudbreak.cloud.model.instance.AvailabilitySetNameService) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Field(java.lang.reflect.Field) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) Assert.assertNull(org.junit.Assert.assertNull) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) YARN(com.sequenceiq.cloudbreak.common.type.CloudConstants.YARN) ReflectionUtils(org.springframework.util.ReflectionUtils) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) SubnetTest(com.sequenceiq.cloudbreak.core.network.SubnetTest) Test(org.junit.Test)

Example 2 with AZURE

use of com.sequenceiq.cloudbreak.common.type.CloudConstants.AZURE in project cloudbreak by hortonworks.

the class LoadBalancerConfigServiceTest method testCreateAzureLoadBalancerWithSkuSetToBasic.

@Test
public void testCreateAzureLoadBalancerWithSkuSetToBasic() {
    Stack stack = createAzureStack(StackType.DATALAKE, PRIVATE_ID_1, true);
    CloudSubnet subnet = getPrivateCloudSubnet(PRIVATE_ID_1, AZ_1);
    DetailedEnvironmentResponse environment = createEnvironment(subnet, false, "AZURE");
    AzureStackV4Parameters azureParameters = new AzureStackV4Parameters();
    azureParameters.setLoadBalancerSku(LoadBalancerSku.BASIC);
    StackV4Request request = new StackV4Request();
    request.setEnableLoadBalancer(false);
    request.setAzure(azureParameters);
    when(entitlementService.azureDatalakeLoadBalancerEnabled(anyString())).thenReturn(true);
    when(blueprint.getBlueprintText()).thenReturn(getBlueprintText("input/clouderamanager-knox.bp"));
    when(subnetSelector.findSubnetById(any(), anyString())).thenReturn(Optional.of(subnet));
    when(availabilitySetNameService.generateName(any(), any())).thenReturn("");
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
        Set<LoadBalancer> loadBalancers = underTest.createLoadBalancers(stack, environment, request);
        assertEquals(1, loadBalancers.size());
        assert loadBalancers.stream().anyMatch(l -> LoadBalancerType.PRIVATE.equals(l.getType()));
        InstanceGroup masterInstanceGroup = stack.getInstanceGroups().stream().filter(ig -> "master".equals(ig.getGroupName())).findFirst().get();
        assertEquals(1, masterInstanceGroup.getTargetGroups().size());
        assertTrue(loadBalancers.stream().allMatch(l -> LoadBalancerSku.BASIC.equals(l.getSku())));
        checkAvailabilitySetAttributes(loadBalancers);
    });
}
Also used : AzureStackV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.stack.AzureStackV4Parameters) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) AZURE(com.sequenceiq.cloudbreak.common.type.CloudConstants.AZURE) AWS(com.sequenceiq.cloudbreak.common.type.CloudConstants.AWS) StringUtils(org.apache.commons.lang3.StringUtils) GCP(com.sequenceiq.cloudbreak.common.type.CloudConstants.GCP) MockitoAnnotations(org.mockito.MockitoAnnotations) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) ProviderParameterCalculator(com.sequenceiq.cloudbreak.common.mappable.ProviderParameterCalculator) PublicEndpointAccessGateway(com.sequenceiq.common.api.type.PublicEndpointAccessGateway) Map(java.util.Map) Spy(org.mockito.Spy) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Assert.fail(org.junit.Assert.fail) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Collectors.toSet(java.util.stream.Collectors.toSet) SubnetSelector(com.sequenceiq.cloudbreak.converter.v4.environment.network.SubnetSelector) AzureStackV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.stack.AzureStackV4Parameters) LoadBalancerPersistenceService(com.sequenceiq.cloudbreak.service.stack.LoadBalancerPersistenceService) Set(java.util.Set) UUID(java.util.UUID) LoadBalancerSku(com.sequenceiq.common.api.type.LoadBalancerSku) Json(com.sequenceiq.cloudbreak.common.json.Json) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) SubnetTest(com.sequenceiq.cloudbreak.core.network.SubnetTest) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Mock(org.mockito.Mock) Network(com.sequenceiq.cloudbreak.domain.Network) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) Assert.assertThrows(org.junit.Assert.assertThrows) HashMap(java.util.HashMap) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) HashSet(java.util.HashSet) FileReaderUtils(com.sequenceiq.cloudbreak.util.FileReaderUtils) AzureInstanceGroupParameters(com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceGroupParameters) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) LoadBalancerCreation(com.sequenceiq.common.api.type.LoadBalancerCreation) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) AvailabilitySetNameService(com.sequenceiq.cloudbreak.cloud.model.instance.AvailabilitySetNameService) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Field(java.lang.reflect.Field) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) Assert.assertNull(org.junit.Assert.assertNull) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) YARN(com.sequenceiq.cloudbreak.common.type.CloudConstants.YARN) ReflectionUtils(org.springframework.util.ReflectionUtils) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) SubnetTest(com.sequenceiq.cloudbreak.core.network.SubnetTest) Test(org.junit.Test)

Example 3 with AZURE

use of com.sequenceiq.cloudbreak.common.type.CloudConstants.AZURE in project cloudbreak by hortonworks.

the class LoadBalancerConfigServiceTest method testCreateAzureLoadBalancerSelectsDefaultWhenSkuIsNotSet.

@Test
public void testCreateAzureLoadBalancerSelectsDefaultWhenSkuIsNotSet() {
    Stack stack = createAzureStack(StackType.DATALAKE, PRIVATE_ID_1, true);
    CloudSubnet subnet = getPrivateCloudSubnet(PRIVATE_ID_1, AZ_1);
    DetailedEnvironmentResponse environment = createEnvironment(subnet, false, "AZURE");
    StackV4Request request = new StackV4Request();
    request.setEnableLoadBalancer(false);
    when(entitlementService.azureDatalakeLoadBalancerEnabled(anyString())).thenReturn(true);
    when(blueprint.getBlueprintText()).thenReturn(getBlueprintText("input/clouderamanager-knox.bp"));
    when(subnetSelector.findSubnetById(any(), anyString())).thenReturn(Optional.of(subnet));
    when(availabilitySetNameService.generateName(any(), any())).thenReturn("");
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
        Set<LoadBalancer> loadBalancers = underTest.createLoadBalancers(stack, environment, request);
        if (LoadBalancerSku.getDefault().equals(LoadBalancerSku.STANDARD)) {
            assertEquals(2, loadBalancers.size());
            assert loadBalancers.stream().anyMatch(l -> LoadBalancerType.PRIVATE.equals(l.getType()));
            assert loadBalancers.stream().anyMatch(l -> LoadBalancerType.OUTBOUND.equals(l.getType()));
        } else if (LoadBalancerSku.getDefault().equals(LoadBalancerSku.BASIC)) {
            assertEquals(1, loadBalancers.size());
            assert loadBalancers.stream().anyMatch(l -> LoadBalancerType.PRIVATE.equals(l.getType()));
        }
        InstanceGroup masterInstanceGroup = stack.getInstanceGroups().stream().filter(ig -> "master".equals(ig.getGroupName())).findFirst().get();
        assertEquals(1, masterInstanceGroup.getTargetGroups().size());
        assertTrue(loadBalancers.stream().allMatch(l -> LoadBalancerSku.getDefault().equals(l.getSku())));
        checkAvailabilitySetAttributes(loadBalancers);
    });
}
Also used : EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) AZURE(com.sequenceiq.cloudbreak.common.type.CloudConstants.AZURE) AWS(com.sequenceiq.cloudbreak.common.type.CloudConstants.AWS) StringUtils(org.apache.commons.lang3.StringUtils) GCP(com.sequenceiq.cloudbreak.common.type.CloudConstants.GCP) MockitoAnnotations(org.mockito.MockitoAnnotations) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) ProviderParameterCalculator(com.sequenceiq.cloudbreak.common.mappable.ProviderParameterCalculator) PublicEndpointAccessGateway(com.sequenceiq.common.api.type.PublicEndpointAccessGateway) Map(java.util.Map) Spy(org.mockito.Spy) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Assert.fail(org.junit.Assert.fail) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Collectors.toSet(java.util.stream.Collectors.toSet) SubnetSelector(com.sequenceiq.cloudbreak.converter.v4.environment.network.SubnetSelector) AzureStackV4Parameters(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.stack.AzureStackV4Parameters) LoadBalancerPersistenceService(com.sequenceiq.cloudbreak.service.stack.LoadBalancerPersistenceService) Set(java.util.Set) UUID(java.util.UUID) LoadBalancerSku(com.sequenceiq.common.api.type.LoadBalancerSku) Json(com.sequenceiq.cloudbreak.common.json.Json) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) SubnetTest(com.sequenceiq.cloudbreak.core.network.SubnetTest) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Mock(org.mockito.Mock) Network(com.sequenceiq.cloudbreak.domain.Network) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) Assert.assertThrows(org.junit.Assert.assertThrows) HashMap(java.util.HashMap) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) LoadBalancerType(com.sequenceiq.common.api.type.LoadBalancerType) HashSet(java.util.HashSet) FileReaderUtils(com.sequenceiq.cloudbreak.util.FileReaderUtils) AzureInstanceGroupParameters(com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceGroupParameters) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) LoadBalancerCreation(com.sequenceiq.common.api.type.LoadBalancerCreation) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) AvailabilitySetNameService(com.sequenceiq.cloudbreak.cloud.model.instance.AvailabilitySetNameService) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Field(java.lang.reflect.Field) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) Assert.assertNull(org.junit.Assert.assertNull) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) YARN(com.sequenceiq.cloudbreak.common.type.CloudConstants.YARN) ReflectionUtils(org.springframework.util.ReflectionUtils) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) SubnetTest(com.sequenceiq.cloudbreak.core.network.SubnetTest) Test(org.junit.Test)

Aggregations

StackType (com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType)3 AzureStackV4Parameters (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.parameter.stack.AzureStackV4Parameters)3 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)3 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)3 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)3 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)3 AvailabilitySetNameService (com.sequenceiq.cloudbreak.cloud.model.instance.AvailabilitySetNameService)3 AzureInstanceGroupParameters (com.sequenceiq.cloudbreak.cloud.model.instance.AzureInstanceGroupParameters)3 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)3 Json (com.sequenceiq.cloudbreak.common.json.Json)3 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)3 ProviderParameterCalculator (com.sequenceiq.cloudbreak.common.mappable.ProviderParameterCalculator)3 AWS (com.sequenceiq.cloudbreak.common.type.CloudConstants.AWS)3 AZURE (com.sequenceiq.cloudbreak.common.type.CloudConstants.AZURE)3 GCP (com.sequenceiq.cloudbreak.common.type.CloudConstants.GCP)3 YARN (com.sequenceiq.cloudbreak.common.type.CloudConstants.YARN)3 SubnetSelector (com.sequenceiq.cloudbreak.converter.v4.environment.network.SubnetSelector)3 SubnetTest (com.sequenceiq.cloudbreak.core.network.SubnetTest)3 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)3 Network (com.sequenceiq.cloudbreak.domain.Network)3