Search in sources :

Example 36 with ApiClusterTemplateService

use of com.cloudera.api.swagger.model.ApiClusterTemplateService 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 37 with ApiClusterTemplateService

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

the class CmTemplateProcessorTest method testIfCustomRoleConfigsAreMerged.

@Test
public void testIfCustomRoleConfigsAreMerged() {
    underTest = new CmTemplateProcessor(getBlueprintText("input/de-ha.bp"));
    // present in cluster template/blueprint
    List<ApiClusterTemplateConfig> hs2RoleConfigs = List.of(new ApiClusterTemplateConfig().name("hiveserver2_mv_files_thread").value("30"));
    List<ApiClusterTemplateRoleConfigGroup> hs2Rcg = List.of(new ApiClusterTemplateRoleConfigGroup().roleType("hiveserver2").configs(hs2RoleConfigs));
    // not present in cluster template/blueprint
    List<ApiClusterTemplateConfig> gatewayRoleConfigs = List.of(new ApiClusterTemplateConfig().name("hive_client_java_heapsize").value("6442450944"));
    List<ApiClusterTemplateRoleConfigGroup> gatewayRcg = List.of(new ApiClusterTemplateRoleConfigGroup().roleType("gateway").configs(gatewayRoleConfigs));
    ApiClusterTemplateService hive = underTest.getTemplate().getServices().stream().filter(service -> "HIVE_ON_TEZ".equals(service.getServiceType())).findFirst().get();
    List<ApiClusterTemplateConfig> existingGatewayConfigs = hive.getRoleConfigGroups().get(0).getConfigs();
    List<ApiClusterTemplateConfig> existingHs2Configs = hive.getRoleConfigGroups().get(1).getConfigs();
    underTest.mergeCustomRoleConfigs(hive, hs2Rcg);
    underTest.mergeCustomRoleConfigs(hive, gatewayRcg);
    assertEquals(existingHs2Configs.size(), hive.getRoleConfigGroups().get(1).getConfigs().size());
    assertEquals((existingGatewayConfigs == null ? 0 : existingGatewayConfigs.size()) + gatewayRoleConfigs.size(), hive.getRoleConfigGroups().get(0).getConfigs().size());
}
Also used : ApiClusterTemplateService(com.cloudera.api.swagger.model.ApiClusterTemplateService) ApiClusterTemplateRoleConfigGroup(com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup) ApiClusterTemplateConfig(com.cloudera.api.swagger.model.ApiClusterTemplateConfig) Test(org.junit.jupiter.api.Test)

Example 38 with ApiClusterTemplateService

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

the class CmTemplateProcessorTest method testAddServiceConfigs.

@Test
public void testAddServiceConfigs() {
    underTest = new CmTemplateProcessor(getBlueprintText("input/clouderamanager.bp"));
    List<ApiClusterTemplateConfig> configs = new ArrayList<>();
    configs.add(new ApiClusterTemplateConfig().name("hive_metastore_database_type").variable("hive-hive_metastore_database_type"));
    underTest.addServiceConfigs("HIVE", List.of("HIVEMETASTORE"), configs);
    ApiClusterTemplateService service = underTest.getTemplate().getServices().stream().filter(srv -> "HIVE".equals(srv.getServiceType())).findAny().get();
    List<ApiClusterTemplateConfig> serviceConfigs = service.getServiceConfigs();
    assertEquals(1, serviceConfigs.size());
    assertEquals("hive_metastore_database_type", serviceConfigs.get(0).getName());
    assertEquals("hive-hive_metastore_database_type", serviceConfigs.get(0).getVariable());
}
Also used : ApiClusterTemplateService(com.cloudera.api.swagger.model.ApiClusterTemplateService) ArrayList(java.util.ArrayList) ApiClusterTemplateConfig(com.cloudera.api.swagger.model.ApiClusterTemplateConfig) Test(org.junit.jupiter.api.Test)

Example 39 with ApiClusterTemplateService

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

the class CmTemplateProcessorTest method addExistingSafetyValveConfigs.

@Test
public void addExistingSafetyValveConfigs() {
    underTest = new CmTemplateProcessor(getBlueprintText("input/clouderamanager-existing-conf.bp"));
    List<ApiClusterTemplateConfig> configs = new ArrayList<>();
    configs.add(new ApiClusterTemplateConfig().name("hive_service_config_safety_valve").value("<property><name>testkey</name><value>testvalue</value></property>"));
    underTest.addServiceConfigs("HIVE", List.of("GATEWAY", "HIVEMETASTORE"), configs);
    ApiClusterTemplateService service = underTest.getTemplate().getServices().stream().filter(srv -> "HIVE".equals(srv.getServiceType())).findAny().get();
    List<ApiClusterTemplateConfig> serviceConfigs = service.getServiceConfigs();
    assertEquals(1, serviceConfigs.size());
    assertEquals("hive_service_config_safety_valve", serviceConfigs.get(0).getName());
    assertTrue(serviceConfigs.get(0).getValue().startsWith("<property><name>testkey</name><value>testvalue</value></property>"));
    assertTrue(serviceConfigs.get(0).getValue().endsWith("<property><name>hive.metastore.server.filter.enabled</name><value>true</value></property> " + "<property><name>hive.metastore.filter.hook</name>" + "<value>org.apache.hadoop.hive.ql.security.authorization.plugin.metastore.HiveMetaStoreAuthorizer</value></property>"));
    assertTrue(serviceConfigs.get(0).getValue().contains("\n"));
    Map<String, List<ApiClusterTemplateConfig>> roleConfigs = new HashMap<>();
    roleConfigs.put("spark_on_yarn-GATEWAY-BASE", List.of(new ApiClusterTemplateConfig().name("spark-conf/spark-defaults.conf_client_config_safety_valve").value("testkey=testvalue")));
    underTest.addRoleConfigs("SPARK_ON_YARN", roleConfigs);
    service = underTest.getTemplate().getServices().stream().filter(srv -> "SPARK_ON_YARN".equals(srv.getServiceType())).findAny().get();
    ApiClusterTemplateRoleConfigGroup gw = service.getRoleConfigGroups().stream().filter(rcg -> "GATEWAY".equals(rcg.getRoleType())).findAny().get();
    List<ApiClusterTemplateConfig> gwConfigs = gw.getConfigs();
    assertEquals(1, gwConfigs.size());
    assertEquals("spark-conf/spark-defaults.conf_client_config_safety_valve", gwConfigs.get(0).getName());
    assertTrue(gwConfigs.get(0).getValue().startsWith("testkey=testvalue"));
    assertTrue(gwConfigs.get(0).getValue().endsWith("spark.yarn.access.hadoopFileSystems=s3a://expn-cis-sandbox-prod-cdp-us-east-1"));
    assertTrue(gwConfigs.get(0).getValue().contains("\n"));
}
Also used : InstanceCount(com.sequenceiq.cloudbreak.cloud.model.InstanceCount) GeneralClusterConfigs(com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) ServiceAttributes(com.sequenceiq.cloudbreak.template.model.ServiceAttributes) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) ApiClusterTemplateRoleConfigGroup(com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup) ApiClusterTemplateInstantiator(com.cloudera.api.swagger.model.ApiClusterTemplateInstantiator) FileReaderUtils(com.sequenceiq.cloudbreak.util.FileReaderUtils) ApiClusterTemplateService(com.cloudera.api.swagger.model.ApiClusterTemplateService) Map.entry(java.util.Map.entry) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) GatewayRecommendation(com.sequenceiq.cloudbreak.cloud.model.GatewayRecommendation) YarnRoles(com.sequenceiq.cloudbreak.cmtemplate.configproviders.yarn.YarnRoles) ApiClusterTemplateRoleConfigGroupInfo(com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroupInfo) ApiClusterTemplate(com.cloudera.api.swagger.model.ApiClusterTemplate) CustomConfigurationPropertyView(com.sequenceiq.cloudbreak.template.views.CustomConfigurationPropertyView) ClusterHostAttributes(com.sequenceiq.cloudbreak.cluster.model.ClusterHostAttributes) AutoscaleRecommendation(com.sequenceiq.cloudbreak.cloud.model.AutoscaleRecommendation) Versioned(com.sequenceiq.cloudbreak.common.type.Versioned) ConfigUtils.configVar(com.sequenceiq.cloudbreak.cmtemplate.configproviders.ConfigUtils.configVar) Set(java.util.Set) Collectors(java.util.stream.Collectors) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) TemplatePreparationObject(com.sequenceiq.cloudbreak.template.TemplatePreparationObject) Test(org.junit.jupiter.api.Test) ServiceComponent(com.sequenceiq.cloudbreak.template.model.ServiceComponent) List(java.util.List) YarnConstants(com.sequenceiq.cloudbreak.cmtemplate.configproviders.yarn.YarnConstants) TreeMap(java.util.TreeMap) ApiClusterTemplateHostInfo(com.cloudera.api.swagger.model.ApiClusterTemplateHostInfo) ResizeRecommendation(com.sequenceiq.cloudbreak.cloud.model.ResizeRecommendation) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ApiClusterTemplateConfig(com.cloudera.api.swagger.model.ApiClusterTemplateConfig) Optional(java.util.Optional) HashMap(java.util.HashMap) ApiClusterTemplateService(com.cloudera.api.swagger.model.ApiClusterTemplateService) ArrayList(java.util.ArrayList) ApiClusterTemplateRoleConfigGroup(com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup) ArrayList(java.util.ArrayList) List(java.util.List) ApiClusterTemplateConfig(com.cloudera.api.swagger.model.ApiClusterTemplateConfig) Test(org.junit.jupiter.api.Test)

Example 40 with ApiClusterTemplateService

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

the class CmTemplateProcessorTest method addExistingRoleConfigs.

@Test
public void addExistingRoleConfigs() {
    underTest = new CmTemplateProcessor(getBlueprintText("input/clouderamanager-existing-conf.bp"));
    Map<String, List<ApiClusterTemplateConfig>> configs = new HashMap<>();
    configs.put("hdfs-NAMENODE-BASE", List.of(new ApiClusterTemplateConfig().name("dfs_name_dir_list").variable("master_NAMENODE")));
    configs.put("hdfs-DATANODE-BASE", List.of(new ApiClusterTemplateConfig().name("dfs_data_dir_list").variable("worker_DATANODE"), new ApiClusterTemplateConfig().name("dfs_data_dir_list_2").variable("worker_DATANODE_2")));
    underTest.addRoleConfigs("HDFS", configs);
    ApiClusterTemplateService service = underTest.getTemplate().getServices().stream().filter(srv -> "HDFS".equals(srv.getServiceType())).findAny().get();
    ApiClusterTemplateRoleConfigGroup dn = service.getRoleConfigGroups().stream().filter(rcg -> "DATANODE".equals(rcg.getRoleType())).findAny().get();
    List<ApiClusterTemplateConfig> dnConfigs = dn.getConfigs();
    ApiClusterTemplateRoleConfigGroup nn = service.getRoleConfigGroups().stream().filter(rcg -> "NAMENODE".equals(rcg.getRoleType())).findAny().get();
    List<ApiClusterTemplateConfig> nnConfigs = nn.getConfigs();
    assertEquals(1, nnConfigs.size());
    assertEquals(4, dnConfigs.size());
    assertEquals("dfs_name_dir_list", nnConfigs.get(0).getName());
    ApiClusterTemplateConfig dfs1Config = dnConfigs.stream().filter(c -> "dfs_data_dir_list".equals(c.getName())).findFirst().get();
    assertEquals("/dfs/dn", dfs1Config.getValue());
    assertNull(dfs1Config.getVariable());
    ApiClusterTemplateConfig dfs2Config = dnConfigs.stream().filter(c -> "dfs_data_dir_list_2".equals(c.getName())).findFirst().get();
    assertEquals("worker_DATANODE_2", dfs2Config.getVariable());
    assertNull(dfs2Config.getValue());
}
Also used : HashMap(java.util.HashMap) ApiClusterTemplateService(com.cloudera.api.swagger.model.ApiClusterTemplateService) ApiClusterTemplateRoleConfigGroup(com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup) ArrayList(java.util.ArrayList) List(java.util.List) ApiClusterTemplateConfig(com.cloudera.api.swagger.model.ApiClusterTemplateConfig) Test(org.junit.jupiter.api.Test)

Aggregations

ApiClusterTemplateService (com.cloudera.api.swagger.model.ApiClusterTemplateService)48 TemplatePreparationObject (com.sequenceiq.cloudbreak.template.TemplatePreparationObject)30 ApiClusterTemplateRoleConfigGroup (com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup)25 HostgroupView (com.sequenceiq.cloudbreak.template.views.HostgroupView)25 ClouderaManagerRepo (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo)19 GeneralClusterConfigs (com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs)18 DisplayName (org.junit.jupiter.api.DisplayName)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)16 ApiClusterTemplateConfig (com.cloudera.api.swagger.model.ApiClusterTemplateConfig)15 ArrayList (java.util.ArrayList)14 Test (org.junit.jupiter.api.Test)13 MethodSource (org.junit.jupiter.params.provider.MethodSource)13 List (java.util.List)12 Map (java.util.Map)10 CmTemplateProcessor (com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor)9 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 Set (java.util.Set)9 Collectors (java.util.stream.Collectors)9 Optional (java.util.Optional)8