Hi. Currently the only initializer for new effectors that can be used in a YAML blueprint is the SshCommandEffector, which creates an effector that can execute an SSH command on an entity. This is useful, but it would be good to have more flexibility, including access to some of the Brooklyn internals. So, I had a look at the JSR-223 scripting extensions to Java, and built a new initializer that can add an effector whose body is a piece of code defined in the blueprint. This code can be in any language supported by the running JVM. Currently only JavaScript is available by default, but my implementation also adds Python 2.7 via the Jython project.
As an example, here is an entity that has a JavaScript effector that takes two arguments, a name and a count, and returns the name repeated multiple times. A real effector would actually do something useful, obviously: services: - type: org.apache.brooklyn.entity.stock.BasicStartable brooklyn.initializers: - type: org.apache.brooklyn.core.effector.script.ScriptEffector brooklyn.config: name: javascript description: | An effector implemented in JavaScript parameters: name: type: java.lang.String description: "Your name" count: type: java.lang.Integer description: "Number of repetitions" script.language: "JavaScript" script.return.var: "data" script.return.type: java.lang.String script.content: | var data = ""; var n = 0; while (n < count) { data += name; n++; } The return value is coerced to script.return.type using TypeCoercions and can be either the content of a variable specified in script.return.var or the default return value of the code, which is often the value of the last expression, if the language supports this. The script content can also be provided as a URL pointing to a file, instead of inline. I am also trying to inject variables into the execution context of the script, so that the code has access to the current task, the calling entity and its management context and other useful Brooklyn objects. I have created a pull request with the initial code, so that people can see the current status: - https://github.com/apache/brooklyn-server/pull/153 This is still work in progress, so further suggestions welcome... Cheers, Andrew. -- Andrew Kennedy ; Founder clocker.io project ; @grkvlt ; Cloudsoft