Search in sources :

Example 1 with ApiClusterTemplateInstantiator

use of com.cloudera.api.swagger.model.ApiClusterTemplateInstantiator in project cloudbreak by hortonworks.

the class CmTemplateProcessorTest method testAddInstantiatorWithBaseRoles.

@Test
public void testAddInstantiatorWithBaseRoles() {
    underTest = new CmTemplateProcessor(getBlueprintText("input/clouderamanager.bp"));
    ClouderaManagerRepo clouderaManagerRepoDetails = new ClouderaManagerRepo();
    clouderaManagerRepoDetails.setVersion(CMRepositoryVersionUtil.CLOUDERAMANAGER_VERSION_6_3_0.getVersion());
    GeneralClusterConfigs generalClusterConfigs = new GeneralClusterConfigs();
    generalClusterConfigs.setClusterName("cluster");
    TemplatePreparationObject.Builder tpoBuilder = new TemplatePreparationObject.Builder().withGeneralClusterConfigs(generalClusterConfigs);
    TemplatePreparationObject templatePreparationObject = tpoBuilder.build();
    underTest.addInstantiator(clouderaManagerRepoDetails, templatePreparationObject, "dszabo-sdx");
    ApiClusterTemplateInstantiator instantiator = underTest.getTemplate().getInstantiator();
    List<ApiClusterTemplateRoleConfigGroupInfo> roleConfigGroups = instantiator.getRoleConfigGroups();
    List<String> refNames = roleConfigGroups.stream().map(ApiClusterTemplateRoleConfigGroupInfo::getRcgRefName).collect(Collectors.toList());
    assertEquals(2, refNames.size());
    assertTrue(refNames.containsAll(List.of("yarn-NODEMANAGER-BASE", "hdfs-DATANODE-BASE")));
    assertEquals("cluster", instantiator.getClusterName());
}
Also used : TemplatePreparationObject(com.sequenceiq.cloudbreak.template.TemplatePreparationObject) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) GeneralClusterConfigs(com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs) ApiClusterTemplateInstantiator(com.cloudera.api.swagger.model.ApiClusterTemplateInstantiator) ApiClusterTemplateRoleConfigGroupInfo(com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroupInfo) Test(org.junit.jupiter.api.Test)

Example 2 with ApiClusterTemplateInstantiator

use of com.cloudera.api.swagger.model.ApiClusterTemplateInstantiator in project cloudbreak by hortonworks.

the class CmTemplateProcessorTest method addInstantiatorKeepsCustomClusterName.

@Test
public void addInstantiatorKeepsCustomClusterName() {
    underTest = new CmTemplateProcessor(getBlueprintText("input/clouderamanager-custom_cluster_name.bp"));
    GeneralClusterConfigs generalClusterConfigs = new GeneralClusterConfigs();
    generalClusterConfigs.setClusterName("cluster");
    TemplatePreparationObject templatePreparationObject = new TemplatePreparationObject.Builder().withGeneralClusterConfigs(generalClusterConfigs).build();
    underTest.addInstantiator(null, templatePreparationObject, null);
    ApiClusterTemplateInstantiator instantiator = underTest.getTemplate().getInstantiator();
    assertEquals("kusztom", instantiator.getClusterName());
}
Also used : TemplatePreparationObject(com.sequenceiq.cloudbreak.template.TemplatePreparationObject) GeneralClusterConfigs(com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs) ApiClusterTemplateInstantiator(com.cloudera.api.swagger.model.ApiClusterTemplateInstantiator) Test(org.junit.jupiter.api.Test)

Example 3 with ApiClusterTemplateInstantiator

use of com.cloudera.api.swagger.model.ApiClusterTemplateInstantiator in project cloudbreak by hortonworks.

the class CmTemplateProcessor method addInstantiator.

public void addInstantiator(ClouderaManagerRepo clouderaManagerRepoDetails, TemplatePreparationObject templatePreparationObject, String sdxContextName) {
    ApiClusterTemplateInstantiator instantiator = ofNullable(cmTemplate.getInstantiator()).orElseGet(ApiClusterTemplateInstantiator::new);
    if (instantiator.getClusterName() == null) {
        instantiator.setClusterName(templatePreparationObject.getGeneralClusterConfigs().getClusterName());
    }
    addCmVersionDependantConfigs(clouderaManagerRepoDetails, templatePreparationObject, instantiator);
    for (ApiClusterTemplateService service : ofNullable(cmTemplate.getServices()).orElse(List.of())) {
        List<String> nonBaseRefs = ofNullable(service.getRoleConfigGroups()).orElse(List.of()).stream().filter(rcg -> rcg.getBase() == null || !rcg.getBase()).map(ApiClusterTemplateRoleConfigGroup::getRefName).collect(Collectors.toList());
        for (String nonBaseRef : nonBaseRefs) {
            instantiator.addRoleConfigGroupsItem(new ApiClusterTemplateRoleConfigGroupInfo().rcgRefName(nonBaseRef));
        }
    }
    ofNullable(sdxContextName).map(name -> List.of(new ApiDataContextRef().name(name))).map(apiDataContextRefs -> new ApiClusterTemplateClusterSpec().dataContextRefs(apiDataContextRefs)).ifPresent(instantiator::clusterSpec);
    cmTemplate.setInstantiator(instantiator);
}
Also used : InstanceCount(com.sequenceiq.cloudbreak.cloud.model.InstanceCount) InstanceCount.atLeast(com.sequenceiq.cloudbreak.cloud.model.InstanceCount.atLeast) LoggerFactory(org.slf4j.LoggerFactory) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) BigDecimal(java.math.BigDecimal) 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) ApiConfigureForKerberosArguments(com.cloudera.api.swagger.model.ApiConfigureForKerberosArguments) ApiClusterTemplateService(com.cloudera.api.swagger.model.ApiClusterTemplateService) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Collectors.toSet(java.util.stream.Collectors.toSet) ApiClusterTemplateRoleConfigGroupInfo(com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroupInfo) ApiClusterTemplate(com.cloudera.api.swagger.model.ApiClusterTemplate) ClusterHostAttributes(com.sequenceiq.cloudbreak.cluster.model.ClusterHostAttributes) Versioned(com.sequenceiq.cloudbreak.common.type.Versioned) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) ApiClusterTemplateHostTemplate(com.cloudera.api.swagger.model.ApiClusterTemplateHostTemplate) BlueprintTextProcessor(com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor) Collectors(java.util.stream.Collectors) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) Objects(java.util.Objects) ServiceComponent(com.sequenceiq.cloudbreak.template.model.ServiceComponent) List(java.util.List) ApiEntityTag(com.cloudera.api.swagger.model.ApiEntityTag) YarnConstants(com.sequenceiq.cloudbreak.cmtemplate.configproviders.yarn.YarnConstants) ApiClusterTemplateHostInfo(com.cloudera.api.swagger.model.ApiClusterTemplateHostInfo) CollectionUtils(org.springframework.util.CollectionUtils) ApiProductVersion(com.cloudera.api.swagger.model.ApiProductVersion) ResizeRecommendation(com.sequenceiq.cloudbreak.cloud.model.ResizeRecommendation) Entry(java.util.Map.Entry) ApiClusterTemplateConfig(com.cloudera.api.swagger.model.ApiClusterTemplateConfig) Optional(java.util.Optional) ApiClusterTemplateClusterSpec(com.cloudera.api.swagger.model.ApiClusterTemplateClusterSpec) ApiClusterTemplateVariable(com.cloudera.api.swagger.model.ApiClusterTemplateVariable) CMRepositoryVersionUtil.isTagsResourceSupportedViaBlueprint(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.isTagsResourceSupportedViaBlueprint) NotImplementedException(org.apache.commons.lang3.NotImplementedException) ApiDataContextRef(com.cloudera.api.swagger.model.ApiDataContextRef) SiteConfigurations(com.sequenceiq.cloudbreak.template.processor.configuration.SiteConfigurations) HashMap(java.util.HashMap) ServiceAttributes(com.sequenceiq.cloudbreak.template.model.ServiceAttributes) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Enums(com.google.common.base.Enums) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) ClusterManagerType(com.sequenceiq.cloudbreak.common.type.ClusterManagerType) ApiClusterTemplateInstantiator(com.cloudera.api.swagger.model.ApiClusterTemplateInstantiator) CMRepositoryVersionUtil.isVersionNewerOrEqualThanLimited(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil.isVersionNewerOrEqualThanLimited) GatewayRecommendation(com.sequenceiq.cloudbreak.cloud.model.GatewayRecommendation) BlueprintProcessingException(com.sequenceiq.cloudbreak.template.BlueprintProcessingException) Entitlement(com.sequenceiq.cloudbreak.auth.altus.model.Entitlement) YarnRoles(com.sequenceiq.cloudbreak.cmtemplate.configproviders.yarn.YarnRoles) Nonnull(javax.annotation.Nonnull) InstanceCount.exactly(com.sequenceiq.cloudbreak.cloud.model.InstanceCount.exactly) CustomConfigurationPropertyView(com.sequenceiq.cloudbreak.template.views.CustomConfigurationPropertyView) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) AutoscaleRecommendation(com.sequenceiq.cloudbreak.cloud.model.AutoscaleRecommendation) Optional.ofNullable(java.util.Optional.ofNullable) HostgroupConfigurations(com.sequenceiq.cloudbreak.template.processor.configuration.HostgroupConfigurations) IOException(java.io.IOException) TemplatePreparationObject(com.sequenceiq.cloudbreak.template.TemplatePreparationObject) TreeMap(java.util.TreeMap) StackType(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) ApiDataContextRef(com.cloudera.api.swagger.model.ApiDataContextRef) ApiClusterTemplateService(com.cloudera.api.swagger.model.ApiClusterTemplateService) ApiClusterTemplateInstantiator(com.cloudera.api.swagger.model.ApiClusterTemplateInstantiator) ApiClusterTemplateRoleConfigGroupInfo(com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroupInfo) ApiClusterTemplateClusterSpec(com.cloudera.api.swagger.model.ApiClusterTemplateClusterSpec)

Example 4 with ApiClusterTemplateInstantiator

use of com.cloudera.api.swagger.model.ApiClusterTemplateInstantiator 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)

Example 5 with ApiClusterTemplateInstantiator

use of com.cloudera.api.swagger.model.ApiClusterTemplateInstantiator in project cloudbreak by hortonworks.

the class CmTemplateProcessorTest method addHostsTest.

@Test
void addHostsTest() {
    Map<String, List<Map<String, String>>> hostGroupMappings = Map.ofEntries(entry("hostGroup1", List.of()), entry("hostGroup2", List.of(hostAttributes("host2_1", false, null), hostAttributes("host2_2", true, null))), entry("hostGroup3", List.of(hostAttributes("host3_1", true, ""), hostAttributes("host3_2", true, "/rack3_2"))));
    underTest = new CmTemplateProcessor(getBlueprintText("input/clouderamanager.bp"));
    ApiClusterTemplate template = underTest.getTemplate();
    ApiClusterTemplateInstantiator instantiator = new ApiClusterTemplateInstantiator();
    template.setInstantiator(instantiator);
    underTest.addHosts(hostGroupMappings);
    List<ApiClusterTemplateHostInfo> hosts = instantiator.getHosts();
    assertThat(hosts).hasSize(4);
    verifyHostInfo(hosts, "hostGroup2", "host2_1", null);
    verifyHostInfo(hosts, "hostGroup2", "host2_2", null);
    verifyHostInfo(hosts, "hostGroup3", "host3_1", null);
    verifyHostInfo(hosts, "hostGroup3", "host3_2", "/rack3_2");
}
Also used : ApiClusterTemplateHostInfo(com.cloudera.api.swagger.model.ApiClusterTemplateHostInfo) ApiClusterTemplateInstantiator(com.cloudera.api.swagger.model.ApiClusterTemplateInstantiator) ArrayList(java.util.ArrayList) List(java.util.List) ApiClusterTemplate(com.cloudera.api.swagger.model.ApiClusterTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

ApiClusterTemplateInstantiator (com.cloudera.api.swagger.model.ApiClusterTemplateInstantiator)6 TemplatePreparationObject (com.sequenceiq.cloudbreak.template.TemplatePreparationObject)5 ApiClusterTemplateRoleConfigGroupInfo (com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroupInfo)4 Test (org.junit.jupiter.api.Test)4 ClouderaManagerRepo (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo)3 GeneralClusterConfigs (com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs)3 ApiClusterTemplate (com.cloudera.api.swagger.model.ApiClusterTemplate)2 ApiClusterTemplateConfig (com.cloudera.api.swagger.model.ApiClusterTemplateConfig)2 ApiClusterTemplateHostInfo (com.cloudera.api.swagger.model.ApiClusterTemplateHostInfo)2 ApiClusterTemplateHostTemplate (com.cloudera.api.swagger.model.ApiClusterTemplateHostTemplate)2 ApiClusterTemplateRoleConfigGroup (com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup)2 ApiClusterTemplateService (com.cloudera.api.swagger.model.ApiClusterTemplateService)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ApiClusterTemplateClusterSpec (com.cloudera.api.swagger.model.ApiClusterTemplateClusterSpec)1 ApiClusterTemplateVariable (com.cloudera.api.swagger.model.ApiClusterTemplateVariable)1 ApiConfigureForKerberosArguments (com.cloudera.api.swagger.model.ApiConfigureForKerberosArguments)1 ApiDataContextRef (com.cloudera.api.swagger.model.ApiDataContextRef)1 ApiEntityTag (com.cloudera.api.swagger.model.ApiEntityTag)1