You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by João Assunção <jo...@exploitsys.com> on 2021/05/20 14:33:44 UTC

How to use configuration placeholders in karaf configs

Hello all,

I'm trying to use placeholders in configurations but I noticed some weird
behavior. Sometimes the placeholder is replaced by an empty string, in
other situations by the value of the property and in others not replaced at
all.

One of my features contains the following configurations:
...
<config
name="com.atobe.ort.photo.repository.PhotoRepositoryServiceProvider"
append="false">
        storageDirectory=${tzc.data}/photos
</config>
<config
name="pt.brisa.service.metrics.rrd.internal.RRDPersistenceServiceProvider"
append="false">
            rrdDefFile = etc/tzc_metrics.xml
            rrdRepository = ${tzc.data}/rrd
            reportingInterval = 60
</config>
..

When the feature is installed, with tzc.data set to "myData", sometimes i
get the following cfg files:
*== com.atobe.ort.photo.repository.PhotoRepositoryServiceProvider.cfg ==*
storageDirectory=${tzc.data}/photos
org.apache.karaf.features.configKey =
com.atobe.ort.photo.repository.PhotoRepositoryServiceProvider

*== pt.brisa.service.metrics.rrd.internal.RRDPersistenceServiceProvider.cfg
==*
rrdDefFile = etc/tzc_metrics.xml
rrdRepository = myData/rrd
reportingInterval = 60
org.apache.karaf.features.configKey =
pt.brisa.service.metrics.rrd.internal.RRDPersistenceServiceProvider

I tried specifying the variable name in config.properties and using  the
-D  flag

Ideally I would like the placeholder to be replaced by the actual value
only when the configuration is passed to the service.

What am I doing wrong ?

Thank you in advance.

Best regards,
João Assunção

Email: joao.assuncao@exploitsys.com
Mobile: +351 916968984
Phone: +351 211933149
Web: www.exploitsys.com

Re: How to use configuration placeholders in karaf configs

Posted by Jean-Baptiste Onofre <jb...@nanthrax.net>.
Hi,

I’m suspecting the interpolation plugin that we added in 4.3.0.

Let me try to reproduce and fix that.

Regards
JB

> Le 20 mai 2021 à 18:59, João Assunção <jo...@exploitsys.com> a écrit :
> 
> I guess I found the culprit. 
> FeatureConfigInstaller uses TypedProperties to load the properties from the feature config element.
> Apparently TypedProperties performs variable interpolation and replaces my placeholders. I still don't understand why sometimes they are replaced and other times they don't
> 
> João Assunção
> 
> Email: joao.assuncao@exploitsys.com <ma...@exploitsys.com>
> Mobile: +351 916968984
> Phone: +351 211933149
> Web: www.exploitsys.com <http://www.exploitsys.com/>
> 
> 
> 
> 
> On Thu, May 20, 2021 at 4:47 PM João Assunção <joao.assuncao@exploitsys.com <ma...@exploitsys.com>> wrote:
> Hello JB
> 
> Yes I'm using Karaf 4.3.0
> 
> I tried with override="true", specifying the placeholder value in custom.properties, and with -D. The behavior is the same.
> For the same feature, some cfg files keep the placeholder while others have the placeholder replaced by an empty string.
> Another weird behavior is that this doesn't occur in my machine but occurs in two other machines. All them are Linux machines running openjdk but mine is a bit slower. 
> 
> I will try to use the <configfile> element instead of <config>
> 
> 
> 
> João Assunção
> 
> Email: joao.assuncao@exploitsys.com <ma...@exploitsys.com>
> Mobile: +351 916968984
> Phone: +351 211933149
> Web: www.exploitsys.com <http://www.exploitsys.com/>
> 
> 
> 
> 
> On Thu, May 20, 2021 at 3:54 PM Jean-Baptiste Onofre <jb@nanthrax.net <ma...@nanthrax.net>> wrote:
> Hi,
> 
> If you want to always take config content from the features, you can user overwrite="true" flag.
> 
> You can override with -D (see http://blog.nanthrax.net/?p=1038 <http://blog.nanthrax.net/?p=1038>).
> 
> I guess you are using Karaf 4.3.x right ? 
> 
> Regards
> JB
> 
>> Le 20 mai 2021 à 16:33, João Assunção <joao.assuncao@exploitsys.com <ma...@exploitsys.com>> a écrit :
>> 
>> Hello all,
>> 
>> I'm trying to use placeholders in configurations but I noticed some weird behavior. Sometimes the placeholder is replaced by an empty string, in other situations by the value of the property and in others not replaced at all.
>> 
>> One of my features contains the following configurations:
>> ...
>> <config name="com.atobe.ort.photo.repository.PhotoRepositoryServiceProvider" append="false">
>>         storageDirectory=${tzc.data}/photos
>> </config>
>> <config name="pt.brisa.service.metrics.rrd.internal.RRDPersistenceServiceProvider" append="false">
>>             rrdDefFile = etc/tzc_metrics.xml
>>             rrdRepository = ${tzc.data}/rrd
>>             reportingInterval = 60
>> </config>
>> ..
>>        
>> When the feature is installed, with tzc.data set to "myData", sometimes i get the following cfg files:
>> == com.atobe.ort.photo.repository.PhotoRepositoryServiceProvider.cfg ==
>> storageDirectory=${tzc.data}/photos
>> org.apache.karaf.features.configKey = com.atobe.ort.photo.repository.PhotoRepositoryServiceProvider
>> 
>> == pt.brisa.service.metrics.rrd.internal.RRDPersistenceServiceProvider.cfg ==
>> rrdDefFile = etc/tzc_metrics.xml
>> rrdRepository = myData/rrd
>> reportingInterval = 60
>> org.apache.karaf.features.configKey = pt.brisa.service.metrics.rrd.internal.RRDPersistenceServiceProvider
>> 
>> I tried specifying the variable name in config.properties and using  the -D  flag
>> 
>> Ideally I would like the placeholder to be replaced by the actual value only when the configuration is passed to the service.
>> 
>> What am I doing wrong ?
>> 
>> Thank you in advance.
>> 
>> Best regards,
>> João Assunção
>> 
>> Email: joao.assuncao@exploitsys.com <ma...@exploitsys.com>
>> Mobile: +351 916968984
>> Phone: +351 211933149
>> Web: www.exploitsys.com <http://www.exploitsys.com/>
>> 
>> 
> 


Re: How to use configuration placeholders in karaf configs

Posted by João Assunção <jo...@exploitsys.com>.
I guess I found the culprit.
FeatureConfigInstaller uses TypedProperties to load the properties from the
feature config element.
Apparently TypedProperties performs variable interpolation and replaces my
placeholders. I still don't understand why sometimes they are replaced and
other times they don't

João Assunção

Email: joao.assuncao@exploitsys.com
Mobile: +351 916968984
Phone: +351 211933149
Web: www.exploitsys.com




On Thu, May 20, 2021 at 4:47 PM João Assunção <jo...@exploitsys.com>
wrote:

> Hello JB
>
> Yes I'm using Karaf 4.3.0
>
> I tried with override="true", specifying the placeholder value in
> custom.properties, and with -D. The behavior is the same.
> For the same feature, some cfg files keep the placeholder while others
> have the placeholder replaced by an empty string.
> Another weird behavior is that this doesn't occur in my machine but
> occurs in two other machines. All them are Linux machines running openjdk
> but mine is a bit slower.
>
> I will try to use the <configfile> element instead of <config>
>
>
>
> João Assunção
>
> Email: joao.assuncao@exploitsys.com
> Mobile: +351 916968984
> Phone: +351 211933149
> Web: www.exploitsys.com
>
>
>
>
> On Thu, May 20, 2021 at 3:54 PM Jean-Baptiste Onofre <jb...@nanthrax.net>
> wrote:
>
>> Hi,
>>
>> If you want to always take config content from the features, you can user
>> overwrite="true" flag.
>>
>> You can override with -D (see http://blog.nanthrax.net/?p=1038).
>>
>> I guess you are using Karaf 4.3.x right ?
>>
>> Regards
>> JB
>>
>> Le 20 mai 2021 à 16:33, João Assunção <jo...@exploitsys.com> a
>> écrit :
>>
>> Hello all,
>>
>> I'm trying to use placeholders in configurations but I noticed some weird
>> behavior. Sometimes the placeholder is replaced by an empty string, in
>> other situations by the value of the property and in others not replaced at
>> all.
>>
>> One of my features contains the following configurations:
>> ...
>> <config
>> name="com.atobe.ort.photo.repository.PhotoRepositoryServiceProvider"
>> append="false">
>>         storageDirectory=${tzc.data}/photos
>> </config>
>> <config
>> name="pt.brisa.service.metrics.rrd.internal.RRDPersistenceServiceProvider"
>> append="false">
>>             rrdDefFile = etc/tzc_metrics.xml
>>             rrdRepository = ${tzc.data}/rrd
>>             reportingInterval = 60
>> </config>
>> ..
>>
>> When the feature is installed, with tzc.data set to "myData", sometimes i
>> get the following cfg files:
>> *== com.atobe.ort.photo.repository.PhotoRepositoryServiceProvider.cfg ==*
>> storageDirectory=${tzc.data}/photos
>> org.apache.karaf.features.configKey =
>> com.atobe.ort.photo.repository.PhotoRepositoryServiceProvider
>>
>> *==
>> pt.brisa.service.metrics.rrd.internal.RRDPersistenceServiceProvider.cfg ==*
>> rrdDefFile = etc/tzc_metrics.xml
>> rrdRepository = myData/rrd
>> reportingInterval = 60
>> org.apache.karaf.features.configKey =
>> pt.brisa.service.metrics.rrd.internal.RRDPersistenceServiceProvider
>>
>> I tried specifying the variable name in config.properties and using  the
>> -D  flag
>>
>> Ideally I would like the placeholder to be replaced by the actual value
>> only when the configuration is passed to the service.
>>
>> What am I doing wrong ?
>>
>> Thank you in advance.
>>
>> Best regards,
>> João Assunção
>>
>> Email: joao.assuncao@exploitsys.com
>> Mobile: +351 916968984
>> Phone: +351 211933149
>> Web: www.exploitsys.com
>>
>>
>>
>>

Re: How to use configuration placeholders in karaf configs

Posted by João Assunção <jo...@exploitsys.com>.
Hello JB

Yes I'm using Karaf 4.3.0

I tried with override="true", specifying the placeholder value in
custom.properties, and with -D. The behavior is the same.
For the same feature, some cfg files keep the placeholder while others have
the placeholder replaced by an empty string.
Another weird behavior is that this doesn't occur in my machine but
occurs in two other machines. All them are Linux machines running openjdk
but mine is a bit slower.

I will try to use the <configfile> element instead of <config>



João Assunção

Email: joao.assuncao@exploitsys.com
Mobile: +351 916968984
Phone: +351 211933149
Web: www.exploitsys.com




On Thu, May 20, 2021 at 3:54 PM Jean-Baptiste Onofre <jb...@nanthrax.net>
wrote:

> Hi,
>
> If you want to always take config content from the features, you can user
> overwrite="true" flag.
>
> You can override with -D (see http://blog.nanthrax.net/?p=1038).
>
> I guess you are using Karaf 4.3.x right ?
>
> Regards
> JB
>
> Le 20 mai 2021 à 16:33, João Assunção <jo...@exploitsys.com> a
> écrit :
>
> Hello all,
>
> I'm trying to use placeholders in configurations but I noticed some weird
> behavior. Sometimes the placeholder is replaced by an empty string, in
> other situations by the value of the property and in others not replaced at
> all.
>
> One of my features contains the following configurations:
> ...
> <config
> name="com.atobe.ort.photo.repository.PhotoRepositoryServiceProvider"
> append="false">
>         storageDirectory=${tzc.data}/photos
> </config>
> <config
> name="pt.brisa.service.metrics.rrd.internal.RRDPersistenceServiceProvider"
> append="false">
>             rrdDefFile = etc/tzc_metrics.xml
>             rrdRepository = ${tzc.data}/rrd
>             reportingInterval = 60
> </config>
> ..
>
> When the feature is installed, with tzc.data set to "myData", sometimes i
> get the following cfg files:
> *== com.atobe.ort.photo.repository.PhotoRepositoryServiceProvider.cfg ==*
> storageDirectory=${tzc.data}/photos
> org.apache.karaf.features.configKey =
> com.atobe.ort.photo.repository.PhotoRepositoryServiceProvider
>
> *==
> pt.brisa.service.metrics.rrd.internal.RRDPersistenceServiceProvider.cfg ==*
> rrdDefFile = etc/tzc_metrics.xml
> rrdRepository = myData/rrd
> reportingInterval = 60
> org.apache.karaf.features.configKey =
> pt.brisa.service.metrics.rrd.internal.RRDPersistenceServiceProvider
>
> I tried specifying the variable name in config.properties and using  the
> -D  flag
>
> Ideally I would like the placeholder to be replaced by the actual value
> only when the configuration is passed to the service.
>
> What am I doing wrong ?
>
> Thank you in advance.
>
> Best regards,
> João Assunção
>
> Email: joao.assuncao@exploitsys.com
> Mobile: +351 916968984
> Phone: +351 211933149
> Web: www.exploitsys.com
>
>
>
>

Re: How to use configuration placeholders in karaf configs

Posted by Jean-Baptiste Onofre <jb...@nanthrax.net>.
Hi,

If you want to always take config content from the features, you can user overwrite="true" flag.

You can override with -D (see http://blog.nanthrax.net/?p=1038 <http://blog.nanthrax.net/?p=1038>).

I guess you are using Karaf 4.3.x right ? 

Regards
JB

> Le 20 mai 2021 à 16:33, João Assunção <jo...@exploitsys.com> a écrit :
> 
> Hello all,
> 
> I'm trying to use placeholders in configurations but I noticed some weird behavior. Sometimes the placeholder is replaced by an empty string, in other situations by the value of the property and in others not replaced at all.
> 
> One of my features contains the following configurations:
> ...
> <config name="com.atobe.ort.photo.repository.PhotoRepositoryServiceProvider" append="false">
>         storageDirectory=${tzc.data}/photos
> </config>
> <config name="pt.brisa.service.metrics.rrd.internal.RRDPersistenceServiceProvider" append="false">
>             rrdDefFile = etc/tzc_metrics.xml
>             rrdRepository = ${tzc.data}/rrd
>             reportingInterval = 60
> </config>
> ..
>        
> When the feature is installed, with tzc.data set to "myData", sometimes i get the following cfg files:
> == com.atobe.ort.photo.repository.PhotoRepositoryServiceProvider.cfg ==
> storageDirectory=${tzc.data}/photos
> org.apache.karaf.features.configKey = com.atobe.ort.photo.repository.PhotoRepositoryServiceProvider
> 
> == pt.brisa.service.metrics.rrd.internal.RRDPersistenceServiceProvider.cfg ==
> rrdDefFile = etc/tzc_metrics.xml
> rrdRepository = myData/rrd
> reportingInterval = 60
> org.apache.karaf.features.configKey = pt.brisa.service.metrics.rrd.internal.RRDPersistenceServiceProvider
> 
> I tried specifying the variable name in config.properties and using  the -D  flag
> 
> Ideally I would like the placeholder to be replaced by the actual value only when the configuration is passed to the service.
> 
> What am I doing wrong ?
> 
> Thank you in advance.
> 
> Best regards,
> João Assunção
> 
> Email: joao.assuncao@exploitsys.com <ma...@exploitsys.com>
> Mobile: +351 916968984
> Phone: +351 211933149
> Web: www.exploitsys.com <http://www.exploitsys.com/>
> 
>