Search in sources :

Example 6 with InstanceConfig

use of com.sohu.cache.entity.InstanceConfig in project cachecloud by sohutv.

the class RedisConfigTemplateServiceImpl method handleClusterConfig.

@Override
public List<String> handleClusterConfig(int port) {
    List<InstanceConfig> instanceConfigList = getByType(ConstUtils.CACHE_TYPE_REDIS_CLUSTER);
    if (CollectionUtils.isEmpty(instanceConfigList)) {
        return Collections.emptyList();
    }
    List<String> configs = new ArrayList<String>();
    for (InstanceConfig instanceConfig : instanceConfigList) {
        if (!instanceConfig.isEffective()) {
            continue;
        }
        String configKey = instanceConfig.getConfigKey();
        String configValue = instanceConfig.getConfigValue();
        if (StringUtils.isBlank(configValue)) {
            configValue = SPECIAL_EMPTY_STR;
        }
        if (RedisClusterConfigEnum.CLUSTER_CONFIG_FILE.getKey().equals(configKey)) {
            configValue = String.format(configValue, port);
        }
        configs.add(combineConfigKeyValue(configKey, configValue));
    }
    return configs;
}
Also used : InstanceConfig(com.sohu.cache.entity.InstanceConfig) ArrayList(java.util.ArrayList)

Example 7 with InstanceConfig

use of com.sohu.cache.entity.InstanceConfig in project cachecloud by sohutv.

the class RedisConfigTemplateServiceImpl method handleCommonConfig.

@Override
public List<String> handleCommonConfig(int port, int maxMemory) {
    List<InstanceConfig> instanceConfigList = getByType(ConstUtils.CACHE_REDIS_STANDALONE);
    if (CollectionUtils.isEmpty(instanceConfigList)) {
        return Collections.emptyList();
    }
    List<String> configs = new ArrayList<String>();
    for (InstanceConfig instanceConfig : instanceConfigList) {
        // 无效配置过滤
        if (!instanceConfig.isEffective()) {
            continue;
        }
        String configKey = instanceConfig.getConfigKey();
        String configValue = instanceConfig.getConfigValue();
        if (StringUtils.isBlank(configValue)) {
            configValue = SPECIAL_EMPTY_STR;
        }
        if (RedisConfigEnum.MAXMEMORY.getKey().equals(configKey)) {
            configValue = String.format(configValue, maxMemory);
        } else if (RedisConfigEnum.DBFILENAME.getKey().equals(configKey) || RedisConfigEnum.APPENDFILENAME.getKey().equals(configKey) || RedisConfigEnum.PORT.getKey().equals(configKey)) {
            configValue = String.format(configValue, port);
        } else if (RedisConfigEnum.DIR.getKey().equals(configKey)) {
            configValue = MachineProtocol.DATA_DIR;
        } else if (RedisConfigEnum.AUTO_AOF_REWRITE_PERCENTAGE.getKey().equals(configKey)) {
            //随机比例 auto-aof-rewrite-percentage
            int percent = 69 + new Random().nextInt(30);
            configValue = String.format(configValue, percent);
        }
        configs.add(combineConfigKeyValue(configKey, configValue));
    }
    return configs;
}
Also used : InstanceConfig(com.sohu.cache.entity.InstanceConfig) Random(java.util.Random) ArrayList(java.util.ArrayList)

Example 8 with InstanceConfig

use of com.sohu.cache.entity.InstanceConfig in project cachecloud by sohutv.

the class InstanceConfigDaoTest method testById.

@Test
public void testById() {
    long id = 1;
    InstanceConfig instanceConfig = instanceConfigDao.getById(id);
    logger.info("===========testById start==============");
    logger.info(instanceConfig.toString());
    logger.info("===========testById end==============");
}
Also used : InstanceConfig(com.sohu.cache.entity.InstanceConfig) BaseTest(com.sohu.test.BaseTest) Test(org.junit.Test)

Example 9 with InstanceConfig

use of com.sohu.cache.entity.InstanceConfig in project cachecloud by sohutv.

the class InstanceConfigDaoTest method testSaveOrUpdate.

@Test
public void testSaveOrUpdate() {
    InstanceConfig instanceConfig = new InstanceConfig();
    instanceConfig.setConfigKey("hello");
    instanceConfig.setConfigValue("world");
    instanceConfig.setInfo("info");
    instanceConfig.setStatus(1);
    instanceConfig.setType(ConstUtils.CACHE_TYPE_REDIS_CLUSTER);
    instanceConfig.setUpdateTime(new Date());
    logger.info("===========testSaveOrUpdate start==============");
    instanceConfigDao.saveOrUpdate(instanceConfig);
    logger.info("===========testSaveOrUpdate end==============");
}
Also used : InstanceConfig(com.sohu.cache.entity.InstanceConfig) Date(java.util.Date) BaseTest(com.sohu.test.BaseTest) Test(org.junit.Test)

Example 10 with InstanceConfig

use of com.sohu.cache.entity.InstanceConfig in project cachecloud by sohutv.

the class InstanceConfigDaoTest method testByConfigKeyAndType.

@Test
public void testByConfigKeyAndType() {
    String configKey = "port";
    int type = ConstUtils.CACHE_REDIS_STANDALONE;
    InstanceConfig instanceConfig = instanceConfigDao.getByConfigKeyAndType(configKey, type);
    logger.info("===========testById start==============");
    logger.info(instanceConfig.toString());
    logger.info("===========testById end==============");
}
Also used : InstanceConfig(com.sohu.cache.entity.InstanceConfig) BaseTest(com.sohu.test.BaseTest) Test(org.junit.Test)

Aggregations

InstanceConfig (com.sohu.cache.entity.InstanceConfig)10 AppUser (com.sohu.cache.entity.AppUser)3 SuccessEnum (com.sohu.cache.web.enums.SuccessEnum)3 BaseTest (com.sohu.test.BaseTest)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 Date (java.util.Date)1 Random (java.util.Random)1