Yang module parsing with yangtools failed

2.6k Views Asked by At

I use opendaylight.yangtools to parse Yang Module files in my application, I'd like only get some information, not instantiate or use it.

I add to my Maven pom.xml this dependencies :

<!-- opendaylight Yangtools -->
<dependency>
    <groupId>org.opendaylight.yangtools</groupId>
    <artifactId>yang-parser-impl</artifactId>
    <version>1.2.0-SNAPSHOT</version>
    <type>jar</type>
</dependency>        
<dependency>
    <groupId>org.opendaylight.yangtools</groupId>
    <artifactId>yang-parser-api</artifactId>
    <version>1.2.0-SNAPSHOT</version>
    <type>jar</type>
</dependency>
<dependency>
    <groupId>org.opendaylight.yangtools</groupId>
    <artifactId>yang-model-api</artifactId>
    <version>1.2.0-SNAPSHOT</version>
    <type>jar</type>
</dependency>

Then I create a class for implementing a parse function :

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class YangParser {

    private static final Logger LOGGER = LoggerFactory.getLogger(YangParser.class);

    public YangParser() {    
    }

    public void parseModule(String file) throws IOException, YangSyntaxErrorException {   
        LOGGER.debug("Parse Yang module from file : " + file);

        try {
            File yang_file = new File(file);
            CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();            
            reactor.addSource(YangStatementStreamSource.create(
                YangTextSchemaSource.forFile(yang_file)));

            SchemaContext schemaContext = reactor.buildEffective();            

            Set<Module> modules = schemaContext.getModules();
            for (Module m : modules) {
                LOGGER.debug("Add YANG module : " + m.getName());
                LOGGER.debug("Namespace : " + m.getNamespace().toString());
            }

        }
        catch (ReactorException e) {
            throw new IllegalStateException("Parsing Yang module failed, error : " + e.getMessage());
        }
    }
}

Then I use this function in a controller for POST API to upload yang file and parse it. When upload a simple Yang file as :

// Contents of "acme-system.yang"
module acme-system {
 namespace "http://acme.example.com/system";
 prefix "acme";

 organization "ACME Inc.";
 contact "[email protected]";
 description
     "The module for entities implementing the ACME system.";

 revision 2007-06-09 {
     description "Initial revision.";
 }

 container system {
     leaf host-name {
         type string;
         description "Hostname for this system";
     }

     leaf-list domain-search {
         type string;
         description "List of domain names to search";
     }

     container login {
         leaf message {
             type string;
             description
                 "Message given at start of login session";
         }

         list user {
             key "name";
             leaf name {
                 type string;
             }
             leaf full-name {
                 type string;
             }
             leaf class {
                 type string;
             }
         }
     }
 }
}

I have a successful response body :

<name>acme-system</name>
<namespace>http://acme.example.com/system</namespace>
<description>The module for entities implementing the ACME system.</description>
<reference/>
<organization>ACME Inc.</organization>
<contact>[email protected]</contact>
<revision>1181340000000</revision>
<yangVersion>1</yangVersion>

When i upload a Yang file with import defined I've an unsuccessful response body with this error:

Parsing Yang module failed, error : Some of SOURCE_PRE_LINKAGE modifiers for statements were not resolved.

These are logs :

DEBUG [http-nio-8080-exec-25] s.d.s.w.PropertySourcedRequestMappingHandlerMapping.getHandlerInternal(306) | Looking up handler method for path /ems/2.0/file/parser
DEBUG [http-nio-8080-exec-25] s.d.s.w.PropertySourcedRequestMappingHandlerMapping.lookupHandlerMethod(108) | looking up handler for path: /ems/2.0/file/parser
DEBUG [http-nio-8080-exec-25] s.d.s.w.PropertySourcedRequestMappingHandlerMapping.getHandlerInternal(316) | Did not find handler method for [/ems/2.0/file/parser]
DEBUG [http-nio-8080-exec-25] o.h.e.t.s.AbstractTransactionImpl.begin(160) | begin
DEBUG [http-nio-8080-exec-25] o.h.e.j.i.LogicalConnectionImpl.obtainConnection(226) | Obtaining JDBC connection
DEBUG [http-nio-8080-exec-25] o.h.e.j.i.LogicalConnectionImpl.obtainConnection(232) | Obtained JDBC connection
DEBUG [http-nio-8080-exec-25] o.h.e.t.i.j.JdbcTransaction.doBegin(69) | initial autocommit status: true
DEBUG [http-nio-8080-exec-25] o.h.e.t.i.j.JdbcTransaction.doBegin(71) | disabling autocommit
DEBUG [http-nio-8080-exec-25] c.a.e.n.c.YangParser.parseModule(37) | Parse Yang module from file : /home/user/yang/iana-if-type.yang
DEBUG [http-nio-8080-exec-25] o.o.y.y.p.s.r.SourceSpecificContext.startPhase(206) | Source org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource@6e5d8661 started phase SOURCE_PRE_LINKAGE
DEBUG [http-nio-8080-exec-25] o.o.y.y.p.s.r.BuildGlobalContext.startPhase(287) | Global phase SOURCE_PRE_LINKAGE started
ERROR [http-nio-8080-exec-25] o.o.y.y.p.s.r.BuildGlobalContext.addSourceExceptions(326) | Failed to parse YANG from source SourceSpecificContext [source=org.opendaylight.yangtools.yang.parser.rfc6020.repo.YangStatementStreamSource@6e5d8661, current=SOURCE_PRE_LINKAGE, finished=INIT]
org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException: Yang model processing phase SOURCE_PRE_LINKAGE failed [at /home/user/yang/iana-if-type.yang:1:0]
    at org.opendaylight.yangtools.yang.parser.stmt.reactor.SourceSpecificContext.failModifiers(SourceSpecificContext.java:353) ~[yang-parser-impl-1.2.0-SNAPSHOT.jar:na]
    at org.opendaylight.yangtools.yang.parser.stmt.reactor.BuildGlobalContext.addSourceExceptions(BuildGlobalContext.java:316) [yang-parser-impl-1.2.0-SNAPSHOT.jar:na]
    at org.opendaylight.yangtools.yang.parser.stmt.reactor.BuildGlobalContext.completePhaseActions(BuildGlobalContext.java:410) [yang-parser-impl-1.2.0-SNAPSHOT.jar:na]
    at org.opendaylight.yangtools.yang.parser.stmt.reactor.BuildGlobalContext.executePhases(BuildGlobalContext.java:218) [yang-parser-impl-1.2.0-SNAPSHOT.jar:na]
    at org.opendaylight.yangtools.yang.parser.stmt.reactor.BuildGlobalContext.buildEffective(BuildGlobalContext.java:229) [yang-parser-impl-1.2.0-SNAPSHOT.jar:na]
    at org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor$BuildAction.buildEffective(CrossSourceStatementReactor.java:280) [yang-parser-impl-1.2.0-SNAPSHOT.jar:na]
    at com.example.common.YangParser.parseModule(YangParser.java:51) [classes/:na]
    at com.example.controllers.services.impl.FileServiceImpl.fileYangParser(FileServiceImpl.java:210) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_144]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_144]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_144]
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) [spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) [spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) [spring-tx-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) [spring-tx-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) [spring-tx-4.2.5.RELEASE.jar:4.2.5.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) [spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at com.sun.proxy.$Proxy283.fileYangParser(Unknown Source) [na:na]
    at com.example.controllers.FileController.FileYangParser(FileController.java:133) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_144]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_144]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_144]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222) [spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) [spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) [spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814) [spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737) [spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) [spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) [spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) [spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) [spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:661) [servlet-api.jar:na]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) [spring-webmvc-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) [servlet-api.jar:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) [catalina.jar:8.5.16]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:8.5.16]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-websocket.jar:8.5.16]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:8.5.16]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:8.5.16]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:170) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at com.example.common.MDCFilter.doFilter(MDCFilter.java:38) [classes/:na]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at com.example.security.StatelessAuthenticationFilter.doFilter(StatelessAuthenticationFilter.java:39) [classes/:na]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177) [spring-security-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) [spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) [spring-web-4.2.3.RELEASE.jar:4.2.3.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [catalina.jar:8.5.16]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [catalina.jar:8.5.16]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) [catalina.jar:8.5.16]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [catalina.jar:8.5.16]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) [catalina.jar:8.5.16]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [catalina.jar:8.5.16]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) [catalina.jar:8.5.16]
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624) [catalina.jar:8.5.16]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [catalina.jar:8.5.16]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [catalina.jar:8.5.16]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799) [tomcat-coyote.jar:8.5.16]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-coyote.jar:8.5.16]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-coyote.jar:8.5.16]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455) [tomcat-coyote.jar:8.5.16]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-coyote.jar:8.5.16]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_144]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_144]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.5.16]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_144]
Caused by: org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException: Imported module [ietf-interfaces] was not found. [at /home/user/yang/iana-if-type.yang:5:2]
    at org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException.throwIf(InferenceException.java:47) ~[yang-parser-impl-1.2.0-SNAPSHOT.jar:na]
    at org.opendaylight.yangtools.yang.parser.stmt.rfc6020.ImportStatementDefinition$1.prerequisiteFailed(ImportStatementDefinition.java:118) ~[yang-parser-impl-1.2.0-SNAPSHOT.jar:na]
    at org.opendaylight.yangtools.yang.parser.stmt.reactor.ModifierImpl.failModifier(ModifierImpl.java:87) ~[yang-parser-impl-1.2.0-SNAPSHOT.jar:na]
    at org.opendaylight.yangtools.yang.parser.stmt.reactor.SourceSpecificContext.failModifiers(SourceSpecificContext.java:341) ~[yang-parser-impl-1.2.0-SNAPSHOT.jar:na]
    ... 92 common frames omitted
DEBUG [http-nio-8080-exec-25] o.h.e.t.s.AbstractTransactionImpl.rollback(205) | rolling back
DEBUG [http-nio-8080-exec-25] o.h.e.t.i.j.JdbcTransaction.doRollback(164) | rolled JDBC Connection
DEBUG [http-nio-8080-exec-25] o.h.e.t.i.j.JdbcTransaction.releaseManagedConnection(126) | re-enabling autocommit
DEBUG [http-nio-8080-exec-25] o.h.e.j.i.LogicalConnectionImpl.releaseConnection(246) | Releasing JDBC connection
DEBUG [http-nio-8080-exec-25] o.h.e.j.i.LogicalConnectionImpl.releaseConnection(264) | Released JDBC connection
ERROR [http-nio-8080-exec-25] c.a.e.n.c.FileController.handleAllException(140) | Parsing Yang module failed, error : Some of SOURCE_PRE_LINKAGE modifiers for statements were not resolved.
DEBUG [http-nio-8080-exec-25] c.a.e.n.c.MDCFilter.doFilter(45) | End filtering request with com.example.common.MDCFilter
DEBUG [http-nio-8080-exec-25] c.a.e.n.s.StatelessAuthenticationFilter.doFilter(41) | End filtering request with com.example.security.StatelessAuthenticationFilter

Can you help me ?

Thanks.

2

There are 2 best solutions below

0
On

I'm not 100% following what you are doing, but I think this message is key:

Caused by: org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException: Imported module [ietf-interfaces] was not found. [at /home/user/yang/iana-if-type.yang:5:2]

So you are trying to load iana-if-type.yang, and that has an import to ietf-interfaces.yang, which it cannot resolve. But I'm not 100% sure what you have to do..

Have you already tried simply having ietf-interfaces.yang in your /home/user/yang/ ? Not sure that works / is sufficient - you may have to tell the YANG parser API where / how it can load depenencies from. During RT in ODL this works via OSGi from the CP. During the CLI mvn binding generation in ODL this works because the Maven plugin looks at the projects CP to find dependant YANG models. Actually, if you look around the source code of the yang-maven-plugin how it finds dependencies, you can probably figure it out from there?

HTH. Otherwise, you may also be able to get more help over on our https://lists.opendaylight.org/mailman/listinfo/yangtools-dev for something like this.

0
On

I was looking at the yang-maven-plugin source code, and came up with the solution to this problem adding all files to the reactor. Look at the sample code.

CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();

        for (final URL url : files) {
            reactor.addSource(
                    YangStatementStreamSource.create(
                        YangTextSchemaSource.forFile(new File(url.getPath()))
                    )
            );
        }

        SchemaContext schemaContext = reactor.buildEffective();