Search in sources :

Example 1 with DisplayName

use of com.sequenceiq.cloudbreak.cloud.model.DisplayName in project cloudbreak by hortonworks.

the class PlatformRecommendationToPlatformRecommendationResponseConverter method convert.

@Override
public RecommendationResponse convert(PlatformRecommendation source) {
    Map<String, VmTypeJson> result = new HashMap<>();
    source.getRecommendations().forEach((hostGroupName, vm) -> result.put(hostGroupName, getConversionService().convert(vm, VmTypeJson.class)));
    Set<VmTypeJson> vmTypes = source.getVirtualMachines().stream().map(vmType -> getConversionService().convert(vmType, VmTypeJson.class)).collect(Collectors.toSet());
    Set<DiskResponse> diskResponses = new HashSet<>();
    for (Entry<DiskType, DisplayName> diskTypeDisplayName : source.getDiskTypes().displayNames().entrySet()) {
        for (Entry<String, VolumeParameterType> volumeParameterType : source.getDiskTypes().diskMapping().entrySet()) {
            if (diskTypeDisplayName.getKey().value().equals(volumeParameterType.getKey())) {
                DiskResponse diskResponse = new DiskResponse(diskTypeDisplayName.getKey().value(), volumeParameterType.getValue().name(), diskTypeDisplayName.getValue().value());
                diskResponses.add(diskResponse);
            }
        }
    }
    return new RecommendationResponse(result, vmTypes, diskResponses);
}
Also used : DisplayName(com.sequenceiq.cloudbreak.cloud.model.DisplayName) PlatformRecommendation(com.sequenceiq.cloudbreak.cloud.model.PlatformRecommendation) DiskType(com.sequenceiq.cloudbreak.cloud.model.DiskType) Set(java.util.Set) HashMap(java.util.HashMap) RecommendationResponse(com.sequenceiq.cloudbreak.api.model.RecommendationResponse) Collectors(java.util.stream.Collectors) DiskResponse(com.sequenceiq.cloudbreak.api.model.DiskResponse) HashSet(java.util.HashSet) Component(org.springframework.stereotype.Component) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) Map(java.util.Map) Entry(java.util.Map.Entry) VmTypeJson(com.sequenceiq.cloudbreak.api.model.VmTypeJson) HashMap(java.util.HashMap) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) VmTypeJson(com.sequenceiq.cloudbreak.api.model.VmTypeJson) DiskType(com.sequenceiq.cloudbreak.cloud.model.DiskType) RecommendationResponse(com.sequenceiq.cloudbreak.api.model.RecommendationResponse) DiskResponse(com.sequenceiq.cloudbreak.api.model.DiskResponse) DisplayName(com.sequenceiq.cloudbreak.cloud.model.DisplayName) HashSet(java.util.HashSet)

Example 2 with DisplayName

use of com.sequenceiq.cloudbreak.cloud.model.DisplayName in project cloudbreak by hortonworks.

the class AwsPlatformResources method regions.

@Override
@Cacheable(cacheNames = "cloudResourceRegionCache", key = "#cloudCredential?.id")
public CloudRegions regions(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    AmazonEC2Client ec2Client = awsClient.createAccess(cloudCredential);
    Map<Region, List<AvailabilityZone>> regionListMap = new HashMap<>();
    Map<Region, String> displayNames = new HashMap<>();
    DescribeRegionsRequest describeRegionsRequest = new DescribeRegionsRequest();
    DescribeRegionsResult describeRegionsResult = ec2Client.describeRegions(describeRegionsRequest);
    String defaultRegion = awsZoneParameterDefault;
    for (com.amazonaws.services.ec2.model.Region awsRegion : describeRegionsResult.getRegions()) {
        if (region == null || Strings.isNullOrEmpty(region.value()) || awsRegion.getRegionName().equals(region.value())) {
            DescribeAvailabilityZonesRequest describeAvailabilityZonesRequest = new DescribeAvailabilityZonesRequest();
            ec2Client.setRegion(RegionUtils.getRegion(awsRegion.getRegionName()));
            Filter filter = new Filter();
            filter.setName("region-name");
            Collection<String> list = new ArrayList<>();
            list.add(awsRegion.getRegionName());
            filter.setValues(list);
            describeAvailabilityZonesRequest.withFilters(filter);
            DescribeAvailabilityZonesResult describeAvailabilityZonesResult = ec2Client.describeAvailabilityZones(describeAvailabilityZonesRequest);
            List<AvailabilityZone> tmpAz = new ArrayList<>();
            for (com.amazonaws.services.ec2.model.AvailabilityZone availabilityZone : describeAvailabilityZonesResult.getAvailabilityZones()) {
                tmpAz.add(availabilityZone(availabilityZone.getZoneName()));
            }
            regionListMap.put(region(awsRegion.getRegionName()), tmpAz);
            DisplayName displayName = regionDisplayNames.get(region(awsRegion.getRegionName()));
            if (displayName == null || Strings.isNullOrEmpty(displayName.value())) {
                displayNames.put(region(awsRegion.getRegionName()), awsRegion.getRegionName());
            } else {
                displayNames.put(region(awsRegion.getRegionName()), displayName.value());
            }
        }
    }
    if (region != null && !Strings.isNullOrEmpty(region.value())) {
        defaultRegion = region.value();
    }
    return new CloudRegions(regionListMap, displayNames, defaultRegion);
}
Also used : AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) HashMap(java.util.HashMap) DescribeAvailabilityZonesRequest(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest) ArrayList(java.util.ArrayList) AvailabilityZone(com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) DescribeRegionsRequest(com.amazonaws.services.ec2.model.DescribeRegionsRequest) DescribeAvailabilityZonesResult(com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult) DescribeRegionsResult(com.amazonaws.services.ec2.model.DescribeRegionsResult) Filter(com.amazonaws.services.ec2.model.Filter) DisplayName(com.sequenceiq.cloudbreak.cloud.model.DisplayName) Region(com.sequenceiq.cloudbreak.cloud.model.Region) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

DisplayName (com.sequenceiq.cloudbreak.cloud.model.DisplayName)2 HashMap (java.util.HashMap)2 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)1 DescribeAvailabilityZonesRequest (com.amazonaws.services.ec2.model.DescribeAvailabilityZonesRequest)1 DescribeAvailabilityZonesResult (com.amazonaws.services.ec2.model.DescribeAvailabilityZonesResult)1 DescribeRegionsRequest (com.amazonaws.services.ec2.model.DescribeRegionsRequest)1 DescribeRegionsResult (com.amazonaws.services.ec2.model.DescribeRegionsResult)1 Filter (com.amazonaws.services.ec2.model.Filter)1 DiskResponse (com.sequenceiq.cloudbreak.api.model.DiskResponse)1 RecommendationResponse (com.sequenceiq.cloudbreak.api.model.RecommendationResponse)1 VmTypeJson (com.sequenceiq.cloudbreak.api.model.VmTypeJson)1 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)1 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)1 DiskType (com.sequenceiq.cloudbreak.cloud.model.DiskType)1 PlatformRecommendation (com.sequenceiq.cloudbreak.cloud.model.PlatformRecommendation)1 Region (com.sequenceiq.cloudbreak.cloud.model.Region)1 VolumeParameterType (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 HashSet (java.util.HashSet)1