mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-13 14:55:58 +10:00
[강운덕] [LUCYSUS-1744] flowCharServer에서 traceDao를 이용하도록 수정.
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-web/trunk@760 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -1,17 +1,23 @@
|
||||
package com.nhn.hippo.web.dao;
|
||||
|
||||
import com.nhn.hippo.web.mapper.SpanMapper;
|
||||
import com.nhn.hippo.web.vo.TraceId;
|
||||
import com.profiler.common.dto.thrift.Span;
|
||||
import com.profiler.common.hbase.HBaseTables;
|
||||
import com.profiler.common.hbase.HbaseTemplate2;
|
||||
import com.profiler.common.util.BytesUtils;
|
||||
import org.apache.hadoop.hbase.client.Get;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.data.hadoop.hbase.RowMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -27,12 +33,42 @@ public class HbaseTraceDao implements TraceDao {
|
||||
private HbaseTemplate2 template2;
|
||||
|
||||
@Autowired
|
||||
private SpanMapper<List<Span>> spanMapper;
|
||||
@Qualifier("spanMapper")
|
||||
private RowMapper<List<Span>> spanMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public List<Span> readSpan(UUID uuid) {
|
||||
byte[] uuidBytes = BytesUtils.longLongToBytes(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
|
||||
public List<Span> selectSpan(UUID traceId) {
|
||||
byte[] uuidBytes = BytesUtils.longLongToBytes(traceId.getMostSignificantBits(), traceId.getLeastSignificantBits());
|
||||
return template2.get(HBaseTables.TRACES, uuidBytes, COLFAM_SPAN, spanMapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Span> selectSpan(long traceIdMost, long traceIdLeast) {
|
||||
byte[] uuidBytes = BytesUtils.longLongToBytes(traceIdMost, traceIdLeast);
|
||||
return template2.get(HBaseTables.TRACES, uuidBytes, COLFAM_SPAN, spanMapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<List<Span>> selectSpans(List<UUID> traceIds) {
|
||||
List<Get> gets = new ArrayList<Get>(traceIds.size());
|
||||
for (UUID traceId : traceIds) {
|
||||
byte[] uuidBytes = BytesUtils.longLongToBytes(traceId.getMostSignificantBits(), traceId.getLeastSignificantBits());
|
||||
Get get = new Get(uuidBytes);
|
||||
get.addFamily(COLFAM_SPAN);
|
||||
gets.add(get);
|
||||
}
|
||||
return template2.get(HBaseTables.TRACES, gets, spanMapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<List<Span>> selectSpans(Set<TraceId> traceIds) {
|
||||
List<Get> gets = new ArrayList<Get>(traceIds.size());
|
||||
for (TraceId traceId : traceIds) {
|
||||
Get get = new Get(traceId.getBytes());
|
||||
get.addFamily(COLFAM_SPAN);
|
||||
gets.add(get);
|
||||
}
|
||||
return template2.get(HBaseTables.TRACES, gets, spanMapper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.nhn.hippo.web.dao;
|
||||
|
||||
|
||||
import com.nhn.hippo.web.vo.TraceId;
|
||||
import com.profiler.common.dto.thrift.Span;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -11,6 +13,12 @@ import java.util.UUID;
|
||||
*/
|
||||
public interface TraceDao {
|
||||
|
||||
List<Span> readSpan(UUID uuid);
|
||||
List<Span> selectSpan(UUID traceId);
|
||||
|
||||
List<Span> selectSpan(long traceIdMost, long traceIdLeast);
|
||||
|
||||
List<List<Span>> selectSpans(List<UUID> traceIds);
|
||||
|
||||
List<List<Span>> selectSpans(Set<TraceId> traceIds);
|
||||
|
||||
}
|
||||
|
||||
@@ -8,10 +8,13 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.nhn.hippo.web.dao.TraceDao;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.hadoop.hbase.client.Get;
|
||||
import org.apache.hadoop.hbase.client.Result;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -27,125 +30,112 @@ import com.profiler.common.hbase.HBaseQuery.HbaseColumn;
|
||||
import com.profiler.common.hbase.HBaseTables;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author netspider
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
public class FlowChartServiceImpl implements FlowChartService {
|
||||
|
||||
@Autowired
|
||||
@Qualifier("hbaseClient")
|
||||
HBaseClient client;
|
||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Override
|
||||
public String[] selectAgentIds(String[] hosts) {
|
||||
List<HbaseColumn> column = new ArrayList<HBaseQuery.HbaseColumn>();
|
||||
column.add(new HbaseColumn("Agents", "AgentID"));
|
||||
@Autowired
|
||||
@Qualifier("hbaseClient")
|
||||
HBaseClient client;
|
||||
|
||||
HBaseQuery query = new HBaseQuery(HBaseTables.SERVERS, null, null, column);
|
||||
Iterator<Map<String, byte[]>> iterator = client.getHBaseData(query);
|
||||
@Autowired
|
||||
private TraceDao traceDao;
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
System.out.println("selectedAgentId=" + iterator.next());
|
||||
}
|
||||
@Override
|
||||
public String[] selectAgentIds(String[] hosts) {
|
||||
List<HbaseColumn> column = new ArrayList<HBaseQuery.HbaseColumn>();
|
||||
column.add(new HbaseColumn("Agents", "AgentID"));
|
||||
|
||||
System.out.println("!!!==============WARNING==============!!!");
|
||||
System.out.println("!!! selectAgentIds IS NOT IMPLEMENTED !!!");
|
||||
System.out.println("!!!===================================!!!");
|
||||
HBaseQuery query = new HBaseQuery(HBaseTables.SERVERS, null, null, column);
|
||||
Iterator<Map<String, byte[]>> iterator = client.getHBaseData(query);
|
||||
|
||||
return hosts;
|
||||
}
|
||||
while (iterator.hasNext()) {
|
||||
System.out.println("selectedAgentId=" + iterator.next());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<TraceId> selectTraceIdsFromTraceIndex(String[] agentIds, long from, long to) {
|
||||
List<HbaseColumn> column = new ArrayList<HBaseQuery.HbaseColumn>();
|
||||
column.add(new HbaseColumn("Trace", "ID"));
|
||||
System.out.println("!!!==============WARNING==============!!!");
|
||||
System.out.println("!!! selectAgentIds IS NOT IMPLEMENTED !!!");
|
||||
System.out.println("!!!===================================!!!");
|
||||
|
||||
Set<TraceId> set = new HashSet<TraceId>();
|
||||
return hosts;
|
||||
}
|
||||
|
||||
for (String agentId : agentIds) {
|
||||
byte[] s = ArrayUtils.addAll(Bytes.toBytes(agentId), Bytes.toBytes(from));
|
||||
byte[] e = ArrayUtils.addAll(Bytes.toBytes(agentId), Bytes.toBytes(to));
|
||||
@Override
|
||||
public Set<TraceId> selectTraceIdsFromTraceIndex(String[] agentIds, long from, long to) {
|
||||
List<HbaseColumn> column = new ArrayList<HBaseQuery.HbaseColumn>();
|
||||
column.add(new HbaseColumn("Trace", "ID"));
|
||||
|
||||
HBaseQuery query = new HBaseQuery(HBaseTables.TRACE_INDEX, s, e, column);
|
||||
Iterator<Map<String, byte[]>> result = client.getHBaseData(query);
|
||||
Set<TraceId> set = new HashSet<TraceId>();
|
||||
|
||||
while (result.hasNext()) {
|
||||
set.add(new TraceId(result.next().get("ID")));
|
||||
}
|
||||
}
|
||||
for (String agentId : agentIds) {
|
||||
byte[] s = ArrayUtils.addAll(Bytes.toBytes(agentId), Bytes.toBytes(from));
|
||||
byte[] e = ArrayUtils.addAll(Bytes.toBytes(agentId), Bytes.toBytes(to));
|
||||
|
||||
return set;
|
||||
}
|
||||
HBaseQuery query = new HBaseQuery(HBaseTables.TRACE_INDEX, s, e, column);
|
||||
Iterator<Map<String, byte[]>> result = client.getHBaseData(query);
|
||||
|
||||
@Override
|
||||
public Map<byte[], List<Span>> selectTraces(List<byte[]> traceIds) {
|
||||
List<Get> gets = new ArrayList<Get>(traceIds.size());
|
||||
for (byte[] traceId : traceIds) {
|
||||
gets.add(new Get(traceId));
|
||||
}
|
||||
while (result.hasNext()) {
|
||||
set.add(new TraceId(result.next().get("ID")));
|
||||
}
|
||||
}
|
||||
|
||||
Result[] results = client.get(HBaseTables.TRACES, gets);
|
||||
return set;
|
||||
}
|
||||
|
||||
// traceId, SpanList
|
||||
final Map<byte[], List<Span>> result = new HashMap<byte[], List<Span>>();
|
||||
@Override
|
||||
public Map<byte[], List<Span>> selectTraces(List<byte[]> traceIds) {
|
||||
List<Get> gets = new ArrayList<Get>(traceIds.size());
|
||||
for (byte[] traceId : traceIds) {
|
||||
gets.add(new Get(traceId));
|
||||
}
|
||||
|
||||
TracesProcessor.process(results, new SpanHandler() {
|
||||
@Override
|
||||
public void handleSpan(byte[] row, byte[] family, byte[] column, Span span) {
|
||||
if (result.containsKey(row)) {
|
||||
result.get(row).add(span);
|
||||
} else {
|
||||
List<Span> list = new ArrayList<Span>();
|
||||
list.add(span);
|
||||
result.put(row, list);
|
||||
}
|
||||
}
|
||||
});
|
||||
Result[] results = client.get(HBaseTables.TRACES, gets);
|
||||
|
||||
return result;
|
||||
}
|
||||
// traceId, SpanList
|
||||
final Map<byte[], List<Span>> result = new HashMap<byte[], List<Span>>();
|
||||
|
||||
@Override
|
||||
public RPCCallTree selectRPCCallTree(Set<TraceId> traceIds) {
|
||||
List<Get> gets = new ArrayList<Get>(traceIds.size());
|
||||
for (TraceId traceId : traceIds) {
|
||||
gets.add(new Get(traceId.getBytes()));
|
||||
}
|
||||
TracesProcessor.process(results, new SpanHandler() {
|
||||
@Override
|
||||
public void handleSpan(byte[] row, byte[] family, byte[] column, Span span) {
|
||||
if (result.containsKey(row)) {
|
||||
result.get(row).add(span);
|
||||
} else {
|
||||
List<Span> list = new ArrayList<Span>();
|
||||
list.add(span);
|
||||
result.put(row, list);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Result[] results = client.get(HBaseTables.TRACES, gets);
|
||||
return result;
|
||||
}
|
||||
|
||||
final RPCCallTree tree = new RPCCallTree();
|
||||
@Override
|
||||
public RPCCallTree selectRPCCallTree(Set<TraceId> traceIds) {
|
||||
final RPCCallTree tree = new RPCCallTree();
|
||||
List<List<Span>> traces = this.traceDao.selectSpans(traceIds);
|
||||
for (List<Span> transaction : traces) {
|
||||
for (Span eachTransaction : transaction) {
|
||||
tree.addSpan(eachTransaction);
|
||||
}
|
||||
}
|
||||
return tree.build();
|
||||
}
|
||||
|
||||
TracesProcessor.process(results, new SpanHandler() {
|
||||
@Override
|
||||
public void handleSpan(byte[] row, byte[] family, byte[] column, Span span) {
|
||||
tree.addSpan(span);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public ServerCallTree selectServerCallTree(Set<TraceId> traceIds) {
|
||||
final ServerCallTree tree = new ServerCallTree();
|
||||
|
||||
return tree.build();
|
||||
}
|
||||
List<List<Span>> traces = this.traceDao.selectSpans(traceIds);
|
||||
for (List<Span> transaction : traces) {
|
||||
for (Span eachTransaction : transaction) {
|
||||
tree.addSpan(eachTransaction);
|
||||
}
|
||||
}
|
||||
return tree.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerCallTree selectServerCallTree(Set<TraceId> traceIds) {
|
||||
List<Get> gets = new ArrayList<Get>(traceIds.size());
|
||||
for (TraceId traceId : traceIds) {
|
||||
gets.add(new Get(traceId.getBytes()));
|
||||
}
|
||||
|
||||
Result[] results = client.get(HBaseTables.TRACES, gets);
|
||||
|
||||
final ServerCallTree tree = new ServerCallTree();
|
||||
|
||||
TracesProcessor.process(results, new SpanHandler() {
|
||||
@Override
|
||||
public void handleSpan(byte[] row, byte[] family, byte[] column, Span span) {
|
||||
tree.addSpan(span);
|
||||
}
|
||||
});
|
||||
|
||||
return tree.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,13 +25,13 @@ public class SpanServiceImpl implements SpanService {
|
||||
@Override
|
||||
public List<SpanAlign> selectSpan(String uuid) {
|
||||
UUID id = UUID.fromString(uuid);
|
||||
List<Span> spans = traceDao.readSpan(id);
|
||||
List<Span> spans = traceDao.selectSpan(id);
|
||||
if (spans == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<SpanAlign> order = order(spans);
|
||||
|
||||
if(order.size() != spans.size()) {
|
||||
if (order.size() != spans.size()) {
|
||||
logger.info("span node not complete! ");
|
||||
}
|
||||
return order;
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
hbase.client.host=localhost
|
||||
#hbase.client.host=localhost
|
||||
hbase.client.host=10.25.131.38
|
||||
|
||||
hbase.client.port=2181
|
||||
@@ -23,7 +23,7 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<import resource="classpath:hbase-web-applicationContext.xml"></import>
|
||||
<import resource="classpath:hbase-applicationContext.xml"></import>
|
||||
|
||||
|
||||
<bean class="com.profiler.common.util.DefaultTBaseLocator"></bean>
|
||||
|
||||
Reference in New Issue
Block a user