Skip to content

Commit 8135ead

Browse files
committed
Merge pull request #3937 from laurrentt/feature/custom-router-mesh-size
feat(deisctl): specify # of routers to install
2 parents e4a54d0 + 18ebc77 commit 8135ead

3 files changed

Lines changed: 45 additions & 3 deletions

File tree

deisctl/client/client.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"os"
7+
"strconv"
78

89
"github.com/deis/deis/deisctl/backend"
910
"github.com/deis/deis/deisctl/backend/fleet"
@@ -110,7 +111,7 @@ Examples:
110111
// Install loads the definitions of components from local unit files.
111112
// After Install, the components will be available to Start.
112113
func (c *Client) Install(argv []string) error {
113-
usage := `Loads the definitions of components from local unit files.
114+
usage := fmt.Sprintf(`Loads the definitions of components from local unit files.
114115
115116
After install, the components will be available to start.
116117
@@ -121,13 +122,24 @@ After install, the components will be available to start.
121122
122123
Usage:
123124
deisctl install [<target>...] [options]
124-
`
125+
126+
Options:
127+
--router-mesh-size=<num> Number of routers to be loaded when installing the platform [default: %d].
128+
`, cmd.DefaultRouterMeshSize)
125129
// parse command-line arguments
126130
args, err := docopt.Parse(usage, argv, true, "", false)
127131
if err != nil {
128132
return err
129133
}
130134

135+
meshSizeArg, _ := args["--router-mesh-size"].(string)
136+
parsedValue, err := strconv.ParseUint(meshSizeArg, 0, 8)
137+
if err != nil || parsedValue < 1 {
138+
fmt.Print("Error: argument --router-mesh-size: invalid value, make sure the value is an integer between 1 and 255.\n")
139+
return err
140+
}
141+
cmd.RouterMeshSize = uint8(parsedValue)
142+
131143
return cmd.Install(args["<target>"].([]string), c.Backend, cmd.CheckRequiredKeys)
132144
}
133145

deisctl/cmd/cmd.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const (
2727
StatelessPlatformCommand string = "stateless-platform"
2828
swarm string = "swarm"
2929
mesos string = "mesos"
30+
// DefaultRouterMeshSize defines the default number of routers to be loaded when installing the platform.
31+
DefaultRouterMeshSize uint8 = 3
3032
)
3133

3234
// ListUnits prints a list of installed units.
@@ -45,6 +47,9 @@ var Stdout io.Writer = os.Stderr
4547
// Location to write standard error information. By default, this is the os.Stderr.
4648
var Stderr io.Writer = os.Stdout
4749

50+
// Number of routers to be installed. By default, it's DefaultRouterMeshSize.
51+
var RouterMeshSize = DefaultRouterMeshSize
52+
4853
// Scale grows or shrinks the number of running components.
4954
// Currently "router", "registry" and "store-gateway" are the only types that can be scaled.
5055
func Scale(targets []string, b backend.Backend) error {
@@ -319,11 +324,19 @@ func installDefaultServices(b backend.Backend, stateless bool, wg *sync.WaitGrou
319324
wg.Wait()
320325

321326
fmt.Fprintln(out, "Routing mesh...")
322-
b.Create([]string{"router@1", "router@2", "router@3"}, wg, out, err)
327+
b.Create(getRouters(), wg, out, err)
323328
wg.Wait()
324329

325330
}
326331

332+
func getRouters() []string {
333+
routers := make([]string, RouterMeshSize)
334+
for i := uint8(0); i < RouterMeshSize; i++ {
335+
routers[i] = fmt.Sprintf("router@%d", i+1)
336+
}
337+
return routers
338+
}
339+
327340
// Uninstall unloads the definitions of the specified components.
328341
// After Uninstall, the components will be unavailable until Install is called.
329342
func Uninstall(targets []string, b backend.Backend) error {

deisctl/cmd/cmd_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,23 @@ func TestInstallPlatform(t *testing.T) {
424424
}
425425
}
426426

427+
func TestInstallPlatformWithCustomRouterMeshSize(t *testing.T) {
428+
t.Parallel()
429+
430+
b := backendStub{}
431+
expected := []string{"store-daemon", "store-monitor", "store-metadata", "store-volume",
432+
"store-gateway@1", "logger", "logspout", "database", "registry@1",
433+
"controller", "builder", "publisher", "router@1", "router@2", "router@3", "router@4", "router@5"}
434+
RouterMeshSize = 5
435+
436+
Install([]string{"platform"}, &b, fakeCheckKeys)
437+
RouterMeshSize = DefaultRouterMeshSize
438+
439+
if !reflect.DeepEqual(b.installedUnits, expected) {
440+
t.Error(fmt.Errorf("Expected %v, Got %v", expected, b.installedUnits))
441+
}
442+
}
443+
427444
func TestInstallStatelessPlatform(t *testing.T) {
428445
t.Parallel()
429446

0 commit comments

Comments
 (0)