You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Steinar Bang <sb...@dod.no> on 2020/09/20 17:00:12 UTC

Possible to get config on first component startup?

I've added config for an Declarative Services component in the
src/main/feature/feature.xml file:

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="oldalbum.roleadder.test">
     <feature name="${karaf-feature-name}">
         <config name="no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment">
             username=${env:USERNAME:-admin}
             password=${env:PASSWORD:-admin}
             allowModify=${env:ALLOW_MODIFY:-true}
         </config>
         <feature>scr</feature>
     </feature>
 </features>

The etc/no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment.cfg
file is created on startup, with the expected content:
 username=${env:USERNAME:-admin}
 password=${env:PASSWORD:-admin}
 allowModify=${env:ALLOW_MODIFY:-true}
 org.apache.karaf.features.configKey = no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment


But on the first call to the @Activate
method the config object is almost empty:
 {component.name=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, component.id=7}

If I stop karaf, delete the data directory, restart karaf, and reinstall
the feature (now with the config file in place), the @Activate method
gets the config results:
 {service.pid=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, allowModify=true, password=admin, org.apache.karaf.features.configKey=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, component.name=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, felix.fileinstall.filename=file:/home/sb/skrot/apache-karaf-4.2.9/etc/no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment.cfg, component.id=4, username=admin}

Is there a way so that I can get the contents of the newly generated
.cfg file on the first component install?

Thanks!


- Steinar


Re: Possible to get config on first component startup?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Jean-Baptiste Onofre <jb...@nanthrax.net>:

> To force config before the component, you need prerequisite=true.
> Can you try:

> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="oldalbum.roleadder.test">
>     <feature name="${karaf-feature-name}-config">
>         <config name="no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment">
>             username=${env:USERNAME:-admin}
>             password=${env:PASSWORD:-admin}
>             allowModify=${env:ALLOW_MODIFY:-true}
>         </config>
>     </feature>
>     <feature name="${karaf-feature-name}">
>         <feature prerequisite="true">${karaf-feature-name}-config</feature>
>         <feature>scr</feature>
>     </feature>
> </features>

Still no luck, unfortunately.

Even with prerequisite="true" in place, the initial startup config comes
up empty.

But when the .cfg file is in place in the etc directory, the injected
config is correct.

But except for a minor annoyance I can work around this: the place I
need the config is in the docker image and there I can copy in the
no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment.cfg
file into the etc directory when building the image.

FWIW I have to do the same thing for the jdbc-config config
files. I.e. copy the file into the etc directory when buildign the
image.

Thanks!


Re: Possible to get config on first component startup?

Posted by Jean-Baptiste Onofre <jb...@nanthrax.net>.
To force config before the component, you need prerequisite=true.

Can you try:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="oldalbum.roleadder.test">
    <feature name="${karaf-feature-name}-config">
        <config name="no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment">
            username=${env:USERNAME:-admin}
            password=${env:PASSWORD:-admin}
            allowModify=${env:ALLOW_MODIFY:-true}
        </config>
    </feature>
    <feature name="${karaf-feature-name}">
        <feature prerequisite="true">${karaf-feature-name}-config</feature>
        <feature>scr</feature>
    </feature>
</features>

?

Regards
JB

> Le 20 sept. 2020 à 22:30, Steinar Bang <sb...@dod.no> a écrit :
> 
>>>>>> Jean-Baptiste Onofré <jb...@nanthrax.net>:
> 
>> You can isolate the config in a dedicated feature and define this
>> feature as prerequisite of the feature containing the scr bundle.
> 
> Thanks! Unfortunately I can't get it to work.
> 
> I first tried putting it in a separate feature in the same feature
> repository as the component, ie. like so:
> 
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="oldalbum.roleadder.test">
>     <feature name="${karaf-feature-name}-config">
>         <config name="no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment">
>             username=${env:USERNAME:-admin}
>             password=${env:PASSWORD:-admin}
>             allowModify=${env:ALLOW_MODIFY:-true}
>         </config>
>     </feature>
>     <feature name="${karaf-feature-name}">
>         <feature>${karaf-feature-name}-config</feature>
>         <feature>scr</feature>
>     </feature>
> </features>
> 
> But the first @Activate config method injection was still empty, except
> for the component.name and the component.id.
> 
> Is the feature repository significant?
> 
> Ie. should the feature reside in a separate feature repository?
> 
> Do the feature need to be alone in that feature repository?  Or can it
> share the repository with an existing feature? (i.e. can I put it into
> the feature repository of an existing bundle maven project or do I have
> to create a new project just for this feature?)
> 
> Thanks!
> 


Re: Possible to get config on first component startup?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Jean-Baptiste Onofré <jb...@nanthrax.net>:

> You can isolate the config in a dedicated feature and define this
> feature as prerequisite of the feature containing the scr bundle.

Thanks! Unfortunately I can't get it to work.

I first tried putting it in a separate feature in the same feature
repository as the component, ie. like so:

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="oldalbum.roleadder.test">
     <feature name="${karaf-feature-name}-config">
         <config name="no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment">
             username=${env:USERNAME:-admin}
             password=${env:PASSWORD:-admin}
             allowModify=${env:ALLOW_MODIFY:-true}
         </config>
     </feature>
     <feature name="${karaf-feature-name}">
         <feature>${karaf-feature-name}-config</feature>
         <feature>scr</feature>
     </feature>
 </features>

But the first @Activate config method injection was still empty, except
for the component.name and the component.id.

Is the feature repository significant?

Ie. should the feature reside in a separate feature repository?

Do the feature need to be alone in that feature repository?  Or can it
share the repository with an existing feature? (i.e. can I put it into
the feature repository of an existing bundle maven project or do I have
to create a new project just for this feature?)

Thanks!


Re: Possible to get config on first component startup?

Posted by Jean-Baptiste Onofré <jb...@nanthrax.net>.
You can isolate the config in a dedicated feature and define this feature as
prerequisite of the feature containing the scr bundle.

  

Regards

JB

  

Le dim. 20 sept. 2020 ? 19:00, Steinar Bang <sb...@dod.no> a ?crit :  

> I've added config for an Declarative Services component in the  
>  
> src/main/feature/feature.xml file:  
>  
>  
>  
>  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>  
>  
>  <features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0"
name="oldalbum.roleadder.test">  
>  
>  <feature name="${karaf-feature-name}">  
>  
>  <config
name="no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment">  
>  
>  username=${env:USERNAME:-admin}  
>  
>  password=${env:PASSWORD:-admin}  
>  
>  allowModify=${env:ALLOW_MODIFY:-true}  
>  
>  </config>  
>  
>  <feature>scr</feature>  
>  
>  </feature>  
>  
>  </features>  
>  
>  
>  
> The
etc/no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment.cfg  
>  
> file is created on startup, with the expected content:  
>  
>  username=${env:USERNAME:-admin}  
>  
>  password=${env:PASSWORD:-admin}  
>  
>  allowModify=${env:ALLOW_MODIFY:-true}  
>  
>  org.apache.karaf.features.configKey =
no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment  
>  
>  
>  
>  
>  
> But on the first call to the @Activate  
>  
> method the config object is almost empty:  
>  
>
{component.name=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment,
component.id=7}  
>  
>  
>  
> If I stop karaf, delete the data directory, restart karaf, and reinstall  
>  
> the feature (now with the config file in place), the @Activate method  
>  
> gets the config results:  
>  
>
{service.pid=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment,
allowModify=true, password=admin,
org.apache.karaf.features.configKey=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment,
component.name=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment,
felix.fileinstall.filename=file:/home/sb/skrot/apache-
karaf-4.2.9/etc/no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment.cfg,
component.id=4, username=admin}  
>  
>  
>  
> Is there a way so that I can get the contents of the newly generated  
>  
> .cfg file on the first component install?  
>  
>  
>  
> Thanks!  
>  
>  
>  
>  
>  
> \- Steinar  
>  
>  
>  
>


Re: Possible to get config on first component startup?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> David Jencks <da...@gmail.com>:

> Bundle state and SCR component state are (mostly) independent.  If
> I’ve understood your use case this is the solution you want
> (configurationPolicy = ConfigurationPolicy.REQUIRE results in
> requiring a configuration to be present for your component to
> activate).

Yes, that's correct.

> Generally immediate = true is not very helpful, but you may be in one
> of the cases where it’s useful.

Ok.

And thanks! :-)


Re: Possible to get config on first component startup?

Posted by David Jencks <da...@gmail.com>.
Bundle state and SCR component state are (mostly) independent.  If I’ve understood your use case this is the solution you want (configurationPolicy =
ConfigurationPolicy.REQUIRE results in requiring a configuration to be present for your component to activate).

Generally immediate = true is not very helpful, but you may be in one of the cases where it’s useful.

David Jencks

> On Sep 21, 2020, at 10:55 AM, Steinar Bang <sb...@dod.no> wrote:
> 
>>>>>> Francois Papon <fr...@openobject.fr>:
> 
>> Hi,
>> May be you can try with:
> 
>> @Component(immediate = true, configurationPolicy =
>> ConfigurationPolicy.REQUIRE)
> 
> With this annotation in place, the breakpoint in the @Activate method
> wasn't called on initial startup (all bundles still showed up as
> Active... is this expected?).
> 
> When the no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment.cfg
> file was in the etc directory, the breakpoint was triggered.
> 
> I tried both with and without prerequisite="true", and the behaviour was
> identical.
> 
> Thanks!
> 


Re: Possible to get config on first component startup?

Posted by Jean-Baptiste Onofre <jb...@nanthrax.net>.
Thanks a lot Steinar.

So, I confirm that it’s the fix I did in Felix FileInstall ;)

Now, I will move forward on Karaf 4.2.10 ;)

Thanks again,
Regards
JB

> Le 22 sept. 2020 à 22:39, Steinar Bang <sb...@dod.no> a écrit :
> 
>>>>>> Jean-Baptiste Onofre <jb...@nanthrax.net>:
> 
>> It’s what I thought and it’s fixed on 4.2.10-SNAPSHOT.
> 
>> If you have the chance to test with 4.2.10-SNAPSHOT to double check, but I’m pretty sure it will work.
> 
> I tested on apache-karaf-4.2.10-20200920.072033-161 and there the config
> object in @Activate method had all values on the initial startup:
> {service.pid=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, allowModify=false, password=admin, org.apache.karaf.features.configKey=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, component.name=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, felix.fileinstall.filename=file:/home/sb/skrot/apache-karaf-4.2.10-SNAPSHOT/etc/no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment.cfg, component.id=4, username=admin}
> 
> So 4.2.10-SNAPSHOT is ok.
> 


Re: Possible to get config on first component startup?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Jean-Baptiste Onofre <jb...@nanthrax.net>:

> It’s what I thought and it’s fixed on 4.2.10-SNAPSHOT.

> If you have the chance to test with 4.2.10-SNAPSHOT to double check, but I’m pretty sure it will work.

I tested on apache-karaf-4.2.10-20200920.072033-161 and there the config
object in @Activate method had all values on the initial startup:
 {service.pid=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, allowModify=false, password=admin, org.apache.karaf.features.configKey=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, component.name=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, felix.fileinstall.filename=file:/home/sb/skrot/apache-karaf-4.2.10-SNAPSHOT/etc/no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment.cfg, component.id=4, username=admin}

So 4.2.10-SNAPSHOT is ok.


Re: Possible to get config on first component startup?

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

It’s what I thought and it’s fixed on 4.2.10-SNAPSHOT.

If you have the chance to test with 4.2.10-SNAPSHOT to double check, but I’m pretty sure it will work.

I did the fix in FileInstall (regression introduced there and fixed).

Regards
JB

> Le 21 sept. 2020 à 22:03, Steinar Bang <sb...@dod.no> a écrit :
> 
>>>>>> Steinar Bang <sb...@dod.no>:
> 
>>>>>> Jean-Baptiste Onofre <jb...@nanthrax.net>:
>>> What Karaf version are you using ? If you tested 4.2.9, can you try
>>> 4.2.8 (I did a fix in FileInstall affecting 4.2.9) ?
> 
>> I'm using 4.2.9 with openjdk 11 on debian 10.5 "buster" on amd64.
> 
>> I will try with 4.2.8.
> 
> On 4.2.8 the config map contained all config on the initial startup:
> {service.pid=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, allowModify=true, password=admin, org.apache.karaf.features.configKey=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, component.name=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, felix.fileinstall.filename=file:/home/sb/skrot/apache-karaf-4.2.8/etc/no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment.cfg, component.id=4, username=admin}
> 
> So this is a regression from 4.2.8 to 4.2.9.
> 
> 


Re: Possible to get config on first component startup?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Steinar Bang <sb...@dod.no>:

>>>>> Jean-Baptiste Onofre <jb...@nanthrax.net>:
>> What Karaf version are you using ? If you tested 4.2.9, can you try
>> 4.2.8 (I did a fix in FileInstall affecting 4.2.9) ?

> I'm using 4.2.9 with openjdk 11 on debian 10.5 "buster" on amd64.

> I will try with 4.2.8.

On 4.2.8 the config map contained all config on the initial startup:
 {service.pid=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, allowModify=true, password=admin, org.apache.karaf.features.configKey=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, component.name=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, felix.fileinstall.filename=file:/home/sb/skrot/apache-karaf-4.2.8/etc/no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment.cfg, component.id=4, username=admin}

So this is a regression from 4.2.8 to 4.2.9.



Re: Possible to get config on first component startup?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Jean-Baptiste Onofre <jb...@nanthrax.net>:

> What Karaf version are you using ? If you tested 4.2.9, can you try
> 4.2.8 (I did a fix in FileInstall affecting 4.2.9) ?

I'm using 4.2.9 with openjdk 11 on debian 10.5 "buster" on amd64.

I will try with 4.2.8.


Re: Possible to get config on first component startup?

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

For sure if the prerequisite feature contains the config, the config will be there before the features.

So, by default, the features are installed async (its own provisioning thread), so, your SCR bundle can start while config is not populated yet.
With required config, start method will be called only when the config is there.

The state of the bundle and the state of SCR components are different (that’s why your bundle can be active, whereas some components are not started). You should better use scr:list and scr:info.

What Karaf version are you using ? If you tested 4.2.9, can you try 4.2.8 (I did a fix in FileInstall affecting 4.2.9) ?

Regards
JB

> Le 21 sept. 2020 à 19:55, Steinar Bang <sb...@dod.no> a écrit :
> 
>>>>>> Francois Papon <fr...@openobject.fr>:
> 
>> Hi,
>> May be you can try with:
> 
>> @Component(immediate = true, configurationPolicy =
>> ConfigurationPolicy.REQUIRE)
> 
> With this annotation in place, the breakpoint in the @Activate method
> wasn't called on initial startup (all bundles still showed up as
> Active... is this expected?).
> 
> When the no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment.cfg
> file was in the etc directory, the breakpoint was triggered.
> 
> I tried both with and without prerequisite="true", and the behaviour was
> identical.
> 
> Thanks!
> 


Re: Possible to get config on first component startup?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Francois Papon <fr...@openobject.fr>:

> Hi,
> May be you can try with:

> @Component(immediate = true, configurationPolicy =
> ConfigurationPolicy.REQUIRE)

With this annotation in place, the breakpoint in the @Activate method
wasn't called on initial startup (all bundles still showed up as
Active... is this expected?).

When the no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment.cfg
file was in the etc directory, the breakpoint was triggered.

I tried both with and without prerequisite="true", and the behaviour was
identical.

Thanks!


Re: Possible to get config on first component startup?

Posted by Łukasz Dywicki <lu...@code-house.org>.
Yeah, my bad - I meant ManagedServiceFactory:
https://docs.osgi.org/javadoc/r5/cmpn/org/osgi/service/cm/ManagedServiceFactory.html

It works with "pid", however this pid becomes a factory one, meaning
that your etc/ configuration files must have -something in the name.
From your example:
etc/no.priv.bang.oldalbum.roleadder.auth-testenvironment.cfg
etc/no.priv.bang.oldalbum.roleadder.auth-prod.cfg

The -prod is not directly visible to managed service #update method call
(however can be retrieved from dictionary if you use fileinstall), cause
"pid" will contain your pid and some random value. Your service factory
can then decide what kind of service should be published and decide to
resign from it if config is invalid.

I used this pattern to build configurable authentication mechanism in
one of customer projects and it served purpose quite well. With proper
tracking and decorating of services you can build whole chain of
elements which will for example result in launching of dedicated
endpoint where user will enter password, or like in your case amend
authorization logic.

Best,
Łukasz

On 21.09.2020 19:58, Steinar Bang wrote:
>>>>>> Łukasz Dywicki <lu...@code-house.org>:
> 
>> Last resort is turning your configuration into
>> ManagedConfigurationFactory and publishing services only when config
>> admin receives an updated version of config.
> 
> Hm... google can't find much on ManagedConfigurationFactory.
> 
> Do you have a URL to some docs?
> 
> Thanks!
> 

Re: Possible to get config on first component startup?

Posted by Steinar Bang <sb...@dod.no>.
>>>>> Łukasz Dywicki <lu...@code-house.org>:

> Last resort is turning your configuration into
> ManagedConfigurationFactory and publishing services only when config
> admin receives an updated version of config.

Hm... google can't find much on ManagedConfigurationFactory.

Do you have a URL to some docs?

Thanks!


Re: Possible to get config on first component startup?

Posted by Łukasz Dywicki <lu...@code-house.org>.
Last resort is turning your configuration into
ManagedConfigurationFactory and publishing services only when config
admin receives an updated version of config.

Best,
Łukasz

On 21.09.2020 09:22, Francois Papon wrote:
> Hi,
> 
> May be you can try with:
> 
> @Component(immediate = true, configurationPolicy =
> ConfigurationPolicy.REQUIRE)
> 
> regards,
> 
> François
> fpapon@apache.org
> 
> Le 20/09/2020 à 19:00, Steinar Bang a écrit :
>> I've added config for an Declarative Services component in the
>> src/main/feature/feature.xml file:
>>
>>  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
>>  <features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="oldalbum.roleadder.test">
>>      <feature name="${karaf-feature-name}">
>>          <config name="no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment">
>>              username=${env:USERNAME:-admin}
>>              password=${env:PASSWORD:-admin}
>>              allowModify=${env:ALLOW_MODIFY:-true}
>>          </config>
>>          <feature>scr</feature>
>>      </feature>
>>  </features>
>>
>> The etc/no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment.cfg
>> file is created on startup, with the expected content:
>>  username=${env:USERNAME:-admin}
>>  password=${env:PASSWORD:-admin}
>>  allowModify=${env:ALLOW_MODIFY:-true}
>>  org.apache.karaf.features.configKey = no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment
>>
>>
>> But on the first call to the @Activate
>> method the config object is almost empty:
>>  {component.name=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, component.id=7}
>>
>> If I stop karaf, delete the data directory, restart karaf, and reinstall
>> the feature (now with the config file in place), the @Activate method
>> gets the config results:
>>  {service.pid=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, allowModify=true, password=admin, org.apache.karaf.features.configKey=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, component.name=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, felix.fileinstall.filename=file:/home/sb/skrot/apache-karaf-4.2.9/etc/no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment.cfg, component.id=4, username=admin}
>>
>> Is there a way so that I can get the contents of the newly generated
>> .cfg file on the first component install?
>>
>> Thanks!
>>
>>
>> - Steinar
>>

Re: Possible to get config on first component startup?

Posted by Francois Papon <fr...@openobject.fr>.
Hi,

May be you can try with:

@Component(immediate = true, configurationPolicy =
ConfigurationPolicy.REQUIRE)

regards,

François
fpapon@apache.org

Le 20/09/2020 à 19:00, Steinar Bang a écrit :
> I've added config for an Declarative Services component in the
> src/main/feature/feature.xml file:
>
>  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
>  <features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="oldalbum.roleadder.test">
>      <feature name="${karaf-feature-name}">
>          <config name="no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment">
>              username=${env:USERNAME:-admin}
>              password=${env:PASSWORD:-admin}
>              allowModify=${env:ALLOW_MODIFY:-true}
>          </config>
>          <feature>scr</feature>
>      </feature>
>  </features>
>
> The etc/no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment.cfg
> file is created on startup, with the expected content:
>  username=${env:USERNAME:-admin}
>  password=${env:PASSWORD:-admin}
>  allowModify=${env:ALLOW_MODIFY:-true}
>  org.apache.karaf.features.configKey = no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment
>
>
> But on the first call to the @Activate
> method the config object is almost empty:
>  {component.name=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, component.id=7}
>
> If I stop karaf, delete the data directory, restart karaf, and reinstall
> the feature (now with the config file in place), the @Activate method
> gets the config results:
>  {service.pid=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, allowModify=true, password=admin, org.apache.karaf.features.configKey=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, component.name=no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment, felix.fileinstall.filename=file:/home/sb/skrot/apache-karaf-4.2.9/etc/no.priv.bang.oldalbum.roleadder.test.ShiroRoleAdderForOldalbumTestEnvironment.cfg, component.id=4, username=admin}
>
> Is there a way so that I can get the contents of the newly generated
> .cfg file on the first component install?
>
> Thanks!
>
>
> - Steinar
>