This is awesome work Ignacio, and thanks again for the contribution! I noticed the PR comments flying by here this afternoon from @nacx and wanted to quickly point something out regarding OpenStack API versioning.
My experience has been that when there is an updated "v1" API, i.e. "v1.1" or "v1.2", then it's *still* the "v1" API. For example, the "current" v2 Glance API is v2.2 [1], and the v1 API is v1.1. To my knowledge, nothing has ever been removed from an dot version of an API, but I could definitely be wrong. ;) My opinion here is that going forward we should move away from package names that use the "v1_0" or "v2_0" nomenclature. I propose that all OpenStack APIs move to the more modern "vX" form, like "v1" or "v2". Please take a look at the newer OpenStack Marconi [2] and OpenStack Swift [3] APIs for additional reference. Since the Glance APIs have not been promoted up and out of the jclouds/jclouds-labs-openstack repo into jclouds/jclouds, this would be an opportune time to address this. Its a small refactor of the code, however it would give us additional momentum in standardizing the OpenStack package version names across the codebase. The OpenStack Neutron API still uses the "v2_0" [4] package naming, and I submit that we would also change it before promotion to jclouds/jclouds. As far as the Nova and Keystone API package names, we can discuss changing them in a future jclouds release. Thoughts? Does this warrant a JIRA? /jd [1] https://github.com/openstack/glance/blob/master/glance/api/versions.py#L47 [2] https://github.com/jclouds/jclouds-labs-openstack/tree/master/openstack-marconi/src/main/java/org/jclouds/openstack/marconi/v1 [3] https://github.com/jclouds/jclouds-labs-openstack/tree/master/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1 [4] https://github.com/jclouds/jclouds-labs-openstack/tree/master/openstack-neutron/src/main/java/org/jclouds/openstack/neutron/v2_0 On Wed, Jan 22, 2014 at 1:45 AM, Ignacio Mulas Viela <[email protected] > wrote: > Nice! It worked perfectly. Seems that all the tests of v1 and v2 are > running fine now :) Thanks! > > @Ignasi The problem was in the ID as you mentioned, thanks for pointing to > the classes that handle the service loading part that part was a bit blurry > for me. > > I will clean a bit the code and upload everything to github so you guys can > have a look to the code :) > > Cheers! > Ignacio > > > 2014/1/21 Ignasi Barrera <[email protected]> > > > Just to add more information, here is where the ServiceLoader takes > > place [1]. It actually loads all the implementations, but when looking > > for an Api or Provider with a given id, the first one with that id is > > returned [2, 3]. > > > > That's why if you want to have different ApiMetadata classes you need > > two different ids for them (regardless of if they are in the same > > Maven project or are in separated ones). This also implies that you > > will need to create two different Contexts if you want to access both > > versions of a Glance Api, as one context is tied to just one > > Api/Provider metadata. > > > > > > Hope this clarifies a bit how it works! > > > > > > [1] > > > https://github.com/jclouds/jclouds/blob/master/core/src/main/java/org/jclouds/ContextBuilder.java#L163-L177 > > [2] > > > https://github.com/jclouds/jclouds/blob/master/core/src/main/java/org/jclouds/providers/Providers.java#L89-L102 > > [3] > > > https://github.com/jclouds/jclouds/blob/master/core/src/main/java/org/jclouds/apis/Apis.java#L77-L90 > > > > On 21 January 2014 22:58, Everett Toews <[email protected]> > > wrote: > > > A pastie or gist would be fine but in this case a pull request would be > > even better. Just a work-in-progress PR for us to look at. It's not like > we > > would necessarily merge it either. It's just to share code and comment on > > it. > > > > > > Everett > > > > > > > > > On Jan 21, 2014, at 3:48 PM, Ignasi Barrera wrote: > > > > > >> Can you paste in a gist or pastie the GlanceApiMetadata classes? > > >> Have you assigned a different ID to each, like "glance-v1" and > > "glance-v2"? > > >> > > >> On 21 January 2014 22:27, Ignacio Mulas Viela <[email protected] > > > > wrote: > > >>> I tried having in the ServiceLoader file the two APiMetadata, run the > > tests > > >>> and it only takes the first class that it is in the serviceLoader > > file. If > > >>> I put first the v2 ApiMetadata then the v1 tests fails due to a cast > > >>> conversion problem. And viceversa if the first class is the v1. The > > error > > >>> is the following (in case v2 is first): > > >>> > > >>> Caused by: java.lang.ClassCastException: com.sun.proxy.$Proxy52 > cannot > > be > > >>> cast to org.jclouds.openstack.glance.v1_0.GlanceApi > > >>> > > >>> The configuration file contains: > > >>> org.jclouds.openstack.glance.v2_0.GlanceApiMetadata > > >>> org.jclouds.openstack.glance.v1_0.GlanceApiMetadata > > >>> > > >>> Any clue about what I am missing here? > > >>> > > >>> > > >>> 2014/1/21 Ignasi Barrera <[email protected]> > > >>> > > >>>> By default you don't have to do nothing apart from having the two > > >>>> ApiMetadata classes and have them declared in the ServiceLoader > file. > > >>>> It will work :) > > >>>> > > >>>> Feel free to join the #jclouds IRC channel @Freenode if you want to > > >>>> discuss it live! > > >>>> > > >>>> On 21 January 2014 21:58, Ignacio Mulas Viela < > [email protected] > > > > > >>>> wrote: > > >>>>> Thanks everyone for the discussion and the hints! I think I will > try > > to > > >>>>> maintain everything inside one glance module and see where it goes, > > If I > > >>>>> can achieve the correct loading of the two services I think it will > > be > > >>>>> better than having the code divided in different projects as Glance > > only > > >>>>> contains one API (imageAPI). > > >>>>> > > >>>>> @Ignasi thanks for the implementation hints, I will try to > > investigate > > >>>> how > > >>>>> I can implement the two contexts depending on the versions. > > >>>>> > > >>>>> > > >>>>> > > >>>>> > > >>>>> 2014/1/21 Ignasi Barrera <[email protected]> > > >>>>> > > >>>>>> With the described approach you'll need two contexts, one to use > > each > > >>>>>> version (as the ServiceLoader will create one instance of the > > service > > >>>> for > > >>>>>> each). > > >>>>>> > > >>>>>> Depending on the complexity of the differences, perhaps it can be > > >>>>>> configured with a single ApiMetadata and let Guice *provide* the > > right > > >>>>>> classes depending on the *apiVersion* (it can be configured when > > >>>> creating > > >>>>>> the context). jclouds-chef already does this to handle the > > >>>> deserialization > > >>>>>> of objects in different versions of the api [1] (see the peoviders > > at > > >>>> the > > >>>>>> end of the file). > > >>>>>> > > >>>>>> [1] > > >>>>>> > > >>>>>> > > >>>> > > > https://github.com/jclouds/jclouds-chef/blob/master/core/src/main/java/org/jclouds/chef/config/ChefParserModule.java > > >>>>>> El 21/01/2014 19:13, "Andrew Phillips" <[email protected]> > > >>>> escribió: > > >>>>>> > > >>>>>>> If we start going down the path of breaking it out into > glance-v1, > > >>>>>>>> glance-v2, and glance-common, we're going to see an explosion of > > >>>>>>>> OpenStack modules in jclouds as new versions of APIs are > released > > in > > >>>>>>>> OpenStack land. > > >>>>>>>> > > >>>>>>> > > >>>>>>> I wasn't very clear in my original answer: I was under the > > impression > > >>>>>> that > > >>>>>>> the two versions cannot coexist simultaneously in the same > > context. If > > >>>>>>> there's no problem to have both of these loaded at the same time, > > then > > >>>>>>> let's definitely try to do that in one dependency! > > >>>>>>> > > >>>>>>> ap > > >>>>>>> > > >>>>>> > > >>>> > > > > > >
