Skip to content

Commit

Permalink
修复已知bug
Browse files Browse the repository at this point in the history
  • Loading branch information
JThink committed Nov 15, 2017
1 parent 8c2df9e commit afd86b5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ allprojects {
apply plugin: 'eclipse'

group = 'skyeye'
version = '1.2.0'
version = '1.2.1'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) th
this.rabbitmqService.sendMessage(info, datas[0]);
LOGGER.info(info);
CacheService.appHosts.add(node);
this.appInfoService.add(host, app, Constants.ZK_NODE_TYPE_EPHEMERAL, LogCollectionStatus.RUNNING);
this.appInfoService.add(host, app, Constants.ZK_NODE_TYPE_EPHEMERAL, this.calLogCollectionStatus(app, host));
}
this.appInfoService.add(host, app, Constants.ZK_NODE_TYPE_PERSISTENT, LogCollectionStatus.HISTORY);
break;
Expand Down Expand Up @@ -152,4 +152,18 @@ private String buildMsg(String time, String app, String host, String deploy, Str
AlertDto alertDto = new AlertDto(time, app, host, deploy, msg);
return alertDto.toString();
}

/**
* 根据app和host计算LogCollectionStatus
* @param app
* @param host
* @return
*/
public LogCollectionStatus calLogCollectionStatus(String app, String host) {
String[] datas = this.zkClient.readData(Constants.ROOT_PATH_EPHEMERAL + Constants.SLASH + app + Constants.SLASH + host).toString().split(Constants.SEMICOLON);
if (datas[0].equals(Constants.APPENDER_INIT_DATA) || datas[0].equals(Constants.APP_APPENDER_RESTART_KEY)) {
return LogCollectionStatus.RUNNING;
}
return LogCollectionStatus.STOPPED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void deleteAll() {
* @return
*/
private String getDeploy(String path) {
String data = this.zkClient.readData(path);
return data.split(Constants.SEMICOLON)[1];
String[] datas = this.zkClient.readData(path).toString().split(Constants.SEMICOLON);
return datas[datas.length - 1];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @date 2016-09-23 14:55:28
*/
@Service
public class AppStatusMonitorService implements InitializingBean {
public class AppStatusMonitorService {

@Autowired
private CuratorFramework curatorFramework;
Expand All @@ -30,8 +30,7 @@ public class AppStatusMonitorService implements InitializingBean {
@Autowired
private AppInfoService appInfoService;

@Override
public void afterPropertiesSet() throws Exception {
public void init() throws Exception {
PathChildrenCache pathChildrenCache = new PathChildrenCache(curatorFramework, Constants.ROOT_PATH_EPHEMERAL, true);
pathChildrenCache.start(PathChildrenCache.StartMode.POST_INITIALIZED_EVENT);
pathChildrenCache.getListenable().addListener(new ScrollChildrenChangeListener(this.rabbitmqService, this.zkClient, this.appInfoService));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ public class CacheService implements InitializingBean {
private AppInfoService appInfoService;
@Autowired
private ZkClient zkClient;
@Autowired
private AppStatusMonitorService appStatusMonitorService;

@Override
public void afterPropertiesSet() throws Exception {
LOGGER.info("开始加载缓存");
// 将mysql数据进行清空
this.appInfoService.deleteAll();
List<String> apps = curatorFramework.getChildren().forPath(Constants.ROOT_PATH_EPHEMERAL);
Expand All @@ -57,6 +60,10 @@ public void afterPropertiesSet() throws Exception {
this.appInfoService.add(host, app, Constants.ZK_NODE_TYPE_PERSISTENT, LogCollectionStatus.HISTORY);
}
}

LOGGER.info("加载缓存结束");

this.appStatusMonitorService.init();
}

/**
Expand All @@ -67,7 +74,7 @@ public void afterPropertiesSet() throws Exception {
*/
private LogCollectionStatus calLogCollectionStatus(String app, String host) {
String[] datas = this.zkClient.readData(Constants.ROOT_PATH_EPHEMERAL + Constants.SLASH + app + Constants.SLASH + host).toString().split(Constants.SEMICOLON);
if (datas[0].equals(Constants.APPENDER_INIT_DATA)) {
if (datas[0].equals(Constants.APPENDER_INIT_DATA) || datas[0].equals(Constants.APP_APPENDER_RESTART_KEY)) {
return LogCollectionStatus.RUNNING;
}
return LogCollectionStatus.STOPPED;
Expand Down

0 comments on commit afd86b5

Please sign in to comment.