Tags and object IDs
Nate Finch
nate.finch at canonical.com
Wed Feb 3 03:28:42 UTC 2016
I always liked you, Tim :)
On Tue, Feb 2, 2016, 10:25 PM Tim Penhey <tim.penhey at canonical.com> wrote:
> Here is my short answer:
>
> use names.UnitTag
>
> That is all.
>
> Tim
>
> On 23/01/16 09:53, Nate Finch wrote:
> > Working in the model layer on the server between the API and the DB.
> > Specifically in my instance, an API call comes in from a unit,
> > requesting the bytes for a resource. We want to record that this unit
> > is now using the bytes from that specific revision of the resource. I
> > have a pointer to a state.Unit, and a function that takes a Resource
> > metadata object and some reference to the unit, and does the actual
> > transaction to the DB to store the unit's ID and the resource
> information.
> >
> > On Fri, Jan 22, 2016 at 3:34 PM William Reade
> > <william.reade at canonical.com <mailto:william.reade at canonical.com>>
> wrote:
> >
> > Need a bit more context here. What layer are you working in?
> >
> > In general terms, entity references in the API *must* use tags;
> > entity references that leak out to users *must not* use tags;
> > otherwise it's a matter of judgment and convenience. In state code,
> > it's annoying to use tags because we've already got the globalKey
> > convention; in worker code it's often justifiable if not exactly
> > awesome.
> > See https://github.com/juju/juju/wiki/Managing-complexity#workers
> >
> > Cheers
> > William
> >
> > On Fri, Jan 22, 2016 at 6:02 PM, Nate Finch
> > <nate.finch at canonical.com <mailto:nate.finch at canonical.com>> wrote:
> >
> > I have a function that is recording which unit is using a
> > specific resource. I wrote the function to take a UnitTag,
> > because that's the closest thing we have to an ID type. However,
> > I and others seem to remember hearing that Tags are really only
> > supposed to be used for the API. That leaves me with a problem -
> > what can I pass to this function to indicate which unit I'm
> > talking about? I'd be fine passing a pointer to the unit object
> > itself, but we're trying to avoid direct dependencies on state.
> > People have suggested just passing a string (presumably
> > unit.Tag().String()), but then my API is too lenient - it
> > appears to say "give me any string you want for an id", but what
> > it really means is "give me a serialized UnitTag".
> >
> > I think most places in the code just use a string for an ID, but
> > this opens up the code to abuses and developer errors.
> >
> > Can someone explain why tags should only be used in the API? It
> > seems like the perfect type to pass around to indicate the ID of
> > a specific object.
> >
> > -Nate
> >
> > --
> > Juju-dev mailing list
> > Juju-dev at lists.ubuntu.com <mailto:Juju-dev at lists.ubuntu.com>
> > Modify settings or unsubscribe at:
> > https://lists.ubuntu.com/mailman/listinfo/juju-dev
> >
> >
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/juju-dev/attachments/20160203/2b756487/attachment.html>
More information about the Juju-dev
mailing list