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