Search in sources :

Example 1 with I1NQueueWorker

use of com.creditease.agent.spi.I1NQueueWorker in project uavstack by uavorg.

the class UpgradeDownloadRequestHandler method handle.

@Override
public void handle(UpgradeHttpMessage message) {
    HttpMessage httpMsg = (HttpMessage) message.getObjectParam("message");
    // Package downloading is time-consuming task, so use 1+n queue to execute it.
    I1NQueueWorker queueWorker = this.get1NQueueWorkerMgr().getQueueWorker(this.feature, UpgradeConstants.UPGRADE_1N_QUEUE_NAME);
    if (queueWorker == null) {
        if (log.isTraceEnable()) {
            log.warn(this, "Download 1N queue does not exit, so ignore this download request");
        }
        httpMsg.putResponseBodyInString("Internal error: 1N queue worker doese not exist", 500, "UTF-8");
        return;
    }
    String baseDir = this.getConfigManager().getFeatureConfiguration(feature, "download.dir");
    String target = httpMsg.getParameter(UpgradeConstants.DOWNLOAD_REQUEST_PARAM_KEY);
    String software = httpMsg.getParameter(UpgradeConstants.DOWNLOAD_TARGET_SOFTWARE);
    if ("list".equalsIgnoreCase(target)) {
        // get the list of upgrade package
        handleListFileRequest(baseDir, software, httpMsg);
        return;
    } else if ("listdir".equalsIgnoreCase(target)) {
        handleListDirRequest(baseDir, httpMsg);
        return;
    }
    int downloadThreshold = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "download.threshold"), 10);
    synchronized (this) {
        if (log.isTraceEnable()) {
            log.info(this, "Current download 1+N worker has " + queueWorker.getActiveCount() + " working tasks");
        }
        if (queueWorker.getActiveCount() >= downloadThreshold) {
            httpMsg.putResponseBodyInString("Too Many Requests", UpgradeConstants.HTTP_CODE_TOO_MANY_REQUESTS, "UTF-8");
            return;
        }
        Abstract1NTask task = new UpgradeDownloadTask(cName, feature, httpMsg);
        queueWorker.put(task);
    }
}
Also used : Abstract1NTask(com.creditease.agent.spi.Abstract1NTask) HttpMessage(com.creditease.agent.spi.HttpMessage) I1NQueueWorker(com.creditease.agent.spi.I1NQueueWorker)

Example 2 with I1NQueueWorker

use of com.creditease.agent.spi.I1NQueueWorker in project uavstack by uavorg.

the class UpgradeDownloadServer method init1NQueueWorker.

private void init1NQueueWorker() {
    int coreSize = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "1nqworker.coresize"), 10);
    int maxSize = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "1nqworker.maxsize"), 10);
    int bqSize = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "1nqworker.bqsize"), 1);
    int timeout = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "1nqworker.keepalivetimeout"), 60000);
    I1NQueueWorker queueWoker = get1NQueueWorkerMgr().newQueueWorker(UpgradeConstants.UPGRADE_1N_QUEUE_NAME, this.feature, coreSize, maxSize, bqSize, timeout);
    new Thread(queueWoker, UpgradeConstants.UPGRADE_1N_QUEUE_NAME).start();
    if (log.isTraceEnable()) {
        log.info(this, String.format(UpgradeConstants.UPGRADE_1N_QUEUE_NAME + " started: coresize:%d,maxsize:%d,bqsize:%d,keepalivetimeout:%d", coreSize, maxSize, bqSize, timeout));
    }
}
Also used : I1NQueueWorker(com.creditease.agent.spi.I1NQueueWorker)

Example 3 with I1NQueueWorker

use of com.creditease.agent.spi.I1NQueueWorker 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 I1NQueueWorker

use of com.creditease.agent.spi.I1NQueueWorker in project uavstack by uavorg.

the class RuntimeNotifyCatcher method start.

@Override
public void start() {
    // reset aredis bootstrap executor pool size
    AsyncRedisConnection.setBootstrapExecutorPoolSize(getCfgInt("cm.bootstrappoolsize", 10));
    // init cache manager
    String cacheServer = getCfg("cm.server");
    int cmMinSize = getCfgInt("cm.minsize", 5);
    int cmMaxSize = getCfgInt("cm.maxsize", 10);
    int cmQueueSize = getCfgInt("cm.qsize", 5);
    String cmPwd = getCfg("cm.pwd");
    CacheManager cm = CacheManagerFactory.build(cacheServer, cmMinSize, cmMaxSize, cmQueueSize, cmPwd);
    getConfigManager().registerComponent(this.feature, CACHE_MANAGER_NAME, cm);
    if (log.isTraceEnable()) {
        log.info(this, String.format("RuntimeNotifyCatcher-CacheManager INIT: server:%s,minsize:%d,maxsize:%d,qsize:%d", cacheServer, cmMinSize, cmMaxSize, cmQueueSize));
    }
    // init slice storage cm
    String storeCMServer = getCfg("storecm.server");
    int storeCMMinSize = getCfgInt("storecm.minsize", 5);
    int storeCMMaxSize = getCfgInt("storecm.maxsize", 10);
    int storeCMQueueSize = getCfgInt("storecm.qsize", 5);
    String storeCMPwd = getCfg("storecm.pwd");
    CacheManager storeCM = CacheManagerFactory.build(storeCMServer, storeCMMinSize, storeCMMaxSize, storeCMQueueSize, storeCMPwd);
    getConfigManager().registerComponent(this.feature, STORAGE_CACHE_MANAGER_NAME, storeCM);
    if (log.isTraceEnable()) {
        log.info(this, String.format("RuntimeNotifyCatcher-StorageCacheManager INIT: server:%s,minsize:%d,maxsize:%d,qsize:%d", storeCMServer, storeCMMinSize, storeCMMaxSize, storeCMQueueSize));
    }
    new StrategyJudgement("StrategyJudgement", this.feature);
    // init strategyMgr
    String strategy = getCfg("strategy.config");
    RuntimeNotifyStrategyMgr rtNotifyStrategyMgr = new RuntimeNotifyStrategyMgr("RuntimeNotifyStrategyMgr", feature, cm);
    /**
     * NOTE: this setting is only for development testing for production env, the strategy is only read from cache
     */
    if (strategy != null) {
        rtNotifyStrategyMgr.loadStrategy(strategy);
    }
    long strategyPeriod = DataConvertHelper.toLong(this.getConfigManager().getFeatureConfiguration(this.feature, "strategy.interval"), 30000);
    this.getTimerWorkManager().scheduleWork("RuntimeNotifyStrategyMgr", rtNotifyStrategyMgr, 0, strategyPeriod);
    if (log.isTraceEnable()) {
        log.info(this, "RuntimeNotifyCatcher-RuntimeNotifyStrategyMgr started: " + strategy);
    }
    // init SliceMgr
    String sliceConfig = getCfg("slice.config");
    RuntimeNotifySliceMgr sliceMgr = new RuntimeNotifySliceMgr("RuntimeNotifySliceMgr", feature, storeCM);
    sliceMgr.loadSliceConfig(sliceConfig);
    if (log.isTraceEnable()) {
        log.info(this, "RuntimeNotifyCatcher-RuntimeNotifySliceMgr started: " + sliceConfig);
    }
    // init 1+N qworker
    int coreSize = getCfgInt("qworker.coresize", 5);
    int maxSize = getCfgInt("qworker.maxsize", 50);
    int bqSize = getCfgInt("qworker.bqsize", 20);
    int timeout = getCfgInt("qworker.keepalivetimeout", 60000);
    I1NQueueWorker runtimeNotifyJudgeWorker = get1NQueueWorkerMgr().newQueueWorker(QWORKER_NAME, feature, coreSize, maxSize, bqSize, timeout);
    qwThread = new Thread(runtimeNotifyJudgeWorker);
    qwThread.setName("RuntimeNotifyCatcher-I1NQueueWorker-MainThread");
    qwThread.start();
    if (log.isTraceEnable()) {
        log.info(this, String.format("RuntimeNotifyCatcher-I1NQueueWorker[" + QWORKER_NAME + "] started: coresize:%d,maxsize:%d,bqsize:%d,keepalivetimeout:%d", coreSize, maxSize, bqSize, timeout));
    }
    // start runtime notify data consumer
    StandardMessagingBuilder smb = new StandardMessagingBuilder("RTNTFCommonMsgBuilder", this.feature);
    try {
        smb.init("com.creditease.uav.feature.runtimenotify.messaging.handlers");
    } catch (IOException e) {
        log.err(this, "Read msgtype2topic.properties FAILs, RuntimeNotifyCatcher can not START", e);
        return;
    }
    runtimeDataConsumer = smb.buildConsumer(MonitorDataFrame.MessageType.RuntimeNtf.toString());
    if (runtimeDataConsumer != null) {
        runtimeDataConsumer.start();
        this.getConfigManager().registerComponent(this.feature, COMSUMER_RUNTIME, runtimeDataConsumer);
        if (log.isTraceEnable()) {
            log.info(this, "RuntimeNotifyCacher RuntimeConsumer started");
        }
    }
    // init timer worker
    boolean isEnableInfoTimer = DataConvertHelper.toBoolean(this.getCfg("nodeinfotimer.enable"), false);
    if (isEnableInfoTimer == true) {
        int period = getCfgInt("nodeinfotimer.period", 15000);
        getTimerWorkManager().scheduleWorkInPeriod("NodeInfoWatcher", new NodeInfoWatcher("NodeInfoWatcher", feature), 0, period);
        if (log.isTraceEnable()) {
            log.info(this, "RuntimeNotifyCatcher-NodeInfoWatcher started: period:" + period);
        }
    }
    // init RuntimeNotifyServerWorker
    int port = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.port"));
    int backlog = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.backlog"));
    int core = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.core"));
    int max = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.max"));
    int bqsize = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.bqsize"));
    runtimeNotifyServerWorker = new RuntimeNotifyServerWorker("RuntimeNotifyServerWorker", feature, "rnswhandlers");
    @SuppressWarnings({ "rawtypes", "unchecked" }) ThreadPoolExecutor exe = new ThreadPoolExecutor(core, max, 30000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(bqsize));
    runtimeNotifyServerWorker.start(exe, port, backlog);
    if (log.isTraceEnable()) {
        log.info(this, "RuntimeNotifyCatcher-RuntimeNotifyServerWorker started");
    }
    // init RuntimeNotifyTimerWorker
    if (DataConvertHelper.toBoolean(this.getCfg("timernotify.enable"), false)) {
        TimerNotifyWorker timerNotifyWorker = new TimerNotifyWorker("TimerNotifyWorker", feature);
        this.getTimerWorkManager().scheduleWork("TimerNotifyWorker", timerNotifyWorker, 0, 60000);
        if (log.isTraceEnable()) {
            log.info(this, "RuntimeNotifyCatcher-RuntimeNotifyStrategyMgr started: " + strategy);
        }
    }
}
Also used : RuntimeNotifyStrategyMgr(com.creditease.uav.feature.runtimenotify.scheduler.RuntimeNotifyStrategyMgr) StrategyJudgement(com.creditease.uav.feature.runtimenotify.StrategyJudgement) StandardMessagingBuilder(org.uavstack.resources.common.messaging.StandardMessagingBuilder) TimerNotifyWorker(com.creditease.uav.feature.runtimenotify.scheduler.TimerNotifyWorker) NodeInfoWatcher(com.creditease.uav.feature.runtimenotify.scheduler.NodeInfoWatcher) IOException(java.io.IOException) RuntimeNotifyServerWorker(com.creditease.uav.feature.runtimenotify.http.RuntimeNotifyServerWorker) I1NQueueWorker(com.creditease.agent.spi.I1NQueueWorker) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) CacheManager(com.creditease.uav.cache.api.CacheManager) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) RuntimeNotifySliceMgr(com.creditease.uav.feature.runtimenotify.RuntimeNotifySliceMgr)

Example 5 with I1NQueueWorker

use of com.creditease.agent.spi.I1NQueueWorker 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)

Aggregations

I1NQueueWorker (com.creditease.agent.spi.I1NQueueWorker)6 RuntimeNotifySliceMgr (com.creditease.uav.feature.runtimenotify.RuntimeNotifySliceMgr)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 NCEventStatusManager (com.creditease.agent.feature.notifycenter.NCEventStatusManager)1 NCHttpServerWorker (com.creditease.agent.feature.notifycenter.NCHttpServerWorker)1 NCJudgementWorker (com.creditease.agent.feature.notifycenter.NCJudgementWorker)1 CEMailAction (com.creditease.agent.feature.notifycenter.actions.CEMailAction)1 HttpCallAction (com.creditease.agent.feature.notifycenter.actions.HttpCallAction)1 JavaMailAction (com.creditease.agent.feature.notifycenter.actions.JavaMailAction)1 PushNotifyEventAction (com.creditease.agent.feature.notifycenter.actions.PushNotifyEventAction)1 SMSAction (com.creditease.agent.feature.notifycenter.actions.SMSAction)1 ThreadAnalysisAction (com.creditease.agent.feature.notifycenter.actions.ThreadAnalysisAction)1 Abstract1NTask (com.creditease.agent.spi.Abstract1NTask)1 HttpMessage (com.creditease.agent.spi.HttpMessage)1 I1NQueueWorkerMgr (com.creditease.agent.spi.I1NQueueWorkerMgr)1 CacheManager (com.creditease.uav.cache.api.CacheManager)1 NotifyStrategy (com.creditease.uav.feature.runtimenotify.NotifyStrategy)1 Slice (com.creditease.uav.feature.runtimenotify.Slice)1 StrategyJudgement (com.creditease.uav.feature.runtimenotify.StrategyJudgement)1