@@ -29,6 +29,8 @@ type NameResolver interface {
2929 ContainerName (containerID string ) string
3030}
3131
32+ // TODO: pass api.ServiceContainer to operations to simplify operation formatting in the plan.
33+
3234// RunContainerOperation creates and starts a new container on a specific machine.
3335type RunContainerOperation struct {
3436 ServiceID string
@@ -56,8 +58,8 @@ func (o *RunContainerOperation) Format(resolver NameResolver) string {
5658}
5759
5860func (o * RunContainerOperation ) String () string {
59- return fmt .Sprintf ("RunContainerOperation[service_id =%s, image =%s, machine_id =%s]" ,
60- o .ServiceID , o .Spec .Container .Image , o . MachineID )
61+ return fmt .Sprintf ("RunContainerOperation[machine_id =%s service_id =%s image =%s]" ,
62+ o .MachineID , o . ServiceID , o .Spec .Container .Image )
6163}
6264
6365// StopContainerOperation stops a container on a specific machine.
@@ -76,26 +78,26 @@ func (o *StopContainerOperation) Execute(ctx context.Context, cli Client) error
7678
7779func (o * StopContainerOperation ) Format (resolver NameResolver ) string {
7880 machineName := resolver .MachineName (o .MachineID )
79- return fmt .Sprintf ("%s: Stop container [name=%s]" , machineName , resolver .ContainerName (o .ContainerID ))
81+ return fmt .Sprintf ("%s: Stop container [id=%s name=%s]" , machineName ,
82+ o .ContainerID , resolver .ContainerName (o .ContainerID ))
8083}
8184
8285func (o * StopContainerOperation ) String () string {
83- return fmt .Sprintf ("StopContainerOperation[service_id =%s, container_id =%s, machine_id =%s]" ,
84- o .ServiceID , o .ContainerID , o .MachineID )
86+ return fmt .Sprintf ("StopContainerOperation[machine_id =%s service_id =%s container_id =%s]" ,
87+ o .MachineID , o .ServiceID , o .ContainerID )
8588}
8689
8790// RemoveContainerOperation stops and removes a container from a specific machine.
8891type RemoveContainerOperation struct {
89- ServiceID string
90- ContainerID string
91- MachineID string
92+ MachineID string
93+ Container api.ServiceContainer
9294}
9395
9496func (o * RemoveContainerOperation ) Execute (ctx context.Context , cli Client ) error {
95- if err := cli .StopContainer (ctx , o .ServiceID , o .ContainerID , container.StopOptions {}); err != nil {
97+ if err := cli .StopContainer (ctx , o .Container . ServiceID () , o .Container . ID , container.StopOptions {}); err != nil {
9698 return fmt .Errorf ("stop container: %w" , err )
9799 }
98- if err := cli .RemoveContainer (ctx , o .ServiceID , o .ContainerID , container.RemoveOptions {
100+ if err := cli .RemoveContainer (ctx , o .Container . ServiceID () , o .Container . ID , container.RemoveOptions {
99101 // Remove anonymous volumes created by the container.
100102 RemoveVolumes : true ,
101103 }); err != nil {
@@ -107,12 +109,13 @@ func (o *RemoveContainerOperation) Execute(ctx context.Context, cli Client) erro
107109
108110func (o * RemoveContainerOperation ) Format (resolver NameResolver ) string {
109111 machineName := resolver .MachineName (o .MachineID )
110- return fmt .Sprintf ("%s: Remove container [name=%s]" , machineName , resolver .ContainerName (o .ContainerID ))
112+ return fmt .Sprintf ("%s: Remove container [ID=%s image=%s]" ,
113+ machineName , o .Container .ShortID (), o .Container .Config .Image )
111114}
112115
113116func (o * RemoveContainerOperation ) String () string {
114- return fmt .Sprintf ("RemoveContainerOperation[service_id =%s, container_id =%s, machine_id =%s]" ,
115- o .ServiceID , o .ContainerID , o .MachineID )
117+ return fmt .Sprintf ("RemoveContainerOperation[machine_id =%s service_id =%s container_id =%s]" ,
118+ o .MachineID , o .Container . ServiceID () , o .Container . ID )
116119}
117120
118121// CreateVolumeOperation creates a volume on a specific machine.
@@ -151,8 +154,8 @@ func (o *CreateVolumeOperation) Format(_ NameResolver) string {
151154}
152155
153156func (o * CreateVolumeOperation ) String () string {
154- return fmt .Sprintf ("CreateVolumeOperation[volume =%s, machine_id =%s]" ,
155- o .VolumeSpec .DockerVolumeName (), o . MachineID )
157+ return fmt .Sprintf ("CreateVolumeOperation[machine_id =%s volume =%s]" ,
158+ o .MachineID , o . VolumeSpec .DockerVolumeName ())
156159}
157160
158161// SequenceOperation is a composite operation that executes a sequence of operations in order.
0 commit comments