提交 ee65e002 编写于 作者: A ascrutae

fix:#75

上级 cffa3e1d
......@@ -15,7 +15,7 @@ public class NetUtils {
private static ILog logger = LogManager.getLogger(NetUtils.class);
public static final String LOCALHOST = "127.0.0.1";
public static final String ANYHOST = "0.0.0.0";
private static final String[] ANY_HOST = {"0.0.0.0", "::0"};
private static final Pattern IP_PATTERN = Pattern.compile("\\d{1,3}(\\.\\d{1,3}){3,5}$");
public static InetAddress getLocalAddress() {
......@@ -68,6 +68,16 @@ public class NetUtils {
return false;
String name = address.getHostAddress();
// 不能是0.0.0.0 也不能是127.0.0.1 并且还得符合IP的正则
return (name != null && !ANYHOST.equals(name) && !LOCALHOST.equals(name) && IP_PATTERN.matcher(name).matches());
return (name != null && !isAnyHost(name) && !LOCALHOST.equals(name) && IP_PATTERN.matcher
(name).matches());
}
public static boolean isAnyHost(String host){
for (String s : ANY_HOST) {
if (s.equals(host)){
return true;
}
}
return false;
}
}
......@@ -5,10 +5,12 @@ import com.a.eye.skywalking.network.grpc.server.SpanStorageServer;
import com.a.eye.skywalking.network.grpc.server.TraceSearchServer;
import com.a.eye.skywalking.network.listener.server.SpanStorageServerListener;
import com.a.eye.skywalking.network.listener.server.TraceSearchListener;
import io.grpc.netty.NettyServerBuilder;
import io.netty.channel.nio.NioEventLoopGroup;
import java.io.IOException;
import java.net.InetSocketAddress;
public class Server {
private io.grpc.Server server;
......@@ -33,13 +35,14 @@ public class Server {
}
}
public static TransferServiceBuilder newBuilder(int port) {
return new TransferServiceBuilder(port);
public static TransferServiceBuilder newBuilder(String host, int port) {
return new TransferServiceBuilder(host, port);
}
public static class TransferServiceBuilder {
private TransferServiceBuilder(int port) {
serverBuilder = NettyServerBuilder.forPort(port);
private TransferServiceBuilder(String host, int port) {
serverBuilder = NettyServerBuilder.forAddress(new InetSocketAddress
(host, port));
serverBuilder.maxConcurrentCallsPerConnection(4);
}
......
......@@ -19,6 +19,8 @@ import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import static com.a.eye.skywalking.registry.assist.NetUtils.isAnyHost;
/**
* Main Class of the routing server.
* It starts server in a sequence:
......@@ -46,9 +48,11 @@ public class Main {
center.start(fetchRegistryCenterConfig());
center.subscribe(Config.StorageNode.SUBSCRIBE_PATH, RoutingService.getRouter());
Server.newBuilder(Config.Server.PORT).addSpanStorageService(new SpanStorageListenerImpl()).addTraceSearchService(new TraceSearchListenerImpl()).build().start();
Server.newBuilder(Config.Server.HOST,Config.Server.PORT).addSpanStorageService(new
SpanStorageListenerImpl()).addTraceSearchService(new TraceSearchListenerImpl()).build().start();
center.register(Config.RegistryCenter.PATH_PREFIX + NetUtils.getLocalAddress().getHostAddress() + ":" + Config.Server.PORT);
center.register(Config.RegistryCenter.PATH_PREFIX + fetchHostOfStorageServerBinding
() + ":" + Config.Server.PORT);
logger.info("Skywalking routing service was started.");
Thread.currentThread().join();
} catch (Exception e) {
......@@ -60,6 +64,14 @@ public class Main {
}
}
private static String fetchHostOfStorageServerBinding(){
if (isAnyHost(Config.Server.HOST)){
return NetUtils.getLocalAddress().getHostAddress();
}
return Config.Server.HOST;
}
private static void initConfig() throws IllegalAccessException, IOException {
Properties properties = new Properties();
try {
......
......@@ -2,6 +2,9 @@ package com.a.eye.skywalking.routing.config;
public class Config {
public static class Server {
public static String HOST = "0.0.0.0";
public static int PORT = 23000;
public static String REST_SERVICE_HOST = "0.0.0.0";
......
# the host that routing server binding
#server.host=0.0.0.0
# the port which routing server listening
server.port=23000
# the ip that rest api service binding
......
......@@ -22,6 +22,7 @@ import java.io.IOException;
import java.util.Map;
import java.util.Properties;
import static com.a.eye.skywalking.registry.assist.NetUtils.isAnyHost;
import static com.a.eye.skywalking.storage.config.Config.RegistryCenter.PATH_PREFIX;
/**
......@@ -48,7 +49,9 @@ public class Main {
DataFilesManager.init();
server = Server.newBuilder(Config.Server.PORT).addSpanStorageService(new StorageListener())
server = Server.newBuilder(Config.Server.HOST, Config.Server.PORT)
.addSpanStorageService(new
StorageListener())
.addAsyncTraceSearchService(new SearchListener()).build();
server.start();
......@@ -77,7 +80,16 @@ public class Main {
registerConfig.setProperty(ZookeeperConfig.AUTH_SCHEMA, Config.RegistryCenter.AUTH_SCHEMA);
registerConfig.setProperty(ZookeeperConfig.AUTH_INFO, Config.RegistryCenter.AUTH_INFO);
registryCenter.start(registerConfig);
registryCenter.register(PATH_PREFIX + NetUtils.getLocalAddress().getHostAddress() + ":" + Config.Server.PORT);
registryCenter.register(PATH_PREFIX + fetchHostOfStorageServerBinding() + ":" + Config
.Server.PORT);
}
private static String fetchHostOfStorageServerBinding(){
if (isAnyHost(Config.Server.HOST)){
return NetUtils.getLocalAddress().getHostAddress();
}
return Config.Server.HOST;
}
private static void initConfig() throws IllegalAccessException, IOException {
......
......@@ -5,6 +5,8 @@ package com.a.eye.skywalking.storage.config;
*/
public class Config {
public static class Server {
public static String HOST = "0.0.0.0";
public static int PORT = 34000;
}
......
# the host that storage server binding
#server.host=0.0.0.0
# the port which storage server listening
server.port=34000
#
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册