more complex api requests

14 views
Skip to first unread message

Zack

unread,
Apr 19, 2013, 8:21:55 PM4/19/13
to jclou...@googlegroups.com
I am figuring out how complex requests should work, specifically json request body with nested arrays, such as { instance: { users: [ { databases: [ {...}, {...}, ...] },  {databases: [...] }, ...} }
Looks like: root.instance.users[].databases[].etc

Is CreateVolumeOptions in org.jclouds.openstack.cinder.v1.options a good example? What else would be?

Thanks

Adrian Cole

unread,
Apr 19, 2013, 8:30:44 PM4/19/13
to jclou...@googlegroups.com
Hey, zack.  Good question.  What api is this for?  

doubly nested things are a pita sometimes, though I tend to prefer maps and such for them.  If the number of parameters isn't insane, then a MapBinder could do the trick by collecting the parameters and allowing you to make a json object out of all of them.

Here's an example:

   @Named("addDirectionalPoolRecord")
   @POST
   @XMLResponseParser(ElementTextHandler.DirectionalPoolRecordID.class)
   @MapBinder(DirectionalRecordAndGeoGroupToXML.class)
   String addRecordIntoNewGroup(@PayloadParam("poolId") String poolId,
         @PayloadParam("record") DirectionalPoolRecord toCreate, @PayloadParam("group") DirectionalGroup group)
         throws ResourceAlreadyExistsException;



--
You received this message because you are subscribed to the Google Groups "jclouds-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jclouds-dev...@googlegroups.com.
To post to this group, send email to jclou...@googlegroups.com.
Visit this group at http://groups.google.com/group/jclouds-dev?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Zack

unread,
Apr 21, 2013, 12:31:28 AM4/21/13
to jclou...@googlegroups.com

Adrian Cole

unread,
Apr 21, 2013, 1:20:31 PM4/21/13
to jclou...@googlegroups.com
p.s. since this is for a create op with 1 mandatory and 2 optional
configs, I could see this as.

InstanceApi.create(Instance)
InstanceApi.createWithDatabase(Instance, db)
InstanceApi.createWithDatabaseAndUser(Instance, db, user)

presuming it is valid to create a database without specifying a user for it.

my 2p

Zack

unread,
Apr 21, 2013, 6:47:44 PM4/21/13
to jclou...@googlegroups.com
Just to clarify, it is my understanding you can create an instance with multiple databases and multiple users, where the each user can also refer to a list of database names. Which is why the request gets a bit complex.

Adrian Cole

unread,
Apr 21, 2013, 7:07:28 PM4/21/13
to jclou...@googlegroups.com
yeah somebody designed a complicated api. so, if the goal is to
expose this in all its glory, then we'd need a call with a
InstanceTemplate thing which can holds an instance, iterable of
databases, iterable of users, and possibly a request map. Personally,
I'd ask a user of this thing and see if people actually do this in
practice. If not, I'd implement a create command that includes
parameters actually used, which might be a simpler model.

2p

Adrian Cole

unread,
Apr 21, 2013, 7:25:39 PM4/21/13
to jclou...@googlegroups.com
rds needs a cleanup, and isn't perfectly modeled, but here is an
example instance request.

Instance newInstance = api().create(
"id",
InstanceRequest.builder()
.instanceClass("db.t1.micro")
.allocatedStorageGB(5)
.securityGroup(securityGroup.getName())
.name("jclouds-db")
.engine("mysql")

.masterUsername("master").masterPassword("Password01")
.backupRetentionPeriod(0).build());

Note the flat request, and lack of complex relationships. You can't
create multiple dbs or multiple users afaik in RDS, which makes it
simple and more approachable.

Ideally, we wouldn't create, test, or do code reviews on things that
don't have a Customer who can validate it covers their use case and
that they will in fact use it, hopefully in prod.

Esp lacking a user, we should be careful not to add hairy code just
because it is defined in a public rest doc. In the case of this, I'd
do a simple create 1 DB with 1 user command and stop until someone
external asks for more in a issue or on the mailing list. This will
keep the review team working on things that add highest value, and
save you from the deep holes of complex api structure.

make sense?

https://github.com/jclouds/jclouds-labs/blob/master/rds/src/test/java/org/jclouds/rds/features/InstanceApiLiveTest.java
http://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBInstance.html

Zack

unread,
Apr 21, 2013, 8:29:42 PM4/21/13
to jclou...@googlegroups.com
Ah this explains it. Thanks!
Reply all
Reply to author
Forward
0 new messages