Best practice on propagating configuration errors from ManagedFactoryService to client?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Best practice on propagating configuration errors from ManagedFactoryService to client?

peterg
Hi all,

thought I'd ask this general OSGi question on this list full of OSGi-knowledgeable people.
Please tell me if it belongs better on a more OSGi-standard specific forum (such as Felix/Equinox perhaps).

So I have a ManagedFactoryService that creates service instances and I have another (client-)bundle that creates instances by registering new configurations with the factory.
What I currently find difficult is to propagate errors (such as a required configuration property missing) from the ManagedFactoryService to the client.

When the client uses an invalid configuration dictionary to instantiate a new service instance as follows

        // instantiate new service with serviceConfig as instantiation parameters
        Configuration config = configurationAdmin.createFactoryConfiguration(factoryPid, null);
        config.update(serviceConfig); 

no exception is raised despite the ManagedFactoryService throwing a ConfigurationException.
I guess this is expected since configuration updates are handled on a separate thread of execution.
But this is problematic since, from the client bundle's perspective, the configuration update appears to have been successful.

So what I really need to know is if there is a best practice for propagating the configuration error from the ManagedFactoryService to the client?
Any suggestions would be appreciated.

best regards, Peter
Reply | Threaded
Open this post in threaded view
|

Re: Best practice on propagating configuration errors from ManagedFactoryService to client?

Filippo Balicchia-2
Why,
don't you use a lookup that after the call to the factory check if the
registration was successful ?
If lookup fail you  thrown a ServiceUnavailableException.


--Filippo

Il 30 gennaio 2012 09:24, Peter Gardfjäll
<[hidden email]> ha scritto:

> Hi all,
>
> thought I'd ask this general OSGi question on this list full of
> OSGi-knowledgeable people.
> Please tell me if it belongs better on a more OSGi-standard specific forum
> (such as Felix/Equinox perhaps).
>
> So I have a ManagedFactoryService that creates service instances and I have
> another (client-)bundle that creates instances by registering new
> configurations with the factory.
> What I currently find difficult is to propagate errors (such as a required
> configuration property missing) from the ManagedFactoryService to the
> client.
>
> When the client uses an invalid configuration dictionary to instantiate a
> new service instance as follows
>
>         // instantiate new service with serviceConfig as instantiation
> parameters
>         Configuration config =
> configurationAdmin.createFactoryConfiguration(factoryPid, null);
>         config.update(serviceConfig);
>
> no exception is raised despite the ManagedFactoryService throwing a
> ConfigurationException.
> I guess this is expected since configuration updates are handled on a
> separate thread of execution.
> But this is problematic since, from the client bundle's perspective, the
> configuration update appears to have been successful.
>
> So what I really need to know is if there is a best practice for propagating
> the configuration error from the ManagedFactoryService to the client?
> Any suggestions would be appreciated.
>
> best regards, Peter
Reply | Threaded
Open this post in threaded view
|

Re: Best practice on propagating configuration errors from ManagedFactoryService to client?

peterg
Thanks Filippo,

but I believe that a straight service lookup wouldn't work.
I don't think that there are any guarantees that the service instance has been registered right after the config.update(...) call.
Thus, I would need to wait for the service to appear (how long?), for example using a ServiceTracker.
Although clearly doable, such a solution sounds a bit ugly/cumbersome.
I was hoping for a more elegant solution.

best regards, Peter

On Mon, Jan 30, 2012 at 2:13 PM, Filippo Balicchia <[hidden email]> wrote:
Why,
don't you use a lookup that after the call to the factory check if the
registration was successful ?
If lookup fail you  thrown a ServiceUnavailableException.


--Filippo

Il 30 gennaio 2012 09:24, Peter Gardfjäll
<[hidden email]> ha scritto:
> Hi all,
>
> thought I'd ask this general OSGi question on this list full of
> OSGi-knowledgeable people.
> Please tell me if it belongs better on a more OSGi-standard specific forum
> (such as Felix/Equinox perhaps).
>
> So I have a ManagedFactoryService that creates service instances and I have
> another (client-)bundle that creates instances by registering new
> configurations with the factory.
> What I currently find difficult is to propagate errors (such as a required
> configuration property missing) from the ManagedFactoryService to the
> client.
>
> When the client uses an invalid configuration dictionary to instantiate a
> new service instance as follows
>
>         // instantiate new service with serviceConfig as instantiation
> parameters
>         Configuration config =
> configurationAdmin.createFactoryConfiguration(factoryPid, null);
>         config.update(serviceConfig);
>
> no exception is raised despite the ManagedFactoryService throwing a
> ConfigurationException.
> I guess this is expected since configuration updates are handled on a
> separate thread of execution.
> But this is problematic since, from the client bundle's perspective, the
> configuration update appears to have been successful.
>
> So what I really need to know is if there is a best practice for propagating
> the configuration error from the ManagedFactoryService to the client?
> Any suggestions would be appreciated.
>
> best regards, Peter

Reply | Threaded
Open this post in threaded view
|

Re: Best practice on propagating configuration errors from ManagedFactoryService to client?

peterg

Furthermore, with the suggested approach there is still no simple way for the client to see _what_ went wrong (was there a missing property? a wrong-typed property? what?). It would just detect that the service wasn't properly created.

best regards, Peter

2012/1/30 Peter Gardfjäll <[hidden email]>
Thanks Filippo,

but I believe that a straight service lookup wouldn't work.
I don't think that there are any guarantees that the service instance has been registered right after the config.update(...) call.
Thus, I would need to wait for the service to appear (how long?), for example using a ServiceTracker.
Although clearly doable, such a solution sounds a bit ugly/cumbersome.
I was hoping for a more elegant solution.

best regards, Peter


On Mon, Jan 30, 2012 at 2:13 PM, Filippo Balicchia <[hidden email]> wrote:
Why,
don't you use a lookup that after the call to the factory check if the
registration was successful ?
If lookup fail you  thrown a ServiceUnavailableException.


--Filippo

Il 30 gennaio 2012 09:24, Peter Gardfjäll
<[hidden email]> ha scritto:
> Hi all,
>
> thought I'd ask this general OSGi question on this list full of
> OSGi-knowledgeable people.
> Please tell me if it belongs better on a more OSGi-standard specific forum
> (such as Felix/Equinox perhaps).
>
> So I have a ManagedFactoryService that creates service instances and I have
> another (client-)bundle that creates instances by registering new
> configurations with the factory.
> What I currently find difficult is to propagate errors (such as a required
> configuration property missing) from the ManagedFactoryService to the
> client.
>
> When the client uses an invalid configuration dictionary to instantiate a
> new service instance as follows
>
>         // instantiate new service with serviceConfig as instantiation
> parameters
>         Configuration config =
> configurationAdmin.createFactoryConfiguration(factoryPid, null);
>         config.update(serviceConfig);
>
> no exception is raised despite the ManagedFactoryService throwing a
> ConfigurationException.
> I guess this is expected since configuration updates are handled on a
> separate thread of execution.
> But this is problematic since, from the client bundle's perspective, the
> configuration update appears to have been successful.
>
> So what I really need to know is if there is a best practice for propagating
> the configuration error from the ManagedFactoryService to the client?
> Any suggestions would be appreciated.
>
> best regards, Peter


Reply | Threaded
Open this post in threaded view
|

Re: Best practice on propagating configuration errors from ManagedFactoryService to client?

peterg
I (cross-)posted this query on the Apache Felix mailing list [1] (sorry...) and basically got the advice to make use of a facade factory service that accepts a configuration, validates it, pushes it through to the ConfigurationAdmin (and subsequently the ManagedFactoryService), and checks that the service was successfully created.

Basically a facade factory that turns the asyncronous call to create a service instance into a synchronous (blocking) one.

best regards, Peter

[1] - http://www.mail-archive.com/users@.../msg11728.html


2012/1/30 Peter Gardfjäll <[hidden email]>

Furthermore, with the suggested approach there is still no simple way for the client to see _what_ went wrong (was there a missing property? a wrong-typed property? what?). It would just detect that the service wasn't properly created.

best regards, Peter


2012/1/30 Peter Gardfjäll <[hidden email]>
Thanks Filippo,

but I believe that a straight service lookup wouldn't work.
I don't think that there are any guarantees that the service instance has been registered right after the config.update(...) call.
Thus, I would need to wait for the service to appear (how long?), for example using a ServiceTracker.
Although clearly doable, such a solution sounds a bit ugly/cumbersome.
I was hoping for a more elegant solution.

best regards, Peter


On Mon, Jan 30, 2012 at 2:13 PM, Filippo Balicchia <[hidden email]> wrote:
Why,
don't you use a lookup that after the call to the factory check if the
registration was successful ?
If lookup fail you  thrown a ServiceUnavailableException.


--Filippo

Il 30 gennaio 2012 09:24, Peter Gardfjäll
<[hidden email]> ha scritto:
> Hi all,
>
> thought I'd ask this general OSGi question on this list full of
> OSGi-knowledgeable people.
> Please tell me if it belongs better on a more OSGi-standard specific forum
> (such as Felix/Equinox perhaps).
>
> So I have a ManagedFactoryService that creates service instances and I have
> another (client-)bundle that creates instances by registering new
> configurations with the factory.
> What I currently find difficult is to propagate errors (such as a required
> configuration property missing) from the ManagedFactoryService to the
> client.
>
> When the client uses an invalid configuration dictionary to instantiate a
> new service instance as follows
>
>         // instantiate new service with serviceConfig as instantiation
> parameters
>         Configuration config =
> configurationAdmin.createFactoryConfiguration(factoryPid, null);
>         config.update(serviceConfig);
>
> no exception is raised despite the ManagedFactoryService throwing a
> ConfigurationException.
> I guess this is expected since configuration updates are handled on a
> separate thread of execution.
> But this is problematic since, from the client bundle's perspective, the
> configuration update appears to have been successful.
>
> So what I really need to know is if there is a best practice for propagating
> the configuration error from the ManagedFactoryService to the client?
> Any suggestions would be appreciated.
>
> best regards, Peter