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);
}
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);
}
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);
}
}
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;
}
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;
}
Aggregations