在Spring Yarn应用程序中使用本地文件

时间:2015-04-17 06:16:53

标签: spring-boot yarn

我需要在纱线容器上部署war文件,因为我正在使用Spring批处理创建一个使用嵌入式jetty服务器部署war文件的纱线应用程序,当我使用自定义句柄处理请求时,它可以正常运行应用程序获取部署在纱线上但是当我使用war文件作为处理程序时它不起作用我得到一个错误

java.io.FileNotFoundException: /root/jettywebapps/webapps/Login.war

但文件实际上存在于给定位置我遇到了如何从纱线容器访问war文件

@OnContainerStart
    public void publicVoidNoArgsMethod() throws Exception {
        String jetty_home="/root/jettywebapps";
        Server server = new Server(9090);
        WebAppContext webapp = new WebAppContext();
        webapp.setContextPath("/Login");
        webapp.setWar(jetty_home+"/webapps/Login.war");
        server.setHandler(webapp);
        server.start();
        server.join();
    }

这是堆栈跟踪

2015-04-17 06:05:14.972] boot - 26920  INFO [main] --- ContainerLauncherRunner: Running YarnContainer with parameters []
[2015-04-17 06:05:14.972] boot - 26920  INFO [main] --- ContainerLauncherRunner: Container requested that we wait state, setting up latch
[2015-04-17 06:05:14.975] boot - 26920  INFO [main] --- DefaultYarnContainer: Processing 1 @YarnComponent handlers
[2015-04-17 06:05:15.038] boot - 26920  INFO [main] --- Server: jetty-8.0.4.v20111024
[2015-04-17 06:05:15.080] boot - 26920  WARN [main] --- WebInfConfiguration: Web application not found /root/jettywebapps/webapps/Login.war
[2015-04-17 06:05:15.081] boot - 26920  WARN [main] --- WebAppContext: Failed startup of context o.e.j.w.WebAppContext{/Login,null},/root/jettywebapps/webapps/Login.war
java.io.FileNotFoundException: /root/jettywebapps/webapps/Login.war
        at org.eclipse.jetty.webapp.WebInfConfiguration.unpack(WebInfConfiguration.java:479)
        at org.eclipse.jetty.webapp.WebInfConfiguration.preConfigure(WebInfConfiguration.java:52)
        at org.eclipse.jetty.webapp.WebAppContext.preConfigure(WebAppContext.java:416)
        at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:452)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
        at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:89)
        at org.eclipse.jetty.server.Server.doStart(Server.java:262)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:59)
        at hello.container.HelloPojo.publicVoidNoArgsMethod(HelloPojo.java:40)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.springframework.expression.spel.support.ReflectiveMethodExecutor.execute(ReflectiveMethodExecutor.java:112)
        at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:129)
        at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:49)
        at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:342)
        at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88)
        at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:131)
        at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:330)
        at org.springframework.yarn.support.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:126)
        at org.springframework.yarn.container.ContainerMethodInvokerHelper.processInternal(ContainerMethodInvokerHelper.java:229)
        at org.springframework.yarn.container.ContainerMethodInvokerHelper.process(ContainerMethodInvokerHelper.java:115)
        at org.springframework.yarn.container.MethodInvokingYarnContainerRuntimeProcessor.process(MethodInvokingYarnContainerRuntimeProcessor.java:51)
        at org.springframework.yarn.container.ContainerHandler.handle(ContainerHandler.java:99)
        at org.springframework.yarn.container.DefaultYarnContainer.getContainerHandlerResults(DefaultYarnContainer.java:174)
        at org.springframework.yarn.container.DefaultYarnContainer.runInternal(DefaultYarnContainer.java:77)

请帮忙 感谢

1 个答案:

答案 0 :(得分:1)

容器可以使用以下代码获取本地文件或hdfs文件:

Configuration conf = new Configuration();
FileSystem localFS = FileSystem.get(URI.create("file://localhost"), conf);
OutputStream outATXT = localFS.create(new Path("/home/walterchen/a.txt"));

Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(URI.create("hdfs://localhost:9000"), conf);
OutputStream out = fs.create(new Path("/home/a.txt"));