...
|
...
|
@@ -10,6 +10,7 @@ import org.apache.curator.RetryPolicy; |
|
|
import org.apache.curator.framework.CuratorFramework;
|
|
|
import org.apache.curator.framework.CuratorFrameworkFactory;
|
|
|
import org.apache.curator.retry.RetryOneTime;
|
|
|
import org.apache.zookeeper.data.Stat;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
...
|
...
|
@@ -18,9 +19,11 @@ import org.springframework.util.CollectionUtils; |
|
|
|
|
|
import com.model.MObjectInfo;
|
|
|
import com.model.ZkConfig;
|
|
|
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.request.ZkTreeAllReq;
|
|
|
import com.monitor.model.request.ZkTreeReq;
|
|
|
import com.monitor.model.response.PageResponse;
|
|
|
import com.monitor.mysql.mapper.MObjectInfoMapper;
|
...
|
...
|
@@ -109,5 +112,90 @@ public class ZkMoitorServiceImpl implements IZkMoitorService { |
|
|
}
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public PageResponse<ZkConfigAll> getZkMonitorDetail(ZkTreeAllReq req) {
|
|
|
|
|
|
PageResponse<ZkConfigAll> response = new PageResponse<ZkConfigAll>();
|
|
|
List<ZkConfigAll> list = new ArrayList<ZkConfigAll>();
|
|
|
int page=0;
|
|
|
RetryPolicy retryPolicy = new RetryOneTime(1000);
|
|
|
CuratorFramework client = CuratorFrameworkFactory.newClient("192.168.102.205"+ ":2181", 5 * 1000, 5 * 1000, retryPolicy);
|
|
|
client.start();
|
|
|
try {
|
|
|
list=getAllChildren(req.getZkPath(),client,req.getIp());
|
|
|
for(ZkConfigAll zk:list){
|
|
|
page++;
|
|
|
}
|
|
|
if (list.size()>10) {
|
|
|
list=list.subList(req.getCurrentPage()*10-10, req.getCurrentPage()*10);
|
|
|
}
|
|
|
response.setCurrentPage(req.getCurrentPage());
|
|
|
response.setPageSize(req.getPageSize());
|
|
|
response.setTotal(page);
|
|
|
response.setRows(list);
|
|
|
} catch (Exception e) {
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int editZkMonitorDetail(ZkTreeAllReq req) {
|
|
|
int result = 0;
|
|
|
RetryPolicy retryPolicy = new RetryOneTime(1000);
|
|
|
CuratorFramework client = CuratorFrameworkFactory.newClient("192.168.102.205"+ ":2181", 5 * 1000, 5 * 1000, retryPolicy);
|
|
|
client.start();
|
|
|
try {
|
|
|
byte[] data = req.getZkValue().getBytes();
|
|
|
client.setData().forPath(req.getZkPath(), data);
|
|
|
|
|
|
String newData = new String(client.getData().forPath(req.getZkPath()));
|
|
|
if(newData.equals(req.getZkValue())){
|
|
|
result=1;
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
result=0;
|
|
|
e.printStackTrace();
|
|
|
}finally {
|
|
|
client.close();
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|