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
> >>>>>>>
> >>>>>>
> >>>>
> >
>

Reply via email to