Browse code

Make `--dispatcher-heartbeat-period` a duration

Make `--dispatcher-heartbeat-period` a duration in `docker swarm
update`, allowing to express the value as "5s", "1h", etc.

Signed-off-by: Arnaud Porterie (icecrime) <arnaud.porterie@docker.com>

Arnaud Porterie (icecrime) authored on 2016/06/15 09:36:37
Showing 3 changed files
... ...
@@ -2,6 +2,7 @@ package swarm
2 2
 
3 3
 import (
4 4
 	"fmt"
5
+	"time"
5 6
 
6 7
 	"golang.org/x/net/context"
7 8
 
... ...
@@ -13,10 +14,10 @@ import (
13 13
 )
14 14
 
15 15
 type updateOptions struct {
16
-	autoAccept       AutoAcceptOption
17
-	secret           string
18
-	taskHistoryLimit int64
19
-	heartbeatPeriod  uint64
16
+	autoAccept          AutoAcceptOption
17
+	secret              string
18
+	taskHistoryLimit    int64
19
+	dispatcherHeartbeat time.Duration
20 20
 }
21 21
 
22 22
 func newUpdateCommand(dockerCli *client.DockerCli) *cobra.Command {
... ...
@@ -36,7 +37,7 @@ func newUpdateCommand(dockerCli *client.DockerCli) *cobra.Command {
36 36
 	flags.Var(&opts.autoAccept, "auto-accept", "Auto acceptance policy (worker, manager or none)")
37 37
 	flags.StringVar(&opts.secret, "secret", "", "Set secret value needed to accept nodes into cluster")
38 38
 	flags.Int64Var(&opts.taskHistoryLimit, "task-history-limit", 10, "Task history retention limit")
39
-	flags.Uint64Var(&opts.heartbeatPeriod, "dispatcher-heartbeat-period", 5000000000, "Dispatcher heartbeat period")
39
+	flags.DurationVar(&opts.dispatcherHeartbeat, "dispatcher-heartbeat", time.Duration(5*time.Second), "Dispatcher heartbeat period")
40 40
 	return cmd
41 41
 }
42 42
 
... ...
@@ -85,8 +86,10 @@ func mergeSwarm(swarm *swarm.Swarm, flags *pflag.FlagSet) error {
85 85
 		spec.Orchestration.TaskHistoryRetentionLimit, _ = flags.GetInt64("task-history-limit")
86 86
 	}
87 87
 
88
-	if flags.Changed("dispatcher-heartbeat-period") {
89
-		spec.Dispatcher.HeartbeatPeriod, _ = flags.GetUint64("dispatcher-heartbeat-period")
88
+	if flags.Changed("dispatcher-heartbeat") {
89
+		if v, err := flags.GetDuration("dispatcher-heartbeat"); err == nil {
90
+			spec.Dispatcher.HeartbeatPeriod = uint64(v.Nanoseconds())
91
+		}
90 92
 	}
91 93
 
92 94
 	return nil
... ...
@@ -1641,7 +1641,7 @@ _docker_swarm_join() {
1641 1641
 _docker_swarm_update() {
1642 1642
 	case "$cur" in
1643 1643
 		-*)
1644
-			COMPREPLY=( $( compgen -W "--auto-accept --dispatcher-heartbeat-period --help --secret --task-history-limit" -- "$cur" ) )
1644
+			COMPREPLY=( $( compgen -W "--auto-accept --dispatcher-heartbeat --help --secret --task-history-limit" -- "$cur" ) )
1645 1645
 			;;
1646 1646
 	esac
1647 1647
 }
... ...
@@ -12,15 +12,16 @@ parent = "smn_cli"
12 12
 
13 13
 # swarm update
14 14
 
15
-	Usage:    docker swarm update [OPTIONS]
16
-
17
-	update the Swarm.
18
-
19
-	Options:
20
-	      --auto-accept value   Acceptance policy (default [worker,manager])
21
-	      --help                Print usage
22
-	      --secret string       Set secret value needed to accept nodes into cluster
23
-
15
+    Usage:  docker swarm update [OPTIONS]
16
+    
17
+    update the Swarm.
18
+    
19
+    Options:
20
+          --auto-accept value               Auto acceptance policy (worker, manager or none)
21
+          --dispatcher-heartbeat duration   Dispatcher heartbeat period (default 5s)
22
+          --help                            Print usage
23
+          --secret string                   Set secret value needed to accept nodes into cluster
24
+          --task-history-limit int          Task history retention limit (default 10)
24 25
 
25 26
 Updates a Swarm cluster with new parameter values. This command must target a manager node.
26 27