Apache Flink:在预定义的上下文中运行时,无法实例化RemoteEnvironment

时间:2015-12-10 10:45:24

标签: apache-flink

有人知道,在远程Flink群集上运行程序时,以下错误的根源是什么?

我该如何解决?

 org.apache.flink.client.program.ProgramInvocationException: The main method caused an error.
    at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:512)
    at org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:395)
    at org.apache.flink.client.program.Client.runBlocking(Client.java:252)
    at org.apache.flink.client.CliFrontend.executeProgramBlocking(CliFrontend.java:675)
    at org.apache.flink.client.CliFrontend.run(CliFrontend.java:326)
    at org.apache.flink.client.CliFrontend.parseParameters(CliFrontend.java:977)
    at org.apache.flink.client.CliFrontend.main(CliFrontend.java:1027)
Caused by: org.apache.flink.api.common.InvalidProgramException: The RemoteEnvironment cannot be instantiated when running in a pre-defined context (such as Command Line Client, Scala Shell, or TestEnvironment)
    at org.apache.flink.api.java.RemoteEnvironment.<init>(RemoteEnvironment.java:118)
    at org.apache.flink.api.java.RemoteEnvironment.<init>(RemoteEnvironment.java:78)
    at org.apache.flink.api.java.ExecutionEnvironment.createRemoteEnvironment(ExecutionEnvironment.java:1155)
    at org.apache.flink.test.myProj.main(myProj.java:133)
    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.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:497)
    ... 6 more

2 个答案:

答案 0 :(得分:3)

在您的Flink计划中,您需要使用

ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

检索ExecutionEnvironment。这会自动获取本地环境(从IDE执行时)或群集环境(使用命令行客户端时)。

如果您想将Flink程序提交到远程群集,则只能使用RemoteEnvironment

答案 1 :(得分:0)

将作业提交到远程环境(您的代码使用.createRemoteEnvironment),您只能通过API调用而不是CLI来完成