OSGI Configuration Admin
El servicio Configiguration Admin, es un servicio de OSGI que nos da un modelo flexible y dinámico para recuperar y hacer configuraciones de nuestros servicios/bundles.
Dummy Example
Servicio configurado:
Simplemente el activator registra el servicio bajo el interfaz ManagedService con un PID determinado.
registration = context.registerService(ManagedService.class.getName(), conf,properties);La clase registrada implementa los métodos de ManagedService
public class Configurated implements ManagedService {
public void updated(Dictionary props) throws ConfigurationException {
// TODO Auto-generated method stubServicio Configurator
Este seria al bundle configurador. Coge la referencia al servicio managed, recupera la configuración del servicio con el PID asociado al servicio configurable y luego hace un update.
config = _confAdmin.getConfiguration("es.mcm.configurator",null);
Dictionary props = config.getProperties();
props.put("port", "8080");
config.update(props);OJO: al recuperar la configuración no recuperamos el properties de configuración del bundle, no es una referencia sino una copia del mismo.
sería un error hacer lo siguiente: config.update();
Target Platform
Framework is launched.
id State Bundle
0 ACTIVE org.eclipse.osgi_3.4.0.v20080605-1900
1 ACTIVE org.ops4j.pax.logging.pax-logging-api_1.1.0
2 ACTIVE org.ops4j.pax.logging.pax-logging-service_1.1.0
3 ACTIVE org.eclipse.osgi.services_3.1.200.v20071203
5 ACTIVE org.eclipse.equinox.cm_1.0.0.v20080121
6 ACTIVE ConfigurationMcm_1.0.0
7 ACTIVE org.apache.felix.scr_1.0.6
15 ACTIVE EjemploManaged_1.0.0OSGI Configiguration Admin tools
Aquí se presentarán herramientas probadas y útiles para lanzar, ver, editar configuraciónes.
Luminis
Esta es otra implementación que no esta mal para editar y ver configuraciones desde consola.
Necesitareis añadir al target platform la consola apache:
2 ACTIVE org.apache.felix.shell_1.0.2Es de muy facil manejo, simplmente ejecutad: cm help o cm y palante:
osgi> cm
osgi> Usage:
cm help print this help message
cm list list all known configurations
cm get <pid> show configuration for service <pid>
cm getv <pid> verbose get (shows value types also)
cm put <pid> key value set string value for service <pid>
cm puts <pid> key value set "simple" value for service <pid>: value is "true", "false",
a char in single quotes, an int, or a number, with appended:
i (Integer), l (Long), f (Float), d (Double), b (Byte), s (Short)
cm del <pid> deletes configuration for service <pid>
cm create <pid> [<loc>] creates configuration for service <pid> (with optional bundle location)Por ejmplo:
cm list
Configuration list:
greetings_servlet_service_factory-1225224526355-0 initial@reference:file:../../workspace2/configurable-greetings-servlets-1.0.0-src/
greetings_servlet_service_factory-1225221990714-1 initial@reference:file:../../workspace2/configurable-greetings-servlets-1.0.0-src/
es.mcm.configurator
m get es.mcm.configurator
Configuration for service (pid) "es.mcm.configurator"
(bundle location = initial@reference:file:../../workspace2/EjemploManaged/)
key value
------ ------
port 8080
prop1 propiedad1
prop2 propiedad2
service.pid es.mcm.configurator Obtenido de: https://opensource.luminis.net/confluence/display/SITE/OSGi+Configuratio...
PAX conf man
Este te permite cargas las propiedades de ficheros properties. Para su uso solo hace faltan dos cosas.
* crear un directorio donde irán alojadas los ficheros de configuración con directorios para facotrias y servicios:
En mi caso: /home/mcm/workspace2/conf Tengo esta estructura:
.
|-- factories
`-- services
`-- es.mcm.configurator.properties
Este fichero tendrá la pinta de un properties:
mcm@McM:~/workspace2/conf$ more services/es.mcm.configurator.properties
prop1 propiedad1
prop2 propiedad2* Añadir una variable de ejecución al entorno, en mi caso:
-Dbundles.configuration.location=/home/mcm/workspace2/conf/* Problemas
- Solo Strings
- Puedes cambiar los ficheros de configuración pero para que se recarguen en el sistema exige un stop/start o update del bundle pax-confman-propsloader-0.2.2.jar
Lo podeis encontrar aquí: http://wiki.ops4j.org/confluence/display/ops4j/Pax+ConfMan
PAX coin
Igual que confman pero coge las propiedades dinamicamete. MOdificas el fichero de configuracion y las carga inmediatamente. Este está en desarrollo.
http://wiki.ops4j.org/confluence/display/ops4j/Pax+Coin
Open Issues
WEB Console
Lo ideal y que todavia no he dado con ello es que a través de la web console podremos modificar las configuraciones de los bundles.
Para que las configuraciones aparezcan en la webconsole, al parecer, hay que utilizar el servicio Metatype:
The Configuration Admin support in the web console is limited to Configurations for which the Metatype Service can provide a descriptor.
The reason for this is, that the configuration list is not cluttered with entries, which will never be used. Since the configuaration admin panel not only asks the configuration admin service for configurations but also looks for ManagedService[Factory] services to display their possibly empty configuration entries we get a lot of these because the Felix Declarative Services implementation registers a ManagedService[Factory] on behalf of each Component[Factory].
The advantage of the Metatype Service is that you can describe your configuration properties and that the console configuration admin support may create an adapted GUI.
Para ello:
Basically you have to options (see the Metatype Service specification for the exact details): Have your ManagedService implement the MetaTypeProvider interface (and register as a service) or provide a Metatype descriptor file in the OSGI-INF/metatype folder in your bundle. (Note, that the MetaTypeProvider objects of a bundle are ignored if the bundle has descriptors in OSGI-INF/metatype).
Finally, ensure you have the Metatype service implementation running, such that the web console is able to call it.
When the Metatype service can provide information about your ManagedService, the configuration admin panel is able to display the configuration.


