41
41
import org .apache .flink .runtime .execution .Environment ;
42
42
import org .apache .flink .runtime .execution .ExecutionState ;
43
43
import org .apache .flink .runtime .executiongraph .AccessExecutionGraph ;
44
+ import org .apache .flink .runtime .executiongraph .AccessExecutionJobVertex ;
44
45
import org .apache .flink .runtime .highavailability .HighAvailabilityServices ;
45
46
import org .apache .flink .runtime .highavailability .nonha .embedded .EmbeddedHaServicesWithLeadershipControl ;
46
47
import org .apache .flink .runtime .io .network .partition .PartitionedFile ;
47
48
import org .apache .flink .runtime .io .network .partition .ResultPartitionID ;
48
- import org .apache .flink .runtime .jobgraph .JobGraph ;
49
49
import org .apache .flink .runtime .jobgraph .JobType ;
50
- import org .apache .flink .runtime .jobgraph .JobVertex ;
51
50
import org .apache .flink .runtime .jobmaster .JobResult ;
52
51
import org .apache .flink .runtime .minicluster .MiniCluster ;
53
52
import org .apache .flink .runtime .minicluster .TestingMiniCluster ;
57
56
import org .apache .flink .streaming .api .graph .GlobalStreamExchangeMode ;
58
57
import org .apache .flink .streaming .api .graph .StreamConfig ;
59
58
import org .apache .flink .streaming .api .graph .StreamGraph ;
60
- import org .apache .flink .streaming .api .graph .StreamingJobGraphGenerator ;
61
59
import org .apache .flink .streaming .api .operators .AbstractStreamOperator ;
62
60
import org .apache .flink .streaming .api .operators .OneInputStreamOperator ;
63
61
import org .apache .flink .streaming .api .operators .Output ;
@@ -165,12 +163,12 @@ public void setup() throws Exception {
165
163
166
164
@ Test
167
165
void testRecoverFromJMFailover () throws Exception {
168
- JobGraph jobGraph = prepareEnvAndGetJobGraph ();
166
+ StreamGraph streamGraph = prepareEnvAndGetStreamGraph ();
169
167
170
168
// blocking all sink
171
169
StubRecordSink .blockSubTasks (0 , 1 , 2 , 3 );
172
170
173
- JobID jobId = flinkCluster .submitJob (jobGraph ).get ().getJobID ();
171
+ JobID jobId = flinkCluster .submitJob (streamGraph ).get ().getJobID ();
174
172
175
173
// wait until sink is running.
176
174
tryWaitUntilCondition (() -> StubRecordSink .attemptIds .size () > 0 );
@@ -188,21 +186,25 @@ void testRecoverFromJMFailover() throws Exception {
188
186
189
187
@ Test
190
188
void testSourceNotAllFinished () throws Exception {
191
- JobGraph jobGraph = prepareEnvAndGetJobGraph ();
189
+ StreamGraph streamGraph = prepareEnvAndGetStreamGraph ();
192
190
193
191
// blocking source 0
194
192
SourceTail .blockSubTasks (0 );
195
193
196
- JobID jobId = flinkCluster .submitJob (jobGraph ).get ().getJobID ();
194
+ JobID jobId = flinkCluster .submitJob (streamGraph ).get ().getJobID ();
197
195
198
196
// wait until source is running.
199
197
tryWaitUntilCondition (() -> SourceTail .attemptIds .size () == SOURCE_PARALLELISM );
200
198
201
- JobVertex source = jobGraph .getVerticesSortedTopologicallyFromSources ().get (0 );
202
199
while (true ) {
203
200
AccessExecutionGraph executionGraph = flinkCluster .getExecutionGraph (jobId ).get ();
201
+ AccessExecutionJobVertex source =
202
+ executionGraph .getAllVertices ().values ().stream ()
203
+ .filter (jobVertex -> jobVertex .getName ().contains ("Source" ))
204
+ .findFirst ()
205
+ .get ();
204
206
long finishedTasks =
205
- Arrays .stream (executionGraph . getJobVertex ( source . getID ()) .getTaskVertices ())
207
+ Arrays .stream (source .getTaskVertices ())
206
208
.filter (task -> task .getExecutionState () == ExecutionState .FINISHED )
207
209
.count ();
208
210
if (finishedTasks == SOURCE_PARALLELISM - 1 ) {
@@ -228,12 +230,12 @@ void testTaskExecutorNotRegisterOnTime() throws Exception {
228
230
Configuration configuration = new Configuration ();
229
231
configuration .set (
230
232
BatchExecutionOptions .JOB_RECOVERY_PREVIOUS_WORKER_RECOVERY_TIMEOUT , Duration .ZERO );
231
- JobGraph jobGraph = prepareEnvAndGetJobGraph (configuration );
233
+ StreamGraph streamGraph = prepareEnvAndGetStreamGraph (configuration );
232
234
233
235
// blocking all sink
234
236
StubRecordSink .blockSubTasks (0 , 1 , 2 , 3 );
235
237
236
- JobID jobId = flinkCluster .submitJob (jobGraph ).get ().getJobID ();
238
+ JobID jobId = flinkCluster .submitJob (streamGraph ).get ().getJobID ();
237
239
238
240
// wait until sink is running.
239
241
tryWaitUntilCondition (() -> StubRecordSink .attemptIds .size () > 0 );
@@ -251,12 +253,12 @@ void testTaskExecutorNotRegisterOnTime() throws Exception {
251
253
252
254
@ Test
253
255
void testPartitionNotFoundTwice () throws Exception {
254
- JobGraph jobGraph = prepareEnvAndGetJobGraph ();
256
+ StreamGraph streamGraph = prepareEnvAndGetStreamGraph ();
255
257
256
258
// blocking map 0 and map 1.
257
259
StubMapFunction .blockSubTasks (0 , 1 );
258
260
259
- JobID jobId = flinkCluster .submitJob (jobGraph ).get ().getJobID ();
261
+ JobID jobId = flinkCluster .submitJob (streamGraph ).get ().getJobID ();
260
262
261
263
// wait until map deploying, which indicates all source finished.
262
264
tryWaitUntilCondition (() -> StubMapFunction .attemptIds .size () > 0 );
@@ -286,12 +288,12 @@ void testPartitionNotFoundTwice() throws Exception {
286
288
287
289
@ Test
288
290
void testPartitionNotFoundAndOperatorCoordinatorNotSupportBatchSnapshot () throws Exception {
289
- JobGraph jobGraph = prepareEnvAndGetJobGraph (false );
291
+ StreamGraph streamGraph = prepareEnvAndGetStreamGraph (false );
290
292
291
293
// blocking all map task
292
294
StubMapFunction2 .blockSubTasks (0 , 1 , 2 , 3 );
293
295
294
- JobID jobId = flinkCluster .submitJob (jobGraph ).get ().getJobID ();
296
+ JobID jobId = flinkCluster .submitJob (streamGraph ).get ().getJobID ();
295
297
296
298
// wait until map deploying, which indicates all source finished.
297
299
tryWaitUntilCondition (() -> StubMapFunction2 .attemptIds .size () > 0 );
@@ -312,12 +314,12 @@ void testPartitionNotFoundAndOperatorCoordinatorNotSupportBatchSnapshot() throws
312
314
313
315
@ Test
314
316
void testPartitionNotFoundAndOperatorCoordinatorSupportBatchSnapshot () throws Exception {
315
- JobGraph jobGraph = prepareEnvAndGetJobGraph ();
317
+ StreamGraph streamGraph = prepareEnvAndGetStreamGraph ();
316
318
317
319
// blocking map 0.
318
320
StubMapFunction .blockSubTasks (0 );
319
321
320
- JobID jobId = flinkCluster .submitJob (jobGraph ).get ().getJobID ();
322
+ JobID jobId = flinkCluster .submitJob (streamGraph ).get ().getJobID ();
321
323
322
324
// wait until map deploying, which indicates all source finished.
323
325
tryWaitUntilCondition (() -> StubMapFunction .attemptIds .size () > 0 );
@@ -336,28 +338,29 @@ void testPartitionNotFoundAndOperatorCoordinatorSupportBatchSnapshot() throws Ex
336
338
checkCountResults ();
337
339
}
338
340
339
- private JobGraph prepareEnvAndGetJobGraph () throws Exception {
341
+ private StreamGraph prepareEnvAndGetStreamGraph () throws Exception {
340
342
Configuration configuration = new Configuration ();
341
343
configuration .set (
342
344
BatchExecutionOptions .JOB_RECOVERY_PREVIOUS_WORKER_RECOVERY_TIMEOUT ,
343
345
previousWorkerRecoveryTimeout );
344
- return prepareEnvAndGetJobGraph (configuration , true );
346
+ return prepareEnvAndGetStreamGraph (configuration , true );
345
347
}
346
348
347
- private JobGraph prepareEnvAndGetJobGraph (Configuration config ) throws Exception {
348
- return prepareEnvAndGetJobGraph (config , true );
349
+ private StreamGraph prepareEnvAndGetStreamGraph (Configuration config ) throws Exception {
350
+ return prepareEnvAndGetStreamGraph (config , true );
349
351
}
350
352
351
- private JobGraph prepareEnvAndGetJobGraph ( boolean operatorCoordinatorsSupportsBatchSnapshot )
352
- throws Exception {
353
+ private StreamGraph prepareEnvAndGetStreamGraph (
354
+ boolean operatorCoordinatorsSupportsBatchSnapshot ) throws Exception {
353
355
Configuration configuration = new Configuration ();
354
356
configuration .set (
355
357
BatchExecutionOptions .JOB_RECOVERY_PREVIOUS_WORKER_RECOVERY_TIMEOUT ,
356
358
previousWorkerRecoveryTimeout );
357
- return prepareEnvAndGetJobGraph (configuration , operatorCoordinatorsSupportsBatchSnapshot );
359
+ return prepareEnvAndGetStreamGraph (
360
+ configuration , operatorCoordinatorsSupportsBatchSnapshot );
358
361
}
359
362
360
- private JobGraph prepareEnvAndGetJobGraph (
363
+ private StreamGraph prepareEnvAndGetStreamGraph (
361
364
Configuration config , boolean operatorCoordinatorsSupportsBatchSnapshot )
362
365
throws Exception {
363
366
flinkCluster =
@@ -371,8 +374,8 @@ private JobGraph prepareEnvAndGetJobGraph(
371
374
env .setRuntimeMode (RuntimeExecutionMode .BATCH );
372
375
373
376
return operatorCoordinatorsSupportsBatchSnapshot
374
- ? createJobGraph (env , methodName )
375
- : createJobGraphWithUnsupportedBatchSnapshotOperatorCoordinator (env , methodName );
377
+ ? createStreamGraph (env , methodName )
378
+ : createStreamGraphWithUnsupportedBatchSnapshotOperatorCoordinator (env , methodName );
376
379
}
377
380
378
381
private TestingMiniClusterConfiguration getMiniClusterConfiguration (Configuration config )
@@ -446,7 +449,7 @@ private void releaseResultPartitionOfSource() {
446
449
new File (flinkConfiguration .get (CoreOptions .TMP_DIRS )));
447
450
}
448
451
449
- private JobGraph createJobGraph (StreamExecutionEnvironment env , String jobName ) {
452
+ private StreamGraph createStreamGraph (StreamExecutionEnvironment env , String jobName ) {
450
453
TupleTypeInfo <Tuple2 <Integer , Integer >> typeInfo =
451
454
new TupleTypeInfo <>(BasicTypeInfo .INT_TYPE_INFO , BasicTypeInfo .INT_TYPE_INFO );
452
455
@@ -468,10 +471,10 @@ private JobGraph createJobGraph(StreamExecutionEnvironment env, String jobName)
468
471
streamGraph .setGlobalStreamExchangeMode (GlobalStreamExchangeMode .ALL_EDGES_BLOCKING );
469
472
streamGraph .setJobType (JobType .BATCH );
470
473
streamGraph .setJobName (jobName );
471
- return StreamingJobGraphGenerator . createJobGraph ( streamGraph ) ;
474
+ return streamGraph ;
472
475
}
473
476
474
- private JobGraph createJobGraphWithUnsupportedBatchSnapshotOperatorCoordinator (
477
+ private StreamGraph createStreamGraphWithUnsupportedBatchSnapshotOperatorCoordinator (
475
478
StreamExecutionEnvironment env , String jobName ) throws Exception {
476
479
477
480
TupleTypeInfo <Tuple2 <Integer , Integer >> typeInfo =
@@ -500,7 +503,7 @@ private JobGraph createJobGraphWithUnsupportedBatchSnapshotOperatorCoordinator(
500
503
streamGraph .setGlobalStreamExchangeMode (GlobalStreamExchangeMode .ALL_EDGES_BLOCKING );
501
504
streamGraph .setJobType (JobType .BATCH );
502
505
streamGraph .setJobName (jobName );
503
- return StreamingJobGraphGenerator . createJobGraph ( streamGraph ) ;
506
+ return streamGraph ;
504
507
}
505
508
506
509
private static void setSubtaskBlocked (
0 commit comments