diff --git a/pom.xml b/pom.xml index 9d44c8d9a..f6625747f 100644 --- a/pom.xml +++ b/pom.xml @@ -1,63 +1,66 @@ - 4.0.0 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 - com.a.eye - skywalking - 2.0-2016 - - skywalking-alarm - skywalking-webui + com.a.eye + skywalking + ${project.version} + + + skywalking-alarm + skywalking-webui skywalking-sniffer - skywalking-storage-center - skywalking-registry + skywalking-storage-center + skywalking-registry + samples/skywalking-auth + samples/skywalking-example + test/skywalking-test-api + skywalking-logging + + pom - samples/skywalking-auth - samples/skywalking-example - test/skywalking-test-api - - pom + skywalking + http://maven.apache.org - skywalking - http://maven.apache.org + + UTF-8 + 2.0-2016 + - - UTF-8 - + + + junit + junit + 4.12 + test + + + org.mockito + mockito-core + 1.10.19 + test + + - - - junit - junit - 4.12 - test - - - com.a.eye - skywalking-protocol - 2.0-2016 - - - - - - - maven-compiler-plugin - - 1.7 - 1.7 - ${project.build.sourceEncoding} - - - - org.apache.maven.plugins - maven-resources-plugin - 2.4.3 - - ${project.build.sourceEncoding} - - - - + + + + maven-compiler-plugin + + 1.7 + 1.7 + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-resources-plugin + 2.4.3 + + ${project.build.sourceEncoding} + + + + diff --git a/skywalking-logging/pom.xml b/skywalking-logging/pom.xml new file mode 100644 index 000000000..1032a3936 --- /dev/null +++ b/skywalking-logging/pom.xml @@ -0,0 +1,28 @@ + + + skywalking + com.a.eye + 2.0-2016 + + 4.0.0 + + skywalking-logging + jar + + skywalking-logging + http://maven.apache.org + + + UTF-8 + + + + + junit + junit + 3.8.1 + test + + + diff --git a/skywalking-logging/src/main/java/com/a/eye/skywalking/logging/ILog.java b/skywalking-logging/src/main/java/com/a/eye/skywalking/logging/ILog.java new file mode 100644 index 000000000..9a27cdf3b --- /dev/null +++ b/skywalking-logging/src/main/java/com/a/eye/skywalking/logging/ILog.java @@ -0,0 +1,14 @@ +package com.a.eye.skywalking.logging; + +/** + * Created by xin on 2016/11/10. + */ +public interface ILog { + void info(String format); + + void info(String format, Object... arguments); + + void error(String format, Throwable e); + + void error(String format, Object argument, Throwable e); +} diff --git a/skywalking-logging/src/main/java/com/a/eye/skywalking/logging/LogManager.java b/skywalking-logging/src/main/java/com/a/eye/skywalking/logging/LogManager.java new file mode 100644 index 000000000..19faba471 --- /dev/null +++ b/skywalking-logging/src/main/java/com/a/eye/skywalking/logging/LogManager.java @@ -0,0 +1,19 @@ +package com.a.eye.skywalking.logging; + +/** + * Created by xin on 2016/11/10. + */ +public class LogManager { + private static LogResolver resolver; + + public static void setLogResolver(LogResolver resolver) { + LogManager.resolver = resolver; + } + + public static ILog getLogger(Class clazz) { + if (resolver == null) { + return NoopLogger.INSTANCE; + } + return LogManager.resolver.getLogger(clazz); + } +} diff --git a/skywalking-logging/src/main/java/com/a/eye/skywalking/logging/LogResolver.java b/skywalking-logging/src/main/java/com/a/eye/skywalking/logging/LogResolver.java new file mode 100644 index 000000000..7e4853dc9 --- /dev/null +++ b/skywalking-logging/src/main/java/com/a/eye/skywalking/logging/LogResolver.java @@ -0,0 +1,8 @@ +package com.a.eye.skywalking.logging; + +/** + * Created by xin on 2016/11/10. + */ +public interface LogResolver { + ILog getLogger(Class clazz); +} diff --git a/skywalking-logging/src/main/java/com/a/eye/skywalking/logging/NoopLogger.java b/skywalking-logging/src/main/java/com/a/eye/skywalking/logging/NoopLogger.java new file mode 100644 index 000000000..236df43bb --- /dev/null +++ b/skywalking-logging/src/main/java/com/a/eye/skywalking/logging/NoopLogger.java @@ -0,0 +1,28 @@ +package com.a.eye.skywalking.logging; + + +/** + * Created by xin on 2016/11/10. + */ +public class NoopLogger implements ILog{ + public static final ILog INSTANCE = new NoopLogger(); + + @Override + public void info(String message) { + + } + + @Override + public void info(String format, Object... arguments) { + + } + + @Override + public void error(String format, Throwable e) { + + } + + @Override + public void error(String format, Object argument, Throwable e) { + } +} diff --git a/skywalking-registry/pom.xml b/skywalking-registry/pom.xml index ed3d24bcb..253a9b3ea 100644 --- a/skywalking-registry/pom.xml +++ b/skywalking-registry/pom.xml @@ -18,5 +18,39 @@ + + org.apache.zookeeper + zookeeper + 3.4.7 + + + com.a.eye + skywalking-logging + ${project.version} + + + + + local-central + http://10.128.7.197:8081/nexus/content/groups/public/ + + true + + + true + + + + apmparty + http://10.128.7.197:8081/nexus/content/repositories/apmparty/ + + true + + + true + + + + diff --git a/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/api/NotifyListener.java b/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/api/NotifyListener.java deleted file mode 100644 index 34221529c..000000000 --- a/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/api/NotifyListener.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.a.eye.skywalking.registry.api; - -import java.util.List; - -public interface NotifyListener { - void notify(List urls); -} diff --git a/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/RegistryCenterFactory.java b/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/RegistryCenterFactory.java similarity index 78% rename from skywalking-registry/src/main/java/com/a/eye/skywalking/registry/RegistryCenterFactory.java rename to skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/RegistryCenterFactory.java index 2de815248..1992c36dc 100644 --- a/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/RegistryCenterFactory.java +++ b/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/RegistryCenterFactory.java @@ -1,7 +1,7 @@ -package com.a.eye.skywalking.registry; +package com.a.eye.skywalking.registry.logging; -import com.a.eye.skywalking.registry.api.Center; -import com.a.eye.skywalking.registry.api.RegistryCenter; +import com.a.eye.skywalking.registry.logging.api.Center; +import com.a.eye.skywalking.registry.logging.api.RegistryCenter; import java.util.HashMap; import java.util.Iterator; @@ -13,6 +13,8 @@ import java.util.ServiceLoader; */ public class RegistryCenterFactory { + public static RegistryCenterFactory INSTANCE = new RegistryCenterFactory(); + private Map registryCenter = new HashMap(); private RegistryCenterFactory() { @@ -33,4 +35,6 @@ public class RegistryCenterFactory { public RegistryCenter getRegistryCenter(String type) { return registryCenter.get(type); } + + } diff --git a/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/api/Center.java b/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/api/Center.java similarity index 78% rename from skywalking-registry/src/main/java/com/a/eye/skywalking/registry/api/Center.java rename to skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/api/Center.java index 5998f459f..b6cf7fc39 100644 --- a/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/api/Center.java +++ b/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/api/Center.java @@ -1,4 +1,4 @@ -package com.a.eye.skywalking.registry.api; +package com.a.eye.skywalking.registry.logging.api; import java.lang.annotation.*; diff --git a/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/api/CenterType.java b/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/api/CenterType.java similarity index 70% rename from skywalking-registry/src/main/java/com/a/eye/skywalking/registry/api/CenterType.java rename to skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/api/CenterType.java index 8aa60e551..56e7e9afe 100644 --- a/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/api/CenterType.java +++ b/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/api/CenterType.java @@ -1,4 +1,4 @@ -package com.a.eye.skywalking.registry.api; +package com.a.eye.skywalking.registry.logging.api; /** * Created by wusheng on 2016/11/10. diff --git a/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/api/EventType.java b/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/api/EventType.java new file mode 100644 index 000000000..52dae6a07 --- /dev/null +++ b/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/api/EventType.java @@ -0,0 +1,9 @@ +package com.a.eye.skywalking.registry.logging.api; + +/** + * Created by xin on 2016/11/10. + */ +public enum EventType { + Add, + Remove; +} diff --git a/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/api/NotifyListener.java b/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/api/NotifyListener.java new file mode 100644 index 000000000..d99c07dee --- /dev/null +++ b/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/api/NotifyListener.java @@ -0,0 +1,5 @@ +package com.a.eye.skywalking.registry.logging.api; + +public interface NotifyListener { + void notify(EventType type, String urls); +} diff --git a/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/api/RegistryCenter.java b/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/api/RegistryCenter.java similarity index 68% rename from skywalking-registry/src/main/java/com/a/eye/skywalking/registry/api/RegistryCenter.java rename to skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/api/RegistryCenter.java index 76195e998..c125af254 100644 --- a/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/api/RegistryCenter.java +++ b/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/api/RegistryCenter.java @@ -1,4 +1,6 @@ -package com.a.eye.skywalking.registry.api; +package com.a.eye.skywalking.registry.logging.api; + +import java.util.Properties; /** * 主要用于注册中心的维护 @@ -23,4 +25,11 @@ public interface RegistryCenter { */ void subscribe(String path, NotifyListener listener); + + /** + * 在注册和订阅之前,需要先启动注册中心 + * + * @param centerConfig 配置参数 + */ + void start(Properties centerConfig); } diff --git a/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/impl/zookeeper/ZookeeperConfig.java b/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/impl/zookeeper/ZookeeperConfig.java new file mode 100644 index 000000000..dd0ed8662 --- /dev/null +++ b/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/impl/zookeeper/ZookeeperConfig.java @@ -0,0 +1,50 @@ +package com.a.eye.skywalking.registry.logging.impl.zookeeper; + +import com.a.eye.skywalking.logging.ILog; +import com.a.eye.skywalking.logging.LogManager; + +import java.util.Properties; + +/** + * Created by xin on 2016/11/10. + */ +public class ZookeeperConfig { + private static ILog logger = LogManager.getLogger(ZookeeperConfig.class); + public static final String CONNECT_URL = "CONNECT_URL"; + public static final String AUTH_SCHEMA = "AUTH_SCHEMA"; + public static final String AUTH_INFO = "AUTH_INFO"; + + private String connectURL; + private String autSchema; + private byte[] auth; + + public ZookeeperConfig(Properties config) { + this.connectURL = config.getProperty(CONNECT_URL); + if (this.connectURL == null || this.connectURL.length() == 0) { + throw new IllegalArgumentException("Connect url cannot be null"); + } + + this.autSchema = config.getProperty(AUTH_SCHEMA); + String authString = config.getProperty(AUTH_INFO); + if (authString != null) { + this.auth = authString.getBytes(); + } + logger.info("connection url: {} \n auth schema : {} \n auth info : {} ", connectURL, autSchema, authString); + } + + public boolean hasAuthInfo() { + return (this.autSchema != null && this.autSchema.length() > 0) && (this.auth != null && this.auth.length > 0); + } + + public String getConnectURL() { + return connectURL; + } + + public String getAutSchema() { + return autSchema; + } + + public byte[] getAuth() { + return auth; + } +} diff --git a/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/impl/zookeeper/ZookeeperRegistryCenter.java b/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/impl/zookeeper/ZookeeperRegistryCenter.java new file mode 100644 index 000000000..0d7317e56 --- /dev/null +++ b/skywalking-registry/src/main/java/com/a/eye/skywalking/registry/logging/impl/zookeeper/ZookeeperRegistryCenter.java @@ -0,0 +1,122 @@ +package com.a.eye.skywalking.registry.logging.impl.zookeeper; + +import com.a.eye.skywalking.logging.ILog; +import com.a.eye.skywalking.logging.LogManager; +import com.a.eye.skywalking.registry.logging.api.*; +import org.apache.zookeeper.*; + +import java.io.IOException; +import java.util.List; +import java.util.Properties; + +@Center(type = CenterType.DEFAULT_CENTER_TYPE) +public class ZookeeperRegistryCenter implements RegistryCenter { + + private ILog logger = LogManager.getLogger(ZookeeperRegistryCenter.class); + + public ZooKeeper client; + + @Override + public void register(String path) { + String createPath = path; + if (path.charAt(0) != '/') { + createPath = "/" + createPath; + } + + recursionCreatePath(createPath, 0); + } + + /** + * @param createPath + * @param index + */ + private void recursionCreatePath(String createPath, int index) { + try { + int next = createPath.indexOf("/", index + 1); + String path = createPath; + CreateMode createMode = CreateMode.EPHEMERAL; + + if (next != -1) { + createMode = CreateMode.PERSISTENT; + path = createPath.substring(0, next); + } + + if (client.exists(path, false) == null) + client.create(path, null, ZooDefs.Ids.OPEN_ACL_UNSAFE, createMode); + + if (next != -1) { + recursionCreatePath(createPath, next); + } + } catch (Exception e) { + logger.error("Failed to create path[{}]", createPath, e); + } + } + + + @Override + public void subscribe(final String path, final NotifyListener listener) { + try { + List childrenPath = client.getChildren(path, new SubscribeWatcher(path, listener)); + for (String child : childrenPath) { + listener.notify(EventType.Add, child); + } + } catch (Exception e) { + logger.error("Failed to subscribe the path {} ", path, e); + } + } + + @Override + public void start(Properties centerConfig) { + ZookeeperConfig config = new ZookeeperConfig(centerConfig); + try { + client = new ZooKeeper(config.getConnectURL(), 60 * 1000, null); + if (config.hasAuthInfo()) { + client.addAuthInfo(config.getAutSchema(), config.getAuth()); + } + } catch (IOException e) { + logger.error("Failed to create zookeeper registry center [{}]", config.getConnectURL(), e); + } + } + + + private class SubscribeWatcher implements Watcher { + private String path; + + private NotifyListener listener; + + public SubscribeWatcher(String path, NotifyListener listener) { + this.path = path; + this.listener = listener; + } + + @Override + public void process(WatchedEvent event) { + if (event.getType() == Event.EventType.NodeChildrenChanged) { + notifyListener(event); + } + + retryWatch(); + } + + private void notifyListener(WatchedEvent event) { + try { + List tmpChildrenPath = client.getChildren(path, null); + if (tmpChildrenPath.contains(event.getPath())) { + listener.notify(EventType.Add, event.getPath()); + } else { + listener.notify(EventType.Remove, event.getPath()); + } + } catch (Exception e) { + logger.error("Failed to fetch path[{}] children.", path, e); + } + } + + private void retryWatch() { + try { + client.getChildren(path, this); + } catch (Exception e) { + logger.error("Failed to rewatch path[{}]", path, e); + } + } + } +} diff --git a/skywalking-registry/src/main/resources/META-INF/services/com.a.eye.skywalking.registry.logging.api.RegistryCenter b/skywalking-registry/src/main/resources/META-INF/services/com.a.eye.skywalking.registry.logging.api.RegistryCenter new file mode 100644 index 000000000..aaa1d63c9 --- /dev/null +++ b/skywalking-registry/src/main/resources/META-INF/services/com.a.eye.skywalking.registry.logging.api.RegistryCenter @@ -0,0 +1 @@ +com.a.eye.skywalking.registry.logging.impl.zookeeper.ZookeeperRegistryCenter diff --git a/skywalking-sniffer/skywalking-api/pom.xml b/skywalking-sniffer/skywalking-api/pom.xml index f2069fd55..29d399de2 100644 --- a/skywalking-sniffer/skywalking-api/pom.xml +++ b/skywalking-sniffer/skywalking-api/pom.xml @@ -20,11 +20,6 @@ - - com.a.eye - skywalking-protocol - 2.0-2016 - net.bytebuddy diff --git a/skywalking-storage-center/skywalking-storage/pom.xml b/skywalking-storage-center/skywalking-storage/pom.xml index 98c6883ab..dbd3052dc 100644 --- a/skywalking-storage-center/skywalking-storage/pom.xml +++ b/skywalking-storage-center/skywalking-storage/pom.xml @@ -26,47 +26,11 @@ log4j-core 2.4.1 - - commons-io - commons-io - 2.4 - - - io.netty - netty-all - 4.0.33.Final - - - org.apache.hbase - hbase-client - 1.1.2 - - - com.a.eye - skywalking-protocol - 2.0-2016 - - - redis.clients - jedis - 2.8.0 - - - com.google.code.gson - gson - 2.2.2 - - - com.zaxxer - HikariCP - 2.4.3 - org.hsqldb hsqldb 2.3.4 - com.a.eye data-carrier diff --git a/skywalking-webui/pom.xml b/skywalking-webui/pom.xml index 1bdab47b8..5eb12cced 100644 --- a/skywalking-webui/pom.xml +++ b/skywalking-webui/pom.xml @@ -34,12 +34,6 @@ - - com.a.eye - skywalking-protocol - 2.0-2016 - - org.springframework spring-webmvc diff --git a/test/skywalking-test-api/pom.xml b/test/skywalking-test-api/pom.xml index d5eefe983..fed2d1e53 100644 --- a/test/skywalking-test-api/pom.xml +++ b/test/skywalking-test-api/pom.xml @@ -20,10 +20,5 @@ - - com.a.eye - skywalking-protocol - ${parent.version} -