3 Replies Latest reply on Oct 25, 2013 12:26 AM by henrique.viecili

    How to osgi:update a bundle without knowing its ID?

    henrique.viecili

      I'm writing some automated deployed scripts and I would like to update a specific bundle but I am not able to determine its ID. (I'm not using Fabric)

       

      My features file looks like this:

      <features name="my-features-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.0.0">
        <feature name="my-feature" version="${project.version}">
          <bundle>mvn:com.example.features/my-feature/${project.version}</bundle>
        </feature>
      </features>
      

       

      After the feature is installed and once my automated build process kick in, it needs to update the bundle. Is there a tool that given a feature name (or maybe a Bundle-SymbolicName) updates the related bundles?

       

      Regards,

      Henrique Viecili

        • 1. Re: How to osgi:update a bundle without knowing its ID?
          davsclaus

          The osgi:update command can take the synbolic name as well, so you can use that.

          JBossFuse:karaf@root> update --help

          DESCRIPTION

                  osgi:update

           

           

            Update bundle.

           

           

          SYNTAX

                  osgi:update [options] id [location]

           

           

          ARGUMENTS

                  id

                          The bundle ID or name or name/version

                  location

                          The bundles update location

           

           

          OPTIONS

                  --help

                          Display this help message

                  --force

                          Forces the command to execute

          And if you are not sure what the name is you can do a list -s to show the names.

          1 of 1 people found this helpful
          • 2. Re: Re: How to osgi:update a bundle without knowing its ID?
            henrique.viecili

            Hi Claus,

             

            the osgi:update from the Fuse/Karaf console works well with the symbolic name (Bundle-SymbolicName = my-feature), but when I run it remotely (Line 04) from my jenkins job I get the following exception:

             

            2013-10-25 11:46:15,264 | INFO  | NioProcessor-3   | ServerSession                    | ?                                   ? | 32 - org.apache.sshd.core - 0.8.0 | Session created from /10.1.10.114:48034
            2013-10-25 11:46:15,383 | INFO  | NioProcessor-3   | ServerSession                    | ?                                   ? | 32 - org.apache.sshd.core - 0.8.0 | Session fuseadmin@/10.1.10.114:48034 authenticated
            2013-10-25 11:46:15,395 | INFO  | NioProcessor-3   | ChannelSession                   | ?                                   ? | 32 - org.apache.sshd.core - 0.8.0 | Executing command: features:addurl mvn:com.example.features/my-feature//xml/features; features:refreshurl
            2013-10-25 11:46:20,607 | INFO  | NioProcessor-3   | ChannelSession                   | ?                                   ? | 32 - org.apache.sshd.core - 0.8.0 | Executing command: features:install my-feature; sleep 5000; osgi:update my-feature
            2013-10-25 11:46:42,040 | INFO  | NioProcessor-3   | SleepAction                      | ?                                   ? | 15 - org.apache.karaf.shell.console - 2.3.0.redhat-60024 | Sleeping for 5000 millisecond(s)
            2013-10-25 11:46:47,041 | INFO  | NioProcessor-3   | SleepAction                      | ?                                   ? | 15 - org.apache.karaf.shell.console - 2.3.0.redhat-60024 | Awake now
            2013-10-25 11:46:47,065 | INFO  | NioProcessor-3   | ShellCommandFactory              | ?                                   ? | 26 - org.apache.karaf.shell.ssh - 2.3.0.redhat-60024 | Exception caught while executing command
            org.apache.felix.gogo.commands.CommandException: Unable to convert argument id with value 'my-feature' to type long
                    at org.apache.felix.gogo.commands.basic.DefaultActionPreparator.prepare(DefaultActionPreparator.java:381)
                    at org.apache.felix.gogo.commands.basic.AbstractCommand.execute(AbstractCommand.java:34)
                    at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:78)[15:org.apache.karaf.shell.console:2.3.0.redhat-60024]
                    at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:474)[15:org.apache.karaf.shell.console:2.3.0.redhat-60024]
                    at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:400)[15:org.apache.karaf.shell.console:2.3.0.redhat-60024]
                    at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)[15:org.apache.karaf.shell.console:2.3.0.redhat-60024]
                    at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)[15:org.apache.karaf.shell.console:2.3.0.redhat-60024]
                    at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)[15:org.apache.karaf.shell.console:2.3.0.redhat-60024]
                    at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:89)[15:org.apache.karaf.shell.console:2.3.0.redhat-60024]
                    at org.apache.karaf.shell.ssh.ShellCommandFactory$ShellCommand$1.run(ShellCommandFactory.java:116)[26:org.apache.karaf.shell.ssh:2.3.0.redhat-60024]
                    at java.security.AccessController.doPrivileged(Native Method)[:1.7.0_25]
                    at org.apache.karaf.jaas.modules.JaasHelper.doAs(JaasHelper.java:67)[29:org.apache.karaf.jaas.modules:2.3.0.redhat-60024]
                    at org.apache.karaf.shell.ssh.ShellCommandFactory$ShellCommand.start(ShellCommandFactory.java:114)[26:org.apache.karaf.shell.ssh:2.3.0.redhat-60024]
                    at org.apache.sshd.server.channel.ChannelSession.handleExec(ChannelSession.java:388)[32:org.apache.sshd.core:0.8.0]
                    at org.apache.sshd.server.channel.ChannelSession.handleRequest(ChannelSession.java:235)[32:org.apache.sshd.core:0.8.0]
                    at org.apache.sshd.server.channel.ChannelSession.handleRequest(ChannelSession.java:195)[32:org.apache.sshd.core:0.8.0]
                    at org.apache.sshd.common.session.AbstractSession.channelRequest(AbstractSession.java:1057)[32:org.apache.sshd.core:0.8.0]
                    at org.apache.sshd.server.session.ServerSession.running(ServerSession.java:229)[32:org.apache.sshd.core:0.8.0]
                    at org.apache.sshd.server.session.ServerSession.handleMessage(ServerSession.java:205)[32:org.apache.sshd.core:0.8.0]
                    at org.apache.sshd.common.session.AbstractSession.decode(AbstractSession.java:566)[32:org.apache.sshd.core:0.8.0]
                    at org.apache.sshd.common.session.AbstractSession.messageReceived(AbstractSession.java:236)[32:org.apache.sshd.core:0.8.0]
                    at org.apache.sshd.common.AbstractSessionIoHandler.messageReceived(AbstractSessionIoHandler.java:58)[32:org.apache.sshd.core:0.8.0]
                    at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.messageReceived(DefaultIoFilterChain.java:690)[35:org.apache.mina.core:2.0.7]
                    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:417)[35:org.apache.mina.core:2.0.7]
                    at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:47)[35:org.apache.mina.core:2.0.7]
                    at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:765)[35:org.apache.mina.core:2.0.7]
                    at org.apache.mina.core.filterchain.IoFilterAdapter.messageReceived(IoFilterAdapter.java:109)[35:org.apache.mina.core:2.0.7]
                    at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:417)[35:org.apache.mina.core:2.0.7]
                    at org.apache.mina.core.filterchain.DefaultIoFilterChain.fireMessageReceived(DefaultIoFilterChain.java:410)[35:org.apache.mina.core:2.0.7]
                    at org.apache.mina.core.polling.AbstractPollingIoProcessor.read(AbstractPollingIoProcessor.java:710)[35:org.apache.mina.core:2.0.7]
                    at org.apache.mina.core.polling.AbstractPollingIoProcessor.process(AbstractPollingIoProcessor.java:664)[35:org.apache.mina.core:2.0.7]
                    at org.apache.mina.core.polling.AbstractPollingIoProcessor.process(AbstractPollingIoProcessor.java:653)[35:org.apache.mina.core:2.0.7]
                    at org.apache.mina.core.polling.AbstractPollingIoProcessor.access$600(AbstractPollingIoProcessor.java:67)[35:org.apache.mina.core:2.0.7]
                    at org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:1124)[35:org.apache.mina.core:2.0.7]
                    at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64)[35:org.apache.mina.core:2.0.7]
                    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)[:1.7.0_25]
                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)[:1.7.0_25]
                    at java.lang.Thread.run(Thread.java:724)[:1.7.0_25]
            Caused by: java.lang.NumberFormatException: For input string: "my-feature"
                    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)[:1.7.0_25]
                    at java.lang.Long.parseLong(Long.java:441)[:1.7.0_25]
                    at java.lang.Long.valueOf(Long.java:540)[:1.7.0_25]
                    at org.apache.aries.blueprint.container.AggregateConverter.convertFromString(AggregateConverter.java:285)
                    at org.apache.aries.blueprint.container.AggregateConverter.convert(AggregateConverter.java:174)
                    at org.apache.karaf.shell.console.commands.BlueprintCommand$BlueprintActionPreparator.convert(BlueprintCommand.java:88)
                    at org.apache.felix.gogo.commands.basic.DefaultActionPreparator.prepare(DefaultActionPreparator.java:377)
                    ... 37 more
            2013-10-25 11:46:47,227 | INFO  | NioProcessor-3   | ServerSession                    | ?                                   ? | 32 - org.apache.sshd.core - 0.8.0 | Session fuseadmin@/10.1.10.114:48034 closed
            

             

            Is there something else I could try?

            • 3. Re: Re: Re: How to osgi:update a bundle without knowing its ID?
              henrique.viecili

              So... after going to the darkest corners of Apache Karaf documentation, I've found this http://repo1.maven.org/maven2/org/apache/karaf/manual/2.3.1/manual-2.3.1.html , more specifically the section called "Using remote instances" with a small code example.

               

              After tinkering a little bit I came up with this script (as a file named deploy-feature.fsh inside $KARAF_HOME/scripts):

              # define helper functions
              bundles = $.context bundles ;
              bundle-by-sn = { bm = new java.util.HashMap ;  each ($bundles) { $bm put ($it symbolicName) $it } ; $bm get $1 }
              bundle-id-by-sn = { b = (bundle-by-sn $1) ; if { $b } { (($b bundleid) toString) } { -1 } }
              
              
              echo "Installing "$1" ..."
              features:install $1
              echo "Installed. ("$1")"
              sleep 5000
              echo "Updating "$1" ..."
              osgi:update --force (bundle-id-by-sn $1)
              echo "Done. ("$1")"
              
              
              
              

               

              now from my remote jenkins job I can execute:

              shell:source scripts/deploy-feature.fsh my-feature

               

              Cheers,

              Henrique Viecili