Search in sources :

Example 1 with PlatformRecommendation

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

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);
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) PlatformRecommendation(com.sequenceiq.cloudbreak.cloud.model.PlatformRecommendation) PlatformResourceRequest(com.sequenceiq.cloudbreak.domain.PlatformResourceRequest)

Example 3 with PlatformRecommendation

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);
}
Also used : Set(java.util.Set) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) HashMap(java.util.HashMap) PlatformDisks(com.sequenceiq.cloudbreak.cloud.model.PlatformDisks) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) VmRecommendations(com.sequenceiq.cloudbreak.cloud.model.VmRecommendations) DiskTypes(com.sequenceiq.cloudbreak.cloud.model.DiskTypes) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) PlatformRecommendation(com.sequenceiq.cloudbreak.cloud.model.PlatformRecommendation)

Aggregations

PlatformRecommendation (com.sequenceiq.cloudbreak.cloud.model.PlatformRecommendation)3 HashMap (java.util.HashMap)2 Set (java.util.Set)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 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)1 DiskType (com.sequenceiq.cloudbreak.cloud.model.DiskType)1 DiskTypes (com.sequenceiq.cloudbreak.cloud.model.DiskTypes)1 DisplayName (com.sequenceiq.cloudbreak.cloud.model.DisplayName)1 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)1 PlatformDisks (com.sequenceiq.cloudbreak.cloud.model.PlatformDisks)1 VmRecommendations (com.sequenceiq.cloudbreak.cloud.model.VmRecommendations)1 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)1 VolumeParameterType (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterType)1 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)1 PlatformResourceRequest (com.sequenceiq.cloudbreak.domain.PlatformResourceRequest)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1