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

Side by Side Diff: state/unit.go

Issue 6814108: state, machiner: new style principal units watcher
Patch Set: state, machiner: new style principal units watcher Created 12 years, 4 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
OLDNEW
1 package state 1 package state
2 2
3 import ( 3 import (
4 "errors" 4 "errors"
5 "fmt" 5 "fmt"
6 "labix.org/v2/mgo" 6 "labix.org/v2/mgo"
7 "labix.org/v2/mgo/txn" 7 "labix.org/v2/mgo/txn"
8 "launchpad.net/juju-core/charm" 8 "launchpad.net/juju-core/charm"
9 "launchpad.net/juju-core/state/presence" 9 "launchpad.net/juju-core/state/presence"
10 "launchpad.net/juju-core/trivial" 10 "launchpad.net/juju-core/trivial"
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 // It returns the started pinger. 397 // It returns the started pinger.
398 func (u *Unit) SetAgentAlive() (*presence.Pinger, error) { 398 func (u *Unit) SetAgentAlive() (*presence.Pinger, error) {
399 p := presence.NewPinger(u.st.presence, u.globalKey()) 399 p := presence.NewPinger(u.st.presence, u.globalKey())
400 err := p.Start() 400 err := p.Start()
401 if err != nil { 401 if err != nil {
402 return nil, err 402 return nil, err
403 } 403 }
404 return p, nil 404 return p, nil
405 } 405 }
406 406
407 // IsAssignedTo returns whether u is a principal assigned to machine m.
408 // It panics if u is not a principal unit.
409 func (u *Unit) IsAssignedTo(m *Machine) bool {
rog 2012/11/09 09:08:08 is this necessary? can't we just use AssignedMachi
aram 2012/11/09 16:50:08 It was impossible to use the previous version of A
410 if !u.IsPrincipal() {
411 panic("unit is not a principal")
412 }
413 return u.doc.MachineId != nil && *u.doc.MachineId == m.doc.Id
414 }
415
407 // AssignedMachineId returns the id of the assigned machine. 416 // AssignedMachineId returns the id of the assigned machine.
408 func (u *Unit) AssignedMachineId() (id int, err error) { 417 func (u *Unit) AssignedMachineId() (id int, err error) {
409 defer trivial.ErrorContextf(&err, "cannot get machine id of unit %q", u) 418 defer trivial.ErrorContextf(&err, "cannot get machine id of unit %q", u)
410 if u.IsPrincipal() { 419 if u.IsPrincipal() {
411 if u.doc.MachineId == nil { 420 if u.doc.MachineId == nil {
412 return 0, errors.New("unit not assigned to machine") 421 return 0, errors.New("unit not assigned to machine")
413 } 422 }
414 return *u.doc.MachineId, nil 423 return *u.doc.MachineId, nil
415 } 424 }
416 pudoc := unitDoc{} 425 pudoc := unitDoc{}
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 return p1.Protocol < p2.Protocol 665 return p1.Protocol < p2.Protocol
657 } 666 }
658 return p1.Number < p2.Number 667 return p1.Number < p2.Number
659 } 668 }
660 669
661 // SortPorts sorts the given ports, first by protocol, 670 // SortPorts sorts the given ports, first by protocol,
662 // then by number. 671 // then by number.
663 func SortPorts(ports []Port) { 672 func SortPorts(ports []Port) {
664 sort.Sort(portSlice(ports)) 673 sort.Sort(portSlice(ports))
665 } 674 }
OLDNEW

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