Search in sources :

Example 1 with AlertEntity

use of com.ctrip.xpipe.redis.console.alert.AlertEntity 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 AlertEntity

use of com.ctrip.xpipe.redis.console.alert.AlertEntity 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 AlertEntity

use of com.ctrip.xpipe.redis.console.alert.AlertEntity in project x-pipe by ctripcorp.

the class NotificationManagerTest method isSuspend.

@Test
@DirtiesContext
public void isSuspend() throws Exception {
    AlertEntity alert = new AlertEntity(hostPort, dcNames[0], cluster, shard, message, ALERT_TYPE.CLIENT_INCONSIS);
    notificationManager.addAlert(cluster, dcNames[0], shard, hostPort, ALERT_TYPE.CLIENT_INCONSIS, message);
    Thread.sleep(1000);
    Assert.assertTrue(notificationManager.isSuspend(alert.getKey(), 1000));
}
Also used : AlertEntity(com.ctrip.xpipe.redis.console.alert.AlertEntity) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 4 with AlertEntity

use of com.ctrip.xpipe.redis.console.alert.AlertEntity in project x-pipe by ctripcorp.

the class NotificationManagerTest method sendRecoveryMessage.

@Test
@DirtiesContext
public void sendRecoveryMessage() throws Exception {
    AlertEntity alert = new AlertEntity(hostPort, dcNames[0], cluster, shard, message, ALERT_TYPE.CLIENT_INCONSIS);
    Assert.assertTrue(notificationManager.sendRecoveryMessage(alert));
    alert = new AlertEntity(hostPort, dcNames[0], cluster, shard, message, ALERT_TYPE.MARK_INSTANCE_DOWN);
    notificationManager.sendRecoveryMessage(alert);
}
Also used : AlertEntity(com.ctrip.xpipe.redis.console.alert.AlertEntity) AbstractConsoleIntegrationTest(com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 5 with AlertEntity

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

Aggregations

AlertEntity (com.ctrip.xpipe.redis.console.alert.AlertEntity)10 AbstractConsoleIntegrationTest (com.ctrip.xpipe.redis.console.AbstractConsoleIntegrationTest)8 Test (org.junit.Test)8 ALERT_TYPE (com.ctrip.xpipe.redis.console.alert.ALERT_TYPE)5 HostPort (com.ctrip.xpipe.endpoint.HostPort)3 DirtiesContext (org.springframework.test.annotation.DirtiesContext)3 ConcurrentSet (io.netty.util.internal.ConcurrentSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AlertPolicy (com.ctrip.xpipe.redis.console.alert.policy.AlertPolicy)1 SendToDBAAlertPolicy (com.ctrip.xpipe.redis.console.alert.policy.SendToDBAAlertPolicy)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1