OPCFoundation / UA-CloudLibrary

OPC UA Information Model database with a REST and GraphQL interface, as well as user management. The global instance of this (hosted by the OPC Foundation) can be found at https://uacloudlibrary.opcfoundation.org.
Other
39 stars 18 forks source link

Transitive dependencies are wrongly detected as missing during indexing #208

Closed mboehm666 closed 1 month ago

mboehm666 commented 4 months ago

Problem

When uploading a nodeset that has transitive dependencies which are not explicitly listed as RequiredModel (i.e. a RequiredModel that is listed depends on one that is not listed), the indexing fails.

Steps to Reproduce

Here is a stripped-down example. It uses 2 minimal nodesets: Parent.xml:

<?xml version="1.0" encoding="utf-8"?>
<UANodeSet LastModified="2024-06-17T12:58:28.927Z" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://opcfoundation.org/UA/2011/03/UANodeSet.xsd" xmlns:uax="http://opcfoundation.org/UA/2008/02/Types.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <NamespaceUris>
        <Uri>http://opcfoundation.org/UA/</Uri>
        <Uri>http://test.com/parent</Uri>
    </NamespaceUris>
    <Models>
        <Model ModelUri="http://test.com/parent" PublicationDate="2024-07-02T00:00:00Z" Version="1.00">
            <RequiredModel ModelUri="http://opcfoundation.org/UA/" PublicationDate="2021-09-15T00:00:00Z" Version="1.04.10"/>
        </Model>
    </Models>
</UANodeSet>

child.xml:

<?xml version="1.0" encoding="utf-8"?>
<UANodeSet LastModified="2024-06-17T12:58:28.927Z" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://opcfoundation.org/UA/2011/03/UANodeSet.xsd" xmlns:uax="http://opcfoundation.org/UA/2008/02/Types.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <NamespaceUris>
        <Uri>http://test.com/parent</Uri>
        <Uri>http://test.com/child</Uri>
    </NamespaceUris>
    <Models>
        <Model ModelUri="http://test.com/child" PublicationDate="2024-07-02T00:00:00Z" Version="1.00">
          <RequiredModel ModelUri="http://test.com/parent" PublicationDate="2024-07-02T00:00:00Z" Version="1.00"/>
        </Model>
    </Models>
</UANodeSet>

The relevant thing to notice is that the child nodeset depends on the parent which, in turn, depends on the UA nodeset. The UA nodeset is not listed as a RequiredModel in child.

The error message is:

The following NodeSets are required: The following NodeSets are required: http://opcfoundation.org/UA/ (Version: 1.04.10, PubDate: 15.09.2021)

Expected behavior

The indexing should succeed, since all required models are known and available.

Analysis

The error seems to happen in CESMII.OpcUa.NodeSetImporter.UANodeSetCacheManager.ImportNodeSets().

The problem there is that in the first loop execution only child and parent are resolved and UA is still missing. Thus results.ErrorMessageis set (line 166). The next loop iteration resolves also UA(there are no more _results.MIssingModels, but since there is already an error message set the final result also has an error message, which in the end fails the indexing, even though all models are available and actually found.

Possible solution

Set the error message for missing models after the loop, not within (not sure, though, how this interacts with a _nodeSetResolver.

Comment

We are aware that the underlying problem likely originates in the CESMII code. However, we experienced the problem in the CloudLibrary and we are not sure how the collaboration with CESMII works, so we decided to file an issue here. Please advise if we should report it in a different way.

opcfoundation-org commented 4 months ago

Every model needs the OPC UA model as a dependency. The OPC UA model URI is always index 0 and is NOT listed in the NamespaceUris. Both of these errors could explain the problem and have nothing do with the transitive model issue. You should NOT need to include all included models from the parent NodeSet in the child NodeSet.

muenchris commented 4 months ago

What version of the OPC Foundation Nodeset did you upload? If its not the exact or higher version of the one referenced in the parent it will cause this error. Line 166 is fine because the errorMessage is deleted in line 188 if there are no more entry in the MissingModels in the _results.

mboehm666 commented 4 months ago

Sorry for the confusion. The problem is not related to the foundation nodeset. I should not have used it in the example. Any other RequiredModel of the parent that is not listed in the child causes the described behavior.

I just tested with the current main branch and the behavior is unchanged for me.

@muenchris I am afraid I cannot follow. Line 188 in UANodeSetCacheManager looks like this:

        static List<ModelValue> OrderByDependencies(List<ModelValue> models)

(its the start of a new method). I am not seeing any code that sets _results.ErrorMessage = "" or similar, except in line 97. Maybe you are looking at some other branch than main?

Just for completeness: I was uploading OPC Foundation Nodeset version 1.04.10 (but, as stated above, it should not matter).

muenchris commented 4 months ago

Sorry, my bad. The fix for this is in the PR waiting for approval for quite some time. If you look into my branch CM-NodeSetValidator2, you can see that there is the fix in line 188. I hope to get the PR approved in the next couple days. Until then, I recommend you using the source from my latest branch.

barnstee commented 4 months ago

Here is the pull request Chris mentioned: https://github.com/cesmii/CESMII-NodeSet-Utilities/pull/40.

mboehm666 commented 4 months ago

Now I understand, thanks for clarification.

barnstee commented 1 month ago

Fixed with https://github.com/OPCFoundation/UA-CloudLibrary/commit/997b233635f5f82c7675d7d800e0ab39e4f9a186.

mboehm666 commented 1 month ago

I can confirm that the issue is fixed in 1.0.2. Thanks for your support!