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

Side by Side Diff: state/state.go

Issue 7554046: Add ServiceDestroyUnits to the API
Patch Set: Add ServiceDestroyUnits to the API Created 12 years 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 | « state/apiserver/apiserver.go ('k') | state/state_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"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 } 50 }
51 var doc toolsDoc 51 var doc toolsDoc
52 if err := raw.Unmarshal(&doc); err != nil { 52 if err := raw.Unmarshal(&doc); err != nil {
53 return err 53 return err
54 } 54 }
55 t.Binary = doc.Version 55 t.Binary = doc.Version
56 t.URL = doc.URL 56 t.URL = doc.URL
57 return nil 57 return nil
58 } 58 }
59 59
60 const serviceSnippet = "[a-z][a-z0-9]*(-[a-z0-9]*[a-z][a-z0-9]*)*"
61
60 var ( 62 var (
61 » validService = regexp.MustCompile("^[a-z][a-z0-9]*(-[a-z0-9]*[a-z][a-z0- 9]*)*$") 63 » validService = regexp.MustCompile("^" + serviceSnippet + "$")
62 » validUnit = regexp.MustCompile("^[a-z][a-z0-9]*(-[a-z0-9]*[a-z][a-z0- 9]*)*/[0-9]+$") 64 » validUnit = regexp.MustCompile("^" + serviceSnippet + "(-[a-z0-9]*[a- z][a-z0-9]*)*/[0-9]+$")
63 validMachine = regexp.MustCompile("^0$|^[1-9][0-9]*$") 65 validMachine = regexp.MustCompile("^0$|^[1-9][0-9]*$")
64 ) 66 )
65 67
66 // IsServiceName returns whether name is a valid service name. 68 // IsServiceName returns whether name is a valid service name.
67 func IsServiceName(name string) bool { 69 func IsServiceName(name string) bool {
68 return validService.MatchString(name) 70 return validService.MatchString(name)
69 } 71 }
70 72
71 // IsUnitName returns whether name is a valid unit name. 73 // IsUnitName returns whether name is a valid unit name.
72 func IsUnitName(name string) bool { 74 func IsUnitName(name string) bool {
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 }} 829 }}
828 if err := st.runner.Run(ops, "", nil); err != nil { 830 if err := st.runner.Run(ops, "", nil); err != nil {
829 return fmt.Errorf("cannot remove empty cleanup document: %v", err) 831 return fmt.Errorf("cannot remove empty cleanup document: %v", err)
830 } 832 }
831 } 833 }
832 if err := iter.Err(); err != nil { 834 if err := iter.Err(); err != nil {
833 return fmt.Errorf("cannot read cleanup document: %v", err) 835 return fmt.Errorf("cannot read cleanup document: %v", err)
834 } 836 }
835 return nil 837 return nil
836 } 838 }
OLDNEW
« no previous file with comments | « state/apiserver/apiserver.go ('k') | state/state_test.go » ('j') | no next file with comments »

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