<div dir="ltr">I'm not sure that is really 100% of the problem here, but we are definitely doing links in an inefficient way these days, due to an early misconception some of us on the Nova team had about *how* to do hyperlinks in json.<div>
<br></div><div>Json schema [1] <font color="#000000">provides ways to indicate, _in the schema of an object_, how it is linked to other objects. For example, if I had an object</font></div><div><font color="#000000"><br>
</font></div><div><font color="#000000">GET /widgets/foo</font></div><div><font color="#000000">{</font></div><div><font color="#000000"> 'name': 'foo',</font></div><div><font color="#000000"> 'self': '/widgets/foo',</font></div>
<div><font color="#000000"> 'bar': '/widgets/foobar',</font></div><div><font color="#000000">}</font></div><div><font color="#000000"><br></font></div><div><font color="#000000">I might use a schema to communicate that 'self' is a self link, and that 'bar' is a related resource by publishing a schema</font></div>
<div><font color="#000000"><br></font></div><div><font color="#000000">GET /schemas/object</font></div><div><font color="#000000">{</font></div><div><font color="#000000"> 'type': 'object',</font></div>
<div><font color="#000000"> 'properties': {</font></div><div><font color="#000000"> 'name': {'type': 'string'},</font></div><div><font color="#000000"> 'self': {'type': 'string'},</font></div>
<div><font color="#000000"> 'bar': {'type': 'string'},</font></div><div><font color="#000000"> },</font></div><div><font color="#000000"> 'links': [</font></div><div>
<font color="#000000"> {'rel': 'self', 'href': '{self}'},</font></div><div><font color="#000000"> {'rel': 'related', 'href': '{bar}'}</font></div>
<div><font color="#000000"> ]</font></div><div><font color="#000000">}</font></div><div><font color="#000000"><br></font></div><div><font color="#000000">What this schema says is that name, self, and bar are string types, that you can construct a self link using the value of the "self" property, and that you can construct a related link using the value of the "bar" property.</font></div>
<div><font color="#000000"><br></font></div><div><font color="#000000">For some reason I cannot remember, we neglected to realize that link descriptor objects [2] were only intended for json schema objects, not the regular objects described by the schemas. In the process, we made hyperlinks in our apis really inefficient by loading them up with unnecessary 'rels' and 'hrefs'. We also made finding relevant links difficult by requiring clients to iterate through an array rather than just explicitly looking up the relevant properties.</font></div>
<div><font color="#000000"><br></font></div><div><font color="#000000">Glance v2 api fixes this problem. But we also tried to go all-in on being schema driven. This combined approach is fine for Glance, but I'm not sure that the "schema-driven" part is necessarily that useful for others. In any case, we needn't have such bloated json hyperlinks for future openstack apis. For example, if you want to have actions listed for a server, you could just do</font></div>
<div><font color="#000000"><br></font></div><div style><font color="#000000">{</font></div><div style><font color="#000000"> "id": "abcd",</font></div><div style><font color="#000000"> ...</font></div>
<div style><font color="#000000"> "actions": {</font></div><div style><font color="#000000"> "stop": "/servers/abcd/stop",</font></div><div style><font color="#000000"> "snapshot": "/servers/abcd/snapshot"</font></div>
<div style><font color="#000000"> }</font></div><div style><font color="#000000">}</font></div><div style><font color="#000000"><br></font></div><div style><font color="#000000">which is a bit more compressed.</font></div>
<div><font color="#000000"><br></font></div><div><font color="#000000">[1] - <a href="http://tools.ietf.org/html/draft-zyp-json-schema-03" target="_blank">http://tools.ietf.org/html/draft-zyp-json-schema-03</a></font></div>
<div>
<font color="#000000">[2] - <a href="http://tools.ietf.org/html/draft-zyp-json-schema-03#section-6.1">http://tools.ietf.org/html/draft-zyp-json-schema-03#section-6.1</a></font></div></div><div class="gmail_extra"><br><br>
<div class="gmail_quote">On Wed, May 8, 2013 at 10:33 PM, Mark McLoughlin <span dir="ltr"><<a href="mailto:markmc@redhat.com" target="_blank">markmc@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Wed, 2013-05-08 at 18:59 +0000, Gabriel Hurley wrote:<br>
> > -----Original Message-----<br>
> > From: Vishvananda Ishaya [mailto:<a href="mailto:vishvananda@gmail.com">vishvananda@gmail.com</a>]<br>
> > Sent: Tuesday, May 07, 2013 3:44 PM<br>
><br>
> > It is relatively easy to include the info at servers/<uuid> however:<br>
> > {<br>
> > "features": ["OS-EXT-SRV-ATTR", "os-start-stop"],<br>
> > "server": {<br>
> > "OS-EXT-SRV-ATTR:host": "1169a68456af48238da47b1d5957a714",<br>
> > "OS-EXT-SRV-ATTR:hypervisor_hostname": "fake-mini",<br>
> > "OS-EXT-SRV-ATTR:instance_name": "instance-00000001",<br>
> > "links": [<br>
> > {"rel": "self",<br>
> > "href":"<a href="http://example.org/v3/servers/009e9aca-b765-11e2-855a-" target="_blank">http://example.org/v3/servers/009e9aca-b765-11e2-855a-</a><br>
> > 008cfa10b980"},<br>
> > {"rel": "start",<br>
> > "href":"<a href="http://example.org/v3/servers/009e9aca-b765-11e2-855a-" target="_blank">http://example.org/v3/servers/009e9aca-b765-11e2-855a-</a><br>
> > 008cfa10b980/start"<br>
> > "feature": "os-start-stop"},<br>
> > {"rel": "stop",<br>
> > "href":"<a href="http://example.org/v3/servers/009e9aca-b765-11e2-855a-" target="_blank">http://example.org/v3/servers/009e9aca-b765-11e2-855a-</a><br>
> > 008cfa10b980/stop"<br>
> > "feature": "os-start-stop"}.<br>
> > ]<br>
> > }<br>
> > }<br>
><br>
> Tht perfectly illustrates my biggest concern with doing this on a<br>
> per-resource basis.<br>
<br>
</div>Per-resource does allow you to expose whether a user has permission to<br>
perform an action, though.<br>
<div class="im"><br>
> The list of "links" gets unconscionably enormous. If I do a "list"<br>
> call and retrieve 100 instances each with 100 links because you have<br>
> 20 extensions the whole thing becomes a mess. I think it's much more<br>
> sane (though less explicit) to understand what's provided by the<br>
> service and extrapolate that to the individual resources therein.<br>
<br>
</div>Yeah, lots of links can be messy. How about URI templates?<br>
<br>
Maybe we have them as a /capabilities/templates resource:<br>
<br>
{"templates": [<br>
{"rel": "server_start_action",<br>
"href": "<a href="http://example.org/v3/servers/{server_uuid}" target="_blank">http://example.org/v3/servers/{server_uuid}</a>"<br>
}<br>
]}<br>
<br>
then just do:<br>
<br>
"links": [<br>
{"rel": "start", "template": "server_start_action"}<br>
]<br>
<br>
Just a thought ...<br>
<br>
Cheers,<br>
Mark.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
_______________________________________________<br>
OpenStack-TC mailing list<br>
<a href="mailto:OpenStack-TC@lists.openstack.org">OpenStack-TC@lists.openstack.org</a><br>
<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-tc" target="_blank">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-tc</a><br>
</div></div></blockquote></div><br></div>