You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Guillaume Nodet <gn...@gmail.com> on 2013/12/04 16:16:36 UTC

Re: File Install System Properties

Felix utils substitution mechanism has a notion of SubstitutionCallback, so
it should not be very difficult to have file install providing a custom
callback for that.
For example you could have a callback which substitutes ${env:xxx} with the
value of the xxx env variable, one for ${sys:xxx} (only system variable)
and the current one which delegates to the bundle, then sys properties.
When the ConfigInstaller loads the configuration, instead of
    InterpolationHelper.performSubstitution((Map) p, context);
which translates to
   InterpolationHelper.performSubstitution(properties, new
BundleContextSubstitutionCallback(context));
we could give a different callback.
Another way would be simply to extend the BundleContextSubstitutionCallback
to delegate to env properties if not found in system properties.



On Mon, Dec 10, 2012 at 11:22 PM, Bengt Rodehav <be...@rodehav.com> wrote:

> I also change the bin/karaf startup script as well as the wrapper.conf
> since I'm running Karaf as a Windows service. Not the route I want either
> but right now that's what i do.
>
> /Bengt
>
>
> 2012/12/10 andrew burks <ab...@yahoo.com>
>
> > Since this option isn't available now, is there a workaround that I can
> > use? Currently I have changed the bin/karaf startup script but this isn't
> > the route I want to take going forward. I am currently attempting to set
> > the system property through the JAVA_OPTS environment variable since this
> > is an environment variable that the system knows of and uses in the
> script
> > but I am not having much luck.
> >
> > - Andrew
> >
> >
> > ________________________________
> >  From: Bengt Rodehav <be...@rodehav.com>
> > To: users@felix.apache.org; andrew burks <ab...@yahoo.com>
> > Sent: Monday, December 10, 2012 1:38 PM
> > Subject: Re: File Install System Properties
> >
> > I agree with you that access to the environment variables would be
> great. I
> > just meant that unless you put the environment variables in a separate
> > namespace (like giving them a prefix of "env." or similar) you would have
> > to specify how to handle name collisions.
> >
> > Today, the variables accessible in FileInstall can come from several
> > sources where system properties is one of them. However, the source of
> the
> > variable is not visible in the name of the variable. I was assuming that
> > this was by design which is why I suggested that environment variables
> > would have the "lowest" priority and would be overridden by system
> > properties. But, bottom line, I'm also interested in acessing environment
> > variables from FileInstall - it would make my life easier too.
> >
> > /Bengt
> >
> >
> > 2012/12/10 andrew burks <ab...@yahoo.com>
> >
> > > Felix,
> > >
> > > That is sort of the way I am currently setting my system property, and
> it
> > > is the only option I see so far.
> > >
> > > Bengt,
> > >
> > > Yes, I agree with your statement about system properties overriding
> > > environment properties. But it would be nice to be able to have file
> > > install access the environment variables. Ultimately, I am trying to
> have
> > > multiple karaf instances watch the same directory for configuration
> file
> > > changes. This has been accomplished, but it would be a lot cleaner if
> the
> > > file install could access environment variables.
> > >
> > > - Andrew
> > >
> > >
> > > ________________________________
> > >  From: Bengt Rodehav <be...@rodehav.com>
> > > To: users@felix.apache.org
> > > Sent: Monday, December 10, 2012 7:28 AM
> > > Subject: Re: File Install System Properties
> > >
> > > I guess the System.getEnv() method could be used to give FileInstall
> > access
> > > to the environment variables. I've been thinking about this myself.
> Right
> > > now I have to fill my startup scripts (and wrapper.conf) with "-D..."
> for
> > > every environment variable I want to use. File install could have an
> > option
> > > to enable this. Logically, I think system properties should override
> > > environment properties.
> > >
> > > /Bengt
> > >
> > >
> > > 2012/12/10 Felix Meschberger <fm...@adobe.com>
> > >
> > > > Hi
> > > >
> > > > This is probably more of a generic Java question than a specific
> Karaf
> > or
> > > > Felix question...
> > > >
> > > > The only way, I know if is to launch Java with things like
> > > >
> > > >   java -Dsys.prop="$ENV_PROP"
> > > >
> > > > Regards
> > > > Felix
> > > >
> > > > Am 07.12.2012 um 21:21 schrieb Andrew Burks:
> > > >
> > > > > Hello Felix,
> > > > >
> > > > > Thanks for the response. Yes, file install supports java
> properties,
> > > but
> > > > my question is that is there any way to set a custom java property
> with
> > > the
> > > > value of a system variable? I've tried specifying it in the
> > > > system.properties file but it did not work. The only way I could get
> it
> > > to
> > > > work was setting the property on the command line when starting up my
> > > karaf
> > > > instance.
> > > > >
> > > > > - Andrew
> > > > >
> > > > >
> > > > >
> > > > > On Dec 4, 2012, at 10:16 AM, Felix Meschberger <fmeschbe@adobe.com
> >
> > > > wrote:
> > > > >
> > > > >> Hi,
> > > > >>
> > > > >> (Not knowledgeable in the internal details)
> > > > >>
> > > > >> Your description sounds like File Install supports Java system
> > > > properties as replacement variables. This is not the same as
> > environment
> > > > variables.
> > > > >>
> > > > >> Regards
> > > > >> Felix
> > > > >>
> > > > >> Am 03.12.2012 um 15:18 schrieb andrew burks:
> > > > >>
> > > > >>> Hi,
> > > > >>>
> > > > >>> I have a few questions about FileInstall and system properties. I
> > am
> > > > working in a linux environment and I would like to know if I can use
> an
> > > > environment variable as a substitution property in a config file. If
> > so,
> > > > how would I go about this? I have created an environment variable and
> > > > substituted it in my fileinstall config file but fileinstall says
> that
> > it
> > > > does not exist. I know it exists because I am able to echo the
> contents
> > > of
> > > > the variable on the command line. I discovered a workaround online
> but
> > > this
> > > > involved changing the bin/karaf startup script and this isn't the the
> > > way I
> > > > would like to go. Could you let me know what I am doing wrong here? I
> > am
> > > > using apache karaf 2.2.7 and file install 3.2.2.
> > > > >>>
> > > > >>> Thanks,
> > > > >>>
> > > > >>> Andrew Burks
> > > > >>
> > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> > > > For additional commands, e-mail: users-help@felix.apache.org
> > > >
> > > >
> > >
> >
>



-- 
------------------------
Guillaume Nodet
------------------------
Red Hat, Open Source Integration

Email: gnodet@redhat.com
Web: http://fusesource.com
Blog: http://gnodet.blogspot.com/

Re: File Install System Properties

Posted by Bengt Rodehav <be...@rodehav.com>.
I think both of these ideas would be welcome additions. My preference is
your first alternative since it is more explicit and wouldn't bring you as
many surprises as if delegation were used.

Would this also work in the custom.properties file in Karaf? I tend to use
custom.properties for variables that I want to reuse in different
configuration files.

While we are on the "variable" subject, I also have an oustanding request
to be able to use variable substitution in org.apache.karaf.features.cfg (
https://issues.apache.org/jira/browse/KARAF-2060) but I guess this is a
Karaf issue and not a Felix issue.

/Bengt


2013/12/4 Guillaume Nodet <gn...@gmail.com>

> Felix utils substitution mechanism has a notion of SubstitutionCallback, so
> it should not be very difficult to have file install providing a custom
> callback for that.
> For example you could have a callback which substitutes ${env:xxx} with the
> value of the xxx env variable, one for ${sys:xxx} (only system variable)
> and the current one which delegates to the bundle, then sys properties.
> When the ConfigInstaller loads the configuration, instead of
>     InterpolationHelper.performSubstitution((Map) p, context);
> which translates to
>    InterpolationHelper.performSubstitution(properties, new
> BundleContextSubstitutionCallback(context));
> we could give a different callback.
> Another way would be simply to extend the BundleContextSubstitutionCallback
> to delegate to env properties if not found in system properties.
>
>
>
> On Mon, Dec 10, 2012 at 11:22 PM, Bengt Rodehav <be...@rodehav.com> wrote:
>
> > I also change the bin/karaf startup script as well as the wrapper.conf
> > since I'm running Karaf as a Windows service. Not the route I want either
> > but right now that's what i do.
> >
> > /Bengt
> >
> >
> > 2012/12/10 andrew burks <ab...@yahoo.com>
> >
> > > Since this option isn't available now, is there a workaround that I can
> > > use? Currently I have changed the bin/karaf startup script but this
> isn't
> > > the route I want to take going forward. I am currently attempting to
> set
> > > the system property through the JAVA_OPTS environment variable since
> this
> > > is an environment variable that the system knows of and uses in the
> > script
> > > but I am not having much luck.
> > >
> > > - Andrew
> > >
> > >
> > > ________________________________
> > >  From: Bengt Rodehav <be...@rodehav.com>
> > > To: users@felix.apache.org; andrew burks <ab...@yahoo.com>
> > > Sent: Monday, December 10, 2012 1:38 PM
> > > Subject: Re: File Install System Properties
> > >
> > > I agree with you that access to the environment variables would be
> > great. I
> > > just meant that unless you put the environment variables in a separate
> > > namespace (like giving them a prefix of "env." or similar) you would
> have
> > > to specify how to handle name collisions.
> > >
> > > Today, the variables accessible in FileInstall can come from several
> > > sources where system properties is one of them. However, the source of
> > the
> > > variable is not visible in the name of the variable. I was assuming
> that
> > > this was by design which is why I suggested that environment variables
> > > would have the "lowest" priority and would be overridden by system
> > > properties. But, bottom line, I'm also interested in acessing
> environment
> > > variables from FileInstall - it would make my life easier too.
> > >
> > > /Bengt
> > >
> > >
> > > 2012/12/10 andrew burks <ab...@yahoo.com>
> > >
> > > > Felix,
> > > >
> > > > That is sort of the way I am currently setting my system property,
> and
> > it
> > > > is the only option I see so far.
> > > >
> > > > Bengt,
> > > >
> > > > Yes, I agree with your statement about system properties overriding
> > > > environment properties. But it would be nice to be able to have file
> > > > install access the environment variables. Ultimately, I am trying to
> > have
> > > > multiple karaf instances watch the same directory for configuration
> > file
> > > > changes. This has been accomplished, but it would be a lot cleaner if
> > the
> > > > file install could access environment variables.
> > > >
> > > > - Andrew
> > > >
> > > >
> > > > ________________________________
> > > >  From: Bengt Rodehav <be...@rodehav.com>
> > > > To: users@felix.apache.org
> > > > Sent: Monday, December 10, 2012 7:28 AM
> > > > Subject: Re: File Install System Properties
> > > >
> > > > I guess the System.getEnv() method could be used to give FileInstall
> > > access
> > > > to the environment variables. I've been thinking about this myself.
> > Right
> > > > now I have to fill my startup scripts (and wrapper.conf) with "-D..."
> > for
> > > > every environment variable I want to use. File install could have an
> > > option
> > > > to enable this. Logically, I think system properties should override
> > > > environment properties.
> > > >
> > > > /Bengt
> > > >
> > > >
> > > > 2012/12/10 Felix Meschberger <fm...@adobe.com>
> > > >
> > > > > Hi
> > > > >
> > > > > This is probably more of a generic Java question than a specific
> > Karaf
> > > or
> > > > > Felix question...
> > > > >
> > > > > The only way, I know if is to launch Java with things like
> > > > >
> > > > >   java -Dsys.prop="$ENV_PROP"
> > > > >
> > > > > Regards
> > > > > Felix
> > > > >
> > > > > Am 07.12.2012 um 21:21 schrieb Andrew Burks:
> > > > >
> > > > > > Hello Felix,
> > > > > >
> > > > > > Thanks for the response. Yes, file install supports java
> > properties,
> > > > but
> > > > > my question is that is there any way to set a custom java property
> > with
> > > > the
> > > > > value of a system variable? I've tried specifying it in the
> > > > > system.properties file but it did not work. The only way I could
> get
> > it
> > > > to
> > > > > work was setting the property on the command line when starting up
> my
> > > > karaf
> > > > > instance.
> > > > > >
> > > > > > - Andrew
> > > > > >
> > > > > >
> > > > > >
> > > > > > On Dec 4, 2012, at 10:16 AM, Felix Meschberger <
> fmeschbe@adobe.com
> > >
> > > > > wrote:
> > > > > >
> > > > > >> Hi,
> > > > > >>
> > > > > >> (Not knowledgeable in the internal details)
> > > > > >>
> > > > > >> Your description sounds like File Install supports Java system
> > > > > properties as replacement variables. This is not the same as
> > > environment
> > > > > variables.
> > > > > >>
> > > > > >> Regards
> > > > > >> Felix
> > > > > >>
> > > > > >> Am 03.12.2012 um 15:18 schrieb andrew burks:
> > > > > >>
> > > > > >>> Hi,
> > > > > >>>
> > > > > >>> I have a few questions about FileInstall and system
> properties. I
> > > am
> > > > > working in a linux environment and I would like to know if I can
> use
> > an
> > > > > environment variable as a substitution property in a config file.
> If
> > > so,
> > > > > how would I go about this? I have created an environment variable
> and
> > > > > substituted it in my fileinstall config file but fileinstall says
> > that
> > > it
> > > > > does not exist. I know it exists because I am able to echo the
> > contents
> > > > of
> > > > > the variable on the command line. I discovered a workaround online
> > but
> > > > this
> > > > > involved changing the bin/karaf startup script and this isn't the
> the
> > > > way I
> > > > > would like to go. Could you let me know what I am doing wrong
> here? I
> > > am
> > > > > using apache karaf 2.2.7 and file install 3.2.2.
> > > > > >>>
> > > > > >>> Thanks,
> > > > > >>>
> > > > > >>> Andrew Burks
> > > > > >>
> > > > >
> > > > >
> > > > >
> ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> > > > > For additional commands, e-mail: users-help@felix.apache.org
> > > > >
> > > > >
> > > >
> > >
> >
>
>
>
> --
> ------------------------
> Guillaume Nodet
> ------------------------
> Red Hat, Open Source Integration
>
> Email: gnodet@redhat.com
> Web: http://fusesource.com
> Blog: http://gnodet.blogspot.com/
>