Search in sources :

Example 1 with ALERT_TYPE

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;
}
Also used : AlertEntity(com.ctrip.xpipe.redis.console.alert.AlertEntity) ALERT_TYPE(com.ctrip.xpipe.redis.console.alert.ALERT_TYPE)

Example 2 with ALERT_TYPE

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());
}
Also used : AlertEntity(com.ctrip.xpipe.redis.console.alert.AlertEntity) ALERT_TYPE(com.ctrip.xpipe.redis.console.alert.ALERT_TYPE) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 3 with ALERT_TYPE

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);
}
Also used : ConcurrentSet(io.netty.util.internal.ConcurrentSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HostPort(com.ctrip.xpipe.endpoint.HostPort) AlertEntity(com.ctrip.xpipe.redis.console.alert.AlertEntity) ALERT_TYPE(com.ctrip.xpipe.redis.console.alert.ALERT_TYPE) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 4 with ALERT_TYPE

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());
        }
    }
}
Also used : ConcurrentSet(io.netty.util.internal.ConcurrentSet) ConcurrentSet(io.netty.util.internal.ConcurrentSet) HostPort(com.ctrip.xpipe.endpoint.HostPort) AlertEntity(com.ctrip.xpipe.redis.console.alert.AlertEntity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ALERT_TYPE(com.ctrip.xpipe.redis.console.alert.ALERT_TYPE) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Example 5 with ALERT_TYPE

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);
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) HostPort(com.ctrip.xpipe.endpoint.HostPort) AlertEntity(com.ctrip.xpipe.redis.console.alert.AlertEntity) ALERT_TYPE(com.ctrip.xpipe.redis.console.alert.ALERT_TYPE) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test)

Aggregations

ALERT_TYPE (com.ctrip.xpipe.redis.console.alert.ALERT_TYPE)6 AlertEntity (com.ctrip.xpipe.redis.console.alert.AlertEntity)5 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)4 Test (org.junit.Test)4 HostPort (com.ctrip.xpipe.endpoint.HostPort)3 ConcurrentSet (io.netty.util.internal.ConcurrentSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 HashMap (java.util.HashMap)1 Set (java.util.Set)1 VelocityContext (org.apache.velocity.VelocityContext)1