Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Dapr
提交
1b78106c
D
Dapr
项目概览
int
/
Dapr
12 个月 前同步成功
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Dapr
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1b78106c
编写于
6月 21, 2019
作者:
Y
yaron2
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix local address check, fix test
上级
5966c45d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
20 addition
and
25 deletion
+20
-25
pkg/action/action.go
pkg/action/action.go
+17
-22
pkg/action/action_test.go
pkg/action/action_test.go
+3
-3
未找到文件。
pkg/action/action.go
浏览文件 @
1b78106c
...
...
@@ -728,7 +728,6 @@ func (i *Action) OnLocalBatchActivation(c *routing.Context) {
}
func
(
i
*
Action
)
OnInvokeAction
(
c
*
routing
.
Context
)
{
_
,
span
,
spanCtx
:=
i
.
TraceSpanFromRoutingContext
(
c
,
nil
,
"OnInvokeAction"
)
if
span
!=
nil
{
defer
span
.
End
()
...
...
@@ -741,9 +740,9 @@ func (i *Action) OnInvokeAction(c *routing.Context) {
targetAddress
:=
string
(
c
.
Request
.
Header
.
Peek
(
addressHeader
))
httpMethod
:=
string
(
c
.
Method
())
corI
d
:=
""
corI
D
:=
""
if
span
!=
nil
{
corI
d
=
diag
.
SerializeSpanContext
(
*
spanCtx
)
corI
D
=
diag
.
SerializeSpanContext
(
*
spanCtx
)
}
headers
:=
map
[
string
]
string
{
...
...
@@ -751,7 +750,7 @@ func (i *Action) OnInvokeAction(c *routing.Context) {
invokedHTTPVerbHeader
:
httpMethod
,
invokedMethodHeader
:
actionMethod
,
actionTargetIDHeader
:
actionID
,
diag
.
CorrelationID
:
corI
d
,
diag
.
CorrelationID
:
corI
D
,
}
if
contextID
!=
""
{
...
...
@@ -782,12 +781,9 @@ func (i *Action) OnInvokeAction(c *routing.Context) {
if
address
==
""
{
if
!
responseDelivered
{
diag
.
SetSpanStatus
(
span
,
trace
.
StatusCodeUnavailable
,
fmt
.
Sprintf
(
"could not locate host for: %s/%s"
,
actionID
,
contextID
))
RespondWithError
(
c
.
RequestCtx
,
500
,
fmt
.
Sprintf
(
"could not locate host for: %s/%s"
,
actionID
,
contextID
))
}
return
}
}
else
{
...
...
@@ -798,16 +794,14 @@ func (i *Action) OnInvokeAction(c *routing.Context) {
var
resp
[]
byte
var
err
error
if
address
==
fmt
.
Sprintf
(
"%s:%v"
,
i
.
IPAddress
,
gRPCPort
)
{
if
i
.
isTargetLocal
(
targetAddress
)
{
resp
,
err
=
i
.
invoke
(
actionMethod
,
actionID
,
contextID
,
""
,
httpMethod
,
string
(
c
.
URI
()
.
QueryString
()),
payload
,
spanCtx
)
}
else
{
conn
,
err
:=
i
.
GetGRPCConnection
(
address
)
if
err
!=
nil
{
log
.
Fatalf
(
"gRPC connection failure: %s"
,
err
)
if
!
responseDelivered
{
diag
.
SetSpanStatus
(
span
,
trace
.
StatusCodeInternal
,
fmt
.
Sprintf
(
"Delivery to action id %s failed - %s"
,
actionID
,
err
.
Error
()))
RespondWithError
(
c
.
RequestCtx
,
500
,
fmt
.
Sprintf
(
"delivery to action id %s failed"
,
actionID
))
}
return
...
...
@@ -828,21 +822,17 @@ func (i *Action) OnInvokeAction(c *routing.Context) {
if
err
!=
nil
{
log
.
Error
(
err
)
diag
.
SetSpanStatus
(
span
,
trace
.
StatusCodeInternal
,
fmt
.
Sprintf
(
"Delivery to action id %s failed - %s"
,
actionID
,
err
.
Error
()))
RespondWithError
(
c
.
RequestCtx
,
500
,
fmt
.
Sprintf
(
"delivery to action id %s failed"
,
actionID
))
}
else
{
if
resp
!=
nil
&&
len
(
resp
)
>
0
{
diag
.
SetSpanStatus
(
span
,
trace
.
StatusCodeOK
,
fmt
.
Sprintf
(
"action was called and returned %s"
,
string
(
resp
)))
RespondWithJSON
(
c
.
RequestCtx
,
200
,
resp
)
}
else
{
diag
.
SetSpanStatus
(
span
,
trace
.
StatusCodeOK
,
fmt
.
Sprintf
(
"action was called but returned no value"
))
return
}
RespondEmpty
(
c
.
RequestCtx
,
200
)
}
if
resp
!=
nil
&&
len
(
resp
)
>
0
{
diag
.
SetSpanStatus
(
span
,
trace
.
StatusCodeOK
,
fmt
.
Sprintf
(
"action was called and returned %s"
,
string
(
resp
)))
RespondWithJSON
(
c
.
RequestCtx
,
200
,
resp
)
}
else
{
diag
.
SetSpanStatus
(
span
,
trace
.
StatusCodeOK
,
fmt
.
Sprintf
(
"action was called but returned no value"
))
RespondEmpty
(
c
.
RequestCtx
,
200
)
}
}
...
...
@@ -1551,6 +1541,11 @@ func (i *Action) SetIPAddress() {
}
}
func
(
i
*
Action
)
isTargetLocal
(
address
string
)
bool
{
return
strings
.
Contains
(
address
,
"localhost"
)
||
strings
.
Contains
(
address
,
"127.0.0.1"
)
||
address
==
fmt
.
Sprintf
(
"%s:%v"
,
i
.
IPAddress
,
gRPCPort
)
}
func
(
i
*
Action
)
GetApplicationConfig
()
{
if
i
.
Protocol
==
GRPCProtocol
{
client
:=
pb
.
NewAppClient
(
i
.
GRPCClient
)
...
...
pkg/action/action_test.go
浏览文件 @
1b78106c
...
...
@@ -16,7 +16,7 @@ func TestInvokeActionGETWithOneParameter(t *testing.T) {
is
:=
assert
.
New
(
t
)
req
:=
fasthttp
.
AcquireRequest
()
req
.
SetRequestURI
(
"http://localhost:3505/action/test-action/echo?param=1"
)
req
.
Header
.
Set
(
"actions.action-address"
,
"
10.0.75.1
:60006"
)
req
.
Header
.
Set
(
"actions.action-address"
,
"
localhost
:60006"
)
req
.
Header
.
SetMethod
(
"GET"
)
resp
:=
fasthttp
.
AcquireResponse
()
client
:=
&
fasthttp
.
Client
{}
...
...
@@ -28,7 +28,7 @@ func TestInvokeActionGETWithTwoParameters(t *testing.T) {
is
:=
assert
.
New
(
t
)
req
:=
fasthttp
.
AcquireRequest
()
req
.
SetRequestURI
(
"http://localhost:3505/action/test-action/echo?param1=1¶m2=2"
)
req
.
Header
.
Set
(
"actions.action-address"
,
"
10.0.75.1
:60006"
)
req
.
Header
.
Set
(
"actions.action-address"
,
"
localhost
:60006"
)
req
.
Header
.
SetMethod
(
"GET"
)
resp
:=
fasthttp
.
AcquireResponse
()
client
:=
&
fasthttp
.
Client
{}
...
...
@@ -55,7 +55,7 @@ func TestInvokeActionGETWithNoParameters(t *testing.T) {
is
:=
assert
.
New
(
t
)
req
:=
fasthttp
.
AcquireRequest
()
req
.
SetRequestURI
(
"http://localhost:3505/action/test-action/echo"
)
req
.
Header
.
Set
(
"actions.action-address"
,
"
10.0.75.1
:60006"
)
req
.
Header
.
Set
(
"actions.action-address"
,
"
localhost
:60006"
)
req
.
Header
.
SetMethod
(
"GET"
)
resp
:=
fasthttp
.
AcquireResponse
()
client
:=
&
fasthttp
.
Client
{}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录