use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class InstanceGroupV4RequestToHostGroupConverter method convert.
public HostGroup convert(InstanceGroupV4Request source) {
HostGroup hostGroup = new HostGroup();
hostGroup.setName(source.getName().toLowerCase());
hostGroup.setRecoveryMode(source.getRecoveryMode());
Set<String> recipeNames = source.getRecipeNames();
if (!CollectionUtils.isEmpty(recipeNames)) {
CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
User user = userService.getOrCreate(cloudbreakUser);
Workspace workspace = workspaceService.get(restRequestThreadLocalService.getRequestedWorkspaceId(), user);
hostGroup.setRecipes(recipeService.getRecipesByNamesForWorkspace(workspace, recipeNames));
}
return hostGroup;
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class ClusterHostServiceRunner method collectUpscaleCandidates.
private Map<String, String> collectUpscaleCandidates(Long clusterId, Map<String, Integer> hostGroupWithAdjustment) {
Map<String, String> hostNames = new HashMap<>();
for (Map.Entry<String, Integer> entry : hostGroupWithAdjustment.entrySet()) {
String hostGroupName = entry.getKey();
Integer adjustment = entry.getValue();
HostGroup hostGroup = hostGroupService.findHostGroupInClusterByName(clusterId, hostGroupName).orElseThrow(NotFoundException.notFound("hostgroup", hostGroupName));
if (hostGroup.getInstanceGroup() != null) {
Long instanceGroupId = hostGroup.getInstanceGroup().getId();
instanceMetaDataService.findUnusedHostsInInstanceGroup(instanceGroupId).stream().filter(instanceMetaData -> instanceMetaData.getDiscoveryFQDN() != null).sorted(Comparator.comparing(InstanceMetaData::getStartDate)).limit(adjustment.longValue()).forEach(im -> hostNames.put(im.getDiscoveryFQDN(), im.getPrivateIp()));
}
}
return hostNames;
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class ClusterBuilderService method loadInstanceMetadataForHostGroups.
private Map<HostGroup, List<InstanceMetaData>> loadInstanceMetadataForHostGroups(Iterable<HostGroup> hostGroups) {
Map<HostGroup, List<InstanceMetaData>> instanceMetaDataByHostGroup = new HashMap<>();
for (HostGroup hostGroup : hostGroups) {
Long instanceGroupId = hostGroup.getInstanceGroup().getId();
List<InstanceMetaData> metas = instanceMetaDataService.findAliveInstancesInInstanceGroup(instanceGroupId);
instanceMetaDataByHostGroup.put(hostGroup, metas);
}
return instanceMetaDataByHostGroup;
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class ClusterBuilderService method prepareExtendedTemplate.
public void prepareExtendedTemplate(Long stackId) {
Stack stack = stackService.getByIdWithListsInTransaction(stackId);
Cluster cluster = stack.getCluster();
Set<HostGroup> hostGroups = hostGroupService.getByClusterWithRecipes(cluster.getId());
setInitialBlueprintText(cluster);
String template = getClusterSetupService(stack).prepareTemplate(loadInstanceMetadataForHostGroups(hostGroups), stackToTemplatePreparationObjectConverter.convert(stack), getSdxContextOptional(stack.getDatalakeCrn()).orElse(null), stack.getDatalakeCrn(), kerberosConfigService.get(stack.getEnvironmentCrn(), stack.getName()).orElse(null));
validateExtendedBlueprintTextDoesNotContainUnresolvedHandlebarParams(template);
cluster.setExtendedBlueprintText(template);
clusterService.save(cluster);
}
use of com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup in project cloudbreak by hortonworks.
the class CollectDownscaleCandidatesHandler method collectCandidates.
private Set<Long> collectCandidates(CollectDownscaleCandidatesRequest request, Stack stack) throws CloudbreakException {
Set<Long> privateIds = new HashSet<>();
LOGGER.debug("Collecting candidates for downscale based on [{}] and stack CRN [{}].", request, stack.getResourceCrn());
for (Map.Entry<String, Integer> entry : request.getHostGroupWithAdjustment().entrySet()) {
String hostGroupName = entry.getKey();
HostGroup hostGroup = hostGroupService.getByClusterIdAndName(stack.getCluster().getId(), hostGroupName).orElseThrow(NotFoundException.notFound("hostgroup", hostGroupName));
LOGGER.debug("Host group has been found for cluster! It's name: {}", hostGroup.getName());
List<InstanceMetaData> metaDataForInstanceGroup = instanceMetaDataService.findAliveInstancesInInstanceGroup(hostGroup.getInstanceGroup().getId());
Set<InstanceMetaData> collectedCandidates = clusterApiConnectors.getConnector(stack).clusterDecomissionService().collectDownscaleCandidates(hostGroup, entry.getValue(), new HashSet<>(metaDataForInstanceGroup));
String collectedHostsAsString = collectedCandidates.stream().map(instanceMetaData -> instanceMetaData.getDiscoveryFQDN() != null ? "FQDN: " + instanceMetaData.getDiscoveryFQDN() : "Private id: " + instanceMetaData.getPrivateId()).collect(Collectors.joining(", "));
LOGGER.debug("The following hosts has been collected as candidates for downscale: [{}]", collectedHostsAsString);
flowMessageService.fireEventAndLog(stack.getId(), AVAILABLE.name(), STACK_SELECT_FOR_DOWNSCALE, collectedHostsAsString);
privateIds.addAll(collectedCandidates.stream().map(InstanceMetaData::getPrivateId).collect(Collectors.toSet()));
}
return privateIds;
}
Aggregations