Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿信在这里
SkyWalking
提交
0131a35d
S
SkyWalking
项目概览
阿信在这里
/
SkyWalking
与 Fork 源项目一致
Fork自
山不在高_有仙则灵 / SkyWalking
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0131a35d
编写于
3月 02, 2016
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完善序列化和反序列化代码。
上级
62b43cde
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
105 addition
and
24 deletion
+105
-24
skywalking-analysis/src/main/java/com/ai/cloud/skywalking/analysis/chainbuild/entity/TraceSpanNode.java
.../skywalking/analysis/chainbuild/entity/TraceSpanNode.java
+47
-7
skywalking-analysis/src/main/java/com/ai/cloud/skywalking/analysis/chainbuild/entity/TraceSpanTree.java
.../skywalking/analysis/chainbuild/entity/TraceSpanTree.java
+45
-17
skywalking-analysis/src/main/java/com/ai/cloud/skywalking/analysis/chainbuild/exception/TraceSpanTreeNotFountException.java
.../chainbuild/exception/TraceSpanTreeNotFountException.java
+13
-0
未找到文件。
skywalking-analysis/src/main/java/com/ai/cloud/skywalking/analysis/chainbuild/entity/TraceSpanNode.java
浏览文件 @
0131a35d
package
com.ai.cloud.skywalking.analysis.chainbuild.entity
;
import
java.util.List
;
import
com.ai.cloud.skywalking.analysis.chainbuild.exception.TraceSpanTreeNotFountException
;
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.TokenGenerator
;
...
...
@@ -7,8 +10,6 @@ import com.ai.cloud.skywalking.protocol.CallType;
import
com.ai.cloud.skywalking.protocol.Span
;
import
com.google.gson.annotations.Expose
;
import
java.util.List
;
public
class
TraceSpanNode
{
protected
TraceSpanNode
prev
=
null
;
...
...
@@ -88,6 +89,13 @@ public class TraceSpanNode {
@Expose
protected
String
applicationId
=
""
;
/**
* Warning: call this constructor ONLY by gson for deserialize
*/
public
TraceSpanNode
(){
}
public
TraceSpanNode
(
TraceSpanNode
parent
,
TraceSpanNode
sub
,
TraceSpanNode
prev
,
TraceSpanNode
next
,
Span
span
,
List
<
TraceSpanNode
>
spanContainer
)
{
this
(
parent
,
sub
,
prev
,
next
,
spanContainer
);
this
.
visualNode
=
false
;
...
...
@@ -170,19 +178,47 @@ public class TraceSpanNode {
}
}
public
TraceSpanNode
prev
()
{
public
TraceSpanNode
prev
(
TraceSpanTree
tree
)
throws
TraceSpanTreeNotFountException
{
if
(
prev
==
null
){
if
(
prevNodeRefToken
==
null
){
throw
new
TraceSpanTreeNotFountException
(
getDesc
()
+
" unexpected prev== null and prevNodeRefToken==null"
);
}
else
{
prev
=
tree
.
findNode
(
prevNodeRefToken
);
}
}
return
prev
;
}
public
TraceSpanNode
next
()
{
public
TraceSpanNode
next
(
TraceSpanTree
tree
)
throws
TraceSpanTreeNotFountException
{
if
(
next
==
null
){
if
(
nextNodeRefToken
==
null
){
throw
new
TraceSpanTreeNotFountException
(
getDesc
()
+
" unexpected next== null and nextNodeRefToken==null"
);
}
else
{
next
=
tree
.
findNode
(
nextNodeRefToken
);
}
}
return
next
;
}
public
TraceSpanNode
parent
()
{
public
TraceSpanNode
parent
(
TraceSpanTree
tree
)
throws
TraceSpanTreeNotFountException
{
if
(
parent
==
null
){
if
(
parentNodeRefToken
==
null
){
throw
new
TraceSpanTreeNotFountException
(
getDesc
()
+
" unexpected parent== null and parentNodeRefToken==null"
);
}
else
{
parent
=
tree
.
findNode
(
parentNodeRefToken
);
}
}
return
parent
;
}
public
TraceSpanNode
sub
()
{
public
TraceSpanNode
sub
(
TraceSpanTree
tree
)
throws
TraceSpanTreeNotFountException
{
if
(
sub
==
null
){
if
(
subNodeRefToken
==
null
){
throw
new
TraceSpanTreeNotFountException
(
getDesc
()
+
" unexpected sub== null and subNodeRefToken==null"
);
}
else
{
sub
=
tree
.
findNode
(
subNodeRefToken
);
}
}
return
sub
;
}
...
...
@@ -244,10 +280,14 @@ public class TraceSpanNode {
public
String
getNodeRefToken
()
throws
TraceSpanTreeSerializeException
{
if
(
StringUtil
.
isBlank
(
nodeRefToken
))
{
throw
new
TraceSpanTreeSerializeException
(
"parentLevel="
+
parentLevel
+
", levelId="
+
levelId
+
", viewPointId="
+
viewPointId
+
", node
ref token is null."
);
throw
new
TraceSpanTreeSerializeException
(
getDesc
()
+
"
ref token is null."
);
}
return
nodeRefToken
;
}
private
String
getDesc
(){
return
"Node[parentLevel="
+
parentLevel
+
", levelId="
+
levelId
+
", viewPointId="
+
viewPointId
+
"]"
;
}
void
serializeRef
()
throws
TraceSpanTreeSerializeException
{
if
(
prev
!=
null
)
{
...
...
skywalking-analysis/src/main/java/com/ai/cloud/skywalking/analysis/chainbuild/entity/TraceSpanTree.java
浏览文件 @
0131a35d
package
com.ai.cloud.skywalking.analysis.chainbuild.entity
;
import
java.io.DataInput
;
import
java.io.DataOutput
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.hadoop.io.Writable
;
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.TraceSpanTreeNotFountException
;
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.TokenGenerator
;
...
...
@@ -9,34 +24,30 @@ import com.google.gson.Gson;
import
com.google.gson.GsonBuilder
;
import
com.google.gson.JsonObject
;
import
com.google.gson.JsonParser
;
import
com.google.gson.annotations.Expose
;
import
com.google.gson.reflect.TypeToken
;
import
org.apache.hadoop.io.Writable
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.DataInput
;
import
java.io.DataOutput
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
public
class
TraceSpanTree
implements
Writable
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
TraceSpanTree
.
class
);
@Expose
private
String
userId
=
null
;
@Expose
private
String
cid
;
@Expose
private
TraceSpanNode
treeRoot
;
@Expose
private
List
<
TraceSpanNode
>
spanContainer
=
new
ArrayList
<
TraceSpanNode
>();
private
Map
<
String
,
TraceSpanNode
>
traceSpanNodeMap
=
new
HashMap
<
String
,
TraceSpanNode
>();
public
TraceSpanTree
()
{
}
public
String
build
(
List
<
Span
>
spanList
)
throws
BuildTraceSpanTreeException
{
public
String
build
(
List
<
Span
>
spanList
)
throws
BuildTraceSpanTreeException
,
TraceSpanTreeNotFountException
{
if
(
spanList
.
size
()
==
0
)
{
throw
new
BuildTraceSpanTreeException
(
"spanList is empty."
);
}
...
...
@@ -62,7 +73,7 @@ public class TraceSpanTree implements Writable {
return
cid
;
}
private
void
build
(
Span
span
)
throws
BuildTraceSpanTreeException
{
private
void
build
(
Span
span
)
throws
BuildTraceSpanTreeException
,
TraceSpanTreeNotFountException
{
if
(
userId
==
null
&&
span
.
getUserId
()
!=
null
)
{
userId
=
span
.
getUserId
();
}
...
...
@@ -76,7 +87,10 @@ public class TraceSpanTree implements Writable {
if
(
span
.
getLevelId
()
>
0
)
{
TraceSpanNode
foundNode
=
findNodeAndCreateVisualNodeIfNess
(
span
.
getParentLevel
(),
span
.
getLevelId
()
-
1
);
new
TraceSpanNode
(
null
,
null
,
foundNode
,
foundNode
.
next
(),
span
,
spanContainer
);
/**
* Create node between foundNode and foundNode.next(maybe foundNode.next == null)
*/
new
TraceSpanNode
(
null
,
null
,
foundNode
,
foundNode
.
next
(
this
),
span
,
spanContainer
);
}
else
{
/**
* levelId=0 find for parent level if parentLevelId = 0.0.1 then
...
...
@@ -91,13 +105,16 @@ public class TraceSpanTree implements Writable {
TraceSpanNode
foundNode
=
findNodeAndCreateVisualNodeIfNess
(
parentLevel
.
substring
(
0
,
idx
),
Integer
.
parseInt
(
parentLevel
.
substring
(
idx
+
1
)));
/**
* Create sub node of using span data. FoundNode is parent node.
*/
new
TraceSpanNode
(
foundNode
,
null
,
null
,
null
,
span
,
spanContainer
);
}
}
private
TraceSpanNode
findNodeAndCreateVisualNodeIfNess
(
String
parentLevelId
,
int
levelId
)
{
String
parentLevelId
,
int
levelId
)
throws
TraceSpanTreeNotFountException
{
String
levelDesc
=
StringUtil
.
isBlank
(
parentLevelId
)
?
(
levelId
+
""
)
:
(
parentLevelId
+
"."
+
levelId
);
String
[]
levelArray
=
levelDesc
.
split
(
"\\."
);
...
...
@@ -108,7 +125,7 @@ public class TraceSpanTree implements Writable {
int
currentLevelInt
=
Integer
.
parseInt
(
currentLevel
);
for
(
int
i
=
0
;
i
<
currentLevelInt
;
i
++)
{
if
(
currentNode
.
hasNext
())
{
currentNode
=
currentNode
.
next
();
currentNode
=
currentNode
.
next
(
this
);
}
else
{
// create visual next node
currentNode
=
new
VisualTraceSpanNode
(
null
,
null
,
...
...
@@ -118,7 +135,7 @@ public class TraceSpanTree implements Writable {
contextParentLevelId
=
contextParentLevelId
==
""
?
(
""
+
currentLevelInt
)
:
(
contextParentLevelId
+
"."
+
currentLevelInt
);
if
(
currentNode
.
hasSub
())
{
currentNode
=
currentNode
.
sub
();
currentNode
=
currentNode
.
sub
(
this
);
}
else
{
// create visual sub node
currentNode
=
new
VisualTraceSpanNode
(
currentNode
,
null
,
null
,
...
...
@@ -153,6 +170,14 @@ public class TraceSpanTree implements Writable {
beforeSerialize
();
return
new
GsonBuilder
().
excludeFieldsWithoutExposeAnnotation
().
create
().
toJson
(
this
);
}
TraceSpanNode
findNode
(
String
nodeRefToken
)
throws
TraceSpanTreeNotFountException
{
if
(
traceSpanNodeMap
.
containsKey
(
nodeRefToken
)){
return
traceSpanNodeMap
.
get
(
nodeRefToken
);
}
else
{
throw
new
TraceSpanTreeNotFountException
(
"nodeRefToken="
+
nodeRefToken
+
" not found."
);
}
}
@Override
public
void
write
(
DataOutput
out
)
throws
IOException
{
...
...
@@ -174,6 +199,9 @@ public class TraceSpanTree implements Writable {
spanContainer
=
new
Gson
().
fromJson
(
jsonObject
.
get
(
"spanContainer"
),
new
TypeToken
<
List
<
TraceSpanNode
>>()
{
}.
getType
());
for
(
TraceSpanNode
node
:
spanContainer
){
traceSpanNodeMap
.
put
(
node
.
getNodeRefToken
(),
node
);
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"Failed to parse the value["
+
value
+
"] to TraceSpanTree Object"
,
e
);
}
...
...
skywalking-analysis/src/main/java/com/ai/cloud/skywalking/analysis/chainbuild/exception/TraceSpanTreeNotFountException.java
0 → 100644
浏览文件 @
0131a35d
package
com.ai.cloud.skywalking.analysis.chainbuild.exception
;
public
class
TraceSpanTreeNotFountException
extends
Exception
{
private
static
final
long
serialVersionUID
=
5559441397011866237L
;
public
TraceSpanTreeNotFountException
(
String
msg
){
super
(
msg
);
}
public
TraceSpanTreeNotFountException
(
String
msg
,
Exception
cause
){
super
(
msg
,
cause
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录