Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
月轩居士
SkyWalking
提交
59c1038e
S
SkyWalking
项目概览
月轩居士
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
4
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,发现更多精彩内容 >>
提交
59c1038e
编写于
1月 13, 2017
作者:
wu-sheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor codes, and add comments.
上级
45a5d125
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
58 addition
and
40 deletion
+58
-40
skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/RestfulAPIService.java
.../com/a/eye/skywalking/routing/http/RestfulAPIService.java
+6
-9
skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/module/AckSpanModule.java
...m/a/eye/skywalking/routing/http/module/AckSpanModule.java
+8
-6
skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/module/RequestSpanModule.java
...eye/skywalking/routing/http/module/RequestSpanModule.java
+9
-7
skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/module/ResponseMessage.java
...a/eye/skywalking/routing/http/module/ResponseMessage.java
+35
-18
未找到文件。
skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/RestfulAPIService.java
浏览文件 @
59c1038e
...
...
@@ -2,7 +2,6 @@ package com.a.eye.skywalking.routing.http;
import
com.a.eye.skywalking.logging.api.ILog
;
import
com.a.eye.skywalking.logging.api.LogManager
;
import
com.a.eye.skywalking.network.dependencies.com.google.gson.Gson
;
import
com.a.eye.skywalking.routing.http.module.ResponseMessage
;
import
java.io.IOException
;
...
...
@@ -11,20 +10,19 @@ import java.util.Map;
import
fi.iki.elonen.NanoHTTPD
;
import
static
com
.
a
.
eye
.
skywalking
.
routing
.
http
.
module
.
ResponseMessage
.
REQUEST_METHOD
_NOT_SUPPORT
;
import
static
com
.
a
.
eye
.
skywalking
.
routing
.
http
.
module
.
ResponseMessage
.
GET
_NOT_SUPPORT
;
import
static
com
.
a
.
eye
.
skywalking
.
routing
.
http
.
module
.
ResponseMessage
.
SERVER_ERROR
;
public
class
RestfulAPIService
extends
NanoHTTPD
{
public
static
final
String
JSON_MIME_TYPE
=
"application/json"
;
private
static
ILog
logger
=
LogManager
.
getLogger
(
RestfulAPIService
.
class
);
private
static
final
SpanStorageController
spanController
=
new
SpanStorageController
();
public
static
final
String
JSON_MIME_TYPE
=
"application/json"
;
private
ILog
logger
=
LogManager
.
getLogger
(
RestfulAPIService
.
class
);
public
RestfulAPIService
(
String
host
,
int
port
)
{
super
(
host
,
port
);
}
public
void
doStart
()
throws
IOException
{
try
{
start
(
NanoHTTPD
.
SOCKET_READ_TIMEOUT
,
false
);
...
...
@@ -39,10 +37,10 @@ public class RestfulAPIService extends NanoHTTPD {
public
Response
serve
(
IHTTPSession
session
)
{
if
(
session
.
getMethod
()
!=
Method
.
POST
)
{
return
newFixedLengthResponse
(
Response
.
Status
.
OK
,
JSON_MIME_TYPE
,
new
Gson
().
toJson
(
REQUEST_METHOD
_NOT_SUPPORT
));
String
.
valueOf
(
GET
_NOT_SUPPORT
));
}
ResponseMessage
responseMessage
=
ResponseMessage
.
URL_
NOT_FOUND
;
ResponseMessage
responseMessage
=
ResponseMessage
.
NOT_FOUND
;
try
{
String
postData
=
getPostData
(
session
);
if
(
spanController
.
isAddAckSpanURI
(
session
.
getUri
()))
{
...
...
@@ -58,8 +56,7 @@ public class RestfulAPIService extends NanoHTTPD {
responseMessage
=
SERVER_ERROR
;
}
return
newFixedLengthResponse
(
Response
.
Status
.
OK
,
JSON_MIME_TYPE
,
new
Gson
().
toJson
(
responseMessage
));
return
newFixedLengthResponse
(
Response
.
Status
.
OK
,
JSON_MIME_TYPE
,
String
.
valueOf
(
responseMessage
));
}
/**
...
...
skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/module/AckSpanModule.java
浏览文件 @
59c1038e
...
...
@@ -9,13 +9,16 @@ import java.util.Map;
/**
* Ack span module
* <p>
* All fields in this class will be initialized by {@link com.google.gson.Gson#fromJson(String, Class)},
* ignore the un-assign values warning.
*/
public
class
AckSpanModule
{
private
String
traceId
;
private
String
parentLevelId
=
""
;
private
int
levelId
=
0
;
private
int
levelId
=
0
;
private
long
cost
;
private
int
routeKey
;
private
int
routeKey
;
private
Map
<
String
,
String
>
tags
;
...
...
@@ -24,16 +27,15 @@ public class AckSpanModule {
return
null
;
}
return
AckSpan
.
newBuilder
().
putAllTags
(
tags
).
setLevelId
(
levelId
).
setParentLevel
(
parentLevelId
).
setRouteKey
(
routeKey
).
setCost
(
cost
)
.
setTraceId
(
TraceIdUtil
.
toTraceId
(
traceId
)).
build
();
return
AckSpan
.
newBuilder
().
putAllTags
(
tags
).
setLevelId
(
levelId
).
setParentLevel
(
parentLevelId
)
.
setRouteKey
(
routeKey
).
setCost
(
cost
).
setTraceId
(
TraceIdUtil
.
toTraceId
(
traceId
)).
build
();
}
private
boolean
illegalAckSpan
()
{
if
(
StringUtil
.
isEmpty
(
traceId
))
{
return
true
;
}
if
(
tags
.
isEmpty
()){
if
(
tags
.
isEmpty
())
{
return
true
;
}
return
false
;
...
...
skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/module/RequestSpanModule.java
浏览文件 @
59c1038e
...
...
@@ -9,22 +9,24 @@ import java.util.Map;
/**
* request span module
* <p>
* All fields in this class will be initialized by {@link com.google.gson.Gson#fromJson(String, Class)},
* ignore the un-assign values warning.
*/
public
class
RequestSpanModule
{
private
String
traceId
;
private
String
parentLevelId
=
""
;
private
int
levelId
;
private
long
startTime
;
private
int
routeKey
;
private
int
levelId
;
private
long
startTime
;
private
int
routeKey
;
private
Map
<
String
,
String
>
tags
;
public
RequestSpan
convertToGRPCModule
()
{
if
(
illegalRequestSpan
())
{
return
null
;
}
return
RequestSpan
.
newBuilder
().
putAllTags
(
tags
).
setLevelId
(
levelId
).
setParentLevel
(
parentLevelId
).
setRouteKey
(
routeKey
).
setStartDate
(
startTime
)
.
setTraceId
(
TraceIdUtil
.
toTraceId
(
traceId
)).
build
();
return
RequestSpan
.
newBuilder
().
putAllTags
(
tags
).
setLevelId
(
levelId
).
setParentLevel
(
parentLevelId
)
.
setRouteKey
(
routeKey
).
setStartDate
(
startTime
).
setTraceId
(
TraceIdUtil
.
toTraceId
(
traceId
)).
build
();
}
...
...
@@ -32,7 +34,7 @@ public class RequestSpanModule {
if
(
StringUtil
.
isEmpty
(
traceId
))
{
return
true
;
}
if
(
tags
.
isEmpty
()){
if
(
tags
.
isEmpty
())
{
return
true
;
}
return
false
;
...
...
skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/module/ResponseMessage.java
浏览文件 @
59c1038e
package
com.a.eye.skywalking.routing.http.module
;
import
com.google.gson.JsonObject
;
import
com.a.eye.skywalking.network.dependencies.com.google.gson.Gson
;
public
class
ResponseMessage
{
public
static
final
ResponseMessage
OK
=
new
ResponseMessage
(
200
,
"Store success"
);
public
static
final
ResponseMessage
REQUEST_METHOD_NOT_SUPPORT
=
new
ResponseMessage
(
403
,
"Request method "
+
"not support"
);
public
static
final
ResponseMessage
SERVER_ERROR
=
new
ResponseMessage
(
500
,
"Server error"
);
public
static
final
ResponseMessage
URL_NOT_FOUND
=
new
ResponseMessage
(
404
,
"Not found"
);
/**
* A {@link ResponseMessage} represent a status code and response messages for http-service.
* <p>
* Created by wusheng on 2017/1/13.
*/
public
enum
ResponseMessage
{
/**
* Request span or Ack Span are received and parsed without any errors.
*/
OK
(
200
,
"Store success"
),
/**
* Request a no-supported service.
*/
GET_NOT_SUPPORT
(
405
,
"Get method not support"
),
/**
* An internal error occurs.
*/
SERVER_ERROR
(
500
,
"Server error"
),
/**
* No service found. Also mean not provide this service.
*/
NOT_FOUND
(
404
,
"Not found"
);
/**
* Response code:
* 200 -- store success
* 403 -- request method not support
* 500 -- server error
* 404 -- not found
* The {@link String} represents the return message of the http services.
* It is in the JSON format, and formatted by {@link com.google.gson.Gson}.
*/
private
int
code
;
private
String
message
;
ResponseMessage
(
int
code
,
String
message
)
{
this
.
code
=
code
;
this
.
message
=
message
;
JsonObject
messageFormatter
=
new
JsonObject
();
messageFormatter
.
addProperty
(
"code"
,
code
);
messageFormatter
.
addProperty
(
"message"
,
message
);
this
.
message
=
messageFormatter
.
toString
();
}
public
int
getCode
()
{
return
code
;
/**
* @return the return message of the http services.
*/
@Override
public
String
toString
()
{
return
message
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录