use of com.sequenceiq.cloudbreak.cloud.model.Coordinate in project cloudbreak by hortonworks.
the class AzureRegionProvider method readEnabledRegions.
private Map<Region, Coordinate> readEnabledRegions() {
String displayNames = resourceDefinition();
Map<Region, Coordinate> regionCoordinates = new HashMap<>();
try {
RegionCoordinateSpecifications regionCoordinateSpecifications = JsonUtil.readValue(displayNames, RegionCoordinateSpecifications.class);
for (RegionCoordinateSpecification regionCoordinateSpecification : regionCoordinateSpecifications.getItems()) {
regionCoordinates.put(region(regionCoordinateSpecification.getName()), coordinate(regionCoordinateSpecification.getLongitude(), regionCoordinateSpecification.getLatitude(), findByLabelOrName(regionCoordinateSpecification.getName()).label(), findByLabelOrName(regionCoordinateSpecification.getName()).name(), regionCoordinateSpecification.isK8sSupported(), regionCoordinateSpecification.getEntitlements()));
}
} catch (IOException ignored) {
LOGGER.error("Failed to read enabled Azure regions from file.");
return regionCoordinates;
}
return regionCoordinates;
}
use of com.sequenceiq.cloudbreak.cloud.model.Coordinate in project cloudbreak by hortonworks.
the class GcpPlatformResources method regions.
@Override
@Cacheable(cacheNames = "cloudResourceRegionCache", key = "#cloudCredential?.id")
public CloudRegions regions(ExtendedCloudCredential cloudCredential, Region region, Map<String, String> filters, boolean availabilityZonesNeeded) throws Exception {
Compute compute = gcpComputeFactory.buildCompute(cloudCredential);
String projectId = gcpStackUtil.getProjectId(cloudCredential);
Map<Region, List<AvailabilityZone>> regionListMap = new HashMap<>();
Map<Region, String> displayNames = new HashMap<>();
Map<Region, Coordinate> coordinates = 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()));
addCoordinate(coordinates, gcpRegion);
}
}
if (region != null && !Strings.isNullOrEmpty(region.value())) {
defaultRegion = region.value();
}
return new CloudRegions(regionListMap, displayNames, coordinates, defaultRegion, true);
}
use of com.sequenceiq.cloudbreak.cloud.model.Coordinate in project cloudbreak by hortonworks.
the class EnvironmentTestData method getCloudRegions.
public static CloudRegions getCloudRegions() {
List<Region> regions = List.of(Region.region("r1"), Region.region("r2"));
List<String> displayNames = List.of("region 1", "region 2");
List<Coordinate> coordinates = List.of(Coordinate.coordinate("1", "2", "Here", "region-1", false, null), Coordinate.coordinate("2", "2", "There", "region-2", false, null));
List<List<AvailabilityZone>> availabilityZones = List.of(List.of(AvailabilityZone.availabilityZone("r1z1")), List.of(AvailabilityZone.availabilityZone("r2z1")));
Map regionZones = new Zip().intoMap(regions, availabilityZones);
Map regionDisplayNames = new Zip().intoMap(regions, displayNames);
Map regionCoordinates = new Zip().intoMap(regions, coordinates);
return new CloudRegions(regionZones, regionDisplayNames, regionCoordinates, "r1", true);
}
use of com.sequenceiq.cloudbreak.cloud.model.Coordinate in project cloudbreak by hortonworks.
the class EnvironmentService method setRegionsFromCloudCoordinates.
private void setRegionsFromCloudCoordinates(Set<String> requestedRegions, CloudRegions cloudRegions, Set<Region> regionSet) {
for (String requestedRegion : requestedRegions) {
Optional<Entry<com.sequenceiq.cloudbreak.cloud.model.Region, Coordinate>> coordinate = cloudRegions.getCoordinates().entrySet().stream().filter(e -> e.getKey().getRegionName().equals(requestedRegion) || e.getValue().getDisplayName().equals(requestedRegion) || e.getValue().getKey().equals(requestedRegion)).findFirst();
if (coordinate.isPresent()) {
Region region = new Region();
region.setName(coordinate.get().getValue().getKey());
String displayName = coordinate.get().getValue().getDisplayName();
region.setDisplayName(isEmpty(displayName) ? coordinate.get().getKey().getRegionName() : displayName);
regionSet.add(region);
}
}
}
use of com.sequenceiq.cloudbreak.cloud.model.Coordinate in project cloudbreak by hortonworks.
the class PlatformRegionsToRegionV1ResponseConverter method convert.
public RegionResponse convert(CloudRegions source) {
RegionResponse json = new RegionResponse();
List<String> regions = new ArrayList<>();
for (Region region : source.getCloudRegions().keySet()) {
regions.add(region.value());
}
Map<String, List<String>> availabilityZones = new HashMap<>();
for (Entry<Region, List<AvailabilityZone>> regionListEntry : source.getCloudRegions().entrySet()) {
List<String> azs = new ArrayList<>();
for (AvailabilityZone availabilityZone : regionListEntry.getValue()) {
azs.add(availabilityZone.value());
}
availabilityZones.put(regionListEntry.getKey().value(), azs);
}
Map<String, String> displayNames = new HashMap<>();
for (Entry<Region, String> regionStringEntry : source.getDisplayNames().entrySet()) {
displayNames.put(regionStringEntry.getKey().value(), regionStringEntry.getValue());
}
List<String> locations = new ArrayList<>();
List<String> k8sSupportedLocations = new ArrayList<>();
for (Entry<Region, Coordinate> coordinateEntry : source.getCoordinates().entrySet()) {
locations.add(coordinateEntry.getKey().getRegionName());
displayNames.put(coordinateEntry.getKey().getRegionName(), coordinateEntry.getValue().getDisplayName());
if (coordinateEntry.getValue().getK8sSupported()) {
k8sSupportedLocations.add(coordinateEntry.getKey().getRegionName());
}
}
Collections.sort(regions);
Collections.sort(locations);
Collections.sort(k8sSupportedLocations);
availabilityZones = availabilityZones.entrySet().stream().sorted(Comparator.comparing(o -> o.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, LinkedHashMap::new));
displayNames = displayNames.entrySet().stream().sorted(Comparator.comparing(o -> o.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, LinkedHashMap::new));
json.setNames(regions);
json.setAvailabilityZones(availabilityZones);
json.setDefaultRegion(source.getDefaultRegion());
json.setDisplayNames(displayNames);
json.setLocations(locations);
json.setK8sSupportedlocations(k8sSupportedLocations);
return json;
}
Aggregations