You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Brock Samson <br...@hotmail.com> on 2014/03/08 01:09:38 UTC

which API to edit .cfg in Karaf at runtime?

i have a bundle deployed in Karaf 3.2.1, which references a .cfg file in its
blueprint bundle-context.xml. i also have a javasript-based ui which allows
for such .cfg files to be edited at runtime. up to this point, i have been
using FileOutputStream("etc/my-bundle-PID.cfg") to perform the actual
editing. however, i am wondering if there is an official set of APIs to
accomplish such task.

thank you for your time!



--
View this message in context: http://karaf.922171.n3.nabble.com/which-API-to-edit-cfg-in-Karaf-at-runtime-tp4032135.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: which API to edit .cfg in Karaf at runtime?

Posted by Brock Samson <br...@hotmail.com>.
thank you for the tip. we are not on 3.0.0  just yet, but i will keep this in
mind.



--
View this message in context: http://karaf.922171.n3.nabble.com/which-API-to-edit-cfg-in-Karaf-at-runtime-tp4032135p4032158.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: which API to edit .cfg in Karaf at runtime?

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
FYI,

on Karaf 3.0.0, you also have an OSGi service for Config.

On the "new" user guide, you can see this section:
http://karaf.apache.org/manual/latest/users-guide/monitoring.html

Explaining the usage of JMX, Jolokia, etc.

Regards
JB

On 03/09/2014 08:43 PM, Richard Kettelerij wrote:
> Hi Brock,
>
> Karaf exposes OSGi ConfigAdmin through JMX. Take a look at the MBeans
> under org.apache.karaf:type=config [1].
>
> Note that .cfg files are not necessary involved. The whole .cfg files
> thing in Karaf is just an abstraction around OSGi ConfigAdmin provided
> by Felix FileInstall. Just as the Karaf config shell commands and the
> Karaf ConfigMBean are an abstraction around OSGi ConfigAdmin.
>
> If you don't like working with JMX directly I suggest you look at
> Jolokia [2], which is a JMX-to-HTTP/JSON bridge. For example hawt.io
> <http://hawt.io> [3] also leverages Jolokia to manage various Java
> frameworks including Karaf.
>
> [1] http://karaf.apache.org/manual/latest-2.3.x/users-guide/jmx.html
> [2] http://www.jolokia.org/
> [3] http://hawt.io
>
> Kind regards,
>
> Richard Kettelerij
> http://richardlog.com
>
>
> On Sat, Mar 8, 2014 at 1:53 AM, Tom Leung <tom.leung@netage.com.hk
> <ma...@netage.com.hk>> wrote:
>
>     use "ConfigAdmin" to edit properties inside the cfg file, may refer the
>     following link:
>
>     http://felix.apache.org/documentation/subprojects/apache-felix-config-admin.
>     html
>     <http://felix.apache.org/documentation/subprojects/apache-felix-config-admin.
>     html>
>
>
>     -----Original Message-----
>     From: Brock Samson [mailto:brock.samson_@hotmail.com
>     <ma...@hotmail.com>]
>     Sent: Saturday, March 08, 2014 8:40 AM
>     To: user@karaf.apache.org <ma...@karaf.apache.org>
>     Subject: RE: which API to edit .cfg in Karaf at runtime?
>
>     Tom,
>
>     i already have all that in place. i just need to know if there is an
>     existing set of APIs that supports runtime editing of a .cfg file rather
>     than using FileOutputStream.
>
>
>
>     --
>     View this message in context:
>     http://karaf.922171.n3.nabble.com/which-API-to-edit-cfg-in-Karaf-at-runtime-
>     tp4032135p4032137.html
>     <http://karaf.922171.n3.nabble.com/which-API-to-edit-cfg-in-Karaf-at-runtime-
>     tp4032135p4032137.html>
>     Sent from the Karaf - User mailing list archive at Nabble.com.
>
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: which API to edit .cfg in Karaf at runtime?

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
org.apache.felix.configadmin

Regards
JB

On 03/11/2014 04:15 AM, Brock Samson wrote:
> thanks, Christian. do you happen to know which bundle ConfigurationAdmin
> resides in?
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/which-API-to-edit-cfg-in-Karaf-at-runtime-tp4032135p4032174.html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Re: which API to edit .cfg in Karaf at runtime?

Posted by Brock Samson <br...@hotmail.com>.
thanks, Christian. do you happen to know which bundle ConfigurationAdmin
resides in?



--
View this message in context: http://karaf.922171.n3.nabble.com/which-API-to-edit-cfg-in-Karaf-at-runtime-tp4032135p4032174.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: which API to edit .cfg in Karaf at runtime?

Posted by Christian Schneider <ch...@die-schneider.net>.
You should be able to just use the OSGi configuration admin service for 
this.
http://www.osgi.org/javadoc/r4v42/org/osgi/service/cm/ConfigurationAdmin.html

Just inject the service into your class, get the configuration by its 
pid (which is the filename without.cfg). Then change properties of the 
Configuration and call update(). This should then also change the files.

Christian

On 10.03.2014 18:12, Brock Samson wrote:
> Richard,
>
> i guess i should have been a bit clearer in my initial post. i already have
> infrastructure in place where my javascript-based ui makes update calls to
> the bundle, so i am not looking for a way to have the ui update .cfg file
> directly. rather, i would like the bundle in question to update its own .cfg
> file, which is why i am looking for a straightforward way to accomplish
> this. is the jmx approach it?
>
> thanks!
>
>
>
> --
> View this message in context: http://karaf.922171.n3.nabble.com/which-API-to-edit-cfg-in-Karaf-at-runtime-tp4032135p4032159.html
> Sent from the Karaf - User mailing list archive at Nabble.com.


-- 
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com


Re: which API to edit .cfg in Karaf at runtime?

Posted by Brock Samson <br...@hotmail.com>.
Richard,

i guess i should have been a bit clearer in my initial post. i already have
infrastructure in place where my javascript-based ui makes update calls to
the bundle, so i am not looking for a way to have the ui update .cfg file
directly. rather, i would like the bundle in question to update its own .cfg
file, which is why i am looking for a straightforward way to accomplish
this. is the jmx approach it?

thanks!



--
View this message in context: http://karaf.922171.n3.nabble.com/which-API-to-edit-cfg-in-Karaf-at-runtime-tp4032135p4032159.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Re: which API to edit .cfg in Karaf at runtime?

Posted by Richard Kettelerij <ri...@gmail.com>.
Hi Brock,

Karaf exposes OSGi ConfigAdmin through JMX. Take a look at the MBeans
under org.apache.karaf:type=config [1].

Note that .cfg files are not necessary involved. The whole .cfg files thing
in Karaf is just an abstraction around OSGi ConfigAdmin provided by Felix
FileInstall. Just as the Karaf config shell commands and the Karaf
ConfigMBean are an abstraction around OSGi ConfigAdmin.

If you don't like working with JMX directly I suggest you look at Jolokia
[2], which is a JMX-to-HTTP/JSON bridge. For example hawt.io [3] also
leverages Jolokia to manage various Java frameworks including Karaf.

[1] http://karaf.apache.org/manual/latest-2.3.x/users-guide/jmx.html
[2] http://www.jolokia.org/
[3] http://hawt.io

Kind regards,

Richard Kettelerij
http://richardlog.com


On Sat, Mar 8, 2014 at 1:53 AM, Tom Leung <to...@netage.com.hk> wrote:

> use "ConfigAdmin" to edit properties inside the cfg file, may refer the
> following link:
>
>
> http://felix.apache.org/documentation/subprojects/apache-felix-config-admin.
> html
>
>
> -----Original Message-----
> From: Brock Samson [mailto:brock.samson_@hotmail.com]
> Sent: Saturday, March 08, 2014 8:40 AM
> To: user@karaf.apache.org
> Subject: RE: which API to edit .cfg in Karaf at runtime?
>
> Tom,
>
> i already have all that in place. i just need to know if there is an
> existing set of APIs that supports runtime editing of a .cfg file rather
> than using FileOutputStream.
>
>
>
> --
> View this message in context:
>
> http://karaf.922171.n3.nabble.com/which-API-to-edit-cfg-in-Karaf-at-runtime-
> tp4032135p4032137.html
> Sent from the Karaf - User mailing list archive at Nabble.com.
>
>

RE: which API to edit .cfg in Karaf at runtime?

Posted by Tom Leung <to...@netage.com.hk>.
use "ConfigAdmin" to edit properties inside the cfg file, may refer the
following link:

http://felix.apache.org/documentation/subprojects/apache-felix-config-admin.
html


-----Original Message-----
From: Brock Samson [mailto:brock.samson_@hotmail.com] 
Sent: Saturday, March 08, 2014 8:40 AM
To: user@karaf.apache.org
Subject: RE: which API to edit .cfg in Karaf at runtime?

Tom,

i already have all that in place. i just need to know if there is an
existing set of APIs that supports runtime editing of a .cfg file rather
than using FileOutputStream.



--
View this message in context:
http://karaf.922171.n3.nabble.com/which-API-to-edit-cfg-in-Karaf-at-runtime-
tp4032135p4032137.html
Sent from the Karaf - User mailing list archive at Nabble.com.


RE: which API to edit .cfg in Karaf at runtime?

Posted by Brock Samson <br...@hotmail.com>.
Tom,

i already have all that in place. i just need to know if there is an
existing set of APIs that supports runtime editing of a .cfg file rather
than using FileOutputStream.



--
View this message in context: http://karaf.922171.n3.nabble.com/which-API-to-edit-cfg-in-Karaf-at-runtime-tp4032135p4032137.html
Sent from the Karaf - User mailing list archive at Nabble.com.

RE: which API to edit .cfg in Karaf at runtime?

Posted by Tom Leung <to...@netage.com.hk>.
I think you want set up a configuration file.  Anytime, the user edit this
file, the value can be reflected in the application.

Why not using Blueprint placeholder and include a blueprint configuration
file as below:

<blueprint default-activation="eager"
           xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0"
           xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0"
 
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0">

    <cm:property-placeholder persistent-id="your.sample.config"
update-strategy="reload" >
		<cm:default-properties>
			<cm:property name="property1" value="foo"/>
		</cm:default-properties>
	</cm:property-placeholder>
	   
	<bean class="sample.YourClassImpl " id="beanDao">
	    	    <property name=" property1" value="${ property1}"/>
    </bean>
</blueprint>


After the bundle has been started, you may create a cfg file named "
your.sample.config.cfg" under Karaf/etc folder.
This cfg file contains the property value as below:

property1=your_value

If the property value has been changed, the new property value will be
reloaded and reflected in the blueprint bean property.





-----Original Message-----
From: Brock Samson [mailto:brock.samson_@hotmail.com] 
Sent: Saturday, March 08, 2014 8:10 AM
To: user@karaf.apache.org
Subject: which API to edit .cfg in Karaf at runtime?

i have a bundle deployed in Karaf 3.2.1, which references a .cfg file in its
blueprint bundle-context.xml. i also have a javasript-based ui which allows
for such .cfg files to be edited at runtime. up to this point, i have been
using FileOutputStream("etc/my-bundle-PID.cfg") to perform the actual
editing. however, i am wondering if there is an official set of APIs to
accomplish such task.

thank you for your time!



--
View this message in context:
http://karaf.922171.n3.nabble.com/which-API-to-edit-cfg-in-Karaf-at-runtime-
tp4032135.html
Sent from the Karaf - User mailing list archive at Nabble.com.