-
-
Notifications
You must be signed in to change notification settings - Fork 423
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
[Automation] Add DynamicImport-Package for scripted automation #663
Conversation
66c1248
to
12f1b25
Compare
Fixes openhab#610 Signed-off-by: Scott Rushworth <openhab@5iver.com>
It looks like DCO does not accept the signoff, if you include the GH account. |
AFAIK a github username is not (and has never been) part of the common signed off footer at all. Is there a defined syntax or is the one choosen by the Git command line tool a suggestion only? |
For openHAB, it has always been, see https://www.openhab.org/docs/developer/contributing/contributing.html#sign-your-work. But I'd be fine to drop this requirement and go with the "plain" sign-off. |
@maggu2810, is this approach for resolving the issue still in question? I was hoping this could be merged before you left for holiday. 😄 |
I still would like to get some more comments about the dynamic imports from the other maintainers. |
Dynamic imports look enticing at first. But after a bit of reading my conclusion is also that using dynamic imports is not recommended (causing issues) and it is regarded as a sign of a non-modular architecture. |
The referenced document is indeed speaking against dynamic imports with strong arguments. |
@davidgraeff, thank you for stirring up the conversation! IMO #610 should be labelled as critical, since nobody that uses scripted automation can use any of the builds since ESH was reintegrated. The alternative is to use Markus' solution in #653, which requires manually adding all imports, which I believe could all be optional. In testing this worked, but IMO is unnecessarily restrictive and will require upkeep to expose more Classes for use in scripts. The articles I have found in regards to OSGi and JSR223, suggested using DynamicImport. Of the articles recommending against DynamicImport, I could not see how the concerns that were being illustrated applied to OH... but I conceded to the experts! @kaikreuzer, could you please weigh in on this? |
Thanks @openhab-5iver for this Comment: https://www.vogella.com/tutorials/OSGi/article.html#life-cycle-of-plug-ins-in-osgi
This state is the same since more than 10 years and you're right, we have to know about the dangers for the dynamic processes in OSGI. I guess there is a reason why this functionality is not set to deprecated. Because exactly here we have an exemplary case in which the many advantages outweigh. If scripting binding is not started, no danger. If binding is started and no no special class are loaded, no static dependencies will be created, no danger. We have all been able to live with this very well so far, haven't we? And yes, this circumstance should definitely be emphasized in the documentation. But please don't forbid it completely! It helps to test many things while scripting and I use the dynamic class-loading feature many many times! Edit: |
Just thought I'd give my 2 cents here. I've been using openHAB for 2.5 years now and over the last few months I've been moving my automation over to Jython. I think this is a great benefit for openHAB as a whole to move away from DSL rules. That said, I'm not a novice when it comes to programming and I am already using imports from all over the core. Because of this I am now stuck back on an older build until this is resolved. I've been following along with @openhab-5iver 's progress getting this sorted out and have a suggestion that might appease both sides: What if we used dynamic imports, but allowed only classes from the core and utilities to be imported? Certainly we would have issues if a class that no longer exists or changed names was being imported by a script, but the core and utilities (with the exception of transform) don't change a runtime very often. Using dynamic import to get a class from a binding would be more likely to cause issues, but this could be denied. I am not a Java programmer and have not used OSGi before, so there's a chance I've misunderstood dynamic import and this filtering is not possible |
I thought it was newly added but it indeed seems to have been used before (see ESH manifest). Were there any reasons for this @maggu2810? |
I have thought about in more detail and we already now have a quite confusing versioning (non semantic) / non consistent API (java/rest/scripts) and basically no existing ABI. I'd say we go with a third way next to Markus static way of listing all classes and the all in solution. I propose to annotate all classes that are going to be exported. An OSGi bundle tracker in the automation.script bundle finds all annotated classes and makes them available. That way a developer immediately sees that an "API contract" with the script engine is established and changes could potentially break user setups. |
Interesting, but this does not help with third party libraries, so would need to be used in conjunction with manual imports. Here are three examples.
DynamicImport was included in the original PR for scripted automation, so if there are any ill effects from using it, we should already be aware of them. I have no doubts that the reason it was added in the first place was to provide exactly the functionality that we are asking to be restored... access to all classes for use within scripted automation. |
@openhab-5iver I see the point. But I'm also asking myself, how do you inject 3rd party java libraries as a script developer? Wouldn't you instead use script engine provided ways and 3rd party script libraries? I think what is problematic for Markus and me is that a script user can access all framework classes and we would need to care about them. And framework classes definitely need an overhaul over the next months when we are allowed to break the API. |
I don't know how you could do that with these many different possibilities and languages that "free" script users use! And I don't see the need for that either. If the API changes, then we have to add this changes to the textual scripts, that's the way it is. Of course we should coordinate together, as we are doing right now. I think we have to distinguish between the scripts compiled in the PaperUI and the free scripts that are used for testing purposes and innovations. The scripts in the PaperUI have to work relatively without any special attention to conventions. But I don't expect that from the free textual scripting part. Therefore my suggestion to have to activate the dynamic import of packages for experienced users first. So the not so experienced user does not get tangled up in the conventions of core java classes. At least that's how I think both approaches to scripts would be possible? |
The Jython setup includes a directory that is added to the classpath, where you can add external libraries. At runtime, you can also add jars using sys,path.append. I do not know if/how this can be done with the other scripting languages. I'm not sure if this is being suggested, but if OH does not make these classes available to scripted automation, the jars can still be added and the classes imported (at least for Jython). The libraries can be updated so that people's scripts work again. However, there are plenty of people who don't use the libraries, including people using scripted Actions/Conditions, that will need to make these updates on their own. So, it's possible, but VERY time consuming and tedious, and even more prone to breaking due to changes. It would be different if this was in preparation for OH3, but for now, IMO we should just put it back the way it was. If this is functionality that is going to be pulled in OH3, we can plan for it. Moving forward, pretty much all of the funcitonality provided by the helper libraries will be implemented as ModuleTypes and/or a scripting API. But even after that, my preference is to still leave the door open for experimentation and access to functionality where an abstraction layer has not yet been built. For a few days now, my production system has been on S1557 with an updated |
It would be nice if this would be fixed in the short term. I am waiting on a fix with my not working groovy rules. Imho, you should just fix this with dynamic imports asap (to restore functionality for people like me) and then implement a scripting api later on. |
My understanding has been that the package name changes of the automation part has been already a "big" breaking change and it is now a good time to address such technical stuff. |
The problem with this only is that nothing works as long as you have come up with a nice solution. Adding dynamic imports only restores the former state and can easily be reverted later on. Do you really think it is better for users to wait for a working version for a month without JSR rules instead of fixing the package names now and then adapt the rules to a new API in a month? |
@vbier Haven't I already comment that we could add dynamic imports now and break things later? |
Nothing, I just misread what you wrote. Adding dynamic imports now and then come up with a nice scripting api would be a good solution. |
@maggu2810 You need to press the "merge" button :D |
I will add my review and agree now, but it would be always nice if other maintainers use the review feature, too. At least for such decisions. |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/mqtt-2-binding-publish-action-with-jsr223-javascript/71417/6 |
I did some tidying up, corrected some of the classes that changed due to the ESH reintegration, and added a warning about using anything other than the official APIs (requested here... openhab/openhab-core#663 (comment)).
@maggu2810, I've added a warning into the JSR223 docs, and will add another in the openhab2-jython repo. Hopefully this addresses your immediate concern. Once #635 is merged and openhab2-addons/4801 is wrapped up (and another for Groovy), I will focus on rule Actions and a scripting API. |
I did some tidying up, corrected some of the classes that changed due to the ESH reintegration, and added a warning about using anything other than the official APIs (requested here... openhab/openhab-core#663 (comment)). Signed-off-by: Scott Rushworth openhab@5iver.com
I did some tidying up, corrected some of the classes that changed due to the ESH reintegration, and added a warning about using anything other than the official APIs (requested here... openhab/openhab-core#663 (comment)). Signed-off-by: Scott Rushworth <openhab@5iver.com>
I did some tidying up, corrected some of the classes that changed due to the ESH reintegration, and added a warning about using anything other than the official APIs (requested here... openhab/openhab-core#663 (comment)). Signed-off-by: Scott Rushworth <openhab@5iver.com>
I did some tidying up, corrected some of the classes that changed due to the ESH reintegration, and added a warning about using anything other than the official APIs (requested here... openhab/openhab-core#663 (comment)). Signed-off-by: Scott Rushworth <openhab@5iver.com>
This pull request has been mentioned on openHAB Community. There might be relevant details there: |
This pull request has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/latest-snapshot-that-runs-jython-properly/73880/2 |
…ns. (openhab#663) Signed-off-by: Confectrician <github@luckenba.ch>
Fixes #610. Discussed in #653.
Signed-off-by: Scott Rushworth openhab@5iver.com (github: openhab-5iver)