Search in sources :

Example 1 with DataStreamUtils

use of org.apache.flink.streaming.api.datastream.DataStreamUtils in project flink by apache.

the class RegionFailoverITCase method createJobGraph.

private JobGraph createJobGraph() {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(NUM_OF_REGIONS);
    env.setMaxParallelism(MAX_PARALLELISM);
    env.enableCheckpointing(200, CheckpointingMode.EXACTLY_ONCE);
    env.getCheckpointConfig().setExternalizedCheckpointCleanup(CheckpointConfig.ExternalizedCheckpointCleanup.RETAIN_ON_CANCELLATION);
    env.disableOperatorChaining();
    // Use DataStreamUtils#reinterpretAsKeyed to avoid merge regions and this stream graph would
    // exist num of 'NUM_OF_REGIONS' individual regions.
    DataStreamUtils.reinterpretAsKeyedStream(env.addSource(new StringGeneratingSourceFunction(NUM_ELEMENTS, NUM_ELEMENTS / NUM_OF_RESTARTS)).name(MULTI_REGION_SOURCE_NAME).setParallelism(NUM_OF_REGIONS), (KeySelector<Tuple2<Integer, Integer>, Integer>) value -> value.f0, TypeInformation.of(Integer.class)).map(new FailingMapperFunction(NUM_OF_RESTARTS)).setParallelism(NUM_OF_REGIONS).addSink(new ValidatingSink()).setParallelism(NUM_OF_REGIONS);
    // another stream graph totally disconnected with the above one.
    env.addSource(new StringGeneratingSourceFunction(NUM_ELEMENTS, NUM_ELEMENTS / NUM_OF_RESTARTS)).name(SINGLE_REGION_SOURCE_NAME).setParallelism(1).map((MapFunction<Tuple2<Integer, Integer>, Object>) value -> value).setParallelism(1);
    return env.getStreamGraph().getJobGraph();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Tuple2(org.apache.flink.api.java.tuple.Tuple2) EmbeddedHaServicesWithLeadershipControl(org.apache.flink.runtime.highavailability.nonha.embedded.EmbeddedHaServicesWithLeadershipControl) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) CheckpointingMode(org.apache.flink.streaming.api.CheckpointingMode) FunctionSnapshotContext(org.apache.flink.runtime.state.FunctionSnapshotContext) MapFunction(org.apache.flink.api.common.functions.MapFunction) MiniClusterResourceConfiguration(org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration) ListState(org.apache.flink.api.common.state.ListState) PerJobCheckpointRecoveryFactory(org.apache.flink.runtime.checkpoint.PerJobCheckpointRecoveryFactory) TestUtils.submitJobAndWaitForResult(org.apache.flink.test.util.TestUtils.submitJobAndWaitForResult) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) TestLogger(org.apache.flink.util.TestLogger) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation) CompletedCheckpoint(org.apache.flink.runtime.checkpoint.CompletedCheckpoint) ClassRule(org.junit.ClassRule) AfterClass(org.junit.AfterClass) KeySelector(org.apache.flink.api.java.functions.KeySelector) HighAvailabilityServices(org.apache.flink.runtime.highavailability.HighAvailabilityServices) CheckpointedFunction(org.apache.flink.streaming.api.checkpoint.CheckpointedFunction) FunctionInitializationContext(org.apache.flink.runtime.state.FunctionInitializationContext) DataStreamUtils(org.apache.flink.streaming.api.datastream.DataStreamUtils) Set(java.util.Set) JobManagerOptions(org.apache.flink.configuration.JobManagerOptions) Collectors(java.util.stream.Collectors) RichSinkFunction(org.apache.flink.streaming.api.functions.sink.RichSinkFunction) List(java.util.List) ValueState(org.apache.flink.api.common.state.ValueState) ClusterClient(org.apache.flink.client.program.ClusterClient) CheckpointConfig(org.apache.flink.streaming.api.environment.CheckpointConfig) KeyGroupRangeAssignment(org.apache.flink.runtime.state.KeyGroupRangeAssignment) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) IntStream(java.util.stream.IntStream) HashMap(java.util.HashMap) RichMapFunction(org.apache.flink.api.common.functions.RichMapFunction) CollectionUtils(org.apache.commons.collections.CollectionUtils) RichParallelSourceFunction(org.apache.flink.streaming.api.functions.source.RichParallelSourceFunction) StreamSupport(java.util.stream.StreamSupport) StandaloneCompletedCheckpointStore(org.apache.flink.runtime.checkpoint.StandaloneCompletedCheckpointStore) Before(org.junit.Before) MiniClusterWithClientResource(org.apache.flink.test.util.MiniClusterWithClientResource) Executor(java.util.concurrent.Executor) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) Configuration(org.apache.flink.configuration.Configuration) CheckpointsCleaner(org.apache.flink.runtime.checkpoint.CheckpointsCleaner) Test(org.junit.Test) IOException(java.io.IOException) CheckpointRecoveryFactory(org.apache.flink.runtime.checkpoint.CheckpointRecoveryFactory) AtomicLong(java.util.concurrent.atomic.AtomicLong) ListCheckpointed(org.apache.flink.streaming.api.checkpoint.ListCheckpointed) HighAvailabilityServicesFactory(org.apache.flink.runtime.highavailability.HighAvailabilityServicesFactory) Assert(org.junit.Assert) Collections(java.util.Collections) HighAvailabilityOptions(org.apache.flink.configuration.HighAvailabilityOptions) TemporaryFolder(org.junit.rules.TemporaryFolder) Assert.assertEquals(org.junit.Assert.assertEquals) Tuple2(org.apache.flink.api.java.tuple.Tuple2) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) MapFunction(org.apache.flink.api.common.functions.MapFunction) RichMapFunction(org.apache.flink.api.common.functions.RichMapFunction)

Aggregations

IOException (java.io.IOException)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Executor (java.util.concurrent.Executor)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 StreamSupport (java.util.stream.StreamSupport)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 MapFunction (org.apache.flink.api.common.functions.MapFunction)1 RichMapFunction (org.apache.flink.api.common.functions.RichMapFunction)1 ListState (org.apache.flink.api.common.state.ListState)1 ListStateDescriptor (org.apache.flink.api.common.state.ListStateDescriptor)1 ValueState (org.apache.flink.api.common.state.ValueState)1 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)1 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)1