Search in sources :

Example 1 with HealthManagerProfileDataLifeKeeper

use of com.creditease.uav.feature.healthmanager.HealthManagerProfileDataLifeKeeper 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)

Aggregations

StandardProfileModeler (com.creditease.agent.profile.api.StandardProfileModeler)1 IActionEngine (com.creditease.agent.spi.IActionEngine)1 CacheManager (com.creditease.uav.cache.api.CacheManager)1 HealthManagerProfileDataLifeKeeper (com.creditease.uav.feature.healthmanager.HealthManagerProfileDataLifeKeeper)1 HealthManagerServerWorker (com.creditease.uav.feature.healthmanager.HealthManagerServerWorker)1 IOException (java.io.IOException)1 Random (java.util.Random)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 StandardMessagingBuilder (org.uavstack.resources.common.messaging.StandardMessagingBuilder)1