Search in sources :

Example 11 with AlarmRule

use of com.alibaba.otter.shared.common.model.config.alarm.AlarmRule in project otter by alibaba.

the class GlobalMonitorTest method testConcurrentProcessWithException.

@Test
public void testConcurrentProcessWithException() {
    new NonStrictExpectations() {

        {
            alarmRuleService.getAlarmRules(AlarmRuleStatus.ENABLE);
            Map<Long, List<AlarmRule>> allRules = new HashMap<Long, List<AlarmRule>>();
            for (long i = 0; i < 10; i++) {
                List<AlarmRule> rules = new ArrayList<AlarmRule>();
                for (int j = 0; j < 5; j++) {
                    rules.add(new AlarmRule());
                }
                allRules.put(i + 1, rules);
            }
            returns(allRules);
        }
    };
    globalMonitor.setNeedConcurrent(true);
    globalMonitor.setPipelineMonitor(exceptionPipelineMonitor);
    try {
        globalMonitor.explore();
    } catch (Exception e) {
        return;
    }
    throw new IllegalStateException("unreached code");
}
Also used : HashMap(java.util.HashMap) AlarmRule(com.alibaba.otter.shared.common.model.config.alarm.AlarmRule) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.testng.annotations.Test) BaseOtterTest(com.alibaba.otter.manager.biz.BaseOtterTest)

Example 12 with AlarmRule

use of com.alibaba.otter.shared.common.model.config.alarm.AlarmRule in project otter by alibaba.

the class AlarmRuleServiceImpl method getAlarmRules.

public Map<Long, List<AlarmRule>> getAlarmRules(AlarmRuleStatus status) {
    Assert.assertNotNull(status);
    List<AlarmRule> alarmRules = getAllAlarmRules(status);
    Map<Long, List<AlarmRule>> result = new HashMap<Long, List<AlarmRule>>();
    for (AlarmRule alarmRule : alarmRules) {
        List<AlarmRule> rules = result.get(alarmRule.getPipelineId());
        if (rules == null) {
            rules = new ArrayList<AlarmRule>();
        }
        if (!rules.contains(alarmRule)) {
            rules.add(alarmRule);
        }
        result.put(alarmRule.getPipelineId(), rules);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) AlarmRule(com.alibaba.otter.shared.common.model.config.alarm.AlarmRule) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with AlarmRule

use of com.alibaba.otter.shared.common.model.config.alarm.AlarmRule in project otter by alibaba.

the class AlarmRuleServiceImpl method doToModel.

private AlarmRule doToModel(AlarmRuleDO alarmRuleDo) {
    AlarmRule alarmRule = new AlarmRule();
    alarmRule.setId(alarmRuleDo.getId());
    alarmRule.setMatchValue(alarmRuleDo.getMatchValue());
    alarmRule.setMonitorName(alarmRuleDo.getMonitorName());
    alarmRule.setReceiverKey(alarmRuleDo.getReceiverKey());
    // 如果数据库里面的数据为空,则返回默认值
    alarmRule.setIntervalTime(alarmRuleDo.getAlarmRuleParameter() == null ? 1800L : alarmRuleDo.getAlarmRuleParameter().getIntervalTime());
    String pauseTime = alarmRuleDo.getAlarmRuleParameter() == null ? null : alarmRuleDo.getAlarmRuleParameter().getPauseTime();
    if (StringUtils.isNotEmpty(pauseTime)) {
        SimpleDateFormat format = new SimpleDateFormat(TIMESTAMP_FORMAT);
        try {
            alarmRule.setPauseTime(format.parse(pauseTime));
        } catch (ParseException e) {
            throw new ManagerException(e);
        }
    }
    alarmRule.setAutoRecovery(alarmRuleDo.getAlarmRuleParameter() == null ? false : alarmRuleDo.getAlarmRuleParameter().getAutoRecovery());
    alarmRule.setRecoveryThresold(alarmRuleDo.getAlarmRuleParameter() == null ? 3 : alarmRuleDo.getAlarmRuleParameter().getRecoveryThresold());
    alarmRule.setPipelineId(alarmRuleDo.getPipelineId());
    alarmRule.setStatus(alarmRuleDo.getStatus());
    alarmRule.setDescription(alarmRuleDo.getDescription());
    alarmRule.setGmtCreate(alarmRuleDo.getGmtCreate());
    alarmRule.setGmtModified(alarmRuleDo.getGmtModified());
    return alarmRule;
}
Also used : AlarmRule(com.alibaba.otter.shared.common.model.config.alarm.AlarmRule) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException)

Example 14 with AlarmRule

use of com.alibaba.otter.shared.common.model.config.alarm.AlarmRule in project otter by alibaba.

the class GlobalMonitor method concurrentProcess.

private void concurrentProcess(Map<Long, List<AlarmRule>> rules) {
    ExecutorCompletionService completionExecutor = new ExecutorCompletionService(executor);
    List<Future> futures = new ArrayList<Future>();
    for (Entry<Long, List<AlarmRule>> entry : rules.entrySet()) {
        final List<AlarmRule> alarmRules = entry.getValue();
        futures.add(completionExecutor.submit(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                pipelineMonitor.explore(alarmRules);
                return null;
            }
        }));
    }
    List<Throwable> exceptions = new ArrayList<Throwable>();
    int index = 0;
    int size = futures.size();
    while (index < size) {
        try {
            Future<?> future = completionExecutor.take();
            future.get();
        } catch (InterruptedException e) {
            exceptions.add(e);
        } catch (ExecutionException e) {
            exceptions.add(e);
        }
        index++;
    }
    if (!exceptions.isEmpty()) {
        StringBuilder sb = new StringBuilder(exceptions.size() + " exception happens in global monitor\n");
        sb.append("exception stack start :\n");
        for (Throwable t : exceptions) {
            sb.append(ExceptionUtils.getStackTrace(t));
        }
        sb.append("exception stack end \n");
        throw new IllegalStateException(sb.toString());
    }
}
Also used : AlarmRule(com.alibaba.otter.shared.common.model.config.alarm.AlarmRule) ArrayList(java.util.ArrayList) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) Callable(java.util.concurrent.Callable) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException)

Example 15 with AlarmRule

use of com.alibaba.otter.shared.common.model.config.alarm.AlarmRule in project otter by alibaba.

the class GlobalMonitorTest method testConcurrentProcess.

@Test
public void testConcurrentProcess() {
    new NonStrictExpectations() {

        {
            alarmRuleService.getAlarmRules(AlarmRuleStatus.ENABLE);
            Map<Long, List<AlarmRule>> allRules = new HashMap<Long, List<AlarmRule>>();
            for (long i = 0; i < 10; i++) {
                List<AlarmRule> rules = new ArrayList<AlarmRule>();
                for (int j = 0; j < 5; j++) {
                    rules.add(new AlarmRule());
                }
                allRules.put(i + 1, rules);
            }
            returns(allRules);
        }
    };
    globalMonitor.setNeedConcurrent(true);
    globalMonitor.setPipelineMonitor(normalPipelineMonitor);
    globalMonitor.explore();
}
Also used : HashMap(java.util.HashMap) AlarmRule(com.alibaba.otter.shared.common.model.config.alarm.AlarmRule) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.testng.annotations.Test) BaseOtterTest(com.alibaba.otter.manager.biz.BaseOtterTest)

Aggregations

AlarmRule (com.alibaba.otter.shared.common.model.config.alarm.AlarmRule)21 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)7 Date (java.util.Date)6 List (java.util.List)6 BaseOtterTest (com.alibaba.otter.manager.biz.BaseOtterTest)4 Test (org.testng.annotations.Test)4 RepeatConfigureException (com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)3 Pipeline (com.alibaba.otter.shared.common.model.config.pipeline.Pipeline)3 ThroughputCondition (com.alibaba.otter.manager.biz.statistics.throughput.param.ThroughputCondition)2 PositionEventData (com.alibaba.otter.shared.arbitrate.model.PositionEventData)2 Channel (com.alibaba.otter.shared.common.model.config.channel.Channel)2 DelayStat (com.alibaba.otter.shared.common.model.statistics.delay.DelayStat)2 ThroughputStat (com.alibaba.otter.shared.common.model.statistics.throughput.ThroughputStat)2 NodeAlarmEvent (com.alibaba.otter.shared.communication.model.arbitrate.NodeAlarmEvent)2 Paginator (com.alibaba.citrus.util.Paginator)1 WebxException (com.alibaba.citrus.webx.WebxException)1 ManagerException (com.alibaba.otter.manager.biz.common.exceptions.ManagerException)1 MainStemEventData (com.alibaba.otter.shared.arbitrate.model.MainStemEventData)1 ChannelStatus (com.alibaba.otter.shared.common.model.config.channel.ChannelStatus)1