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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public List<String> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@
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;
import org.springframework.beans.factory.annotation.Autowired;
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;
Expand Down Expand Up @@ -67,7 +70,13 @@ public class NodeService {
private String serverUrl;

public List<String> getChildren(String cluster, String path) throws ShepherException {
List<String> children = nodeDAO.getChildren(cluster, path);
List<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> children = nodeService.getChildren(cluster, path);

boolean isNodeExist = true;
if(CollectionUtils.isEmpty(children)) {
isNodeExist = false;
}
List<Snapshot> 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);
Expand Down
4 changes: 4 additions & 0 deletions shepher-web/src/main/resources/templates/cluster/index.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
</button>
<button class="btn btn-success rowbtn" id="import-button" onclick="showImportModal(); return false;" <#if !hasPermission>disabled</#if>>Import
</button>
<#if !isNodeExists>
<button class="btn btn-success rowbtn" id="not-exists-node">The node not exists
</button>
</#if>
<label class="checkbox" for="editable">
<input type="checkbox" value="" id="editable" data-toggle="checkbox"
<#if !hasPermission>disabled</#if>>
Expand Down