1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/daemon/cluster/convert/task.go
Tonis Tiigi 534a90a993 Add Swarm management backend
As described in our ROADMAP.md, introduce new Swarm management API
endpoints relying on swarmkit to deploy services. It currently vendors
docker/engine-api changes.

This PR is fully backward compatible (joining a Swarm is an optional
feature of the Engine, and existing commands are not impacted).

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Signed-off-by: Victor Vieux <vieux@docker.com>
Signed-off-by: Daniel Nephin <dnephin@docker.com>
Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
Signed-off-by: Madhu Venugopal <madhu@docker.com>
2016-06-13 22:16:18 -07:00

53 lines
1.6 KiB
Go

package convert
import (
"strings"
types "github.com/docker/engine-api/types/swarm"
swarmapi "github.com/docker/swarmkit/api"
"github.com/docker/swarmkit/protobuf/ptypes"
)
// TaskFromGRPC converts a grpc Task to a Task.
func TaskFromGRPC(t swarmapi.Task) types.Task {
containerConfig := t.Spec.Runtime.(*swarmapi.TaskSpec_Container).Container
containerStatus := t.Status.GetContainer()
task := types.Task{
ID: t.ID,
ServiceID: t.ServiceID,
Slot: int(t.Slot),
NodeID: t.NodeID,
Spec: types.TaskSpec{
ContainerSpec: containerSpecFromGRPC(containerConfig),
Resources: resourcesFromGRPC(t.Spec.Resources),
RestartPolicy: restartPolicyFromGRPC(t.Spec.Restart),
Placement: placementFromGRPC(t.Spec.Placement),
},
Status: types.TaskStatus{
State: types.TaskState(strings.ToLower(t.Status.State.String())),
Message: t.Status.Message,
Err: t.Status.Err,
},
DesiredState: types.TaskState(strings.ToLower(t.DesiredState.String())),
}
// Meta
task.Version.Index = t.Meta.Version.Index
task.CreatedAt, _ = ptypes.Timestamp(t.Meta.CreatedAt)
task.UpdatedAt, _ = ptypes.Timestamp(t.Meta.UpdatedAt)
task.Status.Timestamp, _ = ptypes.Timestamp(t.Status.Timestamp)
if containerStatus != nil {
task.Status.ContainerStatus.ContainerID = containerStatus.ContainerID
task.Status.ContainerStatus.PID = int(containerStatus.PID)
task.Status.ContainerStatus.ExitCode = int(containerStatus.ExitCode)
}
// NetworksAttachments
for _, na := range t.Networks {
task.NetworksAttachments = append(task.NetworksAttachments, networkAttachementFromGRPC(na))
}
return task
}