Permalink
Browse files

Reduce public constant footprint

  • Loading branch information...
1 parent 3010f4a commit 68c1da5a13c370617f96e7371cdd6e1a4c4b4d8a @cloudhead cloudhead committed Sep 6, 2012
Showing with 70 additions and 71 deletions.
  1. +7 −8 app.go
  2. +2 −2 app_test.go
  3. +2 −2 conn_test.go
  4. +4 −4 endpoint.go
  5. +1 −1 endpoint_test.go
  6. +1 −1 event_test.go
  7. +1 −1 file_test.go
  8. +3 −3 instance.go
  9. +1 −1 instance_test.go
  10. +4 −4 proctype.go
  11. +1 −1 proctype_test.go
  12. +3 −3 revision.go
  13. +1 −1 revision_test.go
  14. +5 −5 service.go
  15. +2 −2 service_test.go
  16. +5 −5 snapshot.go
  17. +1 −1 snapshot_test.go
  18. +5 −5 ticket.go
  19. +1 −1 ticket_test.go
  20. +14 −14 visor.go
  21. +6 −6 visor_test.go
View
15 app.go
@@ -12,9 +12,8 @@ import (
"time"
)
-const APPS_PATH = "apps"
-const DEPLOY_LXC = "lxc"
-const SERVICE_PROC_DEFAULT = "web"
+const appsPath = "apps"
+const DeployLXC = "lxc"
type Env map[string]string
@@ -30,7 +29,7 @@ type App struct {
// NewApp returns a new App given a name, repository url and stack.
func NewApp(name string, repourl string, stack Stack, snapshot Snapshot) (app *App) {
app = &App{Name: name, RepoUrl: repourl, Stack: stack, Env: Env{}}
- app.dir = dir{snapshot, path.Join(APPS_PATH, app.Name)}
+ app.dir = dir{snapshot, path.Join(appsPath, app.Name)}
return
}
@@ -58,7 +57,7 @@ func (a *App) Register() (app *App, err error) {
}
if a.DeployType == "" {
- a.DeployType = DEPLOY_LXC
+ a.DeployType = DeployLXC
}
attrs := &file{
@@ -164,7 +163,7 @@ func (a *App) DelEnvironmentVar(k string) (app *App, err error) {
// GetProcTypes returns all registered ProcTypes for the App
func (a *App) GetProcTypes() (ptys []*ProcType, err error) {
- p := a.dir.prefix(PROCS_PATH)
+ p := a.dir.prefix(procsPath)
exists, _, err := a.conn.Exists(p)
if err != nil || !exists {
@@ -218,12 +217,12 @@ func GetApp(s Snapshot, name string) (app *App, err error) {
// Apps returns the list of all registered Apps.
func Apps(s Snapshot) (apps []*App, err error) {
- exists, _, err := s.conn.Exists(APPS_PATH)
+ exists, _, err := s.conn.Exists(appsPath)
if err != nil || !exists {
return
}
- names, err := s.FastForward(-1).getdir(APPS_PATH)
+ names, err := s.FastForward(-1).getdir(appsPath)
if err != nil {
return
}
View
@@ -10,7 +10,7 @@ import (
)
func appSetup(name string) (app *App) {
- s, err := Dial(DEFAULT_ADDR, DEFAULT_ROOT)
+ s, err := Dial(DefaultAddr, DefaultRoot)
if err != nil {
panic(err)
}
@@ -223,7 +223,7 @@ func TestApps(t *testing.T) {
}
app = app.FastForward(-1)
- s, _ := Dial(DEFAULT_ADDR, DEFAULT_ROOT)
+ s, _ := Dial(DefaultAddr, DefaultRoot)
apps, err := Apps(s)
if err != nil {
View
@@ -8,7 +8,7 @@ package visor
import "testing"
func connSetup() (*conn, int64) {
- s, err := Dial(DEFAULT_ADDR, "/conn-test")
+ s, err := Dial(DefaultAddr, "/conn-test")
if err != nil {
panic(err)
}
@@ -25,7 +25,7 @@ func connSetup() (*conn, int64) {
func TestConnDifferentRoot(t *testing.T) {
body := "test"
- s, _ := Dial(DEFAULT_ADDR, "/not-conn-test")
+ s, _ := Dial(DefaultAddr, "/not-conn-test")
_, err := s.conn.Set("root", s.Rev, []byte(body))
if err != nil {
View
@@ -11,7 +11,7 @@ import (
"strconv"
)
-const ENDPOINTS_PATH = "endpoints"
+const endpointsPath = "endpoints"
// Endpoint represents an entry of a Service and supports all fields to be used
// as SRV record.
@@ -27,7 +27,7 @@ type Endpoint struct {
func NewEndpoint(srv *Service, addr string, s Snapshot) (e *Endpoint) {
e = &Endpoint{Addr: addr, Target: addr}
- e.dir = dir{s, srv.dir.prefix(ENDPOINTS_PATH, addr)}
+ e.dir = dir{s, srv.dir.prefix(endpointsPath, addr)}
return
}
@@ -91,7 +91,7 @@ func (e *Endpoint) Inspect() string {
// GetEndpoint fetches the endpoint for the given service and addr from the global
// registry.
func GetEndpoint(s Snapshot, srv *Service, addr string) (e *Endpoint, err error) {
- path := srv.dir.prefix(ENDPOINTS_PATH, addr)
+ path := srv.dir.prefix(endpointsPath, addr)
f, err := s.getFile(path, new(ListCodec))
if err != nil {
@@ -100,7 +100,7 @@ func GetEndpoint(s Snapshot, srv *Service, addr string) (e *Endpoint, err error)
data := f.Value.([]string)
e = &Endpoint{Addr: addr}
- e.dir = dir{s, srv.dir.prefix(ENDPOINTS_PATH, addr)}
+ e.dir = dir{s, srv.dir.prefix(endpointsPath, addr)}
p, err := strconv.ParseInt(data[0], 10, 0)
if err != nil {
View
@@ -10,7 +10,7 @@ import (
)
func endpointSetup(srvName string) (s Snapshot, srv *Service) {
- s, err := Dial(DEFAULT_ADDR, "/endpoint-test")
+ s, err := Dial(DefaultAddr, "/endpoint-test")
if err != nil {
panic(err)
}
View
@@ -11,7 +11,7 @@ import (
)
func eventSetup() (s Snapshot, l chan *Event) {
- s, err := Dial(DEFAULT_ADDR, "/event-test")
+ s, err := Dial(DefaultAddr, "/event-test")
if err != nil {
panic(err)
}
View
@@ -10,7 +10,7 @@ import (
)
func fileSetup(path string, value interface{}) *file {
- s, err := Dial(DEFAULT_ADDR, "/file-test")
+ s, err := Dial(DefaultAddr, "/file-test")
if err != nil {
panic(err)
}
View
@@ -22,7 +22,7 @@ const (
InsStateExited = "exited"
)
-const INSTANCES_PATH = "instances"
+const instancesPath = "instances"
// An Instance represents a running process of a specific type.
type Instance struct {
@@ -72,7 +72,7 @@ func (i *Instance) createSnapshot(rev int64) snapshotable {
}
func (i *Instance) proctypePath() string {
- return path.Join(APPS_PATH, i.AppName, PROCS_PATH, string(i.ProcessName), INSTANCES_PATH, i.Id())
+ return path.Join(appsPath, i.AppName, procsPath, string(i.ProcessName), instancesPath, i.Id())
}
// Register registers an instance with the registry.
@@ -152,7 +152,7 @@ func (i *Instance) LogString() string {
// GetInstance returns an Instance from the given app, rev, proc and instance ids.
func GetInstance(s Snapshot, insName string) (ins *Instance, err error) {
- p := path.Join(INSTANCES_PATH, insName)
+ p := path.Join(instancesPath, insName)
state, _, err := s.conn.Get(p+"/state", nil)
if err != nil {
View
@@ -10,7 +10,7 @@ import (
)
func instanceSetup(addr string, pType ProcessName) (ins *Instance) {
- s, err := Dial(DEFAULT_ADDR, "/instance-test")
+ s, err := Dial(DefaultAddr, "/instance-test")
if err != nil {
panic(err)
}
View
@@ -19,14 +19,14 @@ type ProcType struct {
Port int
}
-const PROCS_PATH = "procs"
+const procsPath = "procs"
func NewProcType(app *App, name ProcessName, s Snapshot) *ProcType {
return &ProcType{
Name: name,
App: app,
dir: dir{
- s, app.dir.prefix(PROCS_PATH, string(name)),
+ s, app.dir.prefix(procsPath, string(name)),
},
}
}
@@ -81,7 +81,7 @@ func (p *ProcType) Unregister() (err error) {
}
func (p *ProcType) instancesPath() string {
- return p.dir.prefix(INSTANCES_PATH)
+ return p.dir.prefix(instancesPath)
}
func (p *ProcType) GetInstanceNames() (ins []string, err error) {
@@ -120,7 +120,7 @@ func (p *ProcType) GetInstances() (ins []*Instance, err error) {
// GetProcType fetches a ProcType from the coordinator
func GetProcType(s Snapshot, app *App, name ProcessName) (p *ProcType, err error) {
- path := app.dir.prefix(PROCS_PATH, string(name))
+ path := app.dir.prefix(procsPath, string(name))
port, err := s.getFile(path+"/port", new(IntCodec))
if err != nil {
View
@@ -10,7 +10,7 @@ import (
)
func proctypeSetup(ref string) (s Snapshot, app *App) {
- s, err := Dial(DEFAULT_ADDR, "/proctype-test")
+ s, err := Dial(DefaultAddr, "/proctype-test")
if err != nil {
panic(err)
}
View
@@ -19,12 +19,12 @@ type Revision struct {
ArchiveUrl string
}
-const REVS_PATH = "revs"
+const revsPath = "revs"
// NewRevision returns a new instance of Revision.
func NewRevision(app *App, ref string, snapshot Snapshot) (rev *Revision) {
rev = &Revision{App: app, Ref: ref}
- rev.dir = dir{snapshot, app.dir.prefix(REVS_PATH, ref)}
+ rev.dir = dir{snapshot, app.dir.prefix(revsPath, ref)}
return
}
@@ -88,7 +88,7 @@ func (r *Revision) Inspect() string {
}
func GetRevision(s Snapshot, app *App, ref string) (r *Revision, err error) {
- path := app.dir.prefix(REVS_PATH, ref)
+ path := app.dir.prefix(revsPath, ref)
codec := new(StringCodec)
f, err := s.getFile(path+"/archive-url", codec)
View
@@ -10,7 +10,7 @@ import (
)
func revSetup() (s Snapshot, app *App) {
- s, err := Dial(DEFAULT_ADDR, "/revision-test")
+ s, err := Dial(DefaultAddr, "/revision-test")
if err != nil {
panic(err)
}
View
@@ -11,7 +11,7 @@ import (
"time"
)
-const SERVICES_PATH = "services"
+const servicesPath = "services"
type Service struct {
dir
@@ -21,7 +21,7 @@ type Service struct {
// NewService returns a new Service given a name.
func NewService(name string, snapshot Snapshot) (srv *Service) {
srv = &Service{Name: name}
- srv.dir = dir{snapshot, path.Join(SERVICES_PATH, srv.Name)}
+ srv.dir = dir{snapshot, path.Join(servicesPath, srv.Name)}
return
}
@@ -72,7 +72,7 @@ func (s *Service) Inspect() string {
}
func (s *Service) GetEndpoints() (endpoints []*Endpoint, err error) {
- p := s.dir.prefix(ENDPOINTS_PATH)
+ p := s.dir.prefix(endpointsPath)
exists, _, err := s.conn.Exists(p)
if err != nil || !exists {
@@ -112,12 +112,12 @@ func GetService(s Snapshot, name string) (srv *Service, err error) {
// Services returns the list of all registered Services.
func Services(s Snapshot) (srvs []*Service, err error) {
- exists, _, err := s.conn.Exists(SERVICES_PATH)
+ exists, _, err := s.conn.Exists(servicesPath)
if err != nil || !exists {
return
}
- names, err := s.getdir(SERVICES_PATH)
+ names, err := s.getdir(servicesPath)
if err != nil {
return
}
View
@@ -10,13 +10,13 @@ import (
)
func serviceSetup(name string) (srv *Service) {
- s, err := Dial(DEFAULT_ADDR, "/service-test")
+ s, err := Dial(DefaultAddr, "/service-test")
if err != nil {
panic(err)
}
r, _ := s.conn.Rev()
- err = s.conn.Del(SERVICES_PATH, r)
+ err = s.conn.Del(servicesPath, r)
rev, err := Init(s)
if err != nil {
panic(err)
View
@@ -67,7 +67,7 @@ func (s Snapshot) GetScale(app string, revision string, processName string) (sca
// A scale of `0` will be returned if any of the path components are missing.
// This is to avoid having to set the /apps/<app>/revs/<rev>/scale/<proc> paths to 0
// when registering revisions.
- path := path.Join(APPS_PATH, app, REVS_PATH, revision, SCALE_PATH, processName)
+ path := path.Join(appsPath, app, revsPath, revision, scalePath, processName)
f, err := s.getFile(path, new(IntCodec))
// File doesn't exist, assume scale = 0
@@ -90,23 +90,23 @@ func (s Snapshot) GetScale(app string, revision string, processName string) (sca
// SetScale sets the scale of an app:proc@rev tuple to the specified value.
func (s Snapshot) SetScale(app string, revision string, processName string, factor int) (s1 Snapshot, err error) {
- path := path.Join(APPS_PATH, app, REVS_PATH, revision, SCALE_PATH, processName)
+ path := path.Join(appsPath, app, revsPath, revision, scalePath, processName)
return s.set(path, strconv.Itoa(factor))
}
// GetProxies gets the list of bazooka-proxy service IPs
func (s Snapshot) GetProxies() ([]string, error) {
- return s.getdir(PROXY_DIR)
+ return s.getdir(proxyDir)
}
// GetPms gets the list of bazooka-pm service IPs
func (s Snapshot) GetPms() ([]string, error) {
- return s.getdir(PM_DIR)
+ return s.getdir(pmDir)
}
// Getuid returns a unique ID from the coordinator
func Getuid(s Snapshot) (int64, error) {
- return s.conn.Set(UID_PATH, -1, []byte{})
+ return s.conn.Set(uidPath, -1, []byte{})
}
// exists checks if the specified path exists at this snapshot's revision
View
@@ -10,7 +10,7 @@ import (
)
func snapshotSetup() (s Snapshot) {
- s, err := Dial(DEFAULT_ADDR, "/snapshot-test")
+ s, err := Dial(DefaultAddr, "/snapshot-test")
if err != nil {
panic(err)
}
Oops, something went wrong.

0 comments on commit 68c1da5

Please sign in to comment.