@@ -4,29 +4,24 @@ import (
44 "encoding/json"
55 "io"
66
7+ "fmt"
78 "github.com/golang/glog"
89 "github.com/hyperhq/hyperd/lib/promise"
910 "github.com/hyperhq/hyperd/types"
1011 "golang.org/x/net/context"
1112)
1213
1314func (s * ServerRPC ) ExecCreate (ctx context.Context , req * types.ExecCreateRequest ) (* types.ExecCreateResponse , error ) {
14- glog .V (3 ).Infof ("ExecCreate with request %s" , req .String ())
15-
1615 cmd , err := json .Marshal (req .Command )
1716 if err != nil {
18- return nil , err
17+ return nil , fmt . Errorf ( "json.Marshal error: %v" , err )
1918 }
2019
2120 execId , err := s .daemon .CreateExec (req .ContainerID , string (cmd ), req .Tty )
2221 if err != nil {
23- glog .Errorf ("ExecCreate failed %v with request %s" , err , req .String ())
24-
25- return nil , err
22+ return nil , fmt .Errorf ("s.daemon.CreateExec error: %v" , err )
2623 }
2724
28- glog .V (3 ).Infof ("ExecCreate done with request %s" , req .String ())
29-
3025 return & types.ExecCreateResponse {
3126 ExecID : execId ,
3227 }, nil
@@ -35,8 +30,9 @@ func (s *ServerRPC) ExecCreate(ctx context.Context, req *types.ExecCreateRequest
3530func (s * ServerRPC ) ExecStart (stream types.PublicAPI_ExecStartServer ) error {
3631 req , err := stream .Recv ()
3732 if err != nil {
38- return err
33+ return fmt . Errorf ( "stream.Recv error: %v" , err )
3934 }
35+ glog .V (3 ).Infof ("ExecStart with ServerStream %s request %s" , stream , req .String ())
4036
4137 inReader , inWriter := io .Pipe ()
4238 outReader , outWriter := io .Pipe ()
@@ -47,16 +43,14 @@ func (s *ServerRPC) ExecStart(stream types.PublicAPI_ExecStartServer) error {
4743 nr , err := outReader .Read (buf )
4844 if nr > 0 {
4945 if err := stream .Send (& types.ExecStartResponse {buf [:nr ]}); err != nil {
50- glog .Errorf ("Send to stream error: %v" , err )
51- return err
46+ return fmt .Errorf ("stream.Send with request %s error: %v" , req .String (), err )
5247 }
5348 }
5449 if err == io .EOF {
5550 return nil
5651 }
5752 if err != nil {
58- glog .Errorf ("Read from pipe error: %v" , err )
59- return err
53+ return fmt .Errorf ("outReader.Read with request %s error: %v" , req .String (), err )
6054 }
6155 }
6256 })
@@ -87,52 +81,45 @@ func (s *ServerRPC) ExecStart(stream types.PublicAPI_ExecStartServer) error {
8781
8882 err = s .daemon .StartExec (inReader , outWriter , req .ContainerID , req .ExecID )
8983 if err != nil {
90- return err
84+ return fmt . Errorf ( "s.daemon.StartExec with request %s error: %v" , req . String (), err )
9185 }
9286 err = <- outErr
9387 return err
9488}
9589
9690// Wait gets exitcode by container and processId
9791func (s * ServerRPC ) Wait (c context.Context , req * types.WaitRequest ) (* types.WaitResponse , error ) {
98- glog .V (3 ).Infof ("Wait with request %s" , req .String ())
99-
10092 //FIXME need update if param NoHang is enabled
10193 code , err := s .daemon .ExitCode (req .Container , req .ProcessId )
10294 if err != nil {
103- glog .Errorf ("Wait failed %v with request %s" , err , req .String ())
10495 return nil , err
10596 }
10697
107- glog .V (3 ).Infof ("Wait done with request %s" , req .String ())
10898 return & types.WaitResponse {
10999 ExitCode : int32 (code ),
110100 }, nil
111101}
112102
113103// ExecSignal sends a singal to specified exec of specified container
114104func (s * ServerRPC ) ExecSignal (ctx context.Context , req * types.ExecSignalRequest ) (* types.ExecSignalResponse , error ) {
115- glog .V (3 ).Infof ("ExecSignal with request %s" , req .String ())
116-
117105 err := s .daemon .KillExec (req .ContainerID , req .ExecID , req .Signal )
118106 if err != nil {
119- glog .Errorf ("ExecSignal failed %v with request %s" , err , req .String ())
120107 return nil , err
121108 }
122109
123- glog .V (3 ).Infof ("ExecSignal done with request %s" , req .String ())
124110 return & types.ExecSignalResponse {}, nil
125111}
126112
127113func (s * ServerRPC ) ExecVM (stream types.PublicAPI_ExecVMServer ) error {
128114 req , err := stream .Recv ()
129115 if err != nil {
130- return err
116+ return fmt . Errorf ( "stream.Recv error: %v" , err )
131117 }
118+ glog .V (3 ).Infof ("ExecVM with ServerStream %s request %s" , stream , req .String ())
132119
133120 cmd , err := json .Marshal (req .Command )
134121 if err != nil {
135- return err
122+ return fmt . Errorf ( "json.Marshal with request %s error: %v" , req . String (), err )
136123 }
137124
138125 inReader , inWriter := io .Pipe ()
@@ -187,13 +174,12 @@ func (s *ServerRPC) ExecVM(stream types.PublicAPI_ExecVMServer) error {
187174
188175 code , err := s .daemon .ExecVM (req .PodID , string (cmd ), inReader , outWriter , outWriter )
189176 if err != nil {
190- return err
177+ return fmt . Errorf ( "s.daemon.ExecVM with request %s error: %v" , req . String (), err )
191178 }
192179 if err := stream .Send (& types.ExecVMResponse {
193180 ExitCode : int32 (code ),
194181 }); err != nil {
195- glog .Errorf ("Send to stream error: %v" , err )
196- return err
182+ return fmt .Errorf ("stream.Send with request %s error: %v" , req .String (), err )
197183 }
198184
199185 return nil
0 commit comments