1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #29041 from aaronlehmann/hide-updatestatus

api: Hide UpdateStatus when it is not present
This commit is contained in:
Sebastiaan van Stijn 2016-12-08 13:55:13 +01:00 committed by GitHub
commit e94a40cdda
5 changed files with 33 additions and 16 deletions

View file

@ -6,10 +6,10 @@ import "time"
type Service struct { type Service struct {
ID string ID string
Meta Meta
Spec ServiceSpec `json:",omitempty"` Spec ServiceSpec `json:",omitempty"`
PreviousSpec *ServiceSpec `json:",omitempty"` PreviousSpec *ServiceSpec `json:",omitempty"`
Endpoint Endpoint `json:",omitempty"` Endpoint Endpoint `json:",omitempty"`
UpdateStatus UpdateStatus `json:",omitempty"` UpdateStatus *UpdateStatus `json:",omitempty"`
} }
// ServiceSpec represents the spec of a service. // ServiceSpec represents the spec of a service.
@ -50,8 +50,8 @@ const (
// UpdateStatus reports the status of a service update. // UpdateStatus reports the status of a service update.
type UpdateStatus struct { type UpdateStatus struct {
State UpdateState `json:",omitempty"` State UpdateState `json:",omitempty"`
StartedAt time.Time `json:",omitempty"` StartedAt *time.Time `json:",omitempty"`
CompletedAt time.Time `json:",omitempty"` CompletedAt *time.Time `json:",omitempty"`
Message string `json:",omitempty"` Message string `json:",omitempty"`
} }

View file

@ -28,7 +28,9 @@ Service Mode:
{{- if .HasUpdateStatus }} {{- if .HasUpdateStatus }}
UpdateStatus: UpdateStatus:
State: {{ .UpdateStatusState }} State: {{ .UpdateStatusState }}
{{- if .HasUpdateStatusStarted }}
Started: {{ .UpdateStatusStarted }} Started: {{ .UpdateStatusStarted }}
{{- end }}
{{- if .UpdateIsCompleted }} {{- if .UpdateIsCompleted }}
Completed: {{ .UpdateStatusCompleted }} Completed: {{ .UpdateStatusCompleted }}
{{- end }} {{- end }}
@ -172,23 +174,27 @@ func (ctx *serviceInspectContext) ModeReplicatedReplicas() *uint64 {
} }
func (ctx *serviceInspectContext) HasUpdateStatus() bool { func (ctx *serviceInspectContext) HasUpdateStatus() bool {
return ctx.Service.UpdateStatus.State != "" return ctx.Service.UpdateStatus != nil && ctx.Service.UpdateStatus.State != ""
} }
func (ctx *serviceInspectContext) UpdateStatusState() swarm.UpdateState { func (ctx *serviceInspectContext) UpdateStatusState() swarm.UpdateState {
return ctx.Service.UpdateStatus.State return ctx.Service.UpdateStatus.State
} }
func (ctx *serviceInspectContext) HasUpdateStatusStarted() bool {
return ctx.Service.UpdateStatus.StartedAt != nil
}
func (ctx *serviceInspectContext) UpdateStatusStarted() string { func (ctx *serviceInspectContext) UpdateStatusStarted() string {
return units.HumanDuration(time.Since(ctx.Service.UpdateStatus.StartedAt)) return units.HumanDuration(time.Since(*ctx.Service.UpdateStatus.StartedAt))
} }
func (ctx *serviceInspectContext) UpdateIsCompleted() bool { func (ctx *serviceInspectContext) UpdateIsCompleted() bool {
return ctx.Service.UpdateStatus.State == swarm.UpdateStateCompleted return ctx.Service.UpdateStatus.State == swarm.UpdateStateCompleted && ctx.Service.UpdateStatus.CompletedAt != nil
} }
func (ctx *serviceInspectContext) UpdateStatusCompleted() string { func (ctx *serviceInspectContext) UpdateStatusCompleted() string {
return units.HumanDuration(time.Since(ctx.Service.UpdateStatus.CompletedAt)) return units.HumanDuration(time.Since(*ctx.Service.UpdateStatus.CompletedAt))
} }
func (ctx *serviceInspectContext) UpdateStatusMessage() string { func (ctx *serviceInspectContext) UpdateStatusMessage() string {

View file

@ -74,9 +74,9 @@ func formatServiceInspect(t *testing.T, format formatter.Format, now time.Time)
}, },
}, },
}, },
UpdateStatus: swarm.UpdateStatus{ UpdateStatus: &swarm.UpdateStatus{
StartedAt: now, StartedAt: &now,
CompletedAt: now, CompletedAt: &now,
}, },
} }

View file

@ -26,8 +26,8 @@ func ServiceFromGRPC(s swarmapi.Service) types.Service {
service.UpdatedAt, _ = ptypes.Timestamp(s.Meta.UpdatedAt) service.UpdatedAt, _ = ptypes.Timestamp(s.Meta.UpdatedAt)
// UpdateStatus // UpdateStatus
service.UpdateStatus = types.UpdateStatus{}
if s.UpdateStatus != nil { if s.UpdateStatus != nil {
service.UpdateStatus = &types.UpdateStatus{}
switch s.UpdateStatus.State { switch s.UpdateStatus.State {
case swarmapi.UpdateStatus_UPDATING: case swarmapi.UpdateStatus_UPDATING:
service.UpdateStatus.State = types.UpdateStateUpdating service.UpdateStatus.State = types.UpdateStateUpdating
@ -37,8 +37,16 @@ func ServiceFromGRPC(s swarmapi.Service) types.Service {
service.UpdateStatus.State = types.UpdateStateCompleted service.UpdateStatus.State = types.UpdateStateCompleted
} }
service.UpdateStatus.StartedAt, _ = ptypes.Timestamp(s.UpdateStatus.StartedAt) startedAt, _ := ptypes.Timestamp(s.UpdateStatus.StartedAt)
service.UpdateStatus.CompletedAt, _ = ptypes.Timestamp(s.UpdateStatus.CompletedAt) if !startedAt.IsZero() {
service.UpdateStatus.StartedAt = &startedAt
}
completedAt, _ := ptypes.Timestamp(s.UpdateStatus.CompletedAt)
if !completedAt.IsZero() {
service.UpdateStatus.CompletedAt = &completedAt
}
service.UpdateStatus.Message = s.UpdateStatus.Message service.UpdateStatus.Message = s.UpdateStatus.Message
} }

View file

@ -155,6 +155,9 @@ func (d *SwarmDaemon) checkServiceRunningTasks(service string) func(*check.C) (i
func (d *SwarmDaemon) checkServiceUpdateState(service string) func(*check.C) (interface{}, check.CommentInterface) { func (d *SwarmDaemon) checkServiceUpdateState(service string) func(*check.C) (interface{}, check.CommentInterface) {
return func(c *check.C) (interface{}, check.CommentInterface) { return func(c *check.C) (interface{}, check.CommentInterface) {
service := d.getService(c, service) service := d.getService(c, service)
if service.UpdateStatus == nil {
return "", nil
}
return service.UpdateStatus.State, nil return service.UpdateStatus.State, nil
} }
} }