A command like config:edit that will let you replace only some properties?

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

A command like config:edit that will let you replace only some properties?

Steinar Bang
Is there a command similar to config:edit that will let you replace some
properties of an existing command instead of replacing all of them?

Whit config:edit you need to do a config:property-set for all of the
existing properties, of an existing config, even the properties that
haven't changed.

Thanks!


- Steinar

Reply | Threaded
Open this post in threaded view
|

Re: A command like config:edit that will let you replace only some properties?

jbonofre
Hi Steinar,

If you do:

karaf@root()> config:edit my.config
karaf@root()> config:property-set foo bar
karaf@root()> config:update

only foo will be changed, other properties are kept.

Not sure I follow what you mean.

Regards
JB

On 09/11/2019 17:58, Steinar Bang wrote:

> Is there a command similar to config:edit that will let you replace some
> properties of an existing command instead of replacing all of them?
>
> Whit config:edit you need to do a config:property-set for all of the
> existing properties, of an existing config, even the properties that
> haven't changed.
>
> Thanks!
>
>
> - Steinar
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|

Re: A command like config:edit that will let you replace only some properties?

cschneider
If you only want to change a single property you can also do this in one step:
config:property-set -p my.config foo bar  

Am So., 10. Nov. 2019 um 05:53 Uhr schrieb Jean-Baptiste Onofré <[hidden email]>:
Hi Steinar,

If you do:

karaf@root()> config:edit my.config
karaf@root()> config:property-set foo bar
karaf@root()> config:update

only foo will be changed, other properties are kept.

Not sure I follow what you mean.

Regards
JB

On 09/11/2019 17:58, Steinar Bang wrote:
> Is there a command similar to config:edit that will let you replace some
> properties of an existing command instead of replacing all of them?
>
> Whit config:edit you need to do a config:property-set for all of the
> existing properties, of an existing config, even the properties that
> haven't changed.
>
> Thanks!
>
>
> - Steinar
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com


--
--
Christian Schneider

http://www.liquid-reality.de

Computer Scientist

Reply | Threaded
Open this post in threaded view
|

Re: A command like config:edit that will let you replace only some properties?

Steinar Bang
In reply to this post by jbonofre
>>>>> Jean-Baptiste Onofré <[hidden email]>:

> Hi Steinar,
> If you do:

> karaf@root()> config:edit my.config
> karaf@root()> config:property-set foo bar
> karaf@root()> config:update

> only foo will be changed, other properties are kept.

> Not sure I follow what you mean.

Hm... I thought that when I tried this last week the resulting file only
had those properties I had added with config:property-set, ie. that the
other properties had gone missing...?

Maybe I fooled myself while testing?  I will try again and keep track of
what I'm doing...:-)

Reply | Threaded
Open this post in threaded view
|

Re: A command like config:edit that will let you replace only some properties?

Steinar Bang
In reply to this post by cschneider
>>>>> Christian Schneider <[hidden email]>:

> If you only want to change a single property you can also do this in one
> step:
> config:property-set -p my.config foo bar

Thanks!  I will try this.

Reply | Threaded
Open this post in threaded view
|

Re: A command like config:edit that will let you replace only some properties?

cschneider
Be careful though. After each such command the config is provided to the application. So if you want to change more than one property in one go then the approach from JB is better.

Christian

Am So., 10. Nov. 2019 um 15:55 Uhr schrieb Steinar Bang <[hidden email]>:
>>>>> Christian Schneider <[hidden email]>:

> If you only want to change a single property you can also do this in one
> step:
> config:property-set -p my.config foo bar

Thanks!  I will try this.



--
--
Christian Schneider

http://www.liquid-reality.de

Computer Scientist

Reply | Threaded
Open this post in threaded view
|

Re: A command like config:edit that will let you replace only some properties?

Steinar Bang
In reply to this post by Steinar Bang
>>>>> Steinar Bang <[hidden email]>:
>>>>> Jean-Baptiste Onofré <[hidden email]>:

>> If you do:

>> karaf@root()> config:edit my.config
>> karaf@root()> config:property-set foo bar
>> karaf@root()> config:update

>> only foo will be changed, other properties are kept.

>> Not sure I follow what you mean.

> Hm... I thought that when I tried this last week the resulting file
> only had those properties I had added with config:property-set,
> ie. that the other properties had gone missing...?

> Maybe I fooled myself while testing?  I will try again and keep track
> of what I'm doing...:-)

Nope, I tried it again now, and it didn't work for me.

Platform: karaf 4.2.7, openjdk 11, debian 10.1 "buster", amd64

Here's what I did:
 1. I installed my application using
     karaf@root()> feature:repo-add mvn:no.priv.bang.authservice/authservice/LATEST/xml/features
     Adding feature url mvn:no.priv.bang.authservice/authservice/LATEST/xml/features
     karaf@root()> feature:install user-admin-with-postgresql
     karaf@root()>
 2. This created the following file in etc/
     -rw-r--r--  1 sb sb   250 Nov 11 22:45 org.ops4j.datasource-authservice-production.cfg
 3. The content of the org.ops4j.datasource-authservice-production.cfg file is:
     osgi.jdbc.driver.name=PostgreSQL JDBC Driver
     dataSourceName=jdbc/authservice
     url=jdbc:postgresql:///authservice
     user=karaf
     password=karaf
     ops4j.preHook=authservicedb
     org.apache.karaf.features.configKey = org.ops4j.datasource-authservice-production
 4. Then I tried replacing just the url property:
     karaf@root()> config:edit org.ops4j.datasource-authservice-production
     karaf@root()> config:property-set url "jdbc:postgresql:///ukelonn"
     karaf@root()> config:update
     karaf@root()>
 5. The resulting file in the etc directory was much smaller
     -rw-r--r--  1 sb sb    33 Nov 11 22:50 org.ops4j.datasource-authservice-production.cfg
 6. The updated file content is just the url setting
     url = jdbc:postgresql:///ukelonn

Did I do something wrong?  Or should I report this as a bug in karaf JIRA?

Reply | Threaded
Open this post in threaded view
|

Re: A command like config:edit that will let you replace only some properties?

cschneider
Maybe it is related to the fact that the original configuration is a factory config.

Perhaps you created a new non factory config that overrides the factory one.

Christian

Am Mo., 11. Nov. 2019 um 22:55 Uhr schrieb Steinar Bang <[hidden email]>:
>>>>> Steinar Bang <[hidden email]>:
>>>>> Jean-Baptiste Onofré <[hidden email]>:

>> If you do:

>> karaf@root()> config:edit my.config
>> karaf@root()> config:property-set foo bar
>> karaf@root()> config:update

>> only foo will be changed, other properties are kept.

>> Not sure I follow what you mean.

> Hm... I thought that when I tried this last week the resulting file
> only had those properties I had added with config:property-set,
> ie. that the other properties had gone missing...?

> Maybe I fooled myself while testing?  I will try again and keep track
> of what I'm doing...:-)

Nope, I tried it again now, and it didn't work for me.

Platform: karaf 4.2.7, openjdk 11, debian 10.1 "buster", amd64

Here's what I did:
 1. I installed my application using
     karaf@root()> feature:repo-add mvn:no.priv.bang.authservice/authservice/LATEST/xml/features
     Adding feature url mvn:no.priv.bang.authservice/authservice/LATEST/xml/features
     karaf@root()> feature:install user-admin-with-postgresql
     karaf@root()>
 2. This created the following file in etc/
     -rw-r--r--  1 sb sb   250 Nov 11 22:45 org.ops4j.datasource-authservice-production.cfg
 3. The content of the org.ops4j.datasource-authservice-production.cfg file is:
     osgi.jdbc.driver.name=PostgreSQL JDBC Driver
     dataSourceName=jdbc/authservice
     url=jdbc:postgresql:///authservice
     user=karaf
     password=karaf
     ops4j.preHook=authservicedb
     org.apache.karaf.features.configKey = org.ops4j.datasource-authservice-production
 4. Then I tried replacing just the url property:
     karaf@root()> config:edit org.ops4j.datasource-authservice-production
     karaf@root()> config:property-set url "jdbc:postgresql:///ukelonn"
     karaf@root()> config:update
     karaf@root()>
 5. The resulting file in the etc directory was much smaller
     -rw-r--r--  1 sb sb    33 Nov 11 22:50 org.ops4j.datasource-authservice-production.cfg
 6. The updated file content is just the url setting
     url = jdbc:postgresql:///ukelonn

Did I do something wrong?  Or should I report this as a bug in karaf JIRA?



--
--
Christian Schneider

http://www.liquid-reality.de

Computer Scientist

Reply | Threaded
Open this post in threaded view
|

Re: A command like config:edit that will let you replace only some properties?

jbonofre
In reply to this post by Steinar Bang
Hi,

That's because it's a factory, not a config.

You have to use config:edit --factory.

Regards
JB

On 11/11/2019 22:57, Steinar Bang wrote:

>>>>>> Steinar Bang <[hidden email]>:
>>>>>> Jean-Baptiste Onofré <[hidden email]>:
>
>>> If you do:
>
>>> karaf@root()> config:edit my.config
>>> karaf@root()> config:property-set foo bar
>>> karaf@root()> config:update
>
>>> only foo will be changed, other properties are kept.
>
>>> Not sure I follow what you mean.
>
>> Hm... I thought that when I tried this last week the resulting file
>> only had those properties I had added with config:property-set,
>> ie. that the other properties had gone missing...?
>
>> Maybe I fooled myself while testing?  I will try again and keep track
>> of what I'm doing...:-)
>
> Nope, I tried it again now, and it didn't work for me.
>
> Platform: karaf 4.2.7, openjdk 11, debian 10.1 "buster", amd64
>
> Here's what I did:
>  1. I installed my application using
>      karaf@root()> feature:repo-add mvn:no.priv.bang.authservice/authservice/LATEST/xml/features
>      Adding feature url mvn:no.priv.bang.authservice/authservice/LATEST/xml/features
>      karaf@root()> feature:install user-admin-with-postgresql
>      karaf@root()>
>  2. This created the following file in etc/
>      -rw-r--r--  1 sb sb   250 Nov 11 22:45 org.ops4j.datasource-authservice-production.cfg
>  3. The content of the org.ops4j.datasource-authservice-production.cfg file is:
>      osgi.jdbc.driver.name=PostgreSQL JDBC Driver
>      dataSourceName=jdbc/authservice
>      url=jdbc:postgresql:///authservice
>      user=karaf
>      password=karaf
>      ops4j.preHook=authservicedb
>      org.apache.karaf.features.configKey = org.ops4j.datasource-authservice-production
>  4. Then I tried replacing just the url property:
>      karaf@root()> config:edit org.ops4j.datasource-authservice-production
>      karaf@root()> config:property-set url "jdbc:postgresql:///ukelonn"
>      karaf@root()> config:update
>      karaf@root()>
>  5. The resulting file in the etc directory was much smaller
>      -rw-r--r--  1 sb sb    33 Nov 11 22:50 org.ops4j.datasource-authservice-production.cfg
>  6. The updated file content is just the url setting
>      url = jdbc:postgresql:///ukelonn
>
> Did I do something wrong?  Or should I report this as a bug in karaf JIRA?
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|

Re: A command like config:edit that will let you replace only some properties?

Steinar Bang
>>>>> Jean-Baptiste Onofré <[hidden email]>:

> Hi,
> That's because it's a factory, not a config.

> You have to use config:edit --factory.

Hm... this was kind of strange...?

I did this:
 karaf@root()> config:edit --factory org.ops4j.datasource-authservice-production
 karaf@root()> config:property-set url "jdbc:postgresql:///ukelonn"
 karaf@root()> config:update
 karaf@root()>

And the result was this:
  -rw-------  1 sb sb    33 Nov 12 19:26 org.ops4j.datasource-authservice-production-18185463578817080582.cfg
  -rw-r--r--  1 sb sb   250 Nov 12 19:24 org.ops4j.datasource-authservice-production.cfg
  -rw-r--r--  1 sb sb   208 Nov 12 19:24 org.ops4j.datasource-authservice-test.cfg

The edited property is in the separate file ie. the one with
"-18185463578817080582".

(I thought maybe karaf would combine the two files into one config.  But
unfortunately, it doesn't seem to work that way...?)

The data I see in the application is the data from the database it
connects to at default, and not the database I'm trying to set with the
URL (the database is a user database so I verify by trying to log in
with specific users).

Reply | Threaded
Open this post in threaded view
|

Re: A command like config:edit that will let you replace only some properties?

jbonofre
The factory is org.ops4j.datasource, the pid is "foo".

Regards
JB

On 12/11/2019 19:41, Steinar Bang wrote:

>>>>>> Jean-Baptiste Onofré <[hidden email]>:
>
>> Hi,
>> That's because it's a factory, not a config.
>
>> You have to use config:edit --factory.
>
> Hm... this was kind of strange...?
>
> I did this:
>  karaf@root()> config:edit --factory org.ops4j.datasource-authservice-production
>  karaf@root()> config:property-set url "jdbc:postgresql:///ukelonn"
>  karaf@root()> config:update
>  karaf@root()>
>
> And the result was this:
>   -rw-------  1 sb sb    33 Nov 12 19:26 org.ops4j.datasource-authservice-production-18185463578817080582.cfg
>   -rw-r--r--  1 sb sb   250 Nov 12 19:24 org.ops4j.datasource-authservice-production.cfg
>   -rw-r--r--  1 sb sb   208 Nov 12 19:24 org.ops4j.datasource-authservice-test.cfg
>
> The edited property is in the separate file ie. the one with
> "-18185463578817080582".
>
> (I thought maybe karaf would combine the two files into one config.  But
> unfortunately, it doesn't seem to work that way...?)
>
> The data I see in the application is the data from the database it
> connects to at default, and not the database I'm trying to set with the
> URL (the database is a user database so I verify by trying to log in
> with specific users).
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|

Re: A command like config:edit that will let you replace only some properties?

Steinar Bang
>>>>> Jean-Baptiste Onofré <[hidden email]>:

> The factory is org.ops4j.datasource, the pid is "foo".

Hm... I've read the docs but I don't understand how this is supposed to
work...?

Perhaps like this...?
 karaf@root()> config:edit --factory --alias authservice-production org.ops4j.datasource
 karaf@root()> config:property-set url "jdbc:postgresql:///ukelonn"
 karaf@root()> config:update
 karaf@root()>

Nope... that just overwrote the original config, so still no luck.
  -rw-------  1 sb sb    33 Nov 12 19:26 org.ops4j.datasource-authservice-production-18185463578817080582.cfg
  -rw-r--r--  1 sb sb    33 Nov 12 21:44 org.ops4j.datasource-authservice-production.cfg
  -rw-r--r--  1 sb sb   208 Nov 12 19:24 org.ops4j.datasource-authservice-test.cfg

(Basically what I'm trying to do is to get the simplest possible config
commands to change the JDBC credentials of a pax-jdbc-config
configuration, while leaving the rest of the configuration in place.)