|
18 | 18 | package org.apache.flink.cdc.composer.flink; |
19 | 19 |
|
20 | 20 | import org.apache.flink.cdc.common.annotation.Internal; |
| 21 | +import org.apache.flink.cdc.common.annotation.VisibleForTesting; |
21 | 22 | import org.apache.flink.cdc.common.configuration.Configuration; |
22 | 23 | import org.apache.flink.cdc.common.event.Event; |
23 | 24 | import org.apache.flink.cdc.common.pipeline.PipelineOptions; |
@@ -59,32 +60,28 @@ public class FlinkPipelineComposer implements PipelineComposer { |
59 | 60 | public static FlinkPipelineComposer ofRemoteCluster( |
60 | 61 | org.apache.flink.configuration.Configuration flinkConfig, List<Path> additionalJars) { |
61 | 62 | StreamExecutionEnvironment env = new StreamExecutionEnvironment(flinkConfig); |
62 | | - additionalJars.forEach( |
63 | | - jarPath -> { |
64 | | - try { |
65 | | - FlinkEnvironmentUtils.addJar( |
66 | | - env, |
67 | | - jarPath.makeQualified(jarPath.getFileSystem()).toUri().toURL()); |
68 | | - } catch (Exception e) { |
69 | | - throw new RuntimeException( |
70 | | - String.format( |
71 | | - "Unable to convert JAR path \"%s\" to URL when adding JAR to Flink environment", |
72 | | - jarPath), |
73 | | - e); |
74 | | - } |
75 | | - }); |
| 63 | + addAdditionalJars(env, additionalJars); |
76 | 64 | return new FlinkPipelineComposer(env, false); |
77 | 65 | } |
78 | 66 |
|
79 | 67 | public static FlinkPipelineComposer ofApplicationCluster(StreamExecutionEnvironment env) { |
80 | 68 | return new FlinkPipelineComposer(env, false); |
81 | 69 | } |
82 | 70 |
|
| 71 | + @VisibleForTesting |
83 | 72 | public static FlinkPipelineComposer ofMiniCluster() { |
84 | 73 | return new FlinkPipelineComposer( |
85 | 74 | StreamExecutionEnvironment.getExecutionEnvironment(), true); |
86 | 75 | } |
87 | 76 |
|
| 77 | + public static FlinkPipelineComposer ofMiniCluster( |
| 78 | + org.apache.flink.configuration.Configuration flinkConfig, List<Path> additionalJars) { |
| 79 | + StreamExecutionEnvironment localEnvironment = |
| 80 | + StreamExecutionEnvironment.getExecutionEnvironment(flinkConfig); |
| 81 | + addAdditionalJars(localEnvironment, additionalJars); |
| 82 | + return new FlinkPipelineComposer(localEnvironment, true); |
| 83 | + } |
| 84 | + |
88 | 85 | private FlinkPipelineComposer(StreamExecutionEnvironment env, boolean isBlocking) { |
89 | 86 | this.env = env; |
90 | 87 | this.isBlocking = isBlocking; |
@@ -254,4 +251,22 @@ private Optional<URL> getContainingJar(Class<?> clazz) throws Exception { |
254 | 251 | } |
255 | 252 | return Optional.of(container); |
256 | 253 | } |
| 254 | + |
| 255 | + private static void addAdditionalJars( |
| 256 | + StreamExecutionEnvironment env, List<Path> additionalJars) { |
| 257 | + additionalJars.forEach( |
| 258 | + jarPath -> { |
| 259 | + try { |
| 260 | + FlinkEnvironmentUtils.addJar( |
| 261 | + env, |
| 262 | + jarPath.makeQualified(jarPath.getFileSystem()).toUri().toURL()); |
| 263 | + } catch (Exception e) { |
| 264 | + throw new RuntimeException( |
| 265 | + String.format( |
| 266 | + "Unable to convert JAR path \"%s\" to URL when adding JAR to Flink environment", |
| 267 | + jarPath), |
| 268 | + e); |
| 269 | + } |
| 270 | + }); |
| 271 | + } |
257 | 272 | } |
0 commit comments