Search in sources :

Example 11 with AzureNetwork

use of com.sequenceiq.environment.network.dao.domain.AzureNetwork in project cloudbreak by hortonworks.

the class EnvironmentNetworkServiceTest method testCreateNetworkIfUnableToObtainNetworkConnectorThenNetworkConnectorNotFoundExceptionComes.

@Test
@SuppressWarnings("unchecked")
void testCreateNetworkIfUnableToObtainNetworkConnectorThenNetworkConnectorNotFoundExceptionComes() {
    EnvironmentDto environmentDto = EnvironmentDto.builder().withCloudPlatform(CLOUD_PLATFORM).build();
    CloudConnector<Object> cloudConnector = mock(CloudConnector.class);
    when(cloudPlatformConnectors.get(any(CloudPlatformVariant.class))).thenReturn(cloudConnector);
    when(cloudConnector.networkConnector()).thenReturn(null);
    Assertions.assertThrows(NetworkConnectorNotFoundException.class, () -> underTest.createCloudNetwork(environmentDto, new AzureNetwork()));
    verify(cloudPlatformConnectors, times(1)).get(any());
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) AzureNetwork(com.sequenceiq.environment.network.dao.domain.AzureNetwork) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with AzureNetwork

use of com.sequenceiq.environment.network.dao.domain.AzureNetwork in project cloudbreak by hortonworks.

the class AzureEnvironmentNetworkConverterTest method testConvertShouldCreateABaseNetworkFromAnEnvironmentAndANetworkDto.

@Test
void testConvertShouldCreateABaseNetworkFromAnEnvironmentAndANetworkDto() {
    Environment environment = createEnvironment();
    NetworkDto networkDto = NetworkDto.builder().withAzure(AzureParams.builder().withNetworkId(NETWORK_ID).withResourceGroupName(RESOURCE_GROUP_NAME).withNoPublicIp(true).build()).withName(NETWORK_NAME).withNetworkCidr(NETWORK_CIDR).withSubnetMetas(createSubnetMetas()).build();
    AzureNetwork actual = (AzureNetwork) underTest.convert(environment, networkDto, Map.of(), Map.of());
    assertEquals(NETWORK_NAME, actual.getName());
    assertEquals(NETWORK_ID, actual.getNetworkId());
    assertEquals(RESOURCE_GROUP_NAME, actual.getResourceGroupName());
    assertTrue(actual.getNoPublicIp());
    assertEquals(NETWORK_CIDR, actual.getNetworkCidr());
    assertEquals(RegistrationType.EXISTING, actual.getRegistrationType());
    assertTrue(SUBNET_IDS.containsAll(actual.getSubnetMetas().keySet()));
    verify(environmentViewConverter).convert(environment);
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) Environment(com.sequenceiq.environment.environment.domain.Environment) AzureNetwork(com.sequenceiq.environment.network.dao.domain.AzureNetwork) Test(org.junit.jupiter.api.Test)

Example 13 with AzureNetwork

use of com.sequenceiq.environment.network.dao.domain.AzureNetwork in project cloudbreak by hortonworks.

the class AzureEnvironmentNetworkConverterTest method testSetProviderSpecificNetworkShouldPopulateTheExistingNetworkWithTheNewNetworkData.

@Test
void testSetProviderSpecificNetworkShouldPopulateTheExistingNetworkWithTheNewNetworkData() {
    AzureNetwork azureNetwork = new AzureNetwork();
    Set<CreatedSubnet> createdSubnets = createCreatedSubnets();
    Map<String, Object> properties = Map.of("resourceGroupName", RESOURCE_GROUP_NAME);
    CreatedCloudNetwork createdCloudNetwork = new CreatedCloudNetwork("network-1", NETWORK_ID, createdSubnets, properties);
    AzureNetwork actual = (AzureNetwork) underTest.setCreatedCloudNetwork(azureNetwork, createdCloudNetwork);
    assertEquals(createdCloudNetwork.getStackName(), actual.getName());
    assertEquals(NETWORK_ID, actual.getNetworkId());
    assertEquals(RESOURCE_GROUP_NAME, actual.getResourceGroupName());
    assertTrue(SUBNET_IDS.containsAll(actual.getSubnetMetas().keySet()));
    assertEquals(SUBNET_1, actual.getSubnetMetas().get(SUBNET_1).getId());
    assertEquals(SUBNET_1, actual.getSubnetMetas().get(SUBNET_1).getName());
    assertEquals(AZ_1, actual.getSubnetMetas().get(SUBNET_1).getAvailabilityZone());
    assertEquals(SUBNET_CIDR_1, actual.getSubnetMetas().get(SUBNET_1).getCidr());
    assertTrue(actual.getSubnetMetas().get(SUBNET_1).isPrivateSubnet());
    assertEquals(SUBNET_2, actual.getSubnetMetas().get(SUBNET_2).getId());
    assertEquals(SUBNET_2, actual.getSubnetMetas().get(SUBNET_2).getName());
    assertEquals(AZ_2, actual.getSubnetMetas().get(SUBNET_2).getAvailabilityZone());
    assertEquals(SUBNET_CIDR_2, actual.getSubnetMetas().get(SUBNET_2).getCidr());
    assertTrue(actual.getSubnetMetas().get(SUBNET_2).isPrivateSubnet());
    assertEquals(SUBNET_3, actual.getSubnetMetas().get(SUBNET_3).getId());
    assertEquals(SUBNET_3, actual.getSubnetMetas().get(SUBNET_3).getName());
    assertEquals(AZ_3, actual.getSubnetMetas().get(SUBNET_3).getAvailabilityZone());
    assertEquals(SUBNET_CIDR_3, actual.getSubnetMetas().get(SUBNET_3).getCidr());
    assertTrue(actual.getSubnetMetas().get(SUBNET_3).isPrivateSubnet());
}
Also used : CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) CreatedSubnet(com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet) AzureNetwork(com.sequenceiq.environment.network.dao.domain.AzureNetwork) Test(org.junit.jupiter.api.Test)

Example 14 with AzureNetwork

use of com.sequenceiq.environment.network.dao.domain.AzureNetwork in project cloudbreak by hortonworks.

the class AzureEnvironmentNetworkConverterTest method createEnvironment.

private Environment createEnvironment() {
    Environment environment = new Environment();
    environment.setName(ENV_NAME);
    environment.setId(1L);
    environment.setAccountId("2");
    environment.setDescription("description");
    environment.setCloudPlatform("AZURE");
    environment.setCredential(new Credential());
    environment.setLatitude(2.4);
    environment.setLongitude(3.5);
    environment.setLocation(LOCATION);
    environment.setLocationDisplayName("London");
    environment.setNetwork(new AzureNetwork());
    environment.setRegions(Collections.singleton(new Region()));
    return environment;
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) Environment(com.sequenceiq.environment.environment.domain.Environment) Region(com.sequenceiq.environment.environment.domain.Region) AzureNetwork(com.sequenceiq.environment.network.dao.domain.AzureNetwork)

Example 15 with AzureNetwork

use of com.sequenceiq.environment.network.dao.domain.AzureNetwork in project cloudbreak by hortonworks.

the class AzureEnvironmentNetworkConverter method convertToNetwork.

@Override
public Network convertToNetwork(BaseNetwork baseNetwork) {
    AzureNetwork azureNetwork = (AzureNetwork) baseNetwork;
    Map<String, Object> param = new HashMap<>();
    param.put(RG_NAME, azureNetwork.getResourceGroupName());
    param.put(NETWORK_ID, azureNetwork.getNetworkId());
    param.put(DATABASE_PRIVATE_DS_ZONE_ID, azureNetwork.getDatabasePrivateDnsZoneId());
    return new Network(null, param);
}
Also used : HashMap(java.util.HashMap) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) AzureNetwork(com.sequenceiq.environment.network.dao.domain.AzureNetwork) AzureNetwork(com.sequenceiq.environment.network.dao.domain.AzureNetwork)

Aggregations

AzureNetwork (com.sequenceiq.environment.network.dao.domain.AzureNetwork)15 Test (org.junit.jupiter.api.Test)7 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)4 CreatedCloudNetwork (com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork)3 Environment (com.sequenceiq.environment.environment.domain.Environment)3 Network (com.sequenceiq.cloudbreak.cloud.model.Network)2 CreatedSubnet (com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet)2 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)1 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)1 Credential (com.sequenceiq.environment.credential.domain.Credential)1 Region (com.sequenceiq.environment.environment.domain.Region)1 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)1 BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)1 AzureParams (com.sequenceiq.environment.network.dto.AzureParams)1 HashMap (java.util.HashMap)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1