diff --git a/shepher-service/src/main/java/com/xiaomi/shepher/dao/NodeDAO.java b/shepher-service/src/main/java/com/xiaomi/shepher/dao/NodeDAO.java index 6a4fd3c..e6d1e2f 100644 --- a/shepher-service/src/main/java/com/xiaomi/shepher/dao/NodeDAO.java +++ b/shepher-service/src/main/java/com/xiaomi/shepher/dao/NodeDAO.java @@ -47,6 +47,8 @@ public List getChildren(String cluster, String path) throws ShepherExcep return Collections.emptyList(); } return zkClient.getChildren(path); + } catch (ZkNoNodeException e) { + throw e; } catch (Exception e) { LOGGER.warn("Fail to get children, Exception:", e); throw ShepherException.createUnknownException(); diff --git a/shepher-service/src/main/java/com/xiaomi/shepher/service/NodeService.java b/shepher-service/src/main/java/com/xiaomi/shepher/service/NodeService.java index e38aeed..c368c8d 100644 --- a/shepher-service/src/main/java/com/xiaomi/shepher/service/NodeService.java +++ b/shepher-service/src/main/java/com/xiaomi/shepher/service/NodeService.java @@ -26,6 +26,8 @@ import com.xiaomi.shepher.dao.NodeDAO; import com.xiaomi.shepher.exception.ShepherException; import com.xiaomi.shepher.util.ReviewUtil; +import org.I0Itec.zkclient.exception.ZkNoNodeException; +import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.data.Stat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,6 +35,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Set; @@ -67,7 +70,13 @@ public class NodeService { private String serverUrl; public List getChildren(String cluster, String path) throws ShepherException { - List children = nodeDAO.getChildren(cluster, path); + List children = null; + try { + children = nodeDAO.getChildren(cluster, path); + } catch (ZkNoNodeException e) { + logger.error("node [{}] not exist",((KeeperException.NoNodeException)e.getCause()).getPath()); + return new ArrayList<>(0); + } Collections.sort(children); return children; } diff --git a/shepher-web/src/main/java/com/xiaomi/shepher/controller/NodeController.java b/shepher-web/src/main/java/com/xiaomi/shepher/controller/NodeController.java index 657460a..7bc7bc4 100644 --- a/shepher-web/src/main/java/com/xiaomi/shepher/controller/NodeController.java +++ b/shepher-web/src/main/java/com/xiaomi/shepher/controller/NodeController.java @@ -34,11 +34,13 @@ import com.xiaomi.shepher.util.ParentPathParser; import com.xiaomi.shepher.util.ReviewUtil; import org.apache.commons.lang3.StringEscapeUtils; +import org.apache.zookeeper.data.Stat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -93,18 +95,25 @@ public String home(@RequestParam(value = "path", defaultValue = SLASH) String pa @RequestParam(value = "show-ip", defaultValue = "") String showIp, Model model) throws ShepherException { List children = nodeService.getChildren(cluster, path); - + boolean isNodeExist = true; + if(CollectionUtils.isEmpty(children)) { + isNodeExist = false; + } List snapshots = snapshotService.getByPath(path, cluster, 0, ReviewUtil.DEFAULT_PAGINATION_LIMIT); ReviewUtil.generateSummary(snapshots); long userId = userHolder.getUser().getId(); boolean hasPermission = permissionService.isPathMember(userId, cluster, path); boolean hasDeletePermission = permissionService.isPathMaster(userId, cluster, path); - + if(!isNodeExist) { + model.addAttribute("isNodeExists", isNodeExist); + }else { + model.addAttribute("isNodeExists", true); + } model.addAttribute("children", children); model.addAttribute("hasChild", !children.isEmpty()); - model.addAttribute("data", StringEscapeUtils.escapeHtml4(nodeService.getData(cluster, path))); - model.addAttribute("stat", nodeService.getStat(cluster, path)); + model.addAttribute("data", isNodeExist ? StringEscapeUtils.escapeHtml4(nodeService.getData(cluster, path)) : "null"); + model.addAttribute("stat", isNodeExist ? nodeService.getStat(cluster, path) : new Stat()); model.addAttribute("path", path); model.addAttribute("pathArr", path.split(SLASH)); model.addAttribute("cluster", cluster); diff --git a/shepher-web/src/main/resources/templates/cluster/index.ftl b/shepher-web/src/main/resources/templates/cluster/index.ftl index 1ea2d58..8fbdea9 100644 --- a/shepher-web/src/main/resources/templates/cluster/index.ftl +++ b/shepher-web/src/main/resources/templates/cluster/index.ftl @@ -31,6 +31,10 @@ + <#if !isNodeExists> + +