karaf-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Ward <tim.w...@paremus.com>
Subject Re: Adding an @Activate to a DS bundle causes the bundle not to load
Date Mon, 04 Dec 2017 23:01:11 GMT
My educated guess...

By adding the activate method you have increased the required version of DS detected by bnd.
This, in turn, has probably added a Require-Capability for the service that you import. This
has no effect at runtime (due to the value of its effective directive) but if the service
exporter does not have a corresponding Provide-Capability then it may have broken the Karaf
feature resolver, which would stop your feature from deploying with the error that you see

In bnd you can fix this using repository augments (as it’s only a resolve-time issue). I
don’t know whether Karaf has a similar feature. 

The other fix is to make sure that your Postgres driver correctly advertises its service capabilities
using Provide-Capability.

Tim

Sent from my iPhone

> On 4 Dec 2017, at 22:15, Steinar Bang <sb@dod.no> wrote:
> 
> Platform: Java 1.8, karaf 4.1.3
> 
> I have the following DS component that exposes a Servlet to the Pax Web
> Whiteboard Extender:
> https://github.com/steinarb/sonar-collector/blob/master/sonar-collector-webhook/src/main/java/no/priv/bang/sonar/collector/webhook/SonarCollectorServlet.java#L55
> 
> The component starts fine, and exposes a Servlet service that is picked
> up by the whiteboard extender, and as far as I can tell, it does what it
> is expected to do (receive POSTs from SonarQube/SonarCloud and store
> build statistics in a PostgreSQL database).
> 
> However, if I add an empty activate method, like so:
> @Component(service={Servlet.class}, property={"alias=/sonar-collector"} )
> public class SonarCollectorServlet extends HttpServlet {
>     ...
>     @Activate
>     public void activate(Map<String, Object> config) {
>     }
>     ...
> }
> 
> then the component fails to load, because of missing dependencies:
> karaf@root()> feature:repo-add mvn:no.priv.bang.sonar.sonar-collector/sonar-collector-webhook/LATEST/xml/features
> Adding feature url mvn:no.priv.bang.sonar.sonar-collector/sonar-collector-webhook/LATEST/xml/features
> karaf@root()> feature:install sonar-collector-webhook
> Error executing command: Unable to resolve root: missing requirement [root] osgi.identity;
osgi.identity=sonar-collector-webhook; type=karaf.feature; version="[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]";
filter:="(&(osgi.identity=sonar-collector-webhook)(type=karaf.feature)(version>=1.0.0.SNAPSHOT)(version<=1.0.0.SNAPSHOT))"
[caused by: Unable to resolve sonar-collector-webhook/1.0.0.SNAPSHOT: missing requirement
[sonar-collector-webhook/1.0.0.SNAPSHOT] osgi.identity; osgi.identity=no.priv.bang.sonar.sonar-collector-webhook;
type=osgi.bundle; version="[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]"; resolution:=mandatory [caused
by: Unable to resolve no.priv.bang.sonar.sonar-collector-webhook/1.0.0.SNAPSHOT: missing requirement
[no.priv.bang.sonar.sonar-collector-webhook/1.0.0.SNAPSHOT] osgi.service; effective:=ac
> tive; filter:="(objectClass=org.osgi.service.jdbc.DataSourceFactory)"]]
> karaf@root()>
> 
> If remove the "@Activate" annotation, the component loads again.
> 
> Does anyone know what might cause this?
> 
> What's strange about this, that the missing depenency the error message
> complains about, ie. org.osgi.service.jdbc.DataSourceFactory, is
> essential to the servlet's operation.  Without a DataSourceFactory, no
> database can be contacted and no data can be saved (and data _is_ saved).
> 
> Is the error message because the bundle can't find the type
> org.osgi.service.jdbc.DataSourceFactory? Or is the message about not
> getting an instance of org.osgi.service.jdbc.DataSourceFactory?
> 
> The full error message from karaf.log below.
> 
> Thanks!
> 
> 
> - Steinar
> 
> Error message from karaf.log follows:
> 
> 2017-12-04T20:28:57,555 | ERROR | Karaf local console user karaf | ShellUtil        
               | 42 - org.apache.karaf.shell.core - 4.1.3 | Exception caught while executing
command
> org.osgi.service.resolver.ResolutionException: Unable to resolve root: missing requirement
[root] osgi.identity; osgi.identity=sonar-collector-webhook; type=karaf.feature; version="[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]";
filter:="(&(osgi.identity=sonar-collector-webhook)(type=karaf.feature)(version>=1.0.0.SNAPSHOT)(version<=1.0.0.SNAPSHOT))"
[caused by: Unable to resolve sonar-collector-webhook/1.0.0.SNAPSHOT: missing requirement
[sonar-collector-webhook/1.0.0.SNAPSHOT] osgi.identity; osgi.identity=no.priv.bang.sonar.sonar-collector-webhook;
type=osgi.bundle; version="[1.0.0.SNAPSHOT,1.0.0.SNAPSHOT]"; resolution:=mandatory [caused
by: Unable to resolve no.priv.bang.sonar.sonar-collector-webhook/1.0.0.SNAPSHOT: missing requirement
[no.priv.bang.sonar.sonar-collector-webhook/1.0.0.SNAPSHOT] osgi.s
> ervice; effective:=active; filter:="(objectClass=org.osgi.service.jdbc.DataSourceFactory)"]]
>    at org.apache.felix.resolver.ResolutionError.toException(ResolutionError.java:42)
~[?:?]
>    at org.apache.felix.resolver.ResolverImpl.doResolve(ResolverImpl.java:391) ~[?:?]
>    at org.apache.felix.resolver.ResolverImpl.resolve(ResolverImpl.java:377) ~[?:?]
>    at org.apache.felix.resolver.ResolverImpl.resolve(ResolverImpl.java:349) ~[?:?]
>    at org.apache.karaf.features.internal.region.SubsystemResolver.resolve(SubsystemResolver.java:218)
~[?:?]
>    at org.apache.karaf.features.internal.service.Deployer.deploy(Deployer.java:291) ~[?:?]
>    at org.apache.karaf.features.internal.service.FeaturesServiceImpl.doProvision(FeaturesServiceImpl.java:1248)
~[?:?]
>    at org.apache.karaf.features.internal.service.FeaturesServiceImpl.lambda$doProvisionInThread$1(FeaturesServiceImpl.java:1147)
~[?:?]
>    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
>    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[?:?]
>    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[?:?]
>    at java.lang.Thread.run(Thread.java:748) [?:?]
> 
> 
> 

Mime
View raw message