Search in sources :

Example 1 with AutoscaleRecommendation

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

the class CloudResourceAdvisor method getPlatformRecommendationByCredential.

private PlatformRecommendation getPlatformRecommendationByCredential(Long workspaceId, String blueprintName, String region, String platformVariant, String availabilityZone, CdpResourceType cdpResourceType, Credential credential) {
    String cloudPlatform = credential.cloudPlatform();
    Map<String, VmType> vmTypesByHostGroup = new HashMap<>();
    Map<String, Boolean> hostGroupContainsMasterComp = new HashMap<>();
    LOGGER.debug("Advising resources for blueprintName: {}, provider: {} and region: {}.", blueprintName, cloudPlatform, region);
    List<String> entitlements = entitlementService.getEntitlements(credential.getAccount());
    BlueprintTextProcessor blueprintTextProcessor = getBlueprintTextProcessor(workspaceId, blueprintName);
    Map<String, Set<String>> componentsByHostGroup = blueprintTextProcessor.getComponentsByHostGroup();
    componentsByHostGroup.forEach((hGName, components) -> hostGroupContainsMasterComp.put(hGName, isThereMasterComponents(blueprintTextProcessor.getClusterManagerType(), hGName, components)));
    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));
    CloudVmTypes vmTypes = cloudParameterService.getVmTypesV2(extendedCloudCredentialConverter.convert(credential), region, platformVariant, cdpResourceType, Maps.newHashMap());
    VmType defaultVmType = getDefaultVmType(availabilityZone, vmTypes);
    if (defaultVmType != null) {
        componentsByHostGroup.keySet().forEach(comp -> vmTypesByHostGroup.put(comp, defaultVmType));
    }
    VmRecommendations recommendations = cloudParameterService.getRecommendation(cloudPlatform);
    Set<VmType> availableVmTypes = null;
    if (StringUtils.isNotBlank(availabilityZone)) {
        availableVmTypes = vmTypes.getCloudVmResponses().get(availabilityZone);
    } else if (vmTypes.getCloudVmResponses() != null && !vmTypes.getCloudVmResponses().isEmpty()) {
        availableVmTypes = vmTypes.getCloudVmResponses().values().iterator().next();
    }
    if (availableVmTypes == null) {
        availableVmTypes = Collections.emptySet();
    }
    if (recommendations != null) {
        Map<String, VmType> masterVmTypes = getVmTypesForComponentType(true, recommendations.getMaster(), hostGroupContainsMasterComp, availableVmTypes, cloudPlatform, diskTypes, recommendations.getMaster());
        vmTypesByHostGroup.putAll(masterVmTypes);
        Map<String, VmType> workerVmTypes = getVmTypesForComponentType(false, recommendations.getWorker(), hostGroupContainsMasterComp, availableVmTypes, cloudPlatform, diskTypes, recommendations.getWorker(), recommendations.getBroker(), recommendations.getQuorum());
        vmTypesByHostGroup.putAll(workerVmTypes);
    } else {
        componentsByHostGroup.keySet().forEach(hg -> vmTypesByHostGroup.put(hg, null));
    }
    Map<String, InstanceCount> instanceCounts = recommendInstanceCounts(blueprintTextProcessor);
    GatewayRecommendation gateway = recommendGateway(blueprintTextProcessor);
    AutoscaleRecommendation autoscale = recommendAutoscale(blueprintTextProcessor);
    ResizeRecommendation resize = recommendResize(blueprintTextProcessor, entitlements);
    return new PlatformRecommendation(vmTypesByHostGroup, availableVmTypes, diskTypes, instanceCounts, gateway, autoscale, resize);
}
Also used : AutoscaleRecommendation(com.sequenceiq.cloudbreak.cloud.model.AutoscaleRecommendation) ResizeRecommendation(com.sequenceiq.cloudbreak.cloud.model.ResizeRecommendation) Set(java.util.Set) Platform(com.sequenceiq.cloudbreak.cloud.model.Platform) HashMap(java.util.HashMap) PlatformDisks(com.sequenceiq.cloudbreak.cloud.model.PlatformDisks) InstanceCount(com.sequenceiq.cloudbreak.cloud.model.InstanceCount) CloudVmTypes(com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes) VmRecommendations(com.sequenceiq.cloudbreak.cloud.model.VmRecommendations) GatewayRecommendation(com.sequenceiq.cloudbreak.cloud.model.GatewayRecommendation) BlueprintTextProcessor(com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor) DiskTypes(com.sequenceiq.cloudbreak.cloud.model.DiskTypes) VmType(com.sequenceiq.cloudbreak.cloud.model.VmType) PlatformRecommendation(com.sequenceiq.cloudbreak.cloud.model.PlatformRecommendation)

Example 2 with AutoscaleRecommendation

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

the class CloudResourceAdvisor method recommendAutoscale.

private AutoscaleRecommendation recommendAutoscale(BlueprintTextProcessor blueprintTextProcessor) {
    String version = blueprintTextProcessor.getVersion().orElse("");
    Versioned blueprintVersion = () -> blueprintTextProcessor.getVersion().get();
    if (!isVersionNewerOrEqualThanLimited(version, CLOUDERAMANAGER_VERSION_7_2_1)) {
        LOGGER.debug("Autoscale is not supported in this version {}.", version);
        return new AutoscaleRecommendation(Set.of(), Set.of());
    }
    AutoscaleRecommendation autoscaleRecommendation = blueprintTextProcessor.recommendAutoscale(blueprintVersion);
    if (autoscaleRecommendation.getTimeBasedHostGroups().isEmpty()) {
        Set<String> autoscaleGroups = filterHostGroupByPredicate(blueprintTextProcessor, this::fallbackTimeBasedAutoscaleFilter);
        if (!autoscaleGroups.isEmpty()) {
            autoscaleRecommendation.setTimeBasedHostGroups(autoscaleGroups);
        }
    }
    if (autoscaleRecommendation.getLoadBasedHostGroups().isEmpty()) {
        Set<String> autoscaleGroups = filterHostGroupByPredicate(blueprintTextProcessor, this::fallbackLoadBasedAutoscaleFilter);
        if (!autoscaleGroups.isEmpty()) {
            autoscaleRecommendation.setLoadBasedHostGroups(autoscaleGroups);
        }
    }
    return autoscaleRecommendation;
}
Also used : AutoscaleRecommendation(com.sequenceiq.cloudbreak.cloud.model.AutoscaleRecommendation) Versioned(com.sequenceiq.cloudbreak.common.type.Versioned)

Example 3 with AutoscaleRecommendation

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

the class AutoscaleV4Controller method getRecommendation.

@Override
@InternalOnly
public AutoscaleRecommendationV4Response getRecommendation(@TenantAwareParam String crn) {
    Stack stack = stackService.getByCrn(crn);
    String blueprintName = stack.getCluster().getBlueprint().getName();
    Long workspaceId = stack.getWorkspace().getId();
    AutoscaleRecommendation autoscaleRecommendation = blueprintService.getAutoscaleRecommendation(workspaceId, blueprintName);
    return autoscaleRecommendationToAutoscaleRecommendationV4ResponseConverter.convert(autoscaleRecommendation);
}
Also used : AutoscaleRecommendation(com.sequenceiq.cloudbreak.cloud.model.AutoscaleRecommendation) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InternalOnly(com.sequenceiq.authorization.annotation.InternalOnly)

Example 4 with AutoscaleRecommendation

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

the class CloudResourceAdvisorTest method testRecommendAutoscaleWhenCloudManagerVersionGreaterThanEqualTo721.

@Test
public void testRecommendAutoscaleWhenCloudManagerVersionGreaterThanEqualTo721() {
    when(blueprintTextProcessor.getVersion()).thenReturn(Optional.of(VERSION_7_2_1));
    Blueprint blueprint = new Blueprint();
    blueprint.setBlueprintText("{\"Blueprints\":{123:2}}");
    when(blueprintTextProcessorFactory.createBlueprintTextProcessor("{\"Blueprints\":{123:2}}")).thenReturn(blueprintTextProcessor);
    when(blueprintTextProcessor.recommendAutoscale(any())).thenReturn(new AutoscaleRecommendation(Set.of("compute"), Set.of("compute")));
    when(blueprintService.getByNameForWorkspaceId(any(), anyLong())).thenReturn(blueprint);
    assertEquals(new AutoscaleRecommendation(Set.of("compute"), Set.of("compute")), underTest.getAutoscaleRecommendation(workspace.getId(), TEST_BLUEPRINT_NAME));
}
Also used : AutoscaleRecommendation(com.sequenceiq.cloudbreak.cloud.model.AutoscaleRecommendation) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Test(org.junit.Test)

Example 5 with AutoscaleRecommendation

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

the class CloudResourceAdvisorTest method testReturnScaleRecommendationForBlueprintWhenCloudManagerVersionGreaterThanEqualTo721.

@Test
public void testReturnScaleRecommendationForBlueprintWhenCloudManagerVersionGreaterThanEqualTo721() {
    when(blueprintTextProcessor.getVersion()).thenReturn(java.util.Optional.of(VERSION_7_2_1));
    when(entitlementService.getEntitlements(anyString())).thenReturn(Collections.emptyList());
    Blueprint blueprint = createBlueprint();
    when(blueprintTextProcessorFactory.createBlueprintTextProcessor("{\"Blueprints\":{123:2}}")).thenReturn(blueprintTextProcessor);
    when(blueprintTextProcessor.recommendAutoscale(any())).thenReturn(new AutoscaleRecommendation(Set.of("compute"), Set.of("compute")));
    when(blueprintTextProcessor.recommendResize(anyList(), any())).thenReturn(new ResizeRecommendation(Set.of("compute"), Set.of("compute")));
    ScaleRecommendation scaleRecommendation = underTest.createForBlueprint(this.workspace.getId(), blueprint);
    assertEquals(new AutoscaleRecommendation(Set.of("compute"), Set.of("compute")), scaleRecommendation.getAutoscaleRecommendation());
    assertEquals(new ResizeRecommendation(Set.of("compute"), Set.of("compute")), scaleRecommendation.getResizeRecommendation());
}
Also used : AutoscaleRecommendation(com.sequenceiq.cloudbreak.cloud.model.AutoscaleRecommendation) ResizeRecommendation(com.sequenceiq.cloudbreak.cloud.model.ResizeRecommendation) ScaleRecommendation(com.sequenceiq.cloudbreak.cloud.model.ScaleRecommendation) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Test(org.junit.Test)

Aggregations

AutoscaleRecommendation (com.sequenceiq.cloudbreak.cloud.model.AutoscaleRecommendation)9 ResizeRecommendation (com.sequenceiq.cloudbreak.cloud.model.ResizeRecommendation)4 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)4 Test (org.junit.Test)4 ScaleRecommendation (com.sequenceiq.cloudbreak.cloud.model.ScaleRecommendation)3 Versioned (com.sequenceiq.cloudbreak.common.type.Versioned)2 BlueprintTextProcessor (com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor)2 InternalOnly (com.sequenceiq.authorization.annotation.InternalOnly)1 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)1 DiskTypes (com.sequenceiq.cloudbreak.cloud.model.DiskTypes)1 GatewayRecommendation (com.sequenceiq.cloudbreak.cloud.model.GatewayRecommendation)1 InstanceCount (com.sequenceiq.cloudbreak.cloud.model.InstanceCount)1 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)1 PlatformDisks (com.sequenceiq.cloudbreak.cloud.model.PlatformDisks)1 PlatformRecommendation (com.sequenceiq.cloudbreak.cloud.model.PlatformRecommendation)1 VmRecommendations (com.sequenceiq.cloudbreak.cloud.model.VmRecommendations)1 VmType (com.sequenceiq.cloudbreak.cloud.model.VmType)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1