Skip to content
Merged
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 @@ -30,8 +30,9 @@ public class NodeMemoryDB extends MemoryDB {
" port, " +
" nodeGroup, " +
" createTime, " +
" threads)" +
" VALUES (?,?,?,?,?,?,?,?,?)";
" threads," +
" hostName)" +
" VALUES (?,?,?,?,?,?,?,?,?,?)";

private String deleteSQL = "DELETE FROM lts_node where identity = ?";

Expand All @@ -50,6 +51,7 @@ private void createTable() {
" nodeGroup varchar(64) ," +
" createTime bigint ," +
" threads int ," +
" hostName varchar(64) ," +
" PRIMARY KEY (identity))";

try {
Expand Down Expand Up @@ -78,7 +80,8 @@ public void addNode(List<Node> nodes) {
node.getPort(),
node.getGroup(),
node.getCreateTime(),
node.getThreads()
node.getThreads(),
node.getHostName()
);
} catch (Exception e) {
LOGGER.error("Insert {} error!", node, e);
Expand Down Expand Up @@ -139,6 +142,7 @@ public List<Node> handle(ResultSet rs) throws SQLException {
node.setCreateTime(rs.getLong("createTime"));
node.setThreads(rs.getInt("threads"));
node.setAvailable(rs.getInt("available") == 1);
node.setHostName(rs.getString("hostName"));
nodes.add(node);
}
return nodes;
Expand Down
6 changes: 3 additions & 3 deletions lts-admin/src/main/webapp/main/node-manager.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@
}
},
{
title: 'IP', dataIndex: 'ip', width: 140, renderer: function (v, obj) {
title: '机器', dataIndex: 'ip', width: 140, renderer: function (v, obj) {
if (obj['nodeType'] == 'JOB_TRACKER') {
return obj['ip'] + ":" + obj['port'];
return obj['hostName'] + "<br/>(" + obj['ip'] + ":" + obj['port'] + ")";
}
return obj['ip'];
return obj['hostName'] + "<br/>(" + obj['ip'] + ")";
}
},
{
Expand Down
9 changes: 9 additions & 0 deletions lts-core/src/main/java/com/lts/core/cluster/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Node {
private NodeType nodeType;
private String ip;
private Integer port;
private String hostName;
private String group;
private Long createTime = SystemClock.now();
// 线程个数
Expand All @@ -30,6 +31,14 @@ public class Node {

private String fullString;

public String getHostName() {
return hostName;
}

public void setHostName(String hostName) {
this.hostName = hostName;
}

public boolean isAvailable() {
return available;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ public static String getLocalHost() {
return address == null ? LOCALHOST : address.getHostAddress();
}

public static String getLocalHostName(){
InetAddress address = getLocalAddress();
if(address == null){
return "localhost";
}
return address.getHostName();
}

/**
* 遍历本地网卡,返回第一个合理的IP。
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static <T extends Node> T create(Class<T> clazz, Config config) {
try {
T node = clazz.newInstance();
node.setIp(NetUtils.getLocalHost());
node.setHostName(NetUtils.getLocalHostName());
node.setGroup(config.getNodeGroup());
node.setThreads(config.getWorkThreads());
node.setPort(config.getListenPort());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public static Node parse(String fullPath) {
node.setCreateTime(Long.valueOf(value));
} else if ("isAvailable".equals(key)) {
node.setAvailable(Boolean.valueOf(value));
} else if("hostName".equals(key)){
node.setHostName(value);
}
}
return node;
Expand Down Expand Up @@ -93,7 +95,9 @@ public static String getFullPath(Node node) {
.append("&createTime=")
.append(node.getCreateTime())
.append("&isAvailable=")
.append(node.isAvailable());
.append(node.isAvailable())
.append("&hostName=")
.append(node.getHostName());

return path.toString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lts.example.benchmark;

import com.lts.example.support.MasterChangeListenerImpl;
import com.lts.example.support.MemoryStatus;
import com.lts.jobtracker.JobTracker;
import com.lts.jobtracker.support.policy.OldDataDeletePolicy;

Expand Down Expand Up @@ -48,13 +49,14 @@ public static void main(String[] args) {
jobTracker.addConfig("job.queue", "mongo");
// mongo 配置
jobTracker.addConfig("mongo.addresses", "127.0.0.1:27017"); // 多个地址用逗号分割
jobTracker.addConfig("mongo.database", "lts2");
jobTracker.addConfig("mongo.database", "lts3");
// 这个是对于 返回给客户端 任务的 老数据删除策略
jobTracker.setOldDataHandler(new OldDataDeletePolicy());
// 设置 zk 客户端用哪个, 可选 zkclient(默认), curator
jobTracker.addConfig("zk.client", "zkclient");
// 启动节点
jobTracker.start();
MemoryStatus.print();
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public class TestJobRunner implements JobRunner {
@Override
public Result run(Job job) throws Throwable {
try {
Thread.sleep(1000L);

if (job.getRetryTimes() > 5) {
return new Result(Action.EXECUTE_FAILED, "重试次数超过5次了,放过你吧!");
}

if (SystemClock.now() % 2 == 1) {
return new Result(Action.EXECUTE_LATER, "稍后执行");
}
// Thread.sleep(1000L);
//
// if (job.getRetryTimes() > 5) {
// return new Result(Action.EXECUTE_FAILED, "重试次数超过5次了,放过你吧!");
// }
//
// if (SystemClock.now() % 2 == 1) {
// return new Result(Action.EXECUTE_LATER, "稍后执行");
// }

// TODO 业务逻辑
LOGGER.info("我要执行:" + job);
Expand Down
4 changes: 2 additions & 2 deletions lts-example/src/main/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

log4j.rootLogger=WARN,stdout
log4j.rootLogger=INFO,stdout

log4j.appender.stdout.Threshold=WARN
log4j.appender.stdout.Threshold=INFO
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%-5p] [%d{HH:mm:ss}] %c - %m%n
Expand Down