github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/leadership/interface.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package leadership 5 6 import ( 7 "time" 8 9 "github.com/juju/errors" 10 ) 11 12 // ErrClaimDenied is the error which will be returned when a 13 // leadership claim has been denied. 14 var ErrClaimDenied = errors.New("leadership claim denied") 15 16 // Claimer exposes leadership acquisition capabilities. 17 type Claimer interface { 18 19 // ClaimLeadership claims leadership of the named service on behalf of the 20 // named unit. If no error is returned, leadership will be guaranteed for 21 // at least the supplied duration from the point when the call was made. 22 ClaimLeadership(serviceId, unitId string, duration time.Duration) error 23 24 // BlockUntilLeadershipReleased blocks until the named service is known 25 // to have no leader, in which case it returns no error; or until the 26 // manager is stopped, in which case it will fail. 27 BlockUntilLeadershipReleased(serviceId string) (err error) 28 } 29 30 // Token represents a unit's leadership of its service. 31 // 32 // It seems to be generic enough (it could easily represent any fact) that it 33 // should find a more general home. 34 type Token interface { 35 36 // Check returns an error if the condition it embodies no longer holds. 37 // If you pass a non-nil value into Check, it must be a pointer to data 38 // of the correct type, into which the token's content will be copied. 39 // 40 // The "correct type" is implementation-specific, and no implementation 41 // is obliged to accept any non-nil parameter; but methods that return 42 // Tokens should explain whether, and how, they will expose their content. 43 // 44 // In practice, most Token implementations will likely expect *[]txn.Op, 45 // so that they can be used to gate mgo/txn-based state changes. 46 Check(interface{}) error 47 } 48 49 // Checker exposes leadership testing capabilities. 50 type Checker interface { 51 52 // LeadershipCheck returns a Token representing the supplied unit's 53 // service leadership. The existence of the token does not imply 54 // its accuracy; you need to Check() it. 55 // 56 // This method returns a token that accepts a *[]txn.Op, into which 57 // it will (on success) copy mgo/txn operations that can be used to 58 // verify the unit's continued leadership as part of another txn. 59 LeadershipCheck(serviceName, unitName string) Token 60 }