PROPOSAL: conditional config constraints
I'd like to add support for more sophisticated config constraints, where
there are inter-dependencies between config keys. I'd like the blueprint
composer web-console to understand (a small number of) these, and thus
to give feedback to the user about what is required and whether their
blueprint is valid.
For example, a blueprint that requires exactly one of config X or config
Y. Another example: config X2 is required if and only if config X1 is
There are a few questions / decision points:
1. What constraints should we support out-of-the-box?
2. What naming convention do we use, so that the UI can parse +
3. Should we support multiple constraints (we do in the REST api, but
not currently in the Java API or in the Blueprint Composer UI)
I suggest we support things like:
The structure of this string would be:
requiredIf("X1"): value is required if config X1 is set;
forbiddenUnless("X1"): value must be null if config X1 is not set;
requiredUnless("Y"): value is required if config Y is not set;
forbiddenIf("Y"): value must be null if config Y is set;
I don't think we want to get too sophisticated. For example, do *not*
support "must match regex '[a-z]+' unless config Y is present". I don't
think we should create a full-blown DSL for this!
We already have the basis of this in our Java code. We support a
predicate of type
`org.apache.brooklyn.core.objs.BrooklynObjectPredicate`, which has the
additional method `boolean apply(T input, BrooklynObject context)`. The
`BrooklynObject` could be an entity, or location, etc. An implementation
of this predicate can therefore lookup other config key's values, when
validating the value.
For the UI, the Blueprint Composer calls:
This returns things like:
The constraint returned here is the toString() of the predicate.
In the UI , there is currently some very simple logic to interpret
this string for particular types of constraint.