add client and register watcher to webui.

This commit is contained in:
wusheng 2016-12-06 19:38:20 +08:00
parent 293981f2a2
commit cc85aa1273
8 changed files with 107 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import com.a.eye.skywalking.logging.impl.log4j2.Log4j2Resolver;
import com.a.eye.skywalking.network.Server;
import com.a.eye.skywalking.registry.RegistryCenterFactory;
import com.a.eye.skywalking.registry.api.RegistryCenter;
import com.a.eye.skywalking.registry.assist.NetUtils;
import com.a.eye.skywalking.registry.impl.zookeeper.ZookeeperConfig;
import com.a.eye.skywalking.routing.config.Config;
import com.a.eye.skywalking.routing.config.ConfigInitializer;
@ -30,7 +31,9 @@ public class Main {
center.start(fetchRegistryCenterConfig());
center.subscribe(Config.StorageNode.SUBSCRIBE_PATH, RoutingService.getRouter());
Server.newBuilder(Config.Routing.PORT).addSpanStorageService(new SpanStorageListenerImpl()).addTraceSearchService(new TraceSearchListenerImpl()).build().start();
Server.newBuilder(Config.Server.PORT).addSpanStorageService(new SpanStorageListenerImpl()).addTraceSearchService(new TraceSearchListenerImpl()).build().start();
center.register(Config.RegistryCenter.PATH_PREFIX + NetUtils.getLocalAddress().getHostAddress() + ":" + Config.Server.PORT);
logger.info("Skywalking routing service was started.");
Thread.currentThread().join();
} catch (Exception e) {

View File

@ -1,7 +1,7 @@
package com.a.eye.skywalking.routing.config;
public class Config {
public static class Routing {
public static class Server {
public static int PORT = 23000;
}

View File

@ -34,6 +34,11 @@
<artifactId>skywalking-logging-impl-log4j2</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>com.a.eye</groupId>
<artifactId>skywalking-registry</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
@ -105,6 +110,5 @@
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,49 @@
package com.a.eye.skywalking.web.client.routing;
import com.a.eye.skywalking.network.Client;
import com.a.eye.skywalking.network.grpc.client.TraceSearchClient;
import com.a.eye.skywalking.registry.api.NotifyListener;
import com.a.eye.skywalking.registry.api.RegistryNode;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
/**
* Created by wusheng on 2016/12/6.
*/
public class RoutingServerWatcher implements NotifyListener {
private ReentrantLock lock = new ReentrantLock();
private static Map<String, TraceSearchClient> allSearchClients = new HashMap();
private static Map<String, Client> allClient = new HashMap<>();
public static TraceSearchClient[] getAllSearchClient(){
return allSearchClients.values().toArray(new TraceSearchClient[0]);
}
@Override
public void notify(List<RegistryNode> registryNodes) {
lock.lock();
try {
registryNodes.forEach((each) -> {
if (RegistryNode.ChangeType.ADDED.equals(each.getChangeType())) {
String connectionURL = each.getNode();
String[] urlSegment = connectionURL.split(":");
if (urlSegment.length != 2) {
throw new IllegalArgumentException();
}
Client client = new Client(urlSegment[0], Integer.valueOf(urlSegment[1]));
TraceSearchClient traceSearchClient = client.newTraceSearchClient();
allClient.put(connectionURL, client);
allSearchClients.put(connectionURL, traceSearchClient);
} else {
allSearchClients.remove(each.getNode());
allClient.remove(each.getNode()).shutdown();
}
});
} finally {
lock.unlock();
}
}
}

View File

@ -0,0 +1,27 @@
package com.a.eye.skywalking.web.client.routing;
import com.a.eye.skywalking.network.grpc.client.TraceSearchClient;
import com.a.eye.skywalking.web.dto.TraceNodesResult;
import java.util.concurrent.ThreadLocalRandom;
/**
* Created by wusheng on 2016/12/6.
*/
public class SearchClient {
private TraceSearchClient client;
public SearchClient() {
TraceSearchClient[] allSearchClients = RoutingServerWatcher.getAllSearchClient();
client = allSearchClients[ThreadLocalRandom.current().nextInt(0, allSearchClients.length)];
}
public TraceNodesResult searchSpan(String traceId){
String[] traceIdSegments = traceId.split(".");
if(traceIdSegments.length != 6){
return new TraceNodesResult();
}
return new TraceNodesResult();
}
}

View File

@ -5,14 +5,13 @@ package com.a.eye.skywalking.web.config;
*/
public class Config {
public static class RegistryCenter {
public static String TYPE = "zookeeper";
public static String AUTH_INFO = "";
public static String AUTH_SCHEMA = "";
public static String CONNECT_URL = "127.0.0.1:2181";
public static String PATH_PREFIX = "/skywalking/storage_list/";
}
public static class RoutingNode {

View File

@ -1,5 +1,9 @@
package com.a.eye.skywalking.web.controller;
import com.a.eye.skywalking.registry.RegistryCenterFactory;
import com.a.eye.skywalking.registry.api.RegistryCenter;
import com.a.eye.skywalking.registry.impl.zookeeper.ZookeeperConfig;
import com.a.eye.skywalking.web.client.routing.RoutingServerWatcher;
import com.a.eye.skywalking.web.common.BaseController;
import com.a.eye.skywalking.web.config.Config;
import com.a.eye.skywalking.web.config.ConfigInitializer;
@ -44,6 +48,11 @@ public class SearchController extends BaseController {
Properties properties = new Properties();
properties.load(SearchController.class.getResourceAsStream("/config.properties"));
ConfigInitializer.initialize(properties, Config.class);
RegistryCenter center = RegistryCenterFactory.INSTANCE.getRegistryCenter(Config.RegistryCenter.TYPE);
center.start(fetchRegistryCenterConfig());
center.subscribe(Config.RoutingNode.SUBSCRIBE_PATH, new RoutingServerWatcher());
}
@RequestMapping(value = "/search/traceId", produces = "application/json; charset=UTF-8")
@ -89,4 +98,12 @@ public class SearchController extends BaseController {
//TODO: not provided in this release
return "";
}
private static Properties fetchRegistryCenterConfig() {
Properties centerConfig = new Properties();
centerConfig.setProperty(ZookeeperConfig.CONNECT_URL, Config.RegistryCenter.CONNECT_URL);
centerConfig.setProperty(ZookeeperConfig.AUTH_SCHEMA, Config.RegistryCenter.AUTH_SCHEMA);
centerConfig.setProperty(ZookeeperConfig.AUTH_INFO, Config.RegistryCenter.AUTH_INFO);
return centerConfig;
}
}

View File

@ -1,6 +1,7 @@
package com.a.eye.skywalking.web.dao.impl;
import com.a.eye.skywalking.network.grpc.Span;
import com.a.eye.skywalking.web.client.routing.SearchClient;
import com.a.eye.skywalking.web.dao.inter.ITraceNodeDao;
import com.a.eye.skywalking.web.dto.TraceNodeInfo;
import com.a.eye.skywalking.web.dto.TraceNodesResult;
@ -28,7 +29,8 @@ public class TraceNodeDao implements ITraceNodeDao {
InvocationTargetException {
List<Span> searchResult = new ArrayList<>();
TraceNodesResult result = new TraceNodesResult();
SearchClient client = new SearchClient();
TraceNodesResult result = client.searchSpan(traceId);
Map<String, TraceNodeInfo> traceNodeInfoMap = new HashMap<>();
searchResult.forEach((span -> {
traceNodeInfoMap.put(span.getLevelId(), new TraceNodeInfo(span));