use of com.ctrip.xpipe.redis.console.alert.ALERT_TYPE in project x-pipe by ctripcorp.
the class SenderManager method getGroupedAlerts.
/**
***********************************************************************
* Ugly implement here, because a unit test is needed for a rarely occurred bug
* that will cause an mail was sent with specified alert type while missing alert details
* Which, obviously was caused by multi-thread, and the concurrenthashmap is not capable of
* controlling the situation that one "thief thread" trying to remove stuffs from its value(set, list, etc.)
*/
List<Map<ALERT_TYPE, Set<AlertEntity>>> getGroupedAlerts(Map<ALERT_TYPE, Set<AlertEntity>> alerts) {
List<Map<ALERT_TYPE, Set<AlertEntity>>> result = new ArrayList<>(3);
if (alerts == null || alerts.isEmpty())
return null;
Map<ALERT_TYPE, Set<AlertEntity>> sendToDBA = new HashMap<>();
Map<ALERT_TYPE, Set<AlertEntity>> sendToXPipeAdmin = new HashMap<>();
Map<ALERT_TYPE, Set<AlertEntity>> sendToClusterAdmin = new HashMap<>();
for (ALERT_TYPE type : alerts.keySet()) {
Set<AlertEntity> alertEntities = new HashSet<>(alerts.get(type));
if (alertEntities == null || alertEntities.isEmpty())
continue;
logger.info("[email_dba] {}, {}, {}", alertEntities, alertEntities.isEmpty(), alertEntities.size());
if ((type.getAlertPolicy() & EMAIL_DBA) != 0 && shouldAlert(type)) {
sendToDBA.put(type, alertEntities);
}
if ((type.getAlertPolicy() & EMAIL_XPIPE_ADMIN) != 0) {
sendToXPipeAdmin.put(type, alertEntities);
}
if ((type.getAlertPolicy() & EMAIL_CLUSTER_ADMIN) != 0 && shouldAlert(type)) {
sendToClusterAdmin.put(type, alertEntities);
}
}
result.add(sendToDBA);
result.add(sendToXPipeAdmin);
result.add(sendToClusterAdmin);
return result;
}
use of com.ctrip.xpipe.redis.console.alert.ALERT_TYPE in project x-pipe by ctripcorp.
the class AlertPolicyManagerTest method testQueryRecepients.
@Test
public void testQueryRecepients() throws Exception {
AlertEntity entity = new AlertEntity(null, null, null, null, ALERT_TYPE.ALERT_SYSTEM_OFF.simpleDesc(), ALERT_TYPE.ALERT_SYSTEM_OFF);
ALERT_TYPE type = entity.getAlertType();
logger.info("type.getAlertPolicy() & EMAIL_DBA: {}", type.getAlertPolicy() & EMAIL_DBA);
logger.info("type.getAlertPolicy() & EMAIL_XPIPE_ADMIN: {}", type.getAlertPolicy() & EMAIL_XPIPE_ADMIN);
logger.info("type.getAlertPolicy() & EMAIL_CLUSTER_ADMIN: {}", type.getAlertPolicy() & EMAIL_CLUSTER_ADMIN);
List<String> recievers = policyManager.queryRecepients(entity);
logger.info("recievers: {}", recievers);
StringBuffer sb = new StringBuffer();
for (String emailAdr : recievers) {
sb.append(emailAdr).append(",");
}
sb.deleteCharAt(sb.length() - 1);
Assert.assertEquals(sb.toString(), consoleConfig.getDBAEmails() + "," + consoleConfig.getXPipeAdminEmails());
}
use of com.ctrip.xpipe.redis.console.alert.ALERT_TYPE in project x-pipe by ctripcorp.
the class SenderManagerTest method sendAlerts.
@Test
public void sendAlerts() throws Exception {
HostPort hostPort = new HostPort("192.168.1.10", 6379);
Map<ALERT_TYPE, Set<AlertEntity>> alerts = new HashMap<>();
alerts.put(ALERT_TYPE.CLIENT_INCONSIS, Collections.singleton(new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.CLIENT_INCONSIS)));
alerts.put(ALERT_TYPE.XREDIS_VERSION_NOT_VALID, Collections.singleton(new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.XREDIS_VERSION_NOT_VALID)));
alerts.put(ALERT_TYPE.QUORUM_DOWN_FAIL, Collections.singleton(new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.QUORUM_DOWN_FAIL)));
alerts.put(ALERT_TYPE.SENTINEL_RESET, Collections.singleton(new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.SENTINEL_RESET)));
alerts.put(ALERT_TYPE.REDIS_CONF_REWRITE_FAILURE, Collections.singleton(new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.REDIS_CONF_REWRITE_FAILURE)));
alerts.put(ALERT_TYPE.REDIS_REPL_DISKLESS_SYNC_ERROR, Collections.singleton(new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.REDIS_REPL_DISKLESS_SYNC_ERROR)));
alerts.put(ALERT_TYPE.MIGRATION_MANY_UNFINISHED, Collections.singleton(new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.MIGRATION_MANY_UNFINISHED)));
logger.info("{}", alerts);
senderManager.sendAlerts(alerts);
}
use of com.ctrip.xpipe.redis.console.alert.ALERT_TYPE in project x-pipe by ctripcorp.
the class SenderManagerTest method testSenderManager.
@Test
public void testSenderManager() {
HostPort hostPort = new HostPort("192.168.1.10", 6379);
Map<ALERT_TYPE, Set<AlertEntity>> alerts = new ConcurrentHashMap<>();
AlertEntity alert = new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.XREDIS_VERSION_NOT_VALID);
Set<AlertEntity> set = new ConcurrentSet<>();
set.add(alert);
alerts.put(ALERT_TYPE.XREDIS_VERSION_NOT_VALID, set);
new Thread(new Runnable() {
@Override
public void run() {
alerts.get(ALERT_TYPE.XREDIS_VERSION_NOT_VALID).remove(alert);
}
}).start();
List<Map<ALERT_TYPE, Set<AlertEntity>>> result = senderManager.getGroupedAlerts(alerts);
logger.info("result: {}", result.get(0));
if (!result.isEmpty()) {
Set<AlertEntity> alertEntities = result.get(0).getOrDefault(alert.getAlertType(), null);
if (alertEntities != null) {
Assert.assertFalse(alertEntities.isEmpty());
}
}
}
use of com.ctrip.xpipe.redis.console.alert.ALERT_TYPE in project x-pipe by ctripcorp.
the class ScheduledAlertMessageDecoratorTest method generateBody.
@Test
public void generateBody() throws Exception {
HostPort hostPort = new HostPort("192.168.1.10", 6379);
Map<ALERT_TYPE, Set<AlertEntity>> alerts = new HashMap<>();
alerts.put(ALERT_TYPE.CLIENT_INCONSIS, Collections.singleton(new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.CLIENT_INCONSIS)));
alerts.put(ALERT_TYPE.XREDIS_VERSION_NOT_VALID, Collections.singleton(new AlertEntity(hostPort, dcNames[0], "cluster-test", "shard-test", "", ALERT_TYPE.XREDIS_VERSION_NOT_VALID)));
String body = decorator.generateBody(alerts);
logger.info("{}", body);
}
Aggregations