use of com.cloudera.api.swagger.model.ApiClusterTemplateHostTemplate in project cloudbreak by hortonworks.
the class CmTemplateProcessor method collectServiceComponentsByHostGroup.
private Map<String, Set<ServiceComponent>> collectServiceComponentsByHostGroup(Map<String, ServiceComponent> rolesByRoleRef) {
Map<String, Set<ServiceComponent>> result = new HashMap<>();
List<ApiClusterTemplateHostTemplate> hostTemplates = Optional.ofNullable(cmTemplate.getHostTemplates()).orElse(List.of());
for (ApiClusterTemplateHostTemplate apiClusterTemplateHostTemplate : hostTemplates) {
Set<ServiceComponent> components = apiClusterTemplateHostTemplate.getRoleConfigGroupsRefNames().stream().map(rolesByRoleRef::get).filter(Objects::nonNull).collect(toSet());
result.put(apiClusterTemplateHostTemplate.getRefName(), components);
}
return result;
}
use of com.cloudera.api.swagger.model.ApiClusterTemplateHostTemplate in project cloudbreak by hortonworks.
the class CmTemplateProcessor method getCardinalityByHostGroup.
@Override
public Map<String, InstanceCount> getCardinalityByHostGroup() {
Map<String, InstanceCount> result = new TreeMap<>();
for (ApiClusterTemplateHostTemplate group : Optional.ofNullable(cmTemplate.getHostTemplates()).orElse(List.of())) {
InstanceCount recommendedCount = recommendInstanceCount(group.getRefName(), group.getCardinality()).orElse(InstanceCount.fallbackInstanceCountRecommendation(group.getRefName()));
result.put(group.getRefName(), recommendedCount);
}
return result;
}
use of com.cloudera.api.swagger.model.ApiClusterTemplateHostTemplate in project cloudbreak by hortonworks.
the class CmHostGroupRoleConfigProviderProcessor method generateConfigs.
@VisibleForTesting
Map<String, Map<String, List<ApiClusterTemplateConfig>>> generateConfigs(CmTemplateProcessor templateProcessor, TemplatePreparationObject source) {
Map<String, Map<String, List<ApiClusterTemplateConfig>>> configsByRoleConfigGroup = new HashMap<>();
Map<String, HostgroupView> hostGroups = source.getHostgroupViews().stream().collect(toMap(HostgroupView::getName, Function.identity()));
List<ApiClusterTemplateHostTemplate> hostTemplates = getHostTemplates(templateProcessor);
Map<String, ServiceComponent> serviceComponents = templateProcessor.mapRoleRefsToServiceComponents();
for (ApiClusterTemplateHostTemplate hostTemplate : hostTemplates) {
String hostGroupName = hostTemplate.getRefName();
List<String> roleConfigGroups = ofNullable(hostTemplate.getRoleConfigGroupsRefNames()).orElseGet(List::of);
HostgroupView hostgroupView = hostGroups.get(hostGroupName);
groupByHostGroupName(source, configsByRoleConfigGroup, serviceComponents, hostGroupName, roleConfigGroups, hostgroupView);
}
return configsByRoleConfigGroup;
}
use of com.cloudera.api.swagger.model.ApiClusterTemplateHostTemplate in project cloudbreak by hortonworks.
the class StackResponseUtils method getRoleConfigNameForHostGroup.
public String getRoleConfigNameForHostGroup(StackV4Response stackResponse, String hostGroupName, String serviceType, String roleType) throws Exception {
String template = stackResponse.getCluster().getBlueprint().getBlueprint();
ApiClusterTemplate cmTemplate = JsonUtil.readValue(template, ApiClusterTemplate.class);
Set<String> hostGroupRoleConfigNames = cmTemplate.getHostTemplates().stream().filter(clusterTemplate -> clusterTemplate.getRefName().equalsIgnoreCase(hostGroupName)).findFirst().map(ApiClusterTemplateHostTemplate::getRoleConfigGroupsRefNames).orElse(List.of()).stream().collect(Collectors.toSet());
String roleReferenceName = cmTemplate.getServices().stream().filter(s -> s.getServiceType().equalsIgnoreCase(serviceType)).findFirst().map(ApiClusterTemplateService::getRoleConfigGroups).orElse(List.of()).stream().filter(rcg -> rcg.getRoleType().equalsIgnoreCase(roleType)).filter(rcg -> hostGroupRoleConfigNames.contains(rcg.getRefName())).map(ApiClusterTemplateRoleConfigGroup::getRefName).findFirst().orElseThrow(() -> new Exception(String.format("Unable to retrieve RoleConfigGroupRefName for Service '%s', RoleType '%s'," + " HostGroup '%s', Cluster '%s'", serviceType, roleType, hostGroupName, stackResponse.getCrn())));
return roleReferenceName;
}
use of com.cloudera.api.swagger.model.ApiClusterTemplateHostTemplate in project cloudbreak by hortonworks.
the class CmHostGroupRoleConfigProviderProcessor method updateConfigsInTemplate.
private void updateConfigsInTemplate(CmTemplateProcessor templateProcessor, Map<String, Map<String, List<ApiClusterTemplateConfig>>> newConfigsByRCG) {
List<ApiClusterTemplateHostTemplate> hostTemplates = getHostTemplates(templateProcessor);
Map<String, ApiClusterTemplateService> serviceByRCG = templateProcessor.getTemplate().getServices().stream().flatMap(service -> ofNullable(service.getRoleConfigGroups()).orElseGet(List::of).stream().map(rcg -> Pair.of(rcg, service))).collect(toMap(pair -> pair.getLeft().getRefName(), Pair::getRight));
Map<String, ApiClusterTemplateRoleConfigGroup> roleConfigGroupByName = templateProcessor.getTemplate().getServices().stream().flatMap(service -> ofNullable(service.getRoleConfigGroups()).orElseGet(List::of).stream()).collect(toMap(ApiClusterTemplateRoleConfigGroup::getRefName, Function.identity()));
ApiClusterTemplateInstantiator instantiator = templateProcessor.getTemplate().getInstantiator();
List<ApiClusterTemplateRoleConfigGroupInfo> instantiatorRoleConfigGroups = instantiator.getRoleConfigGroups();
for (Map.Entry<String, Map<String, List<ApiClusterTemplateConfig>>> entry : newConfigsByRCG.entrySet()) {
String configGroupName = entry.getKey();
ApiClusterTemplateRoleConfigGroup configGroup = roleConfigGroupByName.get(configGroupName);
ApiClusterTemplateService templateService = serviceByRCG.get(configGroupName);
Map<String, List<ApiClusterTemplateConfig>> configsByHostGroup = entry.getValue();
int groupCount = configsByHostGroup.size();
Optional<CmHostGroupRoleConfigProvider> provider = providers.stream().filter(it -> it.getServiceType().equals(templateService.getServiceType())).findFirst();
boolean sharedRoleType = true;
if (provider.isPresent()) {
sharedRoleType = provider.get().sharedRoleType(configGroup.getRoleType());
}
if (groupCount == 1 || sharedRoleType) {
templateProcessor.mergeRoleConfigs(configGroup, configsByHostGroup.values().iterator().next());
} else if (groupCount > 1) {
LOGGER.debug("Cloning config group {} into {} host groups: {}", configGroupName, groupCount, configsByHostGroup.keySet());
// "clone" config group for each host group
Map<String, ApiClusterTemplateRoleConfigGroup> clonesByHostGroup = configsByHostGroup.keySet().stream().map(hostGroupName -> Pair.of(hostGroupName, copyForHostGroup(configGroup, hostGroupName))).collect(toMap(Pair::getKey, Pair::getValue));
// add host group-specific configs to clones
configsByHostGroup.forEach((hostGroupName, newConfigs) -> templateProcessor.mergeRoleConfigs(clonesByHostGroup.get(hostGroupName), newConfigs));
// remove original from service
ApiClusterTemplateService service = serviceByRCG.get(configGroupName);
service.getRoleConfigGroups().removeIf(group -> Objects.equals(group.getRefName(), configGroupName));
// remove original from instantiator
if (instantiatorRoleConfigGroups != null) {
instantiatorRoleConfigGroups.removeIf(groupInfo -> Objects.equals(groupInfo.getRcgRefName(), configGroupName));
}
// add clones to service
service.getRoleConfigGroups().addAll(clonesByHostGroup.values());
// add clones to instantiator
clonesByHostGroup.values().forEach(group -> instantiator.addRoleConfigGroupsItem(new ApiClusterTemplateRoleConfigGroupInfo().rcgRefName(group.getRefName())));
// replace references in host groups
for (ApiClusterTemplateHostTemplate hostTemplate : hostTemplates) {
ApiClusterTemplateRoleConfigGroup rcgForHostGroup = clonesByHostGroup.get(hostTemplate.getRefName());
if (rcgForHostGroup != null) {
hostTemplate.getRoleConfigGroupsRefNames().remove(configGroupName);
hostTemplate.getRoleConfigGroupsRefNames().add(rcgForHostGroup.getRefName());
}
}
}
}
}
Aggregations