bundle not resolved due to pax-jdbc while provisioning in karaf

21 views
Skip to first unread message

Kushal Gautam

unread,
May 8, 2019, 5:00:00 PM5/8/19
to OPS4J
Hi:

I have a bundle that depends on two different data sources; and broker as well. 

The bundle starts properly if I copy the osgi bundle into deploy folder or install it using bundle:install <location>. Installing the bundle this way works perfectly fine without any glitch.

Instead, I tried to install it as a feature as:

<feature name="stats-mbean" description="Stats MBEAN" version="1.0.0">
       
<bundle>file:D:/temp/stats-mbean-1.0.0.jar</bundle>
</feature>


I have created the datasources from "etc/org.ops4j.datasource-*.cfg" config files.

I have included the feature, and when I try to install the feature, I get the following error.

[caused by: Unable to resolve stats-mbean/1.0.0: missing requirement [stats-mbean/1.0.0] osgi.service; effective:=active; filter:="(&(objectClass=javax.sql.DataSource)(osgi.jndi.service.name=dw-datasource))"]]




I have referenced the datasource in my bundle's blueprint as:

<reference id="dw" interface="javax.sql.DataSource" filter="(osgi.jndi.service.name=dw-datasource)" />



I have tried several stuffs, but I am unable to resolve this issue. Strange thing is, I am able to start the same bundle if I install it manually (copy to deploy folder or bundle:install)..

I am not entirely sure if this is an issue of pax-jdbc. If so, do I need to handle such cases specifically in the bundle pom or feature configuration?

Any insights on this would be very helpful.

Regards,
Kushal.

Grzegorz Grzybek

unread,
May 9, 2019, 2:02:01 AM5/9/19
to op...@googlegroups.com
Hello

file:// protocol and d:\ kind of paths are always confusing and unintuitive. Did you try using mvn: URIs just as all Karaf features do?
Can you share the logs from the moment you installed the features?

regards
Grzegorz Grzybek

--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/9af972cd-1d8d-42ec-9506-889d417e6c5c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jean-Baptiste Onofré

unread,
May 9, 2019, 2:06:14 AM5/9/19
to op...@googlegroups.com

Hi,

Clearly, the filter doesn't match. I would recommend to try to change the filter, using name instead of jndi name. I hope you installed jndi feature to use jndi name ?

Regards
JB

Jean-Baptiste Onofré

unread,
May 9, 2019, 2:07:39 AM5/9/19
to op...@googlegroups.com

By the way, did you check you don't have a race condition like you start the bundle (installing the feature) whereas the datasource service is not yet there ?

As workaround you can define the service ref as optional, it will reload once the service is there.

Regards
JB

On 08/05/2019 23:00, Kushal Gautam wrote:

Kushal Gautam

unread,
May 9, 2019, 3:37:00 AM5/9/19
to op...@googlegroups.com
Hi:

I agree about using the file:// protocol and its clumsiness. But, I had to do this without an artifact repository, and considering all the situations (w/o artifacto repo and windows env.), JB suggested that I could use file:// to install the bundles. This works pretty well for bundles that do not have jdbc as their dependencies. I had similar issues with jms as well. But, thanks to the discussion on http://karaf.922171.n3.nabble.com/Features-Core-bundle-stuck-in-quot-Resolved-quot-state-td4047964.html, it got resolved.

There's not much in the logs. May be, I will try to set the logging level to debug and see, and I will post back.

Regards,
Kushal.

Kushal Gautam

unread,
May 9, 2019, 3:53:10 AM5/9/19
to op...@googlegroups.com
Hi again JB to the other side of the world ;)

before installing this feature, I have my Datasources available, and I can see them in service:list DataSource, and I can also query them via jdbc: commands.

Thank you for your inputs.

I just tried with availability="optional" in a fresh karaf instance (as karaf was trying to load the same old jar even though I had replaced it numerous times).

And, this thing worked, just like that. I did not change any specific parameters related to service filters.

So, the issue could have been resolved, may be with availability="optional". I will try to reproduce this.

Your inputs were valuable. Thanks again. :)

Regards,
Kushal.


Kushal Gautam

unread,
May 9, 2019, 4:55:49 AM5/9/19
to op...@googlegroups.com
Hi JB:

just to confirm that availability="optional" in the service reference did the trick. Also, one of the crazy issues was the caching, which loaded the same old jar again and again (even though I had refreshed and replaced the jar). I did try with feature:repo-refresh and tried reboot as well. But, the issue with caching persisted. I had to try in a whole new container.

Thank you for your help. Finally, I have a workaround to this issue.

Regards,
Kushal.

On Thu, May 9, 2019 at 8:07 AM Jean-Baptiste Onofré <jeanbapti...@gmail.com> wrote:

Jean-Baptiste Onofré

unread,
May 9, 2019, 5:06:50 AM5/9/19
to op...@googlegroups.com

Hi,

Ok, that's weird, it means that your bundle is starting before the DataSource service is available for sure.

Regards
JB

Kushal Gautam

unread,
May 9, 2019, 5:23:54 AM5/9/19
to OPS4J
yes, that's very confusing.

As I said earlier, that I verified the existence of datasource before installing the feature. Could it be because of the pooled connection?

Regards,
Kushal.
To unsubscribe from this group and stop receiving emails from it, send an email to op...@googlegroups.com.
--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to op...@googlegroups.com.
--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to op...@googlegroups.com.

Christian Schneider

unread,
May 9, 2019, 4:45:49 PM5/9/19
to op...@googlegroups.com
I dont think this is a race condition.

Is it possible that your bundle has a requirement for the service and that pax-jdbc does not provide a suitable capability.
(As pax-jdbc creates the DataSources from config there is no way how it could provide the capability).

The reason why it might work with optional is that then there is no mandatory requirement.

Does it help when you set 
serviceRequirements=default
in the file org.apache.karaf.features.cfg ?

Christian

--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.


--
--
Christian Schneider

http://www.liquid-reality.de

Computer Scientist

Jean-Baptiste Onofré

unread,
May 10, 2019, 1:28:30 AM5/10/19
to op...@googlegroups.com

Hi,

I guess your bundle contains Requirement in META-INF/MANIFEST. Did you check the feature providing the DataSource provides the Capability ?

Regards
JB

To unsubscribe from this group and stop receiving emails from it, send an email to ops4j+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ops4j/5a666810-4e57-4f91-81a4-0e2c43da9f21%40googlegroups.com.

Christian Schneider

unread,
May 10, 2019, 2:32:21 AM5/10/19
to op...@googlegroups.com
Oh ..sorry .. I meant
serviceRequirements=disable

Christian

Kushal Gautam

unread,
May 10, 2019, 3:14:45 AM5/10/19
to op...@googlegroups.com
Hi:

Thank you for the tip.

well, setting serviceRequirements=disable actually worked. Although I had to restart the instance after updating the configuration.

Is this a recommended and safe approach for a production system?

Regards,
Kushal.

Kushal Gautam

unread,
May 10, 2019, 3:15:58 AM5/10/19
to op...@googlegroups.com
Hi JB:

here is my MANIFEST.MF file:

Manifest-Version: 1.0
Bnd-LastModified: 1557471966933
Build-Jdk: 1.8.0_65
Built-By: Kushal
Bundle-Blueprint: OSGI-INF/blueprint/blueprint.xml
Bundle-ManifestVersion: 2
Bundle-Name: Karaf Plugin Demo
Bundle-SymbolicName: org.apache.karaf.plugin-demo
Bundle-Version: 1.0.0
Created-By: Apache Maven Bundle Plugin
Export-Package: infrastructure;uses:="org.apache.karaf.cellar.core,org
 .osgi.service.cm,services";version="1.0.0",services;version="1.0.0",u
 tils;version="1.0.0"
Import-Package: javax.sql,org.apache.karaf.cellar.core;version="[4.1,5
 )",org.osgi.framework;version="[1.7,2)",org.osgi.service.blueprint;ve
 rsion="[1.0.0,2.0.0)",org.osgi.service.cm;version="[1.5,2)",services
Import-Service: javax.sql.DataSource;multiple:=false;filter=(osgi.jndi
 .service.name=dw-datasource),org.apache.karaf.cellar.core.ClusterM
 anager;multiple:=false,org.osgi.service.cm.ConfigurationAdmin;multipl
 e:=false
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.6))"
Tool: Bnd-4.2.0.201903051501

Regards,
Kushal.

Grzegorz Grzybek

unread,
May 10, 2019, 4:45:17 AM5/10/19
to op...@googlegroups.com
Hello

"Import-Service" manifest header is taken into account by OSGi resolver when resolving a bundle. That's normal, but from my experience, I'd distinguish between static constraints (like Import-Package and Export-Package) and dynamic ones (Import-Service, some Require-Capability, ...). Service resolution can be configuration by the aforementioned serviceRequirements=disable, but what I usually do is configuring maven bundle plugin with:

<configuration>
  <instructions>
    <_removeheaders>Import-Service</_removeheaders>
  </instructions>
</configuration>

See https://bnd.bndtools.org/instructions/removeheaders.html for details. Services come and go in OSGi and it shouldn't be a blocker (IMO) for your bundle to actually resolve. Bundle itself should react to dynamic nature of services.

regards
Grzegorz Grzybek



Jean-Baptiste Onofré

unread,
May 10, 2019, 4:57:32 AM5/10/19
to op...@googlegroups.com

See the Import-Service, that's the requirement. You have to provide a bundle/feature with the capability.

I will provide an example to you.

Regards
JB

Kushal Gautam

unread,
May 10, 2019, 5:40:45 AM5/10/19
to op...@googlegroups.com
An example for such config would be great. :)

Thanks.

Regards,
Kushal.

Kushal Gautam

unread,
May 10, 2019, 5:43:48 AM5/10/19
to op...@googlegroups.com
Hi:

yeah, I saw this solution as well in the karaf forum yesterday. I tried that as well, but didn't seem to resolve the issue. Could be because of the caching issues (it could not resolve the new bundles). I will try that again in a fresh instance.

But, again, does this eliminate the need of setting the service availability to "optional"?

Thanks !

Regards,
Kushal.

Kushal Gautam

unread,
May 23, 2019, 3:09:49 AM5/23/19
to OPS4J
Hi again !

with availability="optional", I am able to install these bundles with "feature:install", but I wanted to add one particular bundle (that uses jdbc and jms as well) as a boot feature, and again it fails to resolve the jms services. Could be because the JMS service has not yet been instantiated. But shouldn't the bundle wait for the dependency?

I tried removing Import-Service using "<_removeheaders>Import-Service</_removeheaders>". But, this had no effect.

How can I provide a capability to a feature? Should I do it in the feature file or the maven bundle plugin?

Regards,
Kushal.
--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to op...@googlegroups.com.
--
--
------------------
OPS4J - http://www.ops4j.org - op...@googlegroups.com

---
You received this message because you are subscribed to the Google Groups "OPS4J" group.
To unsubscribe from this group and stop receiving emails from it, send an email to op...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages