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

add grpc api of container signal #401

Merged
merged 1 commit into from
Jan 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions integration/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,3 +712,17 @@ func (c *HyperClient) Ping() (*types.PingResponse, error) {

return resp, nil
}

// ContainerSignal sends a signal to specified container of specified pod
func (c *HyperClient) ContainerSignal(podID, containerID string, signal int64) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are the test code to call it?

_, err := c.client.ContainerSignal(c.ctx, &types.ContainerSignalRequest{
PodID: podID,
ContainerID: containerID,
Signal: signal,
})
if err != nil {
return err
}

return nil
}
38 changes: 38 additions & 0 deletions integration/hyper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,41 @@ func (s *TestSuite) TestPing(c *C) {
c.Assert(err, IsNil)
c.Logf("Got HyperdStats %v", resp)
}

func (s *TestSuite) TestSendContainerSignal(c *C) {
sigKill := int64(9)
spec := types.UserPod{
Id: "busybox",
}

pod, err := s.client.CreatePod(&spec)
c.Assert(err, IsNil)
c.Logf("Pod created: %s", pod)

defer func() {
err = s.client.RemovePod(pod)
c.Assert(err, IsNil)
}()

container, err := s.client.CreateContainer(pod, &types.UserContainer{Image: "busybox"})
c.Assert(err, IsNil)
c.Logf("Container created: %s", container)

err = s.client.StartPod(pod)
c.Assert(err, IsNil)

containerInfo, err := s.client.GetContainerInfo(container)
c.Assert(err, IsNil)
c.Assert(containerInfo.Status.Phase, Equals, "running")

err = s.client.ContainerSignal(pod, container, sigKill)
c.Assert(err, IsNil)

exitCode, err := s.client.Wait(container, "", false)
c.Assert(err, IsNil)
c.Assert(exitCode, Equals, int32(137))

containerInfo, err = s.client.GetContainerInfo(container)
c.Assert(err, IsNil)
c.Assert(containerInfo.Status.Phase, Equals, "failed")
}
13 changes: 13 additions & 0 deletions serverrpc/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,16 @@ func (s *ServerRPC) ContainerRemove(ctx context.Context, req *types.ContainerRem
}
return &types.ContainerRemoveResponse{}, nil
}

// ContainerSignal sends a singal to specified container of specified pod
func (s *ServerRPC) ContainerSignal(ctx context.Context, req *types.ContainerSignalRequest) (*types.ContainerSignalResponse, error) {
glog.V(3).Infof("ContainerSignal with request %s", req.String())

err := s.daemon.KillPodContainers(req.PodID, req.ContainerID, req.Signal)
if err != nil {
glog.Errorf("Kill Container %s of Pod %s with signal %d failed: %v", req.ContainerID, req.PodID, req.Signal, err)
return nil, err
}

return &types.ContainerSignalResponse{}, nil
}
56 changes: 52 additions & 4 deletions types/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,14 @@ message PingResponse {
string hyperdStats = 1;
}

message ContainerSignalRequest {
string podID = 1;
string containerID = 2;
int64 signal = 3;
}

message ContainerSignalResponse{}

// PublicAPI defines the public APIs which are handled over TCP sockets.
service PublicAPI {
// PodList gets a list of pods
Expand All @@ -772,7 +780,7 @@ service PublicAPI {
rpc PodStart(PodStartRequest) returns (PodStartResponse) {}
// PodStop stops a pod
rpc PodStop(PodStopRequest) returns (PodStopResponse) {}
// PodSignal sends a singal to all containers of specified pod
// PodSignal sends a signal to all containers of specified pod
rpc PodSignal(PodSignalRequest) returns (PodSignalResponse) {}
// PodPause pauses a pod
rpc PodPause(PodPauseRequest) returns (PodPauseResponse) {}
Expand Down Expand Up @@ -805,7 +813,8 @@ service PublicAPI {
// ContainerRename renames a container
rpc ContainerRename(ContainerRenameRequest) returns (ContainerRenameResponse) {}
// TODO: ContainerCommit commits the changes of the specified container
// TODO: ContainerSignal sends a singla to specified container
// ContainerSignal sends a signal to specified container
rpc ContainerSignal(ContainerSignalRequest) returns (ContainerSignalResponse) {}
// TODO: ContainerLabels updates labels of the specified container
// ContainerStop stops the specified container
rpc ContainerStop(ContainerStopRequest) returns (ContainerStopResponse) {}
Expand Down