Skip to content

Commit 18ebc77

Browse files
author
ljalbertsimard
committed
feat(deisctl): specify # of routers to install
1 parent d332f73 commit 18ebc77

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"
@@ -109,7 +110,7 @@ Examples:
109110
// Install loads the definitions of components from local unit files.
110111
// After Install, the components will be available to Start.
111112
func (c *Client) Install(argv []string) error {
112-
usage := `Loads the definitions of components from local unit files.
113+
usage := fmt.Sprintf(`Loads the definitions of components from local unit files.
113114
114115
After install, the components will be available to start.
115116
@@ -120,13 +121,24 @@ After install, the components will be available to start.
120121
121122
Usage:
122123
deisctl install [<target>...] [options]
123-
`
124+
125+
Options:
126+
--router-mesh-size=<num> Number of routers to be loaded when installing the platform [default: %d].
127+
`, cmd.DefaultRouterMeshSize)
124128
// parse command-line arguments
125129
args, err := docopt.Parse(usage, argv, true, "", false)
126130
if err != nil {
127131
return err
128132
}
129133

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

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 {
@@ -316,11 +321,19 @@ func installDefaultServices(b backend.Backend, stateless bool, wg *sync.WaitGrou
316321
wg.Wait()
317322

318323
fmt.Fprintln(out, "Routing mesh...")
319-
b.Create([]string{"router@1", "router@2", "router@3"}, wg, out, err)
324+
b.Create(getRouters(), wg, out, err)
320325
wg.Wait()
321326

322327
}
323328

329+
func getRouters() []string {
330+
routers := make([]string, RouterMeshSize)
331+
for i := uint8(0); i < RouterMeshSize; i++ {
332+
routers[i] = fmt.Sprintf("router@%d", i+1)
333+
}
334+
return routers
335+
}
336+
324337
// Uninstall unloads the definitions of the specified components.
325338
// After Uninstall, the components will be unavailable until Install is called.
326339
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
@@ -423,6 +423,23 @@ func TestInstallPlatform(t *testing.T) {
423423
}
424424
}
425425

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

0 commit comments

Comments
 (0)