From 4d8e560a331546dcf458654286078164e7cd974d Mon Sep 17 00:00:00 2001 From: Andrew Donald Kennedy Date: Mon, 23 May 2016 21:51:53 +0100 Subject: [PATCH] Documentation for new ScriptEffector --- guide/yaml/custom-entities.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/guide/yaml/custom-entities.md b/guide/yaml/custom-entities.md index 69d0d028..531963f1 100644 --- a/guide/yaml/custom-entities.md +++ b/guide/yaml/custom-entities.md @@ -231,6 +231,33 @@ so that the `$message` we passed above gets logged and reported back: period: 1s command: tail -1 server-input +You can even define effectors using your favourite scripting language. By default the +JSR-223 drivers for javaScript and Python are available, and others can be installed. +Add an `initializer` that defines your effector with a block of code, and pass in +data with `parameters` like this: + + brooklyn.initializers: + - type: org.apache.brooklyn.core.effector.script.ScriptEffector + brooklyn.config: + name: modifyEntity + description: JavaScript effector example + parameters: + name: + description: "New name for the entity" + type: java.lang.String + script.language: "JavaScript" + script.return.var: "id" + script.return.type: java.lang.String + script.content: | + var id = entity.getId(); + entity.setDisplayName('Entity: ' + name); + +As you can see, the `script.content` key contains a block of JavaScript code, which +can access the `entity` object and manipulate it. The `script.return.var` and +`script.return.type` keys define a variable and its type that will be returned by +the effector; in this case the `id` variable is set to the value of the entities +Brooklyn id. If you prefer to keep your code in a separate file, you can set the +`script.url` key to a URL pointing at the script. #### Summary