use of com.sequenceiq.cloudbreak.cloud.model.PlatformRecommendation 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.PlatformRecommendation in project cloudbreak by hortonworks.
the class PlatformParameterV1Controller method createRecommendation.
@Override
public RecommendationResponse createRecommendation(RecommendationRequestJson recommendationRequestJson) {
IdentityUser cbUser = authenticatedUserService.getCbUser();
PlatformResourceRequest resourceRequest = conversionService.convert(recommendationRequestJson, PlatformResourceRequest.class);
if (recommendationRequestJson.getBlueprintId() == null && Strings.isNullOrEmpty(recommendationRequestJson.getBlueprintName())) {
fieldIsNotEmpty(recommendationRequestJson.getBlueprintId(), "blueprintId");
}
fieldIsNotEmpty(resourceRequest.getRegion(), "region");
fieldIsNotEmpty(resourceRequest.getAvailabilityZone(), "availabilityZone");
PlatformRecommendation recommendedVms = cloudResourceAdvisor.createForBlueprint(recommendationRequestJson.getBlueprintName(), recommendationRequestJson.getBlueprintId(), resourceRequest, cbUser);
return conversionService.convert(recommendedVms, RecommendationResponse.class);
}
use of com.sequenceiq.cloudbreak.cloud.model.PlatformRecommendation in project cloudbreak by hortonworks.
the class CloudResourceAdvisor method createForBlueprint.
public PlatformRecommendation createForBlueprint(String blueprintName, Long blueprintId, PlatformResourceRequest resourceRequest, IdentityUser cbUser) {
String cloudPlatform = resourceRequest.getCloudPlatform();
String region = resourceRequest.getRegion();
String availabilityZone = resourceRequest.getAvailabilityZone();
Map<String, VmType> vmTypesByHostGroup = new HashMap<>();
Map<String, Boolean> hostGroupContainsMasterComp = new HashMap<>();
LOGGER.info("Advising resources for blueprintId: {}, blueprintName: {}, provider: {} and region: {}.", blueprintId, blueprintName, cloudPlatform, region);
String blueprintText = getBlueprint(blueprintName, blueprintId, cbUser).getBlueprintText();
Map<String, Set<String>> componentsByHostGroup = blueprintProcessorFactory.get(blueprintText).getComponentsByHostGroup();
componentsByHostGroup.forEach((hGName, components) -> hostGroupContainsMasterComp.put(hGName, isThereMasterComponents(components)));
CloudVmTypes vmTypes = cloudParameterService.getVmTypesV2(resourceRequest.getCredential(), resourceRequest.getRegion(), resourceRequest.getPlatformVariant(), resourceRequest.getFilters());
VmType defaultVmType = getDefaultVmType(availabilityZone, vmTypes);
if (defaultVmType != null) {
componentsByHostGroup.keySet().forEach(comp -> vmTypesByHostGroup.put(comp, defaultVmType));
}
VmRecommendations recommendations = cloudParameterService.getRecommendation(cloudPlatform);
Set<VmType> availableVmTypes = vmTypes.getCloudVmResponses().get(availabilityZone);
if (availableVmTypes == null) {
availableVmTypes = Collections.emptySet();
}
if (recommendations != null) {
Map<String, VmType> masterVmTypes = getVmTypesForComponentType(true, recommendations.getMaster(), hostGroupContainsMasterComp, availableVmTypes);
vmTypesByHostGroup.putAll(masterVmTypes);
Map<String, VmType> workerVmTypes = getVmTypesForComponentType(false, recommendations.getWorker(), hostGroupContainsMasterComp, availableVmTypes);
vmTypesByHostGroup.putAll(workerVmTypes);
}
PlatformDisks platformDisks = cloudParameterService.getDiskTypes();
Platform platform = platform(cloudPlatform);
DiskTypes diskTypes = new DiskTypes(platformDisks.getDiskTypes().get(platform), platformDisks.getDefaultDisks().get(platform), platformDisks.getDiskMappings().get(platform), platformDisks.getDiskDisplayNames().get(platform));
return new PlatformRecommendation(vmTypesByHostGroup, availableVmTypes, diskTypes);
}
Aggregations