Search in sources :

Example 11 with CloudRegions

use of com.sequenceiq.cloudbreak.cloud.model.CloudRegions in project cloudbreak by hortonworks.

the class OpenStackPlatformResources method publicIpPool.

@Override
public CloudIpPools publicIpPool(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    OSClient<?> osClient = openStackClient.createOSClient(cloudCredential);
    Map<String, Set<CloudIpPool>> cloudIpPools = new HashMap<>();
    CloudRegions regions = regions(cloudCredential, region, filters);
    for (Entry<Region, List<AvailabilityZone>> regionListEntry : regions.getCloudRegions().entrySet()) {
        Set<CloudIpPool> cloudGateWays = new HashSet<>();
        List<? extends Network> networks = getNetworks(osClient);
        List<? extends Network> networksWithExternalRouter = networks.stream().filter(Network::isRouterExternal).collect(Collectors.toList());
        for (Network network : networksWithExternalRouter) {
            CloudIpPool cloudIpPool = new CloudIpPool();
            cloudIpPool.setId(network.getId());
            cloudIpPool.setName(network.getName());
            cloudGateWays.add(cloudIpPool);
        }
        for (AvailabilityZone availabilityZone : regionListEntry.getValue()) {
            cloudIpPools.put(availabilityZone.value(), cloudGateWays);
        }
    }
    LOGGER.info("openstack public ip pool result: {}", cloudIpPools);
    return new CloudIpPools(cloudIpPools);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) CloudIpPool(com.sequenceiq.cloudbreak.cloud.model.CloudIpPool) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) CloudIpPools(com.sequenceiq.cloudbreak.cloud.model.CloudIpPools) Network(org.openstack4j.model.network.Network) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) Region(com.sequenceiq.cloudbreak.cloud.model.Region) List(java.util.List) HashSet(java.util.HashSet)

Example 12 with CloudRegions

use of com.sequenceiq.cloudbreak.cloud.model.CloudRegions in project cloudbreak by hortonworks.

the class MockPlatformResourcesTest method getDefaultRegionWhenNoDefaultFoundForMockProviderThenShouldReturnWithTheFirstElement.

@Test
public void getDefaultRegionWhenNoDefaultFoundForMockProviderThenShouldReturnWithTheFirstElement() throws Exception {
    ReflectionTestUtils.setField(underTest, "defaultRegions", "AWS:eu-west-1");
    underTest.init();
    CloudRegions regions = underTest.regions(new CloudCredential(1L, "mock"), region("mock"), new HashMap<>());
    Assert.assertEquals("USA", regions.getDefaultRegion());
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) Test(org.junit.Test)

Example 13 with CloudRegions

use of com.sequenceiq.cloudbreak.cloud.model.CloudRegions in project cloudbreak by hortonworks.

the class MockPlatformResourcesTest method getDefaultRegionWhenDefaultFoundForMockProviderThenShouldReturnWithDefaultElement.

@Test
public void getDefaultRegionWhenDefaultFoundForMockProviderThenShouldReturnWithDefaultElement() throws Exception {
    ReflectionTestUtils.setField(underTest, "defaultRegions", "AWS:eu-west-1,MOCK:Europe");
    underTest.init();
    CloudRegions regions = underTest.regions(new CloudCredential(1L, "mock"), region("mock"), new HashMap<>());
    Assert.assertEquals("Europe", regions.getDefaultRegion());
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) Test(org.junit.Test)

Example 14 with CloudRegions

use of com.sequenceiq.cloudbreak.cloud.model.CloudRegions in project cloudbreak by hortonworks.

the class AzurePlatformResources method regions.

@Override
@Cacheable(cacheNames = "cloudResourceRegionCache", key = "#cloudCredential?.id")
public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    AzureClient client = azureClientService.getClient(cloudCredential);
    Map<Region, List<AvailabilityZone>> cloudRegions = new HashMap<>();
    Map<Region, String> displayNames = new HashMap<>();
    String defaultRegion = armZoneParameterDefault;
    for (com.microsoft.azure.management.resources.fluentcore.arm.Region azureRegion : client.getRegion(region)) {
        cloudRegions.put(region(azureRegion.label()), new ArrayList<>());
        displayNames.put(region(azureRegion.label()), azureRegion.label());
    }
    if (region != null && !Strings.isNullOrEmpty(region.value())) {
        defaultRegion = region.value();
    }
    return new CloudRegions(cloudRegions, displayNames, defaultRegion);
}
Also used : HashMap(java.util.HashMap) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) Region(com.sequenceiq.cloudbreak.cloud.model.Region) ArrayList(java.util.ArrayList) List(java.util.List) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)14 HashMap (java.util.HashMap)10 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)8 Region (com.sequenceiq.cloudbreak.cloud.model.Region)7 List (java.util.List)7 Cacheable (org.springframework.cache.annotation.Cacheable)7 HashSet (java.util.HashSet)6 Set (java.util.Set)6 ArrayList (java.util.ArrayList)4 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)3 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)3 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)2 Compute (com.google.api.services.compute.Compute)2 MachineTypeList (com.google.api.services.compute.model.MachineTypeList)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 CloudGateWay (com.sequenceiq.cloudbreak.cloud.model.CloudGateWay)2 CloudGateWays (com.sequenceiq.cloudbreak.cloud.model.CloudGateWays)2 Collections.singletonList (java.util.Collections.singletonList)2 Test (org.junit.Test)2 DescribeAvailabilityZonesRequest (com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest)1