Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Kura » Way to update configuration values set by OSGI-INF/metatype/xxx.xml using class interface(Way to update configuration values set by OSGI-INF/metatype/xxx.xml using class interface)
icon5.gif  Way to update configuration values set by OSGI-INF/metatype/xxx.xml using class interface [message #1651585] Thu, 05 March 2015 11:38 Go to next message
David Ryoo is currently offline David RyooFriend
Messages: 7
Registered: February 2015
Junior Member
Way to update configuration values set by OSGI-INF/metatype/xxx.xml using class interface?

I could see the configuration values using Apply button one the configuration pane from browser. However I could do it on the source code and on the run time. is there any way to access the configuration values set through class interface? if yes, could you explain the way in detail?

Regards,
Re: Way to update configuration values set by OSGI-INF/metatype/xxx.xml using class interface [message #1652649 is a reply to message #1651585] Fri, 06 March 2015 00:06 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hello,

I am not sure I understand your question. Let me explain what is happening and maybe that will help. The values defined in the OSGI-INF/metatype/*.xml file are part of the OSGi Metatype Service specification. They are accessed along with the ComponentContext when the bundle starts or is updated. For example, your bundle would have these methods:

private static Map<String, Object> m_properties;

protected void activate(ComponentContext ctx, Map<String, Object> properties) {
    m_properties = properties;
}
protected void updated(ComponentContext ctx, Map<String, Object> properties) {
     m_properties = properties;
}


When you click "Apply" with the web UI, you are using the ConfigurationService [1] to update the selected bundle. The values displayed on the web form come from the metatype XML file. So, if you are trying to update a bundle without the web UI, I would take a look at the ConfigurationService updateConfiguration method.

[1] http://download.eclipse.org/kura/releases/1.1.0/docs/apidocs/org/eclipse/kura/configuration/ConfigurationService.html

Thanks,
--Dave
Re: Way to update configuration values set by OSGI-INF/metatype/xxx.xml using class interface [message #1652837 is a reply to message #1652649] Fri, 06 March 2015 02:04 Go to previous messageGo to next message
David Ryoo is currently offline David RyooFriend
Messages: 7
Registered: February 2015
Junior Member
Thanks Dave,

I also assumed ConfigurationService can be used to access configuration but I have no idea how to use it because there is no way to access instantiated object for that interface from the documents. how to get instantiated object for that service?

Thanks, David
Re: Way to update configuration values set by OSGI-INF/metatype/xxx.xml using class interface [message #1654151 is a reply to message #1652837] Fri, 06 March 2015 15:04 Go to previous messageGo to next message
Alessandro Da Rugna is currently offline Alessandro Da RugnaFriend
Messages: 43
Registered: December 2014
Member
To get the configuration for one particular service from ConfigurationService:

String PID_MQTT_DATA_TRANSPORT = "org.eclipse.kura.core.data.transport.mqtt.MqttDataTransport";
ComponentConfiguration mqttConfiguration = m_configurationService.getComponentConfiguration(PID_MQTT_DATA_TRANSPORT);
Map<String,Object> mqttConfigurationProperties = mqttConfiguration.getConfigurationProperties();

This will get the MqttDataTransportService configuration, you can ask the configuration of any service registered providing its PID.

This means you need the ConfigurationService available in your service. Just ask OSGi to inject it.
public class YourService implements ConfigurableComponent {
	private ConfigurationService m_configurationService;

	public void setConfigurationService(ConfigurationService configurationService) {
		m_configurationService = configurationService;
	}

	public void unsetConfigurationService(ConfigurationService configurationService) {
		m_configurationService = null;
	}

	// Your methods here ...
}

In your OSGI-INF/yourservice.xml
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" 
    name="your.Service"
    activate="activate" 
    deactivate="deactivate" 
    enabled="true"
    immediate="true"
    configuration-policy="ignore">
    <implementation class="your.ServiceImpl"/>

   <property name="service.pid" type="String" value="your.Service"/>
   <service>
       <provide interface="your.Service"/>
   </service>
                 
   <reference name="ConfigurationService"
     		  policy="static"
    		  bind="setConfigurationService"
    		  unbind="unsetConfigurationService"
    		  cardinality="1..1"
    		  interface="org.eclipse.kura.configuration.ConfigurationService"/>

</scr:component>


Hope this small example will be helpful.


My project: Kura web log level changer https://github.com/darugnaa/kura-web-log
My blog: http://darugnaa.github.io
icon14.gif  Re: Way to update configuration values set by OSGI-INF/metatype/xxx.xml using class interface [message #1656559 is a reply to message #1654151] Sat, 07 March 2015 15:21 Go to previous messageGo to next message
David Ryoo is currently offline David RyooFriend
Messages: 7
Registered: February 2015
Junior Member
Hi Alessandro,

That's great. I could solve issue with your help. thanks a lot.

I hope this kinds of information is reflected guide doc.

thanks/ David

[Updated on: Mon, 09 March 2015 07:49]

Report message to a moderator

Re: Way to update configuration values set by OSGI-INF/metatype/xxx.xml using class interface [message #1700822 is a reply to message #1656559] Tue, 07 July 2015 12:52 Go to previous messageGo to next message
Marco Balzarin is currently offline Marco BalzarinFriend
Messages: 22
Registered: May 2015
Junior Member
Sorry if i resume this old topic, but also i'm trying to use the ConfigurationService. I have followed step by step the previous post of Alessandro, but seems that in my bundle something is missing, because OSGi is not able to inject this service.

In the OSGi console, if i run the "ls" command, my bundle is indicated as "unsatisfied". Pasted below is the output of "comp" command on the bundle in question:

Dynamic information :
*The component is NOT satisfied
The following references are not satisfied:
Reference[name = ConfigurationService, interface = org.eclipse.kura.configuration.ConfigurationService, policy = static, cardinality = 1..1, target = null, bind = setConfigurationService, unbind = unsetConfigurationService]


What can i do?
Re: Way to update configuration values set by OSGI-INF/metatype/xxx.xml using class interface [message #1701049 is a reply to message #1700822] Wed, 08 July 2015 23:28 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hello,

Are there any other unsatisfied components when you run the "ls" command? Can you check the log files (/var/log/kura.log and /var/log/kura-console.log) for any errors?

Thanks,
--Dave
Re: Way to update configuration values set by OSGI-INF/metatype/xxx.xml using class interface [message #1701073 is a reply to message #1701049] Thu, 09 July 2015 08:14 Go to previous messageGo to next message
Marco Balzarin is currently offline Marco BalzarinFriend
Messages: 22
Registered: May 2015
Junior Member
Yes, the only bundle marked as unsatisfied is the one that tries to get injected the configuration service. The only exceptions that i found on the Kura log files, are several NullPointerException occurred when the bundle have tried to use the ConfigurationService (which is null becouse not initialized by OSGi).

I'm not pasting my source code and my service.xml becaouse are exactly the same posted by Alessandro.

I don't know, maybe am i missing some dependencies? In my manifest, i'm importing both the packages org.eclipse.kura.configuration and org.eclipse.kura.core.configuration..

[Updated on: Thu, 09 July 2015 08:15]

Report message to a moderator

Re: Way to update configuration values set by OSGI-INF/metatype/xxx.xml using class interface [message #1701215 is a reply to message #1701073] Thu, 09 July 2015 22:30 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Can you post the complete output of the OSGi console commands 'ss' and 'ls'.

--Dave
Re: Way to update configuration values set by OSGI-INF/metatype/xxx.xml using class interface [message #1734983 is a reply to message #1701215] Tue, 14 June 2016 11:50 Go to previous message
Tejram Kotakonda is currently offline Tejram KotakondaFriend
Messages: 7
Registered: May 2016
Junior Member
Hi Alessandro,
I followed your example given above.But in the below line the getConfigurationProperties() function is returning null.
Map<String,Object> mqttConfigurationProperties = mqttConfiguration.getConfigurationProperties();
Please help me.
Regards
Tejram.
Previous Topic:subscribing to Kura service using mosquitto
Next Topic:Deactivating Bundle
Goto Forum:
  


Current Time: Thu Apr 25 07:25:21 GMT 2024

Powered by FUDForum. Page generated in 0.19906 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top