feature(web): 增加一个直接通过 zookeeper 查询运行时信息的页面
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
package com.lanyuanxiaoyao.service.zookeeper;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import com.lanyuanxiaoyao.service.configuration.entity.zookeeper.ZookeeperNode;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.recipes.locks.InterProcessLock;
|
||||
import org.apache.curator.framework.recipes.locks.InterProcessMutex;
|
||||
import org.apache.zookeeper.data.Stat;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.list.MutableList;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -12,6 +16,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Zookeeper 查询
|
||||
*
|
||||
@@ -44,6 +50,20 @@ public class ZookeeperController {
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("get_children")
|
||||
public ImmutableList<ZookeeperNode> children(@RequestParam("path") String path) throws Exception {
|
||||
if (existsPath(path)) {
|
||||
MutableList<ZookeeperNode> nodes = Lists.mutable.empty();
|
||||
for (String label : client.getChildren().forPath(path)) {
|
||||
String childPath = path + "/" + label;
|
||||
Stat stat = client.checkExists().forPath(childPath);
|
||||
nodes.add(new ZookeeperNode(childPath, label, stat.getCtime(), stat.getMtime()));
|
||||
}
|
||||
return nodes.toImmutable();
|
||||
}
|
||||
return Lists.immutable.empty();
|
||||
}
|
||||
|
||||
@GetMapping("exists_lock")
|
||||
public Boolean existsLock(@RequestParam("path") String path) throws Exception {
|
||||
InterProcessLock lock = new InterProcessMutex(client, path);
|
||||
|
||||
Reference in New Issue
Block a user