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());
}
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());
}
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;
}
}
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());
}
}
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());
}
Aggregations