我目前正在使用图形工具来处理YANG文件,并使用Vaadin作为前端(已集成到Netbeans中)。该工具在Glassfish 4服务器上启动。该工具中涉及YANG的所有功能都直接或间接依赖于Opendaylight的Yang工具(位于https://github.com/opendaylight/yangtools/tree/master/yang)。目前,我的项目可以很好地构建并部署到服务器上,并且在尝试解析YANG文件时仅遇到错误。具体来说,以下类描述了此解析方法:
public class YangParser implements SchemaSourceProvider<YangTextSchemaSource> {
private HashMap<SourceIdentifier,YangTextSchemaSource> sources;
private SharedSchemaRepository repository;
private SchemaContext schemaContext;
private InMemorySchemaSourceCache<ASTSchemaSource> cache;
private List<String> warnings;
YangParser() {
//System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "debug");
sources = new HashMap<>();
repository = new SharedSchemaRepository("yang-context-resolver");
repository.registerSchemaSourceListener(TextToASTTransformer.create(repository, repository));
cache = InMemorySchemaSourceCache.createSoftCache(repository, ASTSchemaSource.class);
warnings = new LinkedList<>();
}
// Will be used in retriever view in order to redirect SchemaContexts into relevant locations and then parse them (as YANG files)
public SharedSchemaRepository getRepo () {
return repository;
}
public Collection<YangTextSchemaSource> getSources() {
return sources.values();
}
public void registerSource(String identifier, String version, URL url)
throws SchemaSourceException, IOException, YangSyntaxErrorException {
registerSource(identifier, version, Resources.asByteSource(url));
}
public void registerSource(String identifier, String version, byte[] bytes)
throws SchemaSourceException, IOException, YangSyntaxErrorException {
registerSource(identifier, version, YangTextSchemaSource.wrap(bytes));
}
public void registerSource(String identifier, String version, ByteSource byteSource)
throws SchemaSourceException, IOException, YangSyntaxErrorException {
YangTextSchemaSource source = YangTextSchemaSource.delegateForByteSource(
RevisionSourceIdentifier.create(identifier, Revision.of(version)), byteSource);
ASTSchemaSource ast = TextToASTTransformer.transformText(source);
SourceIdentifier actualIdentifier = ast.getIdentifier();
// Fixup YANG source identifier if the provided YANG model has a different actual identifier
if (!source.getIdentifier().equals(actualIdentifier))
source = YangTextSchemaSource.delegateForByteSource(actualIdentifier, byteSource);
cache.schemaSourceEncountered(ast);
sources.put(source.getIdentifier(), source);
repository.registerSchemaSource(this, PotentialSchemaSource.create(
source.getIdentifier(), YangTextSchemaSource.class, PotentialSchemaSource.Costs.IMMEDIATE.getValue()));
}
public void parse() {
SchemaContextFactory factory = repository.createSchemaContextFactory(SchemaSourceFilter.ALWAYS_ACCEPT);
Collection<SourceIdentifier> requiredSources = new HashSet<>(sources.keySet());
// Parse all available YANG models, if we fail remove failed model and retry with remaining models
while (!requiredSources.isEmpty()) {
try {
schemaContext = factory.createSchemaContext(requiredSources).checkedGet();
break;
} catch (SchemaResolutionException e) {
if (!e.getUnsatisfiedImports().isEmpty()) {
for (SourceIdentifier id : e.getUnsatisfiedImports().keySet()) {
String imports = e.getUnsatisfiedImports().get(id).stream()
.map(ModuleImport::getModuleName).collect(Collectors.joining(", "));
warnings.add(String.format("%s tries to imports missing model: %s",
id.toYangFilename(), imports));
System.err.printf("%TF %TT: %s\n", System.currentTimeMillis(), System.currentTimeMillis(),
warnings.get(warnings.size() - 1));
}
}
if (e.getFailedSource() != null) {
requiredSources.remove(e.getFailedSource());
warnings.add(String.format("%s failed to parse as a valid YANG model",
e.getFailedSource().toYangFilename()));
System.err.printf("%TF %TT: %s\n", System.currentTimeMillis(), System.currentTimeMillis(),
warnings.get(warnings.size() - 1));
} else {
requiredSources = new HashSet<>(e.getResolvedSources());
}
e.printStackTrace();
}
}
}
// Returns whether sending the files to the URL was successful or not
public boolean sendSchemaContextToPlace(String place){
//Shouldn't need to check is schemaContext is null because that happens beforehand inside RetrieverView
//String charset = "UTF-8";
//String CRLF = "\r\n";
String trimmedPlace = place.trim();
//String boundary = Long.toHexString(System.currentTimeMillis());
//ArrayList<File> listOfFilesToDelete = new ArrayList<>();
int responseCode = -1;
try {
Set<Module> schemaModules = schemaContext.getModules();
URL url = new URL(trimmedPlace);
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
//The following two commented out sections may be unnecessary since the files are directly
//created remotely with respect to their appropriate URLs; the connection is still necessary
//to see if the responsecode is ok
/*
OutputStream output = connection.getOutputStream();
PrintWriter pwOutput = new PrintWriter(new OutputStreamWriter(output, charset), true);
*/
for (Module m: schemaModules) {
File temp = new File((new URL(trimmedPlace + (trimmedPlace.substring(trimmedPlace.length() - 1).equals("/") || trimmedPlace.substring(trimmedPlace.length() - 1).equals("\\")
? "" : "/") + m.getName())).toURI());
PrintWriter pwTemp = new PrintWriter(temp);
pwTemp.write(m.getSource());
pwTemp.close();
/*
pwOutput.append("--" + boundary).append(CRLF);
pwOutput.append("Content-Disposition: form-data; name=\"textFile\"; filename=\"" + temp.getName() + "\"").append(CRLF);
pwOutput.append("Content-Type: text/plain; charset=" + charset).append(CRLF);
pwOutput.append(CRLF).flush();
Files.copy(temp, output);
output.flush();
pwOutput.append(CRLF).flush();
pwOutput.append("--" + boundary + "--").append(CRLF).flush();
pwOutput.close();*/
}
responseCode = ((HttpURLConnection) connection).getResponseCode();
}
catch (MalformedURLException e) {
System.err.printf("The URL you provided, %s, is in an incorrect format.", place);
}
catch (IOException e) {
System.err.print(e.getCause());
}
catch (URISyntaxException e) {
System.err.print("URL conversion to URI failed.");
}
return responseCode == 200;
}
public SchemaContext getSchemaContext() {
return schemaContext;
}
public Collection<String> getWarnings() {
return warnings;
}
public void addWarning(String warning) {
warnings.add(warning);
}
@Override
public CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> getSource(SourceIdentifier sourceIdentifier) {
YangTextSchemaSource source = sources.get(sourceIdentifier);
return source != null ? Futures.immediateCheckedFuture(source) : Futures.immediateFailedCheckedFuture(
new MissingSchemaSourceException("URL for " + sourceIdentifier + " not registered", sourceIdentifier));
}
}
在错误日志(位于最底部)中,有问题的行是:
schemaContext = factory.createSchemaContext(requiredSources).checkedGet();
这里的问题出在checkedGet方法上(即我认为createSchemaContext是成功的),除非我将其解释为错误;特定行位于错误日志顶部附近:
at com.google.common.util.concurrent.AbstractCheckedFuture.checkedGet(AbstractCheckedFuture.java:85)
具体地说,在错误日志中,似乎我在尝试执行checkedGet方法时遇到了ExecutionException;查看相关的类显示,checkedGet看起来像:
try {
return get(timeout, unit);
}
.... <2 other exception catches> ....
catch (ExecutionException e) {
throw mapException(e)
}
我的主要问题是我似乎无法以有意义的方式解释错误日志;对我而言唯一有意义的是最后一个“严重”错误;这个异常是我在RetrieverView中手动抛出的异常(我的另一个类;不包括在内,但实际上流程如下:我创建了一个新的YangParser();然后该解析器多次调用registerSource(___),这只是注册YANG从远程存储库提取的文件-据我所知,registerSource调用中没有一个遇到任何异常;最后,解析器调用parse(在所有已注册的源上),然后遇到日志中显示的错误)。
那么其他两个错误呢?顶部的第一个严重者对我来说毫无意义:这意味着“ SchemaResolutionException {unsatisfiedImports = {}}”是什么意思?由于数组为空,因此似乎不会有不满意的导入。这个错误的原因也令我感到困惑:“ java.lang.NoSuchFieldError:GET_IDENTIFIER”是什么?肯定不在冒犯的类SharedSchemaContextFactory中:
有人可以提供帮助吗?
错误日志:
Severe: SchemaResolutionException{unsatisfiedImports={}}
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.opendaylight.yangtools.util.concurrent.ReflectiveExceptionMapper.newWithCause(ReflectiveExceptionMapper.java:31)
at org.opendaylight.yangtools.util.concurrent.ExceptionMapper.apply(ExceptionMapper.java:80)
at org.opendaylight.yangtools.util.concurrent.ExceptionMapper.apply(ExceptionMapper.java:31)
at com.google.common.util.concurrent.Futures$MappingCheckedFuture.mapException(Futures.java:1809)
at com.google.common.util.concurrent.AbstractCheckedFuture.checkedGet(AbstractCheckedFuture.java:85)
at ANXExplorerV2.YangParser.parse(YangParser.java:107)
at ANXExplorerV2.RetrieverView.lambda$new$c6839ed1$1(RetrieverView.java:241)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:499)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:273)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:237)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1014)
at com.vaadin.ui.Button.fireClick(Button.java:371)
at com.vaadin.ui.Button.click(Button.java:360)
at com.vaadin.ui.Button$ClickShortcut.handleAction(Button.java:477)
at com.vaadin.event.ActionManager.handleAction(ActionManager.java:242)
at com.vaadin.event.ConnectorActionManager.handleAction(ConnectorActionManager.java:75)
at com.vaadin.event.ActionManager.handleAction(ActionManager.java:237)
at com.vaadin.event.ActionManager.handleActions(ActionManager.java:220)
at com.vaadin.ui.UI.changeVariables(UI.java:444)
at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:625)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocation(ServerRpcHandler.java:471)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:414)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:274)
at com.vaadin.server.communication.PushHandler.lambda$new$1(PushHandler.java:146)
at com.vaadin.server.communication.PushHandler.callWithUi(PushHandler.java:236)
at com.vaadin.server.communication.PushHandler.onMessage(PushHandler.java:522)
at com.vaadin.server.communication.PushAtmosphereHandler.onMessage(PushAtmosphereHandler.java:87)
at com.vaadin.server.communication.PushAtmosphereHandler.onRequest(PushAtmosphereHandler.java:77)
at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:224)
at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:114)
at org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:67)
at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:2290)
at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:594)
at org.atmosphere.websocket.DefaultWebSocketProcessor$3.run(DefaultWebSocketProcessor.java:345)
at org.atmosphere.util.VoidExecutorService.execute(VoidExecutorService.java:101)
at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:340)
at org.atmosphere.websocket.DefaultWebSocketProcessor.invokeWebSocketProtocol(DefaultWebSocketProcessor.java:448)
at org.atmosphere.container.JSR356Endpoint$3.onMessage(JSR356Endpoint.java:272)
at org.atmosphere.container.JSR356Endpoint$3.onMessage(JSR356Endpoint.java:269)
at org.glassfish.tyrus.core.TyrusSession.notifyMessageHandlers(TyrusSession.java:576)
at org.glassfish.tyrus.core.TyrusEndpointWrapper.onMessage(TyrusEndpointWrapper.java:871)
at org.glassfish.tyrus.core.TyrusWebSocket.onMessage(TyrusWebSocket.java:212)
at org.glassfish.tyrus.core.frame.TextFrame.respond(TextFrame.java:139)
at org.glassfish.tyrus.core.ProtocolHandler.process(ProtocolHandler.java:807)
at org.glassfish.tyrus.core.TyrusWebSocketEngine$TyrusReadHandler.handle(TyrusWebSocketEngine.java:562)
at org.glassfish.tyrus.servlet.TyrusHttpUpgradeHandler.onDataAvailable(TyrusHttpUpgradeHandler.java:173)
at org.apache.catalina.connector.InputBuffer$ReadHandlerImpl.processDataAvailable(InputBuffer.java:488)
at org.apache.catalina.connector.InputBuffer$ReadHandlerImpl.onDataAvailable(InputBuffer.java:453)
at org.glassfish.grizzly.http.io.InputBuffer.invokeHandler(InputBuffer.java:1089)
at org.glassfish.grizzly.http.io.InputBuffer.invokeHandlerOnProperThread(InputBuffer.java:1080)
at org.glassfish.grizzly.http.io.InputBuffer.append(InputBuffer.java:963)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:271)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoSuchFieldError: GET_IDENTIFIER
at org.opendaylight.yangtools.yang.parser.repo.SharedSchemaContextFactory$2.apply(SharedSchemaContextFactory.java:66)
at org.opendaylight.yangtools.yang.parser.repo.SharedSchemaContextFactory$2.apply(SharedSchemaContextFactory.java:63)
at com.google.common.util.concurrent.Futures$ChainingListenableFuture.run(Futures.java:906)
at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:457)
at com.google.common.util.concurrent.ExecutionList.executeListener(ExecutionList.java:156)
at com.google.common.util.concurrent.ExecutionList.add(ExecutionList.java:101)
at com.google.common.util.concurrent.AbstractFuture.addListener(AbstractFuture.java:170)
at com.google.common.util.concurrent.Futures.transform(Futures.java:567)
at org.opendaylight.yangtools.yang.parser.repo.SharedSchemaContextFactory.createSchemaContext(SharedSchemaContextFactory.java:127)
... 65 more
Severe: java.lang.Exception: Failed to analyze schemas! Please verify that the YANG models of your agent are valid!
at ANXExplorerV2.RetrieverView.lambda$new$c6839ed1$1(RetrieverView.java:244)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:499)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:273)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:237)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1014)
at com.vaadin.ui.Button.fireClick(Button.java:371)
at com.vaadin.ui.Button.click(Button.java:360)
at com.vaadin.ui.Button$ClickShortcut.handleAction(Button.java:477)
at com.vaadin.event.ActionManager.handleAction(ActionManager.java:242)
at com.vaadin.event.ConnectorActionManager.handleAction(ConnectorActionManager.java:75)
at com.vaadin.event.ActionManager.handleAction(ActionManager.java:237)
at com.vaadin.event.ActionManager.handleActions(ActionManager.java:220)
at com.vaadin.ui.UI.changeVariables(UI.java:444)
at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:625)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocation(ServerRpcHandler.java:471)
at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:414)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:274)
at com.vaadin.server.communication.PushHandler.lambda$new$1(PushHandler.java:146)
at com.vaadin.server.communication.PushHandler.callWithUi(PushHandler.java:236)
at com.vaadin.server.communication.PushHandler.onMessage(PushHandler.java:522)
at com.vaadin.server.communication.PushAtmosphereHandler.onMessage(PushAtmosphereHandler.java:87)
at com.vaadin.server.communication.PushAtmosphereHandler.onRequest(PushAtmosphereHandler.java:77)
at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:224)
at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:114)
at org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:67)
at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:2290)
at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:594)
at org.atmosphere.websocket.DefaultWebSocketProcessor$3.run(DefaultWebSocketProcessor.java:345)
at org.atmosphere.util.VoidExecutorService.execute(VoidExecutorService.java:101)
at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:340)
at org.atmosphere.websocket.DefaultWebSocketProcessor.invokeWebSocketProtocol(DefaultWebSocketProcessor.java:448)
at org.atmosphere.container.JSR356Endpoint$3.onMessage(JSR356Endpoint.java:272)
at org.atmosphere.container.JSR356Endpoint$3.onMessage(JSR356Endpoint.java:269)
at org.glassfish.tyrus.core.TyrusSession.notifyMessageHandlers(TyrusSession.java:576)
at org.glassfish.tyrus.core.TyrusEndpointWrapper.onMessage(TyrusEndpointWrapper.java:871)
at org.glassfish.tyrus.core.TyrusWebSocket.onMessage(TyrusWebSocket.java:212)
at org.glassfish.tyrus.core.frame.TextFrame.respond(TextFrame.java:139)
at org.glassfish.tyrus.core.ProtocolHandler.process(ProtocolHandler.java:807)
at org.glassfish.tyrus.core.TyrusWebSocketEngine$TyrusReadHandler.handle(TyrusWebSocketEngine.java:562)
at org.glassfish.tyrus.servlet.TyrusHttpUpgradeHandler.onDataAvailable(TyrusHttpUpgradeHandler.java:173)
at org.apache.catalina.connector.InputBuffer$ReadHandlerImpl.processDataAvailable(InputBuffer.java:488)
at org.apache.catalina.connector.InputBuffer$ReadHandlerImpl.onDataAvailable(InputBuffer.java:453)
at org.glassfish.grizzly.http.io.InputBuffer.invokeHandler(InputBuffer.java:1089)
at org.glassfish.grizzly.http.io.InputBuffer.invokeHandlerOnProperThread(InputBuffer.java:1080)
at org.glassfish.grizzly.http.io.InputBuffer.append(InputBuffer.java:963)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:271)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:748)