...
|
...
|
@@ -22,12 +22,10 @@ import com.model.ZkConfigAll; |
|
|
import com.monitor.cmdb.service.IZkMoitorService;
|
|
|
import com.monitor.influxdb.mapper.IZkMapper;
|
|
|
import com.monitor.influxdb.model.ZkInfo;
|
|
|
import com.monitor.model.domain.PageBean;
|
|
|
import com.monitor.model.request.ZkTreeAllReq;
|
|
|
import com.monitor.model.request.ZkTreeReq;
|
|
|
import com.monitor.model.response.PageResponse;
|
|
|
import com.monitor.mysql.mapper.MObjectInfoMapper;
|
|
|
import com.monitor.mysql.mapper.ZkMonitorConfigMapper;
|
|
|
|
|
|
/**
|
|
|
* Created by yoho on 2016/6/22.
|
...
|
...
|
@@ -44,8 +42,6 @@ public class ZkMoitorServiceImpl implements IZkMoitorService { |
|
|
@Autowired
|
|
|
MObjectInfoMapper mObjectInfoMapper;
|
|
|
|
|
|
@Autowired
|
|
|
ZkMonitorConfigMapper zkMonitorConfigMapper;
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Object> getZkMonitorRecords() {
|
...
|
...
|
@@ -101,7 +97,10 @@ public class ZkMoitorServiceImpl implements IZkMoitorService { |
|
|
zkConfig.setName(chi);
|
|
|
zkConfig.setRoot(rootString);
|
|
|
zkConfig.setIp(req.getIp());
|
|
|
if(chi.equals("config")){
|
|
|
list.add(zkConfig);
|
|
|
}
|
|
|
|
|
|
page++;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -120,26 +119,68 @@ public class ZkMoitorServiceImpl implements IZkMoitorService { |
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public PageResponse<ZkConfigAll> getZkMonitorDetail(ZkConfigAll req) {
|
|
|
public PageResponse<ZkConfigAll> getZkMonitorDetail(ZkTreeAllReq req) {
|
|
|
|
|
|
PageResponse<ZkConfigAll> response = new PageResponse<ZkConfigAll>();
|
|
|
List<ZkConfigAll> list = new ArrayList<ZkConfigAll>();
|
|
|
int pageNum=0;
|
|
|
// 组装分页对象
|
|
|
PageBean page = PageBean.initPageInfo(req.getCurrentPage(),
|
|
|
req.getPageSize(), req);
|
|
|
pageNum = zkMonitorConfigMapper.getZkConfigCount(req);
|
|
|
|
|
|
list=zkMonitorConfigMapper.getZkConfigAll(page.getStartIndex(),page.getPageSize(),req.getIp(),req.getZkPath());
|
|
|
|
|
|
int page=0;
|
|
|
RetryPolicy retryPolicy = new RetryOneTime(1000);
|
|
|
CuratorFramework client = CuratorFrameworkFactory.newClient(req.getIp()+ ":2181", 5 * 1000, 5 * 1000, retryPolicy);
|
|
|
client.start();
|
|
|
try {
|
|
|
list=getAllChildren(req.getZkPath(),client,req.getIp());
|
|
|
for(ZkConfigAll zk:list){
|
|
|
zk.getCurrentPage();
|
|
|
page++;
|
|
|
}
|
|
|
if (list.size()>10&&req.getCurrentPage()*10<list.size()) {
|
|
|
list=list.subList(req.getCurrentPage()*10-10, req.getCurrentPage()*10);
|
|
|
}else if (req.getCurrentPage()*10>list.size()) {
|
|
|
list=list.subList(req.getCurrentPage()*10-10, list.size());
|
|
|
}
|
|
|
response.setCurrentPage(req.getCurrentPage());
|
|
|
response.setPageSize(req.getPageSize());
|
|
|
response.setTotal(pageNum);
|
|
|
response.setTotal(page);
|
|
|
response.setRows(list);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("getZkMonitorDetail fail with ip is {} and path is {}",req.getIp(),req.getZkPath());
|
|
|
e.printStackTrace();
|
|
|
}finally {
|
|
|
client.close();
|
|
|
}
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
public List<ZkConfigAll> getAllChildren(String parentPath,CuratorFramework client,String ip) {
|
|
|
List<ZkConfigAll> childList=new ArrayList<ZkConfigAll>();
|
|
|
try {
|
|
|
//取该路径下的所有子节点
|
|
|
List<String> childNodeNames=client.getChildren().forPath(parentPath);
|
|
|
for(String nodeName: childNodeNames){
|
|
|
//拼接路径
|
|
|
String nodePath=parentPath.concat("/").concat(nodeName);
|
|
|
|
|
|
ZkConfigAll zkNode=new ZkConfigAll();
|
|
|
zkNode.setZkPath(nodePath);
|
|
|
zkNode.setIp(ip);
|
|
|
String data =new String(client.getData().forPath(nodePath),"UTF-8");
|
|
|
zkNode.setZkValue(data);
|
|
|
List<String> liString = client.getChildren().forPath(nodePath);
|
|
|
if(CollectionUtils.isEmpty(liString)){
|
|
|
childList.add(zkNode);
|
|
|
}else {
|
|
|
//递归
|
|
|
childList.addAll(getAllChildren(nodePath, client,ip));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return childList;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
...
|
...
|
|