Search in sources :

Example 11 with ConfigModel

use of com.ctrip.xpipe.redis.console.model.ConfigModel 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 12 with ConfigModel

use of com.ctrip.xpipe.redis.console.model.ConfigModel 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 13 with ConfigModel

use of com.ctrip.xpipe.redis.console.model.ConfigModel 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)

Example 14 with ConfigModel

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

the class ConfigController method changeConfig.

private RetMessage changeConfig(final String key, final String val, final String uri) {
    UserInfo user = UserInfoHolder.DEFAULT.getUser();
    String userId = user.getUserId();
    ConfigModel configModel = new ConfigModel();
    configModel.setUpdateUser(userId);
    configModel.setUpdateIP(uri);
    logger.info("[changeConfig] Config changed by user: {} and ip: {}", userId, uri);
    try {
        boolean target = Boolean.parseBoolean(val);
        if (DefaultConsoleDbConfig.KEY_ALERT_SYSTEM_ON.equalsIgnoreCase(key)) {
            if (target) {
                configService.startAlertSystem(configModel);
            } else {
                configService.stopAlertSystem(configModel, consoleConfig.getConfigDefaultRestoreHours());
            }
        } else if (DefaultConsoleDbConfig.KEY_SENTINEL_AUTO_PROCESS.equalsIgnoreCase(key)) {
            if (target) {
                configService.startSentinelAutoProcess(configModel);
            } else {
                configService.stopSentinelAutoProcess(configModel, consoleConfig.getConfigDefaultRestoreHours());
            }
        } else {
            return RetMessage.createFailMessage("Unknown config key: " + key);
        }
        return RetMessage.createSuccessMessage();
    } catch (Exception e) {
        logger.error("[getExecuteFunction] Exception: {}", e);
        return RetMessage.createFailMessage(e.getMessage());
    }
}
Also used : ConfigModel(com.ctrip.xpipe.redis.console.model.ConfigModel) UserInfo(com.ctrip.xpipe.api.sso.UserInfo)

Example 15 with ConfigModel

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

the class AlertPolicyManagerTest method testEmptyQueryRecipients.

@Test
public void testEmptyQueryRecipients() throws Exception {
    configService.stopAlertSystem(new ConfigModel(), 1);
    alert.setAlertType(ALERT_TYPE.MARK_INSTANCE_UP);
    List<String> result = policyManager.queryRecepients(alert);
    logger.info("[recipients] {}", result);
    Assert.assertFalse(result.isEmpty());
}
Also used : ConfigModel(com.ctrip.xpipe.redis.console.model.ConfigModel) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Aggregations

ConfigModel (com.ctrip.xpipe.redis.console.model.ConfigModel)17 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)5 Test (org.junit.Test)5 ConfigTbl (com.ctrip.xpipe.redis.console.model.ConfigTbl)4 Date (java.util.Date)3 RetMessage (com.ctrip.xpipe.redis.console.controller.api.RetMessage)2 DalException (org.unidal.dal.jdbc.DalException)2 UserInfo (com.ctrip.xpipe.api.sso.UserInfo)1