diff options
author | danielhanrahan <daniel.hanrahan@est.tech> | 2023-09-15 12:02:35 +0100 |
---|---|---|
committer | danielhanrahan <daniel.hanrahan@est.tech> | 2023-09-20 10:46:37 +0100 |
commit | efc557762eac3b75c770159a9ceb9d967d5f7a3c (patch) | |
tree | 9fd2d59abe04f356ecd8aa6b99a06c0bff2ee656 | |
parent | 2dac693692a44452ef7c5a1656caddf12403113b (diff) |
Use YangParserFactory to generate schema context
This is presented as a fix for ClassDefNotFoundErrors
from opendaylight yang parser
Issue-ID: CPS-1866
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: If2d1a8f0319cad0a9517ea3652446e2e43f51fd4
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java | 22 | ||||
-rwxr-xr-x | docs/release-notes.rst | 1 |
2 files changed, 14 insertions, 9 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java b/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java index ca907148dd..0235b004f4 100644 --- a/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java +++ b/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java @@ -43,10 +43,11 @@ import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier; import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; -import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors; -import org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; +import org.opendaylight.yangtools.yang.parser.api.YangParser; +import org.opendaylight.yangtools.yang.parser.api.YangParserException; +import org.opendaylight.yangtools.yang.parser.api.YangParserFactory; +import org.opendaylight.yangtools.yang.parser.impl.DefaultYangParserFactory; +import org.opendaylight.yangtools.yang.xpath.impl.di.DefaultXPathParserFactory; @NoArgsConstructor public final class YangTextSchemaSourceSetBuilder { @@ -56,6 +57,9 @@ public final class YangTextSchemaSourceSetBuilder { private final ImmutableMap.Builder<String, String> yangModelMap = new ImmutableMap.Builder<>(); + private static final YangParserFactory YANG_PARSER_FACTORY = + new DefaultYangParserFactory(new DefaultXPathParserFactory()); + /** * Add Yang resource context. * @@ -136,11 +140,11 @@ public final class YangTextSchemaSourceSetBuilder { * @return the schema context */ private static SchemaContext generateSchemaContext(final Map<String, String> yangResourceNameToContent) { - final CrossSourceStatementReactor.BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild(); + final YangParser yangParser = YANG_PARSER_FACTORY.createParser(); for (final YangTextSchemaSource yangTextSchemaSource : forResources(yangResourceNameToContent)) { final String resourceName = yangTextSchemaSource.getIdentifier().getName(); try { - reactor.addSource(YangStatementStreamSource.create(yangTextSchemaSource)); + yangParser.addSource(yangTextSchemaSource); } catch (final Exception exception) { throw new ModelValidationException("Yang resource processing exception.", String.format("Could not process resource %s:%n%s", resourceName, exception.getMessage()), @@ -148,13 +152,13 @@ public final class YangTextSchemaSourceSetBuilder { } } try { - return reactor.buildEffective(); - } catch (final ReactorException reactorException) { + return yangParser.buildEffectiveModel(); + } catch (final YangParserException yangParserException) { final List<String> resourceNames = yangResourceNameToContent.keySet().stream().collect(Collectors.toList()); Collections.sort(resourceNames); throw new ModelValidationException("Invalid schema set.", String.format("Effective schema context build failed for resources %s.", resourceNames), - reactorException); + yangParserException); } } diff --git a/docs/release-notes.rst b/docs/release-notes.rst index 013617a815..cd7ea80505 100755 --- a/docs/release-notes.rst +++ b/docs/release-notes.rst @@ -39,6 +39,7 @@ Release Data Bug Fixes --------- 3.3.7 + - `CPS-1866 <https://jira.onap.org/browse/CPS-1866>`_ Fix ClassDefNotFoundError in opendaylight Yang parser Features -------- |