use of com.sequenceiq.cloudbreak.cloud.model.ResizeRecommendation 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);
}
use of com.sequenceiq.cloudbreak.cloud.model.ResizeRecommendation 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());
}
use of com.sequenceiq.cloudbreak.cloud.model.ResizeRecommendation in project cloudbreak by hortonworks.
the class CloudResourceAdvisorTest method testReturnEmptyScaleRecommendationForBlueprintWhenCloudManagerVersionLessThanEqualTo720.
@Test
public void testReturnEmptyScaleRecommendationForBlueprintWhenCloudManagerVersionLessThanEqualTo720() {
when(blueprintTextProcessor.getVersion()).thenReturn(java.util.Optional.of(VERSION_7_2_0));
when(entitlementService.getEntitlements(anyString())).thenReturn(Collections.emptyList());
Blueprint blueprint = createBlueprint();
when(blueprintTextProcessorFactory.createBlueprintTextProcessor("{\"Blueprints\":{123:2}}")).thenReturn(blueprintTextProcessor);
when(blueprintTextProcessor.recommendResize(anyList(), any())).thenReturn(new ResizeRecommendation(Set.of(), Set.of()));
ScaleRecommendation scaleRecommendation = underTest.createForBlueprint(this.workspace.getId(), blueprint);
assertEquals(new AutoscaleRecommendation(Set.of(), Set.of()), scaleRecommendation.getAutoscaleRecommendation());
assertEquals(new ResizeRecommendation(Set.of(), Set.of()), scaleRecommendation.getResizeRecommendation());
}
use of com.sequenceiq.cloudbreak.cloud.model.ResizeRecommendation in project cloudbreak by hortonworks.
the class CloudResourceAdvisor method createForBlueprint.
public ScaleRecommendation createForBlueprint(Long workspaceId, Blueprint blueprint) {
LOGGER.debug("Scale advice for blueprintName: {}.", blueprint.getName());
BlueprintTextProcessor blueprintTextProcessor = getBlueprintTextProcessor(blueprint);
AutoscaleRecommendation autoscale = recommendAutoscale(blueprintTextProcessor);
List<String> entitlements = entitlementService.getEntitlements(blueprint.getWorkspace().getTenant().getName());
ResizeRecommendation resize = recommendResize(blueprintTextProcessor, entitlements);
return new ScaleRecommendation(autoscale, resize);
}
use of com.sequenceiq.cloudbreak.cloud.model.ResizeRecommendation in project cloudbreak by hortonworks.
the class CloudResourceAdvisor method recommendResize.
private ResizeRecommendation recommendResize(BlueprintTextProcessor blueprintTextProcessor, List<String> entitlements) {
Versioned blueprintVersion = () -> blueprintTextProcessor.getVersion().get();
ResizeRecommendation resizeRecommendation = blueprintTextProcessor.recommendResize(entitlements, blueprintVersion);
if (resizeRecommendation.getScaleUpHostGroups().isEmpty()) {
Set<String> scaleUpHostGroups = filterHostGroupByPredicate(blueprintTextProcessor, this::fallbackScaleUpFilter);
if (!scaleUpHostGroups.isEmpty()) {
resizeRecommendation.setScaleUpHostGroups(scaleUpHostGroups);
}
}
if (resizeRecommendation.getScaleDownHostGroups().isEmpty()) {
Set<String> scaleDownHostGroups = filterHostGroupByPredicate(blueprintTextProcessor, this::fallbackScaleDownFilter);
if (!scaleDownHostGroups.isEmpty()) {
resizeRecommendation.setScaleDownHostGroups(scaleDownHostGroups);
}
}
return resizeRecommendation;
}
Aggregations