Search in sources :

Example 1 with RegionWrapper

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());
}
Also used : RegionWrapper(com.sequenceiq.environment.environment.domain.RegionWrapper) Test(org.junit.jupiter.api.Test)

Example 2 with RegionWrapper

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());
}
Also used : RegionWrapper(com.sequenceiq.environment.environment.domain.RegionWrapper) Test(org.junit.jupiter.api.Test)

Example 3 with RegionWrapper

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()));
}
Also used : RegionWrapper(com.sequenceiq.environment.environment.domain.RegionWrapper) Test(org.junit.jupiter.api.Test)

Example 4 with RegionWrapper

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()));
        }
    }
}
Also used : EnvironmentDtoConverter(com.sequenceiq.environment.environment.dto.EnvironmentDtoConverter) Environment(com.sequenceiq.environment.environment.domain.Environment) RoleCrnGenerator(com.sequenceiq.cloudbreak.auth.altus.service.RoleCrnGenerator) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) TransactionService(com.sequenceiq.cloudbreak.common.service.TransactionService) AccountAwareResourceRepository(com.sequenceiq.cloudbreak.common.dal.repository.AccountAwareResourceRepository) Map(java.util.Map) RegionWrapper(com.sequenceiq.environment.environment.domain.RegionWrapper) BadRequestException(javax.ws.rs.BadRequestException) Region(com.sequenceiq.environment.environment.domain.Region) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) EnumSet(java.util.EnumSet) Tunnel(com.sequenceiq.common.api.type.Tunnel) ResourceWithId(com.sequenceiq.authorization.service.list.ResourceWithId) PayloadContext(com.sequenceiq.cloudbreak.common.event.PayloadContext) PlatformParameterService(com.sequenceiq.environment.platformresource.PlatformParameterService) Collection(java.util.Collection) Set(java.util.Set) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto) JobResource(com.sequenceiq.cloudbreak.quartz.model.JobResource) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Collectors(java.util.stream.Collectors) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) EnvironmentRepository(com.sequenceiq.environment.environment.repository.EnvironmentRepository) EnvironmentPropertyProvider(com.sequenceiq.authorization.service.EnvironmentPropertyProvider) List(java.util.List) MDCUtils(com.sequenceiq.cloudbreak.logger.MDCUtils) Entry(java.util.Map.Entry) Optional(java.util.Optional) Coordinate(com.sequenceiq.cloudbreak.cloud.model.Coordinate) AbstractAccountAwareResourceService(com.sequenceiq.cloudbreak.common.service.account.AbstractAccountAwareResourceService) OwnerAssignmentService(com.sequenceiq.authorization.service.OwnerAssignmentService) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) HashMap(java.util.HashMap) CompositeAuthResourcePropertyProvider(com.sequenceiq.authorization.service.CompositeAuthResourcePropertyProvider) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) HashSet(java.util.HashSet) Value(org.springframework.beans.factory.annotation.Value) Code(io.grpc.Status.Code) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest) ExperimentalFeatures(com.sequenceiq.environment.environment.domain.ExperimentalFeatures) NotFoundException.notFound(com.sequenceiq.cloudbreak.common.exception.NotFoundException.notFound) Logger(org.slf4j.Logger) NotFoundException.notFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException.notFoundException) PayloadContextProvider(com.sequenceiq.flow.core.PayloadContextProvider) GrpcUmsClient(com.sequenceiq.cloudbreak.auth.altus.GrpcUmsClient) StatusRuntimeException(io.grpc.StatusRuntimeException) EnvironmentValidatorService(com.sequenceiq.environment.environment.validation.EnvironmentValidatorService) ResourceIdProvider(com.sequenceiq.flow.core.ResourceIdProvider) Entry(java.util.Map.Entry) BadRequestException(javax.ws.rs.BadRequestException)

Example 5 with RegionWrapper

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);
    }
}
Also used : CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) RegionWrapper(com.sequenceiq.environment.environment.domain.RegionWrapper)

Aggregations

RegionWrapper (com.sequenceiq.environment.environment.domain.RegionWrapper)6 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)3 Test (org.junit.jupiter.api.Test)3 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)2 Lists (com.google.common.collect.Lists)1 CompositeAuthResourcePropertyProvider (com.sequenceiq.authorization.service.CompositeAuthResourcePropertyProvider)1 EnvironmentPropertyProvider (com.sequenceiq.authorization.service.EnvironmentPropertyProvider)1 OwnerAssignmentService (com.sequenceiq.authorization.service.OwnerAssignmentService)1 ResourceWithId (com.sequenceiq.authorization.service.list.ResourceWithId)1 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)1 GrpcUmsClient (com.sequenceiq.cloudbreak.auth.altus.GrpcUmsClient)1 RoleCrnGenerator (com.sequenceiq.cloudbreak.auth.altus.service.RoleCrnGenerator)1 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)1 RegionAwareInternalCrnGeneratorFactory (com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory)1 Coordinate (com.sequenceiq.cloudbreak.cloud.model.Coordinate)1 AccountAwareResourceRepository (com.sequenceiq.cloudbreak.common.dal.repository.AccountAwareResourceRepository)1 PayloadContext (com.sequenceiq.cloudbreak.common.event.PayloadContext)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 NotFoundException.notFound (com.sequenceiq.cloudbreak.common.exception.NotFoundException.notFound)1 NotFoundException.notFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException.notFoundException)1