Search in sources :

Example 21 with ApiClusterTemplateRoleConfigGroup

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

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

Example 23 with ApiClusterTemplateRoleConfigGroup

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

the class KnoxGatewayConfigProviderTest method testGetAdditionalServicesWhenKnoxRequestedAndBlueprintDoesNoContainKnoxWithMultiGateway.

@Test
public void testGetAdditionalServicesWhenKnoxRequestedAndBlueprintDoesNoContainKnoxWithMultiGateway() {
    HostgroupView master = new HostgroupView("master", 1, InstanceGroupType.GATEWAY, 1);
    HostgroupView master2 = new HostgroupView("master2", 1, InstanceGroupType.GATEWAY, 1);
    HostgroupView worker = new HostgroupView("worker", 2, InstanceGroupType.CORE, 2);
    Gateway gateway = new Gateway();
    TemplatePreparationObject preparationObject = Builder.builder().withHostgroupViews(Set.of(master, master2, worker)).withGateway(gateway, "key", new HashSet<>()).build();
    String inputJson = getBlueprintText("input/clouderamanager.bp");
    CmTemplateProcessor cmTemplateProcessor = new CmTemplateProcessor(inputJson);
    Map<String, ApiClusterTemplateService> additionalServices = underTest.getAdditionalServices(cmTemplateProcessor, preparationObject);
    ApiClusterTemplateService knox1 = additionalServices.get("master");
    ApiClusterTemplateService knox2 = additionalServices.get("master2");
    assertEquals(2, additionalServices.size());
    assertNotNull(knox1);
    assertNotNull(knox2);
    assertEquals("KNOX", knox1.getServiceType());
    assertEquals("KNOX", knox2.getServiceType());
    assertEquals("knox", knox1.getRefName());
    assertEquals("knox", knox2.getRefName());
    ApiClusterTemplateRoleConfigGroup roleConfigGroup1 = knox1.getRoleConfigGroups().get(0);
    ApiClusterTemplateRoleConfigGroup roleConfigGroup2 = knox1.getRoleConfigGroups().get(0);
    assertEquals("KNOX_GATEWAY", roleConfigGroup1.getRoleType());
    assertTrue(roleConfigGroup1.getBase());
    assertEquals("KNOX_GATEWAY", roleConfigGroup2.getRoleType());
    assertTrue(roleConfigGroup2.getBase());
}
Also used : TemplatePreparationObject(com.sequenceiq.cloudbreak.template.TemplatePreparationObject) Gateway(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway) ApiClusterTemplateService(com.cloudera.api.swagger.model.ApiClusterTemplateService) ApiClusterTemplateRoleConfigGroup(com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor) HostgroupView(com.sequenceiq.cloudbreak.template.views.HostgroupView) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with ApiClusterTemplateRoleConfigGroup

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

the class GeneratedCmTemplateService method prepareApiClusterTemplateServices.

private List<ApiClusterTemplateService> prepareApiClusterTemplateServices(Set<ServiceConfig> serviceConfigs, Map<String, Set<String>> hostServiceMap) {
    List<ApiClusterTemplateService> clusterTemplateServices = new ArrayList<>();
    for (ServiceConfig serviceConfig : serviceConfigs) {
        String serviceName = serviceConfig.getName();
        String lowerCaseServiceName = serviceName.toLowerCase();
        ApiClusterTemplateService apiClusterTemplateService = new ApiClusterTemplateService();
        apiClusterTemplateService.setRefName(lowerCaseServiceName);
        apiClusterTemplateService.setServiceType(serviceName);
        apiClusterTemplateService.setRoleConfigGroups(new ArrayList<>());
        serviceConfig.getComponents().forEach(component -> {
            Set<ApiClusterTemplateRoleConfigGroup> roleConfigGroups = new HashSet<>();
            component.getGroups().forEach(group -> {
                String componentName = component.getName();
                boolean base = component.getGroups().size() == 1 || component.isBase();
                String hostServiceNameEnd = base ? "BASE" : group.toUpperCase();
                String hostServiceName = String.format("%s-%s-%s", lowerCaseServiceName, component.getName().toUpperCase(), hostServiceNameEnd);
                ApiClusterTemplateRoleConfigGroup apiClusterTemplateRoleConfigGroup = new ApiClusterTemplateRoleConfigGroup();
                apiClusterTemplateRoleConfigGroup.setRoleType(componentName.toUpperCase());
                apiClusterTemplateRoleConfigGroup.setRefName(hostServiceName);
                apiClusterTemplateRoleConfigGroup.setBase(base);
                if (hostServiceMap.keySet().contains(group)) {
                    hostServiceMap.get(group).add(hostServiceName);
                } else {
                    hostServiceMap.put(group, Sets.newHashSet(hostServiceName));
                }
                roleConfigGroups.add(apiClusterTemplateRoleConfigGroup);
            });
            apiClusterTemplateService.getRoleConfigGroups().addAll(roleConfigGroups);
        });
        clusterTemplateServices.add(apiClusterTemplateService);
    }
    return clusterTemplateServices;
}
Also used : ServiceConfig(com.sequenceiq.cloudbreak.cmtemplate.generator.configuration.domain.dependencies.ServiceConfig) ApiClusterTemplateService(com.cloudera.api.swagger.model.ApiClusterTemplateService) ArrayList(java.util.ArrayList) ApiClusterTemplateRoleConfigGroup(com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup) HashSet(java.util.HashSet)

Example 25 with ApiClusterTemplateRoleConfigGroup

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

the class CmTemplateProcessor method getCustomRoleConfigsMap.

public Map<String, List<ApiClusterTemplateRoleConfigGroup>> getCustomRoleConfigsMap(Set<CustomConfigurationPropertyView> configProperties) {
    Map<String, List<ApiClusterTemplateRoleConfigGroup>> roleConfigsMap = new HashMap<>();
    List<CustomConfigurationPropertyView> roleConfigGroups = getCustomRoleConfigs(configProperties);
    roleConfigGroups.forEach(roleConfigProperty -> {
        String name = roleConfigProperty.getName();
        String value = roleConfigProperty.getValue();
        String service = roleConfigProperty.getServiceType();
        String role = roleConfigProperty.getRoleType();
        roleConfigsMap.computeIfAbsent(service, k -> new ArrayList<>());
        Optional<ApiClusterTemplateRoleConfigGroup> roleConfigGroup = filterRCGsByRoleType(roleConfigsMap.get(service), role);
        if (roleConfigGroup.isPresent()) {
            roleConfigGroup.get().getConfigs().add(new ApiClusterTemplateConfig().name(name).value(value));
        } else {
            ApiClusterTemplateRoleConfigGroup roleToAdd = new ApiClusterTemplateRoleConfigGroup().roleType(role).addConfigsItem(new ApiClusterTemplateConfig().name(name).value(value));
            roleConfigsMap.get(service).add(roleToAdd);
        }
    });
    return roleConfigsMap;
}
Also used : HashMap(java.util.HashMap) CustomConfigurationPropertyView(com.sequenceiq.cloudbreak.template.views.CustomConfigurationPropertyView) ApiClusterTemplateRoleConfigGroup(com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup) List(java.util.List) ArrayList(java.util.ArrayList) ApiClusterTemplateConfig(com.cloudera.api.swagger.model.ApiClusterTemplateConfig)

Aggregations

ApiClusterTemplateRoleConfigGroup (com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroup)25 ApiClusterTemplateService (com.cloudera.api.swagger.model.ApiClusterTemplateService)22 ApiClusterTemplateConfig (com.cloudera.api.swagger.model.ApiClusterTemplateConfig)11 ArrayList (java.util.ArrayList)11 List (java.util.List)11 HashMap (java.util.HashMap)10 TemplatePreparationObject (com.sequenceiq.cloudbreak.template.TemplatePreparationObject)9 Test (org.junit.jupiter.api.Test)8 ApiClusterTemplate (com.cloudera.api.swagger.model.ApiClusterTemplate)5 ClouderaManagerRepo (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo)5 CustomConfigurationPropertyView (com.sequenceiq.cloudbreak.template.views.CustomConfigurationPropertyView)5 HashSet (java.util.HashSet)5 Map (java.util.Map)5 Optional (java.util.Optional)5 ApiClusterTemplateHostTemplate (com.cloudera.api.swagger.model.ApiClusterTemplateHostTemplate)4 ApiClusterTemplateInstantiator (com.cloudera.api.swagger.model.ApiClusterTemplateInstantiator)4 ApiClusterTemplateRoleConfigGroupInfo (com.cloudera.api.swagger.model.ApiClusterTemplateRoleConfigGroupInfo)4 JsonUtil (com.sequenceiq.cloudbreak.common.json.JsonUtil)4 ApiClusterTemplateHostInfo (com.cloudera.api.swagger.model.ApiClusterTemplateHostInfo)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3