Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
985133f1
S
Serving
项目概览
PaddlePaddle
/
Serving
大约 1 年 前同步成功
通知
186
Star
833
Fork
253
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
105
列表
看板
标记
里程碑
合并请求
10
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Serving
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
105
Issue
105
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
985133f1
编写于
8月 09, 2019
作者:
Y
yangrui07
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cube agent code format
上级
3da70904
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
32 addition
and
32 deletion
+32
-32
cube/cube-agent/src/agent/http.go
cube/cube-agent/src/agent/http.go
+10
-10
cube/cube-agent/src/agent/http_get.go
cube/cube-agent/src/agent/http_get.go
+5
-5
cube/cube-agent/src/agent/http_post.go
cube/cube-agent/src/agent/http_post.go
+4
-4
cube/cube-agent/src/agent/util.go
cube/cube-agent/src/agent/util.go
+6
-6
cube/cube-agent/src/agent/work.go
cube/cube-agent/src/agent/work.go
+5
-5
cube/cube-agent/src/agent/work_pool.go
cube/cube-agent/src/agent/work_pool.go
+1
-1
cube/cube-agent/src/cube-agent.go
cube/cube-agent/src/cube-agent.go
+1
-1
未找到文件。
cube/cube-agent/src/agent/http.go
浏览文件 @
985133f1
...
...
@@ -39,7 +39,7 @@ func StartHttp(addr string) error {
func
handleRest
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
var
(
req_log
string
status
int32
status
int32
)
time_begin
:=
time
.
Now
()
...
...
@@ -82,7 +82,7 @@ func handleRest(w http.ResponseWriter, r *http.Request) {
fmt
.
Fprintf
(
w
,
`{"success":"%v", "message":"wrong api", "method":"%s", "api":"%s", "api_list":"%v"}`
,
status
,
r
.
Method
,
api
,
key_list
)
logex
.
Noticef
(
`%v, time=%v, status=%v`
,
logex
.
Noticef
(
`%v, time=%v, status=%v`
,
req_log
,
time
.
Now
()
.
Sub
(
time_begin
)
.
Nanoseconds
()
/
1000000
,
status
)
return
}
...
...
@@ -94,23 +94,23 @@ func handleRest(w http.ResponseWriter, r *http.Request) {
s
=
fmt
.
Sprintf
(
`{"success":"%v", "message":"query ok", "data":%s}`
,
status
,
rst
)
}
else
{
status
=
255
s
=
fmt
.
Sprintf
(
`{"success":"%v", "message":%v, "data":%s}`
,
s
=
fmt
.
Sprintf
(
`{"success":"%v", "message":%v, "data":%s}`
,
status
,
quote
(
err
.
Error
()),
rst
)
}
if
isJsonDict
(
s
)
{
fmt
.
Fprintln
(
w
,
s
)
}
else
{
}
else
{
logex
.
Fatalf
(
"invalid json: %v"
,
s
)
}
if
err
==
nil
{
logex
.
Noticef
(
`%v, time=%v, status=%v, handle_log=%v`
,
req_log
,
time
.
Now
()
.
Sub
(
time_begin
)
.
Nanoseconds
()
/
1000000
,
logex
.
Noticef
(
`%v, time=%v, status=%v, handle_log=%v`
,
req_log
,
time
.
Now
()
.
Sub
(
time_begin
)
.
Nanoseconds
()
/
1000000
,
status
,
quote
(
handle_log
))
}
else
{
logex
.
Noticef
(
`%v, time=%v, status=%v, err=%v, handle_log=%v`
,
req_log
,
time
.
Now
()
.
Sub
(
time_begin
)
.
Nanoseconds
()
/
1000000
,
logex
.
Noticef
(
`%v, time=%v, status=%v, err=%v, handle_log=%v`
,
req_log
,
time
.
Now
()
.
Sub
(
time_begin
)
.
Nanoseconds
()
/
1000000
,
status
,
quote
(
err
.
Error
()),
quote
(
handle_log
))
}
}
...
...
@@ -126,9 +126,9 @@ func parseHttpKv(r *http.Request) map[string]string {
m
[
k
]
=
v
[
0
]
}
}
// allow passing hostname for debug
if
_
,
ok
:=
m
[
"hostname"
];
!
ok
{
if
_
,
ok
:=
m
[
"hostname"
];
!
ok
{
ip
:=
r
.
RemoteAddr
[
:
strings
.
Index
(
r
.
RemoteAddr
,
":"
)]
m
[
"hostname"
],
_
=
getHostname
(
ip
)
}
...
...
cube/cube-agent/src/agent/http_get.go
浏览文件 @
985133f1
...
...
@@ -2,21 +2,21 @@
package
agent
import
(
"fmt"
"encoding/json"
"fmt"
)
func
initGetHandlers
()
{
getHandler
=
map
[
string
]
handlerFunc
{
"/agent/status"
:
GetStatus
,
"/agent/status"
:
GetStatus
,
}
}
func
GetStatus
(
subpath
string
,
m
map
[
string
]
string
,
b
[]
byte
)
(
string
,
string
,
error
)
{
b
,
err
:=
json
.
Marshal
(
BUILTIN_STATUS
)
;
b
,
err
:=
json
.
Marshal
(
BUILTIN_STATUS
)
if
err
!=
nil
{
return
quote
(
""
),
""
,
fmt
.
Errorf
(
"json marshal failed, %v"
,
err
)
}
}
return
string
(
b
),
""
,
err
}
\ No newline at end of file
}
cube/cube-agent/src/agent/http_post.go
浏览文件 @
985133f1
...
...
@@ -2,14 +2,14 @@
package
agent
import
(
"fmt"
"encoding/json"
"fmt"
"github.com/Badangel/logex"
)
func
initPostHandlers
()
{
postHandler
=
map
[
string
]
handlerFunc
{
"/agent/cmd"
:
PostCmd
,
"/agent/cmd"
:
PostCmd
,
}
}
...
...
@@ -25,7 +25,7 @@ func PostCmd(subpath string, m map[string]string, b []byte) (string, string, err
logex
.
Warningf
(
"Another work with same token is doing. Token(%s)"
,
work
.
Token
())
return
quote
(
""
),
""
,
fmt
.
Errorf
(
"Another work with same key is doing."
,
err
)
}
CmdWorkFilter
.
Store
(
work
.
Token
(),
true
)
err
=
work
.
DoWork
()
CmdWorkFilter
.
Delete
(
work
.
Token
())
...
...
@@ -34,4 +34,4 @@ func PostCmd(subpath string, m map[string]string, b []byte) (string, string, err
}
return
quote
(
""
),
""
,
err
}
\ No newline at end of file
}
cube/cube-agent/src/agent/util.go
浏览文件 @
985133f1
...
...
@@ -154,21 +154,21 @@ func GetLocalHostnameCmd() (hostname string, err error) {
// quote quotes string for json output. eg: s="123", quote(s)=`"123"`
func
quote
(
s
string
)
string
{
return
fmt
.
Sprintf
(
"%q"
,
s
)
return
fmt
.
Sprintf
(
"%q"
,
s
)
}
// quoteb quotes byte array for json output.
func
quoteb
(
b
[]
byte
)
string
{
return
quote
(
string
(
b
))
return
quote
(
string
(
b
))
}
// quotea quotes string array for json output
func
quotea
(
a
[]
string
)
string
{
b
,
_
:=
json
.
Marshal
(
a
)
return
string
(
b
)
b
,
_
:=
json
.
Marshal
(
a
)
return
string
(
b
)
}
func
isJsonDict
(
s
string
)
bool
{
var
js
map
[
string
]
interface
{}
return
json
.
Unmarshal
([]
byte
(
s
),
&
js
)
==
nil
var
js
map
[
string
]
interface
{}
return
json
.
Unmarshal
([]
byte
(
s
),
&
js
)
==
nil
}
cube/cube-agent/src/agent/work.go
浏览文件 @
985133f1
...
...
@@ -417,7 +417,7 @@ func (work *Work) CheckToReload() bool {
}
func
(
work
*
Work
)
Reload
()
(
err
error
)
{
if
(
work
.
Port
==
""
)
{
if
work
.
Port
==
""
{
err
=
errors
.
New
(
"Reload with invalid port."
)
return
}
...
...
@@ -544,8 +544,8 @@ func (work *Work) Check() (err error) {
work
.
clearPatchData
()
work
.
clearPatchLink
()
master_host
,
master_port
,
_
:=
GetMaster
(
work
.
MasterAddress
)
cmd
:=
fmt
.
Sprintf
(
"cd %s && export STRATEGY_DIR=%s && ./downloader -h %s -p %s -d %s -s %d"
,
work
.
DeployPath
,
work
.
DeployPath
,
master_host
,
master_port
,
work
.
DictName
,
work
.
ShardSeq
)
cmd
:=
fmt
.
Sprintf
(
"cd %s && export STRATEGY_DIR=%s && ./downloader -h %s -p %s -d %s -s %d"
,
work
.
DeployPath
,
work
.
DeployPath
,
master_host
,
master_port
,
work
.
DictName
,
work
.
ShardSeq
)
_
,
_
,
err
=
RetryCmd
(
cmd
,
RETRY_TIMES
)
}
...
...
@@ -632,7 +632,7 @@ func (work *Work) Pop() (err error) {
func
writeStateFile
(
dictName
string
,
shardSeq
int
,
service
,
state
string
)
{
stateFile
:=
fmt
.
Sprintf
(
".state_%s_%d"
,
dictName
,
shardSeq
)
if
service
!=
""
{
stateFile
=
stateFile
+
"_"
+
service
;
stateFile
=
stateFile
+
"_"
+
service
}
cmd
:=
fmt
.
Sprintf
(
"echo '%s' > %s/state/%s"
,
state
,
Dir
,
stateFile
)
...
...
@@ -644,7 +644,7 @@ func writeStateFile(dictName string, shardSeq int, service, state string) {
func
RemoveStateFile
(
dictName
string
,
shardSeq
int
,
service
string
)
{
stateFile
:=
fmt
.
Sprintf
(
".state_%s_%d"
,
dictName
,
shardSeq
)
if
service
!=
""
{
stateFile
=
stateFile
+
"_"
+
service
;
stateFile
=
stateFile
+
"_"
+
service
}
cmd
:=
fmt
.
Sprintf
(
"rm -f %s/state/%s"
,
Dir
,
stateFile
)
...
...
cube/cube-agent/src/agent/work_pool.go
浏览文件 @
985133f1
...
...
@@ -3,8 +3,8 @@ package agent
import
(
"errors"
"fmt"
"sync/atomic"
"sync"
"sync/atomic"
)
type
(
...
...
cube/cube-agent/src/cube-agent.go
浏览文件 @
985133f1
...
...
@@ -3,8 +3,8 @@ package main
import
(
"agent"
"fmt"
"github.com/docopt/docopt-go"
"github.com/Badangel/logex"
"github.com/docopt/docopt-go"
"os"
"path/filepath"
"runtime"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录