Search in sources :

Example 1 with Coordinate

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;
}
Also used : RegionCoordinateSpecification(com.sequenceiq.cloudbreak.cloud.model.RegionCoordinateSpecification) Coordinate(com.sequenceiq.cloudbreak.cloud.model.Coordinate) HashMap(java.util.HashMap) Region(com.sequenceiq.cloudbreak.cloud.model.Region) IOException(java.io.IOException) RegionCoordinateSpecifications(com.sequenceiq.cloudbreak.cloud.model.RegionCoordinateSpecifications)

Example 2 with Coordinate

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) Coordinate(com.sequenceiq.cloudbreak.cloud.model.Coordinate) Compute(com.google.api.services.compute.Compute) Region(com.sequenceiq.cloudbreak.cloud.model.Region) RegionList(com.google.api.services.compute.model.RegionList) List(java.util.List) MachineTypeList(com.google.api.services.compute.model.MachineTypeList) SubnetworkList(com.google.api.services.compute.model.SubnetworkList) FirewallList(com.google.api.services.compute.model.FirewallList) ArrayList(java.util.ArrayList) NetworkList(com.google.api.services.compute.model.NetworkList) RegionList(com.google.api.services.compute.model.RegionList) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 3 with Coordinate

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);
}
Also used : Coordinate(com.sequenceiq.cloudbreak.cloud.model.Coordinate) Region(com.sequenceiq.cloudbreak.cloud.model.Region) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) List(java.util.List) Map(java.util.Map)

Example 4 with Coordinate

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);
        }
    }
}
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) Region(com.sequenceiq.environment.environment.domain.Region)

Example 5 with Coordinate

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;
}
Also used : Region(com.sequenceiq.cloudbreak.cloud.model.Region) HashMap(java.util.HashMap) RegionResponse(com.sequenceiq.environment.api.v1.platformresource.model.RegionResponse) Collectors(java.util.stream.Collectors) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) List(java.util.List) Component(org.springframework.stereotype.Component) Map(java.util.Map) Entry(java.util.Map.Entry) Coordinate(com.sequenceiq.cloudbreak.cloud.model.Coordinate) Comparator(java.util.Comparator) Collections(java.util.Collections) RegionResponse(com.sequenceiq.environment.api.v1.platformresource.model.RegionResponse) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) LinkedHashMap(java.util.LinkedHashMap) Entry(java.util.Map.Entry) Coordinate(com.sequenceiq.cloudbreak.cloud.model.Coordinate) Region(com.sequenceiq.cloudbreak.cloud.model.Region) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Coordinate (com.sequenceiq.cloudbreak.cloud.model.Coordinate)11 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Region (com.sequenceiq.cloudbreak.cloud.model.Region)7 ArrayList (java.util.ArrayList)5 Map (java.util.Map)4 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)3 Entry (java.util.Map.Entry)3 Collectors (java.util.stream.Collectors)3 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)2 DescribeRegionsResult (com.amazonaws.services.ec2.model.DescribeRegionsResult)2 RegionCoordinateSpecification (com.sequenceiq.cloudbreak.cloud.model.RegionCoordinateSpecification)2 RegionCoordinateSpecifications (com.sequenceiq.cloudbreak.cloud.model.RegionCoordinateSpecifications)2 IOException (java.io.IOException)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Logger (org.slf4j.Logger)2