You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "DiFrango, Ronald (CONT)" <Ro...@capitalone.com> on 2014/02/13 20:53:55 UTC

Conditional Configuration Keys

All,

I searched around and could find an answer, I have a set of properties where I want to conditionally select them based upon environment variables.  For example, I have the following set:

schemas.default=DB
schemas.perf=PERF
schemas.qa=QA
schemas.int=INT

And I would like to do something to the effect of:

If (env.variable == 'qa')
schemas=QA
else If (env.variable == 'perf')
schemas=PERF
else If (env.variable == 'int)
schemas=int
else
schemas=DB

The way I accomplished this today is that I created an AOP interceptor that does this work and when the clients request "schema" it does this logic.

My preference would be to handle this during property loading time.  Are there any extensions where I could do such a thing?

Thanks,

Ron

________________________________________________________

The information contained in this e-mail is confidential and/or proprietary to Capital One and/or its affiliates. The information transmitted herewith is intended only for use by the individual or entity to which it is addressed.  If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.

RE: Conditional Configuration Keys

Posted by "DiFrango, Ronald (CONT)" <Ro...@capitalone.com>.
Thanks Oliver...I'll continue down that path.

Ron DiFrango
Director/ Architect | Captech  
Solutions Architecture | Team Super Glue (Mobile)
cell: (804) 855-9196| ronald.difrango@capitalone.com



-----Original Message-----
From: Oliver Heger [mailto:oliver.heger@oliver-heger.de] 
Sent: Thursday, February 13, 2014 3:43 PM
To: Commons Users List
Subject: Re: Conditional Configuration Keys

Hi Ron,

Am 13.02.2014 21:28, schrieb DiFrango, Ronald (CONT):
> Oliver,
> 
> Thanks for that reference, and while that is somewhat helpful it means that for each environment, we still need a separate properties file for each of the environments and another one for the common stuff.  Previously, we had accomplished this before by conditionally loading files based upon path within our XML file like:
> 
> 		<properties
> 			fileName="${config.root}/test-app/environment/${config.env}/test.properties"
> 			listDelimiter="|">
> 			<reloadingStrategy refreshDelay="10000"
> 				config-class="org.apache.commons.configuration.reloading.FileChangedReloadingStrategy" />
> 		</properties>
> 
> My hope was to find a way to do that a little bit more concisely within a single file or as I mentioned hooking into the property loading process.

your current solution based on a DefaultConfigurationBuilder and interpolated variables is more or less the recommended way for your use case. I don't think that this can be much improved.

If you only use properties files, an option could be using the include directive [1] in a clever way. Here you can use variables, too.

There is also the possibility to set an IOFactory on a PropertiesConfiguration. This factory is used for creating an input stream to the file to read. But it is more intended for adapting the format to be parsed and not for selecting different sets of properties.

Oliver

[1]
http://commons.apache.org/proper/commons-configuration/userguide/howto_properties.html#Includes

> 
> Thanks,
> 
> Ron
> 
> -----Original Message-----
> From: Oliver Heger [mailto:oliver.heger@oliver-heger.de]
> Sent: Thursday, February 13, 2014 3:14 PM
> To: Commons Users List
> Subject: Re: Conditional Configuration Keys
> 
> Hi Ron,
> 
> Am 13.02.2014 20:53, schrieb DiFrango, Ronald (CONT):
>> All,
>>
>> I searched around and could find an answer, I have a set of properties where I want to conditionally select them based upon environment variables.  For example, I have the following set:
>>
>> schemas.default=DB
>> schemas.perf=PERF
>> schemas.qa=QA
>> schemas.int=INT
>>
>> And I would like to do something to the effect of:
>>
>> If (env.variable == 'qa')
>> schemas=QA
>> else If (env.variable == 'perf')
>> schemas=PERF
>> else If (env.variable == 'int)
>> schemas=int
>> else
>> schemas=DB
>>
>> The way I accomplished this today is that I created an AOP interceptor that does this work and when the clients request "schema" it does this logic.
>>
>> My preference would be to handle this during property loading time.  Are there any extensions where I could do such a thing?
> 
> You might want to have a look at multi-tenant configurations [1]. If I understand you correctly, this feature solves your problem. It is possible to access different configuration sources based on interpolated properties. System properties or environment variables can also be used to determine the set of properties available.
> 
> HTH
> Oliver
> 
> [1]
> http://commons.apache.org/proper/commons-configuration/userguide/howto
> _multitenant.html#Multi-tenant_Configurations
> 
>>
>> Thanks,
>>
>> Ron
>>
>> ________________________________________________________
>>
>> The information contained in this e-mail is confidential and/or proprietary to Capital One and/or its affiliates. The information transmitted herewith is intended only for use by the individual or entity to which it is addressed.  If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 
> ________________________________________________________
> 
> The information contained in this e-mail is confidential and/or proprietary to Capital One and/or its affiliates. The information transmitted herewith is intended only for use by the individual or entity to which it is addressed.  If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org

________________________________________________________

The information contained in this e-mail is confidential and/or proprietary to Capital One and/or its affiliates. The information transmitted herewith is intended only for use by the individual or entity to which it is addressed.  If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: Conditional Configuration Keys

Posted by Oliver Heger <ol...@oliver-heger.de>.
Hi Ron,

Am 13.02.2014 21:28, schrieb DiFrango, Ronald (CONT):
> Oliver,
> 
> Thanks for that reference, and while that is somewhat helpful it means that for each environment, we still need a separate properties file for each of the environments and another one for the common stuff.  Previously, we had accomplished this before by conditionally loading files based upon path within our XML file like:
> 
> 		<properties
> 			fileName="${config.root}/test-app/environment/${config.env}/test.properties"
> 			listDelimiter="|">
> 			<reloadingStrategy refreshDelay="10000"
> 				config-class="org.apache.commons.configuration.reloading.FileChangedReloadingStrategy" />
> 		</properties>
> 
> My hope was to find a way to do that a little bit more concisely within a single file or as I mentioned hooking into the property loading process.

your current solution based on a DefaultConfigurationBuilder and
interpolated variables is more or less the recommended way for your use
case. I don't think that this can be much improved.

If you only use properties files, an option could be using the include
directive [1] in a clever way. Here you can use variables, too.

There is also the possibility to set an IOFactory on a
PropertiesConfiguration. This factory is used for creating an input
stream to the file to read. But it is more intended for adapting the
format to be parsed and not for selecting different sets of properties.

Oliver

[1]
http://commons.apache.org/proper/commons-configuration/userguide/howto_properties.html#Includes

> 
> Thanks,
> 
> Ron
> 
> -----Original Message-----
> From: Oliver Heger [mailto:oliver.heger@oliver-heger.de] 
> Sent: Thursday, February 13, 2014 3:14 PM
> To: Commons Users List
> Subject: Re: Conditional Configuration Keys
> 
> Hi Ron,
> 
> Am 13.02.2014 20:53, schrieb DiFrango, Ronald (CONT):
>> All,
>>
>> I searched around and could find an answer, I have a set of properties where I want to conditionally select them based upon environment variables.  For example, I have the following set:
>>
>> schemas.default=DB
>> schemas.perf=PERF
>> schemas.qa=QA
>> schemas.int=INT
>>
>> And I would like to do something to the effect of:
>>
>> If (env.variable == 'qa')
>> schemas=QA
>> else If (env.variable == 'perf')
>> schemas=PERF
>> else If (env.variable == 'int)
>> schemas=int
>> else
>> schemas=DB
>>
>> The way I accomplished this today is that I created an AOP interceptor that does this work and when the clients request "schema" it does this logic.
>>
>> My preference would be to handle this during property loading time.  Are there any extensions where I could do such a thing?
> 
> You might want to have a look at multi-tenant configurations [1]. If I understand you correctly, this feature solves your problem. It is possible to access different configuration sources based on interpolated properties. System properties or environment variables can also be used to determine the set of properties available.
> 
> HTH
> Oliver
> 
> [1]
> http://commons.apache.org/proper/commons-configuration/userguide/howto_multitenant.html#Multi-tenant_Configurations
> 
>>
>> Thanks,
>>
>> Ron
>>
>> ________________________________________________________
>>
>> The information contained in this e-mail is confidential and/or proprietary to Capital One and/or its affiliates. The information transmitted herewith is intended only for use by the individual or entity to which it is addressed.  If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 
> ________________________________________________________
> 
> The information contained in this e-mail is confidential and/or proprietary to Capital One and/or its affiliates. The information transmitted herewith is intended only for use by the individual or entity to which it is addressed.  If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


RE: Conditional Configuration Keys

Posted by "DiFrango, Ronald (CONT)" <Ro...@capitalone.com>.
Oliver,

Thanks for that reference, and while that is somewhat helpful it means that for each environment, we still need a separate properties file for each of the environments and another one for the common stuff.  Previously, we had accomplished this before by conditionally loading files based upon path within our XML file like:

		<properties
			fileName="${config.root}/test-app/environment/${config.env}/test.properties"
			listDelimiter="|">
			<reloadingStrategy refreshDelay="10000"
				config-class="org.apache.commons.configuration.reloading.FileChangedReloadingStrategy" />
		</properties>

My hope was to find a way to do that a little bit more concisely within a single file or as I mentioned hooking into the property loading process.

Thanks,

Ron

-----Original Message-----
From: Oliver Heger [mailto:oliver.heger@oliver-heger.de] 
Sent: Thursday, February 13, 2014 3:14 PM
To: Commons Users List
Subject: Re: Conditional Configuration Keys

Hi Ron,

Am 13.02.2014 20:53, schrieb DiFrango, Ronald (CONT):
> All,
> 
> I searched around and could find an answer, I have a set of properties where I want to conditionally select them based upon environment variables.  For example, I have the following set:
> 
> schemas.default=DB
> schemas.perf=PERF
> schemas.qa=QA
> schemas.int=INT
> 
> And I would like to do something to the effect of:
> 
> If (env.variable == 'qa')
> schemas=QA
> else If (env.variable == 'perf')
> schemas=PERF
> else If (env.variable == 'int)
> schemas=int
> else
> schemas=DB
> 
> The way I accomplished this today is that I created an AOP interceptor that does this work and when the clients request "schema" it does this logic.
> 
> My preference would be to handle this during property loading time.  Are there any extensions where I could do such a thing?

You might want to have a look at multi-tenant configurations [1]. If I understand you correctly, this feature solves your problem. It is possible to access different configuration sources based on interpolated properties. System properties or environment variables can also be used to determine the set of properties available.

HTH
Oliver

[1]
http://commons.apache.org/proper/commons-configuration/userguide/howto_multitenant.html#Multi-tenant_Configurations

> 
> Thanks,
> 
> Ron
> 
> ________________________________________________________
> 
> The information contained in this e-mail is confidential and/or proprietary to Capital One and/or its affiliates. The information transmitted herewith is intended only for use by the individual or entity to which it is addressed.  If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org

________________________________________________________

The information contained in this e-mail is confidential and/or proprietary to Capital One and/or its affiliates. The information transmitted herewith is intended only for use by the individual or entity to which it is addressed.  If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: Conditional Configuration Keys

Posted by Oliver Heger <ol...@oliver-heger.de>.
Hi Ron,

Am 13.02.2014 20:53, schrieb DiFrango, Ronald (CONT):
> All,
> 
> I searched around and could find an answer, I have a set of properties where I want to conditionally select them based upon environment variables.  For example, I have the following set:
> 
> schemas.default=DB
> schemas.perf=PERF
> schemas.qa=QA
> schemas.int=INT
> 
> And I would like to do something to the effect of:
> 
> If (env.variable == 'qa')
> schemas=QA
> else If (env.variable == 'perf')
> schemas=PERF
> else If (env.variable == 'int)
> schemas=int
> else
> schemas=DB
> 
> The way I accomplished this today is that I created an AOP interceptor that does this work and when the clients request "schema" it does this logic.
> 
> My preference would be to handle this during property loading time.  Are there any extensions where I could do such a thing?

You might want to have a look at multi-tenant configurations [1]. If I
understand you correctly, this feature solves your problem. It is
possible to access different configuration sources based on interpolated
properties. System properties or environment variables can also be used
to determine the set of properties available.

HTH
Oliver

[1]
http://commons.apache.org/proper/commons-configuration/userguide/howto_multitenant.html#Multi-tenant_Configurations

> 
> Thanks,
> 
> Ron
> 
> ________________________________________________________
> 
> The information contained in this e-mail is confidential and/or proprietary to Capital One and/or its affiliates. The information transmitted herewith is intended only for use by the individual or entity to which it is addressed.  If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org