-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from forsake0120/add_virtual_host
dashboard-client支持内部IP,虚拟IP,虚拟端口
- Loading branch information
Showing
11 changed files
with
739 additions
and
550 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,5 @@ tmp/ | |
logs/ | ||
node_modules | ||
coverage-report | ||
.vscode | ||
.vscode | ||
*.factorypath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,76 +19,94 @@ | |
import java.io.Serializable; | ||
import java.util.Objects; | ||
|
||
import org.springframework.util.StringUtils; | ||
|
||
/** | ||
* Host and port definition | ||
* | ||
* @author chen.pengzhi ([email protected]) | ||
*/ | ||
public class HostAndPort implements Comparable<HostAndPort>, Serializable { | ||
|
||
private static final int serialVersionUID = 0x11; | ||
|
||
private String host; | ||
|
||
private int port; | ||
|
||
public HostAndPort() { | ||
} | ||
|
||
public HostAndPort(String host, int port) { | ||
this.host = host; | ||
this.port = port; | ||
} | ||
|
||
/** | ||
* Convert host & port to instance id | ||
* | ||
* @return instance id | ||
*/ | ||
public String toInstanceId() { | ||
return String.format("%s_%d", host, port); | ||
} | ||
|
||
public String getHost() { | ||
return host; | ||
} | ||
|
||
public void setHost(String host) { | ||
this.host = host; | ||
} | ||
|
||
public int getPort() { | ||
return port; | ||
} | ||
|
||
public void setPort(int port) { | ||
this.port = port; | ||
} | ||
|
||
@Override | ||
public int compareTo(HostAndPort o) { | ||
int hostSign = Integer.compare(host.compareTo(o.host), 0) << 2; | ||
int portSign = Integer.compare(port, o.port); | ||
return hostSign + portSign; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "HostAndPort{" + "host='" + host + '\'' + ", port=" + port + '}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
HostAndPort that = (HostAndPort) o; | ||
return getPort() == that.getPort() && Objects.equals(getHost(), that.getHost()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getHost(), getPort()); | ||
} | ||
private static final int serialVersionUID = 0x11; | ||
|
||
private String host; | ||
|
||
private String internalHost; | ||
|
||
private int port; | ||
|
||
// public HostAndPort() { | ||
// } | ||
|
||
public HostAndPort(String host, String interHost, int port) { | ||
this.host = host; | ||
this.port = port; | ||
this.internalHost = interHost; | ||
} | ||
|
||
/** | ||
* Convert host & port to instance id | ||
* | ||
* @return instance id | ||
*/ | ||
public String toInstanceId() { | ||
if (StringUtils.isEmpty(internalHost)) { | ||
return String.format("%s_%d", host, port); | ||
} else { | ||
return String.format("%s_%s_%d", host, internalHost, port); | ||
} | ||
} | ||
|
||
public String getInternalHost() { | ||
return "null".equals(internalHost) ? null : internalHost; | ||
} | ||
|
||
public void setInternalHost(String internalHost) { | ||
this.internalHost = internalHost; | ||
} | ||
|
||
public String getHost() { | ||
return host; | ||
} | ||
|
||
public void setHost(String host) { | ||
this.host = host; | ||
} | ||
|
||
public int getPort() { | ||
return port; | ||
} | ||
|
||
public void setPort(int port) { | ||
this.port = port; | ||
} | ||
|
||
@Override | ||
public int compareTo(HostAndPort o) { | ||
int hostSign = Integer.compare(host.compareTo(o.host), 0) << 2; | ||
int internalSign = Integer.compare(internalHost.compareTo(o.internalHost), 0) << 1; | ||
int portSign = Integer.compare(port, o.port); | ||
return hostSign + portSign + internalSign; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "HostAndPort{" + "host='" + host + '\'' + ", internalHost='" + internalHost + '\'' + ", port=" + port + '}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
HostAndPort that = (HostAndPort) o; | ||
return getPort() == that.getPort() && Objects.equals(getHost(), that.getHost()) && Objects.equals(getInternalHost(), that.getInternalHost()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getHost(), getInternalHost(), getPort()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,18 +16,20 @@ | |
*/ | ||
package com.alipay.sofa.dashboard.client.registry.zookeeper; | ||
|
||
import com.alipay.sofa.dashboard.client.model.common.Application; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.lang.NonNull; | ||
import org.springframework.lang.Nullable; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.net.URI; | ||
import java.net.URLDecoder; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.lang.NonNull; | ||
import org.springframework.lang.Nullable; | ||
import org.springframework.util.StringUtils; | ||
|
||
import com.alipay.sofa.dashboard.client.model.common.Application; | ||
|
||
/** | ||
* @author [email protected] | ||
* @date 2019-08-29 09:18 | ||
|
@@ -45,14 +47,15 @@ final class ZookeeperRegistryUtils { | |
/** | ||
* Convert an instance definition into session node name | ||
* | ||
* @param instance application instance | ||
* @param instance | ||
* application instance | ||
* @return session node name | ||
*/ | ||
@NonNull | ||
static String toSessionNode(Application instance) { | ||
String appId = String.format("%s:%d?startTime=%d&lastRecover=%d&state=%s", | ||
instance.getHostName(), instance.getPort(), instance.getStartTime(), | ||
instance.getLastRecover(), instance.getAppState()); | ||
String appId = String.format("%s:%d?internalHost=%s&startTime=%d&lastRecover=%d&state=%s", | ||
instance.getHostName(), instance.getPort(), instance.getInternalHost(), | ||
instance.getStartTime(), instance.getLastRecover(), instance.getAppState()); | ||
String appName = instance.getAppName(); | ||
return String.format("%s/%s/%s", ZookeeperConstants.SOFA_BOOT_CLIENT_INSTANCE, appName, | ||
appId); | ||
|
@@ -61,7 +64,8 @@ static String toSessionNode(Application instance) { | |
/** | ||
* Parse session node to application instance. | ||
* | ||
* @param sessionNode session node path | ||
* @param sessionNode | ||
* session node path | ||
* @return {@code null}, if this session path is not a legal one | ||
*/ | ||
@Nullable | ||
|
@@ -90,6 +94,7 @@ static Application parseSessionNode(String sessionNode) { | |
|
||
Application application = new Application(); | ||
application.setAppName(appName); | ||
application.setInternalHost(query.get("internalHost")); | ||
application.setHostName(instanceUri.getHost()); | ||
application.setPort(instanceUri.getPort()); | ||
application.setAppState(query.get("state")); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,8 @@ | |
*/ | ||
package com.alipay.sofa.dashboard.redis.config; | ||
|
||
import com.alipay.sofa.dashboard.redis.io.LettuceConnFactoryProvider; | ||
import com.alipay.sofa.dashboard.redis.io.RedisRecordExporter; | ||
import com.alipay.sofa.dashboard.redis.io.RedisRecordImporter; | ||
import com.alipay.sofa.dashboard.redis.properties.SofaDashboardRedisProperties; | ||
import io.lettuce.core.resource.DefaultClientResources; | ||
import java.io.Closeable; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
|
@@ -31,7 +28,12 @@ | |
import org.springframework.data.redis.core.StringRedisTemplate; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.io.Closeable; | ||
import com.alipay.sofa.dashboard.redis.io.LettuceConnFactoryProvider; | ||
import com.alipay.sofa.dashboard.redis.io.RedisRecordExporter; | ||
import com.alipay.sofa.dashboard.redis.io.RedisRecordImporter; | ||
import com.alipay.sofa.dashboard.redis.properties.SofaDashboardRedisProperties; | ||
|
||
import io.lettuce.core.resource.DefaultClientResources; | ||
|
||
/** | ||
* @author chen.pengzhi ([email protected]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.