|
18 | 18 | package org.apache.seatunnel.api.table.factory;
|
19 | 19 |
|
20 | 20 | import org.apache.seatunnel.api.common.CommonOptions;
|
| 21 | +import org.apache.seatunnel.api.common.JobContext; |
21 | 22 | import org.apache.seatunnel.api.common.PluginIdentifier;
|
22 | 23 | import org.apache.seatunnel.api.configuration.ReadonlyConfig;
|
23 | 24 | import org.apache.seatunnel.api.configuration.util.ConfigValidator;
|
|
37 | 38 | import org.apache.seatunnel.api.table.connector.TableSource;
|
38 | 39 | import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
|
39 | 40 | import org.apache.seatunnel.api.transform.SeaTunnelTransform;
|
| 41 | +import org.apache.seatunnel.common.constants.EngineType; |
| 42 | +import org.apache.seatunnel.common.constants.JobMode; |
| 43 | +import org.apache.seatunnel.common.constants.PluginType; |
40 | 44 | import org.apache.seatunnel.common.utils.ExceptionUtils;
|
41 | 45 |
|
42 | 46 | import org.slf4j.Logger;
|
@@ -106,7 +110,10 @@ Tuple2<SeaTunnelSource<T, SplitT, StateT>, List<CatalogTable>> restoreAndPrepare
|
106 | 110 | if (fallback) {
|
107 | 111 | source =
|
108 | 112 | fallbackCreateSource.apply(
|
109 |
| - PluginIdentifier.of("seatunnel", "source", factoryId)); |
| 113 | + PluginIdentifier.of( |
| 114 | + EngineType.SEATUNNEL.getEngine(), |
| 115 | + PluginType.SOURCE.getType(), |
| 116 | + factoryId)); |
110 | 117 | source.prepare(options.toConfig());
|
111 | 118 |
|
112 | 119 | } else {
|
@@ -205,7 +212,10 @@ SeaTunnelSink<IN, StateT, CommitInfoT, AggregatedCommitInfoT> createAndPrepareSi
|
205 | 212 | if (fallback) {
|
206 | 213 | SeaTunnelSink sink =
|
207 | 214 | fallbackCreateSink.apply(
|
208 |
| - PluginIdentifier.of("seatunnel", "sink", factoryId)); |
| 215 | + PluginIdentifier.of( |
| 216 | + EngineType.SEATUNNEL.getEngine(), |
| 217 | + PluginType.SINK.getType(), |
| 218 | + factoryId)); |
209 | 219 | sink.prepare(config.toConfig());
|
210 | 220 | sink.setTypeInfo(catalogTable.getSeaTunnelRowType());
|
211 | 221 |
|
@@ -273,6 +283,23 @@ public static <T extends Factory> URL getFactoryUrl(T factory) {
|
273 | 283 | return factory.getClass().getProtectionDomain().getCodeSource().getLocation();
|
274 | 284 | }
|
275 | 285 |
|
| 286 | + public static <T extends Factory> Optional<T> discoverOptionalFactory( |
| 287 | + ClassLoader classLoader, |
| 288 | + Class<T> factoryClass, |
| 289 | + String factoryIdentifier, |
| 290 | + Function<String, T> discoverOptionalFactoryFunction) { |
| 291 | + |
| 292 | + if (discoverOptionalFactoryFunction != null) { |
| 293 | + T apply = discoverOptionalFactoryFunction.apply(factoryIdentifier); |
| 294 | + if (apply != null) { |
| 295 | + return Optional.of(apply); |
| 296 | + } else { |
| 297 | + return Optional.empty(); |
| 298 | + } |
| 299 | + } |
| 300 | + return discoverOptionalFactory(classLoader, factoryClass, factoryIdentifier); |
| 301 | + } |
| 302 | + |
276 | 303 | public static <T extends Factory> Optional<T> discoverOptionalFactory(
|
277 | 304 | ClassLoader classLoader, Class<T> factoryClass, String factoryIdentifier) {
|
278 | 305 | final List<T> foundFactories = discoverFactories(classLoader, factoryClass);
|
@@ -436,4 +463,14 @@ private static <T extends Factory> boolean isFallback(
|
436 | 463 | }
|
437 | 464 | return false;
|
438 | 465 | }
|
| 466 | + |
| 467 | + public static void ensureJobModeMatch(JobContext jobContext, SeaTunnelSource source) { |
| 468 | + if (jobContext.getJobMode() == JobMode.BATCH |
| 469 | + && source.getBoundedness() |
| 470 | + == org.apache.seatunnel.api.source.Boundedness.UNBOUNDED) { |
| 471 | + throw new UnsupportedOperationException( |
| 472 | + String.format( |
| 473 | + "'%s' source don't support off-line job.", source.getPluginName())); |
| 474 | + } |
| 475 | + } |
439 | 476 | }
|
0 commit comments