Skip to content

Commit 5158bd7

Browse files
committed
fix(deisctl): update mesos code to use io.Writer
The mesos start/stop/install code needed to change from using channels to io.Writers in order to compile.
1 parent 7ad2a47 commit 5158bd7

1 file changed

Lines changed: 56 additions & 76 deletions

File tree

deisctl/cmd/mesos.go

Lines changed: 56 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,90 +2,80 @@ package cmd
22

33
import (
44
"fmt"
5+
"io"
56
"sync"
6-
"time"
77

88
"github.com/deis/deis/deisctl/backend"
9-
"github.com/deis/deis/deisctl/utils"
9+
"github.com/deis/deis/pkg/prettyprint"
1010
)
1111

1212
// InstallMesos loads all Mesos units for StartMesos
1313
func InstallMesos(b backend.Backend) error {
1414

15-
outchan := make(chan string)
16-
errchan := make(chan error)
1715
var wg sync.WaitGroup
1816

19-
go printState(outchan, errchan, 500*time.Millisecond)
17+
io.WriteString(Stdout, prettyprint.DeisIfy("Installing Mesos..."))
2018

21-
outchan <- utils.DeisIfy("Installing Mesos...")
22-
23-
installMesosServices(b, &wg, outchan, errchan)
19+
installMesosServices(b, &wg, Stdout, Stderr)
2420

2521
wg.Wait()
26-
close(outchan)
2722

28-
fmt.Println("Done.")
29-
fmt.Println()
30-
fmt.Println("Please run `deisctl start mesos` to boot up Mesos.")
23+
fmt.Fprintln(Stdout, "Done.")
24+
fmt.Fprintln(Stdout, "")
25+
fmt.Fprintln(Stdout, "Please run `deisctl start mesos` to boot up Mesos.")
3126
return nil
3227
}
3328

34-
func installMesosServices(b backend.Backend, wg *sync.WaitGroup, outchan chan string, errchan chan error) {
29+
func installMesosServices(b backend.Backend, wg *sync.WaitGroup, out, err io.Writer) {
3530

36-
outchan <- fmt.Sprintf("Zookeeper...")
37-
b.Create([]string{"zookeeper"}, wg, outchan, errchan)
31+
fmt.Fprintln(out, "Zookeeper...")
32+
b.Create([]string{"zookeeper"}, wg, out, err)
3833
wg.Wait()
3934

40-
outchan <- fmt.Sprintf("Mesos Master...")
41-
b.Create([]string{"mesos-master"}, wg, outchan, errchan)
35+
fmt.Fprintln(out, "Mesos Master...")
36+
b.Create([]string{"mesos-master"}, wg, out, err)
4237
wg.Wait()
4338

44-
outchan <- fmt.Sprintf("Mesos Slave...")
45-
b.Create([]string{"mesos-slave"}, wg, outchan, errchan)
39+
fmt.Fprintln(out, "Mesos Slave...")
40+
b.Create([]string{"mesos-slave"}, wg, out, err)
4641
wg.Wait()
4742

48-
outchan <- fmt.Sprintf("Marathon Framework...")
49-
b.Create([]string{"mesos-marathon"}, wg, outchan, errchan)
43+
fmt.Fprintln(out, "Marathon Framework...")
44+
b.Create([]string{"mesos-marathon"}, wg, out, err)
5045
wg.Wait()
5146
}
5247

5348
// UninstallMesos unloads and uninstalls all Mesos component definitions
5449
func UninstallMesos(b backend.Backend) error {
5550

56-
outchan := make(chan string)
57-
errchan := make(chan error)
5851
var wg sync.WaitGroup
5952

60-
go printState(outchan, errchan, 500*time.Millisecond)
61-
62-
outchan <- utils.DeisIfy("Uninstalling Mesos...")
53+
io.WriteString(Stdout, prettyprint.DeisIfy("Uninstalling Mesos..."))
6354

64-
uninstallMesosServices(b, &wg, outchan, errchan)
55+
uninstallMesosServices(b, &wg, Stdout, Stderr)
6556

6657
wg.Wait()
67-
close(outchan)
6858

69-
fmt.Println("Done.")
59+
fmt.Fprintln(Stdout, "Done.")
7060
return nil
7161
}
7262

73-
func uninstallMesosServices(b backend.Backend, wg *sync.WaitGroup, outchan chan string, errchan chan error) error {
63+
func uninstallMesosServices(b backend.Backend, wg *sync.WaitGroup, out, err io.Writer) error {
7464

75-
outchan <- fmt.Sprintf("Marathon Framework...")
76-
b.Destroy([]string{"mesos-marathon"}, wg, outchan, errchan)
65+
fmt.Fprintln(out, "Marathon Framework...")
66+
b.Destroy([]string{"mesos-marathon"}, wg, out, err)
7767
wg.Wait()
7868

79-
outchan <- fmt.Sprintf("Mesos Slave...")
80-
b.Destroy([]string{"mesos-slave"}, wg, outchan, errchan)
69+
fmt.Fprintln(out, "Mesos Slave...")
70+
b.Destroy([]string{"mesos-slave"}, wg, out, err)
8171
wg.Wait()
8272

83-
outchan <- fmt.Sprintf("Mesos Master...")
84-
b.Destroy([]string{"mesos-master"}, wg, outchan, errchan)
73+
fmt.Fprintln(out, "Mesos Master...")
74+
b.Destroy([]string{"mesos-master"}, wg, out, err)
8575
wg.Wait()
8676

87-
outchan <- fmt.Sprintf("Zookeeper...")
88-
b.Destroy([]string{"zookeeper"}, wg, outchan, errchan)
77+
fmt.Fprintln(out, "Zookeeper...")
78+
b.Destroy([]string{"zookeeper"}, wg, out, err)
8979
wg.Wait()
9080

9181
return nil
@@ -94,81 +84,71 @@ func uninstallMesosServices(b backend.Backend, wg *sync.WaitGroup, outchan chan
9484
// StartMesos activates all Mesos components.
9585
func StartMesos(b backend.Backend) error {
9686

97-
outchan := make(chan string)
98-
errchan := make(chan error)
9987
var wg sync.WaitGroup
10088

101-
go printState(outchan, errchan, 500*time.Millisecond)
89+
io.WriteString(Stdout, prettyprint.DeisIfy("Starting Mesos..."))
10290

103-
outchan <- utils.DeisIfy("Starting Mesos...")
104-
105-
startMesosServices(b, &wg, outchan, errchan)
91+
startMesosServices(b, &wg, Stdout, Stderr)
10692

10793
wg.Wait()
108-
close(outchan)
10994

110-
fmt.Println("Done.")
111-
fmt.Println()
112-
fmt.Println("Please use `deisctl config controller set schedulerModule=mesos_marathon`")
95+
fmt.Fprintln(Stdout, "Done.")
96+
fmt.Fprintln(Stdout, "")
97+
fmt.Fprintln(Stdout, "Please use `deisctl config controller set schedulerModule=mesos_marathon`")
11398
return nil
11499
}
115100

116-
func startMesosServices(b backend.Backend, wg *sync.WaitGroup, outchan chan string, errchan chan error) {
101+
func startMesosServices(b backend.Backend, wg *sync.WaitGroup, out, err io.Writer) {
117102

118-
outchan <- fmt.Sprintf("Zookeeper...")
119-
b.Start([]string{"zookeeper"}, wg, outchan, errchan)
103+
fmt.Fprintln(out, "Zookeeper...")
104+
b.Start([]string{"zookeeper"}, wg, out, err)
120105
wg.Wait()
121106

122-
outchan <- fmt.Sprintf("Mesos Master...")
123-
b.Start([]string{"mesos-master"}, wg, outchan, errchan)
107+
fmt.Fprintln(out, "Mesos Master...")
108+
b.Start([]string{"mesos-master"}, wg, out, err)
124109
wg.Wait()
125110

126-
outchan <- fmt.Sprintf("Mesos Slave...")
127-
b.Start([]string{"mesos-slave"}, wg, outchan, errchan)
111+
fmt.Fprintln(out, "Mesos Slave...")
112+
b.Start([]string{"mesos-slave"}, wg, out, err)
128113
wg.Wait()
129114

130-
outchan <- fmt.Sprintf("Marathon Framework...")
131-
b.Start([]string{"mesos-marathon"}, wg, outchan, errchan)
115+
fmt.Fprintln(out, "Marathon Framework...")
116+
b.Start([]string{"mesos-marathon"}, wg, out, err)
132117
wg.Wait()
133118
}
134119

135120
// StopMesos deactivates all Mesos components.
136121
func StopMesos(b backend.Backend) error {
137122

138-
outchan := make(chan string)
139-
errchan := make(chan error)
140123
var wg sync.WaitGroup
141124

142-
go printState(outchan, errchan, 500*time.Millisecond)
143-
144-
outchan <- utils.DeisIfy("Stopping Mesos...")
125+
io.WriteString(Stdout, prettyprint.DeisIfy("Stopping Mesos..."))
145126

146-
stopMesosServices(b, &wg, outchan, errchan)
127+
stopMesosServices(b, &wg, Stdout, Stderr)
147128

148129
wg.Wait()
149-
close(outchan)
150130

151-
fmt.Println("Done.")
152-
fmt.Println()
153-
fmt.Println("Please run `deisctl start mesos` to restart Mesos.")
131+
fmt.Fprintln(Stdout, "Done.")
132+
fmt.Fprintln(Stdout, "")
133+
fmt.Fprintln(Stdout, "Please run `deisctl start mesos` to restart Mesos.")
154134
return nil
155135
}
156136

157-
func stopMesosServices(b backend.Backend, wg *sync.WaitGroup, outchan chan string, errchan chan error) {
137+
func stopMesosServices(b backend.Backend, wg *sync.WaitGroup, out, err io.Writer) {
158138

159-
outchan <- fmt.Sprintf("Marathon Framework...")
160-
b.Stop([]string{"mesos-marathon"}, wg, outchan, errchan)
139+
fmt.Fprintln(out, "Marathon Framwork...")
140+
b.Stop([]string{"mesos-marathon"}, wg, out, err)
161141
wg.Wait()
162142

163-
outchan <- fmt.Sprintf("Mesos Slave...")
164-
b.Stop([]string{"mesos-slave"}, wg, outchan, errchan)
143+
fmt.Fprintln(out, "Mesos Slave...")
144+
b.Stop([]string{"mesos-slave"}, wg, out, err)
165145
wg.Wait()
166146

167-
outchan <- fmt.Sprintf("Mesos Master...")
168-
b.Stop([]string{"mesos-master"}, wg, outchan, errchan)
147+
fmt.Fprintln(out, "Mesos Master...")
148+
b.Stop([]string{"mesos-master"}, wg, out, err)
169149
wg.Wait()
170150

171-
outchan <- fmt.Sprintf("Zookeeper...")
172-
b.Stop([]string{"zookeeper"}, wg, outchan, errchan)
151+
fmt.Fprintln(out, "Zookeeper...")
152+
b.Stop([]string{"zookeeper"}, wg, out, err)
173153
wg.Wait()
174154
}

0 commit comments

Comments
 (0)