cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rohit Yadav <>
Subject [DISCUSS] Using framework level API argument validation
Date Thu, 21 Apr 2016 11:07:57 GMT

Whenever we've to write new APIs, we end up putting a lot of validations such as Strings.isNullOrEmpty
or checks on API args such as on id we do this a lot getId() != null && getId() >
0 and on failing throw server api exception (as cloudstack entity ids are always > 0, such
as ids of vms, volumes etc).

While working on recent dynamic-roles PR, I ended up writing several such validations for
all the new APIs and based on suggestions from John I could rid of all such checks by introducing
a new @Parameter annotation field call validators() which is a list of validators we want
to run for an API arg. This does not break any existing API which might have inconsistent
assumptions (such as few accept id to be -1), and on local env all existing unit tests and
smoke tests have passed.

Please find an implementation in the dynamic-roles PR where all the new dynamic roles APIs
use these annotations:


As soon as the PR is accepted and merged, I'll update the wiki page and we can get this pattern
adopted over time:

Rohit Yadav


Rohit Yadav
53 Chandos Place, Covent Garden, London  WC2N 4HSUK
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message