Search in sources :

Example 1 with VolumeParameterType

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

the class AzurePlatformResources method virtualMachines.

@Override
@Cacheable(cacheNames = "cloudResourceVmTypeCache", key = "#cloudCredential?.id + #region.getRegionName()")
public CloudVmTypes virtualMachines(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    AzureClient client = azureClientService.getClient(cloudCredential);
    Set<VirtualMachineSize> vmTypes = client.getVmTypes(region.value());
    Map<String, Set<VmType>> cloudVmResponses = new HashMap<>();
    Map<String, VmType> defaultCloudVmResponses = new HashMap<>();
    Set<VmType> types = new HashSet<>();
    VmType defaultVmType = null;
    for (VirtualMachineSize virtualMachineSize : vmTypes) {
        float memoryInGB = virtualMachineSize.memoryInMB() / NO_MB_PER_GB;
        VmTypeMetaBuilder builder = VmTypeMetaBuilder.builder().withCpuAndMemory(virtualMachineSize.numberOfCores(), memoryInGB);
        for (VolumeParameterType volumeParameterType : values()) {
            switch(volumeParameterType) {
                case MAGNETIC:
                    builder.withMagneticConfig(volumeParameterConfig(MAGNETIC, virtualMachineSize));
                    break;
                default:
                    break;
            }
        }
        VmType vmType = VmType.vmTypeWithMeta(virtualMachineSize.name(), builder.create(), true);
        types.add(vmType);
        if (virtualMachineSize.name().equals(armVmDefault)) {
            defaultVmType = vmType;
        }
    }
    cloudVmResponses.put(region.value(), types);
    defaultCloudVmResponses.put(region.value(), defaultVmType);
    return new CloudVmTypes(cloudVmResponses, defaultCloudVmResponses);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) AzureClient(com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient) VirtualMachineSize(com.microsoft.azure.management.compute.VirtualMachineSize) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) VmTypeMetaBuilder(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder) HashSet(java.util.HashSet) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 2 with VolumeParameterType

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

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

the class TemplateValidator method validateTemplateRequest.

public void validateTemplateRequest(Credential credential, Template value, String region, String availabilityZone, String variant) {
    CloudVmTypes cloudVmTypes = cloudParameterService.getVmTypesV2(credential, region, variant, new HashMap<>());
    if (StringUtils.isEmpty(value.getInstanceType())) {
        validateCustomInstanceType(value);
    } else {
        VmType vmType = null;
        VolumeParameterType volumeParameterType = null;
        Platform platform = Platform.platform(value.cloudPlatform());
        Map<String, Set<VmType>> machines = cloudVmTypes.getCloudVmResponses();
        String locationString = locationService.location(region, availabilityZone);
        if (machines.containsKey(locationString) && !machines.get(locationString).isEmpty()) {
            for (VmType type : machines.get(locationString)) {
                if (type.value().equals(value.getInstanceType())) {
                    vmType = type;
                    break;
                }
            }
            if (vmType == null) {
                throw new BadRequestException(String.format("The '%s' instance type isn't supported by '%s' platform", value.getInstanceType(), platform.value()));
            }
        }
        Map<Platform, Map<String, VolumeParameterType>> disks = diskMappings.get();
        if (disks.containsKey(platform) && !disks.get(platform).isEmpty()) {
            Map<String, VolumeParameterType> map = disks.get(platform);
            volumeParameterType = map.get(value.getVolumeType());
            if (volumeParameterType == null) {
                throw new BadRequestException(String.format("The '%s' volume type isn't supported by '%s' platform", value.getVolumeType(), platform.value()));
            }
        }
        validateVolume(value, vmType, platform, volumeParameterType);
    }
}
Also used : CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) Set(java.util.Set) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with VolumeParameterType

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

the class TemplateDecorator method decorate.

public Template decorate(Credential credential, Template subject, String region, String availabilityZone, String variant) {
    PlatformDisks platformDisks = cloudParameterService.getDiskTypes();
    CloudVmTypes vmTypesV2 = cloudParameterService.getVmTypesV2(credential, region, variant, new HashMap<>());
    String locationString = locationService.location(region, availabilityZone);
    VolumeParameterConfig config;
    try {
        Platform platform = Platform.platform(subject.cloudPlatform());
        VmType vmType = vmTypesV2.getCloudVmResponses().getOrDefault(locationString, Collections.emptySet()).stream().filter(curr -> curr.value().equals(subject.getInstanceType())).findFirst().get();
        Map<String, VolumeParameterType> map = platformDisks.getDiskMappings().get(platform);
        VolumeParameterType volumeParameterType = map.get(subject.getVolumeType());
        config = vmType.getVolumeParameterbyVolumeParameterType(volumeParameterType);
    } catch (NoSuchElementException ignored) {
        LOGGER.info("No VolumeParameterConfig found, which might be normal for platforms like OpenStack");
        config = VolumeParameterConfig.EMPTY;
    }
    if (config.volumeParameterType() != null) {
        if (subject.getVolumeCount() == null) {
            subject.setVolumeCount(config.maximumNumber());
        }
        if (subject.getVolumeSize() == null) {
            subject.setVolumeSize(config.maximumSize());
        }
    }
    return subject;
}
Also used : CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) PlatformDisks(com.sequenceiq.cloudbreak.cloud.model.PlatformDisks) VolumeParameterConfig(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig) NoSuchElementException(java.util.NoSuchElementException)

Example 5 with VolumeParameterType

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

the class OpenStackPlatformResources method collectVmTypes.

private Set<VmType> collectVmTypes(OSClient<?> osClient) {
    Set<VmType> types = new HashSet<>();
    for (Flavor flavor : openStackClient.getFlavors(osClient)) {
        VmTypeMetaBuilder builder = VmTypeMetaBuilder.builder().withCpuAndMemory(flavor.getVcpus(), flavor.getRam());
        for (VolumeParameterType volumeParameterType : values()) {
            switch(volumeParameterType) {
                case MAGNETIC:
                    builder.withMagneticConfig(volumeParameterConfig(MAGNETIC));
                    break;
                case SSD:
                    builder.withSsdConfig(null);
                    break;
                case EPHEMERAL:
                    builder.withEphemeralConfig(null);
                    break;
                case ST1:
                    builder.withSt1Config(null);
                    break;
                case AUTO_ATTACHED:
                    builder.withAutoAttachedConfig(null);
                    break;
                default:
                    break;
            }
        }
        VmType vmType = VmType.vmTypeWithMeta(flavor.getName(), builder.create(), true);
        types.add(vmType);
    }
    LOGGER.info("openstack collect vm types result: {}", types);
    return types;
}
Also used : VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) VmTypeMetaBuilder(com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder) VolumeParameterType(com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType) Flavor(org.openstack4j.model.compute.Flavor) HashSet(java.util.HashSet)

Aggregations

VolumeParameterType (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType)5 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)4 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)2 VmTypeMetaBuilder (com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta.VmTypeMetaBuilder)2 Map (java.util.Map)2 VirtualMachineSize (com.microsoft.azure.management.compute.VirtualMachineSize)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 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)1 DiskType (com.sequenceiq.cloudbreak.cloud.model.DiskType)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 VolumeParameterConfig (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1