use of com.sequenceiq.environment.environment.domain.RegionWrapper in project cloudbreak by hortonworks.
the class EnvironmentServiceTest method setLocationByCoordinates.
@Test
void setLocationByCoordinates() {
RegionWrapper location = new RegionWrapper("r1", "Somewhere else", 1.2, 1.3, Collections.emptySet());
environmentServiceUnderTest.setLocation(environment, location, EnvironmentTestData.getCloudRegions());
assertEquals("Here", environment.getLocationDisplayName());
}
use of com.sequenceiq.environment.environment.domain.RegionWrapper in project cloudbreak by hortonworks.
the class EnvironmentServiceTest method setLocationByLocation.
@Test
void setLocationByLocation() {
RegionWrapper location = new RegionWrapper("r3", "Somewhere else", 1.2, 1.3, Collections.emptySet());
environmentServiceUnderTest.setLocation(environment, location, EnvironmentTestData.getCloudRegions());
assertEquals("Somewhere else", environment.getLocationDisplayName());
}
use of com.sequenceiq.environment.environment.domain.RegionWrapper in project cloudbreak by hortonworks.
the class EnvironmentServiceTest method setLocationLocationCoordinatesAreInvalid.
@Test
void setLocationLocationCoordinatesAreInvalid() {
RegionWrapper location = new RegionWrapper("r3", "Somewhere else", null, 1.3, Collections.emptySet());
assertThrows(BadRequestException.class, () -> environmentServiceUnderTest.setLocation(environment, location, EnvironmentTestData.getCloudRegions()));
}
use of com.sequenceiq.environment.environment.domain.RegionWrapper 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.environment.environment.domain.RegionWrapper in project cloudbreak by hortonworks.
the class EnvironmentInitHandler method setLocationAndRegions.
private void setLocationAndRegions(Environment environment) {
CloudRegions cloudRegions = environmentService.getRegionsByEnvironment(environment);
RegionWrapper regionWrapper = environment.getRegionWrapper();
environmentService.setLocation(environment, regionWrapper, cloudRegions);
if (cloudRegions.areRegionsSupported()) {
environmentService.setRegions(environment, regionWrapper.getRegions(), cloudRegions);
}
}
Aggregations