From 293981f2a253bd7b63577da3f2a26ebc23fafe8f Mon Sep 17 00:00:00 2001 From: wusheng Date: Tue, 6 Dec 2016 16:55:47 +0800 Subject: [PATCH] move NetUtils for refaction. --- .../com/a/eye/skywalking/registry/assist}/NetUtils.java | 7 +------ .../data/file/2016_12_06_16_55_18_667_1000 | 1 + .../src/main/java/com/a/eye/skywalking/storage/Main.java | 4 ++-- .../a/eye/skywalking/storage/boot/ElasticBootstrap.java | 9 ++++++++- .../storage/data/index/IndexOperatorFactory.java | 5 +++-- .../skywalking-storage/src/test/java/StorageThread.java | 4 +--- .../skywalking/storage/data/index/IndexOperatorTest.java | 2 +- 7 files changed, 17 insertions(+), 15 deletions(-) rename {skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/util => skywalking-commons/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/assist}/NetUtils.java (93%) create mode 100644 skywalking-storage-center/data/file/2016_12_06_16_55_18_667_1000 diff --git a/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/util/NetUtils.java b/skywalking-commons/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/assist/NetUtils.java similarity index 93% rename from skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/util/NetUtils.java rename to skywalking-commons/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/assist/NetUtils.java index 9d13b38ff..84bbf7804 100644 --- a/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/util/NetUtils.java +++ b/skywalking-commons/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/assist/NetUtils.java @@ -1,8 +1,7 @@ -package com.a.eye.skywalking.storage.util; +package com.a.eye.skywalking.registry.assist; import com.a.eye.skywalking.logging.api.ILog; import com.a.eye.skywalking.logging.api.LogManager; -import com.a.eye.skywalking.storage.config.Config; import java.net.InetAddress; import java.net.NetworkInterface; @@ -71,8 +70,4 @@ public class NetUtils { // 不能是0.0.0.0 也不能是127.0.0.1 并且还得符合IP的正则 return (name != null && !ANYHOST.equals(name) && !LOCALHOST.equals(name) && IP_PATTERN.matcher(name).matches()); } - - public static int getIndexServerPort(){ - return Config.Server.PORT + 1000; - } } diff --git a/skywalking-storage-center/data/file/2016_12_06_16_55_18_667_1000 b/skywalking-storage-center/data/file/2016_12_06_16_55_18_667_1000 new file mode 100644 index 000000000..89cb71e14 --- /dev/null +++ b/skywalking-storage-center/data/file/2016_12_06_16_55_18_667_1000 @@ -0,0 +1 @@ +JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1JappR1 \ No newline at end of file diff --git a/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/Main.java b/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/Main.java index cdb128b05..0c9e69ad5 100644 --- a/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/Main.java +++ b/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/Main.java @@ -16,7 +16,7 @@ import com.a.eye.skywalking.storage.data.file.DataFilesManager; import com.a.eye.skywalking.storage.data.index.IndexOperatorFactory; import com.a.eye.skywalking.storage.listener.SearchListener; import com.a.eye.skywalking.storage.listener.StorageListener; -import com.a.eye.skywalking.storage.util.NetUtils; +import com.a.eye.skywalking.registry.assist.NetUtils; import java.io.IOException; import java.util.Map; @@ -43,7 +43,7 @@ public class Main { initConfig(); HealthCollector.init(SERVER_REPORTER_NAME); - new ElasticBootstrap().boot(NetUtils.getIndexServerPort()); + new ElasticBootstrap().boot(); IndexOperatorFactory.initOperatorPool(); DataFilesManager.init(); diff --git a/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/boot/ElasticBootstrap.java b/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/boot/ElasticBootstrap.java index 32e39f327..66529304d 100644 --- a/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/boot/ElasticBootstrap.java +++ b/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/boot/ElasticBootstrap.java @@ -2,6 +2,7 @@ package com.a.eye.skywalking.storage.boot; import com.a.eye.skywalking.logging.api.ILog; import com.a.eye.skywalking.logging.api.LogManager; +import com.a.eye.skywalking.storage.config.Config; import java.io.File; import java.io.IOException; @@ -22,7 +23,8 @@ public class ElasticBootstrap { this.elasticHome = fetchElasticHome(); } - public void boot(int port) throws IOException { + public void boot() throws IOException { + int port = getIndexServerPort(); ElasticConfigModifier modifier = new ElasticConfigModifier(elasticHome); modifier.replaceConfig(port); @@ -48,4 +50,9 @@ public class ElasticBootstrap { public String fetchElasticHome() { return System.getProperty(DATA_INDEX_HOME, DEVELOP_RUNTIME_ELASTIC_HOME); } + + public static int getIndexServerPort(){ + return Config.Server.PORT + 1000; + } + } diff --git a/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/data/index/IndexOperatorFactory.java b/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/data/index/IndexOperatorFactory.java index 91fbfbf21..612bee17a 100644 --- a/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/data/index/IndexOperatorFactory.java +++ b/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/data/index/IndexOperatorFactory.java @@ -1,9 +1,10 @@ package com.a.eye.skywalking.storage.data.index; +import com.a.eye.skywalking.storage.boot.ElasticBootstrap; import com.a.eye.skywalking.storage.config.Config; import com.a.eye.skywalking.storage.data.exception.BorrowIndexOperatorFromPoolFailedException; import com.a.eye.skywalking.storage.data.exception.IndexOperatorInitializeFailedException; -import com.a.eye.skywalking.storage.util.NetUtils; +import com.a.eye.skywalking.registry.assist.NetUtils; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; @@ -18,7 +19,7 @@ public class IndexOperatorFactory { public static IndexOperator createIndexOperator() { try { return new IndexOperator(new PreBuiltTransportClient(Settings.EMPTY).addTransportAddress( - new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), NetUtils.getIndexServerPort() + new InetSocketTransportAddress(InetAddress.getLoopbackAddress(), ElasticBootstrap.getIndexServerPort() ))); } catch (Exception e) { throw new IndexOperatorInitializeFailedException("Failed to initialize operator.", e); diff --git a/skywalking-storage-center/skywalking-storage/src/test/java/StorageThread.java b/skywalking-storage-center/skywalking-storage/src/test/java/StorageThread.java index 1550f798a..338b87b91 100644 --- a/skywalking-storage-center/skywalking-storage/src/test/java/StorageThread.java +++ b/skywalking-storage-center/skywalking-storage/src/test/java/StorageThread.java @@ -1,16 +1,14 @@ import com.a.eye.skywalking.network.Client; import com.a.eye.skywalking.network.grpc.AckSpan; import com.a.eye.skywalking.network.grpc.RequestSpan; -import com.a.eye.skywalking.network.grpc.SendResult; import com.a.eye.skywalking.network.grpc.TraceId; import com.a.eye.skywalking.network.grpc.client.SpanStorageClient; import com.a.eye.skywalking.network.listener.client.StorageClientListener; -import com.a.eye.skywalking.storage.util.NetUtils; +import com.a.eye.skywalking.registry.assist.NetUtils; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.locks.LockSupport; public class StorageThread extends Thread { diff --git a/skywalking-storage-center/skywalking-storage/src/test/java/com/a/eye/skywalking/storage/data/index/IndexOperatorTest.java b/skywalking-storage-center/skywalking-storage/src/test/java/com/a/eye/skywalking/storage/data/index/IndexOperatorTest.java index 443d56e11..96387d656 100644 --- a/skywalking-storage-center/skywalking-storage/src/test/java/com/a/eye/skywalking/storage/data/index/IndexOperatorTest.java +++ b/skywalking-storage-center/skywalking-storage/src/test/java/com/a/eye/skywalking/storage/data/index/IndexOperatorTest.java @@ -4,7 +4,7 @@ import com.a.eye.skywalking.network.grpc.RequestSpan; import com.a.eye.skywalking.network.grpc.TraceId; import com.a.eye.skywalking.storage.data.file.DataFileNameDesc; import com.a.eye.skywalking.storage.data.spandata.RequestSpanData; -import com.a.eye.skywalking.storage.util.NetUtils; +import com.a.eye.skywalking.registry.assist.NetUtils; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress;