On Sun, Aug 25, 2013 at 11:52 PM, Mike Sam <[email protected]> wrote:
> I have a question around how RelationList cmd works specially on a peer > relation. I have seen it that although you may deploy multiple units > together (with -n on deploy), the relationlist may not return all of the > deployed units on the first calls on its relation change hook. I am > guessing maybe the units who are not showing up have not processed their > join hook yet or something in that nature. > In narrow terms, there shouldn't be any significant differences in different kinds of relations: the set of units that join and depart depend on the relation kind, but everything I say below applies as much to provider/requirer relations as to peer relations. 1> What does relationlist actually return? Are they the relations set at > the deploy step? Are they the relations which have at least executed their > join hook? > Relation-list lists the remote units known to the local unit. This is determined purely by what hooks have been run locally: a remote unit becomes known when the local unit runs its -joined hook, and becomes unknown again after the local unit runs its -departed hook. The fact of a remote unit's presence in relation-list implies *nothing* about what relation hooks that unit may itself have run. > 2> How can you guarantee at relation change hook step that relationlist > can get a complete list of the units participating in the relation and have > already processed their join hook before processing their the > relation-changed hook? > You can't. But you *can* guarantee that each unit will eventually run a changed hook in which all remote units are known and all their settings are up to date. So if the charm you're developing needs (or is configured to need) N units, it would be reasonable to write a -changed hook that did the following: * if local settings (`relation-get $JUJU_UNIT_NAME`) are incomplete, fill them in (`relation-set key=value ...`) * if less than N-1 remote units are returned from relation-list, exit without error * collect the units' settings with relation-get; if any are incomplete, exit without error * configure the software to use the collected unit settings > 3> You need the above in situation where you need to do automatic master > election among your units. Any better way to do this without relationlist? > relation-list is the expected way to list known remote units. You may find https://juju.ubuntu.com/docs/authors-charms-in-action.html useful in building your mental model of what hooks run when. Cheers William
-- Juju-dev mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/juju-dev
