Skip to content

Commit 1ef1bf4

Browse files
committed
Merge pull request #28 from qq254963746/develop
Develop
2 parents 066ac9b + 8a61816 commit 1ef1bf4

File tree

94 files changed

+2367
-678
lines changed

Some content is hidden

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

94 files changed

+2367
-678
lines changed

lts-admin/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@
4141
<artifactId>lts-core</artifactId>
4242
<version>${project.version}</version>
4343
</dependency>
44+
<dependency>
45+
<groupId>com.lts</groupId>
46+
<artifactId>lts-queue-api</artifactId>
47+
<version>${project.version}</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>com.lts</groupId>
51+
<artifactId>lts-queue-mysql</artifactId>
52+
<version>${project.version}</version>
53+
</dependency>
54+
<dependency>
55+
<groupId>com.lts</groupId>
56+
<artifactId>lts-queue-mongo</artifactId>
57+
<version>${project.version}</version>
58+
</dependency>
4459
<dependency>
4560
<groupId>log4j</groupId>
4661
<artifactId>log4j</artifactId>
Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,66 @@
11
package com.lts.job.web.cluster;
22

33
import com.lts.job.core.Application;
4+
import com.lts.job.core.cluster.Node;
5+
import com.lts.job.queue.*;
46

57
/**
68
* Robert HG (254963746@qq.com) on 6/5/15.
79
*/
8-
public class AdminApplication extends Application{
10+
public class AdminApplication extends Application {
911

12+
private CronJobQueue cronJobQueue;
13+
private ExecutableJobQueue executableJobQueue;
14+
private ExecutingJobQueue executingJobQueue;
15+
private JobFeedbackQueue jobFeedbackQueue;
16+
private NodeGroupStore nodeGroupStore;
17+
private Node node;
18+
19+
public Node getNode() {
20+
return node;
21+
}
22+
23+
public void setNode(Node node) {
24+
this.node = node;
25+
}
26+
27+
public CronJobQueue getCronJobQueue() {
28+
return cronJobQueue;
29+
}
30+
31+
public void setCronJobQueue(CronJobQueue cronJobQueue) {
32+
this.cronJobQueue = cronJobQueue;
33+
}
34+
35+
public ExecutableJobQueue getExecutableJobQueue() {
36+
return executableJobQueue;
37+
}
38+
39+
public void setExecutableJobQueue(ExecutableJobQueue executableJobQueue) {
40+
this.executableJobQueue = executableJobQueue;
41+
}
42+
43+
public ExecutingJobQueue getExecutingJobQueue() {
44+
return executingJobQueue;
45+
}
46+
47+
public void setExecutingJobQueue(ExecutingJobQueue executingJobQueue) {
48+
this.executingJobQueue = executingJobQueue;
49+
}
50+
51+
public NodeGroupStore getNodeGroupStore() {
52+
return nodeGroupStore;
53+
}
54+
55+
public void setNodeGroupStore(NodeGroupStore nodeGroupStore) {
56+
this.nodeGroupStore = nodeGroupStore;
57+
}
58+
59+
public JobFeedbackQueue getJobFeedbackQueue() {
60+
return jobFeedbackQueue;
61+
}
62+
63+
public void setJobFeedbackQueue(JobFeedbackQueue jobFeedbackQueue) {
64+
this.jobFeedbackQueue = jobFeedbackQueue;
65+
}
1066
}
Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.lts.job.web.cluster;
22

3-
import com.lts.job.core.Application;
43
import com.lts.job.core.cluster.Config;
54
import com.lts.job.core.cluster.Node;
6-
import com.lts.job.core.cluster.NodeType;
75
import com.lts.job.core.registry.NotifyEvent;
86
import com.lts.job.core.registry.NotifyListener;
97
import com.lts.job.core.registry.Registry;
@@ -13,7 +11,10 @@
1311
import com.lts.job.core.util.StringUtils;
1412
import com.lts.job.web.request.NodeRequest;
1513
import com.lts.job.web.support.AppConfigurer;
16-
import com.lts.job.web.support.db.NodeMemDB;
14+
import com.lts.job.web.support.memorydb.NodeMemDB;
15+
import org.springframework.beans.factory.InitializingBean;
16+
import org.springframework.beans.factory.annotation.Autowired;
17+
import org.springframework.beans.factory.annotation.Qualifier;
1718
import org.springframework.stereotype.Component;
1819

1920
import java.util.ArrayList;
@@ -23,41 +24,27 @@
2324
* Robert HG (254963746@qq.com) on 6/5/15.
2425
*/
2526
@Component
26-
public class RegistryService {
27+
public class RegistryService implements InitializingBean {
2728

28-
private final ConcurrentHashSet<String/*clusterName*/> map;
29+
private final ConcurrentHashSet<String/*clusterName*/> MAP = new ConcurrentHashSet<String>();
30+
private NodeMemDB nodeMemDB = new NodeMemDB();
2931

30-
private NodeMemDB nodeMemDB;
31-
32-
public RegistryService() {
33-
this.map = new ConcurrentHashSet<String>();
34-
this.nodeMemDB = new NodeMemDB();
35-
}
32+
@Autowired
33+
@Qualifier("application")
34+
AdminApplication application;
3635

3736
public synchronized void register(String clusterName) {
3837

39-
if (map.contains(clusterName)) {
38+
if (MAP.contains(clusterName)) {
4039
return;
4140
}
4241

43-
final Node node = new Node();
44-
node.setIdentity("LTS_admin_" + StringUtils.generateUUID());
45-
node.addListenNodeType(NodeType.JOB_CLIENT);
46-
node.addListenNodeType(NodeType.TASK_TRACKER);
47-
node.addListenNodeType(NodeType.JOB_TRACKER);
48-
49-
Config config = new Config();
50-
config.setIdentity(node.getIdentity());
51-
config.setNodeType(node.getNodeType());
52-
config.setRegistryAddress(AppConfigurer.getProperties("registry.address"));
42+
Config config = application.getConfig();
5343
config.setClusterName(clusterName);
5444

55-
Application application = new AdminApplication();
56-
application.setConfig(config);
57-
5845
Registry registry = RegistryFactory.getRegistry(config);
5946

60-
registry.subscribe(node, new NotifyListener() {
47+
registry.subscribe(application.getNode(), new NotifyListener() {
6148
@Override
6249
public void notify(NotifyEvent event, List<Node> nodes) {
6350
if (CollectionUtils.isEmpty(nodes)) {
@@ -74,14 +61,25 @@ public void notify(NotifyEvent event, List<Node> nodes) {
7461
}
7562
});
7663

77-
map.add(clusterName);
64+
MAP.add(clusterName);
7865
}
7966

8067
public List<String> getAllClusterNames() {
81-
return new ArrayList<String>(map.list());
68+
return new ArrayList<String>(MAP.list());
8269
}
8370

8471
public List<Node> getNodes(NodeRequest request) {
8572
return nodeMemDB.search(request);
8673
}
74+
75+
@Override
76+
public void afterPropertiesSet() throws Exception {
77+
String clusterNames = AppConfigurer.getProperties("clusterNames");
78+
if (StringUtils.isNotEmpty(clusterNames)) {
79+
String[] clusters = clusterNames.split(",");
80+
for (String cluster : clusters) {
81+
register(cluster.trim());
82+
}
83+
}
84+
}
8785
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.lts.job.web.controller.api;
2+
3+
import com.lts.job.core.domain.JobQueueRequest;
4+
import com.lts.job.core.domain.PageResponse;
5+
import com.lts.job.core.util.CollectionUtils;
6+
import com.lts.job.queue.domain.JobPo;
7+
import com.lts.job.web.cluster.AdminApplication;
8+
import com.lts.job.web.controller.AbstractController;
9+
import com.lts.job.web.vo.RestfulResponse;
10+
import org.springframework.beans.factory.annotation.Autowired;
11+
import org.springframework.web.bind.annotation.RequestMapping;
12+
import org.springframework.web.bind.annotation.RestController;
13+
14+
import java.util.List;
15+
16+
/**
17+
* @author Robert HG (254963746@qq.com) on 6/6/15.
18+
*/
19+
@RestController
20+
public class JobQueueApiController extends AbstractController {
21+
22+
@Autowired
23+
AdminApplication application;
24+
25+
@RequestMapping("/job-queue/cron-job-get")
26+
public RestfulResponse getCronJobList(JobQueueRequest request) {
27+
PageResponse<JobPo> pageResponse = application.getCronJobQueue().pageSelect(request);
28+
RestfulResponse response = new RestfulResponse();
29+
response.setSuccess(true);
30+
response.setResults(pageResponse.getResults());
31+
response.setRows(pageResponse.getRows());
32+
return response;
33+
}
34+
35+
@RequestMapping("/job-queue/executable-job-get")
36+
public RestfulResponse getExecutableJobList(JobQueueRequest request) {
37+
PageResponse<JobPo> pageResponse = application.getExecutableJobQueue().pageSelect(request);
38+
RestfulResponse response = new RestfulResponse();
39+
response.setSuccess(true);
40+
response.setResults(pageResponse.getResults());
41+
response.setRows(pageResponse.getRows());
42+
return response;
43+
}
44+
45+
@RequestMapping("/job-queue/executing-job-get")
46+
public RestfulResponse getExecutingJobList(JobQueueRequest request) {
47+
PageResponse<JobPo> pageResponse = application.getExecutingJobQueue().pageSelect(request);
48+
RestfulResponse response = new RestfulResponse();
49+
response.setSuccess(true);
50+
response.setResults(pageResponse.getResults());
51+
response.setRows(pageResponse.getRows());
52+
return response;
53+
}
54+
}

lts-admin/src/main/java/com/lts/job/web/controller/ui/UIController.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.lts.job.web.controller.ui;
22

3+
import com.lts.job.core.cluster.NodeType;
4+
import com.lts.job.queue.domain.NodeGroupPo;
5+
import com.lts.job.web.cluster.AdminApplication;
36
import com.lts.job.web.cluster.RegistryService;
47
import org.springframework.beans.factory.annotation.Autowired;
58
import org.springframework.stereotype.Controller;
@@ -16,6 +19,8 @@ public class UIController {
1619

1720
@Autowired
1821
RegistryService registryService;
22+
@Autowired
23+
AdminApplication application;
1924

2025
@RequestMapping("node/node-manager")
2126
public String nodeManagerUI(Model model) {
@@ -24,4 +29,28 @@ public String nodeManagerUI(Model model) {
2429
return "node-manager";
2530
}
2631

32+
@RequestMapping("job-queue/cron-job-queue")
33+
public String cronJobQueueUI(Model model) {
34+
setAttr(model);
35+
return "cron-job-queue";
36+
}
37+
38+
@RequestMapping("job-queue/executable-job-queue")
39+
public String executableJobQueueUI(Model model) {
40+
setAttr(model);
41+
return "executable-job-queue";
42+
}
43+
44+
@RequestMapping("job-queue/executing-job-queue")
45+
public String executingJobQueueUI(Model model) {
46+
setAttr(model);
47+
return "executing-job-queue";
48+
}
49+
50+
private void setAttr(Model model){
51+
List<NodeGroupPo> jobClientNodeGroups = application.getNodeGroupStore().getNodeGroup(NodeType.JOB_CLIENT);
52+
model.addAttribute("jobClientNodeGroups", jobClientNodeGroups);
53+
List<NodeGroupPo> taskTrackerNodeGroups = application.getNodeGroupStore().getNodeGroup(NodeType.TASK_TRACKER);
54+
model.addAttribute("taskTrackerNodeGroups", taskTrackerNodeGroups);
55+
}
2756
}

lts-admin/src/main/java/com/lts/job/web/request/NodeRequest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lts.job.web.request;
22

33
import com.lts.job.core.cluster.NodeType;
4+
import com.lts.job.core.domain.PageRequest;
45

56
import java.util.Date;
67

lts-admin/src/main/java/com/lts/job/web/request/PageRequest.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)