Do states have namespace?

Marco Ceppi marco.ceppi at canonical.com
Tue Apr 18 13:30:21 UTC 2017


On Tue, Apr 18, 2017 at 8:57 AM Alex Kavanagh <alex.kavanagh at canonical.com>
wrote:

> Hi
>
>
> On Tue, Apr 18, 2017 at 1:50 PM, fengxia <fxia1 at lenovo.com> wrote:
>
>> I did a quick experiment:
>>
>> 1. Created two layers in one charm, each layer has a few states,
>> set_state() can trigger @when defined in other layers.
>>
>> 2. Use the same set of states, now splitting them in two charms => @when
>> don't trigger anymore.
>>
>> So does this mean states have a namespace by the charm it belongs?
>
>
> States are stored on the individual instance of the charm.  They are
> private and no other charm can see those states.
>

More directly, states are private per unit of a charm. Layers namespace by
convention rather than implicitly. For example, layer foo should set states
as follows:

set_state('foo.state-name')

That state, as you've seen, can be responded to by any other layer in that
charm, in that deployed unit. As such, if you have two units of charm bar,
bar/0 can not see or set states for bar/1 and vice versa.

If you need to transfer state between charms, that's what Juju Relations
are for. They provide the ability to transfer key/vals between one or more
connected item:
https://jujucharms.com/docs/stable/developer-layers-interfaces

Thanks,
Marco Ceppi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/juju/attachments/20170418/38062e63/attachment.html>


More information about the Juju mailing list