Search in sources :

Example 1 with Slice

use of com.creditease.uav.feature.runtimenotify.Slice 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 2 with Slice

use of com.creditease.uav.feature.runtimenotify.Slice in project uavstack by uavorg.

the class HealthManagerClient method loadSlices.

private static void loadSlices(String ip, long range, String key) {
    CacheManager cm = getCM(ip);
    StringBuilder sb = new StringBuilder();
    long end = System.currentTimeMillis();
    long start = end - range * 1000;
    int cacheLen = cm.llen("store.region.uav", key);
    sb.append("range:" + range + "\n\r");
    sb.append("key:" + key + "\n\r");
    sb.append("len:" + cacheLen + "\n\r");
    List<Slice> list = new ArrayList<>();
    for (int index = cacheLen - 1; index > 0; index--) {
        String sj = cm.lindex("store.region.uav", key, index);
        Slice r = new Slice(sj);
        if (r.getTime() <= end && r.getTime() >= start) {
            list.add(r);
            continue;
        }
        if (r.getTime() < start) {
            break;
        }
    }
    Collections.reverse(list);
    sb.append("sellen:" + list.size() + "\n\r");
    for (Slice slice : list) {
        sb.append(JSONHelper.toString(slice) + "\n\r");
    }
    try {
        IOHelper.writeTxtFile(IOHelper.getCurrentPath() + "/rtslice_cache.txt", sb.toString(), "utf-8", false);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Slice(com.creditease.uav.feature.runtimenotify.Slice) ArrayList(java.util.ArrayList) CacheManager(com.creditease.uav.cache.api.CacheManager) IOException(java.io.IOException)

Example 3 with Slice

use of com.creditease.uav.feature.runtimenotify.Slice in project uavstack by uavorg.

the class RuntimeNotifyCatcher method pushToSliceQueue.

private void pushToSliceQueue(MonitorDataFrame mdf, boolean needConcurrent) {
    long now = System.currentTimeMillis();
    if (now - mdf.getTimeFlag() > DROP_TIMEOUT) {
        if (log.isDebugEnable()) {
            log.debug(this, "MDF too late, drop it: " + mdf.toJSONString());
        }
        return;
    }
    // step 1: store slices
    List<Slice> slices = extractSlice(mdf);
    RuntimeNotifySliceMgr rnsm = (RuntimeNotifySliceMgr) ConfigurationManager.getInstance().getComponent(this.feature, "RuntimeNotifySliceMgr");
    rnsm.storeSlices(slices, mdf.getTag());
    if (log.isDebugEnable()) {
        log.debug(this, "Prepare Slices for Judge: count= " + slices.size());
    }
    // step 2: notification judge
    if (needConcurrent == false) {
        // one thread judge
        for (Slice slice : slices) {
            new JudgeNotifyTask(JudgeNotifyTask.class.getSimpleName(), "runtimenotify", slice).run();
        }
    } else {
        // 1+N Queue Judge
        I1NQueueWorker n1nqw = get1NQueueWorkerMgr().getQueueWorker(this.feature, RuntimeNotifyCatcher.QWORKER_NAME);
        for (Slice slice : slices) {
            n1nqw.put(new JudgeNotifyTask(JudgeNotifyTask.class.getSimpleName(), feature, slice));
        }
    }
}
Also used : Slice(com.creditease.uav.feature.runtimenotify.Slice) JudgeNotifyTask(com.creditease.uav.feature.runtimenotify.task.JudgeNotifyTask) RuntimeNotifySliceMgr(com.creditease.uav.feature.runtimenotify.RuntimeNotifySliceMgr) I1NQueueWorker(com.creditease.agent.spi.I1NQueueWorker)

Example 4 with Slice

use of com.creditease.uav.feature.runtimenotify.Slice in project uavstack by uavorg.

the class RuntimeNotifyCatcher method extractSlice.

/**
 * extractSlice
 *
 * @param mdf
 * @return
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private List<Slice> extractSlice(MonitorDataFrame mdf) {
    List<Slice> list = new ArrayList<>();
    Map<String, List<Map>> frames = mdf.getDatas();
    String appgroup = mdf.getExt("appgroup");
    for (Map.Entry<String, List<Map>> frame : frames.entrySet()) {
        List<Map> servers = frame.getValue();
        for (Map server : servers) {
            String meId = (String) server.get("MEId");
            List<Map> instances = (List<Map>) server.get("Instances");
            for (Map ins : instances) {
                String id = (String) ins.get("id");
                Map values = (Map) ins.get("values");
                values.put("ip", mdf.getIP());
                values.put("host", mdf.getHost());
                values.put("appgroup", appgroup);
                String key = frame.getKey() + RuntimeNotifyCatcher.STRATEGY_SEPARATOR + meId + RuntimeNotifyCatcher.STRATEGY_SEPARATOR + id;
                Slice slice = new Slice(key, mdf.getTimeFlag());
                slice.setArgs(values);
                slice.setMdf(mdf);
                list.add(slice);
            }
        }
    }
    if (log.isDebugEnable()) {
        log.debug(this, "RuntimeNotify Extract Slices: slices size=" + list.size());
    }
    return list;
}
Also used : Slice(com.creditease.uav.feature.runtimenotify.Slice) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 5 with Slice

use of com.creditease.uav.feature.runtimenotify.Slice in project uavstack by uavorg.

the class JudgeNotifyTimerTask method run.

@Override
public void run() {
    CacheLock lock = null;
    try {
        lock = cm.newCacheLock(LOCK_REGION, stra.getName(), LOCK_TIMEOUT);
        if (!lock.getLock()) {
            return;
        }
        /**
         * Step 1:find out instance
         */
        for (String instance : stra.getInstances()) {
            /**
             * Step 2: judge the strategy
             */
            StrategyJudgement judgement = (StrategyJudgement) getConfigManager().getComponent(feature, "StrategyJudgement");
            Map<String, String> result = judgement.judge(new Slice(instance, judge_time), stra, null);
            /**
             * Step 3: if fire the event, build notification event
             */
            if (result != null && !result.isEmpty()) {
                NotificationEvent event = this.newNotificationEvent(instance, 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, "JudgeNotifyTimerTask" + stra.getName() + " RUN FAIL.", e);
    } finally {
        if (lock != null && lock.isLockInHand()) {
            lock.releaseLock();
        }
    }
    if (log.isDebugEnable()) {
        long cost = System.currentTimeMillis() - taskStart;
        String detail = cost < 10 ? "" : " detail:strategy=" + JSONHelper.toString(stra);
        log.debug(this, "whole task lifecycle COST: (" + cost + ")ms" + detail);
    }
}
Also used : CacheLock(com.creditease.uav.cache.api.CacheManager.CacheLock) StrategyJudgement(com.creditease.uav.feature.runtimenotify.StrategyJudgement) Slice(com.creditease.uav.feature.runtimenotify.Slice) NotificationEvent(com.creditease.agent.monitor.api.NotificationEvent)

Aggregations

Slice (com.creditease.uav.feature.runtimenotify.Slice)6 ArrayList (java.util.ArrayList)3 NotificationEvent (com.creditease.agent.monitor.api.NotificationEvent)2 CacheManager (com.creditease.uav.cache.api.CacheManager)2 RuntimeNotifySliceMgr (com.creditease.uav.feature.runtimenotify.RuntimeNotifySliceMgr)2 StrategyJudgement (com.creditease.uav.feature.runtimenotify.StrategyJudgement)2 I1NQueueWorker (com.creditease.agent.spi.I1NQueueWorker)1 CacheLock (com.creditease.uav.cache.api.CacheManager.CacheLock)1 NotifyStrategy (com.creditease.uav.feature.runtimenotify.NotifyStrategy)1 RuntimeNotifyStrategyMgr (com.creditease.uav.feature.runtimenotify.scheduler.RuntimeNotifyStrategyMgr)1 JudgeNotifyTask (com.creditease.uav.feature.runtimenotify.task.JudgeNotifyTask)1 IOException (java.io.IOException)1 List (java.util.List)1 Map (java.util.Map)1