scheduled command job fails with "java.lang.IllegalStateException: A job is already in foreground"
Karaf 4.3.6 If more then one command is schedule to run in the foreground, the some of the command will fail to run with "java.lang.IllegalStateException: A job is already in foreground". Command that are scheduled to run in the background do not have this issue. Is this the intended behavior? Please update the documentation, https://karaf.apache.org/manual/latest/#_schedule_a_command, on running jobs in the background. Where job runs Command to schedule job --- --- Foreground scheduler:schedule-command --cron "0 0/1 * * * ?" "http:list" Background scheduler:schedule-command --cron "0 0/1 * * * ?" "http:list &" *** * Scheduling the commands to run in the foreground *** karaf@root()> scheduler:schedule-command --cron "0 0/1 * * * ?" "http:list" karaf@root()> scheduler:schedule-command --cron "0 0/1 * * * ?" "http:proxy-list" karaf@root()> scheduler:list Name │ Schedule ─┼── bugdataEmailReceiver.165 │ at(2022-05-16T12:22:05.378-04:00, -1, 30) http:proxy-list │ cron(0 0/1 * * * ?) http:list│ cron(0 0/1 * * * ?) karaf@root()> ID │ Servlet │ Servlet-Name │ State │ Alias │ Url ───┼──┼──┼─┼───┼─ 86 │ Whiteboard$1 │ cxf-servlet │ Deployed│ │ [/*] *** * karaf.log *** 13:40:00.023 WARN [Karaf_Worker-22] Error executing scheduled command http:proxy-list java.lang.IllegalStateException: A job is already in foreground at org.apache.felix.gogo.runtime.CommandSessionImpl$JobImpl.foreground(CommandSessionImpl.java:677) ~[?:?] at org.apache.felix.gogo.runtime.CommandSessionImpl$JobImpl.start(CommandSessionImpl.java:794) ~[?:?] at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:300) ~[?:?] at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:169) ~[?:?] at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:149) ~[?:?] at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:179) ~[?:?] at org.apache.karaf.shell.impl.console.ConsoleSessionImpl.execute(ConsoleSessionImpl.java:496) ~[?:?] at org.apache.karaf.scheduler.command.support.CommandJob.execute(CommandJob.java:40) [!/:?] at org.apache.karaf.scheduler.core.QuartzJobExecutor.execute(QuartzJobExecutor.java:58) [!/:?] at org.quartz.core.JobRunShell.run(JobRunShell.java:202) [!/:?] at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [!/:?] *** * Scheduling the commands to run in the background *** karaf@root()> scheduler:schedule-command --cron "0 0/1 * * * ?" "http:list &" karaf@root()> scheduler:schedule-command --cron "0 0/1 * * * ?" "http:proxy-list &" karaf@root()> [1] background http:proxy-list karaf@root()> URL │ ProxyTo │ Balancing Policy ┼─┼─ [1] donehttp:proxy-list karaf@root()> [1] background http:list karaf@root()> ID │ Servlet │ Servlet-Name │ State │ Alias │ Url ───┼──┼──┼─┼───┼─ 86 │ Whiteboard$1 │ cxf-servlet │ Deployed│ │ [/*] [1] donehttp:list
cut/paste error in the logger definition of the Scheduler's CommandJob?
Looks like a cut/paste error in the logger definition for Scheduler's CommandJob. https://github.com/apache/karaf/blob/main/scheduler/src/main/java/org/apache/karaf/scheduler/command/support/CommandJob.java public class CommandJob implements Job { private static final Logger LOGGER = LoggerFactory.getLogger(ScriptJob.class); Paul Spencer
Scheduled command fails with "session is closed" after client session closed.
Karaf 4.3.6 I have scheduled a command to run on a cron schedule, but the command fails with "java.lang.IllegalStateException: session is closed" after I exit the Karaf client session. The command will only run in the client session scheduling the command. Since command execution can be schedule, I would expect the client session scheduling the command would not be required for each execution. What is I doing wrong? *** * Command to schedule the execution of foo:emailReport at 5PM ** karaf@root()> scheduler:schedule-command --cron "0 0 17 * * ?" "foo:emailReport -r j...@example.com &" karaf@root()> scheduler:list Name │ Schedule ──┼─── foo:emailReport -r j...@example.com │ cron(0 0 17 * * ?) *** * karaf.log *** 2022-05-15T17:00:00,025 | WARN | Karaf_Worker-5 | ScriptJob | 80 - org.apache.karaf.scheduler.core - 4.3.6 | Error executing scheduled command foo:emailReport -r j...@example.com & java.lang.IllegalStateException: session is closed at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:171) ~[?:?] at org.apache.karaf.shell.impl.console.ConsoleSessionImpl.execute(ConsoleSessionImpl.java:496) ~[?:?] at org.apache.karaf.scheduler.command.support.CommandJob.execute(CommandJob.java:40) [!/:?] at org.apache.karaf.scheduler.core.QuartzJobExecutor.execute(QuartzJobExecutor.java:58) [!/:?] at org.quartz.core.JobRunShell.run(JobRunShell.java:202) [!/:?] at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [!/:?] 2022-05-15T17:03:41,930 | INFO | Karaf_Worker-6 | ServiceRequestEmailReceiver | 152 - com.alexanderpest.bugdata.msg-email-receiver - 2.0.2 | Message count = 554 karaf@root()> scheduler:list Name │ Schedule ──┼─── foo:emailReport -r j...@example.com & │ cron(0 0 17 * * ?) Paul Spencer
Re: How to preserve comments and property order in json configuration files?
Hi, Comments are conserved in property/cfg files (thanks to Felix Utils Properties), but I don't think I've implemented this in the JSON config support. Worth to create a jira as well :) Thanks, Regards JB On Mon, May 16, 2022 at 4:42 PM Paul Spencer wrote: > > Karaf 4.3.6 > > The OSGi specification mentions the support of comments in json configuration > files, > https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.configurator.html#d0e131566, > but the comments are stripped and the properties are reorder when a > configuration file is read. > > How can comments and property order in json configuration files be preserved? > > > > *** > * foo.json before config:property-list --pid foo > *** > { > // Network Port Number > "port":300, > > // Array of int > "an_int_array":[ 2, 3, 4 ], > > // Complex structure > "complex":{ > "a":1, > "b":"two" > } > } > > > *** > * foo.json after config:property-list --pid foo > *** > { > "an_int_array":[ > 2, > 3, > 4, > 5 > ], > "complex":"{\"a\":1,\"b\":\"two\"}", > "port":300 > } > > > Paul Spencer
Re: Setting a configuration parameter to null throws an NPE.
Hi Paul Yes, that's a good point. Can you please create a Jira about that, I will "bypass" property with null value. Thanks, Regards JB On Mon, May 16, 2022 at 3:47 PM Paul Spencer wrote: > > Karaf 4.3.6 > Setting a configuration parameter to null throws a NullPointerException. The > specification, > https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.configurator.html, > is silent on the use of null as a property value, but includes the following > "If a requested conversion cannot be performed, then the configuration is not > processed and the Configurator implementation should log an error."; in > addition the configuration parameter are stored in a Dictionary structure > which requires a non-null key and non-null value. > > Although the json format supports 'null' as value and OSGi confutation > appears to required non-null values, should Karaf log something like "Null > value for not supported." instead of throwing a NPE? > > *** > * Thrown exception > *** > > java.lang.NullPointerException: null > at > org.apache.karaf.config.core.impl.JsonConfigInstaller.setConfig(JsonConfigInstaller.java:87) > ~[?:?] > at > org.apache.karaf.config.core.impl.JsonConfigInstaller.update(JsonConfigInstaller.java:66) > ~[?:?] > at > org.apache.felix.fileinstall.internal.DirectoryWatcher.update(DirectoryWatcher.java:1117) > [!/:3.7.4] > at > org.apache.felix.fileinstall.internal.DirectoryWatcher.update(DirectoryWatcher.java:919) > [!/:3.7.4] > at > org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:488) > [!/:3.7.4] > at > org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365) > [!/:3.7.4] > at > org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316) > [!/:3.7.4] > > > *** > * etc/foo.json > *** > { >"myNullValue":null > } > > Paul Spencer
How to preserve comments and property order in json configuration files?
Karaf 4.3.6 The OSGi specification mentions the support of comments in json configuration files, https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.configurator.html#d0e131566, but the comments are stripped and the properties are reorder when a configuration file is read. How can comments and property order in json configuration files be preserved? *** * foo.json before config:property-list --pid foo *** { // Network Port Number "port":300, // Array of int "an_int_array":[ 2, 3, 4 ], // Complex structure "complex":{ "a":1, "b":"two" } } *** * foo.json after config:property-list --pid foo *** { "an_int_array":[ 2, 3, 4, 5 ], "complex":"{\"a\":1,\"b\":\"two\"}", "port":300 } Paul Spencer
Setting a configuration parameter to null throws an NPE.
Karaf 4.3.6 Setting a configuration parameter to null throws a NullPointerException. The specification, https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.configurator.html, is silent on the use of null as a property value, but includes the following "If a requested conversion cannot be performed, then the configuration is not processed and the Configurator implementation should log an error."; in addition the configuration parameter are stored in a Dictionary structure which requires a non-null key and non-null value. Although the json format supports 'null' as value and OSGi confutation appears to required non-null values, should Karaf log something like "Null value for not supported." instead of throwing a NPE? *** * Thrown exception *** java.lang.NullPointerException: null at org.apache.karaf.config.core.impl.JsonConfigInstaller.setConfig(JsonConfigInstaller.java:87) ~[?:?] at org.apache.karaf.config.core.impl.JsonConfigInstaller.update(JsonConfigInstaller.java:66) ~[?:?] at org.apache.felix.fileinstall.internal.DirectoryWatcher.update(DirectoryWatcher.java:1117) [!/:3.7.4] at org.apache.felix.fileinstall.internal.DirectoryWatcher.update(DirectoryWatcher.java:919) [!/:3.7.4] at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:488) [!/:3.7.4] at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365) [!/:3.7.4] at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316) [!/:3.7.4] *** * etc/foo.json *** { "myNullValue":null } Paul Spencer