Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ThingManager is missing config description during normalization #3191

Closed
wants to merge 1 commit into from

Conversation

J-N-K
Copy link
Member

@J-N-K J-N-K commented Dec 3, 2022

Reported on the forum. In some cases the ThingManageImpl tried to initialize the thing before all config descriptions are loaded.

This can happen because the OH-INF/config directory is processed in parallel to the thing descriptions. In case the handler factory is added and the thing description parser sets the corresponding ReadyMarker before the config descriptions are completly parsed this results in a warning because the config description cannot be found during normalization of the thing or channel configuration.

Signed-off-by: Jan N. Klug github@klug.nrw

Reported on the forum. In some cases the `ThingManageImpl` tried to initialize the thing before all config descriptions are loaded.

This can happen because the `OH-INF/config` directory is processed in parallel to the thing descriptions. In case the handler factory is added and the thing description parser sets the corresponding `ReadyMarker` before the config descriptions are completly parsed this results in a warning because the config description cannot be found during normalization of the thing or channel configuration.

Signed-off-by: Jan N. Klug <github@klug.nrw>
@J-N-K J-N-K added the bug An unexpected problem or unintended behavior of the Core label Dec 3, 2022
@J-N-K J-N-K requested a review from a team as a code owner December 3, 2022 17:43
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-3-4-milestone-discussion/138093/126

@splatch
Copy link
Contributor

splatch commented Dec 4, 2022

I am not sure approach in this PR is valid because relying on registering config descriptors in thing manager builds functionality which should be provided by config layer itself. Maybe a new ConfigDescriptionManager or ConfigDescriptorRegistry could help here?

Just an idea:
OH-INF/config -> ConfigDescriptorProvider -> ConfigDescriptorRegistry -> ConfigDescriptorManager -> ConfigDescriptorListener -> ThingManagerImpl

With this approach each step has its own responsibility and ThingManager can be free of internals of config descriptor discovery.

@J-N-K
Copy link
Member Author

J-N-K commented Dec 4, 2022

The problem with that approach is that the ThingManagerImpl can't know which config descriptions are needed (while that may be possible to check for the thing itself, the config descriptions for all channels of that thing can't be easily checked in advance (e.g. in the reported case on the forum the missing description is http:channel-config). Iterating over all channels, getting the config description URI and checking if they are available in the config description registry seems to be quite expensive compared to the solution we have now.

All config descriptions are available, when the bundle has been processed, so this is a sort of short-cut. The same approach is used for the thing descriptions themself, so I merely extended what is already there.

@splatch
Copy link
Contributor

splatch commented Dec 4, 2022

Thanks for explaining detail of issue. Still I don't think that tracking directly appearing of config descriptors within thing manager itself is fully justified. A basic fact that thing manager tracks thing types which might be provided by OH-INF entries, does not mean that it should keep eye on configs too.
Imperative approach taken now makes logic less clear. Making kind of a dependency set for things would not only simplify code, cause you then could just rely on ie. thingDependencies.satisfied() call, it would also let cover various kinds of requirements to activate thing under one interface.
Keep in mind that config descriptors both for thing types and channel types can be provisioned through ConfigDescriptorProvider. Tracking OH-INF entries might be incomplete to cover all bindings.

@J-N-K
Copy link
Member Author

J-N-K commented Dec 4, 2022

While it is incomplete it is at least better than what we have now.

I did check if an alternative approach is possible and that requires a BIG refactoring. It is quite easy to check if all dependencies are met (we can just check for the thing and all of it's channels if the type is present in the respective registry and if a config description uri is present and the config description itself is present in the registry).

What makes it difficult is that we need a trigger to check if a thing can be initialized. We currently use two of these: a ready marker when a bundle has finished loading thing types and the addition of a thing handler factory. This PR adds a third one - a ready marker when a bundle has finished loading config descriptions.

If we don't use the ready markers anymore, we would need to be notified of a change in ConfigDescriptionRegistry, ThingTypeRegistry and ChannelTypeRegistry. Unfortunately none of these implements change listeners.

@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-3-4-release-discussion/142257/131

@J-N-K
Copy link
Member Author

J-N-K commented Jan 8, 2023

Closing, will be superseded by another solution that also tries to solve #1924.

@J-N-K J-N-K closed this Jan 8, 2023
@J-N-K J-N-K deleted the bug-configdescriptionmissing branch April 21, 2023 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of the Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants