Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 699dd7d

Browse files
committed
serverrpc: update log and error to make it clear
Signed-off-by: Hui Zhu <[email protected]>
1 parent f933b46 commit 699dd7d

File tree

6 files changed

+49
-45
lines changed

6 files changed

+49
-45
lines changed

Diff for: serverrpc/attach.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package serverrpc
22

33
import (
4+
"fmt"
45
"github.com/golang/glog"
56
"github.com/hyperhq/hyperd/types"
67
"io"
@@ -12,8 +13,9 @@ func (s *ServerRPC) Attach(stream types.PublicAPI_AttachServer) error {
1213
return nil
1314
}
1415
if err != nil {
15-
return err
16+
return fmt.Errorf("stream.Recv error: %v", err)
1617
}
18+
glog.V(3).Infof("Attach with ServerStream %s request %s", stream, req.String())
1719

1820
ir, iw := io.Pipe()
1921
or, ow := io.Pipe()
@@ -63,5 +65,10 @@ func (s *ServerRPC) Attach(stream types.PublicAPI_AttachServer) error {
6365
}
6466
}()
6567

66-
return s.daemon.Attach(ir, ow, req.ContainerID)
68+
err = s.daemon.Attach(ir, ow, req.ContainerID)
69+
if err != nil {
70+
return fmt.Errorf("s.daemon.Attach with request %s error: %v", req.String(), err)
71+
}
72+
73+
return nil
6774
}

Diff for: serverrpc/exec.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ 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"
@@ -13,12 +14,12 @@ import (
1314
func (s *ServerRPC) ExecCreate(ctx context.Context, req *types.ExecCreateRequest) (*types.ExecCreateResponse, error) {
1415
cmd, err := json.Marshal(req.Command)
1516
if err != nil {
16-
return nil, err
17+
return nil, fmt.Errorf("json.Marshal error: %v", err)
1718
}
1819

1920
execId, err := s.daemon.CreateExec(req.ContainerID, string(cmd), req.Tty)
2021
if err != nil {
21-
return nil, err
22+
return nil, fmt.Errorf("s.daemon.CreateExec error: %v", err)
2223
}
2324

2425
return &types.ExecCreateResponse{
@@ -29,8 +30,9 @@ func (s *ServerRPC) ExecCreate(ctx context.Context, req *types.ExecCreateRequest
2930
func (s *ServerRPC) ExecStart(stream types.PublicAPI_ExecStartServer) error {
3031
req, err := stream.Recv()
3132
if err != nil {
32-
return err
33+
return fmt.Errorf("stream.Recv error: %v", err)
3334
}
35+
glog.V(3).Infof("ExecStart with ServerStream %s request %s", stream, req.String())
3436

3537
inReader, inWriter := io.Pipe()
3638
outReader, outWriter := io.Pipe()
@@ -41,16 +43,14 @@ func (s *ServerRPC) ExecStart(stream types.PublicAPI_ExecStartServer) error {
4143
nr, err := outReader.Read(buf)
4244
if nr > 0 {
4345
if err := stream.Send(&types.ExecStartResponse{buf[:nr]}); err != nil {
44-
glog.Errorf("Send to stream error: %v", err)
45-
return err
46+
return fmt.Errorf("stream.Send with request %s error: %v", req.String(), err)
4647
}
4748
}
4849
if err == io.EOF {
4950
return nil
5051
}
5152
if err != nil {
52-
glog.Errorf("Read from pipe error: %v", err)
53-
return err
53+
return fmt.Errorf("outReader.Read with request %s error: %v", req.String(), err)
5454
}
5555
}
5656
})
@@ -81,7 +81,7 @@ func (s *ServerRPC) ExecStart(stream types.PublicAPI_ExecStartServer) error {
8181

8282
err = s.daemon.StartExec(inReader, outWriter, req.ContainerID, req.ExecID)
8383
if err != nil {
84-
return err
84+
return fmt.Errorf("s.daemon.StartExec with request %s error: %v", req.String(), err)
8585
}
8686
err = <-outErr
8787
return err
@@ -113,12 +113,13 @@ func (s *ServerRPC) ExecSignal(ctx context.Context, req *types.ExecSignalRequest
113113
func (s *ServerRPC) ExecVM(stream types.PublicAPI_ExecVMServer) error {
114114
req, err := stream.Recv()
115115
if err != nil {
116-
return err
116+
return fmt.Errorf("stream.Recv error: %v", err)
117117
}
118+
glog.V(3).Infof("ExecVM with ServerStream %s request %s", stream, req.String())
118119

119120
cmd, err := json.Marshal(req.Command)
120121
if err != nil {
121-
return err
122+
return fmt.Errorf("json.Marshal with request %s error: %v", req.String(), err)
122123
}
123124

124125
inReader, inWriter := io.Pipe()
@@ -173,13 +174,12 @@ func (s *ServerRPC) ExecVM(stream types.PublicAPI_ExecVMServer) error {
173174

174175
code, err := s.daemon.ExecVM(req.PodID, string(cmd), inReader, outWriter, outWriter)
175176
if err != nil {
176-
return err
177+
return fmt.Errorf("s.daemon.ExecVM with request %s error: %v", req.String(), err)
177178
}
178179
if err := stream.Send(&types.ExecVMResponse{
179180
ExitCode: int32(code),
180181
}); err != nil {
181-
glog.Errorf("Send to stream error: %v", err)
182-
return err
182+
return fmt.Errorf("stream.Send with request %s error: %v", req.String(), err)
183183
}
184184

185185
return nil

Diff for: serverrpc/images.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io"
66
"io/ioutil"
77

8+
"fmt"
89
enginetypes "github.com/docker/engine-api/types"
910
"github.com/golang/glog"
1011
"github.com/hyperhq/hyperd/types"
@@ -49,6 +50,7 @@ func (s *ServerRPC) ImagePull(req *types.ImagePullRequest, stream types.PublicAP
4950
RegistryToken: req.Auth.Registrytoken,
5051
}
5152
}
53+
glog.V(3).Infof("ImagePull with ServerStream %s request %s", stream, req.String())
5254

5355
r, w := io.Pipe()
5456

@@ -74,7 +76,7 @@ func (s *ServerRPC) ImagePull(req *types.ImagePullRequest, stream types.PublicAP
7476
}
7577

7678
if err := stream.Send(&types.ImagePullResponse{Data: data[:n]}); err != nil {
77-
glog.Errorf("Send image pull progress to stream error: %v", err)
79+
glog.Errorf("Send image pull progress to stream error: %v", err)
7880
return
7981
}
8082
}
@@ -83,6 +85,9 @@ func (s *ServerRPC) ImagePull(req *types.ImagePullRequest, stream types.PublicAP
8385
pullResult = s.daemon.CmdImagePull(req.Image, req.Tag, authConfig, nil, w)
8486
complete = true
8587

88+
if pullResult != nil {
89+
pullResult = fmt.Errorf("s.daemon.CmdImagePull with request %s error: %v", req.String(), pullResult)
90+
}
8691
return pullResult
8792
}
8893

@@ -99,6 +104,7 @@ func (s *ServerRPC) ImagePush(req *types.ImagePushRequest, stream types.PublicAP
99104
RegistryToken: req.Auth.Registrytoken,
100105
}
101106
}
107+
glog.V(3).Infof("ImagePush with ServerStream %s request %s", stream, req.String())
102108

103109
buffer := bytes.NewBuffer([]byte{})
104110
var pushResult error
@@ -119,15 +125,17 @@ func (s *ServerRPC) ImagePush(req *types.ImagePushRequest, stream types.PublicAP
119125
}
120126

121127
if err != nil {
122-
glog.Errorf("ImagePush read image push stream failed %v with request %s", err, req.String())
123-
return err
128+
return fmt.Errorf("ImagePush read image push stream with request %s error: %v", req.String(), err)
124129
}
125130

126131
if err := stream.Send(&types.ImagePushResponse{Data: data}); err != nil {
127-
return err
132+
return fmt.Errorf("stream.Send with request %s error: %v", req.String(), err)
128133
}
129134
}
130135

136+
if pushResult != nil {
137+
pushResult = fmt.Errorf("s.daemon.CmdImagePush with request %s error: %v", req.String(), pushResult)
138+
}
131139
return pushResult
132140
}
133141

Diff for: serverrpc/logs.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ import (
55
"io"
66
"time"
77

8+
"fmt"
89
timetypes "github.com/docker/engine-api/types/time"
910
"github.com/golang/glog"
1011
"github.com/hyperhq/hyperd/daemon"
1112
"github.com/hyperhq/hyperd/types"
1213
)
1314

1415
func (s *ServerRPC) ContainerLogs(req *types.ContainerLogsRequest, stream types.PublicAPI_ContainerLogsServer) error {
16+
glog.V(3).Infof("ContainerLogs with ServerStream %s request %s", stream, req.String())
17+
1518
var since time.Time
1619
if req.Since != "" {
1720
s, n, err := timetypes.ParseTimestamps(req.Since, 0)
1821
if err != nil {
19-
glog.Errorf("ContainerLogs failed %v with request %s", err, req.String())
20-
return err
22+
return fmt.Errorf("timetypes.ParseTimestamps with request %s error: %v", req.String(), err)
2123
}
2224
since = time.Unix(s, n)
2325
}
@@ -42,8 +44,7 @@ func (s *ServerRPC) ContainerLogs(req *types.ContainerLogsRequest, stream types.
4244
} else {
4345
err := s.daemon.GetContainerLogs(req.Container, logsConfig)
4446
if err != nil {
45-
glog.Errorf("ContainerLogs failed %v with request %s", err, req.String())
46-
return err
47+
return fmt.Errorf("s.daemon.GetContainerLogs with request %s error: %v", req.String(), err)
4748
}
4849
}
4950

@@ -55,13 +56,12 @@ func (s *ServerRPC) ContainerLogs(req *types.ContainerLogsRequest, stream types.
5556
eof = true
5657
}
5758
} else if err != nil {
58-
glog.Errorf("ContainerLogs failed %v with request %s", err, req.String())
59-
return err
59+
return fmt.Errorf("buffer.ReadBytes with request %s error: %v", req.String(), err)
6060
}
6161

6262
if err := stream.Send(&types.ContainerLogsResponse{Log: s}); err != nil {
6363
stop <- true
64-
return err
64+
return fmt.Errorf("stream.Send with request %s error: %v", req.String(), err)
6565
}
6666

6767
if eof == true {

Diff for: serverrpc/pod.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package serverrpc
33
import (
44
"fmt"
55

6-
"github.com/golang/glog"
76
"github.com/hyperhq/hyperd/types"
87
runvtypes "github.com/hyperhq/runv/hypervisor/types"
98
"golang.org/x/net/context"
@@ -34,13 +33,12 @@ func (s *ServerRPC) PodStart(ctx context.Context, req *types.PodStartRequest) (*
3433
// PodRemove removes a pod by podID
3534
func (s *ServerRPC) PodRemove(ctx context.Context, req *types.PodRemoveRequest) (*types.PodRemoveResponse, error) {
3635
if req.PodID == "" {
37-
return nil, fmt.Errorf("PodRemove failed PodID is required for PodRemove with request %s", req.String())
36+
return nil, fmt.Errorf("PodRemove failed PodID is required for PodRemove")
3837
}
3938

4039
code, cause, err := s.daemon.RemovePod(req.PodID)
4140
if err != nil {
42-
glog.Errorf("PodRemove failed %v with request %s", err, req.String())
43-
return nil, err
41+
return nil, fmt.Errorf("s.daemon.RemovePod error: %v", err)
4442
}
4543

4644
return &types.PodRemoveResponse{

Diff for: serverrpc/portmapping.go

+6-15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package serverrpc
22

33
import (
4-
"errors"
5-
6-
"github.com/hyperhq/hypercontainer-utils/hlog"
4+
"fmt"
75
"github.com/hyperhq/hyperd/types"
86
"golang.org/x/net/context"
97
)
@@ -12,8 +10,7 @@ import (
1210
func (s *ServerRPC) PortMappingList(ctx context.Context, req *types.PortMappingListRequest) (*types.PortMappingListResponse, error) {
1311
p, ok := s.daemon.PodList.Get(req.PodID)
1412
if !ok {
15-
err := errors.New("Pod not found")
16-
return nil, err
13+
return nil, fmt.Errorf("Pod not found")
1714
}
1815

1916
return &types.PortMappingListResponse{
@@ -25,15 +22,12 @@ func (s *ServerRPC) PortMappingList(ctx context.Context, req *types.PortMappingL
2522
func (s *ServerRPC) PortMappingAdd(ctx context.Context, req *types.PortMappingModifyRequest) (*types.PortMappingModifyResponse, error) {
2623
p, ok := s.daemon.PodList.Get(req.PodID)
2724
if !ok {
28-
err := errors.New("Pod not found")
29-
s.Log(hlog.ERROR, "PortMappingAdd failed %v with request %s", err, req.String())
30-
return nil, err
25+
return nil, fmt.Errorf("Pod not found")
3126
}
3227

3328
err := p.AddPortMapping(req.PortMappings)
3429
if err != nil {
35-
s.Log(hlog.ERROR, "PortMappingAdd failed %v with request %s", err, req.String())
36-
return nil, err
30+
return nil, fmt.Errorf("p.AddPortMapping error: %v", err)
3731
}
3832

3933
return &types.PortMappingModifyResponse{}, nil
@@ -43,15 +37,12 @@ func (s *ServerRPC) PortMappingAdd(ctx context.Context, req *types.PortMappingMo
4337
func (s *ServerRPC) PortMappingDel(ctx context.Context, req *types.PortMappingModifyRequest) (*types.PortMappingModifyResponse, error) {
4438
p, ok := s.daemon.PodList.Get(req.PodID)
4539
if !ok {
46-
err := errors.New("Pod not found")
47-
s.Log(hlog.ERROR, "PortMappingDel failed %v with request %s", err, req.String())
48-
return nil, err
40+
return nil, fmt.Errorf("Pod not found")
4941
}
5042

5143
err := p.RemovePortMappingByDest(req.PortMappings)
5244
if err != nil {
53-
s.Log(hlog.ERROR, "PortMappingDel failed %v with request %s", err, req.String())
54-
return nil, err
45+
return nil, fmt.Errorf("p.RemovePortMappingByDest error: %v", err)
5546
}
5647

5748
return &types.PortMappingModifyResponse{}, nil

0 commit comments

Comments
 (0)