Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
月轩居士
SkyWalking
提交
cffa3e1d
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,发现更多精彩内容 >>
提交
cffa3e1d
编写于
1月 13, 2017
作者:
A
ascrutae
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复部分问题
上级
59c1038e
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
74 addition
and
45 deletion
+74
-45
skywalking-commons/skywalking-util/src/main/java/com/a/eye/skywalking/util/TraceIdUtil.java
.../src/main/java/com/a/eye/skywalking/util/TraceIdUtil.java
+9
-0
skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/RestfulAPIService.java
.../com/a/eye/skywalking/routing/http/RestfulAPIService.java
+3
-2
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
+9
-9
skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/module/RequestSpanModule.java
...eye/skywalking/routing/http/module/RequestSpanModule.java
+10
-10
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
+20
-6
skywalking-storage-center/skywalking-routing/src/test/java/com/a/eye/skywalking/routing/http/ResponseResult.java
...ava/com/a/eye/skywalking/routing/http/ResponseResult.java
+6
-4
skywalking-storage-center/skywalking-routing/src/test/java/com/a/eye/skywalking/routing/http/RestfulAPIServiceTest.java
.../a/eye/skywalking/routing/http/RestfulAPIServiceTest.java
+17
-14
未找到文件。
skywalking-commons/skywalking-util/src/main/java/com/a/eye/skywalking/util/TraceIdUtil.java
浏览文件 @
cffa3e1d
...
...
@@ -27,4 +27,13 @@ public class TraceIdUtil {
}
public
static
boolean
isIllegalTraceId
(
String
traceId
){
if
(
StringUtil
.
isEmpty
(
traceId
)){
return
true
;
}
return
traceId
.
split
(
"\\."
).
length
!=
6
;
}
}
skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/RestfulAPIService.java
浏览文件 @
cffa3e1d
...
...
@@ -36,7 +36,7 @@ public class RestfulAPIService extends NanoHTTPD {
@Override
public
Response
serve
(
IHTTPSession
session
)
{
if
(
session
.
getMethod
()
!=
Method
.
POST
)
{
return
newFixedLengthResponse
(
Response
.
Status
.
OK
,
JSON_MIME_TYPE
,
return
newFixedLengthResponse
(
GET_NOT_SUPPORT
.
getStatus
()
,
JSON_MIME_TYPE
,
String
.
valueOf
(
GET_NOT_SUPPORT
));
}
...
...
@@ -56,7 +56,8 @@ public class RestfulAPIService extends NanoHTTPD {
responseMessage
=
SERVER_ERROR
;
}
return
newFixedLengthResponse
(
Response
.
Status
.
OK
,
JSON_MIME_TYPE
,
String
.
valueOf
(
responseMessage
));
return
newFixedLengthResponse
(
responseMessage
.
getStatus
(),
JSON_MIME_TYPE
,
String
.
valueOf
(
responseMessage
));
}
/**
...
...
skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/module/AckSpanModule.java
浏览文件 @
cffa3e1d
...
...
@@ -4,21 +4,20 @@ import com.a.eye.skywalking.network.grpc.AckSpan;
import
com.a.eye.skywalking.util.StringUtil
;
import
com.a.eye.skywalking.util.TraceIdUtil
;
import
java.util.HashMap
;
import
java.util.Map
;
import
static
com
.
a
.
eye
.
skywalking
.
util
.
TraceIdUtil
.
isIllegalTraceId
;
/**
* 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.
* 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
String
parentLevelId
;
private
int
levelId
=
0
;
private
long
cost
;
private
int
routeKey
;
private
int
routeKey
;
private
Map
<
String
,
String
>
tags
;
...
...
@@ -32,9 +31,10 @@ public class AckSpanModule {
}
private
boolean
illegalAckSpan
()
{
if
(
StringUtil
.
isEmpty
(
traceId
))
{
if
(
isIllegalTraceId
(
traceId
))
{
return
true
;
}
if
(
tags
.
isEmpty
())
{
return
true
;
}
...
...
skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/module/RequestSpanModule.java
浏览文件 @
cffa3e1d
...
...
@@ -4,21 +4,20 @@ import com.a.eye.skywalking.network.grpc.RequestSpan;
import
com.a.eye.skywalking.util.StringUtil
;
import
com.a.eye.skywalking.util.TraceIdUtil
;
import
java.util.HashMap
;
import
java.util.Map
;
import
static
com
.
a
.
eye
.
skywalking
.
util
.
TraceIdUtil
.
isIllegalTraceId
;
/**
* 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.
* 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
String
parentLevelId
;
private
int
levelId
;
private
long
startTime
;
private
int
routeKey
;
private
Map
<
String
,
String
>
tags
;
public
RequestSpan
convertToGRPCModule
()
{
...
...
@@ -31,9 +30,10 @@ public class RequestSpanModule {
}
private
boolean
illegalRequestSpan
()
{
if
(
StringUtil
.
isEmpty
(
traceId
))
{
if
(
isIllegalTraceId
(
traceId
))
{
return
true
;
}
if
(
tags
.
isEmpty
())
{
return
true
;
}
...
...
skywalking-storage-center/skywalking-routing/src/main/java/com/a/eye/skywalking/routing/http/module/ResponseMessage.java
浏览文件 @
cffa3e1d
...
...
@@ -2,6 +2,9 @@ package com.a.eye.skywalking.routing.http.module;
import
com.google.gson.JsonObject
;
import
fi.iki.elonen.NanoHTTPD
;
/**
* A {@link ResponseMessage} represent a status code and response messages for http-service.
* <p>
...
...
@@ -11,19 +14,19 @@ public enum ResponseMessage {
/**
* Request span or Ack Span are received and parsed without any errors.
*/
OK
(
200
,
"Store success"
),
OK
(
NanoHTTPD
.
Response
.
Status
.
OK
,
"Store success"
),
/**
* Request a no-supported service.
*/
GET_NOT_SUPPORT
(
405
,
"Get method not support"
),
GET_NOT_SUPPORT
(
NanoHTTPD
.
Response
.
Status
.
METHOD_NOT_ALLOWED
,
"Get method not support"
),
/**
* An internal error occurs.
*/
SERVER_ERROR
(
500
,
"Server error"
),
SERVER_ERROR
(
NanoHTTPD
.
Response
.
Status
.
INTERNAL_ERROR
,
"Server error"
),
/**
* No service found. Also mean not provide this service.
*/
NOT_FOUND
(
404
,
"Not found"
);
NOT_FOUND
(
NanoHTTPD
.
Response
.
Status
.
NOT_FOUND
,
"Not found"
);
/**
* The {@link String} represents the return message of the http services.
...
...
@@ -31,13 +34,24 @@ public enum ResponseMessage {
*/
private
String
message
;
ResponseMessage
(
int
code
,
String
message
)
{
/**
*
*/
private
NanoHTTPD
.
Response
.
IStatus
status
;
ResponseMessage
(
NanoHTTPD
.
Response
.
Status
status
,
String
message
)
{
this
.
status
=
status
;
JsonObject
messageFormatter
=
new
JsonObject
();
messageFormatter
.
addProperty
(
"code"
,
code
);
messageFormatter
.
addProperty
(
"code"
,
status
.
getRequestStatus
()
);
messageFormatter
.
addProperty
(
"message"
,
message
);
this
.
message
=
messageFormatter
.
toString
();
}
public
NanoHTTPD
.
Response
.
IStatus
getStatus
()
{
return
status
;
}
/**
* @return the return message of the http services.
*/
...
...
skywalking-storage-center/skywalking-routing/src/test/java/com/a/eye/skywalking/routing/http/ResponseResult.java
浏览文件 @
cffa3e1d
package
com.a.eye.skywalking.routing.http
;
import
com.google.gson.Gson
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonObject
;
import
com.google.gson.JsonParser
;
import
com.a.eye.skywalking.routing.http.module.ResponseMessage
;
/**
* Created by xin on 2017/1/10.
...
...
@@ -16,8 +17,9 @@ public class ResponseResult {
this
.
responseBody
=
responseBody
;
}
public
ResponseMessage
getResponseMessage
()
{
return
new
Gson
().
fromJson
(
responseBody
,
ResponseMessage
.
class
);
public
JsonObject
getResponseMessage
()
{
JsonParser
jsonParser
=
new
JsonParser
();
return
(
JsonObject
)
jsonParser
.
parse
(
responseBody
);
}
public
int
getStatusCode
(){
...
...
skywalking-storage-center/skywalking-routing/src/test/java/com/a/eye/skywalking/routing/http/RestfulAPIServiceTest.java
浏览文件 @
cffa3e1d
package
com.a.eye.skywalking.routing.http
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonObject
;
import
com.a.eye.skywalking.routing.http.module.ResponseMessage
;
import
org.junit.After
;
...
...
@@ -28,17 +31,15 @@ public class RestfulAPIServiceTest {
@Test
public
void
testRequestMethodWithGet
()
throws
IOException
{
ResponseResult
responseResult
=
HttpClientUtil
.
doGet
(
REST_URL_PREFIX
);
assertEquals
(
200
,
responseResult
.
getStatusCode
());
ResponseMessage
responseMessage
=
responseResult
.
getResponseMessage
();
assertEquals
(
403
,
responseMessage
.
getCode
());
assertEquals
(
405
,
responseResult
.
getStatusCode
());
validateResponseCode
(
405
,
responseResult
);
}
@Test
public
void
testRequestMethodWithWrongURL
()
throws
IOException
{
ResponseResult
responseResult
=
HttpClientUtil
.
doPost
(
REST_URL_PREFIX
,
"{}"
);
assertEquals
(
200
,
responseResult
.
getStatusCode
());
ResponseMessage
responseMessage
=
responseResult
.
getResponseMessage
();
assertEquals
(
404
,
responseMessage
.
getCode
());
assertEquals
(
404
,
responseResult
.
getStatusCode
());
validateResponseCode
(
404
,
responseResult
);
}
@Test
...
...
@@ -58,8 +59,7 @@ public class RestfulAPIServiceTest {
" }\n"
+
"}]"
);
assertEquals
(
200
,
responseResult
.
getStatusCode
());
ResponseMessage
responseMessage
=
responseResult
.
getResponseMessage
();
assertEquals
(
200
,
responseMessage
.
getCode
());
validateResponseCode
(
200
,
responseResult
);
}
@Test
...
...
@@ -84,11 +84,9 @@ public class RestfulAPIServiceTest {
"}]"
);
assertEquals
(
200
,
responseResult
.
getStatusCode
());
ResponseMessage
responseMessage
=
responseResult
.
getResponseMessage
();
assertEquals
(
200
,
responseMessage
.
getCode
());
validateResponseCode
(
200
,
responseResult
);
}
@Test
public
void
testAddWithErrorRequestSpanJson
()
throws
IOException
{
ResponseResult
responseResult
=
HttpClientUtil
.
doPost
...
...
@@ -110,9 +108,14 @@ public class RestfulAPIServiceTest {
" }\n"
+
"}"
);
assertEquals
(
200
,
responseResult
.
getStatusCode
());
ResponseMessage
responseMessage
=
responseResult
.
getResponseMessage
();
assertEquals
(
500
,
responseMessage
.
getCode
());
assertEquals
(
500
,
responseResult
.
getStatusCode
());
validateResponseCode
(
500
,
responseResult
);
}
private
void
validateResponseCode
(
int
expectedCode
,
ResponseResult
responseResult
)
{
JsonObject
responseJson
=
responseResult
.
getResponseMessage
();
assertEquals
(
expectedCode
,
responseJson
.
get
(
"code"
).
getAsInt
());
}
@After
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录