Skip to content

Commit 2aac6b5

Browse files
committed
first
0 parents commit 2aac6b5

File tree

348 files changed

+81181
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

348 files changed

+81181
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/*
2+
target/*
3+
tree-source.iml

pom.xml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.lzz</groupId>
8+
<artifactId>tree-source</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<parent>
12+
<groupId>org.springframework.boot</groupId>
13+
<artifactId>spring-boot-starter-parent</artifactId>
14+
<version>1.5.2.RELEASE</version>
15+
</parent>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.springframework.boot</groupId>
20+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-devtools</artifactId>
25+
<optional>true</optional>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-test</artifactId>
30+
<scope>test</scope>
31+
</dependency>
32+
<dependency>
33+
<groupId>net.sf.json-lib</groupId>
34+
<artifactId>json-lib</artifactId>
35+
<version>2.4</version>
36+
<classifier>jdk15</classifier>
37+
</dependency>
38+
<dependency>
39+
<groupId>com.fasterxml.jackson.core</groupId>
40+
<artifactId>jackson-databind</artifactId>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.apache.curator</groupId>
44+
<artifactId>curator-recipes</artifactId>
45+
<version>2.8.0</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.apache.curator</groupId>
49+
<artifactId>curator-client</artifactId>
50+
<version>2.8.0</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>mysql</groupId>
54+
<artifactId>mysql-connector-java</artifactId>
55+
<version>6.0.6</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>redis.clients</groupId>
59+
<artifactId>jedis</artifactId>
60+
<version>2.9.0</version>
61+
</dependency>
62+
</dependencies>
63+
64+
<properties>
65+
<java.version>1.8</java.version>
66+
</properties>
67+
68+
<build>
69+
<plugins>
70+
<plugin>
71+
<groupId>org.springframework.boot</groupId>
72+
<artifactId>spring-boot-maven-plugin</artifactId>
73+
</plugin>
74+
</plugins>
75+
</build>
76+
77+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.lzz;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
/**
6+
* Created by lzz on 2018/3/18.
7+
*/
8+
9+
@SpringBootApplication
10+
public class Application {
11+
12+
public static void main(String[] args) {
13+
SpringApplication.run(Application.class, args);
14+
}
15+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.lzz.control;
2+
3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.ui.Model;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
7+
/**
8+
* Created by lzz on 2018/3/18.
9+
*/
10+
@Controller
11+
public class IndexController {
12+
@RequestMapping("/index")
13+
public String index(Model model) {
14+
String page = "index";
15+
return page;
16+
}
17+
18+
@RequestMapping("/welcome")
19+
public String welcome(Model model) {
20+
String page = "welcome";
21+
return page;
22+
}
23+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.lzz.control;
2+
3+
import com.lzz.logic.SourceLogic;
4+
import com.lzz.model.SourceType;
5+
import com.lzz.model.Tnode;
6+
import org.springframework.stereotype.Controller;
7+
import org.springframework.ui.Model;
8+
import org.springframework.util.StringUtils;
9+
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.bind.annotation.RequestMethod;
11+
import org.springframework.web.bind.annotation.RequestParam;
12+
import org.springframework.web.bind.annotation.ResponseBody;
13+
import javax.annotation.Resource;
14+
15+
/**
16+
* Created by lzz on 2018/3/18.
17+
*/
18+
@Controller
19+
public class SourceControl {
20+
@Resource
21+
SourceLogic logic;
22+
23+
@RequestMapping("/source")
24+
public String index(@RequestParam SourceType type, Model model) {
25+
String page = "welcome";
26+
switch (type){
27+
case zk:
28+
page = "zk";
29+
break;
30+
case hbase:
31+
page = "hbase";
32+
break;
33+
case kafka:
34+
page = "kafka";
35+
break;
36+
case mysql:
37+
page = "mysql";
38+
break;
39+
case redis:
40+
page = "redis";
41+
break;
42+
}
43+
return page;
44+
}
45+
46+
@RequestMapping(value="/get-path-children", method = RequestMethod.GET)
47+
@ResponseBody
48+
public Tnode getPathChildren(@RequestParam String address,
49+
@RequestParam(value="path", defaultValue="/") String path,
50+
@RequestParam SourceType sourceType) throws Exception {
51+
52+
if( StringUtils.isEmpty(address) || address.length() < 10 ){
53+
return null;
54+
}
55+
Tnode tnode = new Tnode();
56+
tnode.setText( path );
57+
tnode.setId( path );
58+
tnode.setType("parent");
59+
tnode.setSourceType( sourceType );
60+
tnode = logic.getList( address, tnode );
61+
return tnode;
62+
}
63+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.lzz.dao;
2+
3+
import com.lzz.model.Tnode;
4+
5+
/**
6+
* Created by lzz on 2018/3/18.
7+
*/
8+
public interface ITreeSource {
9+
Tnode getTnodeList(Tnode tnode) throws Exception;
10+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.lzz.dao;
2+
3+
import com.lzz.model.Tnode;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
/**
9+
* Created by lzz on 2018/3/18.
10+
*/
11+
public abstract class SourceBase implements ITreeSource {
12+
protected Tnode getTnodeList(SourceBase sourceBase, Tnode tnode) throws Exception {
13+
this.tnodeTemplate(this, tnode);
14+
this.close();
15+
return tnode;
16+
}
17+
18+
@Override
19+
public Tnode getTnodeList(Tnode tnode) throws Exception {
20+
return getTnodeList(this, tnode);
21+
}
22+
23+
protected Tnode tnodeTemplate(SourceBase sourceBase, Tnode tnode) throws Exception {
24+
String path = tnode.getId();
25+
List<Tnode> childNode = tnode.getChildren();
26+
List<String> childrenList = sourceBase.childrenList( path );
27+
for(int i = 0; i < childrenList.size(); i++){
28+
String childName = childrenList.get(i);
29+
Tnode tnode1 = new Tnode();
30+
tnode1.setText( childName );
31+
32+
String childPath = "";
33+
if( "/".equals( path ) ){
34+
childPath = path + childName;
35+
}else{
36+
childPath = path + "/" + childName;
37+
}
38+
tnode1.setId( childPath );
39+
int childrenNum = sourceBase.getNumChildren( childPath );
40+
if( childrenNum > 0 ){
41+
tnode1.setType("parent");
42+
List<Tnode> grandson = new ArrayList<>();
43+
Tnode ellipsisNode = new Tnode();
44+
ellipsisNode.setType("ellipsis");
45+
ellipsisNode.setId( childPath + "/..." );
46+
ellipsisNode.setText("...");
47+
grandson.add( ellipsisNode );
48+
tnode1.setChildren( grandson );
49+
}else{
50+
tnode1.setType("leaf");
51+
}
52+
childNode.add( tnode1);
53+
if( i > 50 ){
54+
childNode.add( new Tnode(path+ "/...", "...", "ellipsis") );
55+
break;
56+
}
57+
}
58+
return tnode;
59+
60+
}
61+
62+
public abstract int getNumChildren(String childPath) throws Exception;
63+
64+
65+
public abstract List<String> childrenList(String path) throws Exception;
66+
67+
public abstract void close();
68+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.lzz.dao.kafka;
2+
3+
/**
4+
* Created by lzz on 2018/3/19.
5+
*/
6+
public interface IKafkaClient {
7+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.lzz.dao.kafka;
2+
3+
import com.google.common.collect.Lists;
4+
import com.lzz.dao.SourceBase;
5+
import com.lzz.dao.zk.CuratorClient;
6+
7+
import java.util.*;
8+
9+
/**
10+
* Created by lzz on 2018/3/19.
11+
*/
12+
public class KafkaClient extends SourceBase implements IKafkaClient {
13+
private static final String CONSUMER_PATH = "/consumers";
14+
private Map<String, Set<String>> topicConsumerMap = new HashMap<>();
15+
private SourceBase curatorClient;
16+
17+
public KafkaClient(String zk){
18+
curatorClient = new CuratorClient(zk);
19+
initTopicConsumerMap();
20+
}
21+
22+
private void initTopicConsumerMap(){
23+
24+
try {
25+
List<String> cList = curatorClient.childrenList( CONSUMER_PATH );
26+
for(String consumer : cList){
27+
List<String> topics = curatorClient.childrenList( CONSUMER_PATH + "/" + consumer + "/offsets" );
28+
for(String topic : topics){
29+
if( topicConsumerMap.get( topic ) == null ){
30+
topicConsumerMap.put( topic, new HashSet<>());
31+
}
32+
topicConsumerMap.get( topic ).add( consumer );
33+
}
34+
}
35+
} catch (Exception ignore) {
36+
37+
}
38+
}
39+
40+
@Override
41+
public int getNumChildren(String childPath) throws Exception {
42+
int childrenNum = 0;
43+
if( childPath.equals("/") ){
44+
childrenNum = getTopicNum();
45+
}else if( childPath.split("/").length == 2 ){
46+
childrenNum = getConsumerNum(childPath);
47+
}
48+
return childrenNum;
49+
}
50+
51+
@Override
52+
public List<String> childrenList(String path) throws Exception {
53+
List<String> cList = new ArrayList<>();
54+
if( path.equals("/") ){
55+
cList = curatorClient.childrenList("/brokers/topics");
56+
}else if( path.split("/").length == 2 ){
57+
Set<String> consumerList = topicConsumerMap.get( path.split("/")[1] );
58+
cList = Lists.newArrayList(consumerList);
59+
}
60+
return cList;
61+
}
62+
63+
@Override
64+
public void close() {
65+
this.curatorClient.close();
66+
}
67+
68+
private int getConsumerNum(String childPath) throws Exception {
69+
String topic = childPath.split("/")[1];
70+
int num = 0;
71+
Set<String> consumerSet = topicConsumerMap.get( topic );
72+
if( null != consumerSet ){
73+
num = consumerSet.size();
74+
}
75+
return num;
76+
}
77+
78+
private int getTopicNum() throws Exception {
79+
int num = curatorClient.getNumChildren("/brokers/topics");
80+
return num;
81+
}
82+
83+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.lzz.dao.redis;
2+
3+
/**
4+
* Created by lzz on 2018/3/19.
5+
*/
6+
public interface IRedis {
7+
}

0 commit comments

Comments
 (0)