From 79897da570147c054d8b5557c2fd946b0e39b391 Mon Sep 17 00:00:00 2001 From: Wang Xu Date: Tue, 20 Dec 2016 19:50:05 +0800 Subject: [PATCH 1/4] separate start and attach in the client side Signed-off-by: Wang Xu --- client/run.go | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/client/run.go b/client/run.go index 86883e57..21d92656 100644 --- a/client/run.go +++ b/client/run.go @@ -33,6 +33,7 @@ func (cli *HyperClient) HyperCmdRun(args ...string) (err error) { spec apitype.UserPod code int tty = false + res chan error ) if copt.IsContainer { @@ -72,32 +73,44 @@ func (cli *HyperClient) HyperCmdRun(args ...string) (err error) { }() } - if copt.Attach { + if copt.Attach && len(spec.Containers) > 0 { + res = make(chan error, 1) tty = spec.Tty || spec.Containers[0].Tty + p, err := cli.client.GetPodInfo(podId) + if err != nil { + fmt.Fprintf(cli.err, "failed to get pod info: %v", err) + return err + } if tty { - p, err := cli.client.GetPodInfo(podId) - if err == nil { - cli.monitorTtySize(p.Spec.Containers[0].ContainerID, "") - } - + cli.monitorTtySize(p.Spec.Containers[0].ContainerID, "") oldState, err := term.SetRawTerminal(cli.inFd) if err != nil { return err } defer term.RestoreTerminal(cli.inFd, oldState) } + cname := spec.Containers[0].Name + go func() { + res <- cli.client.Attach(cname, tty, cli.in, cli.out, cli.err) + }() } - _, err = cli.client.StartPod(podId, vmId, copt.Attach, tty, cli.in, cli.out, cli.err) + _, err = cli.client.StartPod(podId, vmId, false, tty, nil, nil, nil) if err != nil { - return + return err } if !copt.Attach { t2 := time.Now() fmt.Printf("Time to run a POD is %d ms\n", (t2.UnixNano()-t1.UnixNano())/1000000) } + + if res != nil { + err = <-res + return cli.client.GetExitCode(spec.Containers[0].Name, "") + } + return nil } From 7027839beb090620a668e8950a91fcba93194af7 Mon Sep 17 00:00:00 2001 From: Wang Xu Date: Tue, 20 Dec 2016 22:45:37 +0800 Subject: [PATCH 2/4] remove attach option of pod start REST API client may issue an attach before start Signed-off-by: Wang Xu --- client/api/interface.go | 2 +- client/api/start.go | 37 +++++++-------------------------- client/run.go | 3 +-- client/start.go | 2 +- daemon/server.go | 5 ++--- server/router/pod/backend.go | 4 +--- server/router/pod/pod_routes.go | 33 +---------------------------- 7 files changed, 14 insertions(+), 72 deletions(-) diff --git a/client/api/interface.go b/client/api/interface.go index 70d996f0..8417a860 100644 --- a/client/api/interface.go +++ b/client/api/interface.go @@ -31,7 +31,7 @@ type APIInterface interface { GetPodInfo(podName string) (*types.PodInfo, error) CreatePod(spec interface{}) (string, int, error) - StartPod(podId, vmId string, attach, tty bool, stdin io.ReadCloser, stdout, stderr io.Writer) (string, error) + StartPod(podId string) error StopPod(podId, stopVm string) (int, string, error) RmPod(id string) error PausePod(podId string) error diff --git a/client/api/start.go b/client/api/start.go index b7dd75d8..1eb2b113 100644 --- a/client/api/start.go +++ b/client/api/start.go @@ -2,63 +2,40 @@ package api import ( "fmt" - "io" "net/url" "github.com/hyperhq/hyperd/engine" "github.com/hyperhq/runv/hypervisor/types" ) -func (cli *Client) StartPod(podId, vmId string, attach, tty bool, stdin io.ReadCloser, stdout, stderr io.Writer) (string, error) { +func (cli *Client) StartPod(podId string) error { v := url.Values{} v.Set("podId", podId) - if !attach { - return cli.startPodWithoutTty(&v) - } else { - v.Set("attach", "yes") - - err := cli.hijackRequest("pod/start", &v, tty, stdin, stdout, stderr) - if err != nil { - fmt.Printf("StartPod failed: %s\n", err.Error()) - return "", err - } - - containerId, err := cli.GetContainerByPod(podId) - if err != nil { - return "", err - } - - return "", cli.GetExitCode(containerId, "") - } -} - -func (cli *Client) startPodWithoutTty(v *url.Values) (string, error) { - body, _, err := readBody(cli.call("POST", "/pod/start?"+v.Encode(), nil, nil)) if err != nil { - return "", err + return err } out := engine.NewOutput() remoteInfo, err := out.AddEnv() if err != nil { - return "", err + return err } if _, err := out.Write(body); err != nil { - return "", fmt.Errorf("Error reading remote info: %s", err) + return fmt.Errorf("Error reading remote info: %s", err) } out.Close() errCode := remoteInfo.GetInt("Code") if errCode != types.E_OK { if errCode != types.E_BAD_REQUEST && errCode != types.E_FAILED { - return "", fmt.Errorf("Error code is %d", errCode) + return fmt.Errorf("Error code is %d", errCode) } else { - return "", fmt.Errorf("Cause is %s", remoteInfo.Get("Cause")) + return fmt.Errorf("Cause is %s", remoteInfo.Get("Cause")) } } - return remoteInfo.Get("ID"), nil + return nil } func (cli *Client) StartContainer(container string) error { diff --git a/client/run.go b/client/run.go index 21d92656..fb2292ab 100644 --- a/client/run.go +++ b/client/run.go @@ -29,7 +29,6 @@ func (cli *HyperClient) HyperCmdRun(args ...string) (err error) { var ( podId string - vmId string spec apitype.UserPod code int tty = false @@ -96,7 +95,7 @@ func (cli *HyperClient) HyperCmdRun(args ...string) (err error) { }() } - _, err = cli.client.StartPod(podId, vmId, false, tty, nil, nil, nil) + err = cli.client.StartPod(podId) if err != nil { return err } diff --git a/client/start.go b/client/start.go index cc024444..84d1e8dd 100644 --- a/client/start.go +++ b/client/start.go @@ -29,7 +29,7 @@ func (cli *HyperClient) HyperCmdStart(args ...string) error { ) if !opts.Container { - _, err = cli.client.StartPod(id, "", false, false, nil, nil, nil) + err = cli.client.StartPod(id) if err != nil { return err } diff --git a/daemon/server.go b/daemon/server.go index a7501dca..9ad394a8 100644 --- a/daemon/server.go +++ b/daemon/server.go @@ -238,14 +238,13 @@ func (daemon *Daemon) CmdSetPodLabels(podId string, override bool, labels map[st return v, nil } -func (daemon *Daemon) CmdStartPod(stdin io.ReadCloser, stdout io.WriteCloser, podId, vmId string, attach bool) (*engine.Env, error) { - code, cause, err := daemon.StartPod(stdin, stdout, podId, attach) +func (daemon *Daemon) CmdStartPod(podId string) (*engine.Env, error) { + code, cause, err := daemon.StartPod(nil, nil, podId, false) if err != nil { return nil, err } v := &engine.Env{} - v.Set("ID", vmId) v.SetInt("Code", code) v.Set("Cause", cause) diff --git a/server/router/pod/backend.go b/server/router/pod/backend.go index 3254e380..ccc784fc 100644 --- a/server/router/pod/backend.go +++ b/server/router/pod/backend.go @@ -1,8 +1,6 @@ package pod import ( - "io" - "github.com/hyperhq/hyperd/engine" ) @@ -13,7 +11,7 @@ type Backend interface { CmdGetPodStats(podId string) (interface{}, error) CmdCreatePod(podArgs string) (*engine.Env, error) CmdSetPodLabels(podId string, override bool, labels map[string]string) (*engine.Env, error) - CmdStartPod(in io.ReadCloser, out io.WriteCloser, podId, vmId string, attach bool) (*engine.Env, error) + CmdStartPod(podId string) (*engine.Env, error) CmdPausePod(podId string) error CmdUnpausePod(podId string) error CmdList(item, podId, vmId string, auxiliary bool) (*engine.Env, error) diff --git a/server/router/pod/pod_routes.go b/server/router/pod/pod_routes.go index e10fd288..75f61133 100644 --- a/server/router/pod/pod_routes.go +++ b/server/router/pod/pod_routes.go @@ -2,8 +2,6 @@ package pod import ( "encoding/json" - "fmt" - "io" "io/ioutil" "net/http" @@ -108,42 +106,13 @@ func (p *podRouter) postPodStart(ctx context.Context, w http.ResponseWriter, r * return err } - attach := false podId := r.Form.Get("podId") - vmId := r.Form.Get("vmId") - if val := r.Form.Get("attach"); val == "yes" || val == "true" || val == "on" { - attach = true - } - - var ( - inStream io.ReadCloser = nil - outStream io.WriteCloser = nil - ) - - if attach { - // Setting up the streaming http interface. - in, out, err := httputils.HijackConnection(w) - if err != nil { - return err - } - inStream = in - outStream = out.(io.WriteCloser) - defer httputils.CloseStreams(inStream, outStream) - - fmt.Fprintf(outStream, "HTTP/1.1 101 UPGRADED\r\nContent-Type: application/vnd.docker.raw-stream\r\nConnection: Upgrade\r\nUpgrade: tcp\r\n\r\n") - } - - env, err := p.backend.CmdStartPod(inStream, outStream, podId, vmId, attach) + env, err := p.backend.CmdStartPod(podId) if err != nil { return err } - if attach { - w.WriteHeader(http.StatusNoContent) - return nil - } - return env.WriteJSON(w, http.StatusOK) } From 392fb71273df8bd9e5987924bfc19ce719c5e6d7 Mon Sep 17 00:00:00 2001 From: Wang Xu Date: Tue, 20 Dec 2016 23:08:16 +0800 Subject: [PATCH 3/4] try add aufs-tools to travis installation list Signed-off-by: Wang Xu --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f1bb1ad8..a634db38 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ matrix: before_install: - sudo apt-get update -qq - - sudo apt-get install -y autoconf automake pkg-config libdevmapper-dev libsqlite3-dev libvirt-dev qemu libvirt-bin -qq + - sudo apt-get install -y autoconf automake pkg-config libdevmapper-dev libsqlite3-dev libvirt-dev qemu libvirt-bin aufs-tools -qq - cd `mktemp -d` - mkdir -p ${GOPATH}/src/github.com/hyperhq - wget https://git.fedorahosted.org/cgit/lvm2.git/snapshot/lvm2-2_02_131.tar.xz From 48122d86a9298d2fdf00aa9da47b14fa33e4926d Mon Sep 17 00:00:00 2001 From: Wang Xu Date: Tue, 20 Dec 2016 23:50:48 +0800 Subject: [PATCH 4/4] finally, we could remove the todo line for start API //TODO: remove the tty stream in StartPod API, now we could support attach after created //Done. Signed-off-by: Wang Xu --- client/api/start.go | 25 +------- daemon/daemonbuilder/pod.go | 2 +- daemon/run.go | 27 ++------- daemon/server.go | 5 +- integration/client.go | 33 ++--------- integration/hyper_test.go | 12 ++-- serverrpc/pod.go | 62 ++------------------ types/types.pb.go | 110 +++++++++++++----------------------- types/types.proto | 11 ++-- 9 files changed, 67 insertions(+), 220 deletions(-) diff --git a/client/api/start.go b/client/api/start.go index 1eb2b113..dbdf9549 100644 --- a/client/api/start.go +++ b/client/api/start.go @@ -1,40 +1,17 @@ package api import ( - "fmt" "net/url" - - "github.com/hyperhq/hyperd/engine" - "github.com/hyperhq/runv/hypervisor/types" ) func (cli *Client) StartPod(podId string) error { v := url.Values{} v.Set("podId", podId) - body, _, err := readBody(cli.call("POST", "/pod/start?"+v.Encode(), nil, nil)) - if err != nil { - return err - } - out := engine.NewOutput() - remoteInfo, err := out.AddEnv() + _, _, err := readBody(cli.call("POST", "/pod/start?"+v.Encode(), nil, nil)) if err != nil { return err } - - if _, err := out.Write(body); err != nil { - return fmt.Errorf("Error reading remote info: %s", err) - } - out.Close() - errCode := remoteInfo.GetInt("Code") - if errCode != types.E_OK { - if errCode != types.E_BAD_REQUEST && - errCode != types.E_FAILED { - return fmt.Errorf("Error code is %d", errCode) - } else { - return fmt.Errorf("Cause is %s", remoteInfo.Get("Cause")) - } - } return nil } diff --git a/daemon/daemonbuilder/pod.go b/daemon/daemonbuilder/pod.go index f8141524..0b6ad226 100644 --- a/daemon/daemonbuilder/pod.go +++ b/daemon/daemonbuilder/pod.go @@ -190,7 +190,7 @@ func (d Docker) ContainerStart(cId string, hostConfig *containertypes.HostConfig } }() - if _, _, err = d.Daemon.StartPod(nil, nil, podId, false); err != nil { + if err = d.Daemon.StartPod(podId); err != nil { return } diff --git a/daemon/run.go b/daemon/run.go index d4f71195..d95a59ac 100644 --- a/daemon/run.go +++ b/daemon/run.go @@ -2,7 +2,6 @@ package daemon import ( "fmt" - "io" "github.com/golang/glog" @@ -43,24 +42,10 @@ func (daemon *Daemon) CreatePod(podId string, podSpec *apitypes.UserPod) (*pod.X return p, nil } -//TODO: remove the tty stream in StartPod API, now we could support attach after created -func (daemon *Daemon) StartPod(stdin io.ReadCloser, stdout io.WriteCloser, podId string, attach bool) (int, string, error) { +func (daemon *Daemon) StartPod(podId string) error { p, ok := daemon.PodList.Get(podId) if !ok { - return -1, "", fmt.Errorf("The pod(%s) can not be found, please create it first", podId) - } - - var waitTty chan error - - if attach { - glog.V(1).Info("Run pod with tty attached") - - ids := p.ContainerIdsOf(apitypes.UserContainer_REGULAR) - for _, id := range ids { - waitTty = make(chan error, 1) - p.Attach(id, stdin, stdout, waitTty) - break - } + return fmt.Errorf("The pod(%s) can not be found, please create it first", podId) } glog.Infof("Starting pod %q in vm: %q", podId, p.SandboxName()) @@ -68,14 +53,10 @@ func (daemon *Daemon) StartPod(stdin io.ReadCloser, stdout io.WriteCloser, podId err := p.Start() if err != nil { glog.Infof("failed to start pod %s: %v", p.Id(), err) - return -1, err.Error(), err - } - - if waitTty != nil { - <-waitTty + return err } - return 0, "", err + return err } func (daemon *Daemon) WaitContainer(cid string, second int) (int, error) { diff --git a/daemon/server.go b/daemon/server.go index 9ad394a8..a37e4fa7 100644 --- a/daemon/server.go +++ b/daemon/server.go @@ -239,15 +239,12 @@ func (daemon *Daemon) CmdSetPodLabels(podId string, override bool, labels map[st } func (daemon *Daemon) CmdStartPod(podId string) (*engine.Env, error) { - code, cause, err := daemon.StartPod(nil, nil, podId, false) + err := daemon.StartPod(podId) if err != nil { return nil, err } v := &engine.Env{} - v.SetInt("Code", code) - v.Set("Cause", cause) - return v, nil } diff --git a/integration/client.go b/integration/client.go index 3188a255..bb735168 100644 --- a/integration/client.go +++ b/integration/client.go @@ -453,36 +453,13 @@ func (c *HyperClient) ContainerExecStart(containerId, execId string, stdin io.Re } // StartPod starts a pod by podID -func (c *HyperClient) StartPod(podID, vmID string, attach bool) error { - stream, err := c.client.PodStart(context.Background()) - if err != nil { - return err - } - - req := types.PodStartMessage{ - PodID: podID, - VmID: vmID, - Attach: attach, - } - if err := stream.Send(&req); err != nil { - return err - } - - if attach { - if _, err := stream.Recv(); err != nil { - return err - } - - return nil +func (c *HyperClient) StartPod(podID string) error { + req := &types.PodStartRequest{ + PodID: podID, } - cmd := types.PodStartMessage{ - Data: []byte("ls\n"), - } - if err := stream.Send(&cmd); err != nil { - return err - } - if _, err := stream.Recv(); err != nil { + _, err := c.client.PodStart(c.ctx, req) + if err != nil { return err } diff --git a/integration/hyper_test.go b/integration/hyper_test.go index 9ece8ce3..4cf16d93 100644 --- a/integration/hyper_test.go +++ b/integration/hyper_test.go @@ -98,7 +98,7 @@ func (s *TestSuite) TestPostAttach(c *C) { c.Logf("Pod created: %s", pod) defer s.client.RemovePod(pod) - err = s.client.StartPod(pod, "", false) + err = s.client.StartPod(pod) c.Assert(err, IsNil) podInfo, err := s.client.GetPodInfo(pod) @@ -154,7 +154,7 @@ func (s *TestSuite) TestCreateAndStartPod(c *C) { c.Errorf("Can't found pod %s", pod) } - err = s.client.StartPod(pod, "", false) + err = s.client.StartPod(pod) c.Assert(err, IsNil) podInfo, err := s.client.GetPodInfo(pod) @@ -296,7 +296,7 @@ func (s *TestSuite) TestAddListDeleteService(c *C) { c.Log(" 2 ===> create pod") - err = s.client.StartPod(pod, "", false) + err = s.client.StartPod(pod) c.Assert(err, IsNil) updateService := []*types.UserService{ @@ -368,7 +368,7 @@ func (s *TestSuite) TestStartAndStopPod(c *C) { c.Assert(err, IsNil) c.Logf("Pod created: %s", pod) - err = s.client.StartPod(pod, "", false) + err = s.client.StartPod(pod) c.Assert(err, IsNil) podInfo, err := s.client.GetPodInfo(pod) @@ -429,7 +429,7 @@ func (s *TestSuite) TestPauseAndUnpausePod(c *C) { c.Assert(err, IsNil) c.Logf("Pod created: %s", pod) - err = s.client.StartPod(pod, "", false) + err = s.client.StartPod(pod) c.Assert(err, IsNil) podInfo, err := s.client.GetPodInfo(pod) @@ -479,7 +479,7 @@ func (s *TestSuite) TestGetPodStats(c *C) { c.Assert(err, IsNil) }() - err = s.client.StartPod(podID, "", false) + err = s.client.StartPod(podID) c.Assert(err, IsNil) stats, err := s.client.GetPodStats(podID) diff --git a/serverrpc/pod.go b/serverrpc/pod.go index d45bd2d4..4a88b195 100644 --- a/serverrpc/pod.go +++ b/serverrpc/pod.go @@ -2,7 +2,6 @@ package serverrpc import ( "fmt" - "io" "github.com/golang/glog" "github.com/hyperhq/hyperd/types" @@ -26,68 +25,17 @@ func (s *ServerRPC) PodCreate(ctx context.Context, req *types.PodCreateRequest) } // PodStart starts a pod by podID -func (s *ServerRPC) PodStart(stream types.PublicAPI_PodStartServer) error { - req, err := stream.Recv() - if err == io.EOF { - return nil - } - if err != nil { - return err - } +func (s *ServerRPC) PodStart(ctx context.Context, req *types.PodStartRequest) (*types.PodStartResponse, error) { glog.V(3).Infof("PodStart with request %s", req.String()) - if !req.Attach { - _, _, err := s.daemon.StartPod(nil, nil, req.PodID, req.Attach) - if err != nil { - glog.Errorf("StartPod failed: %v", err) - return err - } - - // Send an empty message to client, so client could wait for start complete - if err := stream.Send(&types.PodStartMessage{}); err != nil { - return err - } - - return nil - } - - ir, iw := io.Pipe() - or, ow := io.Pipe() + err := s.daemon.StartPod(req.PodID) - go func() { - for { - cmd, err := stream.Recv() - if err != nil { - return - } - - if _, err := iw.Write(cmd.Data); err != nil { - return - } - } - - }() - - go func() { - for { - res := make([]byte, 512) - n, err := or.Read(res) - if err != nil { - return - } - - if err := stream.Send(&types.PodStartMessage{Data: res[:n]}); err != nil { - return - } - } - }() - - if _, _, err := s.daemon.StartPod(ir, ow, req.PodID, req.Attach); err != nil { + if err != nil { glog.Errorf("StartPod failed: %v", err) - return err + return nil, err } - return nil + return &types.PodStartResponse{}, nil } // PodRemove removes a pod by podID diff --git a/types/types.pb.go b/types/types.pb.go index 2babc8b4..52f38bc6 100644 --- a/types/types.pb.go +++ b/types/types.pb.go @@ -86,7 +86,8 @@ It has these top-level messages: ExecCreateResponse ExecStartRequest ExecStartResponse - PodStartMessage + PodStartRequest + PodStartResponse WaitRequest WaitResponse AttachMessage @@ -1561,16 +1562,20 @@ func (m *ExecStartResponse) Reset() { *m = ExecStartResponse{} } func (m *ExecStartResponse) String() string { return proto.CompactTextString(m) } func (*ExecStartResponse) ProtoMessage() {} -type PodStartMessage struct { - PodID string `protobuf:"bytes,1,opt,name=podID,proto3" json:"podID,omitempty"` - VmID string `protobuf:"bytes,2,opt,name=vmID,proto3" json:"vmID,omitempty"` - Attach bool `protobuf:"varint,3,opt,name=attach,proto3" json:"attach,omitempty"` - Data []byte `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"` +type PodStartRequest struct { + PodID string `protobuf:"bytes,1,opt,name=podID,proto3" json:"podID,omitempty"` +} + +func (m *PodStartRequest) Reset() { *m = PodStartRequest{} } +func (m *PodStartRequest) String() string { return proto.CompactTextString(m) } +func (*PodStartRequest) ProtoMessage() {} + +type PodStartResponse struct { } -func (m *PodStartMessage) Reset() { *m = PodStartMessage{} } -func (m *PodStartMessage) String() string { return proto.CompactTextString(m) } -func (*PodStartMessage) ProtoMessage() {} +func (m *PodStartResponse) Reset() { *m = PodStartResponse{} } +func (m *PodStartResponse) String() string { return proto.CompactTextString(m) } +func (*PodStartResponse) ProtoMessage() {} type WaitRequest struct { Container string `protobuf:"bytes,1,opt,name=container,proto3" json:"container,omitempty"` @@ -2094,7 +2099,8 @@ func init() { proto.RegisterType((*ExecCreateResponse)(nil), "types.ExecCreateResponse") proto.RegisterType((*ExecStartRequest)(nil), "types.ExecStartRequest") proto.RegisterType((*ExecStartResponse)(nil), "types.ExecStartResponse") - proto.RegisterType((*PodStartMessage)(nil), "types.PodStartMessage") + proto.RegisterType((*PodStartRequest)(nil), "types.PodStartRequest") + proto.RegisterType((*PodStartResponse)(nil), "types.PodStartResponse") proto.RegisterType((*WaitRequest)(nil), "types.WaitRequest") proto.RegisterType((*WaitResponse)(nil), "types.WaitResponse") proto.RegisterType((*AttachMessage)(nil), "types.AttachMessage") @@ -2159,7 +2165,7 @@ type PublicAPIClient interface { // PodRemove deletes a pod by podID PodRemove(ctx context.Context, in *PodRemoveRequest, opts ...grpc.CallOption) (*PodRemoveResponse, error) // PodStart starts a pod - PodStart(ctx context.Context, opts ...grpc.CallOption) (PublicAPI_PodStartClient, error) + PodStart(ctx context.Context, in *PodStartRequest, opts ...grpc.CallOption) (*PodStartResponse, error) // PodStop stops a pod PodStop(ctx context.Context, in *PodStopRequest, opts ...grpc.CallOption) (*PodStopResponse, error) // PodSignal sends a singal to all containers of specified pod @@ -2269,35 +2275,13 @@ func (c *publicAPIClient) PodRemove(ctx context.Context, in *PodRemoveRequest, o return out, nil } -func (c *publicAPIClient) PodStart(ctx context.Context, opts ...grpc.CallOption) (PublicAPI_PodStartClient, error) { - stream, err := grpc.NewClientStream(ctx, &_PublicAPI_serviceDesc.Streams[0], c.cc, "/types.PublicAPI/PodStart", opts...) +func (c *publicAPIClient) PodStart(ctx context.Context, in *PodStartRequest, opts ...grpc.CallOption) (*PodStartResponse, error) { + out := new(PodStartResponse) + err := grpc.Invoke(ctx, "/types.PublicAPI/PodStart", in, out, c.cc, opts...) if err != nil { return nil, err } - x := &publicAPIPodStartClient{stream} - return x, nil -} - -type PublicAPI_PodStartClient interface { - Send(*PodStartMessage) error - Recv() (*PodStartMessage, error) - grpc.ClientStream -} - -type publicAPIPodStartClient struct { - grpc.ClientStream -} - -func (x *publicAPIPodStartClient) Send(m *PodStartMessage) error { - return x.ClientStream.SendMsg(m) -} - -func (x *publicAPIPodStartClient) Recv() (*PodStartMessage, error) { - m := new(PodStartMessage) - if err := x.ClientStream.RecvMsg(m); err != nil { - return nil, err - } - return m, nil + return out, nil } func (c *publicAPIClient) PodStop(ctx context.Context, in *PodStopRequest, opts ...grpc.CallOption) (*PodStopResponse, error) { @@ -2391,7 +2375,7 @@ func (c *publicAPIClient) PodStats(ctx context.Context, in *PodStatsRequest, opt } func (c *publicAPIClient) ContainerLogs(ctx context.Context, in *ContainerLogsRequest, opts ...grpc.CallOption) (PublicAPI_ContainerLogsClient, error) { - stream, err := grpc.NewClientStream(ctx, &_PublicAPI_serviceDesc.Streams[1], c.cc, "/types.PublicAPI/ContainerLogs", opts...) + stream, err := grpc.NewClientStream(ctx, &_PublicAPI_serviceDesc.Streams[0], c.cc, "/types.PublicAPI/ContainerLogs", opts...) if err != nil { return nil, err } @@ -2477,7 +2461,7 @@ func (c *publicAPIClient) ExecCreate(ctx context.Context, in *ExecCreateRequest, } func (c *publicAPIClient) ExecStart(ctx context.Context, opts ...grpc.CallOption) (PublicAPI_ExecStartClient, error) { - stream, err := grpc.NewClientStream(ctx, &_PublicAPI_serviceDesc.Streams[2], c.cc, "/types.PublicAPI/ExecStart", opts...) + stream, err := grpc.NewClientStream(ctx, &_PublicAPI_serviceDesc.Streams[1], c.cc, "/types.PublicAPI/ExecStart", opts...) if err != nil { return nil, err } @@ -2508,7 +2492,7 @@ func (x *publicAPIExecStartClient) Recv() (*ExecStartResponse, error) { } func (c *publicAPIClient) Attach(ctx context.Context, opts ...grpc.CallOption) (PublicAPI_AttachClient, error) { - stream, err := grpc.NewClientStream(ctx, &_PublicAPI_serviceDesc.Streams[3], c.cc, "/types.PublicAPI/Attach", opts...) + stream, err := grpc.NewClientStream(ctx, &_PublicAPI_serviceDesc.Streams[2], c.cc, "/types.PublicAPI/Attach", opts...) if err != nil { return nil, err } @@ -2584,7 +2568,7 @@ func (c *publicAPIClient) ServiceUpdate(ctx context.Context, in *ServiceUpdateRe } func (c *publicAPIClient) ImagePull(ctx context.Context, in *ImagePullRequest, opts ...grpc.CallOption) (PublicAPI_ImagePullClient, error) { - stream, err := grpc.NewClientStream(ctx, &_PublicAPI_serviceDesc.Streams[4], c.cc, "/types.PublicAPI/ImagePull", opts...) + stream, err := grpc.NewClientStream(ctx, &_PublicAPI_serviceDesc.Streams[3], c.cc, "/types.PublicAPI/ImagePull", opts...) if err != nil { return nil, err } @@ -2616,7 +2600,7 @@ func (x *publicAPIImagePullClient) Recv() (*ImagePullResponse, error) { } func (c *publicAPIClient) ImagePush(ctx context.Context, in *ImagePushRequest, opts ...grpc.CallOption) (PublicAPI_ImagePushClient, error) { - stream, err := grpc.NewClientStream(ctx, &_PublicAPI_serviceDesc.Streams[5], c.cc, "/types.PublicAPI/ImagePush", opts...) + stream, err := grpc.NewClientStream(ctx, &_PublicAPI_serviceDesc.Streams[4], c.cc, "/types.PublicAPI/ImagePush", opts...) if err != nil { return nil, err } @@ -2695,7 +2679,7 @@ type PublicAPIServer interface { // PodRemove deletes a pod by podID PodRemove(context.Context, *PodRemoveRequest) (*PodRemoveResponse, error) // PodStart starts a pod - PodStart(PublicAPI_PodStartServer) error + PodStart(context.Context, *PodStartRequest) (*PodStartResponse, error) // PodStop stops a pod PodStop(context.Context, *PodStopRequest) (*PodStopResponse, error) // PodSignal sends a singal to all containers of specified pod @@ -2813,30 +2797,16 @@ func _PublicAPI_PodRemove_Handler(srv interface{}, ctx context.Context, dec func return out, nil } -func _PublicAPI_PodStart_Handler(srv interface{}, stream grpc.ServerStream) error { - return srv.(PublicAPIServer).PodStart(&publicAPIPodStartServer{stream}) -} - -type PublicAPI_PodStartServer interface { - Send(*PodStartMessage) error - Recv() (*PodStartMessage, error) - grpc.ServerStream -} - -type publicAPIPodStartServer struct { - grpc.ServerStream -} - -func (x *publicAPIPodStartServer) Send(m *PodStartMessage) error { - return x.ServerStream.SendMsg(m) -} - -func (x *publicAPIPodStartServer) Recv() (*PodStartMessage, error) { - m := new(PodStartMessage) - if err := x.ServerStream.RecvMsg(m); err != nil { +func _PublicAPI_PodStart_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { + in := new(PodStartRequest) + if err := dec(in); err != nil { return nil, err } - return m, nil + out, err := srv.(PublicAPIServer).PodStart(ctx, in) + if err != nil { + return nil, err + } + return out, nil } func _PublicAPI_PodStop_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { @@ -3274,6 +3244,10 @@ var _PublicAPI_serviceDesc = grpc.ServiceDesc{ MethodName: "PodRemove", Handler: _PublicAPI_PodRemove_Handler, }, + { + MethodName: "PodStart", + Handler: _PublicAPI_PodStart_Handler, + }, { MethodName: "PodStop", Handler: _PublicAPI_PodStop_Handler, @@ -3376,12 +3350,6 @@ var _PublicAPI_serviceDesc = grpc.ServiceDesc{ }, }, Streams: []grpc.StreamDesc{ - { - StreamName: "PodStart", - Handler: _PublicAPI_PodStart_Handler, - ServerStreams: true, - ClientStreams: true, - }, { StreamName: "ContainerLogs", Handler: _PublicAPI_ContainerLogs_Handler, diff --git a/types/types.proto b/types/types.proto index 048a8ad5..345d7030 100644 --- a/types/types.proto +++ b/types/types.proto @@ -570,13 +570,12 @@ message ExecStartResponse{ bytes stdout = 1; } -message PodStartMessage { - string podID = 1; - string vmID = 2; - bool attach = 3; - bytes data = 4; +message PodStartRequest { + string podID = 1; } +message PodStartResponse {} + message WaitRequest{ string container = 1; string processId = 2; @@ -770,7 +769,7 @@ service PublicAPI { // PodRemove deletes a pod by podID rpc PodRemove(PodRemoveRequest) returns (PodRemoveResponse) {} // PodStart starts a pod - rpc PodStart(stream PodStartMessage) returns (stream PodStartMessage) {} + rpc PodStart(PodStartRequest) returns (PodStartResponse) {} // PodStop stops a pod rpc PodStop(PodStopRequest) returns (PodStopResponse) {} // PodSignal sends a singal to all containers of specified pod