提交logging工程以及完成zookeeper实现的注册中心,删除对protocol工程的依赖
This commit is contained in:
parent
dbc221e2ed
commit
b185f1e0b4
111
pom.xml
111
pom.xml
|
|
@ -1,63 +1,66 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking</artifactId>
|
||||
<version>2.0-2016</version>
|
||||
<modules>
|
||||
<module>skywalking-alarm</module>
|
||||
<module>skywalking-webui</module>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking</artifactId>
|
||||
<version>${project.version}</version>
|
||||
|
||||
<modules>
|
||||
<module>skywalking-alarm</module>
|
||||
<module>skywalking-webui</module>
|
||||
<module>skywalking-sniffer</module>
|
||||
<module>skywalking-storage-center</module>
|
||||
<module>skywalking-registry</module>
|
||||
<module>skywalking-storage-center</module>
|
||||
<module>skywalking-registry</module>
|
||||
<module>samples/skywalking-auth</module>
|
||||
<module>samples/skywalking-example</module>
|
||||
<module>test/skywalking-test-api</module>
|
||||
<module>skywalking-logging</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<module>samples/skywalking-auth</module>
|
||||
<module>samples/skywalking-example</module>
|
||||
<module>test/skywalking-test-api</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
<name>skywalking</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<name>skywalking</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.version>2.0-2016</project.version>
|
||||
</properties>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>1.10.19</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-protocol</artifactId>
|
||||
<version>2.0-2016</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.4.3</version>
|
||||
<configuration>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.4.3</version>
|
||||
<configuration>
|
||||
<encoding>${project.build.sourceEncoding}</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>skywalking</artifactId>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<version>2.0-2016</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>skywalking-logging</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>skywalking-logging</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.a.eye.skywalking.logging;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/11/10.
|
||||
*/
|
||||
public interface LogResolver {
|
||||
ILog getLogger(Class<?> clazz);
|
||||
}
|
||||
|
|
@ -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) {
|
||||
}
|
||||
}
|
||||
|
|
@ -18,5 +18,39 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.zookeeper</groupId>
|
||||
<artifactId>zookeeper</artifactId>
|
||||
<version>3.4.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-logging</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>local-central</id>
|
||||
<url>http://10.128.7.197:8081/nexus/content/groups/public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>apmparty</id>
|
||||
<url>http://10.128.7.197:8081/nexus/content/repositories/apmparty/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
package com.a.eye.skywalking.registry.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface NotifyListener {
|
||||
void notify(List<String> urls);
|
||||
}
|
||||
|
|
@ -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<String, RegistryCenter> registryCenter = new HashMap<String, RegistryCenter>();
|
||||
|
||||
private RegistryCenterFactory() {
|
||||
|
|
@ -33,4 +35,6 @@ public class RegistryCenterFactory {
|
|||
public RegistryCenter getRegistryCenter(String type) {
|
||||
return registryCenter.get(type);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.a.eye.skywalking.registry.api;
|
||||
package com.a.eye.skywalking.registry.logging.api;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
|
|
@ -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.
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.a.eye.skywalking.registry.logging.api;
|
||||
|
||||
/**
|
||||
* Created by xin on 2016/11/10.
|
||||
*/
|
||||
public enum EventType {
|
||||
Add,
|
||||
Remove;
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package com.a.eye.skywalking.registry.logging.api;
|
||||
|
||||
public interface NotifyListener {
|
||||
void notify(EventType type, String urls);
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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<String> 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<String> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
com.a.eye.skywalking.registry.logging.impl.zookeeper.ZookeeperRegistryCenter
|
||||
|
|
@ -20,11 +20,6 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-protocol</artifactId>
|
||||
<version>2.0-2016</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.bytebuddy</groupId>
|
||||
|
|
|
|||
|
|
@ -26,47 +26,11 @@
|
|||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>4.0.33.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.hbase</groupId>
|
||||
<artifactId>hbase-client</artifactId>
|
||||
<version>1.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-protocol</artifactId>
|
||||
<version>2.0-2016</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>2.8.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>2.4.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hsqldb</groupId>
|
||||
<artifactId>hsqldb</artifactId>
|
||||
<version>2.3.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>data-carrier</artifactId>
|
||||
|
|
|
|||
|
|
@ -34,12 +34,6 @@
|
|||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-protocol</artifactId>
|
||||
<version>2.0-2016</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
|
|
|
|||
|
|
@ -20,10 +20,5 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.a.eye</groupId>
|
||||
<artifactId>skywalking-protocol</artifactId>
|
||||
<version>${parent.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
|||
Loading…
Reference in New Issue