Skip to content

Commit b2467f3

Browse files
committed
Merge branch 'develop'
# Conflicts: # build/build.sh
2 parents 7c0ef1a + cfe0467 commit b2467f3

File tree

8 files changed

+49
-50
lines changed

8 files changed

+49
-50
lines changed

build/build.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
project_path=$(cd `dirname $0`; pwd)
3+
cd $project_path
4+
ls | grep -v '\.sh' | xargs rm -rf
5+
mkdir conf/
6+
mkdir web/
7+
mkdir logs/
8+
cd ../redis-manager-dashboard
9+
mvn clean package -Dmaven.test.skip=true
10+
mv -f target/classes/data/ $project_path/
11+
mv -f target/classes/application.yml $project_path/conf/
12+
mv -f target/classes/log4j2.xml $project_path/conf/
13+
rm -rf target/classes/com/
14+
mv -f target/classes/* $project_path/web/
15+
mv -f target/lib/ $project_path/
16+
cp target/*.jar $project_path/

redis-manager-dashboard/src/main/java/com/newegg/ec/redis/client/RedisClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class RedisClient implements IRedisClient {
2626

2727
private static final String OK = "OK";
2828

29-
private static final String PONG = "pong";
29+
private static final String PONG = "PONG";
3030

3131
/**
3232
* info subkey
@@ -60,6 +60,7 @@ public RedisClient(RedisURI redisURI) {
6060
}
6161
} catch (JedisConnectionException e) {
6262
// try next nodes
63+
close();
6364
}
6465
}
6566
}
@@ -531,7 +532,8 @@ public String clusterSaveConfig() {
531532

532533
@Override
533534
public boolean ping() {
534-
return Objects.equals(jedis.ping(), PONG);
535+
String ping = jedis.ping();
536+
return !Strings.isNullOrEmpty(ping) && Objects.equals(ping.toUpperCase(), PONG);
535537
}
536538

537539
@Override

redis-manager-dashboard/src/main/java/com/newegg/ec/redis/client/RedisClientFactory.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,14 @@
1313
public class RedisClientFactory {
1414

1515
public static RedisClusterClient buildRedisClusterClient(RedisURI redisURI) {
16-
RedisClusterClient redisClusterClient = new RedisClusterClient(redisURI);
17-
return redisClusterClient;
16+
return new RedisClusterClient(redisURI);
1817
}
1918

2019
public static RedisClusterClient buildRedisClusterClient(RedisNode redisNode, String requirePass) {
2120
RedisURI redisURI = new RedisURI(redisNode.getHost(), redisNode.getPort(), requirePass);
2221
return buildRedisClusterClient(redisURI);
2322
}
2423

25-
public static RedisClusterClient buildRedisClusterClient(RedisNode redisNode) {
26-
return buildRedisClusterClient(redisNode, null);
27-
}
28-
29-
public static RedisClusterClient buildRedisClusterClient(HostAndPort hostAndPort, String requirePass) {
30-
RedisURI redisURI = new RedisURI(hostAndPort, requirePass);
31-
return buildRedisClusterClient(redisURI);
32-
}
33-
3424
public static RedisClient buildRedisClient(RedisURI redisURI) {
3525
RedisClient redisClient = new RedisClient(redisURI);
3626
if (redisClient.getJedisClient() == null) {
@@ -45,14 +35,12 @@ public static RedisClient buildRedisClient(RedisNode redisNode) {
4535

4636
public static RedisClient buildRedisClient(RedisNode redisNode, String requirePass) {
4737
RedisURI redisURI = new RedisURI(redisNode.getHost(), redisNode.getPort(), requirePass);
48-
RedisClient redisClient = buildRedisClient(redisURI);
49-
return redisClient;
38+
return buildRedisClient(redisURI);
5039
}
5140

5241
public static RedisClient buildRedisClient(HostAndPort hostAndPort, String requirePass) {
5342
RedisURI redisURI = new RedisURI(hostAndPort, requirePass);
54-
RedisClient redisClient = buildRedisClient(redisURI);
55-
return redisClient;
43+
return buildRedisClient(redisURI);
5644
}
5745

5846
}

redis-manager-dashboard/src/main/java/com/newegg/ec/redis/service/impl/RedisNodeService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ public class RedisNodeService implements IRedisNodeService {
4242

4343
@Override
4444
public List<RedisNode> getRedisNodeListByClusterId(Integer clusterId) {
45+
Cluster cluster = clusterService.getClusterById(clusterId);
4546
try {
46-
Cluster cluster = clusterService.getClusterById(clusterId);
4747
List<RedisNode> realRedisNodeList = redisService.getRedisNodeList(cluster);
4848
List<RedisNode> dbRedisNodeList = redisNodeDao.selectRedisNodeListByClusterId(clusterId);
4949
List<RedisNode> redisNodeList = mergeRedisNode(realRedisNodeList, dbRedisNodeList);
5050
return sortRedisNodeList(redisNodeList);
5151
} catch (Exception e) {
52-
logger.error("Get redis node list failed.", e);
52+
logger.error("Get redis node list failed, cluster: " + cluster.getClusterName(), e);
5353
return null;
5454
}
5555
}

redis-manager-dashboard/src/main/java/com/newegg/ec/redis/service/impl/RedisService.java

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import org.slf4j.LoggerFactory;
1616
import org.springframework.beans.factory.annotation.Autowired;
1717
import org.springframework.beans.factory.annotation.Value;
18-
import org.springframework.context.ApplicationListener;
19-
import org.springframework.context.event.ContextRefreshedEvent;
2018
import org.springframework.stereotype.Service;
2119
import redis.clients.jedis.ClusterReset;
2220
import redis.clients.jedis.HostAndPort;
@@ -40,7 +38,7 @@
4038
* @date 7/26/2019
4139
*/
4240
@Service
43-
public class RedisService implements IRedisService, ApplicationListener<ContextRefreshedEvent> {
41+
public class RedisService implements IRedisService {
4442

4543
private static final Logger logger = LoggerFactory.getLogger(RedisService.class);
4644

@@ -53,11 +51,6 @@ public class RedisService implements IRedisService, ApplicationListener<ContextR
5351
@Value("${redis-manager.monitor.slow-log-limit:100}")
5452
private int slowLogLimit;
5553

56-
@Override
57-
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
58-
59-
}
60-
6154
@Override
6255
public Map<String, String> getNodeInfo(HostAndPort hostAndPort, String redisPassword) {
6356
RedisClient redisClient = null;
@@ -83,8 +76,9 @@ public Map<String, Map<String, Long>> getKeyspaceInfo(Cluster cluster) {
8376
List<RedisNode> redisMasterNodeList = getRedisMasterNodeList(cluster);
8477
Map<String, Map<String, Long>> keyspaceInfoMap = new LinkedHashMap<>();
8578
redisMasterNodeList.forEach(redisNode -> {
86-
RedisClient redisClient = RedisClientFactory.buildRedisClient(redisNode, cluster.getRedisPassword());
79+
RedisClient redisClient = null;
8780
try {
81+
redisClient = RedisClientFactory.buildRedisClient(redisNode, cluster.getRedisPassword());
8882
Map<String, String> keyspaceInfo = redisClient.getInfo(RedisClient.KEYSPACE);
8983
if (keyspaceInfo.isEmpty()) {
9084
return;
@@ -143,15 +137,16 @@ public List<RedisNode> getRedisNodeList(Cluster cluster) {
143137
RedisURI redisURI = new RedisURI(cluster.getNodes(), cluster.getRedisPassword());
144138
String redisMode = cluster.getRedisMode();
145139
List<RedisNode> nodeList = new ArrayList<>();
146-
RedisClient redisClient = RedisClientFactory.buildRedisClient(redisURI);
140+
RedisClient redisClient = null;
147141
try {
142+
redisClient = RedisClientFactory.buildRedisClient(redisURI);
148143
if (STANDALONE.equalsIgnoreCase(redisMode)) {
149144
nodeList = redisClient.nodes();
150145
} else if (CLUSTER.equalsIgnoreCase(redisMode)) {
151146
nodeList = redisClient.clusterNodes();
152147
}
153148
} catch (Exception e) {
154-
logger.error("Get redis node list failed, " + cluster, e);
149+
logger.error("Get redis node list failed, " + cluster.getClusterName(), e);
155150
} finally {
156151
close(redisClient);
157152
}
@@ -193,7 +188,6 @@ public Map<String, String> getClusterInfo(Cluster cluster) {
193188

194189
@Override
195190
public List<RedisSlowLog> getRedisSlowLog(Cluster cluster, SlowLogParam slowLogParam) {
196-
197191
List<RedisNode> nodeList;
198192
String node = slowLogParam.getNode();
199193
if (Strings.isNullOrEmpty(node)) {
@@ -206,12 +200,10 @@ public List<RedisSlowLog> getRedisSlowLog(Cluster cluster, SlowLogParam slowLogP
206200
}
207201
List<RedisSlowLog> redisSlowLogList = new ArrayList<>();
208202
for (RedisNode redisNode : nodeList) {
209-
HostAndPort hostAndPort = null;
203+
HostAndPort hostAndPort = new HostAndPort(redisNode.getHost(), redisNode.getPort());
210204
RedisClient redisClient = null;
211205
try {
212-
hostAndPort = new HostAndPort(redisNode.getHost(), redisNode.getPort());
213-
RedisURI redisURI = new RedisURI(hostAndPort, cluster.getRedisPassword());
214-
redisClient = RedisClientFactory.buildRedisClient(redisURI);
206+
redisClient = RedisClientFactory.buildRedisClient(redisNode, cluster.getRedisPassword());
215207
List<Slowlog> slowLogs = redisClient.getSlowLog(slowLogLimit);
216208
for (Slowlog slowLog : slowLogs) {
217209
RedisSlowLog redisSlowLog = new RedisSlowLog(hostAndPort, slowLog);
@@ -341,8 +333,7 @@ public boolean clusterForget(Cluster cluster, RedisNode forgetNode) {
341333
}
342334
RedisClient redisClient = null;
343335
try {
344-
RedisURI redisURI = new RedisURI(redisNode.getHost(), redisNode.getPort(), redisPassword);
345-
redisClient = RedisClientFactory.buildRedisClient(redisURI);
336+
redisClient = RedisClientFactory.buildRedisClient(redisNode, redisPassword);
346337
redisClient.clusterForget(forgetNodeId);
347338
} catch (Exception e) {
348339
logger.error("Forget cluster node failed, cluster name: " + clusterName + ", bad node: " + redisNode.getHost() + ":" + redisNode.getPort(), e);
@@ -352,9 +343,7 @@ public boolean clusterForget(Cluster cluster, RedisNode forgetNode) {
352343
}
353344
RedisClient redisClient = null;
354345
try {
355-
// time out
356-
RedisURI redisURI = new RedisURI(forgetNode.getHost(), forgetNode.getPort(), redisPassword);
357-
redisClient = RedisClientFactory.buildRedisClient(redisURI);
346+
redisClient = RedisClientFactory.buildRedisClient(forgetNode, redisPassword);
358347
// Forget itself
359348
redisClient.clusterReset(ClusterReset.HARD);
360349
return true;

redis-manager-dashboard/src/main/java/com/newegg/ec/redis/util/LinuxInfoUtil.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
import com.newegg.ec.redis.entity.Machine;
66
import com.newegg.ec.redis.entity.Result;
77

8-
import java.net.Inet4Address;
9-
import java.net.InetAddress;
10-
import java.net.NetworkInterface;
11-
import java.net.SocketException;
8+
import java.net.*;
129
import java.util.Enumeration;
1310
import java.util.HashMap;
1411
import java.util.Map;
@@ -31,7 +28,7 @@ private LinuxInfoUtil() {
3128
}
3229

3330
public static String getIpAddress() throws SocketException {
34-
Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
31+
/*Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
3532
InetAddress ip;
3633
while (allNetInterfaces.hasMoreElements()) {
3734
NetworkInterface netInterface = allNetInterfaces.nextElement();
@@ -46,8 +43,15 @@ public static String getIpAddress() throws SocketException {
4643
}
4744
}
4845
}
46+
}*/
47+
String ip = "";
48+
try {
49+
ip = InetAddress.getLocalHost().getHostAddress();
50+
} catch (UnknownHostException e) {
51+
// TODO Auto-generated catch block
52+
ip = "127.0.0.1";
4953
}
50-
return "127.0.0.1";
54+
return ip;
5155
}
5256

5357
public static final boolean login(Machine machine) throws Exception {

redis-manager-dashboard/src/main/java/com/newegg/ec/redis/util/RedisNodeInfoUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ private RedisNodeInfoUtil() {
112112

113113
private static final BigDecimal BIG_DECIMAL_1024 = new BigDecimal(1024);
114114

115-
public static final NodeInfo parseInfoToObject(Map<String, String> infoMap, NodeInfo lastTimeNodeInfo) {
115+
public static NodeInfo parseInfoToObject(Map<String, String> infoMap, NodeInfo lastTimeNodeInfo) {
116116
JSONObject infoJSONObject = new JSONObject();
117117
long keys = 0;
118118
long expires = 0;

redis-manager-dashboard/src/main/java/com/newegg/ec/redis/util/RedisUtil.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private RedisUtil() {
7373
* @return
7474
* @throws IOException
7575
*/
76-
public static final Map<String, String> parseInfoToMap(String info) throws IOException {
76+
public static Map<String, String> parseInfoToMap(String info) throws IOException {
7777
Map<String, String> infoMap = new LinkedHashMap<>();
7878
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(info.getBytes(Charset.forName("utf8"))), Charset.forName("utf8")));
7979
String line;
@@ -92,7 +92,7 @@ public static final Map<String, String> parseInfoToMap(String info) throws IOExc
9292
return infoMap;
9393
}
9494

95-
public static final Set<HostAndPort> nodesToHostAndPortSet(String nodes) {
95+
public static Set<HostAndPort> nodesToHostAndPortSet(String nodes) {
9696
String[] nodeList = SignUtil.splitByCommas(nodes);
9797
int length = nodeList.length;
9898
Set<HostAndPort> hostAndPortSet = new HashSet<>(length);
@@ -106,7 +106,7 @@ public static final Set<HostAndPort> nodesToHostAndPortSet(String nodes) {
106106
return hostAndPortSet;
107107
}
108108

109-
public static final HostAndPort nodesToHostAndPort(String node) {
109+
public static HostAndPort nodesToHostAndPort(String node) {
110110
Set<HostAndPort> hostAndPortSet = nodesToHostAndPortSet(node);
111111
return hostAndPortSet.iterator().next();
112112
}

0 commit comments

Comments
 (0)