[SOLVED] Jython on docker?

@5iver thanks, that helped

(I wish instalation of “future” rule engine is not that tedious as it is now …)

1 Like

Rule engines are easy. Script engines are currently complex but will be made as simple as an addon… that’s my next major effort to wrap up.

so is it worth to tinker with it now, or shall I better wait for OH addon? :slight_smile:

I meant a Jython script engine add-on that will simplify the installation. If you are running then play! Shout if you need anything! The Jython add-on could take months.

ye, it seems to having bad times on 2.5M3 Docker…

2019-09-30 23:48:46.656 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'javascript/core/000_startup_delay.js'
2019-09-30 23:49:17.795 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'python/core/000_startup_delay.py'
2019-09-30 23:49:49.310 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'python/core/components/100_DirectoryTrigger.py'
2019-09-30 23:49:51.427 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/100_DirectoryTrigger.py': ImportError: No module named configuration in <script> at line number 21
2019-09-30 23:49:51.429 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'python/core/components/100_OsgiEventTrigger.py'
2019-09-30 23:49:53.458 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/100_OsgiEventTrigger.py': ImportError: No module named configuration in <script> at line number 17
2019-09-30 23:49:53.460 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'python/core/components/100_StartupTrigger.py'
2019-09-30 23:49:55.243 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/100_StartupTrigger.py': ImportError: No module named configuration in <script> at line number 16
2019-09-30 23:49:55.244 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'python/core/components/200_JythonBindingInfoProvider.py'
2019-09-30 23:49:56.849 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/200_JythonBindingInfoProvider.py': ImportError: No module named configuration in <script> at line number 19
2019-09-30 23:49:56.850 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'python/core/components/200_JythonExtensionProvider.py'
2019-09-30 23:49:58.780 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/200_JythonExtensionProvider.py': ImportError: No module named configuration in <script> at line number 29
2019-09-30 23:49:58.781 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'python/core/components/200_JythonItemChannelLinkProvider.py'
2019-09-30 23:50:00.734 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/200_JythonItemChannelLinkProvider.py': ImportError: No module named configuration in <script> at line number 18
2019-09-30 23:50:00.743 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'python/core/components/200_JythonItemProvider.py'
2019-09-30 23:50:02.702 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/200_JythonItemProvider.py': ImportError: No module named configuration in <script> at line number 10
2019-09-30 23:50:02.708 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'python/core/components/200_JythonThingProvider.py'
2019-09-30 23:50:04.609 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/200_JythonThingProvider.py': ImportError: No module named configuration in <script> at line number 17
2019-09-30 23:50:04.610 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'python/core/components/200_JythonThingTypeProvider.py'
2019-09-30 23:50:06.439 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/200_JythonThingTypeProvider.py': ImportError: No module named configuration in <script> at line number 17
2019-09-30 23:50:06.441 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'python/core/components/200_JythonTransform.py'
2019-09-30 23:50:07.942 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/core/components/200_JythonTransform.py': ImportError: No module named configuration in <script> at line number 19
2019-09-30 23:50:07.951 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'python/personal/hello_world.py'
2019-09-30 23:50:11.207 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/openhab/conf/automation/jsr223/python/personal/hello_world.py': ImportError: No module named configuration in <script> at line number 5

not sure if it’s worth debugging, still feels quite rough for production use

You need to follow all the steps in the installation instructions. Your issue is at step 8 (rename /automation/lib/python/configuration.py.example). It looks like the docker docs need an update.

ah havent followed core instalation when on docker… will give it a shot in the evening. Thanks!

works now., thank you very much

anyway, running hello_world.py generates every 10second event.log as follows

2019-10-01 17:49:20.937 [.event.RuleStatusInfoEvent] - aa44f76f-814b-4a51-9f80-177a79c484fe updated: RUNNING
2019-10-01 17:49:20.939 [.event.RuleStatusInfoEvent] - aa44f76f-814b-4a51-9f80-177a79c484fe updated: IDLE
2019-10-01 17:49:30.938 [.event.RuleStatusInfoEvent] - aa44f76f-814b-4a51-9f80-177a79c484fe updated: RUNNING
2019-10-01 17:49:30.941 [.event.RuleStatusInfoEvent] - aa44f76f-814b-4a51-9f80-177a79c484fe updated: IDLE
2019-10-01 17:49:40.938 [.event.RuleStatusInfoEvent] - aa44f76f-814b-4a51-9f80-177a79c484fe updated: RUNNING
2019-10-01 17:49:40.940 [.event.RuleStatusInfoEvent] - aa44f76f-814b-4a51-9f80-177a79c484fe updated: IDLE
2019-10-01 17:49:50.940 [.event.RuleStatusInfoEvent] - aa44f76f-814b-4a51-9f80-177a79c484fe updated: RUNNING
2019-10-01 17:49:50.941 [.event.RuleStatusInfoEvent] - aa44f76f-814b-4a51-9f80-177a79c484fe updated: IDLE

but nothing in openhab.log eg. “Hello World!”

Where should be this entry found please? Or have I messed up something else ?

Thanks

Looks like you’re in the events.log… take a look in the openhab.log.

yes …

Check the installation instructions again. Did you set the logger?

what do you mean?
I should follow core instalation step by step for docker image?
what about karaf console as in docker there is no port 8101 exposed

You could setup Karaf for ssh, but it’s easier to use the $OPENHAB_RUNTIME/bin/client script. Another option is to edit the $OPENHAB_USERDATA/etc/org.ops4j.pax.logging.cfg file and manually add the logger.

Both are detailed in the OH documentation.

@marcel_erkel, could you please help kriznik?

that worked even in docker, thanks!
all is now working

1 Like

@kriznik

Good to see that you got it working. I was typing the following, so for future reference should anyone stumble on this while searching.

In $OPENHAB_CONF/automation/lib/python/configuration.py change the default LOG_PREFIX to:

LOG_PREFIX = "org.openhab.automation.jsr223.jython"

To access the the karaf console you can enter the container:

docker exec -ti <your-openhab-container-name> /bin/bash

and execute

/openhab/runtime/bin/client

or execute the client using:

docker exec -ti <your-openhab-container-name> /openhab/runtime/bin/client

@marcel_erkel yeah, client did the trick. I guess docs would need some update here and there to get it sorted for wide crowd of people :wink:

just for my curiosity… what’s benefits of jsr over dsl?
Am not judging anything, but tinkering with very common example of Time Of Day (DP): DSL and JSR

  1. DSL version is shorter (40ish lines vs. 60ish + config)
  2. DSL version looks way lighter in terms of cpu usage
  • dsl takes 1 core at max 20% for second
  • jsr takes 2 cores at 74% and 80% for 2seconds
  1. DSL version is much more user friendlier in terms of “programming skills” – which can be solved by some kind of GUI sure.
    and this being said by someone who programs in python quite often, this jython feels bit messy especially at the begining where you need to know what to import from where somehow
  2. instalation and configuration is simply not yet there, yes can be done, but it’s not really straight and not for regular Joe at least.

This is not indeed exact, but … what’s the deal here?

no flame, just genuine question

I feel limited by the DSL. Jython gives me the option to use functions, classes, add python libraries using pip. It’s much more normal programming.

Code reuse also is much simpler:


(I probably need to update that topic due to the changes since 2.5.0.M1)

I don’t really know the ToD implementations so I can’t comment on why the DSL version uses less lines of code than the Jython version and why it apparently uses more CPU (there is a thread here on the forum which shows the opposite… I don’t really care as long as I don’t notice it).

When using the official openHAB Docker container, all that is needed to install Jython and the openHAB helper libraries is to download two files to the /etc/cont-init.d directory and restart the container. It doesn’t get much simpler than that (this is PR Scott referenced).

But if you prefer the DSL that’s fine with me :slight_smile:

yeah I clearly get some advantages of having ability to import stuff and use whole programming environment as such… but if we take OH rules as something what should drive internal stuff, I don’t see much need for it. eg. yes for programmers which likes to tinker around the code all the time.
But for non-programming people this looks bit harsh. Different story would be if there will be some intuitive gui on top of that maybe.

What I was really surprised is how it performed to achieve very same stuff, where dsl in my test case was more than twice as fast as jsr.
And frankly, working with classes is not for everyone, reusable code is nice, but usual OH implemetantion probably does not normally need it anyways.

anyway, beside documentation and some stuff on this forum, where I can find out which parts of OH engine should I import to work with items, triggers, rules, states etc.? is there anywhere some kind of complex doc or is it something which is currently work in progress?

as I said, I would like to give it a shot, as I know python well. Yet jython feels bit ugly for me still, so I guess need to give it some time.

I use Python elsewhere without classes. I expect I can use Jython too but I just installed it last night and have not yet tried it.

1 Like

sure, you indeed can