You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jclouds.apache.org by Andrew Phillips <ap...@qrmedia.com> on 2013/08/05 20:30:45 UTC

Re: Post-de-async, what's the equivalent of (api metadata).CONTEXT_TOKEN.isAssignableFrom?

> So I guess we're stuck with that godawful amount of text for 1.6.x, and
> slightly less for 1.7. It'd still be nice to have something like the old
> CONTEXT_TOKEN for the de-async world, though.

If I understand correctly, the goal here is to verify that the  
"unwrap" call will succeed, and I guess we're looking to avoid nasty  
"try...catch"-style solutions?

How about something like the following - not exactly less typing, but still:

ApiMetadata apiMeta = ctx.getProviderMetadata().getApiMetadata();
if ((apiMeta instanceof HttpApiMetadata) &&  
EC2Api.class.isAssignableFrom((HttpApiMetdata) apiMeta).getApi())){
   ...
}

Of course, if you're expecting it to be an HttpApiMetdata, you can  
skip the instanceof check..?

ap


PS: Detail on the whole discussion around the deprecation of  
CONTEXT_TOKEN here:

https://issues.apache.org/jira/browse/JCLOUDS-82

Re: Post-de-async, what's the equivalent of (api metadata).CONTEXT_TOKEN.isAssignableFrom?

Posted by Andrew Phillips <ap...@qrmedia.com>.
Quoting Andrew Bayer <an...@gmail.com>:

> The if is there to see what the actual provider/API is - this is from
> Whirr, checking to see what API's in use so we can figure out what to do
> about security groups/firewalls. I'll see if I can come up with something
> cleaner...

Am I guessing that a direct link between Context or View and Api would  
be ideal? So you could do something like e.g.  
EC2Api.class.isAssignableFrom(view.getBackendApi())..?

Perhaps worth looking at whether a

Class<? extends Closeable> getBackendApi()

or

TypeToken<? extends Closeable> getBackendApi()

method could be added to View, alongside potentially a

/**
  * equivalent to unwrapApi(getBackendApi())
  */
Closeable unwrapApi()

?

ap

Re: Post-de-async, what's the equivalent of (api metadata).CONTEXT_TOKEN.isAssignableFrom?

Posted by Andrew Phillips <ap...@qrmedia.com>.
How about something like

if (token(ApiContext.class).isAssignableFrom(ctx.getBackendType())) {
   Closeable api = ((ApiContext) unwrap()).getApi();
}

That's pretty much what BaseView does for unwrapApi, it seems [2].  
Admittedly, to check for a *particular* API you'd need to figure out  
what the generic type argument of ctx.getBackendType() is, I guess...

ap

[1]  
https://github.com/jclouds/jclouds/blob/master/core/src/main/java/org/jclouds/rest/ApiContext.java
[2]  
https://github.com/jclouds/jclouds/blob/master/core/src/main/java/org/jclouds/internal/BaseView.java#L70

Re: Post-de-async, what's the equivalent of (api metadata).CONTEXT_TOKEN.isAssignableFrom?

Posted by Andrew Bayer <an...@gmail.com>.
The if is there to see what the actual provider/API is - this is from
Whirr, checking to see what API's in use so we can figure out what to do
about security groups/firewalls. I'll see if I can come up with something
cleaner...

A.

On Mon, Aug 5, 2013 at 11:30 AM, Andrew Phillips <ap...@qrmedia.com>wrote:

> So I guess we're stuck with that godawful amount of text for 1.6.x, and
>> slightly less for 1.7. It'd still be nice to have something like the old
>> CONTEXT_TOKEN for the de-async world, though.
>>
>
> If I understand correctly, the goal here is to verify that the "unwrap"
> call will succeed, and I guess we're looking to avoid nasty
> "try...catch"-style solutions?
>
> How about something like the following - not exactly less typing, but
> still:
>
> ApiMetadata apiMeta = ctx.getProviderMetadata().**getApiMetadata();
> if ((apiMeta instanceof HttpApiMetadata) && EC2Api.class.isAssignableFrom(
> **(HttpApiMetdata) apiMeta).getApi())){
>   ...
> }
>
> Of course, if you're expecting it to be an HttpApiMetdata, you can skip
> the instanceof check..?
>
> ap
>
>
> PS: Detail on the whole discussion around the deprecation of CONTEXT_TOKEN
> here:
>
> https://issues.apache.org/**jira/browse/JCLOUDS-82<https://issues.apache.org/jira/browse/JCLOUDS-82>
>