Search in sources :

Example 1 with NotifyStrategy

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);
    }
}
Also used : NotifyStrategy(com.creditease.uav.feature.runtimenotify.NotifyStrategy) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with NotifyStrategy

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();
    }
}
Also used : NotifyStrategy(com.creditease.uav.feature.runtimenotify.NotifyStrategy)

Example 3 with NotifyStrategy

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));
    }
}
Also used : JudgeNotifyTimerTask(com.creditease.uav.feature.runtimenotify.task.JudgeNotifyTimerTask) NotifyStrategy(com.creditease.uav.feature.runtimenotify.NotifyStrategy) HashSet(java.util.HashSet) I1NQueueWorker(com.creditease.agent.spi.I1NQueueWorker)

Example 4 with NotifyStrategy

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);
    }
}
Also used : RuntimeNotifyStrategyMgr(com.creditease.uav.feature.runtimenotify.scheduler.RuntimeNotifyStrategyMgr) StrategyJudgement(com.creditease.uav.feature.runtimenotify.StrategyJudgement) NotifyStrategy(com.creditease.uav.feature.runtimenotify.NotifyStrategy) NotificationEvent(com.creditease.agent.monitor.api.NotificationEvent) Slice(com.creditease.uav.feature.runtimenotify.Slice) CacheManager(com.creditease.uav.cache.api.CacheManager) RuntimeNotifySliceMgr(com.creditease.uav.feature.runtimenotify.RuntimeNotifySliceMgr)

Example 5 with NotifyStrategy

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);
    }
}
Also used : HashMap(java.util.HashMap) NotifyStrategy(com.creditease.uav.feature.runtimenotify.NotifyStrategy) NotificationEvent(com.creditease.agent.monitor.api.NotificationEvent) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date)

Aggregations

NotifyStrategy (com.creditease.uav.feature.runtimenotify.NotifyStrategy)5 NotificationEvent (com.creditease.agent.monitor.api.NotificationEvent)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 I1NQueueWorker (com.creditease.agent.spi.I1NQueueWorker)1 CacheManager (com.creditease.uav.cache.api.CacheManager)1 RuntimeNotifySliceMgr (com.creditease.uav.feature.runtimenotify.RuntimeNotifySliceMgr)1 Slice (com.creditease.uav.feature.runtimenotify.Slice)1 StrategyJudgement (com.creditease.uav.feature.runtimenotify.StrategyJudgement)1 RuntimeNotifyStrategyMgr (com.creditease.uav.feature.runtimenotify.scheduler.RuntimeNotifyStrategyMgr)1 JudgeNotifyTimerTask (com.creditease.uav.feature.runtimenotify.task.JudgeNotifyTimerTask)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1