Where can I find a working example of how to remotely invoke an OSGi service contained within Eclipse Virgo? - osgi

Can anyone point to a step-by-step tutorial on how to configure a remotely-accessible service contained within Eclipse Virgo 3.0x? I know that standards exist, etc., but I can find NO example which does not seem to contain a bunch of hand waving instead of specific steps along with working code/configurations to download. I don't care if the example uses Apache CXF, Eclipse ECF, or just about anything else. What I want is the equivalent of RMI in that both the transport and wire protocol are abstracted away behind what appears to both client and server-side developers as just plain Java (with some liberties taken).
Which bundles must be deployed into Virgo to support remoting? What Spring-ish configuration settings work? What jars must be on the client-side classpath? Etc, etc.?

I played around with Apache CXF DOSGI and got it working quite easily.
Download CXF single bundle distribution from here - I used 1.3.0.
Unzip Virgo (I used the kernel distribution for simplicity), copy CXF bundle to pickup, and start Virgo:
$ bin/startup.sh
[2012-04-04 14:17:33.011] startup-tracker <KE0001I> Kernel starting.
[2012-04-04 14:17:36.135] startup-tracker <KE0002I> Kernel started.
...
[2012-04-04 14:17:38.561] sync Event Dispatcher Thread <UR0001I> User region ready.
[2012-04-04 14:17:39.565] fs-watcher <HD0001I> Hot deployer processing 'INITIAL' event for file 'cxf-dosgi-ri-singlebundle-distribution-1.3.jar'.
[2012-04-04 14:17:40.060] fs-watcher <DE0000I> Installing bundle 'cxf-dosgi-ri-singlebundle-distribution' version '1.3.0'.
[2012-04-04 14:17:40.570] fs-watcher <DE0001I> Installed bundle 'cxf-dosgi-ri-singlebundle-distribution' version '1.3.0'.
[2012-04-04 14:17:40.593] fs-watcher <DE0004I> Starting bundle 'cxf-dosgi-ri-singlebundle-distribution' version '1.3.0'.
[2012-04-04 14:17:43.498] start-signalling-1 <DE0005I> Started bundle 'cxf-dosgi-ri-singlebundle-distribution' version '1.3.0'.
Install and run ZooKeeper server according to these instructions - I used 3.4.3. See also the ZooKeeper instructions including how to create a configuration file.
Create a file org.apache.cxf.dosgi.discovery.zookeeper.properties containing:
zookeeper.host = 127.0.0.1
and copy to pickup:
[2012-04-04 14:29:51.385] fs-watcher <HD0001I> Hot deployer processing 'CREATED' event for file 'org.apache.cxf.dosgi.discovery.zookeeper.properties'.
[2012-04-04 14:29:51.417] fs-watcher <DE0000I> Installing configuration 'org.apache.cxf.dosgi.discovery.zookeeper' version '0.0.0'.
[2012-04-04 14:29:51.428] fs-watcher <DE0001I> Installed configuration 'org.apache.cxf.dosgi.discovery.zookeeper' version '0.0.0'.
[2012-04-04 14:29:51.434] fs-watcher <DE0004I> Starting configuration 'org.apache.cxf.dosgi.discovery.zookeeper' version '0.0.0'.
[2012-04-04 14:29:51.439] fs-watcher <DE0005I> Started configuration 'org.apache.cxf.dosgi.discovery.zookeeper' version '0.0.0'.
Unzip another copy of Virgo kernel,copy the CXF bundle and org.apache.cxf.dosgi.discovery.zookeeper.properties into pickup, and start with a different JMX port:
$ bin/startup.sh -jmxport 9876
That's it, but to check that it's working, the remaining steps run the greeter sample...
Install/start the greeter interface and implementation bundles into the first Virgo instance. The simplest way is to copy the interface bundle to repository/usr and then copy the implementation bundle to pickup.
Install/start the greeter interface and client bundles into the second Virgo instance. The simplest way is to copy the interface bundle to repository/usr and then copy the client bundle to pickup.
When the "Invoke Remote Greeter Service" window appears, enter a string (e.g. "foo") into the Name field and click "Invoke".
The first Virgo instance shows the following trace log messages (in serviceability/logs/log.log):
Invoking: greetMe(foo)
The second Virgo instance shows the following trace log messages:
[2012-04-05 14:14:56.766] INFO Thread-29 System.out *** Invoking greeter ***
[2012-04-05 14:14:56.970] INFO Thread-29 System.out greetMe("foo") returns:
[2012-04-05 14:14:56.971] INFO Thread-29 System.out Hola foo
[2012-04-05 14:14:56.971] INFO Thread-29 System.out Bonjour foo
[2012-04-05 14:14:56.972] INFO Thread-29 System.out Hoi foo
[2012-04-05 14:14:56.972] INFO Thread-29 System.out Hello foo
[2012-04-05 14:14:56.972] INFO Thread-29 System.out *** Opening greeter client dialog ***
Look in the service registry of the second Virgo instance.
osgi> vsh:service examine 245
Properties:
endpoint.id:
http://localhost:9090/greeter
objectClass:
org.apache.cxf.dosgi.samples.greeter.GreeterService
service.id:
245
service.imported:
true
service.imported.configs:
org.apache.cxf.ws
Publisher: cxf-dosgi-ri-singlebundle-distribution 1.3.0 [84]
Consumer(s):
cxf-dosgi-ri-samples-greeter-client 1.2.0 [86]
A remote GreeterService has been published in the service registry.

This may not be precisely what you are looking for, but I have every reason to believe that the instructions in the Remote Services chapter in Enterprise OSGi in Action should work with Virgo.

Related

Karaf Bundle.getState() doesn't exactly match bundle's status in bundle:list

how does the karaf client's bundle:list command determine the bundles' states? When a bundle show "Failure" in bundle:list, programmatically running this bundle's getState() (to display on a gui) shows Active. Is there another api i can use to determine if the bundle is in Failure state? Karaf version is 4.1.5 although it shows on earlier versions too. Thanks.
I've had a similar situation. If you look at the Karaf sources for the bundle:list, you'll notice that they use org.apache.karaf.bundle.core.BundleInfo to get the state via org.apache.karaf.bundle.core.BundleService =>
org.apache.karaf.bundle.core.BundleInfo info = bundleService.getInfo(bundle.get());
info.getState();
More info: https://github.com/apache/karaf/blob/5144a1eba5687dab0f016a9bf95e58e6687a26ad/bundle/core/src/main/java/org/apache/karaf/bundle/command/List.java

OSGI bundle status grace period

I am trying to install two bundles on Karaf. For one of the bundle i am getting error and when I see the bundle:diag i got below message. It is the same thing compaining in logs also. Similar kind of bundle already deploy and it has the same dependencies. first one is working but the for second bundle i am getting below error. any thoughts?
opendaylight-user#root>bundle:diag
videoweb (421)
Status: GracePeriod
Blueprint
2/10/16 6:07 PM
Missing dependencies:
(objectClass=org.osgi.service.http.HttpService)
2016-02-10 23:54:07.113 GMT+00:00 [Blueprint Extender: 3] ERROR o.a.a.b.c.BlueprintContainerImpl - Unable to start blueprint container for bundle com.xyz.videosdn.tesweb due to unresolved dependencies [(objectClass=org.osgi.service.http.HttpService)]
java.util.concurrent.TimeoutException: null
at org.apache.aries.blueprint.container.BlueprintContainerImpl$1.run(BlueprintContainerImpl.java:336) [org.apache.aries.blueprint.core:1.4.0]
at org.apache.aries.blueprint.utils.threading.impl.DiscardableRunnable.run(DiscardableRunnable.java:48) [org.apache.aries.blueprint.core:1.4.0]
The error means that your bundle has a mandatory reference to a service with the interface org.osgi.service.http.HttpService.
So you need to install a bundle that provides this service. In karaf this service is normally provided by pax-web. It can be installed using:
feature:install http

karaf 3.0.1 not starting up

I'm trying to start karaf 3.0.1 in a solaris box (without internet) but getting the following error:
karaf: Ignoring predefined value for KARAF_HOME
Could not resolve mvn:org.eclipse/org.eclipse.osgi/3.8.2.v20130124-134944
and in karaf.log:
Jun 30, 2014 12:21:09 PM org.apache.karaf.main.Main main
SEVERE: Could not launch framework
java.lang.RuntimeException: Could not resolve mvn:org.eclipse/org.eclipse.osgi/3.8.2.v20130124-134944
at org.apache.karaf.main.util.SimpleMavenResolver.resolve(SimpleMavenResolver.java:59)
at org.apache.karaf.main.Main.createClassLoader(Main.java:315)
at org.apache.karaf.main.Main.launch(Main.java:234)
at org.apache.karaf.main.Main.main(Main.java:171)
the bundles are well in place (system folder) and the org.ops4j.pax.url.mvn.cfg file states:
org.ops4j.pax.url.mvn.repositories=\
file:${karaf.home}/${karaf.default.repository}#id=system.repository, \
file:${karaf.data}/kar#id=kar.repository#multi\
http://repo1.maven.org/maven2#id=central,\
http://repository.springsource.com/maven/bundles/release#id=spring.ebr.release,\
http://repository.springsource.com/maven/bundles/external#id=spring.ebr.external
I've tried running the framework using the three methods (server, service, client) but nothing seems to be working.
my environment is:
KARAF_BASE=/export/home/mehdi/bin/karaf
KARAF_HOME=/export/home/mehdi/bin/karaf
KARAF_ETC=/export/home/mehdi/bin/karaf/etc
KARAF_DATA=/export/home/mehdi/bin/karaf/data
JAVA_HOME=/opt/temp/jre1.7.0_13
I googled a bit and found a workaround which says to add -h 127.0.0.1 to the client script, but still nothing.

ServiceMix bundle status is "Active" even though bundle deployment fails

I have (intentionally created situation to test my CI setup) a bundle which does not have all dependencies configured correctly. When I deploy that the deployment fails with an exception as it should:
2014-02-07 09:17:15,738 | ERROR | rint Extender: 3 | BlueprintCamelContext | 103 - org.apache.camel.camel-blueprint - 2.10.7 | Error occurred during starting Camel: CamelContext(ura) due "org.xmlsoap.schemas.soap.envelope" doesnt contain ObjectFactory.class or jaxb.index
javax.xml.bind.JAXBException: "org.xmlsoap.schemas.soap.envelope" doesnt contain ObjectFactory.class or jaxb.index
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.7.0_11]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)[:1.7.0_11]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.7.0_11]
at java.lang.reflect.Method.invoke(Method.java:601)[:1.7.0_11]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:143)[89:org.apache.servicemix.specs.jaxb-api-2.2:2.2.0]
at javax.xml.bind.ContextFinder.find(ContextFinder.java:310)[89:org.apache.servicemix.specs.jaxb-api-2.2:2.2.0]
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:412)[89:org.apache.servicemix.specs.jaxb-api-2.2:2.2.0]
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:375)[89:org.apache.servicemix.specs.jaxb-api-2.2:2.2.0]
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:279)[89:org.apache.servicemix.specs.jaxb-api-2.2:2.2.0]
at org.apache.camel.dataformat.soap.SoapJaxbDataFormat.createContext(SoapJaxbDataFormat.java:303)[206:org.apache.camel.camel-soap:2.10.7]
at org.apache.camel.converter.jaxb.JaxbDataFormat.doStart(JaxbDataFormat.java:254)[187:org.apache.camel.camel-jaxb:2.10.7]
at org.apache.camel.dataformat.soap.SoapJaxbDataFormat.doStart(SoapJaxbDataFormat.java:101)[206:org.apache.camel.camel-soap:2.10.7]
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)[100:org.apache.camel.camel-core:2.10.7]
at org.apache.camel.util.ServiceHelper.startService(ServiceHelper.java:62)
The problem is that the bundle status is still "Active". Why?
karaf#root> osgi:list
START LEVEL 100 , List Threshold: 50
ID State Blueprint Spring Level Name
[ 242] [Active ] [Created ] [ ] [ 80] integraatiot-foo (1.0.0.SNAPSHOT)
I would like to setup my CI builds to that they detect failed bundles using http://code.citytechinc.com/osgi-bundle-status-maven-plugin/. This idea fails since bundle status is always "Active".
The bundle is active because it has been activated. This is normal. If an error occurred in some code within the bundle, that is nothing to do with the OSGi active state.
So you need to work out some way to report your internal failure such that it can be picked up by a CI build. I suggest using the OSGi LogService.
You'll need to make sure all your dependencies are required and with the correct version.
In this case it might be that the package your importing does existing in the wrong version.
Or better did you make sure you only import the right version of the package with [2,3.0) for example. Especially the stack trace makes it suspicious to me that your using import without version range and therefore do import the JRE jaxb classes which usually do have version 0.0.0
To check which bundles are actually used for import log in the shell and do a bundle:header [bundleID]

Running rake task from within war file

My code base initially was written in ruby. It had a rakefile.rb file to perform db migration. I later changed the whole thing to jruby for the ease of deployment which works fine. Only problem I am facing is how to run my rake task (to perform db migrations).
I tried
java -jar GV_S.war -S rake db_migrate[1]
with 1 being the version but this didn't work.
this gave me :
[Winstone 2012/03/23 18:04:56] - Beginning extraction from war file
[Winstone 2012/03/23 18:04:56] - WARNING: The Servlet 2.4/2.5 spec XSD was unavailable inside the winstone classpath. Will be retrieved from the web if required (slow)
[Winstone 2012/03/23 18:04:56] - No webapp classes folder found - /tmp/winstone6913591014121608835webroot/GV_S.war/WEB-INF/classes
[webapp 2012/03/23 18:04:57] - jruby 1.6.7 (ruby-1.9.2-p312) (2012-02-22 3e82bc8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_26) [linux-amd64-java]
[Winstone 2012/03/23 18:05:03] - Listener winstone.ajp13.Ajp13Listener not found / disabled - ignoring
[Winstone 2012/03/23 18:05:03] - Listener winstone.ssl.HttpsListener not found / disabled - ignoring
[Winstone 2012/03/23 18:05:03] - Winstone Servlet Engine v0.9.10 running: controlPort=disabled
[Winstone 2012/03/23 18:05:03] - HTTP Listener started: port=8080
Any help 'll be appreciated
-Thanks
this seems not yet supported by warbler - executing jruby style commads works with an executable .jar but making a .war executable only allows it to run with an embed web server ... nothing else.
Finally found something that works.... i first tried
java -jar lib/jruby-complete-1.6.7.jar -S rake db_migrate[1]
which was working fine on my personal machine but giving me something like the message below on production
rake aborted!
cannot load Java class com.mysql.jdbc.Driver
Tasks: TOP => db_migrate
(See full trace by running task with --trace)
this was because i was using gems like sequel, logger etc inside my rake task.... i head those installed on my machine but not on production machine.... installing those gems on production was not an option.... so i installed the gems required in the rake task in a separate directory and converted it into a jar file( http://blog.nicksieger.com/articles/2009/01/10/jruby-1-1-6-gems-in-a-jar)... this command finally worked...
java -jar lib/jruby-complete-1.6.7.jar -rlib/mygems.jar -S rake db_migrate[1]
point to note: no matter where you place the jar file, warbler 'll always send this to lib directory although you 'll still see a dummy jar file at the original location...
i think the solution can be a bit neater if worked out in a couple of ways, although haven't tried this....
i>by including the gem files in jruby-complete-1.6.7.jar itself as mentioned in the blog mentioned above...
java -jar lib/jruby-complete-1.6.7.jar -S rake db_migrate[1]
should work then...
ii>by writing some kind of a manifest file and include it in the mygems.jar to make this run independently... if this happens
java -jar myapp.jar -S rake db_migrate[1]
should work

Resources