> +   /**
> +    * Retrieve the virtual machine this volume is attached to.
> +    * 
> +    * @return The virtual machine this volume is attached to, or null if it 
> is
> +    * not attached.
> +    */
> +   public VirtualMachine getVirtualMachine() {
> +      checkState(ATTACHED == VolumeState.valueOf(target.getState()), "Volume 
> is not attached to a VM");
> +      RESTLink vmLink = 
> checkNotNull(target.searchLink(ParentLinkName.VIRTUAL_MACHINE),
> +            ValidationErrors.MISSING_REQUIRED_LINK + " " + 
> ParentLinkName.VIRTUAL_MACHINE);
> +      vmLink.setType(VirtualMachineWithNodeExtendedDto.BASE_MEDIA_TYPE);
> +      HttpResponse response = context.getApi().get(vmLink);
> +
> +      ParseXMLWithJAXB<VirtualMachineWithNodeExtendedDto> parser = new 
> ParseXMLWithJAXB<VirtualMachineWithNodeExtendedDto>(
> +            context.utils().xml(),
> +            TypeLiteral.get(VirtualMachineWithNodeExtendedDto.class));

Agree. We could request the parser to the Guice injector by providing the 
appropriate type token. I think that would be a cleaner approach.

Regarding the specific API call, I think it wouldn't provide benefit: To be 
able to make that call we would have to parse the URI in the link to extract 
the different ids to be passed as a parameter to the api call. This adds the 
complexity, and the chance to introduce a bug, in the parsing logic.

It is also worth taking into account that the Abiquo Api does a strong use of 
the HATEOAS concept, and if you take a look at the api classes you con't see 
any endpoint (almost any) declared there. This is because the endpoints are 
extracted from the objects returned by the Api. This has the advantages that 
if, for any reason, a URI changed, jclouds would continue working as all 
endpoints are generated dinamically. If we manually parse the URI in the link, 
we will lose this.

Apart from that, calling the generic method in the AbiquoApi to get the link, 
only implies one manual step: parsing the result. But we already know the type 
of the result and can ask Guice for the appropriate parser, so that shouldn't 
be a problem.

Personally, I think it is cleaner to use the method to get a generic link and 
manually call the parser to parse the result, than parsing the URI of the link 
to call a concrete method of the specific api class. (I'm open to discuss this 
though :D).


---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs/pull/31/files#r7324342

Reply via email to