diff --git a/skywalking-storage-center/pom.xml b/skywalking-storage-center/pom.xml index ea38b9765..7f2cff9c3 100644 --- a/skywalking-storage-center/pom.xml +++ b/skywalking-storage-center/pom.xml @@ -19,11 +19,6 @@ - - com.a.eye - skywalking-logging-api - ${project.version} - com.a.eye skywalking-network @@ -36,18 +31,18 @@ com.a.eye - skywalking-health-report - ${project.version} + skywalking-registry + ${project.parent.version} com.a.eye skywalking-logging-impl-log4j2 - ${project.version} + ${project.parent.version} com.a.eye - skywalking-registry - ${project.version} + skywalking-health-report + ${project.parent.version} diff --git a/skywalking-storage-center/skywalking-storage/bin/storageServer.sh b/skywalking-storage-center/skywalking-storage/bin/storageServer.sh new file mode 100644 index 000000000..d58ac0b2f --- /dev/null +++ b/skywalking-storage-center/skywalking-storage/bin/storageServer.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +STORAGE_SERVER_BIN="$0" + +# Get standard environment variables +STORAGE_SERVER_BIN_DIR=`dirname "$STORAGE_SERVER_BIN"` +STORAGE_PREFIX="${STORAGE_SERVER_BIN_DIR}/.." +STORAGE_LOG_DIR="${STORAGE_SERVER_BIN_DIR}/../log" +STORAGE_CFG_DIR="${STORAGE_SERVER_BIN_DIR}/../config" + +#echo $STORAGE_SERVER_BIN_DIR +#set java home +if [ "$JAVA_HOME" != "" ]; then + JAVA="$JAVA_HOME/bin/java" +else + JAVA=java +fi + +CLASSPATH="$STORAGE_CFG_DIR:$CLASSPATH" + +for i in "${STORAGE_SERVER_BIN_DIR}"/../lib/*.jar +do + CLASSPATH="$i:$CLASSPATH" +done + +echo "CLASSPATH=$CLASSPATH" + + +$JAVA ${JAVA_OPTS} -DDATA_INDEX_HOME=${STORAGE_SERVER_BIN_DIR}/../data/index -classpath $CLASSPATH com.a.eye.skywalking.storage.Main >> ${STORAGE_SERVER_BIN_DIR}/../logs/storage-server.log & 2>&1& diff --git a/skywalking-storage-center/skywalking-storage/lib/dataindex-es-5.0.1.zip b/skywalking-storage-center/skywalking-storage/lib/dataindex-es-5.0.1.zip old mode 100644 new mode 100755 index e506eeae9..ac17dd32a Binary files a/skywalking-storage-center/skywalking-storage/lib/dataindex-es-5.0.1.zip and b/skywalking-storage-center/skywalking-storage/lib/dataindex-es-5.0.1.zip differ diff --git a/skywalking-storage-center/skywalking-storage/pom.xml b/skywalking-storage-center/skywalking-storage/pom.xml index f318aa003..5c4d339e4 100644 --- a/skywalking-storage-center/skywalking-storage/pom.xml +++ b/skywalking-storage-center/skywalking-storage/pom.xml @@ -25,6 +25,12 @@ transport 5.0.1 + + org.yaml + snakeyaml + 1.17 + test + @@ -39,8 +45,129 @@ ${project.build.sourceEncoding} + + org.apache.maven.plugins + maven-resources-plugin + 2.6 + + + copy-resources + package + + copy-resources + + + ${project.build.directory}/install/config + + + src/main/resources + false + + + + + + copy-start-script + package + + copy-resources + + + ${project.build.directory}/install/bin + + + bin + false + + + + + + + + maven-dependency-plugin + + + copy-dependencies + package + + copy-dependencies + + + + + ${project.build.directory}/install/lib + false + true + runtime + compile + + + + maven-jar-plugin + + + *.properties + *.xml + + ${project.build.directory}/install/lib + + + + org.apache.maven.plugins + maven-antrun-plugin + 1.8 + + + unpack + compile + + + + + + + + + + + + + + run + + + + clean + pre-clean + + + + + + + run + + + + tar + package + + + + + + + + + run + + + + - - 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 363dfeb8d..101f5b7ef 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 @@ -9,6 +9,7 @@ import com.a.eye.skywalking.registry.RegistryCenterFactory; import com.a.eye.skywalking.registry.api.CenterType; import com.a.eye.skywalking.registry.api.RegistryCenter; import com.a.eye.skywalking.registry.impl.zookeeper.ZookeeperConfig; +import com.a.eye.skywalking.storage.boot.ElasticBooter; import com.a.eye.skywalking.storage.config.Config; import com.a.eye.skywalking.storage.config.ConfigInitializer; import com.a.eye.skywalking.storage.data.file.DataFilesManager; @@ -28,7 +29,7 @@ import static com.a.eye.skywalking.storage.config.Config.RegistryCenter.PATH_PRE */ public class Main { - private static final ILog logger = LogManager.getLogger(Main.class); + private static final ILog logger = LogManager.getLogger(Main.class); private static final String SERVER_REPORTER_NAME = "DataConsumer Server"; static { @@ -42,6 +43,7 @@ public class Main { initializeParam(); HealthCollector.init(SERVER_REPORTER_NAME); + new ElasticBooter().boot(NetUtils.getIndexServerPort()); IndexOperatorFactory.initOperatorPool(); DataFilesManager.init(); @@ -59,6 +61,7 @@ public class Main { logger.info("SkyWalking storage server started."); Thread.currentThread().join(); } catch (Throwable e) { + e.printStackTrace(); logger.error("SkyWalking storage server start failure.", e); } finally { provider.stop(); @@ -73,8 +76,7 @@ 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 + NetUtils.getLocalAddress().getHostAddress() + ":" + Config.Server.PORT); } private static void initializeParam() throws IllegalAccessException, IOException { diff --git a/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/boot/ElasticBooter.java b/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/boot/ElasticBooter.java index eb2c43572..f715c2a91 100644 --- a/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/boot/ElasticBooter.java +++ b/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/boot/ElasticBooter.java @@ -1,21 +1,30 @@ package com.a.eye.skywalking.storage.boot; +import com.a.eye.skywalking.logging.api.ILog; +import com.a.eye.skywalking.logging.api.LogManager; + import java.io.File; +import java.io.IOException; /** * Created by xin on 2016/11/20. */ public class ElasticBooter { + private static ILog logger = LogManager.getLogger(ElasticBooter.class); + public static final String DATA_INDEX_HOME = "DATA_INDEX_HOME"; + private static final String DEVELOP_RUNTIME_ELASTIC_HOME = + ElasticBooter.class.getResource("/").getPath() + ".." + File.separator + "install" + File.separator + "data" + + File.separator + "index"; private String elasticHome; - public ElasticBooter(String elasticHome) { - this.elasticHome = elasticHome; + public ElasticBooter() { + this.elasticHome = fetchElasticHome(); } - public void boot(int port) { + public void boot(int port) throws IOException { ElasticConfigModifier modifier = new ElasticConfigModifier(elasticHome); - modifier.append(port).replaceConfig(); + modifier.replaceConfig(port); ElasticServer elasticServer = new ElasticServer(elasticHome); @@ -26,8 +35,17 @@ public class ElasticBooter { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { - elasticServer.stop(); + try { + elasticServer.stop(); + } catch (IOException e) { + logger.error("Failed to stop elastic server.", e); + } } }); } + + + public String fetchElasticHome() { + return System.getProperty(DATA_INDEX_HOME, DEVELOP_RUNTIME_ELASTIC_HOME); + } } diff --git a/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/boot/ElasticConfigModifier.java b/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/boot/ElasticConfigModifier.java index d094eb4c1..65f9e390a 100644 --- a/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/boot/ElasticConfigModifier.java +++ b/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/boot/ElasticConfigModifier.java @@ -1,16 +1,44 @@ package com.a.eye.skywalking.storage.boot; +import com.a.eye.skywalking.logging.api.ILog; +import com.a.eye.skywalking.logging.api.LogManager; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Files; + +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; + class ElasticConfigModifier { + private static ILog logger = LogManager.getLogger(ElasticConfigModifier.class); + private File elasticConfigDir = null; + public ElasticConfigModifier(String elasticHome) { - + this.elasticConfigDir = new File(elasticHome, "config"); + if (!elasticConfigDir.exists()) { + logger.warn("Elastic search config dir is not exists. Will create it"); + elasticConfigDir.mkdirs(); + } } - public ElasticConfigModifier append(int port) { - return null; + public void replaceConfig(int port) throws IOException { + File newConfigFile = new File(elasticConfigDir, "elasticsearch.yml"); + Files.copy(ElasticConfigModifier.class.getResourceAsStream("/elasticsearch.yml"), newConfigFile.toPath(), + REPLACE_EXISTING); + appendingNewConfig(port, newConfigFile); + return; } - public void replaceConfig() { - + private void appendingNewConfig(int port, File newConfigFile) throws IOException { + FileWriter writer = null; + try { + writer = new FileWriter(newConfigFile, true); + writer.write("transport.tcp.port: " + port); + writer.flush(); + } finally { + writer.close(); + } } } diff --git a/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/boot/ElasticServer.java b/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/boot/ElasticServer.java index 4820efac5..38c853e8e 100644 --- a/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/boot/ElasticServer.java +++ b/skywalking-storage-center/skywalking-storage/src/main/java/com/a/eye/skywalking/storage/boot/ElasticServer.java @@ -1,21 +1,48 @@ package com.a.eye.skywalking.storage.boot; +import com.a.eye.skywalking.logging.api.ILog; +import com.a.eye.skywalking.logging.api.LogManager; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + class ElasticServer { - private boolean started; + + private static ILog logger = LogManager.getLogger(ElasticServer.class); + private String elasticBinDir; public ElasticServer(String elasticHome) { - + this.elasticBinDir = elasticHome + File.separator + "bin" + File.separator; } - public void stop() { + public void stop() throws IOException { + int pid = readServerPID(); + if (pid == -1) { + return; + } + Runtime.getRuntime().exec("kill -9 " + pid); } - public boolean isStarted() { - return started; + public boolean isStarted() throws IOException { + return false; } - public void start() { - + public void start() throws IOException { + Runtime.getRuntime().exec(elasticBinDir + "elasticsearch -p " + elasticBinDir + "elastic.pid -d"); } + + + private int readServerPID() { + try { + BufferedReader reader = new BufferedReader(new FileReader(elasticBinDir + "elastic.pid")); + return Integer.parseInt(reader.readLine()); + } catch (IOException e) { + logger.error("Failed to elastic server pid", e); + } + return -1; + } + } diff --git a/skywalking-storage-center/skywalking-storage/src/main/resources/log4j.properties b/skywalking-storage-center/skywalking-storage/src/main/resources/log4j.properties index 17c194cc6..d9bf017d4 100644 --- a/skywalking-storage-center/skywalking-storage/src/main/resources/log4j.properties +++ b/skywalking-storage-center/skywalking-storage/src/main/resources/log4j.properties @@ -1,19 +1,13 @@ # logger # -log4j.rootLogger=CONSOLE,Rolling_File +log4j.rootLogger=Rolling_File log4j.logger.org.apache=OFF log4j.logger.io.netty=OFF log4j.org.elasticsearch=OFF log4j.logger.com.a.eye.skywalking.network.dependencies.io.netty=OFF -# Console Appender # -log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender -log4j.appender.CONSOLE.Target=System.out -log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout -log4j.appender.CONSOLE.layout.ConversionPattern=%d %-5p %c{1}:%L - %m%n - log4j.appender.Rolling_File=org.apache.log4j.RollingFileAppender log4j.appender.Rolling_File.Threshold=WARN -log4j.appender.Rolling_File.File=logs/storage-server-log4j.log +log4j.appender.Rolling_File.File=../logs/storage-server-log4j.log log4j.appender.Rolling_File.Append=true log4j.appender.Rolling_File.MaxFileSize=100MB log4j.appender.Rolling_File.MaxBackupIndex=5 diff --git a/skywalking-storage-center/skywalking-storage/src/main/resources/log4j2.xml b/skywalking-storage-center/skywalking-storage/src/main/resources/log4j2.xml index 0d5cd5ce7..ef8f05935 100644 --- a/skywalking-storage-center/skywalking-storage/src/main/resources/log4j2.xml +++ b/skywalking-storage-center/skywalking-storage/src/main/resources/log4j2.xml @@ -4,7 +4,7 @@ - @@ -17,7 +17,6 @@ - diff --git a/skywalking-storage-center/skywalking-storage/src/test/java/StorageClient.java b/skywalking-storage-center/skywalking-storage/src/test/java/StorageClient.java index cd18e2c9f..268c5034e 100644 --- a/skywalking-storage-center/skywalking-storage/src/test/java/StorageClient.java +++ b/skywalking-storage-center/skywalking-storage/src/test/java/StorageClient.java @@ -8,8 +8,9 @@ import com.a.eye.skywalking.network.grpc.*; import static com.a.eye.skywalking.network.grpc.SpanStorageServiceGrpc.newStub; public class StorageClient { + private static ManagedChannel channel = - ManagedChannelBuilder.forAddress("10.128.35.79", 34000).usePlaintext(true).build(); + ManagedChannelBuilder.forAddress("127.0.0.1", 34000).usePlaintext(true).build(); private static SpanStorageServiceGrpc.SpanStorageServiceStub spanStorageServiceStub = newStub(channel); @@ -19,28 +20,26 @@ public class StorageClient { public static void main(String[] args) throws InterruptedException { - long startTime = System.currentTimeMillis(); - - - for (int i = 0; i < 1000000; i++) { + for (int i = 0; i < 1; i++) { + long value = System.currentTimeMillis(); RequestSpan requestSpan = - RequestSpan.newBuilder().setSpanType(1).setAddress("127.0.0.1").setApplicationId("1").setCallType("1") - .setLevelId(0).setProcessNo("19287").setStartDate(System.currentTimeMillis()).setTraceId( - TraceId.newBuilder().addSegments(201611).addSegments(System.currentTimeMillis()).addSegments(8504828) - .addSegments(2277).addSegments(53).addSegments(3).build()).setUserId("1") - .setViewPointId("http://localhost:8080/wwww/test/helloWorld").build(); + RequestSpan.newBuilder().setSpanType(1).setAddress("127.0.0.1").setApplicationId("1") + .setCallType("1").setLevelId(0).setProcessNo("19287") + .setStartDate(System.currentTimeMillis()).setTraceId( + TraceId.newBuilder().addSegments(201611).addSegments(value) + .addSegments(8504828).addSegments(2277).addSegments(53).addSegments(3).build()) + .setUserId("1").setViewPointId("http://localhost:8080/wwww/test/helloWorld").build(); AckSpan ackSpan = AckSpan.newBuilder().setLevelId(0).setCost(10).setTraceId( - TraceId.newBuilder().addSegments(201611).addSegments(System.currentTimeMillis()).addSegments(8504828) - .addSegments(2277).addSegments(53).addSegments(3).build()).setStatusCode(0) + TraceId.newBuilder().addSegments(201611).addSegments(value).addSegments(8504828).addSegments(2277) + .addSegments(53).addSegments(3).build()).setStatusCode(0) .setViewpointId("http://localhost:8080/wwww/test/helloWorld").build(); StreamObserver ackSpanStreamObserver = spanStorageServiceStub.storageACKSpan(new StreamObserver() { @Override public void onNext(SendResult sendResult) { - } @Override @@ -70,7 +69,7 @@ public class StorageClient { endTime2 = System.currentTimeMillis(); } }); - for (int j = 0; j < 10; j++) { + for (int j = 0; j < 1; j++) { requestSpanStreamObserver.onNext(requestSpan); ackSpanStreamObserver.onNext(ackSpan); @@ -87,7 +86,7 @@ public class StorageClient { requestSpanStreamObserver.onCompleted(); - if(i % 1_000 == 0){ + if (i % 1_000 == 0) { System.out.println(i); } diff --git a/skywalking-storage-center/skywalking-storage/src/test/java/com/a/eye/skywalking/storage/SearchClient.java b/skywalking-storage-center/skywalking-storage/src/test/java/com/a/eye/skywalking/storage/SearchClient.java index 8edc4b69c..92fff7856 100644 --- a/skywalking-storage-center/skywalking-storage/src/test/java/com/a/eye/skywalking/storage/SearchClient.java +++ b/skywalking-storage-center/skywalking-storage/src/test/java/com/a/eye/skywalking/storage/SearchClient.java @@ -36,7 +36,7 @@ public class SearchClient { StreamObserver searchResult = searchServiceStub.search(serverStreamObserver); searchResult.onNext(QueryTask.newBuilder().setTraceId( - TraceId.newBuilder().addSegments(201611).addSegments(1479267274243L).addSegments(8504828) + TraceId.newBuilder().addSegments(201611).addSegments(1479717228982L).addSegments(8504828) .addSegments(2277).addSegments(53).addSegments(3).build()).setTaskId(1).build()); searchResult.onCompleted(); diff --git a/skywalking-storage-center/skywalking-storage/src/test/java/com/a/eye/skywalking/storage/boot/ElasticBooterTest.java b/skywalking-storage-center/skywalking-storage/src/test/java/com/a/eye/skywalking/storage/boot/ElasticBooterTest.java new file mode 100644 index 000000000..4aaab8f1e --- /dev/null +++ b/skywalking-storage-center/skywalking-storage/src/test/java/com/a/eye/skywalking/storage/boot/ElasticBooterTest.java @@ -0,0 +1,32 @@ +package com.a.eye.skywalking.storage.boot; + +import org.junit.After; +import org.junit.Test; + +import java.io.File; + +import static com.a.eye.skywalking.storage.boot.ElasticBooter.DATA_INDEX_HOME; +import static org.junit.Assert.assertEquals; + +public class ElasticBooterTest { + private String bastPath = ElasticBooterTest.class.getResource("/").getPath() + ".." + File.separator; + + + @Test + public void fetchElasticHomeWithoutProperty() { + ElasticBooter booter = new ElasticBooter(); + assertEquals("Elastic Home :", booter.fetchElasticHome(), bastPath + "install/data/index"); + } + + @Test + public void fetchElasticHomeWithProperty() { + System.setProperty(DATA_INDEX_HOME, "/test/test"); + ElasticBooter fetcher = new ElasticBooter(); + assertEquals("Elastic Home :", fetcher.fetchElasticHome(), "/test/test"); + } + + @After + public void tearUp() { + System.clearProperty(DATA_INDEX_HOME); + } +} diff --git a/skywalking-storage-center/skywalking-storage/src/test/java/com/a/eye/skywalking/storage/boot/ElasticConfigModifierTest.java b/skywalking-storage-center/skywalking-storage/src/test/java/com/a/eye/skywalking/storage/boot/ElasticConfigModifierTest.java new file mode 100644 index 000000000..d5f04fbca --- /dev/null +++ b/skywalking-storage-center/skywalking-storage/src/test/java/com/a/eye/skywalking/storage/boot/ElasticConfigModifierTest.java @@ -0,0 +1,46 @@ +package com.a.eye.skywalking.storage.boot; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.yaml.snakeyaml.Yaml; + +import java.io.File; +import java.io.FileInputStream; +import java.nio.file.Files; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class ElasticConfigModifierTest { + + private File configDir = new File(ElasticConfigModifierTest.class.getResource("/").getFile(), "test"); + File elasticSearchConfigFile = new File(configDir + File.separator + "config", "elasticsearch.yml"); + + @Before + public void setUp() throws Exception { + + } + + @After + public void tearDown() throws Exception { + Files.delete(elasticSearchConfigFile.toPath()); + Files.delete(new File(configDir, "config").toPath()); + Files.delete(configDir.toPath()); + } + + @Test + public void testReplaceConfig() throws Exception { + ElasticConfigModifier modifier = new ElasticConfigModifier(configDir.getPath()); + modifier.replaceConfig(18080); + + assertTrue(elasticSearchConfigFile.exists()); + + Yaml yaml = new Yaml(); + HashMap config = (HashMap) yaml.load(new FileInputStream + (elasticSearchConfigFile)); + assertEquals(18080,config.get("transport.tcp.port").intValue()); + } +}