Search in sources :

Example 6 with PlatformDisks

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

Example 7 with PlatformDisks

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

PlatformDisks (com.sequenceiq.cloudbreak.cloud.model.PlatformDisks)7 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)6 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)4 Map (java.util.Map)4 VolumeParameterConfig (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig)3 Set (java.util.Set)3 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 DiskTypes (com.sequenceiq.cloudbreak.cloud.model.DiskTypes)2 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)2 VmTypeMeta (com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta)2 Credential (com.sequenceiq.cloudbreak.domain.Credential)2 Template (com.sequenceiq.cloudbreak.domain.Template)2 Collections.emptyMap (java.util.Collections.emptyMap)2 Collections.emptySet (java.util.Collections.emptySet)2 Collections.singletonMap (java.util.Collections.singletonMap)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 Matchers.anyMap (org.mockito.Matchers.anyMap)2 PlatformDisksJson (com.sequenceiq.cloudbreak.api.model.PlatformDisksJson)1 PlatformOrchestratorsJson (com.sequenceiq.cloudbreak.api.model.PlatformOrchestratorsJson)1