use of com.vip.saturn.job.console.domain.TreeNode in project Saturn by vipshop.
the class InitRegistryCenterService method parseDirectory2Tree.
/**
* generate a tree recursively.
* @param directory directory
* @param treeNodeParent treeNodeParent
* @param fullPath fullPath
* @return TreeNode
*/
public static TreeNode parseDirectory2Tree(String directory, TreeNode treeNodeParent, String fullPath, String degree) {
String[] nodes = directory.split("/");
String nodeName = nodes[0];
TreeNode node = new TreeNode();
node.setTitle(nodeName);
// if there is only one node left, just saves it to the subs and return.
if (nodes.length == 1) {
node.setTitle("<a title=\"总览\" href=overview?name=" + fullPath + " target=\"contentFrame\">" + nodeName + "</a>");
node.setFullPath(fullPath);
node.setDomain(nodeName);
node.setFolder(false);
node.setLazy(true);
node.setExtraClasses("custom-degree-circle degree-" + degree);
treeNodeParent.getChildren().add(node);
return treeNodeParent;
} else {
directory = directory.replace(nodeName + "/", "");
// if not, create new node, otherwise, pass the exist node to next loop.
if (treeNodeParent.getTitle() == null && !treeNodeParent.getChildren().isEmpty()) {
List<TreeNode> listSubTree = treeNodeParent.getChildren();
for (TreeNode tn : listSubTree) {
if (nodeName.equals(tn.getTitle())) {
parseDirectory2Tree(directory, tn, fullPath, degree);
return treeNodeParent;
}
}
treeNodeParent.getChildren().add(parseDirectory2Tree(directory, node, fullPath, degree));
return treeNodeParent;
}
if (nodeName.equals(treeNodeParent.getTitle())) {
parseDirectory2Tree(directory, treeNodeParent, fullPath, degree);
return treeNodeParent;
}
List<TreeNode> listSubTree = treeNodeParent.getChildren();
for (TreeNode tn : listSubTree) {
if (nodeName.equals(tn.getTitle())) {
parseDirectory2Tree(directory, tn, fullPath, degree);
return tn;
}
}
treeNodeParent.getChildren().add(parseDirectory2Tree(directory, node, fullPath, degree));
return treeNodeParent;
}
}
use of com.vip.saturn.job.console.domain.TreeNode in project Saturn by vipshop.
the class InitRegistryCenterService method reloadDomainRootTreeNode.
public static void reloadDomainRootTreeNode() {
TreeNode resultNode = null;
for (TreeNode treeNode : InitRegistryCenterService.ZKBSKEY_TO_TREENODE_MAP.values()) {
if (treeNode != null) {
treeNode = treeNode.deepCopy();
if (resultNode == null) {
resultNode = treeNode;
} else {
for (TreeNode childNode : treeNode.getChildren()) {
addToTree(resultNode, childNode);
}
}
}
}
if (resultNode != null) {
DOMAIN_ROOT_TREE_NODE = resultNode;
}
domainTreeinited.compareAndSet(false, true);
}
use of com.vip.saturn.job.console.domain.TreeNode in project Saturn by vipshop.
the class RegistryCenterServiceImpl method refreshTreeData.
private void refreshTreeData() {
// clear removed zkCluster treeData
Iterator<Entry<String, TreeNode>> iterator = InitRegistryCenterService.ZKBSKEY_TO_TREENODE_MAP.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, TreeNode> next = iterator.next();
String zkClusterKey = next.getKey();
if (!zkClusterMap.containsKey(zkClusterKey)) {
iterator.remove();
}
}
// refresh online zkCluster treeData, clear offline zkCluster treeData
Collection<ZkCluster> zkClusters = zkClusterMap.values();
for (ZkCluster zkCluster : zkClusters) {
refreshTreeData(zkCluster);
}
InitRegistryCenterService.reloadDomainRootTreeNode();
}
use of com.vip.saturn.job.console.domain.TreeNode in project Saturn by vipshop.
the class InitRegistryCenterService method initTreeJson.
/**
* transfer /a/b/b1, /a/b/b2 to {"title":"a", "children":["title":"b", "children": ["title": b1, "title": b2]]}
*
* @param registryCenterConfiguration 注册中心配置类
*/
public static void initTreeJson(Set<RegistryCenterConfiguration> registryCenterConfiguration) {
TreeNode treeData = new TreeNode();
for (RegistryCenterConfiguration conf : registryCenterConfiguration) {
String nameAndnameSpace = conf.getNameAndNamespace();
if (nameAndnameSpace.startsWith("/")) {
nameAndnameSpace = nameAndnameSpace.substring(1);
}
treeData = parseDirectory2Tree(nameAndnameSpace, treeData, conf.getNameAndNamespace(), conf.getDegree());
}
log.info("init tree data: {}", treeData);
}
use of com.vip.saturn.job.console.domain.TreeNode in project Saturn by vipshop.
the class InitRegistryCenterService method initTreeJson.
public static void initTreeJson(ArrayList<RegistryCenterConfiguration> registryCenterConfiguration, String zkBsk) {
TreeNode treeData = new TreeNode();
for (RegistryCenterConfiguration conf : registryCenterConfiguration) {
String nameAndnameSpace = conf.getNameAndNamespace();
if (nameAndnameSpace.startsWith("/")) {
nameAndnameSpace = nameAndnameSpace.substring(1);
}
treeData = parseDirectory2Tree(nameAndnameSpace, treeData, conf.getNameAndNamespace(), conf.getDegree());
}
ZKBSKEY_TO_TREENODE_MAP.put(zkBsk, treeData);
log.info("init {} tree data: {}", zkBsk, treeData);
}
Aggregations