Skip to content

Commit a6c6829

Browse files
committed
Merge branch 'develop'
2 parents c49fa79 + 2d8f21e commit a6c6829

File tree

11 files changed

+65
-59
lines changed

11 files changed

+65
-59
lines changed

redis-manager-dashboard/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@
5959
<artifactId>spring-boot-starter-log4j2</artifactId>
6060
</dependency>
6161

62-
<dependency>
63-
<groupId>org.springframework.boot</groupId>
64-
<artifactId>spring-boot-starter-websocket</artifactId>
65-
</dependency>
6662
<dependency>
6763
<groupId>org.springframework.boot</groupId>
6864
<artifactId>spring-boot-starter-test</artifactId>

redis-manager-dashboard/src/main/java/com/newegg/ec/redis/config/SystemConfig.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ public boolean getHumpbackEnabled() {
181181
}
182182

183183
public String getCurrentHost() {
184-
String ipAddress = LinuxInfoUtil.getIpAddress();
185-
if (Strings.isNullOrEmpty(ipAddress)) {
186-
ipAddress = currentHost;
184+
String host = currentHost;
185+
if (!Strings.isNullOrEmpty(host)) {
186+
return currentHost;
187187
}
188-
return ipAddress;
188+
return LinuxInfoUtil.getIp();
189189
}
190190
}

redis-manager-dashboard/src/main/java/com/newegg/ec/redis/controller/SystemConfigController.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@ public Result getHumpbackEnabled() {
4646
return Result.successResult(systemConfig.getHumpbackEnabled());
4747
}
4848

49-
@Deprecated
50-
@RequestMapping(value = "/getServerAddress", method = RequestMethod.GET)
51-
@ResponseBody
52-
public Result getServerAddress() throws SocketException {
53-
return Result.successResult(LinuxInfoUtil.getIpAddress() + SignUtil.COLON + systemConfig.getServerPort());
54-
}
55-
5649
@RequestMapping(value = "/getAuthorization", method = RequestMethod.GET)
5750
@ResponseBody
5851
public Result getAuthorization() {

redis-manager-dashboard/src/main/java/com/newegg/ec/redis/controller/oauth/AuthService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public boolean signOut() {
7373
String urlTemplate = "%s/api/%s?callback=%s";
7474
String authorizationServer = systemConfig.getAuthorizationServer();
7575
String siteKey = systemConfig.getSiteKey();
76-
String serverAddress = LinuxInfoUtil.getIpAddress() + SignUtil.COLON + systemConfig.getServerPort();
76+
String serverAddress = LinuxInfoUtil.getIp() + SignUtil.COLON + systemConfig.getServerPort();
7777
try {
7878
HttpClientUtil.get(String.format(urlTemplate, authorizationServer, siteKey, serverAddress));
7979
} catch (IOException e) {

redis-manager-dashboard/src/main/java/com/newegg/ec/redis/plugin/install/InstallationTemplate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ private String updateRedisPassword(String redisPassword, Cluster cluster) {
610610
private String generateConnectionNodes(Cluster cluster) {
611611
List<RedisNode> masterNodeList = redisService.getRedisMasterNodeList(cluster);
612612
// 随机选前3个节点
613-
StringBuffer nodes = new StringBuffer();
613+
StringBuilder nodes = new StringBuilder();
614614
int size = masterNodeList.size();
615615
RedisNode redisNode1 = masterNodeList.get(0);
616616
nodes.append(redisNode1.getHost()).append(COLON).append(redisNode1.getPort());

redis-manager-dashboard/src/main/java/com/newegg/ec/redis/plugin/install/entity/InstallationLogContainer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import java.util.concurrent.TimeUnit;
1212

1313
/**
14+
* TODO: 并发问题
15+
*
1416
* @author Jay.H.Zou
1517
* @date 4/5/2020
1618
*/

redis-manager-dashboard/src/main/java/com/newegg/ec/redis/plugin/install/service/AbstractNodeOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public boolean checkPorts(InstallationParam installationParam) {
107107
String ip = redisNode.getHost();
108108
int port = redisNode.getPort();
109109
// 如果端口能通,则认为该端口被占用
110-
if (NetworkUtil.telnet(ip, port)) {
110+
if (!NetworkUtil.checkFreePort(ip, port)) {
111111
InstallationLogContainer.appendLog(clusterName, "The port has been used, host: " + ip + ", port: " + port);
112112
return false;
113113
}

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

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
import ch.ethz.ssh2.Connection;
44
import com.google.common.base.Strings;
55
import com.newegg.ec.redis.entity.Machine;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
68

79
import java.net.InetAddress;
8-
import java.net.UnknownHostException;
10+
import java.net.NetworkInterface;
11+
import java.util.Enumeration;
912
import java.util.HashMap;
1013
import java.util.Map;
1114

@@ -19,35 +22,39 @@
1922
*/
2023
public class LinuxInfoUtil {
2124

25+
private static final Logger logger = LoggerFactory.getLogger(LinuxInfoUtil.class);
26+
2227
public static final String MEMORY_FREE = "memory_free";
2328

2429
public static final String VERSION = "version";
2530

2631
private LinuxInfoUtil() {
2732
}
2833

29-
public static String getIpAddress() {
30-
/*Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
31-
InetAddress ip;
32-
while (allNetInterfaces.hasMoreElements()) {
33-
NetworkInterface netInterface = allNetInterfaces.nextElement();
34-
if (netInterface.isLoopback() || netInterface.isVirtual() || !netInterface.isUp()) {
35-
continue;
36-
} else {
37-
Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
38-
while (addresses.hasMoreElements()) {
39-
ip = addresses.nextElement();
40-
if (ip instanceof Inet4Address) {
41-
return ip.getHostAddress();
34+
public static String getIp() {
35+
String ip = "";
36+
try {
37+
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
38+
NetworkInterface intf = en.nextElement();
39+
String name = intf.getName();
40+
if (!name.contains("docker") && !name.contains("lo")) {
41+
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
42+
//获得IP
43+
InetAddress inetAddress = enumIpAddr.nextElement();
44+
if (!inetAddress.isLoopbackAddress()) {
45+
String ipAddress = inetAddress.getHostAddress().toString();
46+
if (!ipAddress.contains("::")
47+
&& !ipAddress.contains("0:0:")
48+
&& !ipAddress.contains("fe80")
49+
&& !"127.0.0.1".equals(ip)) {
50+
ip = ipAddress;
51+
}
52+
}
4253
}
4354
}
4455
}
45-
}*/
46-
String ip = "";
47-
try {
48-
ip = InetAddress.getLocalHost().getHostAddress();
49-
} catch (UnknownHostException e) {
50-
// TODO Auto-generated catch block
56+
} catch (Exception e) {
57+
logger.error("get current ip failed.", e);
5158
ip = null;
5259
}
5360
return ip;

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

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,35 @@ public class NetworkUtil {
2222
private NetworkUtil() {
2323
}
2424

25-
/**
26-
* 监测端口是否在使用
27-
*
28-
* @param ip
29-
* @param port
30-
* @return
31-
*/
32-
public static final boolean telnet(String ip, int port) {
25+
public static boolean checkFreePort(String ip, int port) {
26+
try {
27+
return !connect(ip, port);
28+
} catch (Exception e) {
29+
logger.info(ip + ":" + port + " is free.");
30+
return true;
31+
}
32+
}
33+
34+
public static boolean telnet(String ip, int port) {
35+
try {
36+
return connect(ip, port);
37+
} catch (Exception e) {
38+
logger.warn(ip + ":" + port + " can't access.");
39+
return false;
40+
}
41+
}
42+
43+
private static boolean connect(String ip, int port) throws IOException {
3344
Socket socket = new Socket();
3445
try {
3546
socket.connect(new InetSocketAddress(ip, port), TIMEOUT);
3647
return socket.isConnected();
37-
} catch (Exception e) {
38-
logger.warn(ip + ":" + port + " can't access.");
3948
} finally {
4049
try {
4150
socket.close();
4251
} catch (IOException ignore) {
4352
}
4453
}
45-
return false;
4654
}
4755

4856
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public static String unzipToTargetPath(Machine machine, String filePath, String
128128
* @throws Exception
129129
*/
130130
public static String mkdir(Machine machine, String path, boolean sudo) throws Exception {
131-
StringBuffer command = new StringBuffer();
131+
StringBuilder command = new StringBuilder();
132132
if (sudo) {
133133
command.append("sudo ");
134134
}

0 commit comments

Comments
 (0)