You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sj...@apache.org on 2015/10/14 15:55:53 UTC

[07/17] incubator-brooklyn git commit: Website documentation on constraints

Website documentation on constraints


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/781e2cfa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/781e2cfa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/781e2cfa

Branch: refs/heads/master
Commit: 781e2cfaa97d28ac796bb4c185a5412c0e490fda
Parents: 60d85fa
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Fri Sep 11 18:32:54 2015 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Thu Oct 8 17:54:43 2015 +0100

----------------------------------------------------------------------
 .../concepts/configuration-sensor-effectors.md     |  4 ++--
 docs/guide/java/entities.md                        | 17 +++++++++++++++--
 2 files changed, 17 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/781e2cfa/docs/guide/concepts/configuration-sensor-effectors.md
----------------------------------------------------------------------
diff --git a/docs/guide/concepts/configuration-sensor-effectors.md b/docs/guide/concepts/configuration-sensor-effectors.md
index bb41343..6363b8a 100644
--- a/docs/guide/concepts/configuration-sensor-effectors.md
+++ b/docs/guide/concepts/configuration-sensor-effectors.md
@@ -15,7 +15,7 @@ Configuration is propagated when an application "goes live" (i.e. it becomes "ma
 Configuration values can be specified in a configuration file (``~/.brooklyn/brooklyn.properties``)
 to apply universally, and/or programmatically to a specific entity and its descendants 
 by calling `.configure(KEY, VALUE)` in the entity spec when creating it.
-There is also an ``entity.setConfig(KEY, VALUE)`` method.
+There is also an ``entity.config().set(KEY, VALUE)`` method.
 
 Additionally, many common configuration parameters are available as "flags" which can be supplied as Strings when constructing
 then entity, in the form
@@ -35,6 +35,6 @@ Sensors can be updated by the entity or associated tasks, and sensors from an en
 Effectors can be invoked by an entity's parent remotely, and the invoker is able to track the execution of that effector. Effectors can be invoked by other entities, but use this functionality with care to prevent too many managers!
 
 An entity consists of a Java interface (used when interacting with the entity) and a Java class. For resilience. it is recommended to store 
-the entity's state in attributes (see `getAttribute(AttributeKey)``). If internal fields can be used then the data will be lost on brooklyn 
+the entity's state in attributes (see ``getAttribute(AttributeKey)``). If internal fields can be used then the data will be lost on brooklyn
 restart, and may cause problems if the entity is to be moved to a different brooklyn management node.
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/781e2cfa/docs/guide/java/entities.md
----------------------------------------------------------------------
diff --git a/docs/guide/java/entities.md b/docs/guide/java/entities.md
index b83c61a..b83bfc9 100644
--- a/docs/guide/java/entities.md
+++ b/docs/guide/java/entities.md
@@ -50,8 +50,21 @@ TODO: why to use config?
   Syntax is as described in the PortRange interface. For example, "8080-8099,8800+" will try port 8080, try sequentially through 8099, then try from 8800 until all ports are exhausted.
   
   This is particularly useful on a contended machine (localhost!). Like ordinary configuration, the config is done by the user, and the actual port used is reported back as a sensor on the entity.
- 
- 
+
+- Validation of config values can be applied by supplying a ``Predicate`` to the ``constraint`` of a ConfigKey builder.
+  Constraints are tested after an entity is initialised and before an entity managed.
+  Useful predicates include:
+  - ``StringPredicates.isNonBlank``: require that a String key is neither null nor empty.
+  - ``ResourcePredicates.urlExists``: require that a URL that is loadable by Brooklyn. Use this to
+    confirm that necessary resources are available to the entity.
+  - ``Predicates.in``: require one of a fixed set of values.
+  - ``Predicates.containsPattern``: require that a value match a regular expression pattern.
+
+  An important caveat is that only constraints on config keys that are on an entity's type hierarchy can be
+  tested automatically. Brooklyn has no knowledge of the true type of other keys until they are retrieved with a
+  ``config().get(key)``.
+
+
 Implementing Sensors
 --------------------