提交 6f08371c 编写于 作者: A ascrutae

1. 添加TraceSpanTree序列化方法

2. 将Mapper的Keyout对象修改成TraceSpanTree
上级 06445fc5
package com.ai.cloud.skywalking.analysis.chainbuild; package com.ai.cloud.skywalking.analysis.chainbuild;
import java.io.IOException; import com.ai.cloud.skywalking.analysis.chainbuild.entity.TraceSpanTree;
import java.util.ArrayList; import com.ai.cloud.skywalking.analysis.chainbuild.util.VersionIdentifier;
import java.util.List; import com.ai.cloud.skywalking.analysis.config.ConfigInitializer;
import com.ai.cloud.skywalking.protocol.Span;
import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
...@@ -13,42 +13,42 @@ import org.apache.hadoop.io.Text; ...@@ -13,42 +13,42 @@ import org.apache.hadoop.io.Text;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.ai.cloud.skywalking.analysis.chainbuild.entity.TraceSpanTree; import java.io.IOException;
import com.ai.cloud.skywalking.analysis.chainbuild.util.VersionIdentifier; import java.util.ArrayList;
import com.ai.cloud.skywalking.analysis.config.ConfigInitializer; import java.util.List;
import com.ai.cloud.skywalking.protocol.Span;
public class ChainBuildMapper extends TableMapper<Text, TraceSpanTree> {
private Logger logger = LoggerFactory
.getLogger(ChainBuildMapper.class);
@Override
protected void setup(Context context) throws IOException,
InterruptedException {
ConfigInitializer.initialize();
}
@Override
protected void map(ImmutableBytesWritable key, Result value, Context context)
throws IOException, InterruptedException {
if (!VersionIdentifier.enableAnaylsis(Bytes.toString(key.get()))) {
return;
}
try {
List<Span> spanList = new ArrayList<Span>();
for (Cell cell : value.rawCells()) {
Span span = new Span(Bytes.toString(cell.getValueArray(),
cell.getValueOffset(), cell.getValueLength()));
spanList.add(span);
}
public class ChainBuildMapper extends TableMapper<Text, Text> { TraceSpanTree tree = new TraceSpanTree();
private Logger logger = LoggerFactory tree.build(spanList);
.getLogger(ChainBuildMapper.class); context.write(new Text(tree.getTreeRoot().getNodeRefToken()), tree);
} catch (Throwable e) {
@Override logger.error("Failed to mapper call chain[" + key.toString() + "]",
protected void setup(Context context) throws IOException, e);
InterruptedException { }
ConfigInitializer.initialize(); }
}
@Override
protected void map(ImmutableBytesWritable key, Result value, Context context)
throws IOException, InterruptedException {
if(!VersionIdentifier.enableAnaylsis(Bytes.toString(key.get()))){
return;
}
try {
List<Span> spanList = new ArrayList<Span>();
for (Cell cell : value.rawCells()) {
Span span = new Span(Bytes.toString(cell.getValueArray(),
cell.getValueOffset(), cell.getValueLength()));
spanList.add(span);
}
TraceSpanTree tree = new TraceSpanTree();
tree.build(spanList);
} catch (Throwable e) {
logger.error("Failed to mapper call chain[" + key.toString() + "]",
e);
}
}
} }
package com.ai.cloud.skywalking.analysis.chainbuild.entity; package com.ai.cloud.skywalking.analysis.chainbuild.entity;
import java.util.List;
import com.ai.cloud.skywalking.analysis.chainbuild.exception.TraceSpanTreeSerializeException; import com.ai.cloud.skywalking.analysis.chainbuild.exception.TraceSpanTreeSerializeException;
import com.ai.cloud.skywalking.analysis.chainbuild.util.StringUtil; import com.ai.cloud.skywalking.analysis.chainbuild.util.StringUtil;
import com.ai.cloud.skywalking.analysis.chainbuild.util.TokenGenerator;
import com.ai.cloud.skywalking.protocol.CallType; import com.ai.cloud.skywalking.protocol.CallType;
import com.ai.cloud.skywalking.protocol.Span; import com.ai.cloud.skywalking.protocol.Span;
import java.util.List;
public class TraceSpanNode { public class TraceSpanNode {
protected TraceSpanNode prev = null; protected TraceSpanNode prev = null;
protected TraceSpanNode next = null; protected TraceSpanNode next = null;
protected TraceSpanNode parent = null; protected TraceSpanNode parent = null;
protected TraceSpanNode sub = null; protected TraceSpanNode sub = null;
protected String prevNodeRefToken = null; protected String prevNodeRefToken = null;
protected String nextNodeRefToken = null; protected String nextNodeRefToken = null;
protected String parentNodeRefToken = null; protected String parentNodeRefToken = null;
protected String subNodeRefToken = null; protected String subNodeRefToken = null;
protected String nodeRefToken = null; protected String nodeRefToken = null;
protected boolean visualNode = true; protected boolean visualNode = true;
protected String parentLevel; protected String parentLevel;
protected int levelId; protected int levelId;
protected String viewPointId = ""; protected String viewPointId = "";
protected long cost = 0; protected long cost = 0;
protected long callTimes = 0; protected long callTimes = 0;
/** /**
* 节点调用的状态<br/> * 节点调用的状态<br/>
* 0:成功<br/> * 0:成功<br/>
* 1:异常<br/> * 1:异常<br/>
* 异常判断原则:代码产生exception,并且此exception不在忽略列表中 * 异常判断原则:代码产生exception,并且此exception不在忽略列表中
*/ */
protected byte statusCode = 0; protected byte statusCode = 0;
/** /**
* 节点调用的错误堆栈<br/> * 节点调用的错误堆栈<br/>
* 堆栈以JAVA的exception为主要判断依据 * 堆栈以JAVA的exception为主要判断依据
*/ */
protected String exceptionStack; protected String exceptionStack;
/** /**
* 节点类型描述<br/> * 节点类型描述<br/>
* 已字符串的形式描述<br/> * 已字符串的形式描述<br/>
* 如:java,dubbo等 * 如:java,dubbo等
*/ */
protected String spanType = ""; protected String spanType = "";
/** /**
* 节点调用过程中的业务字段<br/> * 节点调用过程中的业务字段<br/>
* 如:业务系统设置的订单号,SQL语句等 * 如:业务系统设置的订单号,SQL语句等
*/ */
protected String businessKey = ""; protected String businessKey = "";
/** /**
* 节点调用所在的系统逻辑名称<br/> * 节点调用所在的系统逻辑名称<br/>
* 由授权文件指定 * 由授权文件指定
*/ */
protected String applicationId = ""; protected String applicationId = "";
public TraceSpanNode(TraceSpanNode parent, TraceSpanNode sub, TraceSpanNode prev, TraceSpanNode next, Span span, List<TraceSpanNode> spanContainer) { public TraceSpanNode(TraceSpanNode parent, TraceSpanNode sub, TraceSpanNode prev, TraceSpanNode next, Span span, List<TraceSpanNode> spanContainer) {
this(parent, sub, prev, next, spanContainer); this(parent, sub, prev, next, spanContainer);
this.visualNode = false; this.visualNode = false;
this.parentLevel = span.getParentLevel(); this.parentLevel = span.getParentLevel();
this.levelId = span.getLevelId(); this.levelId = span.getLevelId();
this.viewPointId = span.getViewPointId(); this.viewPointId = span.getViewPointId();
this.cost = span.getCost(); this.cost = span.getCost();
this.callTimes = 1; this.callTimes = 1;
this.statusCode = span.getStatusCode(); this.statusCode = span.getStatusCode();
if(span.isReceiver()){ if (span.isReceiver()) {
this.exceptionStack = "server stack:"; this.exceptionStack = "server stack:";
}else{ } else {
this.exceptionStack = "client stack:"; this.exceptionStack = "client stack:";
} }
this.exceptionStack += span.getExceptionStack(); this.exceptionStack += span.getExceptionStack();
this.spanType = span.getSpanType(); this.spanType = span.getSpanType();
this.businessKey = span.getBusinessKey(); this.businessKey = span.getBusinessKey();
this.applicationId = span.getApplicationId(); this.applicationId = span.getApplicationId();
//TODO: to set nodeToken //nodeToken : MD5(parentLevelId + levelId + viewpoint)
} nodeRefToken = TokenGenerator.generateNodeToken(parentLevel + "-" + levelId + "-" + viewPointId);
protected TraceSpanNode(TraceSpanNode parent, TraceSpanNode sub, TraceSpanNode prev, TraceSpanNode next, List<TraceSpanNode> spanContainer){ }
this.visualNode = true;
this.setParent(parent); protected TraceSpanNode(TraceSpanNode parent, TraceSpanNode sub, TraceSpanNode prev, TraceSpanNode next, List<TraceSpanNode> spanContainer) {
if(parent != null){ this.visualNode = true;
parent.setSub(this); this.setParent(parent);
} if (parent != null) {
this.setSub(sub); parent.setSub(this);
if(sub != null){ }
sub.setParent(this); this.setSub(sub);
} if (sub != null) {
this.setPrev(prev); sub.setParent(this);
if(prev != null){ }
prev.setNext(this); this.setPrev(prev);
} if (prev != null) {
this.setNext(next); prev.setNext(this);
if(next != null){ }
next.setPrev(this); this.setNext(next);
} if (next != null) {
spanContainer.add(this); next.setPrev(this);
} }
spanContainer.add(this);
protected TraceSpanNode(TraceSpanNode parent, TraceSpanNode sub, TraceSpanNode prev, TraceSpanNode next, String parentLevelId, int levelId, List<TraceSpanNode> spanContainer){ }
this(parent, sub, prev, next, spanContainer);
this.parentLevel = parentLevelId; protected TraceSpanNode(TraceSpanNode parent, TraceSpanNode sub, TraceSpanNode prev, TraceSpanNode next, String parentLevelId, int levelId, List<TraceSpanNode> spanContainer) {
this.levelId = levelId; this(parent, sub, prev, next, spanContainer);
this.callTimes = 0; this.parentLevel = parentLevelId;
} this.levelId = levelId;
this.callTimes = 0;
boolean hasNext(){ }
if(this.next != null){
return true; boolean hasNext() {
}else{ if (this.next != null) {
return false; return true;
} } else {
} return false;
}
boolean hasSub(){ }
if(this.sub != null){
return true; boolean hasSub() {
}else{ if (this.sub != null) {
return false; return true;
} } else {
} return false;
}
void mergeSpan(Span span){ }
if(CallType.convert(span.getCallType()) == CallType.ASYNC){
this.cost += span.getCost(); void mergeSpan(Span span) {
} if (CallType.convert(span.getCallType()) == CallType.ASYNC) {
if(span.getStatusCode() != 0 && !StringUtil.isBlank(span.getExceptionStack())){ this.cost += span.getCost();
if(span.isReceiver()){ }
this.exceptionStack += "server stack:"; if (span.getStatusCode() != 0 && !StringUtil.isBlank(span.getExceptionStack())) {
}else{ if (span.isReceiver()) {
this.exceptionStack += "client stack:"; this.exceptionStack += "server stack:";
} } else {
this.exceptionStack += span.getExceptionStack(); this.exceptionStack += "client stack:";
} }
} this.exceptionStack += span.getExceptionStack();
}
public TraceSpanNode prev() { }
return prev;
} public TraceSpanNode prev() {
return prev;
public TraceSpanNode next() { }
return next;
} public TraceSpanNode next() {
return next;
public TraceSpanNode parent() { }
return parent;
} public TraceSpanNode parent() {
return parent;
public TraceSpanNode sub() { }
return sub;
} public TraceSpanNode sub() {
return sub;
public void setPrev(TraceSpanNode prev) { }
this.prev = prev;
} public void setPrev(TraceSpanNode prev) {
this.prev = prev;
public void setNext(TraceSpanNode next) { }
this.next = next;
} public void setNext(TraceSpanNode next) {
this.next = next;
public void setParent(TraceSpanNode parent) { }
this.parent = parent;
} public void setParent(TraceSpanNode parent) {
this.parent = parent;
public void setSub(TraceSpanNode sub) { }
this.sub = sub;
} public void setSub(TraceSpanNode sub) {
this.sub = sub;
public boolean isVisualNode() { }
return visualNode;
} public boolean isVisualNode() {
return visualNode;
public String getParentLevel() { }
return parentLevel;
} public String getParentLevel() {
return parentLevel;
public int getLevelId() { }
return levelId;
} public int getLevelId() {
return levelId;
public String getViewPointId() { }
return viewPointId;
} public String getViewPointId() {
return viewPointId;
public long getCost() { }
return cost;
} public long getCost() {
return cost;
public byte getStatusCode() { }
return statusCode;
} public byte getStatusCode() {
return statusCode;
public String getExceptionStack() { }
return exceptionStack;
} public String getExceptionStack() {
return exceptionStack;
public String getSpanType() { }
return spanType;
} public String getSpanType() {
return spanType;
public String getBusinessKey() { }
return businessKey;
} public String getBusinessKey() {
return businessKey;
public String getApplicationId() { }
return applicationId;
} public String getApplicationId() {
return applicationId;
public String getNodeRefToken() throws TraceSpanTreeSerializeException { }
if(StringUtil.isBlank(nodeRefToken)){
throw new TraceSpanTreeSerializeException("parentLevel=" + parentLevel + ", levelId=" + levelId + ", viewPointId=" + viewPointId + ", node ref token is null."); public String getNodeRefToken() throws TraceSpanTreeSerializeException {
} if (StringUtil.isBlank(nodeRefToken)) {
return nodeRefToken; throw new TraceSpanTreeSerializeException("parentLevel=" + parentLevel + ", levelId=" + levelId + ", viewPointId=" + viewPointId + ", node ref token is null.");
} }
return nodeRefToken;
void serializeRef() throws TraceSpanTreeSerializeException{ }
if(prev != null){
prevNodeRefToken = prev.getNodeRefToken(); void serializeRef() throws TraceSpanTreeSerializeException {
} if (prev != null) {
if(parent != null){ prevNodeRefToken = prev.getNodeRefToken();
parentNodeRefToken = parent.getNodeRefToken(); }
} if (parent != null) {
if(next != null){ parentNodeRefToken = parent.getNodeRefToken();
nextNodeRefToken = next.getNodeRefToken(); }
} if (next != null) {
if(sub != null){ nextNodeRefToken = next.getNodeRefToken();
subNodeRefToken = sub.getNodeRefToken(); }
} if (sub != null) {
} subNodeRefToken = sub.getNodeRefToken();
}
}
} }
package com.ai.cloud.skywalking.analysis.chainbuild.entity; package com.ai.cloud.skywalking.analysis.chainbuild.entity;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ai.cloud.skywalking.analysis.chainbuild.exception.BuildTraceSpanTreeException; import com.ai.cloud.skywalking.analysis.chainbuild.exception.BuildTraceSpanTreeException;
import com.ai.cloud.skywalking.analysis.chainbuild.exception.TraceSpanTreeSerializeException; import com.ai.cloud.skywalking.analysis.chainbuild.exception.TraceSpanTreeSerializeException;
import com.ai.cloud.skywalking.analysis.chainbuild.util.StringUtil; import com.ai.cloud.skywalking.analysis.chainbuild.util.StringUtil;
import com.ai.cloud.skywalking.analysis.chainbuild.util.TokenGenerator; import com.ai.cloud.skywalking.analysis.chainbuild.util.TokenGenerator;
import com.ai.cloud.skywalking.protocol.Span; import com.ai.cloud.skywalking.protocol.Span;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import org.apache.hadoop.io.Writable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TraceSpanTree { import java.io.DataInput;
private Logger logger = LoggerFactory.getLogger(TraceSpanTree.class); import java.io.DataOutput;
import java.io.IOException;
private String userId = null; import java.util.ArrayList;
import java.util.Collections;
private String cid; import java.util.Comparator;
import java.util.List;
private TraceSpanNode treeRoot;
private List<TraceSpanNode> spanContainer = new ArrayList<TraceSpanNode>();
public TraceSpanTree() {
}
public String build(List<Span> spanList) throws BuildTraceSpanTreeException {
if (spanList.size() == 0) {
throw new BuildTraceSpanTreeException("spanList is empty.");
}
Collections.sort(spanList, new Comparator<Span>() {
@Override
public int compare(Span span1, Span span2) {
String span1TraceLevel = span1.getParentLevel() + "."
+ span1.getLevelId();
String span2TraceLevel = span2.getParentLevel() + "."
+ span2.getLevelId();
return span1TraceLevel.compareTo(span2TraceLevel);
}
});
cid = generateChainToken(spanList.get(0));
treeRoot = new TraceSpanNode(null, null, null, null, spanList.get(0), spanContainer);
if (spanList.size() > 1) {
for (int i = 1; i < spanList.size(); i++) {
this.build(spanList.get(i));
}
}
return cid;
}
private void build(Span span) throws BuildTraceSpanTreeException {
if (userId == null && span.getUserId() != null) {
userId = span.getUserId();
}
TraceSpanNode clientOrServerNode = findNodeAndCreateVisualNodeIfNess(
span.getParentLevel(), span.getLevelId());
if (clientOrServerNode != null) {
clientOrServerNode.mergeSpan(span);
}
if (span.getLevelId() > 0) {
TraceSpanNode foundNode = findNodeAndCreateVisualNodeIfNess(
span.getParentLevel(), span.getLevelId() - 1);
if (foundNode != null) {
new TraceSpanNode(null, null, foundNode, foundNode.next(), span, spanContainer);
}
} else {
/**
* levelId=0 find for parent level if parentLevelId = 0.0.1 then
* find node[parentLevelId=0.0,levelId=1]
*/
String parentLevel = span.getParentLevel();
int idx = parentLevel.lastIndexOf("\\.");
if (idx < 0) {
throw new BuildTraceSpanTreeException("parentLevel="
+ parentLevel + " is unexpected.");
}
TraceSpanNode foundNode = findNodeAndCreateVisualNodeIfNess(
parentLevel.substring(0, idx),
Integer.parseInt(parentLevel.substring(idx + 1)));
}
}
private TraceSpanNode findNodeAndCreateVisualNodeIfNess(
String parentLevelId, int levelId) {
String levelDesc = StringUtil.isBlank(parentLevelId) ? (levelId + "")
: (parentLevelId + "." + levelId);
String[] levelArray = levelDesc.split("\\.");
TraceSpanNode currentNode = treeRoot;
String contextParentLevelId = "";
for (String currentLevel : levelArray) {
int currentLevelInt = Integer.parseInt(currentLevel);
for (int i = 0; i < currentLevelInt; i++) {
if (currentNode.hasNext()) {
currentNode = currentNode.next();
} else {
// create visual next node
currentNode = new VisualTraceSpanNode(null, null,
currentNode, null, contextParentLevelId, i, spanContainer);
}
}
contextParentLevelId = contextParentLevelId == "" ? ("" + currentLevelInt)
: (contextParentLevelId + "." + currentLevelInt);
if (currentNode.hasSub()) {
currentNode = currentNode.sub();
} else {
// create visual sub node
currentNode = new VisualTraceSpanNode(currentNode, null, null,
null, contextParentLevelId, 0, spanContainer);
}
}
return currentNode;
}
private String generateChainToken(Span level0Span)
throws BuildTraceSpanTreeException {
if (StringUtil.isBlank(level0Span.getParentLevel())
&& level0Span.getLevelId() == 0) {
StringBuilder chainTokenDesc = new StringBuilder();
chainTokenDesc.append(level0Span.getViewPointId());
return TokenGenerator.generateCID(chainTokenDesc.toString());
} else {
throw new BuildTraceSpanTreeException("tid:"
+ level0Span.getTraceId() + " level0 span data is illegal");
}
}
private void beforeSerialize() throws TraceSpanTreeSerializeException{
for(TraceSpanNode treeNode : spanContainer){
treeNode.serializeRef();
}
}
public class TraceSpanTree implements Writable {
private Logger logger = LoggerFactory.getLogger(TraceSpanTree.class);
private String userId = null;
private String cid;
private TraceSpanNode treeRoot;
private List<TraceSpanNode> spanContainer = new ArrayList<TraceSpanNode>();
public TraceSpanTree() {
}
public String build(List<Span> spanList) throws BuildTraceSpanTreeException {
if (spanList.size() == 0) {
throw new BuildTraceSpanTreeException("spanList is empty.");
}
Collections.sort(spanList, new Comparator<Span>() {
@Override
public int compare(Span span1, Span span2) {
String span1TraceLevel = span1.getParentLevel() + "."
+ span1.getLevelId();
String span2TraceLevel = span2.getParentLevel() + "."
+ span2.getLevelId();
return span1TraceLevel.compareTo(span2TraceLevel);
}
});
cid = generateChainToken(spanList.get(0));
treeRoot = new TraceSpanNode(null, null, null, null, spanList.get(0), spanContainer);
if (spanList.size() > 1) {
for (int i = 1; i < spanList.size(); i++) {
this.build(spanList.get(i));
}
}
return cid;
}
private void build(Span span) throws BuildTraceSpanTreeException {
if (userId == null && span.getUserId() != null) {
userId = span.getUserId();
}
TraceSpanNode clientOrServerNode = findNodeAndCreateVisualNodeIfNess(
span.getParentLevel(), span.getLevelId());
if (clientOrServerNode != null) {
clientOrServerNode.mergeSpan(span);
}
if (span.getLevelId() > 0) {
TraceSpanNode foundNode = findNodeAndCreateVisualNodeIfNess(
span.getParentLevel(), span.getLevelId() - 1);
if (foundNode != null) {
new TraceSpanNode(null, null, foundNode, foundNode.next(), span, spanContainer);
}
} else {
/**
* levelId=0 find for parent level if parentLevelId = 0.0.1 then
* find node[parentLevelId=0.0,levelId=1]
*/
String parentLevel = span.getParentLevel();
int idx = parentLevel.lastIndexOf("\\.");
if (idx < 0) {
throw new BuildTraceSpanTreeException("parentLevel="
+ parentLevel + " is unexpected.");
}
TraceSpanNode foundNode = findNodeAndCreateVisualNodeIfNess(
parentLevel.substring(0, idx),
Integer.parseInt(parentLevel.substring(idx + 1)));
}
}
private TraceSpanNode findNodeAndCreateVisualNodeIfNess(
String parentLevelId, int levelId) {
String levelDesc = StringUtil.isBlank(parentLevelId) ? (levelId + "")
: (parentLevelId + "." + levelId);
String[] levelArray = levelDesc.split("\\.");
TraceSpanNode currentNode = treeRoot;
String contextParentLevelId = "";
for (String currentLevel : levelArray) {
int currentLevelInt = Integer.parseInt(currentLevel);
for (int i = 0; i < currentLevelInt; i++) {
if (currentNode.hasNext()) {
currentNode = currentNode.next();
} else {
// create visual next node
currentNode = new VisualTraceSpanNode(null, null,
currentNode, null, contextParentLevelId, i, spanContainer);
}
}
contextParentLevelId = contextParentLevelId == "" ? ("" + currentLevelInt)
: (contextParentLevelId + "." + currentLevelInt);
if (currentNode.hasSub()) {
currentNode = currentNode.sub();
} else {
// create visual sub node
currentNode = new VisualTraceSpanNode(currentNode, null, null,
null, contextParentLevelId, 0, spanContainer);
}
}
return currentNode;
}
private String generateChainToken(Span level0Span)
throws BuildTraceSpanTreeException {
if (StringUtil.isBlank(level0Span.getParentLevel())
&& level0Span.getLevelId() == 0) {
StringBuilder chainTokenDesc = new StringBuilder();
chainTokenDesc.append(level0Span.getViewPointId());
return TokenGenerator.generateCID(chainTokenDesc.toString());
} else {
throw new BuildTraceSpanTreeException("tid:"
+ level0Span.getTraceId() + " level0 span data is illegal");
}
}
private void beforeSerialize() throws TraceSpanTreeSerializeException {
for (TraceSpanNode treeNode : spanContainer) {
treeNode.serializeRef();
}
}
public String serialize() throws TraceSpanTreeSerializeException {
beforeSerialize();
return new Gson().toJson(this);
}
@Override
public void write(DataOutput out) throws IOException {
try {
out.write(serialize().getBytes());
} catch (TraceSpanTreeSerializeException e) {
logger.error("Failed to serialize Chain Id[" + cid + "]", e);
}
}
@Override
public void readFields(DataInput in) throws IOException {
String value = in.readLine();
try {
JsonObject jsonObject = (JsonObject) new JsonParser().parse(value);
userId = jsonObject.get("userId").getAsString();
cid = jsonObject.get("cid").getAsString();
treeRoot = new Gson().fromJson(jsonObject.get("treeRoot"), TraceSpanNode.class);
spanContainer = new Gson().fromJson(jsonObject.get("spanContainer"),
new TypeToken<List<TraceSpanNode>>() {
}.getType());
} catch (Exception e) {
logger.error("Failed to parse the value[" + value + "] to TraceSpanTree Object", e);
}
}
public TraceSpanNode getTreeRoot() {
return treeRoot;
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册