From f1e4ee3c95bd9eb77f2dd454bac468207bc9f85c Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Mon, 22 Aug 2016 16:43:35 -0700 Subject: [PATCH] Add server impl for StopContainer Signed-off-by: Mrunal Patel --- server/runtime.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/server/runtime.go b/server/runtime.go index 15f850ed..c1927d08 100644 --- a/server/runtime.go +++ b/server/runtime.go @@ -476,7 +476,22 @@ func (s *Server) StartContainer(ctx context.Context, req *pb.StartContainerReque } // StopContainer stops a running container with a grace period (i.e., timeout). -func (s *Server) StopContainer(context.Context, *pb.StopContainerRequest) (*pb.StopContainerResponse, error) { +func (s *Server) StopContainer(ctx context.Context, req *pb.StopContainerRequest) (*pb.StopContainerResponse, error) { + containerName := req.ContainerId + + if *containerName == "" { + return nil, fmt.Errorf("PodSandboxId should not be empty") + } + c := s.state.containers[*containerName] + if c == nil { + return nil, fmt.Errorf("specified container not found: %s", *containerName) + } + + if err := s.runtime.StopContainer(c); err != nil { + return nil, fmt.Errorf("failed to stop container %s in sandbox %s: %v", c.Name(), *containerName, err) + } + + return &pb.StopContainerResponse{}, nil return nil, nil }