Search in sources :

Example 1 with ApiClusterTemplateHostTemplate

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;
}
Also used : Collectors.toSet(java.util.stream.Collectors.toSet) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ServiceComponent(com.sequenceiq.cloudbreak.template.model.ServiceComponent) ApiClusterTemplateHostTemplate(com.cloudera.api.swagger.model.ApiClusterTemplateHostTemplate)

Example 2 with ApiClusterTemplateHostTemplate

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;
}
Also used : InstanceCount(com.sequenceiq.cloudbreak.cloud.model.InstanceCount) TreeMap(java.util.TreeMap) ApiClusterTemplateHostTemplate(com.cloudera.api.swagger.model.ApiClusterTemplateHostTemplate)

Example 3 with ApiClusterTemplateHostTemplate

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;
}
Also used : HashMap(java.util.HashMap) ServiceComponent(com.sequenceiq.cloudbreak.template.model.ServiceComponent) ApiClusterTemplateConfig(com.cloudera.api.swagger.model.ApiClusterTemplateConfig) ArrayList(java.util.ArrayList) List(java.util.List) HostgroupView(com.sequenceiq.cloudbreak.template.views.HostgroupView) HashMap(java.util.HashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) ApiClusterTemplateHostTemplate(com.cloudera.api.swagger.model.ApiClusterTemplateHostTemplate) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with ApiClusterTemplateHostTemplate

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;
}
Also used : ApiClusterTemplate(com.cloudera.api.swagger.model.ApiClusterTemplate) InstanceMetadataType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) ApiClusterTemplateHostTemplate(com.cloudera.api.swagger.model.ApiClusterTemplateHostTemplate) Collectors(java.util.stream.Collectors) InstanceMetaDataV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.instancemetadata.InstanceMetaDataV4Response) List(java.util.List) Service(org.springframework.stereotype.Service) Map(java.util.Map) ApiClusterTemplateRoleConfigGroup(com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup) Optional(java.util.Optional) ApiClusterTemplateService(com.cloudera.api.swagger.model.ApiClusterTemplateService) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) ApiClusterTemplateRoleConfigGroup(com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup) ApiClusterTemplate(com.cloudera.api.swagger.model.ApiClusterTemplate)

Example 5 with ApiClusterTemplateHostTemplate

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());
                }
            }
        }
    }
}
Also used : Logger(org.slf4j.Logger) Optional.ofNullable(java.util.Optional.ofNullable) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ApiClusterTemplateHostTemplate(com.cloudera.api.swagger.model.ApiClusterTemplateHostTemplate) Function(java.util.function.Function) TemplatePreparationObject(com.sequenceiq.cloudbreak.template.TemplatePreparationObject) ArrayList(java.util.ArrayList) Objects(java.util.Objects) Inject(javax.inject.Inject) ServiceComponent(com.sequenceiq.cloudbreak.template.model.ServiceComponent) HostgroupView(com.sequenceiq.cloudbreak.template.views.HostgroupView) List(java.util.List) Component(org.springframework.stereotype.Component) Collectors.toMap(java.util.stream.Collectors.toMap) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) ApiClusterTemplateRoleConfigGroup(com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup) ApiClusterTemplateConfig(com.cloudera.api.swagger.model.ApiClusterTemplateConfig) ApiClusterTemplateInstantiator(com.cloudera.api.swagger.model.ApiClusterTemplateInstantiator) Optional(java.util.Optional) ApiClusterTemplateService(com.cloudera.api.swagger.model.ApiClusterTemplateService) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ApiClusterTemplateRoleConfigGroupInfo(com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroupInfo) ApiClusterTemplateRoleConfigGroup(com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup) ApiClusterTemplateConfig(com.cloudera.api.swagger.model.ApiClusterTemplateConfig) ApiClusterTemplateService(com.cloudera.api.swagger.model.ApiClusterTemplateService) ApiClusterTemplateInstantiator(com.cloudera.api.swagger.model.ApiClusterTemplateInstantiator) ArrayList(java.util.ArrayList) List(java.util.List) ApiClusterTemplateRoleConfigGroupInfo(com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroupInfo) HashMap(java.util.HashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) ApiClusterTemplateHostTemplate(com.cloudera.api.swagger.model.ApiClusterTemplateHostTemplate) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

ApiClusterTemplateHostTemplate (com.cloudera.api.swagger.model.ApiClusterTemplateHostTemplate)6 ServiceComponent (com.sequenceiq.cloudbreak.template.model.ServiceComponent)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 ApiClusterTemplateConfig (com.cloudera.api.swagger.model.ApiClusterTemplateConfig)2 ApiClusterTemplateRoleConfigGroup (com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup)2 ApiClusterTemplateService (com.cloudera.api.swagger.model.ApiClusterTemplateService)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 HostgroupView (com.sequenceiq.cloudbreak.template.views.HostgroupView)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors.toMap (java.util.stream.Collectors.toMap)2 ApiClusterTemplate (com.cloudera.api.swagger.model.ApiClusterTemplate)1 ApiClusterTemplateInstantiator (com.cloudera.api.swagger.model.ApiClusterTemplateInstantiator)1 ApiClusterTemplateRoleConfigGroupInfo (com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroupInfo)1 InstanceMetadataType (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType)1 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)1 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)1