...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package chaosdaemon
17
18 import (
19 "context"
20
21 "github.com/golang/protobuf/ptypes/empty"
22 "github.com/pkg/errors"
23
24 pb "github.com/chaos-mesh/chaos-mesh/pkg/chaosdaemon/pb"
25 )
26
27
28 func (s *DaemonServer) ContainerKill(ctx context.Context, req *pb.ContainerRequest) (*empty.Empty, error) {
29 log := s.getLoggerFromContext(ctx)
30
31 log.Info("Container Kill", "request", req)
32
33 action := req.Action.Action
34 if action != pb.ContainerAction_KILL {
35 err := errors.Errorf("container action is %s , not kill", action)
36 log.Error(err, "container action is not expected")
37 return nil, err
38 }
39
40 err := s.crClient.ContainerKillByContainerID(ctx, req.ContainerId)
41 if err != nil {
42 log.Error(err, "error while killing container")
43 return nil, err
44 }
45
46 return &empty.Empty{}, nil
47 }
48
49 func (s *DaemonServer) ContainerGetPid(ctx context.Context, req *pb.ContainerRequest) (*pb.ContainerResponse, error) {
50 log := s.getLoggerFromContext(ctx)
51
52 log.Info("container GetPid", "request", req)
53
54 action := req.Action.Action
55 if action != pb.ContainerAction_GETPID {
56 err := errors.Errorf("container action is %s , not getpid", action)
57 log.Error(err, "container action is not expected")
58 return nil, err
59 }
60
61 pid, err := s.crClient.GetPidFromContainerID(ctx, req.ContainerId)
62 if err != nil {
63 log.Error(err, "error while getting pid from container")
64 return nil, err
65 }
66
67 return &pb.ContainerResponse{Pid: pid}, nil
68 }
69