Skip to content
This repository was archived by the owner on Jul 28, 2020. It is now read-only.

Commit 8ff7edc

Browse files
Anthony Emengojoaopapereira
authored andcommitted
Move provision methods to appropriately-names files
Signed-off-by: Joao Pereira <[email protected]>
1 parent ee49da8 commit 8ff7edc

File tree

5 files changed

+182
-319
lines changed

5 files changed

+182
-319
lines changed

provision/controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ import (
44
"code.cloudfoundry.org/cfdev/config"
55
"context"
66
"github.com/aemengo/bosh-runc-cpi/client"
7+
"io"
78
)
89

10+
type UI interface {
11+
Say(message string, args ...interface{})
12+
Writer() io.Writer
13+
}
14+
915
type Controller struct {
1016
Config config.Config
1117
}

provision/progress.go

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,13 @@
11
package provision
22

33
import (
4-
e "errors"
54
"fmt"
6-
"io"
7-
"strings"
85
"time"
96

107
"code.cloudfoundry.org/cfdev/bosh"
118
"code.cloudfoundry.org/cfdev/errors"
129
)
1310

14-
type UI interface {
15-
Say(message string, args ...interface{})
16-
Writer() io.Writer
17-
}
18-
19-
func (c *Controller) WhiteListServices(whiteList string, services []Service) ([]Service, error) {
20-
if services == nil {
21-
return nil, e.New("Error whitelisting services")
22-
}
23-
24-
if strings.ToLower(whiteList) == "all" {
25-
return services, nil
26-
}
27-
28-
var whiteListed []Service
29-
30-
if whiteList == "none" {
31-
for _, service := range services {
32-
if service.Flagname == "always-include" {
33-
whiteListed = append(whiteListed, service)
34-
}
35-
}
36-
37-
return whiteListed, nil
38-
}
39-
40-
if whiteList == "" {
41-
for _, service := range services {
42-
if service.DefaultDeploy {
43-
whiteListed = append(whiteListed, service)
44-
}
45-
}
46-
47-
return whiteListed, nil
48-
}
49-
50-
for _, service := range services {
51-
if (strings.ToLower(whiteList) == strings.ToLower(service.Flagname)) || (strings.ToLower(service.Flagname) == "always-include") {
52-
whiteListed = append(whiteListed, service)
53-
}
54-
}
55-
56-
return whiteListed, nil
57-
}
58-
59-
func (c *Controller) DeployServices(ui UI, services []Service) error {
60-
b, err := bosh.New(c.Config)
61-
if err != nil {
62-
return err
63-
}
64-
65-
errChan := make(chan error, 1)
66-
67-
for _, service := range services {
68-
start := time.Now()
69-
70-
ui.Say("Deploying %s...", service.Name)
71-
72-
go func(handle string, serviceManifest string) {
73-
errChan <- c.DeployService(service)
74-
}(service.Handle, service.Script)
75-
76-
err = c.report(start, ui, b, service, errChan)
77-
if err != nil {
78-
return err
79-
}
80-
}
81-
82-
return nil
83-
}
84-
8511
func (c *Controller) report(start time.Time, ui UI, b *bosh.Bosh, service Service, errChan chan error) error {
8612
ticker := time.NewTicker(time.Second)
8713

provision/progress_test.go

Lines changed: 0 additions & 105 deletions
This file was deleted.

provision/services.go

Lines changed: 79 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,91 @@ package provision
22

33
import (
44
"code.cloudfoundry.org/cfdev/bosh"
5+
"errors"
56
"os"
67
"os/exec"
78
"path/filepath"
89
"runtime"
910
"strings"
11+
"time"
1012
)
1113

14+
type Service struct {
15+
Name string `yaml:"name"`
16+
Flagname string `yaml:"flag_name"`
17+
DefaultDeploy bool `yaml:"default_deploy"`
18+
Handle string `yaml:"handle"` //TODO <-- remove
19+
Script string `yaml:"script"`
20+
Deployment string `yaml:"deployment"`
21+
IsErrand bool `yaml:"errand"`
22+
}
23+
24+
func (c *Controller) WhiteListServices(whiteList string, services []Service) ([]Service, error) {
25+
if services == nil {
26+
return nil, errors.New("Error whitelisting services")
27+
}
28+
29+
if strings.ToLower(whiteList) == "all" {
30+
return services, nil
31+
}
32+
33+
var whiteListed []Service
34+
35+
if whiteList == "none" {
36+
for _, service := range services {
37+
if service.Flagname == "always-include" {
38+
whiteListed = append(whiteListed, service)
39+
}
40+
}
41+
42+
return whiteListed, nil
43+
}
44+
45+
if whiteList == "" {
46+
for _, service := range services {
47+
if service.DefaultDeploy {
48+
whiteListed = append(whiteListed, service)
49+
}
50+
}
51+
52+
return whiteListed, nil
53+
}
54+
55+
for _, service := range services {
56+
if (strings.ToLower(whiteList) == strings.ToLower(service.Flagname)) || (strings.ToLower(service.Flagname) == "always-include") {
57+
whiteListed = append(whiteListed, service)
58+
}
59+
}
60+
61+
return whiteListed, nil
62+
}
63+
64+
func (c *Controller) DeployServices(ui UI, services []Service) error {
65+
b, err := bosh.New(c.Config)
66+
if err != nil {
67+
return err
68+
}
69+
70+
errChan := make(chan error, 1)
71+
72+
for _, service := range services {
73+
start := time.Now()
74+
75+
ui.Say("Deploying %s...", service.Name)
76+
77+
go func(handle string, serviceManifest string) {
78+
errChan <- c.DeployService(service)
79+
}(service.Handle, service.Script)
80+
81+
err = c.report(start, ui, b, service, errChan)
82+
if err != nil {
83+
return err
84+
}
85+
}
86+
87+
return nil
88+
}
89+
1290
func (c *Controller) DeployService(service Service) error {
1391
var cmd *exec.Cmd
1492

@@ -31,14 +109,4 @@ func (c *Controller) DeployService(service Service) error {
31109
cmd.Stderr = logFile
32110

33111
return cmd.Run()
34-
}
35-
36-
type Service struct {
37-
Name string `yaml:"name"`
38-
Flagname string `yaml:"flag_name"`
39-
DefaultDeploy bool `yaml:"default_deploy"`
40-
Handle string `yaml:"handle"` //TODO <-- remove
41-
Script string `yaml:"script"`
42-
Deployment string `yaml:"deployment"`
43-
IsErrand bool `yaml:"errand"`
44-
}
112+
}

0 commit comments

Comments
 (0)