use of com.sequenceiq.cloudbreak.cloud.model.Coordinate in project cloudbreak by hortonworks.
the class AwsPlatformResources method readRegionCoordinates.
private Map<Region, Coordinate> readRegionCoordinates(String displayNames) {
Map<Region, Coordinate> regionCoordinates = new HashMap<>();
try {
RegionCoordinateSpecifications regionCoordinateSpecifications = JsonUtil.readValue(displayNames, RegionCoordinateSpecifications.class);
for (RegionCoordinateSpecification regionCoordinateSpecification : regionCoordinateSpecifications.getItems()) {
Region region = region(regionCoordinateSpecification.getName());
if (!enabledRegions.contains(region)) {
continue;
}
Optional<Entry<Region, DisplayName>> regionEntry = regionDisplayNames.entrySet().stream().filter(e -> e.getKey().getRegionName().equalsIgnoreCase(regionCoordinateSpecification.getName())).findFirst();
regionCoordinates.put(region, coordinate(regionCoordinateSpecification.getLongitude(), regionCoordinateSpecification.getLatitude(), regionCoordinateSpecification.getDisplayName(), regionEntry.isPresent() ? regionEntry.get().getKey().value() : regionCoordinateSpecification.getDisplayName(), regionCoordinateSpecification.isK8sSupported(), regionCoordinateSpecification.getEntitlements()));
}
} catch (IOException ignored) {
return regionCoordinates;
}
return regionCoordinates;
}
use of com.sequenceiq.cloudbreak.cloud.model.Coordinate in project cloudbreak by hortonworks.
the class AzureRegionProvider method regions.
public CloudRegions regions(Region region, Collection<com.microsoft.azure.management.resources.fluentcore.arm.Region> azureRegions, List<String> entitlements) {
Map<Region, List<AvailabilityZone>> cloudRegions = new HashMap<>();
Map<Region, String> displayNames = new HashMap<>();
Map<Region, Coordinate> coordinates = new HashMap<>();
String defaultRegion = armZoneParameterDefault;
azureRegions = filterByEnabledRegions(azureRegions);
for (com.microsoft.azure.management.resources.fluentcore.arm.Region azureRegion : azureRegions) {
Coordinate coordinate = enabledRegions.get(region(azureRegion.label()));
if (isEntitledFor(coordinate, entitlements)) {
cloudRegions.put(region(azureRegion.label()), new ArrayList<>());
displayNames.put(region(azureRegion.label()), azureRegion.label());
if (coordinate == null || coordinate.getLongitude() == null || coordinate.getLatitude() == null) {
LOGGER.warn("Unregistered region with location coordinates on azure side: {} using default California", azureRegion.label());
coordinates.put(region(azureRegion.label()), Coordinate.defaultCoordinate());
} else {
coordinates.put(region(azureRegion.label()), coordinate);
}
}
}
if (region != null && !Strings.isNullOrEmpty(region.value())) {
defaultRegion = region.value();
}
return new CloudRegions(cloudRegions, displayNames, coordinates, defaultRegion, true);
}
use of com.sequenceiq.cloudbreak.cloud.model.Coordinate in project cloudbreak by hortonworks.
the class EnvironmentService method setLocation.
public void setLocation(Environment environment, RegionWrapper regionWrapper, CloudRegions cloudRegions) {
if (regionWrapper != null) {
LOGGER.debug("Setting location for environment. Location: '{}'.", regionWrapper);
Optional<Entry<com.sequenceiq.cloudbreak.cloud.model.Region, Coordinate>> coordinate = cloudRegions.getCoordinates().entrySet().stream().filter(e -> e.getKey().getRegionName().equals(regionWrapper.getName()) || e.getValue().getDisplayName().equals(regionWrapper.getName()) || e.getValue().getKey().equals(regionWrapper.getName())).findFirst();
if (coordinate.isPresent()) {
environment.setLocation(coordinate.get().getValue().getKey());
environment.setLocationDisplayName(coordinate.get().getValue().getDisplayName());
environment.setLatitude(coordinate.get().getValue().getLatitude());
environment.setLongitude(coordinate.get().getValue().getLongitude());
} else if (regionWrapper.getLatitude() != null && regionWrapper.getLongitude() != null) {
environment.setLocation(regionWrapper.getName());
environment.setLocationDisplayName(regionWrapper.getDisplayName());
environment.setLatitude(regionWrapper.getLatitude());
environment.setLongitude(regionWrapper.getLongitude());
} else {
throw new BadRequestException(String.format("No location found with name %s in the location list. The supported locations are: [%s]", regionWrapper.getName(), cloudRegions.locationNames()));
}
}
}
use of com.sequenceiq.cloudbreak.cloud.model.Coordinate in project cloudbreak by hortonworks.
the class GcpPlatformResources method addCoordinate.
public void addCoordinate(Map<Region, Coordinate> coordinates, com.google.api.services.compute.model.Region gcpRegion) {
Coordinate coordinate = regionCoordinates.get(region(gcpRegion.getName()));
if (coordinate == null || coordinate.getLongitude() == null || coordinate.getLatitude() == null) {
LOGGER.warn("Unregistered region with location coordinates on gcp side: {} using default California", gcpRegion.getName());
coordinates.put(region(gcpRegion.getName()), Coordinate.defaultCoordinate());
} else {
coordinates.put(region(gcpRegion.getName()), coordinate);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.Coordinate in project cloudbreak by hortonworks.
the class AwsPlatformResources method addCoordinate.
public void addCoordinate(Map<Region, Coordinate> coordinates, com.amazonaws.services.ec2.model.Region awsRegion) {
Coordinate coordinate = regionCoordinates.get(region(awsRegion.getRegionName()));
if (coordinate == null || coordinate.getLongitude() == null || coordinate.getLatitude() == null) {
LOGGER.warn("Unregistered region with location coordinates on aws side: {} using default California", awsRegion.getRegionName());
coordinates.put(region(awsRegion.getRegionName()), Coordinate.defaultCoordinate());
} else {
coordinates.put(region(awsRegion.getRegionName()), coordinate);
}
}
Aggregations