Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.
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
23 changes: 18 additions & 5 deletions api/client/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/docker/engine-api/types/network"
"github.com/docker/engine-api/types/strslice"
"github.com/docker/go-connections/nat"
"github.com/docker/go-units"
units "github.com/docker/go-units"
Cli "github.com/hyperhq/hypercli/cli"
ropts "github.com/hyperhq/hypercli/opts"
flag "github.com/hyperhq/hypercli/pkg/mflag"
Expand Down Expand Up @@ -383,6 +383,8 @@ func (cli *DockerCli) CmdFuncInspect(args ...string) error {
// Usage: hyper func call NAME
func (cli *DockerCli) CmdFuncCall(args ...string) error {
cmd := Cli.Subcmd("func call", []string{"NAME"}, "Call a function", false)
wait := cmd.Bool([]string{"-wait"}, false, "Block until the call is completed")

cmd.Require(flag.Exact, 1)
if err := cmd.ParseFlags(args, true); err != nil {
return err
Expand All @@ -398,11 +400,24 @@ func (cli *DockerCli) CmdFuncCall(args ...string) error {
}
}

ret, err := cli.client.FuncCall(context.Background(), name, stdin)
body, err := cli.client.FuncCall(context.Background(), name, stdin, *wait)
if err != nil {
return err
}
defer body.Close()

if *wait {
_, err = io.Copy(cli.out, body)
return err
}

var ret types.FuncCallResponse
err = json.NewDecoder(body).Decode(&ret)
if err != nil {
return err
}
fmt.Fprintf(cli.out, "CallId: %s\n", ret.CallId)

return nil
}

Expand All @@ -424,9 +439,7 @@ func (cli *DockerCli) CmdFuncGet(args ...string) error {
if err != nil {
return err
}
defer func() {
body.Close()
}()
defer body.Close()

_, err = io.Copy(cli.out, body)
return err
Expand Down
16 changes: 7 additions & 9 deletions vendor/src/github.com/docker/engine-api/client/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,26 +182,24 @@ func (cli *Client) FuncInspectWithCallId(ctx context.Context, id string) (*types
return &fn, err
}

func (cli *Client) FuncCall(ctx context.Context, name string, stdin io.Reader) (*types.FuncCallResponse, error) {
func (cli *Client) FuncCall(ctx context.Context, name string, stdin io.Reader, wait bool) (io.ReadCloser, error) {
fn, _, err := cli.FuncInspectWithRaw(ctx, name)
if err != nil {
return nil, err
}
req, err := newFuncEndpointRequest("POST", path.Join("call", name, fn.UUID), nil, stdin)
if err != nil {
return nil, err
subpath := ""
if wait {
subpath += "/wait"
}
resp, err := funcEndpointRequest(req)
req, err := newFuncEndpointRequest("POST", path.Join("call", name, fn.UUID, subpath), nil, stdin)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var ret types.FuncCallResponse
err = json.NewDecoder(resp.Body).Decode(&ret)
resp, err := funcEndpointRequest(req)
if err != nil {
return nil, err
}
return &ret, nil
return resp.Body, nil
}

func (cli *Client) FuncGet(ctx context.Context, callId string, wait bool) (io.ReadCloser, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ type APIClient interface {
FuncList(ctx context.Context, opts types.FuncListOptions) ([]types.Func, error)
FuncInspect(ctx context.Context, name string) (types.Func, error)
FuncInspectWithRaw(ctx context.Context, name string) (types.Func, []byte, error)
FuncCall(ctx context.Context, name string, stdin io.Reader) (*types.FuncCallResponse, error)
FuncCall(ctx context.Context, name string, stdin io.Reader, wait bool) (io.ReadCloser, error)
FuncGet(ctx context.Context, callId string, wait bool) (io.ReadCloser, error)
FuncLogs(ctx context.Context, name, callId string, follow bool, tail string) (io.ReadCloser, error)
FuncStatus(ctx context.Context, name string) (*types.FuncStatusResponse, error)
Expand Down