Do states have namespace?

2017-04-18 Thread fengxia

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?

--
Feng xia
Engineer
Lenovo USA

Phone: 5088011794
fx...@lenovo.com

Lenovo.com
Twitter | Facebook | Instagram | Blogs | Forums


--
Juju mailing list
Juju@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/juju


Re: Do states have namespace?

2017-04-18 Thread Alex Kavanagh
Hi


On Tue, Apr 18, 2017 at 1:50 PM, fengxia  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.

Cheers
Alex.


>
>
> --
> Feng xia
> Engineer
> Lenovo USA
>
> Phone: 5088011794
> fx...@lenovo.com
>
> Lenovo.com
> Twitter | Facebook | Instagram | Blogs | Forums
>
>
> --
> Juju mailing list
> Juju@lists.ubuntu.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailm
> an/listinfo/juju
>



-- 
Alex Kavanagh - Software Engineer
Cloud Dev Ops - Solutions & Product Engineering - Canonical Ltd
-- 
Juju mailing list
Juju@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/juju


Re: Do states have namespace?

2017-04-18 Thread Marco Ceppi
On Tue, Apr 18, 2017 at 8:57 AM Alex Kavanagh 
wrote:

> Hi
>
>
> On Tue, Apr 18, 2017 at 1:50 PM, fengxia  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
-- 
Juju mailing list
Juju@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/juju


Re: Do states have namespace?

2017-04-18 Thread fengxia

Replying my own question:

charmhelpers.core.unitdata shows how states are stored -- 
"reactive.state.xyz" is saved in a sqlite3 as a string. So if split 
states in multiple charms, I think it will still work if deploying these 
charms to the same unit because they will be registered in the same DB.


Can someone verify this?

On 04/18/2017 08:50 AM, fengxia 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?



--
Feng xia
Engineer
Lenovo USA

Phone: 5088011794
fx...@lenovo.com

Lenovo.com
Twitter | Facebook | Instagram | Blogs | Forums


--
Juju mailing list
Juju@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/juju


Re: Do states have namespace?

2017-04-18 Thread Marco Ceppi
No, because it's a sqlitedb per unit of charm. So a charm collocated on the
same machine will still have its own state.

Can I ask what you're looking to achieve?

Marco

On Tue, Apr 18, 2017, 10:05 fengxia  wrote:

> Replying my own question:
>
> charmhelpers.core.unitdata shows how states are stored --
> "reactive.state.xyz" is saved in a sqlite3 as a string. So if split
> states in multiple charms, I think it will still work if deploying these
> charms to the same unit because they will be registered in the same DB.
>
> Can someone verify this?
>
> On 04/18/2017 08:50 AM, fengxia 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?
> >
>
> --
> Feng xia
> Engineer
> Lenovo USA
>
> Phone: 5088011794
> fx...@lenovo.com
>
> Lenovo.com
> Twitter | Facebook | Instagram | Blogs | Forums
>
>
> --
> Juju mailing list
> Juju@lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/juju
>
-- 
Juju mailing list
Juju@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/juju


Re: Do states have namespace?

2017-04-18 Thread fengxia

Marco,

I'm modeling a complex workload which may end up having a lots of 
states. So before going down that path I want to understand better how 
to modularize these states instead of laying all flat. So I thought of 
putting them into different layers within a single charm -- this works. 
Then to divide them into different charms -- this didn't.


Now I can see each unit has its own sqlite so these states won't come 
across.


On 04/18/2017 10:16 AM, Marco Ceppi wrote:


No, because it's a sqlitedb per unit of charm. So a charm collocated 
on the same machine will still have its own state.


Can I ask what you're looking to achieve?

Marco


On Tue, Apr 18, 2017, 10:05 fengxia > wrote:


Replying my own question:

charmhelpers.core.unitdata shows how states are stored --
"reactive.state.xyz " is saved in a
sqlite3 as a string. So if split
states in multiple charms, I think it will still work if deploying
these
charms to the same unit because they will be registered in the
same DB.

Can someone verify this?

On 04/18/2017 08:50 AM, fengxia 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?
>

--
Feng xia
Engineer
Lenovo USA

Phone: 5088011794
fx...@lenovo.com 

Lenovo.com
Twitter | Facebook | Instagram | Blogs | Forums


--
Juju mailing list
Juju@lists.ubuntu.com 
Modify settings or unsubscribe at:
https://lists.ubuntu.com/mailman/listinfo/juju



--
Feng xia
Engineer
Lenovo USA

Phone: 5088011794
fx...@lenovo.com

Lenovo.com
Twitter | Facebook | Instagram | Blogs | Forums

-- 
Juju mailing list
Juju@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/juju


Re: Do states have namespace?

2017-04-18 Thread fengxia

I see. Thanks for the pointer. This is very helpful in our design.


On 04/18/2017 09:30 AM, Marco Ceppi wrote:
On Tue, Apr 18, 2017 at 8:57 AM Alex Kavanagh 
mailto:alex.kavan...@canonical.com>> wrote:


Hi


On Tue, Apr 18, 2017 at 1:50 PM, fengxia mailto:fx...@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


--
Feng xia
Engineer
Lenovo USA

Phone: 5088011794
fx...@lenovo.com

Lenovo.com
Twitter | Facebook | Instagram | Blogs | Forums

-- 
Juju mailing list
Juju@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/juju