Binding configuration does not persist

Hello dear maintainers! I’ve got another nasty problem in my development environment. Every time i start app.bndrun my binding comes up with a fresh and new config with no data inside. Map object in @Activate method of my ThingFactoryHandler every time contains only two key-value pairs: service.name and service.id.
However the validated configuration is saved correctly, because my binding successfully generates a new keypair and i see it in PaperUI in binding config. I can even insert the key manually and it works.
Is it a known bug or “feature” in the demo/test environment, or am i doing something wrong ? As always, the code is here: https://github.com/Sonic-Amiga/org.openhab.binding.devireg

Haven’t checked your code yet, but in case if you re-run provisioning and launch new build then it is likely that older data/cache folder is wiped out and configuration storage as well.
Under the hoods configurations are persisted by OSGi ConfigAdmin implementation. As far I remember the default used in OH is Felix Config Admin which keeps copy of data next to the bundle under cache/ directory or so. Check out if that’s the case, if so you can try to configure admin bundle in a way which keeps data above the folder which gets cleared.
Try defining felix.cm.dir For a launch and see if it remains.

@splatch Hello! Back from London and back to the development. Sorry for perhaps stupid questions; i’m totally new to all this OSGi stuff.

  1. “next to the bundle” - where is this exactly? I am using Eclipse, installed it as described in OH documentation. I’ve scanned my openhab-master and openhab-addons directories for anything named “cache” and nothing was found.
  2. How to define properties? I know they can be specified on command line while running java with -D switch. But what about app.bndrun being launched from Eclipse ?
  3. What does “re-run provisioning” exactly mean? I am just using “run OSGi button”, as described in docs.

I found “Runtime properties” list in app.bndrun page in Eclipse and added “felix.cm.dir” with value of “${.}/runtime/cache” there. From other properties i figured out that ${.} refers to openhab-master\git\openhab-distro\launch\app\runtime , so i created “cache” subdir there and ran the app. After i ran the app and even changed some values manually the dir is still empty.

I’ve stepped into Configuration.update() in debug mode and figured out the root cause.
The configuration is stored in XML file at location:
C:\Users\Asus\AppData\Local\Temp\osgi.5416450383779042057.fw\org.eclipse.osgi\17\data\config\binding\devireg.config
Apparently this “osgi.???.fw” part is different on every run. Overriding it so some determined value would fix the problem.
I wonder, can it be considered a bug in demo environment ? Obviously, any binding would suffer from this problem.

Some more tracing reveals this path comes from:
bundleContext.getDataFile( DEFAULT_CONFIG_DIR );
with Javadoc saying:
a file in the persistent storage area provided for the bundle by the Framework
What is “area provided by the Framework” and how to configure it to something reusable ?

UPD: i’ve found this one level up the stack trace:
final FilePersistenceManager fpm = new FilePersistenceManager( bundleContext,
bundleContext.getProperty( CM_CONFIG_DIR ) );
with CM_CONFIG_DIR being “felix.cm.dir” you mentioned. So - how to set properties ?

I’ve fixed the problem. It was my fault not to press “Save” button after adding the property to “Runtime properties” list.
Shouldn’t git version already contain this setting, set to e.g. ${.}/runtime/config ? IMHO picking random directory every time is wrong since it makes saving configuration effectively not working.

Hey @Sonic,
Sorry - I was offline most of the day thus I couldn’t answer earlier. Glad you managed to pass the issue over.

WRT defaults and stuff, I believe it is dependant on particular situation, as in some cases configuration might include settings or access tokens which gets expired or changed when you re-run whole thing.

I am not a valid candidate to answer this question as I do development in slightly different way, however @maggu2810 @Kai and @hilbrand might be better positioned to address your concern. :slight_smile:

We can always add a commented line in app.bndrun so next person with similar issue to yours will have faster path learning how to solve the problem. :slight_smile:

Ouch, really? Example ? If so, why are they stored in config in the first place ?
Since binding config is user-editable thing, i expect it to be persistent. And i’d expect it to be persistent in development environment too. This is exactly why i hit this - i store an access token there.

@splatch Sorry, I am not invovled in the openHAB development anymore.