Search in sources :

Example 1 with RegionResponse

use of com.sequenceiq.environment.api.v1.platformresource.model.RegionResponse in project cloudbreak by hortonworks.

the class CredentialPlatformResourceController method getRegionsByCredential.

@Override
@CustomPermissionCheck
public RegionResponse getRegionsByCredential(String credentialName, String credentialCrn, String region, String platformVariant, String availabilityZone, boolean availabilityZonesNeeded) {
    customCheckUtil.run(() -> permissionCheckByCredential(credentialName, credentialCrn));
    String accountId = getAccountId();
    PlatformResourceRequest request = platformParameterService.getPlatformResourceRequest(accountId, credentialName, credentialCrn, region, platformVariant, availabilityZone);
    LOGGER.info("Get /platform_resources/regions, request: {}", request);
    CloudRegions regions = platformParameterService.getRegionsByCredential(request, availabilityZonesNeeded);
    RegionResponse response = platformRegionsToRegionV1ResponseConverter.convert(regions);
    LOGGER.info("Resp /platform_resources/regions, request: {}, regions: {}, response: {}", request, regions, response);
    return response;
}
Also used : RegionResponse(com.sequenceiq.environment.api.v1.platformresource.model.RegionResponse) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest) CustomPermissionCheck(com.sequenceiq.authorization.annotation.CustomPermissionCheck)

Example 2 with RegionResponse

use of com.sequenceiq.environment.api.v1.platformresource.model.RegionResponse in project cloudbreak by hortonworks.

the class EnvironmentPlatformResourceController method getRegionsByCredential.

@Override
@CheckPermissionByResourceCrn(action = AuthorizationResourceAction.DESCRIBE_ENVIRONMENT)
public RegionResponse getRegionsByCredential(@ResourceCrn String environmentCrn, String region, String platformVariant, String availabilityZone, boolean availabilityZonesNeeded) {
    String accountId = getAccountId();
    validateEnvironmentCrnPattern(environmentCrn);
    PlatformResourceRequest request = platformParameterService.getPlatformResourceRequestByEnvironment(accountId, environmentCrn, region, platformVariant, availabilityZone, null);
    LOGGER.info("Get /platform_resources/regions, request: {}", request);
    CloudRegions regions = platformParameterService.getRegionsByCredential(request, availabilityZonesNeeded);
    RegionResponse response = platformRegionsToRegionV1ResponseConverter.convert(regions);
    LOGGER.info("Resp /platform_resources/regions, request: {}, regions: {}, response: {}", request, regions, response);
    return response;
}
Also used : RegionResponse(com.sequenceiq.environment.api.v1.platformresource.model.RegionResponse) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)

Example 3 with RegionResponse

use of com.sequenceiq.environment.api.v1.platformresource.model.RegionResponse 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)

Example 4 with RegionResponse

use of com.sequenceiq.environment.api.v1.platformresource.model.RegionResponse in project cloudbreak by hortonworks.

the class DistroXV1RequestToStackV4RequestConverterTest method createCompactRegionResponse.

private CompactRegionResponse createCompactRegionResponse() {
    CompactRegionResponse regionResponse = new CompactRegionResponse();
    regionResponse.setNames(List.of("myregion"));
    return regionResponse;
}
Also used : CompactRegionResponse(com.sequenceiq.environment.api.v1.environment.model.response.CompactRegionResponse)

Aggregations

CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)3 RegionResponse (com.sequenceiq.environment.api.v1.platformresource.model.RegionResponse)3 PlatformResourceRequest (com.sequenceiq.environment.platformresource.PlatformResourceRequest)2 CheckPermissionByResourceCrn (com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)1 CustomPermissionCheck (com.sequenceiq.authorization.annotation.CustomPermissionCheck)1 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)1 Coordinate (com.sequenceiq.cloudbreak.cloud.model.Coordinate)1 Region (com.sequenceiq.cloudbreak.cloud.model.Region)1 CompactRegionResponse (com.sequenceiq.environment.api.v1.environment.model.response.CompactRegionResponse)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Collectors (java.util.stream.Collectors)1 Component (org.springframework.stereotype.Component)1