Search in sources :

Example 11 with CacheManager

use of com.creditease.uav.cache.api.CacheManager in project uavstack by uavorg.

the class InvokeChainProcessServer method stop.

@Override
public void stop() {
    // close ESClient
    ESClient client = (ESClient) this.getConfigManager().getComponent(this.feature, "ESClient");
    if (client != null) {
        client.close();
    }
    // stop InvokeChainQueryServerWorker
    if (ivcQueryServerWorker != null) {
        ivcQueryServerWorker.stop();
        if (log.isTraceEnable()) {
            log.info(this, "InvokeChainQueryServerWorker stop");
        }
    }
    // remove cacheManager
    CacheManager cm = (CacheManager) this.getConfigManager().getComponent(this.feature, "IVCCacheManager");
    if (cm != null) {
        cm.shutdown();
    }
    this.getConfigManager().unregisterComponent(this.feature, "IVCCacheManager");
    // shutdown NodeOperActionEngine
    this.getActionEngineMgr().shutdown("SlowOperActionEngine");
    super.stop();
}
Also used : ESClient(com.creditease.uav.elasticsearch.client.ESClient) CacheManager(com.creditease.uav.cache.api.CacheManager)

Example 12 with CacheManager

use of com.creditease.uav.cache.api.CacheManager in project uavstack by uavorg.

the class HealthManagerClient method loadRuntimeStrategy.

private static void loadRuntimeStrategy(String ip) {
    CacheManager cm = getCM(ip);
    Map<String, String> strategyMap = cm.getHashAll(RuntimeNotifyStrategyMgr.UAV_CACHE_REGION, RuntimeNotifyStrategyMgr.RT_STRATEGY_KEY);
    String dat = JSONHelper.toString(strategyMap);
    try {
        IOHelper.writeTxtFile(IOHelper.getCurrentPath() + "/rtstgy_cache.txt", dat, "utf-8", false);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : CacheManager(com.creditease.uav.cache.api.CacheManager) IOException(java.io.IOException)

Example 13 with CacheManager

use of com.creditease.uav.cache.api.CacheManager 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 14 with CacheManager

use of com.creditease.uav.cache.api.CacheManager in project uavstack by uavorg.

the class HealthManagerClient method loadProfileCache.

public static void loadProfileCache(String ip) {
    CacheManager cm = getCM(ip);
    Map<String, String> data = cm.getHashAll(HealthManagerConstants.STORE_REGION_UAV, HealthManagerConstants.STORE_KEY_PROFILEINFO);
    String dat = JSONHelper.toString(data);
    try {
        IOHelper.writeTxtFile(IOHelper.getCurrentPath() + "/profile_cache.txt", dat, "utf-8", false);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : CacheManager(com.creditease.uav.cache.api.CacheManager) IOException(java.io.IOException)

Example 15 with CacheManager

use of com.creditease.uav.cache.api.CacheManager 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)

Aggregations

CacheManager (com.creditease.uav.cache.api.CacheManager)26 IOException (java.io.IOException)6 HashMap (java.util.HashMap)4 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)4 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)4 Path (javax.ws.rs.Path)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 ESClient (com.creditease.uav.elasticsearch.client.ESClient)2 RuntimeNotifySliceMgr (com.creditease.uav.feature.runtimenotify.RuntimeNotifySliceMgr)2 Slice (com.creditease.uav.feature.runtimenotify.Slice)2 StrategyJudgement (com.creditease.uav.feature.runtimenotify.StrategyJudgement)2 RuntimeNotifyStrategyMgr (com.creditease.uav.feature.runtimenotify.scheduler.RuntimeNotifyStrategyMgr)2 Random (java.util.Random)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2 StandardMessagingBuilder (org.uavstack.resources.common.messaging.StandardMessagingBuilder)2 HeartBeatQueryListenWorker (com.creditease.agent.feature.hbagent.HeartBeatQueryListenWorker)1 HeartBeatServerLifeKeeper (com.creditease.agent.feature.hbagent.HeartBeatServerLifeKeeper)1