-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Add support for JSR-223 scripting of effectors #153
Conversation
0eb870f
to
a77cb7a
Compare
@ahgittin I'd be interested in your thoughts about this idea... Still need to add more examples and tests, as well as writing documentation - where do you suggest this should go? |
1b6da78
to
82454ea
Compare
<dependency> | ||
<groupId>org.python</groupId> | ||
<artifactId>jython</artifactId> | ||
<version>2.7.0</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible/feasible to install additional python modules for use with jython? Does the cPython ecosystem place nicely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that as long as the archives with the .py
or .pyc
files inside are on the CLASSPATH this is possible, and executing import whatever
will work, and have seen examples, but I have not tested this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a while, we bundled jython (via winrm4j, until we re-wrote that as pure Java). The jython libraries pulled in about 20 or 30MB of dependencies. It would certainly be nice if folk can add that to the classpath (or OSGi bundles) themselves, but I don't think we want to ship it with Brooklyn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree that jython is better left as an optional addon - not worth the weight it brings in. Plus we already bundle groovy and javascript is provided by the JRE so there are alternatives to choose from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add it as a test-only dependency instead, to validate that we can call additional JSR-223 languages if required, but document that we only support JavaScript (as either Rhino in 7.x or Nashorn in 8.x) by default,
Maybe<Effector<?>> javaScriptEffector = entity.getEntityType().getEffectorByName("javaScriptEffector"); | ||
Assert.assertTrue(javaScriptEffector.isPresentAndNonNull(), "The JavaScript effector does not exist"); | ||
Object result = Entities.invokeEffector(entity, entity, javaScriptEffector.get()).getUnchecked(); | ||
Assert.assertTrue(result instanceof String, "Returned value is of type String"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be "Returned value is not of type string"?
@sjcorbett Once #152 is merged I will update this to take advantage of the same features |
+1 for the idea - very useful in yaml context. I've been wanting to see this for a while. |
@neykov that's a reasonable point - this exposes |
I talked with @neykov about this, and we agreed that a sandbox would be required, and also that it would be difficult. I have been thinking about how to implement it, and one mechanism might be to inject a |
Looks like it's possible to secure a script engine so it can run any 3d party scripts, but it's language spefic. There's nothing in JSR-223 that we can rely on. |
Closing this, as much of the desired functionality can be obtained through use of the meta effectors in #605 |
This is an attempt to add scripting language support to Brooklyn blueprints, so that effectors can be added in various languages directly. JSR-223 supports JavaScript and I have also added the Python 2.7.0 plugin, but many other languages are available.
See the
script-effector-example.yaml
file for an example of how these scripting languages can be used to implement effectors.