Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
serverPort=9090
#Comma seperated list of all the zookeeper servers
zkServer=localhost:2181,localhost:2181
#the default zk root to show
zkRootPath=/
#Http path of the repository. Ignore if you dont intent to upload files from repository.
scmRepo=http://myserver.com/@rev1=
#Path appended to the repo url. Ignore if you dont intent to upload files from repository.
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/com/deem/zkui/controller/Home.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import javax.servlet.http.HttpServletResponse;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooKeeper;
import org.h2.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -56,6 +57,11 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t

Map<String, Object> templateParam = new HashMap<>();
String zkPath = request.getParameter("zkPath");
String zkRootPath = globalProps.getProperty("zkRootPath");

if (!StringUtils.isNullOrEmpty(zkRootPath) && (StringUtils.isNullOrEmpty(zkPath) || zkPath.equals("/"))) {
zkPath = zkRootPath;
}
String navigate = request.getParameter("navigate");
ZooKeeper zk = ServletUtil.INSTANCE.getZookeeper(request, response, zkServerLst[0], globalProps);
List<String> nodeLst;
Expand Down Expand Up @@ -164,7 +170,12 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
response.sendRedirect("/home?zkPath=" + displayPath);
break;
case "Search":
Set<LeafBean> searchResult = ZooKeeperUtil.INSTANCE.searchTree(searchStr, ServletUtil.INSTANCE.getZookeeper(request, response, zkServerLst[0], globalProps), authRole);
String zkPath = request.getParameter("zkPath");
String zkRootPath = globalProps.getProperty("zkRootPath");
if (StringUtils.isNullOrEmpty(zkPath)) {
zkPath = zkRootPath;
}
Set<LeafBean> searchResult = ZooKeeperUtil.INSTANCE.searchTree(searchStr, zkPath, ServletUtil.INSTANCE.getZookeeper(request, response, zkServerLst[0], globalProps), authRole);
templateParam.put("searchResult", searchResult);
ServletUtil.INSTANCE.renderHtml(request, response, templateParam, "search.ftl.html");
break;
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/com/deem/zkui/utils/ZooKeeperUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@
import com.deem.zkui.vo.LeafBean;
import com.deem.zkui.vo.ZKNode;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.*;

import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
Expand All @@ -36,6 +31,7 @@
import org.apache.zookeeper.data.ACL;
import org.apache.zookeeper.data.Id;
import org.apache.zookeeper.data.Stat;
import org.h2.util.StringUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
Expand Down Expand Up @@ -131,17 +127,26 @@ public void setDefaultAcl(String jsonAcl) {
defaultAcl = newDefault;
}

public Set<LeafBean> searchTree(String searchString, ZooKeeper zk, String authRole) throws InterruptedException, KeeperException {
public Set<LeafBean> searchTree(String searchString, String zkRootPath, ZooKeeper zk, String authRole) throws InterruptedException, KeeperException {
//Export all nodes and then search.
long startTime = System.currentTimeMillis();
Set<LeafBean> searchResult = new TreeSet<>();
Set<LeafBean> leaves = new TreeSet<>();
exportTreeInternal(leaves, ZK_ROOT_NODE, zk, authRole);
if (StringUtils.isNullOrEmpty(zkRootPath)) {
zkRootPath = ZK_ROOT_NODE;
}
exportTreeInternal(leaves, zkRootPath, zk, authRole);
long estimatedTime = System.currentTimeMillis() - startTime;
logger.trace("Elapsed Time in Secs for Export Tree Internal: {}, the total search leaves {}" , estimatedTime / 1000, leaves.size());
startTime = System.currentTimeMillis();
for (LeafBean leaf : leaves) {
String leafValue = ServletUtil.INSTANCE.externalizeNodeValue(leaf.getValue());
if (leaf.getPath().contains(searchString) || leaf.getName().contains(searchString) || leafValue.contains(searchString)) {
searchResult.add(leaf);
}
}
long estimatedTime1 = System.currentTimeMillis() - startTime;
logger.trace("Elapsed Time in Secs for Search: {}", estimatedTime1 / 1000);
return searchResult;

}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/webapp/template/home.ftl.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,13 @@
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">Search</h4>
<h4 class="modal-title" id="myModalLabel">Search in ${displayPath}</h4>
</div>
<div class="modal-body">
<div class="input-group input-group-lg">
<span class="input-group-addon">Search</span>
<input type="text" id="search" name="searchStr" class="form-control" >
<input type="hidden" name="zkPath" value="${displayPath}"/>
</div>
</div>
<div class="modal-footer">
Expand Down