Search in sources :

Example 6 with CacheManager

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

the class HealthManager method start.

@Override
public void start() {
    // init cache manager
    String cacheServerAddress = this.getConfigManager().getFeatureConfiguration(this.feature, "store.addr");
    int minConcurrent = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "store.concurrent.min"));
    int maxConcurrent = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "store.concurrent.max"));
    int queueSize = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "store.concurrent.bqsize"));
    String password = this.getConfigManager().getFeatureConfiguration(this.feature, "store.concurrent.pwd");
    CacheManager cm = CacheManagerFactory.build(cacheServerAddress, minConcurrent, maxConcurrent, queueSize, password);
    this.getConfigManager().registerComponent(this.feature, "HMCacheManager", cm);
    // start HealthManagerProfileDataLifeKeeper
    isStartLifeKeeper = Boolean.parseBoolean(this.getConfigManager().getFeatureConfiguration(this.feature, "lifekeeper.enable"));
    if (isStartLifeKeeper == true) {
        // init HealthManagerProfileDataLifeKeeper
        HealthManagerProfileDataLifeKeeper profileDataLifeKeepWorker = new HealthManagerProfileDataLifeKeeper("HealthManagerProfileDataLifeKeeper", this.feature);
        long interval = Long.parseLong(this.getConfigManager().getFeatureConfiguration(this.feature, "lifekeeper.interval"));
        long randomDely = new Random().nextInt(3) + 3;
        this.getTimerWorkManager().scheduleWorkInPeriod("HealthManagerProfileDataLifeKeeper", profileDataLifeKeepWorker, randomDely * 1000, interval);
        if (log.isTraceEnable()) {
            log.info(this, "HealthManagerProfileDataLifeKeeper started");
        }
    }
    /**
     * Start the DBStore service NOTE: this must be the first to start
     */
    buildDataStores(this.getConfigManager());
    // start all datastores
    DataStoreFactory.getInstance().startAll(this.feature);
    if (log.isTraceEnable()) {
        log.info(this, "HealthManager DataStore Factory started");
    }
    /**
     * Start the HealthManger Http service
     */
    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"));
    healthServerListenWorker = new HealthManagerServerWorker("HealthMangerServerWorker", this.feature, "healthMangerHandlers");
    @SuppressWarnings({ "rawtypes", "unchecked" }) ThreadPoolExecutor exe = new ThreadPoolExecutor(core, max, 30000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(bqsize));
    healthServerListenWorker.start(exe, port, backlog);
    if (log.isTraceEnable()) {
        log.info(this, "HealthManager DataStore HttpServer started");
    }
    StandardMessagingBuilder smb = new StandardMessagingBuilder("HMCommonMsgBuilder", this.feature);
    try {
        smb.init("com.creditease.uav.feature.healthmanager.messaging.handlers");
    } catch (IOException e) {
        log.err(this, "Read msgtype2topic.properties FAILs, HealthManager can not START", e);
        return;
    }
    monitorDataConsumer = smb.buildConsumer(MonitorDataFrame.MessageType.Monitor.toString());
    notificationConsumer = smb.buildConsumer(MonitorDataFrame.MessageType.Notification.toString());
    profileDataConsumer = smb.buildConsumer(MonitorDataFrame.MessageType.Profile.toString());
    logDataConsumer = smb.buildConsumer(MonitorDataFrame.MessageType.Log.toString());
    nodeinfoDataConsumer = smb.buildConsumer(MonitorDataFrame.MessageType.NodeInfo.toString());
    // start monitorDataConsumer
    if (monitorDataConsumer != null) {
        monitorDataConsumer.start();
        this.getConfigManager().registerComponent(this.feature, HealthManagerConstants.COMSUMER_MONITOR, monitorDataConsumer);
        if (log.isTraceEnable()) {
            log.info(this, "HealthManager MDFConsumer started");
        }
    }
    // start notificationConsumer
    if (this.notificationConsumer != null) {
        notificationConsumer.start();
        this.getConfigManager().registerComponent(this.feature, HealthManagerConstants.COMSUMER_NOTIFY, notificationConsumer);
        if (log.isTraceEnable()) {
            log.info(this, "HealthManager NotifyConsumer started");
        }
    }
    // start profileDataConsumer
    if (this.profileDataConsumer != null) {
        /**
         * INIT StandardProfileModelingEngine & StandardProfileModeler
         */
        IActionEngine engine = this.getActionEngineMgr().newActionEngine("StandardProfileModelingEngine", feature);
        new StandardProfileModeler("StandardProfileModeler", feature, engine);
        // start profile consumer
        profileDataConsumer.start();
        this.getConfigManager().registerComponent(this.feature, HealthManagerConstants.COMSUMER_PROFILE, profileDataConsumer);
        if (log.isTraceEnable()) {
            log.info(this, "HealthManager ProfileConsumer started");
        }
    }
    // start logDataConsumer
    if (this.logDataConsumer != null) {
        logDataConsumer.start();
        this.getConfigManager().registerComponent(this.feature, HealthManagerConstants.COMSUMER_LOG, logDataConsumer);
        if (log.isTraceEnable()) {
            log.info(this, "HealthManager LogConsumer started");
        }
    }
    // start nodeinfoDataConsumer
    if (nodeinfoDataConsumer != null) {
        nodeinfoDataConsumer.start();
        this.getConfigManager().registerComponent(this.feature, HealthManagerConstants.COMSUMER_NODE, nodeinfoDataConsumer);
        if (log.isTraceEnable()) {
            log.info(this, "HealthManager NodeInfoConsumer started");
        }
    }
}
Also used : StandardMessagingBuilder(org.uavstack.resources.common.messaging.StandardMessagingBuilder) HealthManagerServerWorker(com.creditease.uav.feature.healthmanager.HealthManagerServerWorker) IOException(java.io.IOException) IActionEngine(com.creditease.agent.spi.IActionEngine) HealthManagerProfileDataLifeKeeper(com.creditease.uav.feature.healthmanager.HealthManagerProfileDataLifeKeeper) Random(java.util.Random) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) CacheManager(com.creditease.uav.cache.api.CacheManager) StandardProfileModeler(com.creditease.agent.profile.api.StandardProfileModeler) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 7 with CacheManager

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

the class RuntimeNotifyCatcher method stop.

@Override
public void stop() {
    // stop runtimeDataConsumer
    if (runtimeDataConsumer != null) {
        runtimeDataConsumer.shutdown();
        this.getConfigManager().unregisterComponent(this.feature, COMSUMER_RUNTIME);
        if (log.isTraceEnable()) {
            log.info(this, "RuntimeNotifyCatcher RuntimeConsumer shutdown");
        }
    }
    // stop runtime server worker
    runtimeNotifyServerWorker.stop();
    if (log.isTraceEnable()) {
        log.info(this, "RuntimeNotifyCatcher-RuntimeNotifyServerWorker stopped");
    }
    // stop nodeinfotimer
    boolean isEnableInfoTimer = DataConvertHelper.toBoolean(this.getCfg("nodeinfotimer.enable"), false);
    if (isEnableInfoTimer == true) {
        getTimerWorkManager().cancel("NodeInfoWatcher");
        if (log.isTraceEnable()) {
            log.info(this, "RuntimeNotifyCatcher-NodeInfoWatcher stopped");
        }
    }
    // stop 1+N worker
    if (qwThread != null && qwThread.isAlive()) {
        qwThread.interrupt();
    }
    get1NQueueWorkerMgr().shutdown(this.feature, QWORKER_NAME);
    if (log.isTraceEnable()) {
        log.info(this, "RuntimeNotifyCatcher-I1NQueueWorker[" + QWORKER_NAME + "] stopped");
    }
    // stop RuntimeNotifyStrategyMgr
    this.getTimerWorkManager().cancel("RuntimeNotifyStrategyMgr");
    if (log.isTraceEnable()) {
        log.info(this, "RuntimeNotifyCatcher-RuntimeNotifyStrategyMgr stopped");
    }
    // stop RuntimeNotifyTimerWorker
    this.getTimerWorkManager().cancel("timerNotifyWorker");
    if (log.isTraceEnable()) {
        log.info(this, "RuntimeNotifyCatcher-timerNotifyWorker stopped");
    }
    // shutdown CacheManager
    CacheManager RNStorageCacheManager = (CacheManager) this.getConfigManager().getComponent(this.feature, STORAGE_CACHE_MANAGER_NAME);
    RNStorageCacheManager.shutdown();
    CacheManager RuntimeNotifyCacheManager = (CacheManager) this.getConfigManager().getComponent(this.feature, CACHE_MANAGER_NAME);
    RuntimeNotifyCacheManager.shutdown();
    if (log.isTraceEnable()) {
        log.info(this, "RuntimeNotifyCatcher-CacheManager stopped");
    }
    this.getConfigManager().unregisterComponent(this.feature, "StrategyJudgement");
    super.stop();
}
Also used : CacheManager(com.creditease.uav.cache.api.CacheManager)

Example 8 with CacheManager

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

the class DataTest4ProfileOnRedis method testLoad.

public static void testLoad() {
    SystemLogger.init("DEBUG", true, 5);
    CacheManager cm = CacheManager.instance();
    Map<String, String> data = cm.getHashAll(HealthManagerConstants.STORE_REGION_UAV, HealthManagerConstants.STORE_KEY_PROFILEINFO);
    System.out.println(JSONHelper.toString(data));
}
Also used : CacheManager(com.creditease.uav.cache.api.CacheManager)

Example 9 with CacheManager

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

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

the class DoTestAredisHookProxy method main.

public static void main(String[] args) throws InterruptedException {
    ConsoleLogger cl = new ConsoleLogger("test");
    cl.setDebugable(true);
    UAVServer.instance().setLog(cl);
    UAVServer.instance().putServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR, ServerVendor.TOMCAT);
    @SuppressWarnings("rawtypes") AredisHookProxy p = new AredisHookProxy("test", new HashMap());
    p.doProxyInstall(null, "test");
    SystemLogger.init("DEBUG", true, 0);
    CacheManager cm = CacheManagerFactory.build("localhost:6379", 1, 5, 5);
    cm.put("TEST", "foo", "bar");
    String v = cm.get("TEST", "foo");
    System.out.println(v);
    Thread.sleep(1000l);
    cm.shutdown();
}
Also used : HashMap(java.util.HashMap) ConsoleLogger(com.creditease.monitor.log.ConsoleLogger) CacheManager(com.creditease.uav.cache.api.CacheManager)

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