Search in sources :

Example 1 with StandardMessagingBuilder

use of org.uavstack.resources.common.messaging.StandardMessagingBuilder in project uavstack by uavorg.

the class GatherDataManager method start.

@Override
public void start() {
    StandardMessagingBuilder builder = new StandardMessagingBuilder("GatherDataManagerMessageBuilder", feature);
    try {
        builder.init();
    } catch (IOException e) {
        log.err(this, "Read msgtype2topic.properties FAILs, GatherDataManager can not START", e);
        return;
    }
    String[] topics = getConfigManager().getFeatureConfiguration(feature, "topics").split(",");
    List<MessageHandler> handlers = new ArrayList<>();
    for (String topic : topics) {
        handlers.add(new DefaultGatherDataHandler(topic));
    }
    MessagingContext.putConsumerHandlers(handlers);
    // init consumers
    consumers = new ArrayList<>();
    for (String topic : topics) {
        MessageConsumer consumer = builder.buildConsumer(topic);
        if (consumer == null) {
            continue;
        }
        consumers.add(consumer);
    }
    // start all consumers
    for (MessageConsumer consumer : consumers) {
        consumer.start();
        log.info(this, "GatherData Consumer [" + consumer.getName() + "] start");
    }
    log.info(this, "GatherDataManager start");
}
Also used : StandardMessagingBuilder(org.uavstack.resources.common.messaging.StandardMessagingBuilder) MessageConsumer(com.creditease.uav.messaging.api.MessageConsumer) MessageHandler(com.creditease.uav.messaging.api.MessageHandler) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DefaultGatherDataHandler(com.creditease.uav.collect.server.messaging.DefaultGatherDataHandler)

Example 2 with StandardMessagingBuilder

use of org.uavstack.resources.common.messaging.StandardMessagingBuilder 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 3 with StandardMessagingBuilder

use of org.uavstack.resources.common.messaging.StandardMessagingBuilder in project uavstack by uavorg.

the class HMNewLogService method start.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void start() {
    /**
     * INIT ESClient
     */
    String esAddrStr = this.getConfigManager().getFeatureConfiguration(this.feature, "es.addr");
    String clusterName = this.getConfigManager().getFeatureConfiguration(this.feature, "es.clustername");
    ESClient client = new ESClient(esAddrStr, clusterName);
    this.getConfigManager().registerComponent(this.feature, "ESClient", client);
    /**
     * HMNewLogIndexMgr
     */
    new HMNewLogIndexMgr("HMNewLogIndexMgr", feature);
    /**
     * Log Consumer
     */
    StandardMessagingBuilder smb = new StandardMessagingBuilder("HMCommonMsgBuilder", this.feature);
    try {
        smb.init("com.creditease.uav.healthmanager.newlog.handlers");
    } catch (IOException e) {
        log.err(this, "Read msgtype2topic.properties FAILs, HealthManager can not START", e);
        return;
    }
    logDataConsumer = smb.buildConsumer(MonitorDataFrame.MessageType.Log.toString());
    // start logDataConsumer
    if (this.logDataConsumer != null) {
        logDataConsumer.start();
        this.getConfigManager().registerComponent(this.feature, "NewlogDataConsumer", logDataConsumer);
        if (log.isTraceEnable()) {
            log.info(this, "HMNewLogService LogConsumer started");
        }
    }
    // run NewLogQueryServerWorker
    boolean isStartQueryServer = DataConvertHelper.toBoolean(this.getConfigManager().getFeatureConfiguration(this.feature, "http.enable"), true);
    if (isStartQueryServer == true) {
        int port = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.port"), 7899);
        int backlog = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.backlog"), 10);
        int core = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.core"), 10);
        int max = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.max"), 100);
        int bqsize = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.bqsize"), 10);
        queryServer = new NewLogQueryServerWorker("NewLogQueryServerWorker", feature, "qhandlers");
        ThreadPoolExecutor executor = new ThreadPoolExecutor(core, max, 30, TimeUnit.SECONDS, new ArrayBlockingQueue(bqsize));
        queryServer.start(executor, port, backlog);
        if (log.isTraceEnable()) {
            log.info(this, "NewLogQueryServerWorker started");
        }
    }
}
Also used : StandardMessagingBuilder(org.uavstack.resources.common.messaging.StandardMessagingBuilder) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ESClient(com.creditease.uav.elasticsearch.client.ESClient) IOException(java.io.IOException) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) NewLogQueryServerWorker(com.creditease.uav.healthmanager.newlog.http.NewLogQueryServerWorker)

Example 4 with StandardMessagingBuilder

use of org.uavstack.resources.common.messaging.StandardMessagingBuilder 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

IOException (java.io.IOException)4 StandardMessagingBuilder (org.uavstack.resources.common.messaging.StandardMessagingBuilder)4 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)3 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)3 CacheManager (com.creditease.uav.cache.api.CacheManager)2 StandardProfileModeler (com.creditease.agent.profile.api.StandardProfileModeler)1 I1NQueueWorker (com.creditease.agent.spi.I1NQueueWorker)1 IActionEngine (com.creditease.agent.spi.IActionEngine)1 DefaultGatherDataHandler (com.creditease.uav.collect.server.messaging.DefaultGatherDataHandler)1 ESClient (com.creditease.uav.elasticsearch.client.ESClient)1 HealthManagerProfileDataLifeKeeper (com.creditease.uav.feature.healthmanager.HealthManagerProfileDataLifeKeeper)1 HealthManagerServerWorker (com.creditease.uav.feature.healthmanager.HealthManagerServerWorker)1 RuntimeNotifySliceMgr (com.creditease.uav.feature.runtimenotify.RuntimeNotifySliceMgr)1 StrategyJudgement (com.creditease.uav.feature.runtimenotify.StrategyJudgement)1 RuntimeNotifyServerWorker (com.creditease.uav.feature.runtimenotify.http.RuntimeNotifyServerWorker)1 NodeInfoWatcher (com.creditease.uav.feature.runtimenotify.scheduler.NodeInfoWatcher)1 RuntimeNotifyStrategyMgr (com.creditease.uav.feature.runtimenotify.scheduler.RuntimeNotifyStrategyMgr)1 TimerNotifyWorker (com.creditease.uav.feature.runtimenotify.scheduler.TimerNotifyWorker)1 NewLogQueryServerWorker (com.creditease.uav.healthmanager.newlog.http.NewLogQueryServerWorker)1 MessageConsumer (com.creditease.uav.messaging.api.MessageConsumer)1