+cc: dev@jclouds.apache.org

Hi,

I'm implementing subnetworks for Google Cloud Platform, and your help with
something that could be trivial.

In our case the a network has subnetworks. So the obvious implementation is
to add a collection to the Network object. As the API returns URI (and I
don't know how to build them into other objects right at the @Delegate
level) I'm making it return a List<URI>

The caller now has that list and I would like to fetch their respective
Subnetwork objects based on its selfLink. I could not figure out a way to
do that. :-( That's when you come in :-)

The "trick" is that the subnetwork API requires both project and region, so
when we build the SubnetworkApi if I follow the pattern I need to first
resolve those 2:

GET https://www.googleapis.com/compute/v1/projects/*project*/regions/
*region*/subnetworks


This is the code I wrote for the client. Part 1 works well, as well as part
2. The question is inside part 2....

GoogleComputeEngineApi api = compute.getContext().unwrapApi(
> GoogleComputeEngineApi.class);
> ==== Part 1 ====
> System.out.println("Listing subnetworks in region us-central1...");
> Iterator<ListPage<Subnetwork>> subnetworks = api.subnetworksInRegion("us-
> central1").list();
> while (subnetworks.hasNext()) {
> for (Subnetwork subnetwork : subnetworks.next()) {
>     System.out.printf("%s @ %s\n", subnetwork.name(),
> subnetwork.region());
>   }
> }
> ==== Part 2 ====
> System.out.println("Listing networks in project...");
> Iterator<ListPage<Network>> networks = api.networks().list();
> while (networks.hasNext()) {
> for (Network network : networks.next()) {
>     System.out.printf("%-20s %s\n", network.name(),
> network.type().toString());
> for (URI subnet : network.subnetworks()) {
>       System.out.printf(" subnetwork: %s\n", subnet);
>       // HOW DO I GET THE SUBNETWORK OBJECT HERE?!?!?!?!?
>       // (or how to build List<Subnetwork> instead of List<URI>?
>     }
>   }
>
> }
>
>
Or would it be better to simply return List<Subnetwork> instead of
List<URI>? And if you think that's the best approach how do I build the
Subnetwork from inside the AutoValue here:

@SerializedNames({ "id", "creationTimestamp", "selfLink", "name",
"description", "IPv4Range", "gatewayIPv4", "autoCreateSubnetworks",
"subnetworks"
})
public static Network create(String id, Date creationTimestamp, URI
selfLink, String name, String description, String rangeIPv4,
      String gatewayIPv4, String autoCreateSubnetworks, *Set<Subnetwork>
subnetworks*) {
return new AutoValue_Network(id, creationTimestamp, selfLink, name, type,
description, rangeIPv4, gatewayIPv4,
           subnetworks);
}
In this case because subnetworks is an array of URL it is expecting to be a
List<String> (or List<URI>). I want to convert to a List<Subnetwork>.

How do I do that?


Thanks in advance for your help!!
-- Nelson

Reply via email to