Add Exec IDs

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2017-06-28 12:54:10 -07:00
parent e283b3802d
commit f93bfb6233
36 changed files with 1441 additions and 2055 deletions

View File

@@ -16,25 +16,28 @@ import (
)
type Task struct {
containerID string
shim *client.Client
namespace string
id string
shim *client.Client
namespace string
}
func newTask(id, namespace string, shim *client.Client) *Task {
return &Task{
containerID: id,
shim: shim,
namespace: namespace,
id: id,
shim: shim,
namespace: namespace,
}
}
func (t *Task) ID() string {
return t.id
}
func (t *Task) Info() runtime.TaskInfo {
return runtime.TaskInfo{
ID: t.containerID,
ContainerID: t.containerID,
Runtime: pluginID,
Namespace: t.namespace,
ID: t.id,
Runtime: pluginID,
Namespace: t.namespace,
}
}
@@ -47,7 +50,9 @@ func (t *Task) Start(ctx context.Context) error {
}
func (t *Task) State(ctx context.Context) (runtime.State, error) {
response, err := t.shim.State(ctx, empty)
response, err := t.shim.State(ctx, &shim.StateRequest{
ID: t.id,
})
if err != nil {
return runtime.State{}, errors.New(grpc.ErrorDesc(err))
}
@@ -89,10 +94,10 @@ func (t *Task) Resume(ctx context.Context) error {
return err
}
func (t *Task) Kill(ctx context.Context, signal uint32, pid uint32, all bool) error {
func (t *Task) Kill(ctx context.Context, signal uint32, all bool) error {
_, err := t.shim.Kill(ctx, &shim.KillRequest{
ID: t.id,
Signal: signal,
Pid: pid,
All: all,
})
if err != nil {
@@ -101,28 +106,28 @@ func (t *Task) Kill(ctx context.Context, signal uint32, pid uint32, all bool) er
return err
}
func (t *Task) Exec(ctx context.Context, opts runtime.ExecOpts) (runtime.Process, error) {
func (t *Task) Exec(ctx context.Context, id string, opts runtime.ExecOpts) (runtime.Process, error) {
request := &shim.ExecProcessRequest{
ID: id,
Stdin: opts.IO.Stdin,
Stdout: opts.IO.Stdout,
Stderr: opts.IO.Stderr,
Terminal: opts.IO.Terminal,
Spec: opts.Spec,
}
resp, err := t.shim.Exec(ctx, request)
if err != nil {
if _, err := t.shim.Exec(ctx, request); err != nil {
return nil, errors.New(grpc.ErrorDesc(err))
}
return &Process{
pid: int(resp.Pid),
t: t,
id: id,
t: t,
}, nil
}
func (t *Task) Pids(ctx context.Context) ([]uint32, error) {
resp, err := t.shim.ListPids(ctx, &shim.ListPidsRequest{
ID: t.containerID,
// TODO: (@crosbymichael) this id can probably be removed
ID: t.id,
})
if err != nil {
return nil, errors.New(grpc.ErrorDesc(err))
@@ -130,9 +135,9 @@ func (t *Task) Pids(ctx context.Context) ([]uint32, error) {
return resp.Pids, nil
}
func (t *Task) ResizePty(ctx context.Context, pid uint32, size runtime.ConsoleSize) error {
func (t *Task) ResizePty(ctx context.Context, size runtime.ConsoleSize) error {
_, err := t.shim.ResizePty(ctx, &shim.ResizePtyRequest{
Pid: pid,
ID: t.id,
Width: size.Width,
Height: size.Height,
})
@@ -142,9 +147,9 @@ func (t *Task) ResizePty(ctx context.Context, pid uint32, size runtime.ConsoleSi
return err
}
func (t *Task) CloseIO(ctx context.Context, pid uint32) error {
func (t *Task) CloseIO(ctx context.Context) error {
_, err := t.shim.CloseIO(ctx, &shim.CloseIORequest{
Pid: pid,
ID: t.id,
Stdin: true,
})
if err != nil {
@@ -164,9 +169,9 @@ func (t *Task) Checkpoint(ctx context.Context, path string, options *types.Any)
return nil
}
func (t *Task) DeleteProcess(ctx context.Context, pid uint32) (*runtime.Exit, error) {
func (t *Task) DeleteProcess(ctx context.Context, id string) (*runtime.Exit, error) {
r, err := t.shim.DeleteProcess(ctx, &shim.DeleteProcessRequest{
Pid: pid,
ID: id,
})
if err != nil {
return nil, errors.New(grpc.ErrorDesc(err))
@@ -174,7 +179,7 @@ func (t *Task) DeleteProcess(ctx context.Context, pid uint32) (*runtime.Exit, er
return &runtime.Exit{
Status: r.ExitStatus,
Timestamp: r.ExitedAt,
Pid: pid,
Pid: r.Pid,
}, nil
}
@@ -185,28 +190,10 @@ func (t *Task) Update(ctx context.Context, resources *types.Any) error {
return err
}
type Process struct {
pid int
t *Task
}
func (p *Process) Kill(ctx context.Context, signal uint32, _ bool) error {
_, err := p.t.shim.Kill(ctx, &shim.KillRequest{
Signal: signal,
Pid: uint32(p.pid),
})
if err != nil {
err = errors.New(grpc.ErrorDesc(err))
}
return err
}
func (p *Process) State(ctx context.Context) (runtime.State, error) {
// use the container status for the status of the process
state, err := p.t.State(ctx)
if err != nil {
return state, err
}
state.Pid = uint32(p.pid)
return state, nil
func (t *Task) Process(ctx context.Context, id string) (runtime.Process, error) {
// TODO: verify process exists for container
return &Process{
id: id,
t: t,
}, nil
}