package org.myorg.quickstart;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;
import org.apache.flink.runtime.minicluster.LocalFlinkMiniCluster;
import org.apache.flink.configuration.Configuration;
public class WordCount {
public static void main(String[] args) throws Exception {
final LocalFlinkMiniCluster cluster = new LocalFlinkMiniCluster(new Configuration(), false); //line 16
cluster.start(); //line 17
final StreamExecutionEnvironment env = StreamExecutionEnvironment.createRemoteEnvironment("localhost", 6123);
final long N = 10;
DataStream<Long> stream = env.generateSequence(1, N);
stream.map(new MapFunction<Long, Long>() {
@Override
public Long map(Long value) throws Exception {
return 2 * value;
}
}).print();
env.execute("WC Test");
}
public static final class LineSplitter implements FlatMapFunction<String, Tuple2<String, Integer>> {
@Override
public void flatMap(String value, Collector<Tuple2<String, Integer>> out) {
// normalize and split the line
String[] tokens = value.toLowerCase().split("\\W+");
// emit the pairs
for (String token : tokens) {
if (token.length() > 0) {
out.collect(new Tuple2<String, Integer>(token, 1));
}
}
}
}
}
上面的代码可以在本地迷你集群上成功运行(windows + IDEA)。
然后,我在第16行和第17行发表评论。我在虚拟框中以Flink
或start-local.sh
开始start-cluster.sh
。但是,这次IDEA
我的程序失败了。它抱怨与工作经理无关,如下所示。
任何人都可以帮我找出失败的原因吗?我是否需要在virtualbox中为Flink
进行特殊设置。我已在虚拟机设置中转发JobManager
端口6123
。我甚至编译jar
并在虚拟框内运行jar
并出现相同的错误。
09:16:00,631 INFO org.apache.flink.streaming.api.environment.RemoteStreamEnvironment - Running remotely at localhost:6123
09:16:01,220 INFO org.apache.flink.client.program.StandaloneClusterClient - Submitting job with JobID: 2e53f2e2f66f023c2f4748f7fe6d4545. Waiting for job completion.
Submitting job with JobID: 2e53f2e2f66f023c2f4748f7fe6d4545. Waiting for job completion.
09:16:01,220 INFO org.apache.flink.client.program.StandaloneClusterClient - Starting client actor system.
09:16:02,212 INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
09:16:02,295 INFO Remoting - Starting remoting
09:16:02,530 INFO Remoting - Remoting started; listening on addresses :[akka.tcp://flink@127.0.0.1:56050]
09:16:02,542 INFO org.apache.flink.runtime.client.JobClientActor - Disconnect from JobManager null.
09:16:02,550 INFO org.apache.flink.runtime.client.JobClientActor - Received job Window WordCount (2e53f2e2f66f023c2f4748f7fe6d4545).
09:16:02,550 INFO org.apache.flink.runtime.client.JobClientActor - Could not submit job Window WordCount (2e53f2e2f66f023c2f4748f7fe6d4545), because there is no connection to a JobManager.
09:16:02,624 WARN akka.remote.ReliableDeliverySupervisor - Association with remote system [akka.tcp://flink@127.0.0.1:6123] has failed, address is now gated for [5000] ms. Reason is: [Association failed with [akka.tcp://flink@127.0.0.1:6123]].
Process finished with exit code 1
答案 0 :(得分:0)
我发现问题是因为maven的代码库与flink运行版本不同。一旦我确保所有lib都更新为flink 1.1.2,就没有问题。