Search in sources :

Example 1 with DiskType

use of com.sequenceiq.cloudbreak.cloud.model.DiskType 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 DiskType

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

the class TemplateValidator method validateVolumeType.

private void validateVolumeType(Template value, Platform platform) {
    DiskType diskType = DiskType.diskType(value.getVolumeType());
    Map<Platform, Collection<DiskType>> diskTypes = cloudParameterService.getDiskTypes().getDiskTypes();
    if (diskTypes.containsKey(platform) && !diskTypes.get(platform).isEmpty()) {
        if (!diskTypes.get(platform).contains(diskType)) {
            throw new BadRequestException(String.format("The '%s' platform does not support '%s' volume type", platform.value(), diskType.value()));
        }
    }
}
Also used : DiskType(com.sequenceiq.cloudbreak.cloud.model.DiskType) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) Collection(java.util.Collection) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException)

Example 3 with DiskType

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

the class GetDiskTypesHandler method accept.

@Override
public void accept(Event<GetDiskTypesRequest> getDiskTypesRequestEvent) {
    LOGGER.info("Received event: {}", getDiskTypesRequestEvent);
    GetDiskTypesRequest request = getDiskTypesRequestEvent.getData();
    try {
        Map<Platform, Collection<DiskType>> platformDiskTypes = Maps.newHashMap();
        Map<Platform, DiskType> defaultDiskTypes = Maps.newHashMap();
        Map<Platform, Map<String, VolumeParameterType>> diskMappings = Maps.newHashMap();
        Map<Platform, Map<DiskType, DisplayName>> diskDisplayNames = Maps.newHashMap();
        for (Entry<Platform, Collection<Variant>> connector : cloudPlatformConnectors.getPlatformVariants().getPlatformToVariants().entrySet()) {
            DiskTypes diskTypes = cloudPlatformConnectors.getDefault(connector.getKey()).parameters().diskTypes();
            defaultDiskTypes.put(connector.getKey(), diskTypes.defaultType());
            platformDiskTypes.put(connector.getKey(), diskTypes.types());
            diskMappings.put(connector.getKey(), diskTypes.diskMapping());
            diskDisplayNames.put(connector.getKey(), diskTypes.displayNames());
        }
        GetDiskTypesResult getDiskTypesResult = new GetDiskTypesResult(request, new PlatformDisks(platformDiskTypes, defaultDiskTypes, diskMappings, diskDisplayNames));
        request.getResult().onNext(getDiskTypesResult);
        LOGGER.info("Query platform disk types finished.");
    } catch (RuntimeException e) {
        request.getResult().onNext(new GetDiskTypesResult(e.getMessage(), e, request));
    }
}
Also used : Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) PlatformDisks(com.sequenceiq.cloudbreak.cloud.model.PlatformDisks) DiskType(com.sequenceiq.cloudbreak.cloud.model.DiskType) GetDiskTypesRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetDiskTypesRequest) GetDiskTypesResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetDiskTypesResult) DiskTypes(com.sequenceiq.cloudbreak.cloud.model.DiskTypes) Collection(java.util.Collection) Map(java.util.Map)

Aggregations

DiskType (com.sequenceiq.cloudbreak.cloud.model.DiskType)3 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)2 Collection (java.util.Collection)2 Map (java.util.Map)2 DiskResponse (com.sequenceiq.cloudbreak.api.model.DiskResponse)1 RecommendationResponse (com.sequenceiq.cloudbreak.api.model.RecommendationResponse)1 VmTypeJson (com.sequenceiq.cloudbreak.api.model.VmTypeJson)1 GetDiskTypesRequest (com.sequenceiq.cloudbreak.cloud.event.platform.GetDiskTypesRequest)1 GetDiskTypesResult (com.sequenceiq.cloudbreak.cloud.event.platform.GetDiskTypesResult)1 DiskTypes (com.sequenceiq.cloudbreak.cloud.model.DiskTypes)1 DisplayName (com.sequenceiq.cloudbreak.cloud.model.DisplayName)1 PlatformDisks (com.sequenceiq.cloudbreak.cloud.model.PlatformDisks)1 PlatformRecommendation (com.sequenceiq.cloudbreak.cloud.model.PlatformRecommendation)1 VolumeParameterType (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1