Search in sources :

Example 1 with JobConfigMeta

use of com.vip.saturn.job.console.domain.JobConfigMeta in project Saturn by vipshop.

the class SystemConfigController method genSystemConfigInfo.

private Map<String, List<SystemConfigVo>> genSystemConfigInfo(Map<String, List<JobConfigMeta>> jobConfigGroups, List<SystemConfig> systemConfigs) {
    Map<String, SystemConfig> systemConfigMap = convertList2Map(systemConfigs);
    Map<String, List<SystemConfigVo>> jobConfigDisplayInfoMap = Maps.newHashMap();
    for (Map.Entry<String, List<JobConfigMeta>> group : jobConfigGroups.entrySet()) {
        List<JobConfigMeta> jobConfigMetas = group.getValue();
        List<SystemConfigVo> jobConfigVos = Lists.newArrayListWithCapacity(jobConfigMetas.size());
        for (JobConfigMeta configMeta : jobConfigMetas) {
            SystemConfig systemConfig = systemConfigMap.get(configMeta.getName());
            String value = systemConfig != null ? systemConfig.getValue() : null;
            jobConfigVos.add(new SystemConfigVo(configMeta.getName(), value, configMeta.getDesc_zh()));
        }
        jobConfigDisplayInfoMap.put(group.getKey(), jobConfigVos);
    }
    return jobConfigDisplayInfoMap;
}
Also used : SystemConfig(com.vip.saturn.job.console.mybatis.entity.SystemConfig) JobConfigMeta(com.vip.saturn.job.console.domain.JobConfigMeta) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) SystemConfigVo(com.vip.saturn.job.console.domain.SystemConfigVo)

Example 2 with JobConfigMeta

use of com.vip.saturn.job.console.domain.JobConfigMeta in project Saturn by vipshop.

the class ConsoleConfigController method genSystemConfigInfo.

/**
 * 根据Yaml定义,返回作业配置。
 *
 * @param jobConfigGroups 来自yaml定义的配置展现分类定义
 * @param systemConfigs 数据库的系统配置项
 * @return 配置分组与配置信息map
 */
private Map<String, List<SystemConfigVo>> genSystemConfigInfo(Map<String, List<JobConfigMeta>> jobConfigGroups, List<SystemConfig> systemConfigs) {
    Map<String, SystemConfig> systemConfigMap = convertList2Map(systemConfigs);
    Map<String, List<SystemConfigVo>> jobConfigDisplayInfoMap = Maps.newHashMap();
    Set<String> categorizedConfigKeySet = Sets.newHashSet();
    for (Map.Entry<String, List<JobConfigMeta>> group : jobConfigGroups.entrySet()) {
        List<JobConfigMeta> jobConfigMetas = group.getValue();
        List<SystemConfigVo> jobConfigVos = Lists.newArrayListWithCapacity(jobConfigMetas.size());
        for (JobConfigMeta configMeta : jobConfigMetas) {
            String configName = configMeta.getName();
            SystemConfig systemConfig = systemConfigMap.get(configName);
            String value = systemConfig != null ? systemConfig.getValue() : null;
            jobConfigVos.add(new SystemConfigVo(configName, value, configMeta.getDesc_zh()));
            categorizedConfigKeySet.add(configName);
        }
        jobConfigDisplayInfoMap.put(group.getKey(), jobConfigVos);
    }
    // 将所有没有在yaml定义的配置放到Others组别
    if (categorizedConfigKeySet.size() != systemConfigs.size()) {
        List<SystemConfigVo> unCategorizedJobConfigVos = getUncategorizedSystemConfigs(systemConfigs, categorizedConfigKeySet);
        jobConfigDisplayInfoMap.put("other_configs", unCategorizedJobConfigVos);
    }
    return jobConfigDisplayInfoMap;
}
Also used : SystemConfig(com.vip.saturn.job.console.mybatis.entity.SystemConfig) JobConfigMeta(com.vip.saturn.job.console.domain.JobConfigMeta) SystemConfigVo(com.vip.saturn.job.console.domain.SystemConfigVo)

Example 3 with JobConfigMeta

use of com.vip.saturn.job.console.domain.JobConfigMeta in project Saturn by vipshop.

the class SystemConfigControllerTest method testGetConfigMeta.

@Test
public void testGetConfigMeta() throws Exception {
    MvcResult result = mvc.perform(get("/console/configs")).andExpect(status().isOk()).andReturn();
    String body = result.getResponse().getContentAsString();
    Map<String, Object> resultMap = JSONObject.parseObject(body, Map.class);
    Map<String, Object> objValue = (Map<String, Object>) resultMap.get("obj");
    assertEquals(4, objValue.size());
    List<JobConfigMeta> metas = (List<JobConfigMeta>) objValue.get("job_configs");
    assertEquals(2, metas.size());
    metas = (List<JobConfigMeta>) objValue.get("executor_configs");
    assertEquals(2, metas.size());
    metas = (List<JobConfigMeta>) objValue.get("cluster_configs");
    assertEquals(4, metas.size());
    metas = (List<JobConfigMeta>) objValue.get("console_configs");
    assertEquals(2, metas.size());
}
Also used : JobConfigMeta(com.vip.saturn.job.console.domain.JobConfigMeta) JSONObject(com.alibaba.fastjson.JSONObject) List(java.util.List) MvcResult(org.springframework.test.web.servlet.MvcResult) Map(java.util.Map) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) AbstractSaturnConsoleTest(com.vip.saturn.job.console.AbstractSaturnConsoleTest)

Example 4 with JobConfigMeta

use of com.vip.saturn.job.console.domain.JobConfigMeta in project Saturn by vipshop.

the class ConsoleConfigControllerTest method testGetConfigMeta.

@Test
public void testGetConfigMeta() throws Exception {
    MvcResult result = mvc.perform(get("/console/configs/console")).andExpect(status().isOk()).andReturn();
    String body = result.getResponse().getContentAsString();
    Map<String, Object> resultMap = JSONObject.parseObject(body, Map.class);
    Map<String, Object> objValue = (Map<String, Object>) resultMap.get("obj");
    assertEquals(5, objValue.size());
    List<JobConfigMeta> metas = (List<JobConfigMeta>) objValue.get("job_configs");
    assertTrue(metas.size() > 0);
    metas = (List<JobConfigMeta>) objValue.get("executor_configs");
    assertTrue(metas.size() > 0);
    metas = (List<JobConfigMeta>) objValue.get("cluster_configs");
    assertTrue(metas.size() > 0);
    metas = (List<JobConfigMeta>) objValue.get("console_configs");
    assertTrue(metas.size() > 0);
    metas = (List<JobConfigMeta>) objValue.get("other_configs");
    assertTrue(metas.size() > 0);
}
Also used : JobConfigMeta(com.vip.saturn.job.console.domain.JobConfigMeta) JSONObject(com.alibaba.fastjson.JSONObject) List(java.util.List) MvcResult(org.springframework.test.web.servlet.MvcResult) Map(java.util.Map) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) AbstractSaturnConsoleTest(com.vip.saturn.job.console.AbstractSaturnConsoleTest)

Aggregations

JobConfigMeta (com.vip.saturn.job.console.domain.JobConfigMeta)4 List (java.util.List)3 Map (java.util.Map)3 JSONObject (com.alibaba.fastjson.JSONObject)2 AbstractSaturnConsoleTest (com.vip.saturn.job.console.AbstractSaturnConsoleTest)2 SystemConfigVo (com.vip.saturn.job.console.domain.SystemConfigVo)2 SystemConfig (com.vip.saturn.job.console.mybatis.entity.SystemConfig)2 Test (org.junit.Test)2 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)2 MvcResult (org.springframework.test.web.servlet.MvcResult)2 HashMap (java.util.HashMap)1