use of com.creditease.uav.cache.api.CacheManager in project uavstack by uavorg.
the class HealthManagerClient method getCM.
private static CacheManager getCM(String ip) {
SystemLogger.init("INFO", false, 5);
ConfigurationManager.build(new HashMap<String, String>());
CacheManager.build(ip, 2, 5, 10);
CacheManager cm = CacheManager.instance();
return cm;
}
use of com.creditease.uav.cache.api.CacheManager in project uavstack by uavorg.
the class HealthManagerClient method loadNodeInfoCache.
private static void loadNodeInfoCache(String ip) {
CacheManager cm = getCM(ip);
Map<String, String> data = cm.getHashAll(HeartBeatProtocol.STORE_REGION_UAV, HeartBeatProtocol.STORE_KEY_NODEINFO);
String dat = JSONHelper.toString(data);
try {
IOHelper.writeTxtFile(IOHelper.getCurrentPath() + "/nodeinfo_cache.txt", dat, "utf-8", false);
} catch (IOException e) {
e.printStackTrace();
}
}
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");
}
}
}
use of com.creditease.uav.cache.api.CacheManager in project uavstack by uavorg.
the class HealthManager method stop.
@Override
public void stop() {
// stop monitorDataConsumer
if (this.monitorDataConsumer != null) {
monitorDataConsumer.shutdown();
this.getConfigManager().unregisterComponent(this.feature, HealthManagerConstants.COMSUMER_MONITOR);
if (log.isTraceEnable()) {
log.info(this, "HealthManager MdfConsumer shutdown");
}
}
// stop notificationConsumer
if (this.notificationConsumer != null) {
notificationConsumer.shutdown();
this.getConfigManager().unregisterComponent(this.feature, HealthManagerConstants.COMSUMER_NOTIFY);
if (log.isTraceEnable()) {
log.info(this, "HealthManager NotifyConsumer shutdown");
}
}
// stop profileDataConsumer
if (this.profileDataConsumer != null) {
// shut down StandardProfileModelingEngine
this.getActionEngineMgr().shutdown("StandardProfileModelingEngine");
profileDataConsumer.shutdown();
this.getConfigManager().unregisterComponent(this.feature, HealthManagerConstants.COMSUMER_PROFILE);
if (log.isTraceEnable()) {
log.info(this, "HealthManager ProfileConsumer shutdown");
}
}
// stop logDataConsumer
if (this.logDataConsumer != null) {
logDataConsumer.shutdown();
this.getConfigManager().unregisterComponent(this.feature, HealthManagerConstants.COMSUMER_LOG);
if (log.isTraceEnable()) {
log.info(this, "HealthManager LogConsumer shutdown");
}
}
// stop nodeinfoDataConsumer
if (this.nodeinfoDataConsumer != null) {
nodeinfoDataConsumer.shutdown();
this.getConfigManager().unregisterComponent(this.feature, HealthManagerConstants.COMSUMER_NODE);
if (log.isTraceEnable()) {
log.info(this, "HealthManager NodeInfoConsumer shutdown");
}
}
// stop healthServerListenWorker
healthServerListenWorker.stop();
if (log.isTraceEnable()) {
log.info(this, "HealthManager DataStore HttpServer shutdown");
}
// NOTE: this should be the last to stop
DataStoreFactory.getInstance().stopAll(this.feature);
if (log.isTraceEnable()) {
log.info(this, "HealthManager DataStore Factory shutdown");
}
if (isStartLifeKeeper == true) {
// stop HealthManagerProfileDataLifeKeeper
this.getTimerWorkManager().cancel("HealthManagerProfileDataLifeKeeper");
if (log.isTraceEnable()) {
log.info(this, "HealthManagerProfileDataLifeKeeper stopped");
}
}
// shutdown CacheManager
CacheManager HMCacheManager = (CacheManager) this.getConfigManager().getComponent(this.feature, "HMCacheManager");
HMCacheManager.shutdown();
super.stop();
}
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");
if (engine != null) {
this.getActionEngineMgr().shutdown("RuntimeNotifyActionEngine");
}
super.stop();
}
Aggregations