Search in sources :

Example 1 with RegionList

use of com.google.api.services.compute.model.RegionList in project google-cloud-java by GoogleCloudPlatform.

the class HttpComputeRpc method listRegions.

@Override
public Tuple<String, Iterable<Region>> listRegions(Map<Option, ?> options) {
    try {
        RegionList regionsList = compute.regions().list(this.options.getProjectId()).setFilter(Option.FILTER.getString(options)).setMaxResults(Option.MAX_RESULTS.getLong(options)).setPageToken(Option.PAGE_TOKEN.getString(options)).setFields(Option.FIELDS.getString(options)).execute();
        Iterable<Region> regions = regionsList.getItems();
        return Tuple.of(regionsList.getNextPageToken(), regions);
    } catch (IOException ex) {
        throw translate(ex);
    }
}
Also used : Region(com.google.api.services.compute.model.Region) RegionList(com.google.api.services.compute.model.RegionList) IOException(java.io.IOException)

Example 2 with RegionList

use of com.google.api.services.compute.model.RegionList in project cloudbreak by hortonworks.

the class GcpPlatformResources method regions.

@Override
@Cacheable(cacheNames = "cloudResourceRegionCache", key = "#cloudCredential?.id")
public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters) throws Exception {
    Compute compute = GcpStackUtil.buildCompute(cloudCredential);
    String projectId = GcpStackUtil.getProjectId(cloudCredential);
    Map<Region, List<AvailabilityZone>> regionListMap = new HashMap<>();
    Map<Region, String> displayNames = new HashMap<>();
    String defaultRegion = gcpZoneParameterDefault;
    RegionList regionList = compute.regions().list(projectId).execute();
    for (com.google.api.services.compute.model.Region gcpRegion : regionList.getItems()) {
        if (region == null || Strings.isNullOrEmpty(region.value()) || gcpRegion.getName().equals(region.value())) {
            List<AvailabilityZone> availabilityZones = new ArrayList<>();
            for (String s : gcpRegion.getZones()) {
                String[] split = s.split("/");
                if (split.length > 0) {
                    availabilityZones.add(AvailabilityZone.availabilityZone(split[split.length - 1]));
                }
            }
            regionListMap.put(region(gcpRegion.getName()), availabilityZones);
            displayNames.put(region(gcpRegion.getName()), displayName(gcpRegion.getName()));
        }
    }
    if (region != null && !Strings.isNullOrEmpty(region.value())) {
        defaultRegion = region.value();
    }
    return new CloudRegions(regionListMap, displayNames, defaultRegion);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) Compute(com.google.api.services.compute.Compute) Region(com.sequenceiq.cloudbreak.cloud.model.Region) ArrayList(java.util.ArrayList) NetworkList(com.google.api.services.compute.model.NetworkList) RegionList(com.google.api.services.compute.model.RegionList) List(java.util.List) MachineTypeList(com.google.api.services.compute.model.MachineTypeList) FirewallList(com.google.api.services.compute.model.FirewallList) RegionList(com.google.api.services.compute.model.RegionList) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

RegionList (com.google.api.services.compute.model.RegionList)2 Compute (com.google.api.services.compute.Compute)1 FirewallList (com.google.api.services.compute.model.FirewallList)1 MachineTypeList (com.google.api.services.compute.model.MachineTypeList)1 NetworkList (com.google.api.services.compute.model.NetworkList)1 Region (com.google.api.services.compute.model.Region)1 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)1 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)1 Region (com.sequenceiq.cloudbreak.cloud.model.Region)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Cacheable (org.springframework.cache.annotation.Cacheable)1