Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
iSulad
提交
a73d8a01
I
iSulad
项目概览
openeuler
/
iSulad
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
iSulad
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a73d8a01
编写于
4月 22, 2020
作者:
O
openeuler-ci-bot
提交者:
Gitee
4月 22, 2020
浏览文件
操作
浏览文件
下载
差异文件
!213 exec: separate stdout and stderr in exec
Merge pull request !213 from lifeng_isula/fix_exec_stderr
上级
25c84e06
4598eaf9
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
119 addition
and
35 deletion
+119
-35
src/api/services/containers/container.proto
src/api/services/containers/container.proto
+2
-1
src/connect/client/grpc/grpc_containers_client.cc
src/connect/client/grpc/grpc_containers_client.cc
+6
-1
src/connect/service/grpc/grpc_containers_service.cc
src/connect/service/grpc/grpc_containers_service.cc
+26
-7
src/connect/service/rest/rest_containers_service.c
src/connect/service/rest/rest_containers_service.c
+1
-1
src/services/callback.h
src/services/callback.h
+1
-1
src/services/cri/cri_container.cc
src/services/cri/cri_container.cc
+8
-4
src/services/execution/execute/execution_stream.c
src/services/execution/execute/execution_stream.c
+6
-5
src/services/execution/manager/health_check.c
src/services/execution/manager/health_check.c
+10
-6
src/websocket/service/attach_serve.cc
src/websocket/service/attach_serve.cc
+1
-1
src/websocket/service/exec_serve.cc
src/websocket/service/exec_serve.cc
+9
-6
src/websocket/service/ws_server.cc
src/websocket/service/ws_server.cc
+47
-1
src/websocket/service/ws_server.h
src/websocket/service/ws_server.h
+2
-1
未找到文件。
src/api/services/containers/container.proto
浏览文件 @
a73d8a01
...
...
@@ -324,7 +324,8 @@ message RemoteExecRequest {
}
message
RemoteExecResponse
{
bytes
stdout
=
1
;
bool
finish
=
2
;
bytes
stderr
=
2
;
bool
finish
=
3
;
}
message
AttachRequest
{
...
...
src/connect/client/grpc/grpc_containers_client.cc
浏览文件 @
a73d8a01
...
...
@@ -1004,7 +1004,12 @@ out:
if
(
stream_response
.
finish
())
{
break
;
}
std
::
cout
<<
stream_response
.
stdout
()
<<
std
::
flush
;
if
(
!
stream_response
.
stdout
().
empty
())
{
std
::
cout
<<
stream_response
.
stdout
()
<<
std
::
flush
;
}
if
(
!
stream_response
.
stderr
().
empty
())
{
std
::
cerr
<<
stream_response
.
stderr
()
<<
std
::
flush
;
}
}
write_task
.
stop
();
stream
->
WritesDone
();
...
...
src/connect/service/grpc/grpc_containers_service.cc
浏览文件 @
a73d8a01
...
...
@@ -616,7 +616,7 @@ Status ContainerServiceImpl::Exec(ServerContext *context, const ExecRequest *req
return
Status
::
CANCELLED
;
}
ret
=
cb
->
container
.
exec
(
container_req
,
&
container_res
,
-
1
,
nullptr
);
ret
=
cb
->
container
.
exec
(
container_req
,
&
container_res
,
-
1
,
nullptr
,
nullptr
);
tret
=
exec_response_to_grpc
(
container_res
,
reply
);
free_container_exec_request
(
container_req
);
...
...
@@ -629,7 +629,7 @@ Status ContainerServiceImpl::Exec(ServerContext *context, const ExecRequest *req
return
Status
::
OK
;
}
ssize_t
WriteExecResponseToRemoteClient
(
void
*
context
,
const
void
*
data
,
size_t
len
)
ssize_t
WriteExec
Stdout
ResponseToRemoteClient
(
void
*
context
,
const
void
*
data
,
size_t
len
)
{
if
(
context
==
nullptr
||
data
==
nullptr
||
len
==
0
)
{
return
0
;
...
...
@@ -644,6 +644,21 @@ ssize_t WriteExecResponseToRemoteClient(void *context, const void *data, size_t
return
(
ssize_t
)
len
;
}
ssize_t
WriteExecStderrResponseToRemoteClient
(
void
*
context
,
const
void
*
data
,
size_t
len
)
{
if
(
context
==
nullptr
||
data
==
nullptr
||
len
==
0
)
{
return
0
;
}
auto
stream
=
static_cast
<
ServerReaderWriter
<
RemoteExecResponse
,
RemoteExecRequest
>
*>
(
context
);
RemoteExecResponse
response
;
response
.
set_stderr
((
char
*
)
data
,
len
);
if
(
!
stream
->
Write
(
response
))
{
ERROR
(
"Failed to write request to grpc client"
);
return
-
1
;
}
return
(
ssize_t
)
len
;
}
class
RemoteExecReceiveFromClientTask
:
public
StoppableThread
{
public:
RemoteExecReceiveFromClientTask
()
=
default
;
...
...
@@ -720,11 +735,15 @@ Status ContainerServiceImpl::RemoteExec(ServerContext *context,
});
}
struct
io_write_wrapper
stringWriter
=
{
0
};
stringWriter
.
context
=
(
void
*
)
stream
;
stringWriter
.
write_func
=
WriteExecResponseToRemoteClient
;
stringWriter
.
close_func
=
nullptr
;
(
void
)
cb
->
container
.
exec
(
container_req
,
&
container_res
,
read_pipe_fd
[
0
],
&
stringWriter
);
struct
io_write_wrapper
StdoutstringWriter
=
{
0
};
StdoutstringWriter
.
context
=
(
void
*
)
stream
;
StdoutstringWriter
.
write_func
=
WriteExecStdoutResponseToRemoteClient
;
StdoutstringWriter
.
close_func
=
nullptr
;
struct
io_write_wrapper
StderrstringWriter
=
{
0
};
StderrstringWriter
.
context
=
(
void
*
)
stream
;
StderrstringWriter
.
write_func
=
WriteExecStderrResponseToRemoteClient
;
StderrstringWriter
.
close_func
=
nullptr
;
(
void
)
cb
->
container
.
exec
(
container_req
,
&
container_res
,
read_pipe_fd
[
0
],
&
StdoutstringWriter
,
&
StderrstringWriter
);
RemoteExecResponse
finish_response
;
finish_response
.
set_finish
(
true
);
...
...
src/connect/service/rest/rest_containers_service.c
浏览文件 @
a73d8a01
...
...
@@ -945,7 +945,7 @@ static void rest_exec_cb(evhtp_request_t *req, void *arg)
goto
out
;
}
(
void
)
cb
->
container
.
exec
(
crequest
,
&
cresponse
,
-
1
,
NULL
);
(
void
)
cb
->
container
.
exec
(
crequest
,
&
cresponse
,
-
1
,
NULL
,
NULL
);
evhtp_send_exec_repsponse
(
req
,
cresponse
,
RESTFUL_RES_OK
);
out:
...
...
src/services/callback.h
浏览文件 @
a73d8a01
...
...
@@ -113,7 +113,7 @@ typedef struct {
int
(
*
list
)(
const
container_list_request
*
request
,
container_list_response
**
response
);
int
(
*
exec
)(
const
container_exec_request
*
request
,
container_exec_response
**
response
,
int
stdinfd
,
struct
io_write_wrapper
*
stdout
);
int
stdinfd
,
struct
io_write_wrapper
*
stdout
,
struct
io_write_wrapper
*
stderr
);
int
(
*
attach
)(
const
container_attach_request
*
request
,
container_attach_response
**
response
,
int
stdinfd
,
struct
io_write_wrapper
*
stdout
,
struct
io_write_wrapper
*
stderr
);
...
...
src/services/cri/cri_container.cc
浏览文件 @
a73d8a01
...
...
@@ -1339,7 +1339,8 @@ void CRIRuntimeServiceImpl::ExecSync(const std::string &containerID,
const
google
::
protobuf
::
RepeatedPtrField
<
std
::
string
>
&
cmd
,
int64_t
timeout
,
runtime
::
v1alpha2
::
ExecSyncResponse
*
reply
,
Errors
&
error
)
{
struct
io_write_wrapper
stringWriter
=
{
0
};
struct
io_write_wrapper
StdoutstringWriter
=
{
0
};
struct
io_write_wrapper
StderrstringWriter
=
{
0
};
if
(
m_cb
==
nullptr
||
m_cb
->
container
.
exec
==
nullptr
)
{
error
.
SetError
(
"Unimplemented callback"
);
...
...
@@ -1365,9 +1366,12 @@ void CRIRuntimeServiceImpl::ExecSync(const std::string &containerID,
goto
cleanup
;
}
stringWriter
.
context
=
(
void
*
)
reply
->
mutable_stdout
();
stringWriter
.
write_func
=
WriteToString
;
if
(
m_cb
->
container
.
exec
(
request
,
&
response
,
-
1
,
&
stringWriter
))
{
StdoutstringWriter
.
context
=
(
void
*
)
reply
->
mutable_stdout
();
StdoutstringWriter
.
write_func
=
WriteToString
;
StderrstringWriter
.
context
=
(
void
*
)
reply
->
mutable_stderr
();
StderrstringWriter
.
write_func
=
WriteToString
;
if
(
m_cb
->
container
.
exec
(
request
,
&
response
,
-
1
,
&
StdoutstringWriter
,
&
StderrstringWriter
))
{
if
(
response
!=
nullptr
&&
response
->
errmsg
!=
nullptr
)
{
error
.
SetError
(
response
->
errmsg
);
}
else
{
...
...
src/services/execution/execute/execution_stream.c
浏览文件 @
a73d8a01
...
...
@@ -608,8 +608,8 @@ static int container_exec_cb_check(const container_exec_request *request, contai
}
static
int
exec_prepare_console
(
container_t
*
cont
,
const
container_exec_request
*
request
,
int
stdinfd
,
struct
io_write_wrapper
*
stdout_handler
,
char
**
fifos
,
char
**
fifopath
,
int
*
sync_fd
,
pthread_t
*
thread_id
)
struct
io_write_wrapper
*
stdout_handler
,
struct
io_write_wrapper
*
stderr_handler
,
char
**
fifo
s
,
char
**
fifo
path
,
int
*
sync_fd
,
pthread_t
*
thread_id
)
{
int
ret
=
0
;
const
char
*
id
=
cont
->
common_config
->
id
;
...
...
@@ -629,7 +629,7 @@ static int exec_prepare_console(container_t *cont, const container_exec_request
goto
out
;
}
if
(
ready_copy_io_data
(
*
sync_fd
,
false
,
request
->
stdin
,
request
->
stdout
,
request
->
stderr
,
stdinfd
,
stdout_handler
,
NULL
,
(
const
char
**
)
fifos
,
thread_id
))
{
stdinfd
,
stdout_handler
,
stderr_handler
,
(
const
char
**
)
fifos
,
thread_id
))
{
ret
=
-
1
;
goto
out
;
}
...
...
@@ -730,7 +730,7 @@ out:
}
static
int
container_exec_cb
(
const
container_exec_request
*
request
,
container_exec_response
**
response
,
int
stdinfd
,
struct
io_write_wrapper
*
stdout_handler
)
int
stdinfd
,
struct
io_write_wrapper
*
stdout_handler
,
struct
io_write_wrapper
*
stderr_handler
)
{
int
exit_code
=
0
;
int
sync_fd
=
-
1
;
...
...
@@ -802,7 +802,8 @@ static int container_exec_cb(const container_exec_request *request, container_ex
}
}
if
(
exec_prepare_console
(
cont
,
request
,
stdinfd
,
stdout_handler
,
fifos
,
&
fifopath
,
&
sync_fd
,
&
thread_id
))
{
if
(
exec_prepare_console
(
cont
,
request
,
stdinfd
,
stdout_handler
,
stderr_handler
,
fifos
,
&
fifopath
,
&
sync_fd
,
&
thread_id
))
{
cc
=
ISULAD_ERR_EXEC
;
goto
pack_response
;
}
...
...
src/services/execution/manager/health_check.c
浏览文件 @
a73d8a01
...
...
@@ -516,7 +516,8 @@ void *health_check_run(void *arg)
char
**
cmd_slice
=
NULL
;
char
output
[
REV_BUF_SIZE
]
=
{
0
};
char
timebuffer
[
TIME_STR_SIZE
]
=
{
0
};
struct
io_write_wrapper
ctx
=
{
0
};
struct
io_write_wrapper
Stdoutctx
=
{
0
};
struct
io_write_wrapper
Stderrctx
=
{
0
};
container_t
*
cont
=
NULL
;
service_callback_t
*
cb
=
NULL
;
container_exec_request
*
container_req
=
NULL
;
...
...
@@ -559,7 +560,7 @@ void *health_check_run(void *arg)
container_req
->
tty
=
false
;
container_req
->
attach_stdin
=
false
;
container_req
->
attach_stdout
=
true
;
container_req
->
attach_stderr
=
fals
e
;
container_req
->
attach_stderr
=
tru
e
;
container_req
->
timeout
=
timeout_with_default
(
config
->
health_check
->
timeout
,
DEFAULT_PROBE_TIMEOUT
)
/
Time_Second
;
container_req
->
container_id
=
util_strdup_s
(
cont
->
common_config
->
id
);
container_req
->
argv
=
cmd_slice
;
...
...
@@ -575,10 +576,13 @@ void *health_check_run(void *arg)
}
result
->
start
=
util_strdup_s
(
timebuffer
);
ctx
.
context
=
(
void
*
)
output
;
ctx
.
write_func
=
write_to_string
;
ctx
.
close_func
=
NULL
;
ret
=
cb
->
container
.
exec
(
container_req
,
&
container_res
,
-
1
,
&
ctx
);
Stdoutctx
.
context
=
(
void
*
)
output
;
Stdoutctx
.
write_func
=
write_to_string
;
Stdoutctx
.
close_func
=
NULL
;
Stderrctx
.
context
=
(
void
*
)
output
;
Stderrctx
.
write_func
=
write_to_string
;
Stderrctx
.
close_func
=
NULL
;
ret
=
cb
->
container
.
exec
(
container_req
,
&
container_res
,
-
1
,
&
Stdoutctx
,
&
Stderrctx
);
if
(
ret
!=
0
)
{
health_check_exec_failed_handle
(
container_res
,
result
);
}
else
{
...
...
src/websocket/service/attach_serve.cc
浏览文件 @
a73d8a01
...
...
@@ -48,7 +48,7 @@ int AttachServe::Execute(struct lws *wsi, const std::string &token,
}
struct
io_write_wrapper
stringWriter
=
{
0
};
stringWriter
.
context
=
(
void
*
)
wsi
;
stringWriter
.
write_func
=
WsWriteToClient
;
stringWriter
.
write_func
=
WsWrite
Stdout
ToClient
;
stringWriter
.
close_func
=
closeWsConnect
;
container_req
->
attach_stderr
=
false
;
int
ret
=
cb
->
container
.
attach
(
container_req
,
&
container_res
,
...
...
src/websocket/service/exec_serve.cc
浏览文件 @
a73d8a01
...
...
@@ -45,11 +45,14 @@ int ExecServe::Execute(struct lws *wsi, const std::string &token,
ERROR
(
"Failed to transform grpc request!"
);
return
-
1
;
}
struct
io_write_wrapper
stringWriter
=
{
0
};
stringWriter
.
context
=
(
void
*
)
wsi
;
stringWriter
.
write_func
=
WsWriteToClient
;
struct
io_write_wrapper
StdoutstringWriter
=
{
0
};
StdoutstringWriter
.
context
=
(
void
*
)
wsi
;
StdoutstringWriter
.
write_func
=
WsWriteStdoutToClient
;
struct
io_write_wrapper
StderrstringWriter
=
{
0
};
StderrstringWriter
.
context
=
(
void
*
)
wsi
;
StderrstringWriter
.
write_func
=
WsWriteStderrToClient
;
int
ret
=
cb
->
container
.
exec
(
container_req
,
&
container_res
,
container_req
->
attach_stdin
?
read_pipe_fd
:
-
1
,
&
stringWriter
);
container_req
->
attach_stdin
?
read_pipe_fd
:
-
1
,
&
StdoutstringWriter
,
&
Stderr
stringWriter
);
if
(
ret
!=
0
)
{
std
::
string
message
;
if
(
container_res
!=
nullptr
&&
container_res
->
errmsg
!=
nullptr
)
{
...
...
@@ -57,11 +60,11 @@ int ExecServe::Execute(struct lws *wsi, const std::string &token,
}
else
{
message
=
"Failed to call exec container callback. "
;
}
WsWriteToClient
(
wsi
,
message
.
c_str
(),
message
.
length
());
WsWrite
Stdout
ToClient
(
wsi
,
message
.
c_str
(),
message
.
length
());
}
if
(
container_res
!=
nullptr
&&
container_res
->
exit_code
!=
0
)
{
std
::
string
exit_info
=
"Exit code :"
+
std
::
to_string
((
int
)
container_res
->
exit_code
)
+
"
\n
"
;
WsWriteToClient
(
wsi
,
exit_info
.
c_str
(),
exit_info
.
length
());
WsWrite
Stdout
ToClient
(
wsi
,
exit_info
.
c_str
(),
exit_info
.
length
());
}
free_container_exec_request
(
container_req
);
free_container_exec_response
(
container_res
);
...
...
src/websocket/service/ws_server.cc
浏览文件 @
a73d8a01
...
...
@@ -410,7 +410,7 @@ void WebsocketServer::Wait()
}
ssize_t
WsWriteToClient
(
void
*
context
,
const
void
*
data
,
size_t
len
)
ssize_t
WsWrite
Stdout
ToClient
(
void
*
context
,
const
void
*
data
,
size_t
len
)
{
const
int
RETRIES
=
10
;
const
int
CHECK_PERIOD_SECOND
=
1
;
...
...
@@ -456,6 +456,52 @@ ssize_t WsWriteToClient(void *context, const void *data, size_t len)
return
(
ssize_t
)
len
;
}
ssize_t
WsWriteStderrToClient
(
void
*
context
,
const
void
*
data
,
size_t
len
)
{
const
int
RETRIES
=
10
;
const
int
CHECK_PERIOD_SECOND
=
1
;
const
int
TRIGGER_PERIOD_MS
=
100
;
struct
lws
*
wsi
=
static_cast
<
struct
lws
*>
(
context
);
WebsocketServer
*
server
=
WebsocketServer
::
GetInstance
();
server
->
LockAllWsSession
();
auto
it
=
server
->
GetWsisData
().
find
(
wsi
);
if
(
it
==
server
->
GetWsisData
().
end
())
{
ERROR
(
"invalid session!"
);
server
->
UnlockAllWsSession
();
return
0
;
}
it
->
second
.
SetProcessingStatus
(
true
);
server
->
UnlockAllWsSession
();
server
->
SetLwsSendedFlag
(
wsi
,
false
);
it
->
second
.
buf_mutex
->
lock
();
auto
&
buf
=
it
->
second
.
buf
;
// Determine if it is standard output channel or error channel?
(
void
)
memset
(
buf
,
0
,
LWS_PRE
+
MAX_MSG_BUFFER_SIZE
+
1
);
buf
[
LWS_PRE
]
=
STDERRCHANNEL
;
(
void
)
memcpy
(
&
buf
[
LWS_PRE
+
1
],
(
void
*
)
data
,
len
);
auto
start
=
std
::
chrono
::
system_clock
::
now
();
lws_callback_on_writable
(
wsi
);
it
->
second
.
buf_mutex
->
unlock
();
int
count
=
0
;
while
(
!
it
->
second
.
sended
&&
count
<
RETRIES
)
{
auto
end
=
std
::
chrono
::
system_clock
::
now
();
auto
duration
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
end
-
start
);
double
spend_time
=
static_cast
<
double
>
(
duration
.
count
())
*
std
::
chrono
::
microseconds
::
period
::
num
/
std
::
chrono
::
microseconds
::
period
::
den
;
if
(
spend_time
>
CHECK_PERIOD_SECOND
)
{
lws_callback_on_writable
(
wsi
);
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
TRIGGER_PERIOD_MS
));
start
=
std
::
chrono
::
system_clock
::
now
();
count
++
;
}
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
TRIGGER_PERIOD_MS
));
}
it
->
second
.
SetProcessingStatus
(
false
);
return
(
ssize_t
)
len
;
}
int
closeWsConnect
(
void
*
context
,
char
**
err
)
{
(
void
)
err
;
...
...
src/websocket/service/ws_server.h
浏览文件 @
a73d8a01
...
...
@@ -119,7 +119,8 @@ private:
int
m_listenPort
;
};
ssize_t
WsWriteToClient
(
void
*
context
,
const
void
*
data
,
size_t
len
);
ssize_t
WsWriteStdoutToClient
(
void
*
context
,
const
void
*
data
,
size_t
len
);
ssize_t
WsWriteStderrToClient
(
void
*
context
,
const
void
*
data
,
size_t
len
);
int
closeWsConnect
(
void
*
context
,
char
**
err
);
#endif
/* __WEBSOCKET_SERVER_H_ */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录