Search in sources :

Example 11 with NetworkCidr

use of com.sequenceiq.cloudbreak.cloud.network.NetworkCidr in project cloudbreak by hortonworks.

the class EnvironmentNetworkServiceTest method testGetNetworkCidrWhenNetworkNull.

@Test
void testGetNetworkCidrWhenNetworkNull() {
    Credential credential = mock(Credential.class);
    NetworkCidr result = underTest.getNetworkCidr(null, "AWS", credential);
    assertNull(result);
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with NetworkCidr

use of com.sequenceiq.cloudbreak.cloud.network.NetworkCidr in project cloudbreak by hortonworks.

the class NetworkServiceTest method testRefreshMetadataFromGoogleCloudProviderMustUseSubnetName.

@Test
public void testRefreshMetadataFromGoogleCloudProviderMustUseSubnetName() {
    NetworkDto networkDto = mock(NetworkDto.class);
    AuthenticationDto authenticationDto = mock(AuthenticationDto.class);
    EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
    EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
    SecurityAccessDto securityAccessDto = mock(SecurityAccessDto.class);
    ParametersDto parametersDto = mock(ParametersDto.class);
    EnvironmentNetworkConverter environmentNetworkConverter = mock(EnvironmentNetworkConverter.class);
    Network network = mock(Network.class);
    Credential credential = mock(Credential.class);
    BaseNetwork baseNetwork = new GcpNetwork();
    baseNetwork.setRegistrationType(RegistrationType.EXISTING);
    Environment environment = new Environment();
    environment.setCloudPlatform("GCP");
    environment.setCredential(credential);
    EnvironmentEditDto environmentEditDto = new EnvironmentEditDto("description", "accountId", networkDto, authenticationDto, environmentTelemetry, environmentBackup, securityAccessDto, Tunnel.CCMV2, IdBrokerMappingSource.MOCK, CloudStorageValidation.ENABLED, "adminGroupName", parametersDto);
    when(environmentNetworkConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentNetworkConverter);
    when(environmentNetworkConverter.convertToDto(baseNetwork)).thenReturn(networkDto);
    when(cloudNetworkService.retrieveSubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
    when(cloudNetworkService.retrieveEndpointGatewaySubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
    when(environmentNetworkConverter.convertToNetwork(any(BaseNetwork.class))).thenReturn(network);
    when(environmentNetworkService.getNetworkCidr(any(Network.class), anyString(), any(Credential.class))).thenReturn(new NetworkCidr("10.0.0.0", new ArrayList<>()));
    BaseNetwork result = underTest.refreshMetadataFromCloudProvider(baseNetwork, environmentEditDto, environment);
    Assertions.assertEquals(result.getSubnetMetas().keySet().stream().findFirst().get(), "subnet1");
    Assertions.assertEquals(result.getSubnetMetas().keySet().size(), 1);
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) Credential(com.sequenceiq.environment.credential.domain.Credential) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) EnvironmentBackup(com.sequenceiq.environment.environment.dto.EnvironmentBackup) GcpNetwork(com.sequenceiq.environment.network.dao.domain.GcpNetwork) ArrayList(java.util.ArrayList) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) EnvironmentNetworkConverter(com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter) NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) AuthenticationDto(com.sequenceiq.environment.environment.dto.AuthenticationDto) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) GcpNetwork(com.sequenceiq.environment.network.dao.domain.GcpNetwork) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) Environment(com.sequenceiq.environment.environment.domain.Environment) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with NetworkCidr

use of com.sequenceiq.cloudbreak.cloud.network.NetworkCidr in project cloudbreak by hortonworks.

the class EnvironmentInitHandlerTest method testInitSuccess.

@Test
void testInitSuccess() {
    EnvironmentDto dto = getEnvironmentDto();
    NetworkDto networkDto = NetworkDto.builder().withRegistrationType(RegistrationType.EXISTING).build();
    dto.setNetwork(networkDto);
    Event<EnvironmentDto> event = new Event<>(dto);
    Environment environment = getEnvironment();
    EnvironmentNetworkConverter environmentNetworkConverter = mock(EnvironmentNetworkConverter.class);
    Network network = mock(Network.class);
    String cidr = "10.0.0.0/16";
    when(environmentNetworkConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentNetworkConverter);
    when(environmentNetworkConverter.convertToNetwork(environment.getNetwork())).thenReturn(network);
    when(environmentNetworkService.getNetworkCidr(any(), anyString(), any())).thenReturn(new NetworkCidr(cidr));
    when(environmentService.findEnvironmentById(dto.getId())).thenReturn(Optional.of(environment));
    Map<UmsVirtualGroupRight, String> virtualGroups = Map.of(UmsVirtualGroupRight.HBASE_ADMIN, "apple1", UmsVirtualGroupRight.ENVIRONMENT_ACCESS, "apple2");
    when(virtualGroupService.createVirtualGroups(ACCOUNT_ID, CRN)).thenReturn(virtualGroups);
    CloudRegions cloudRegions = new CloudRegions(Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), "apple", true);
    when(environmentService.getRegionsByEnvironment(environment)).thenReturn(cloudRegions);
    environmentInitHandler.accept(event);
    assertEquals(cidr, environment.getNetwork().getNetworkCidr());
    verify(environmentNetworkService, times(1)).getNetworkCidr(eq(network), eq(CloudPlatform.AWS.name()), eq(environment.getCredential()));
    verify(environmentService, times(0)).setAdminGroupName(environment, null);
    verify(environmentService, times(1)).assignEnvironmentAdminRole(CREATOR, CRN);
    verify(environmentService, times(1)).setLocation(environment, environment.getRegionWrapper(), cloudRegions);
    verify(environmentService, times(1)).setRegions(environment, environment.getRegionWrapper().getRegions(), cloudRegions);
    verify(environmentService, times(1)).save(environment);
    verify(eventSender, times(1)).sendEvent(any(), any());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EnvironmentNetworkConverter(com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter) UmsVirtualGroupRight(com.sequenceiq.cloudbreak.auth.altus.UmsVirtualGroupRight) NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) Event(reactor.bus.Event) Environment(com.sequenceiq.environment.environment.domain.Environment) Test(org.junit.jupiter.api.Test)

Example 14 with NetworkCidr

use of com.sequenceiq.cloudbreak.cloud.network.NetworkCidr in project cloudbreak by hortonworks.

the class AzureNetworkConnectorTest method testGetNetworkCidrMoreThanOne.

@Test
public void testGetNetworkCidrMoreThanOne() {
    String networkId = "vnet-1";
    String resourceGroupName = "resourceGroupName";
    String cidrBlock1 = "10.0.0.0/16";
    String cidrBlock2 = "10.23.0.0/16";
    Network network = new Network(null, Map.of(AzureUtils.NETWORK_ID, networkId));
    CloudCredential credential = new CloudCredential();
    com.microsoft.azure.management.network.Network azureNetwork = mock(com.microsoft.azure.management.network.Network.class);
    when(azureClientService.getClient(credential)).thenReturn(azureClient);
    when(azureUtils.getCustomResourceGroupName(network)).thenReturn(resourceGroupName);
    when(azureUtils.getCustomNetworkId(network)).thenReturn(networkId);
    when(azureClient.getNetworkByResourceGroup(resourceGroupName, networkId)).thenReturn(azureNetwork);
    when(azureNetwork.addressSpaces()).thenReturn(List.of(cidrBlock1, cidrBlock2));
    NetworkCidr result = underTest.getNetworkCidr(network, credential);
    assertEquals(cidrBlock1, result.getCidr());
}
Also used : NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 15 with NetworkCidr

use of com.sequenceiq.cloudbreak.cloud.network.NetworkCidr in project cloudbreak by hortonworks.

the class AzureNetworkConnectorTest method testCreateNetworkWithSubnetsShouldReturnTheNetworkNameAndSubnetName.

@Test
public void testCreateNetworkWithSubnetsShouldReturnTheNetworkNameAndSubnetName() {
    String networkCidr = "0.0.0.0/16";
    Set<NetworkSubnetRequest> subnets = new HashSet<>(Arrays.asList(createSubnetRequest(SUBNET_CIDR_0), createSubnetRequest(SUBNET_CIDR_1)));
    Deployment templateDeployment = mock(Deployment.class);
    ResourceGroup resourceGroup = mock(ResourceGroup.class);
    Map<String, Map> outputs = createOutput();
    ArrayList<SubnetRequest> subnetRequests = Lists.newArrayList(publicSubnetRequest("10.0.1.0/24", 0), publicSubnetRequest("10.0.1.0/24", 1));
    NetworkCreationRequest networkCreationRequest = createNetworkRequest(networkCidr, subnets);
    when(resourceGroup.name()).thenReturn(ENV_NAME);
    when(azureSubnetRequestProvider.provide(anyString(), anyList(), anyList(), anyBoolean())).thenReturn(subnetRequests);
    when(azureUtils.generateResourceGroupNameByNameAndId(anyString(), anyString())).thenReturn(ENV_NAME);
    when(azureClientService.getClient(networkCreationRequest.getCloudCredential())).thenReturn(azureClient);
    when(azureNetworkTemplateBuilder.build(networkCreationRequest, subnetRequests, resourceGroup.name())).thenReturn(TEMPLATE);
    when(azureClient.createTemplateDeployment(ENV_NAME, STACK_NAME, TEMPLATE, PARAMETER)).thenReturn(templateDeployment);
    when(azureClient.createResourceGroup(ENV_NAME, REGION.value(), Collections.emptyMap())).thenReturn(resourceGroup);
    when(resourceGroup.name()).thenReturn(ENV_NAME);
    when(templateDeployment.outputs()).thenReturn(outputs);
    CreatedCloudNetwork actual = underTest.createNetworkWithSubnets(networkCreationRequest);
    assertEquals(ENV_NAME, actual.getNetworkId());
    assertTrue(actual.getSubnets().stream().anyMatch(cloudSubnet -> cloudSubnet.getSubnetId().equals(SUBNET_ID_0)));
    assertTrue(actual.getSubnets().stream().anyMatch(cloudSubnet -> cloudSubnet.getSubnetId().equals(SUBNET_ID_1)));
    assertTrue(actual.getSubnets().size() == 2);
}
Also used : Arrays(java.util.Arrays) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) NetworkDeletionRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkDeletionRequest) NetworkResourcesCreationRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkResourcesCreationRequest) Mockito.doThrow(org.mockito.Mockito.doThrow) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Map(java.util.Map) Location(com.sequenceiq.cloudbreak.cloud.model.Location) BadRequestException(javax.ws.rs.BadRequestException) MediaType(okhttp3.MediaType) ResponseBody(okhttp3.ResponseBody) NetworkSubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) Set(java.util.Set) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) AzureTransientDeploymentService(com.sequenceiq.cloudbreak.cloud.azure.template.AzureTransientDeploymentService) AzureClientService(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClientService) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) SubnetSelectionParameters(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters) Variant(com.sequenceiq.cloudbreak.cloud.model.Variant) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) AzureNetworkView(com.sequenceiq.cloudbreak.cloud.azure.view.AzureNetworkView) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) NetworkCreationRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkCreationRequest) HashMap(java.util.HashMap) Response(retrofit2.Response) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) SubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest) PUBLIC(com.sequenceiq.cloudbreak.cloud.model.network.SubnetType.PUBLIC) Lists(com.google.common.collect.Lists) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) Network(com.sequenceiq.cloudbreak.cloud.model.Network) ExpectedException(org.junit.rules.ExpectedException) InjectMocks(org.mockito.InjectMocks) Deployment(com.microsoft.azure.management.resources.Deployment) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) Rule(org.junit.Rule) CloudException(com.microsoft.azure.CloudException) AzureSubnetSelectorService(com.sequenceiq.cloudbreak.cloud.azure.subnet.selector.AzureSubnetSelectorService) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NetworkSubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest) SubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.SubnetRequest) NetworkCreationRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkCreationRequest) Deployment(com.microsoft.azure.management.resources.Deployment) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) NetworkSubnetRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkSubnetRequest) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) Map(java.util.Map) HashMap(java.util.HashMap) ResourceGroup(com.microsoft.azure.management.resources.ResourceGroup) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

NetworkCidr (com.sequenceiq.cloudbreak.cloud.network.NetworkCidr)17 Network (com.sequenceiq.cloudbreak.cloud.model.Network)14 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)9 CreatedCloudNetwork (com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork)8 BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)6 Test (org.junit.Test)6 Test (org.junit.jupiter.api.Test)6 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)5 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)5 EnvironmentNetworkConverter (com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 DescribeVpcsRequest (com.amazonaws.services.ec2.model.DescribeVpcsRequest)4 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)4 AmazonEc2Client (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonEc2Client)4 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)4 Credential (com.sequenceiq.environment.credential.domain.Credential)4 Environment (com.sequenceiq.environment.environment.domain.Environment)4 ArrayList (java.util.ArrayList)4 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)3