Search in sources :

Example 71 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.

the class GatewaySecurityGroupDecoratorTest method testConvertExtendsGatewaySecurityGroupsWithDefaultGatewayCidrsWithoutCCM.

@Test
public void testConvertExtendsGatewaySecurityGroupsWithDefaultGatewayCidrsWithoutCCM() {
    ReflectionTestUtils.setField(underTest, "defaultGatewayCidr", Set.of("0.0.0.0/0", "1.1.1.1/1"));
    ReflectionTestUtils.setField(underTest, "nginxPort", 9443);
    // WHEN
    underTest.extendGatewaySecurityGroupWithDefaultGatewayCidrs(stack, Tunnel.DIRECT);
    // THEN
    Set<InstanceGroup> gateways = stack.getInstanceGroups().stream().filter(ig -> InstanceGroupType.isGateway(ig.getInstanceGroupType())).collect(Collectors.toSet());
    for (InstanceGroup ig : gateways) {
        assertEquals(2, ig.getSecurityGroup().getSecurityRules().stream().filter(rule -> rule.getCidr().equals("0.0.0.0/0") || rule.getCidr().equals("1.1.1.1/1") && Arrays.stream(rule.getPorts()).anyMatch(port -> port.equals("9443"))).count());
    }
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Arrays(java.util.Arrays) Assert.assertNull(org.junit.Assert.assertNull) Set(java.util.Set) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Test(org.junit.Test) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Collectors(java.util.stream.Collectors) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) Tunnel(com.sequenceiq.common.api.type.Tunnel) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.Test)

Example 72 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.

the class LoadBalancerConfigServiceTest method testCreateAzurePrivateLoadBalancer.

@Test
public void testCreateAzurePrivateLoadBalancer() {
    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);
        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());
        checkAvailabilitySetAttributes(loadBalancers);
    });
}
Also used : 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 73 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.

the class LoadBalancerConfigServiceTest method testCreateLoadBalancerForDataLakePrivateSubnets.

@Test
public void testCreateLoadBalancerForDataLakePrivateSubnets() {
    Stack stack = createAwsStack(StackType.DATALAKE, PRIVATE_ID_1);
    CloudSubnet subnet = getPrivateCloudSubnet(PRIVATE_ID_1, AZ_1);
    DetailedEnvironmentResponse environment = createEnvironment(subnet, false, "AWS");
    StackV4Request request = new StackV4Request();
    request.setEnableLoadBalancer(false);
    when(entitlementService.datalakeLoadBalancerEnabled(anyString())).thenReturn(true);
    when(blueprint.getBlueprintText()).thenReturn(getBlueprintText("input/clouderamanager-knox.bp"));
    when(subnetSelector.findSubnetById(any(), anyString())).thenReturn(Optional.of(subnet));
    ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> {
        Set<LoadBalancer> loadBalancers = underTest.createLoadBalancers(stack, environment, request);
        assertEquals(1, loadBalancers.size());
        assertEquals(LoadBalancerType.PRIVATE, loadBalancers.iterator().next().getType());
        InstanceGroup masterInstanceGroup = stack.getInstanceGroups().stream().filter(ig -> "master".equals(ig.getGroupName())).findFirst().get();
        assertEquals(1, masterInstanceGroup.getTargetGroups().size());
    });
}
Also used : 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 74 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup 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 75 with InstanceGroup

use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.

the class LoadBalancerConfigServiceTest method testGetKnoxGatewayWhenKnoxImplicitlyDefinedByGatewayGroup.

@Test
public void testGetKnoxGatewayWhenKnoxImplicitlyDefinedByGatewayGroup() {
    Set<String> groups = Set.of("gateway");
    InstanceGroup instanceGroup = new InstanceGroup();
    instanceGroup.setGroupName("gateway");
    instanceGroup.setInstanceGroupType(InstanceGroupType.GATEWAY);
    Cluster cluster = new Cluster();
    cluster.setBlueprint(blueprint);
    Stack stack = new Stack();
    stack.setCluster(cluster);
    stack.setInstanceGroups(Set.of(instanceGroup));
    when(blueprint.getBlueprintText()).thenReturn("{}");
    Set<String> selectedGroups = underTest.getKnoxGatewayGroups(stack);
    assertEquals(groups, selectedGroups);
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) SubnetTest(com.sequenceiq.cloudbreak.core.network.SubnetTest) Test(org.junit.Test)

Aggregations

InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)288 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)132 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)93 Test (org.junit.jupiter.api.Test)91 HashSet (java.util.HashSet)68 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)57 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)47 Template (com.sequenceiq.cloudbreak.domain.Template)45 Test (org.junit.Test)44 Json (com.sequenceiq.cloudbreak.common.json.Json)38 Set (java.util.Set)37 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)34 ArrayList (java.util.ArrayList)31 LinkedHashSet (java.util.LinkedHashSet)31 Map (java.util.Map)28 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)27 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)27 List (java.util.List)26 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)25 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)22