From 43228cc2a7f06d5e1b6e398023684c80d9ed1270 Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Wed, 14 Apr 2021 14:15:41 -0400 Subject: Fix yangparser invocation Fix YangParser invocation in restconf-provider to address breaking change in ODL Aluminum release. Issue-ID: SDNC-1515 Signed-off-by: Dan Timoney Change-Id: I9974889bfa9bbd11077c95275c0cb8ba59b1b0bb --- .../restconfapicall/RestconfApiCallNode.java | 60 +++++++++++++++------- .../plugins/restconfapicall/RestconfApiUtils.java | 25 ++++----- 2 files changed, 50 insertions(+), 35 deletions(-) (limited to 'plugins/restconf-client/provider/src/main/java') diff --git a/plugins/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiCallNode.java b/plugins/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiCallNode.java index 679ba57b7..b5a9df706 100644 --- a/plugins/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiCallNode.java +++ b/plugins/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiCallNode.java @@ -3,6 +3,7 @@ * ONAP - CCSDK * ================================================================================ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * Modifications Copyright (c) 2021 AT&T * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,7 +49,6 @@ import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DfSerializ import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DfSerializerUtil.XML_TREE_ERR; import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DfSerializerUtil.getXmlWriter; import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.MdsalPropertiesNodeUtils.getModuleNamespace; -import static org.osgi.framework.FrameworkUtil.getBundle; import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -85,10 +85,9 @@ import org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.PropertiesNodeSer import org.opendaylight.restconf.common.context.InstanceIdentifierContext; import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaNode; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; +import org.opendaylight.yangtools.yang.model.parser.api.YangParserException; +import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -109,12 +108,20 @@ public class RestconfApiCallNode implements SvcLogicJavaPlugin { private RestapiCallNode restapiCallNode; /** - * Creates an instance of restconf api call node with restapi call node. + * Yang parser factory + */ + private YangParserFactory parserFactory; + + + /** + * Creates an instance of restconf api call node with restapi call node, within OSGi * * @param r restapi call node + * @param parserFactory Yang parser factory */ - public RestconfApiCallNode(RestapiCallNode r) { + public RestconfApiCallNode(RestapiCallNode r, YangParserFactory parserFactory) { this.restapiCallNode = r; + this.parserFactory = parserFactory; } /** @@ -125,6 +132,25 @@ public class RestconfApiCallNode implements SvcLogicJavaPlugin { return restapiCallNode; } + + /** + * Returns the yang parser factory instance + * @return + */ + public YangParserFactory getParserFactory() { + return parserFactory; + } + + /** + * set the yang parser factory instance + * @return + */ + public void setParserFactory(YangParserFactory parserFactory) { + this.parserFactory = parserFactory; + } + + + /** * Sends the restconf request using the parameters map and the memory * context. And this method allows the directed graphs to interact with @@ -299,21 +325,17 @@ public class RestconfApiCallNode implements SvcLogicJavaPlugin { * @return schema context * @throws SvcLogicException when schema context fetching fails */ - private EffectiveModelContext getSchemaContext(YangParameters params) - throws SvcLogicException { - if (params.dirPath != null) { - return getSchemaCtxFromDir(params.dirPath); - } - BundleContext bc = getBundle(SchemaContext.class).getBundleContext(); - EffectiveModelContext schemaContext = null; - if (bc != null) { - ServiceReference reference = bc.getServiceReference( - SchemaContext.class); - if (reference != null) { - schemaContext = (EffectiveModelContext) bc.getService(reference); + private EffectiveModelContext getSchemaContext(YangParameters params) throws SvcLogicException { + try { + + if (params.dirPath != null) { + return getSchemaCtxFromDir(getParserFactory(), params.dirPath); + } else { + return (getParserFactory().createParser().buildEffectiveModel()); } + } catch (YangParserException e) { + throw new SvcLogicException("Caught exception creating yang model context", e); } - return schemaContext; } /** diff --git a/plugins/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiUtils.java b/plugins/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiUtils.java index d22c3707a..134868c15 100644 --- a/plugins/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiUtils.java +++ b/plugins/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/restconfapicall/RestconfApiUtils.java @@ -5,6 +5,7 @@ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. * * Modifications Copyright © 2018 IBM. + * Modifications Copyright (c) 2021 AT&T * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,18 +25,13 @@ package org.onap.ccsdk.sli.plugins.restconfapicall; import static org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode.getParameters; import static org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode.parseParam; -import static org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode.DEFAULT_MODE; import static org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource.forFile; -import static org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors.defaultReactor; -import static org.opendaylight.yangtools.yang.parser.rfc7950.repo.YangStatementStreamSource.create; import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collection; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -43,10 +39,10 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicException; import org.onap.ccsdk.sli.plugins.restapicall.HttpMethod; import org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.YangParameters; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; +import org.opendaylight.yangtools.yang.model.parser.api.YangParser; +import org.opendaylight.yangtools.yang.model.parser.api.YangParserException; +import org.opendaylight.yangtools.yang.model.parser.api.YangParserFactory; import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; -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; /** * Utilities for restconf api call node. @@ -188,27 +184,24 @@ public final class RestconfApiUtils { * @return YANG schema context * @throws SvcLogicException when YANG file reading fails */ - static EffectiveModelContext getSchemaCtxFromDir(String di) + static EffectiveModelContext getSchemaCtxFromDir(YangParserFactory parserFactory, String di) throws SvcLogicException { Path d = Paths.get(di); File dir = d.toFile(); List yangFiles = new LinkedList<>(); getYangFiles(dir, yangFiles); - final Collection sources = - new ArrayList<>(yangFiles.size()); + YangParser parser = parserFactory.createParser(); for (File file : yangFiles) { try { - sources.add(create(forFile(file))); + parser.addSource(forFile(file)); } catch (IOException | YangSyntaxErrorException e) { throw new SvcLogicException(YANG_FILE_ERR + e.getMessage(), e); } } - final CrossSourceStatementReactor.BuildAction reactor = defaultReactor() - .newBuild(DEFAULT_MODE).addSources(sources); try { - return reactor.buildEffective(); - } catch (ReactorException e) { + return parser.buildEffectiveModel(); + } catch (YangParserException e) { throw new SvcLogicException(YANG_FILE_ERR + e.getMessage(), e); } } -- cgit 1.2.3-korg