Skip to content

Commit 1543103

Browse files
mknyszekgopherbot
authored andcommitted
cmd/gomote: add -new-group flag to create
This flag creates a new group for the newly-created instances. For golang/go#53956. Change-Id: Ib65a6391a554dbeb1f6f0e44c286ad5b0d221757 Reviewed-on: https://go-review.googlesource.com/c/build/+/418302 Run-TryBot: Michael Knyszek <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Michael Knyszek <[email protected]> Reviewed-by: Carlos Amedee <[email protected]>
1 parent d44332d commit 1543103

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

cmd/gomote/create.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ func create(args []string) error {
164164
fs.IntVar(&count, "count", 1, "number of instances to create")
165165
var setup bool
166166
fs.BoolVar(&setup, "setup", false, "set up the instance by pushing GOROOT and building the Go toolchain")
167+
var newGroup string
168+
fs.StringVar(&newGroup, "new-group", "", "also create a new group and add the new instances to it")
167169

168170
fs.Parse(args)
169171
if fs.NArg() != 1 {
@@ -180,7 +182,15 @@ func create(args []string) error {
180182
}
181183
}
182184

183-
var activeGroupMu sync.Mutex
185+
var groupMu sync.Mutex
186+
group := activeGroup
187+
if newGroup != "" {
188+
group, err = doCreateGroup(newGroup)
189+
if err != nil {
190+
return err
191+
}
192+
}
193+
184194
eg, ctx := errgroup.WithContext(context.Background())
185195
client := gomoteServerClient(ctx)
186196
for i := 0; i < count; i++ {
@@ -207,10 +217,10 @@ func create(args []string) error {
207217
}
208218
}
209219
fmt.Println(inst)
210-
if activeGroup != nil {
211-
activeGroupMu.Lock()
212-
activeGroup.Instances = append(activeGroup.Instances, inst)
213-
activeGroupMu.Unlock()
220+
if group != nil {
221+
groupMu.Lock()
222+
group.Instances = append(group.Instances, inst)
223+
groupMu.Unlock()
214224
}
215225
if !setup {
216226
return nil
@@ -239,8 +249,8 @@ func create(args []string) error {
239249
if err := eg.Wait(); err != nil {
240250
return err
241251
}
242-
if activeGroup != nil {
243-
return storeGroup(activeGroup)
252+
if group != nil {
253+
return storeGroup(group)
244254
}
245255
return nil
246256
}

cmd/gomote/group.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ func createGroup(args []string) error {
5757
if len(args) != 1 {
5858
usage()
5959
}
60-
name := args[0]
60+
_, err := doCreateGroup(args[0])
61+
return err
62+
}
63+
64+
func doCreateGroup(name string) (*groupData, error) {
6165
if _, err := loadGroup(name); err == nil {
62-
return fmt.Errorf("group %q already exists", name)
66+
return nil, fmt.Errorf("group %q already exists", name)
6367
}
64-
if err := storeGroup(&groupData{
65-
Name: name,
66-
}); err != nil {
67-
return err
68-
}
69-
return nil
68+
g := &groupData{Name: name}
69+
return g, storeGroup(g)
7070
}
7171

7272
func destroyGroup(args []string) error {

0 commit comments

Comments
 (0)