use of com.creditease.uav.feature.runtimenotify.NotifyStrategy in project uavstack by uavorg.
the class RuntimeNotifyStrategyMgr method loadStrategy.
/**
* only for development load from local configuration file
*
* @param json
*/
@SuppressWarnings("unchecked")
public void loadStrategy(String json) {
Map<String, Object> stras = JSONHelper.toObject(json, Map.class);
for (Entry<String, Object> entry : stras.entrySet()) {
String key = entry.getKey();
Map<String, Object> m = (Map<String, Object>) entry.getValue();
NotifyStrategy stra = NotifyStrategy.parse(key, JSONHelper.toString(m));
if (log.isDebugEnable()) {
log.debug(this, "Parse NotifyStrategy: " + JSONHelper.toString(stra));
}
if ("I".equals(stra.getScope()) && !stra.getInstances().isEmpty()) {
// deal with multi instances
putMultiInstStrategy(key, stra);
continue;
}
putStrategy(key, stra);
}
}
use of com.creditease.uav.feature.runtimenotify.NotifyStrategy in project uavstack by uavorg.
the class RuntimeNotifyStrategyMgr method run.
/**
* to sync the strategy setting from cache
*/
@Override
public void run() {
Map<String, String> strategyMap = cm.getHashAll(UAV_CACHE_REGION, RT_STRATEGY_KEY);
if (null == strategyMap || strategyMap.isEmpty()) {
return;
}
try {
strategyLock.lockInterruptibly();
fScope.clear();
mScope.clear();
iScope.clear();
multiInsts.clear();
strategies.clear();
for (String key : strategyMap.keySet()) {
String json = strategyMap.get(key);
NotifyStrategy stra = NotifyStrategy.parse(key, json);
if (log.isDebugEnable()) {
log.debug(this, "Parse NotifyStrategy: " + JSONHelper.toString(stra));
}
if ("I".equals(stra.getScope()) && !stra.getInstances().isEmpty()) {
// deal with multi instances
putMultiInstStrategy(key, stra);
continue;
}
putStrategy(key, stra);
}
} catch (InterruptedException e) {
// ignore
} finally {
strategyLock.unlock();
}
}
use of com.creditease.uav.feature.runtimenotify.NotifyStrategy in project uavstack by uavorg.
the class TimerNotifyWorker method run.
@Override
public void run() {
RuntimeNotifyStrategyMgr strategyMgr = (RuntimeNotifyStrategyMgr) getConfigManager().getComponent(this.feature, "RuntimeNotifyStrategyMgr");
HashSet<NotifyStrategy> strategies = new HashSet<NotifyStrategy>(strategyMgr.getStrategies());
for (NotifyStrategy stra : strategies) {
if (stra.getType() != NotifyStrategy.Type.TIMER) {
continue;
}
I1NQueueWorker n1nqw = get1NQueueWorkerMgr().getQueueWorker(this.feature, RuntimeNotifyCatcher.QWORKER_NAME);
n1nqw.put(new JudgeNotifyTimerTask(JudgeNotifyTask.class.getSimpleName(), feature, System.currentTimeMillis(), stra));
}
}
use of com.creditease.uav.feature.runtimenotify.NotifyStrategy in project uavstack by uavorg.
the class JudgeNotifyTask method run.
@Override
public void run() {
NotifyStrategy stra = null;
try {
/**
* Step 1: seek strategy
*/
RuntimeNotifyStrategyMgr strategyMgr = (RuntimeNotifyStrategyMgr) getConfigManager().getComponent(this.feature, "RuntimeNotifyStrategyMgr");
stra = strategyMgr.seekStrategy(curSlice.getKey());
if (stra == null) {
return;
}
/**
* Step 1.5: underclocking
*/
long range = stra.getMaxRange();
if (range > 0) {
CacheManager cm = (CacheManager) getConfigManager().getComponent(this.feature, STORAGE_CACHE_MANAGER_NAME);
String judgedKey = genJudgedKey(curSlice);
if (cm.exists(UAV_CACHE_REGION, judgedKey)) {
return;
} else {
cm.put(UAV_CACHE_REGION, judgedKey, String.valueOf(curSlice.getTime()));
cm.expire(UAV_CACHE_REGION, judgedKey, range, TimeUnit.MILLISECONDS);
}
}
/**
* Step 2: dump range slices
*/
List<Slice> rangeSlices = null;
if (range > 0) {
RuntimeNotifySliceMgr sliceMgr = (RuntimeNotifySliceMgr) getConfigManager().getComponent(this.feature, "RuntimeNotifySliceMgr");
rangeSlices = sliceMgr.getSlices(curSlice, range);
if (rangeSlices.isEmpty()) {
if (log.isDebugEnable()) {
log.debug(this, "RuntimeNotify judge dump invalid.");
}
return;
}
} else {
rangeSlices = new ArrayList<>(1);
rangeSlices.add(curSlice);
}
/**
* Step 3: judge the strategy
*/
StrategyJudgement judgement = (StrategyJudgement) getConfigManager().getComponent(feature, "StrategyJudgement");
Map<String, String> result = judgement.judge(curSlice, stra, rangeSlices);
// ?? maybe no effective
if (rangeSlices != null) {
rangeSlices.clear();
rangeSlices = null;
}
/**
* Step 5: if fire the event, build notification event
*/
if (result != null && !result.isEmpty()) {
NotificationEvent event = this.newNotificationEvent(result, stra.getConvergences());
// get context
putContext(event);
// get action
putNotifyAction(event, stra);
// get msg tempalte
putNotifyMsg(event, stra);
if (this.log.isTraceEnable()) {
this.log.info(this, "RuntimeNotify Notification Event Happen: event=" + event.toJSONString());
}
this.putNotificationEvent(event);
}
} catch (Exception e) {
log.err(this, "JudgeNotifyTask RUN FAIL.", e);
}
if (log.isDebugEnable()) {
long cost = System.currentTimeMillis() - taskStart;
String detail = cost < 10 ? "" : " detail: key=" + curSlice.getKey() + ", strategy=" + JSONHelper.toString(stra);
log.debug(this, "whole task lifecycle COST: (" + cost + ")ms" + detail);
}
}
use of com.creditease.uav.feature.runtimenotify.NotifyStrategy in project uavstack by uavorg.
the class NodeInfoWatcher method fireEvent.
/**
* 触发预警事件
*/
private void fireEvent(Map<String, Map<String, String>> deadProcs) {
/**
* Step 1: split crash event by IP
*/
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Map<String, CrashEventObj> ips = new HashMap<String, CrashEventObj>();
for (Entry<String, Map<String, String>> en : deadProcs.entrySet()) {
String procKey = en.getKey();
String[] procInfo = procKey.split("_", -1);
String ip = procInfo[0];
String procName = procInfo[1];
String deadtime = en.getValue().get("deadtime");
String appgroup = en.getValue().get("appgroup");
CrashEventObj ceo;
if (!ips.containsKey(ip)) {
ceo = new CrashEventObj(ip, appgroup);
ips.put(ip, ceo);
} else {
ceo = ips.get(ip);
}
ceo.increDeadProcsCount();
ceo.addDeadProcName(procName);
ceo.addDeadProcInfo("触发时间:" + format.format(new Date(Long.parseLong(deadtime))) + ", 进程信息:" + procKey);
}
/**
* Step 2: send notification event by IP
*/
RuntimeNotifyStrategyMgr strategyMgr = (RuntimeNotifyStrategyMgr) getConfigManager().getComponent(this.feature, "RuntimeNotifyStrategyMgr");
for (CrashEventObj ceo : ips.values()) {
String title = "应用组[" + ceo.getAppGroup() + "]的" + ceo.getIp() + "共发现" + ceo.getDeadProcsCount() + "进程" + ceo.getDeadProcNamesAsString() + "可疑死掉";
String description = ceo.getDeadProcsInfoAsString();
NotificationEvent event = new NotificationEvent(NotificationEvent.EVENT_RT_ALERT_CRASH, title, description, System.currentTimeMillis(), ceo.getIp(), "");
/**
* Notification Manager will not block the event, the frozen time has no effect to this event
*/
event.addArg(NotificationEvent.EVENT_Tag_NoBlock, "true");
// add appgroup
event.addArg("appgroup", ceo.getAppGroup());
NotifyStrategy stra = strategyMgr.seekStrategy("server@procCrash@" + ceo.getIp());
if (null != stra) {
putNotifyAction(event, stra);
}
if (log.isTraceEnable()) {
log.info(this, "NodeInfoWatcher Crash Event Happen: event=" + event.toJSONString());
}
this.putNotificationEvent(event);
}
}
Aggregations