Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(950)

Side by Side Diff: state/state.go

Issue 6573050: state: fix tools marshaling
Patch Set: state: fix tools marshaling Created 11 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « [revision details] ('k') | state/tools_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // The state package enables reading, observing, and changing 1 // The state package enables reading, observing, and changing
2 // the state stored in MongoDB of a whole environment 2 // the state stored in MongoDB of a whole environment
3 // managed by juju. 3 // managed by juju.
4 package state 4 package state
5 5
6 import ( 6 import (
7 "fmt" 7 "fmt"
8 "labix.org/v2/mgo" 8 "labix.org/v2/mgo"
9 "labix.org/v2/mgo/bson" 9 "labix.org/v2/mgo/bson"
10 "labix.org/v2/mgo/txn" 10 "labix.org/v2/mgo/txn"
11 "launchpad.net/juju-core/charm" 11 "launchpad.net/juju-core/charm"
12 "launchpad.net/juju-core/environs/config" 12 "launchpad.net/juju-core/environs/config"
13 "launchpad.net/juju-core/state/presence" 13 "launchpad.net/juju-core/state/presence"
14 "launchpad.net/juju-core/state/watcher" 14 "launchpad.net/juju-core/state/watcher"
15 "launchpad.net/juju-core/trivial" 15 "launchpad.net/juju-core/trivial"
16 "launchpad.net/juju-core/version" 16 "launchpad.net/juju-core/version"
17 "net/url" 17 "net/url"
18 "regexp" 18 "regexp"
19 ) 19 )
20 20
21 // TODO(niemeyer): This must not be exported.
21 type D []bson.DocElem 22 type D []bson.DocElem
22 23
23 // Tools describes a particular set of juju tools and where to find them. 24 // Tools describes a particular set of juju tools and where to find them.
24 type Tools struct { 25 type Tools struct {
25 version.Binary 26 version.Binary
26 URL string 27 URL string
27 } 28 }
28 29
30 type toolsDoc struct {
31 Version version.Binary
32 URL string
33 }
34
35 func (t *Tools) GetBSON() (interface{}, error) {
36 return &toolsDoc{t.Binary, t.URL}, nil
37 }
38
39 func (t *Tools) SetBSON(raw bson.Raw) error {
40 var doc toolsDoc
41 if err := raw.Unmarshal(&doc); err != nil {
42 return err
43 }
44 t.Binary = doc.Version
45 t.URL = doc.URL
46 return nil
47 }
48
29 var ( 49 var (
30 validService = regexp.MustCompile("^[a-z][a-z0-9]*(-[a-z0-9]*[a-z][a-z0- 9]*)*$") 50 validService = regexp.MustCompile("^[a-z][a-z0-9]*(-[a-z0-9]*[a-z][a-z0- 9]*)*$")
31 validUnit = regexp.MustCompile("^[a-z][a-z0-9]*(-[a-z0-9]*[a-z][a-z0- 9]*)*/[0-9]+$") 51 validUnit = regexp.MustCompile("^[a-z][a-z0-9]*(-[a-z0-9]*[a-z][a-z0- 9]*)*/[0-9]+$")
32 ) 52 )
33 53
34 // IsServiceName returns whether name is a valid service name. 54 // IsServiceName returns whether name is a valid service name.
35 func IsServiceName(name string) bool { 55 func IsServiceName(name string) bool {
36 return validService.MatchString(name) 56 return validService.MatchString(name)
37 } 57 }
38 58
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 s.watcher.StartSync() 496 s.watcher.StartSync()
477 s.pwatcher.StartSync() 497 s.pwatcher.StartSync()
478 } 498 }
479 499
480 // Sync forces watchers to resynchronize their state with the 500 // Sync forces watchers to resynchronize their state with the
481 // database immediately, and waits until all events are known. 501 // database immediately, and waits until all events are known.
482 func (s *State) Sync() { 502 func (s *State) Sync() {
483 s.watcher.Sync() 503 s.watcher.Sync()
484 s.pwatcher.Sync() 504 s.pwatcher.Sync()
485 } 505 }
OLDNEW
« no previous file with comments | « [revision details] ('k') | state/tools_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b