Search in sources :

Example 1 with ConfigTbl

use of com.ctrip.xpipe.redis.console.model.ConfigTbl in project x-pipe by ctripcorp.

the class ConfigDao method setConfig.

public void setConfig(ConfigModel config, Date until) throws DalException {
    logger.info("[setConfig] {}: {}", config, until);
    boolean insert = false;
    try {
        getKey(config.getKey());
    } catch (DalException e) {
        logger.info("[setKey][not exist, create]{}", e.getMessage());
        insert = true;
    }
    ConfigTbl configTbl = new ConfigTbl();
    configTbl.setKey(config.getKey());
    configTbl.setValue(config.getVal());
    if (config.getUpdateIP() != null) {
        configTbl.setLatestUpdateIp(config.getUpdateIP());
    }
    if (config.getUpdateUser() != null) {
        configTbl.setLatestUpdateUser(config.getUpdateUser());
    }
    if (until != null) {
        configTbl.setUntil(until);
    }
    if (!insert) {
        queryHandler.handleUpdate(new DalQuery<Integer>() {

            @Override
            public Integer doQuery() throws DalException {
                return configTblDao.updateValAndUntilByKey(configTbl, ConfigTblEntity.UPDATESET_FULL);
            }
        });
    } else {
        configTbl.setDesc("insert automatically");
        queryHandler.handleInsert(new DalQuery<Integer>() {

            @Override
            public Integer doQuery() throws DalException {
                return configTblDao.insert(configTbl);
            }
        });
    }
    logger.info("[setConfig] config update successfully, as {}", config.toString());
}
Also used : ConfigTbl(com.ctrip.xpipe.redis.console.model.ConfigTbl) DalException(org.unidal.dal.jdbc.DalException)

Example 2 with ConfigTbl

use of com.ctrip.xpipe.redis.console.model.ConfigTbl in project x-pipe by ctripcorp.

the class ConfigServiceImpl method getConfig.

@Override
public ConfigModel getConfig(String key) {
    try {
        ConfigTbl configTbl = configDao.getByKey(key);
        ConfigModel config = new ConfigModel();
        config.setKey(key);
        config.setVal(configTbl.getValue());
        config.setUpdateIP(configTbl.getLatestUpdateIp());
        config.setUpdateUser(configTbl.getLatestUpdateUser());
        return config;
    } catch (DalException e) {
        logger.error("[getConfig] {}", e);
        return null;
    }
}
Also used : ConfigTbl(com.ctrip.xpipe.redis.console.model.ConfigTbl) ConfigModel(com.ctrip.xpipe.redis.console.model.ConfigModel) DalException(org.unidal.dal.jdbc.DalException)

Example 3 with ConfigTbl

use of com.ctrip.xpipe.redis.console.model.ConfigTbl in project x-pipe by ctripcorp.

the class ConfigDaoTest method testSetConfigAndUntil2.

@Test
public void testSetConfigAndUntil2() throws Exception {
    String localKey = "config.dao.test";
    String value = String.valueOf(true);
    Date date = DateTimeUtils.getHoursLaterDate(1);
    configDao.setKey(localKey, value);
    value = String.valueOf(false);
    ConfigModel model = new ConfigModel().setKey(localKey).setVal(value);
    configDao.setConfigAndUntil(model, date);
    ConfigTbl config = configDao.getByKey(localKey);
    logger.info("config: {}", config);
    Assert.assertEquals(value, config.getValue());
    Assert.assertEquals(date, config.getUntil());
}
Also used : ConfigModel(com.ctrip.xpipe.redis.console.model.ConfigModel) ConfigTbl(com.ctrip.xpipe.redis.console.model.ConfigTbl) Date(java.util.Date) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 4 with ConfigTbl

use of com.ctrip.xpipe.redis.console.model.ConfigTbl in project x-pipe by ctripcorp.

the class ConfigDaoTest method testSetKeyAndUntil.

@Test
public void testSetKeyAndUntil() throws Exception {
    String localKey = "config.dao.test";
    String value = String.valueOf(false);
    Date date = DateTimeUtils.getHoursLaterDate(1);
    ConfigModel model = new ConfigModel().setKey(localKey).setVal(value);
    configDao.setConfigAndUntil(model, date);
    ConfigTbl config = configDao.getByKey(localKey);
    logger.info("config: {}", config);
    Assert.assertEquals(value, config.getValue());
    Assert.assertEquals(date, config.getUntil());
}
Also used : ConfigModel(com.ctrip.xpipe.redis.console.model.ConfigModel) ConfigTbl(com.ctrip.xpipe.redis.console.model.ConfigTbl) Date(java.util.Date) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 5 with ConfigTbl

use of com.ctrip.xpipe.redis.console.model.ConfigTbl in project x-pipe by ctripcorp.

the class ConfigServiceImpl method getAndResetTrueIfExpired.

private boolean getAndResetTrueIfExpired(String key) {
    try {
        ConfigTbl config = configDao.getByKey(key);
        boolean result = Boolean.valueOf(config.getValue());
        if (!result) {
            Date expireDate = config.getUntil();
            Date currentDate = new Date();
            ConfigModel configModel = new ConfigModel().setKey(key).setVal(String.valueOf(true)).setUpdateUser("System");
            if (currentDate.after(expireDate)) {
                logger.info("[getAndResetTrueIfExpired] Off time expired, reset to be true");
                configDao.setConfig(configModel);
                result = true;
            }
        }
        return result;
    } catch (Exception e) {
        return true;
    }
}
Also used : ConfigTbl(com.ctrip.xpipe.redis.console.model.ConfigTbl) ConfigModel(com.ctrip.xpipe.redis.console.model.ConfigModel) Date(java.util.Date) DalException(org.unidal.dal.jdbc.DalException)

Aggregations

ConfigTbl (com.ctrip.xpipe.redis.console.model.ConfigTbl)5 ConfigModel (com.ctrip.xpipe.redis.console.model.ConfigModel)4 Date (java.util.Date)3 DalException (org.unidal.dal.jdbc.DalException)3 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)2 Test (org.junit.Test)2