Package io.pravega.connectors.flink
Class FlinkPravegaReader<T>
- java.lang.Object
-
- org.apache.flink.api.common.functions.AbstractRichFunction
-
- org.apache.flink.streaming.api.functions.source.RichParallelSourceFunction<T>
-
- io.pravega.connectors.flink.FlinkPravegaReader<T>
-
- Type Parameters:
T
- The type of the event to be written.
- All Implemented Interfaces:
java.io.Serializable
,org.apache.flink.api.common.functions.Function
,org.apache.flink.api.common.functions.RichFunction
,org.apache.flink.api.common.functions.StoppableFunction
,org.apache.flink.api.java.typeutils.ResultTypeQueryable<T>
,org.apache.flink.streaming.api.checkpoint.ExternallyInducedSource<T,io.pravega.client.stream.Checkpoint>
,org.apache.flink.streaming.api.checkpoint.WithMasterCheckpointHook<io.pravega.client.stream.Checkpoint>
,org.apache.flink.streaming.api.functions.source.ParallelSourceFunction<T>
,org.apache.flink.streaming.api.functions.source.SourceFunction<T>
public class FlinkPravegaReader<T> extends org.apache.flink.streaming.api.functions.source.RichParallelSourceFunction<T> implements org.apache.flink.api.java.typeutils.ResultTypeQueryable<T>, org.apache.flink.api.common.functions.StoppableFunction, org.apache.flink.streaming.api.checkpoint.ExternallyInducedSource<T,io.pravega.client.stream.Checkpoint>
Flink source implementation for reading from pravega storage.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FlinkPravegaReader.Builder<T>
A builder forFlinkPravegaReader
.
-
Field Summary
Fields Modifier and Type Field Description protected io.pravega.client.EventStreamClientFactory
eventStreamClientFactory
protected static java.lang.String
ONLINE_READERS_METRICS_GAUGE
protected static java.lang.String
PRAVEGA_READER_METRICS_GROUP
protected static java.lang.String
READER_GROUP_METRICS_GROUP
protected static java.lang.String
READER_GROUP_NAME_METRICS_GAUGE
protected io.pravega.client.admin.ReaderGroupManager
readerGroupManager
protected static java.lang.String
SCOPE_NAME_METRICS_GAUGE
protected static java.lang.String
SEGMENT_POSITIONS_METRICS_GAUGE
protected static java.lang.String
SEPARATOR
protected static java.lang.String
STREAM_METRICS_GROUP
protected static java.lang.String
STREAM_NAMES_METRICS_GAUGE
protected static java.lang.String
UNREAD_BYTES_METRICS_GAUGE
-
Constructor Summary
Constructors Modifier Constructor Description protected
FlinkPravegaReader(java.lang.String hookUid, io.pravega.client.ClientConfig clientConfig, io.pravega.client.stream.ReaderGroupConfig readerGroupConfig, java.lang.String readerGroupScope, java.lang.String readerGroupName, org.apache.flink.api.common.serialization.DeserializationSchema<T> deserializationSchema, org.apache.flink.util.SerializedValue<AssignerWithTimeWindows<T>> assignerWithTimeWindows, org.apache.flink.api.common.time.Time eventReadTimeout, org.apache.flink.api.common.time.Time checkpointInitiateTimeout, boolean enableMetrics)
Creates a new Flink Pravega reader instance which can be added as a source to a Flink job.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> FlinkPravegaReader.Builder<T>
builder()
Gets a builder forFlinkPravegaReader
to read Pravega streams using the Flink streaming API.void
cancel()
void
close()
protected io.pravega.client.EventStreamClientFactory
createEventStreamClientFactory()
Create theEventStreamClientFactory
for the current configuration.protected io.pravega.client.stream.EventStreamReader<T>
createEventStreamReader(java.lang.String readerId)
Create theEventStreamReader
for the current configuration.org.apache.flink.runtime.checkpoint.MasterTriggerRestoreHook<io.pravega.client.stream.Checkpoint>
createMasterTriggerRestoreHook()
protected io.pravega.client.admin.ReaderGroupManager
createReaderGroupManager()
Create theReaderGroupManager
for the current configuration.org.apache.flink.api.common.typeinfo.TypeInformation<T>
getProducedType()
void
open(org.apache.flink.configuration.Configuration parameters)
void
run(org.apache.flink.streaming.api.functions.source.SourceFunction.SourceContext<T> ctx)
void
setCheckpointTrigger(org.apache.flink.streaming.api.checkpoint.ExternallyInducedSource.CheckpointTrigger checkpointTrigger)
void
stop()
-
-
-
Field Detail
-
PRAVEGA_READER_METRICS_GROUP
protected static final java.lang.String PRAVEGA_READER_METRICS_GROUP
- See Also:
- Constant Field Values
-
READER_GROUP_METRICS_GROUP
protected static final java.lang.String READER_GROUP_METRICS_GROUP
- See Also:
- Constant Field Values
-
STREAM_METRICS_GROUP
protected static final java.lang.String STREAM_METRICS_GROUP
- See Also:
- Constant Field Values
-
UNREAD_BYTES_METRICS_GAUGE
protected static final java.lang.String UNREAD_BYTES_METRICS_GAUGE
- See Also:
- Constant Field Values
-
READER_GROUP_NAME_METRICS_GAUGE
protected static final java.lang.String READER_GROUP_NAME_METRICS_GAUGE
- See Also:
- Constant Field Values
-
SCOPE_NAME_METRICS_GAUGE
protected static final java.lang.String SCOPE_NAME_METRICS_GAUGE
- See Also:
- Constant Field Values
-
ONLINE_READERS_METRICS_GAUGE
protected static final java.lang.String ONLINE_READERS_METRICS_GAUGE
- See Also:
- Constant Field Values
-
STREAM_NAMES_METRICS_GAUGE
protected static final java.lang.String STREAM_NAMES_METRICS_GAUGE
- See Also:
- Constant Field Values
-
SEGMENT_POSITIONS_METRICS_GAUGE
protected static final java.lang.String SEGMENT_POSITIONS_METRICS_GAUGE
- See Also:
- Constant Field Values
-
SEPARATOR
protected static final java.lang.String SEPARATOR
- See Also:
- Constant Field Values
-
eventStreamClientFactory
protected transient io.pravega.client.EventStreamClientFactory eventStreamClientFactory
-
readerGroupManager
protected transient io.pravega.client.admin.ReaderGroupManager readerGroupManager
-
-
Constructor Detail
-
FlinkPravegaReader
protected FlinkPravegaReader(java.lang.String hookUid, io.pravega.client.ClientConfig clientConfig, io.pravega.client.stream.ReaderGroupConfig readerGroupConfig, java.lang.String readerGroupScope, java.lang.String readerGroupName, org.apache.flink.api.common.serialization.DeserializationSchema<T> deserializationSchema, org.apache.flink.util.SerializedValue<AssignerWithTimeWindows<T>> assignerWithTimeWindows, org.apache.flink.api.common.time.Time eventReadTimeout, org.apache.flink.api.common.time.Time checkpointInitiateTimeout, boolean enableMetrics)
Creates a new Flink Pravega reader instance which can be added as a source to a Flink job.The reader will use the given
readerName
to store its state (its positions in the stream segments) in Flink's checkpoints/savepoints. This name is used in a similar way as the operator UIDs (SingleOutputStreamOperator.uid(String)
) to identify state when matching it into another job that resumes from this job's checkpoints/savepoints.Without specifying a
readerName
, the job will correctly checkpoint and recover, but new instances of the job can typically not resume this reader's state (positions).- Parameters:
hookUid
- The UID of the source hook in the job graph.clientConfig
- The Pravega client configuration.readerGroupConfig
- The Pravega reader group configuration.readerGroupScope
- The reader group scope name.readerGroupName
- The reader group name.deserializationSchema
- The implementation to deserialize events from Pravega streams.assignerWithTimeWindows
- The serialized value of the implementation to extract timestamp from deserialized events (only in event-time mode).eventReadTimeout
- The event read timeout.checkpointInitiateTimeout
- The checkpoint initiation timeout.enableMetrics
- Flag to indicate whether metrics needs to be enabled or not.
-
-
Method Detail
-
run
public void run(org.apache.flink.streaming.api.functions.source.SourceFunction.SourceContext<T> ctx) throws java.lang.Exception
- Specified by:
run
in interfaceorg.apache.flink.streaming.api.functions.source.SourceFunction<T>
- Throws:
java.lang.Exception
-
cancel
public void cancel()
- Specified by:
cancel
in interfaceorg.apache.flink.streaming.api.functions.source.SourceFunction<T>
-
stop
public void stop()
- Specified by:
stop
in interfaceorg.apache.flink.api.common.functions.StoppableFunction
-
getProducedType
public org.apache.flink.api.common.typeinfo.TypeInformation<T> getProducedType()
- Specified by:
getProducedType
in interfaceorg.apache.flink.api.java.typeutils.ResultTypeQueryable<T>
-
open
public void open(org.apache.flink.configuration.Configuration parameters) throws java.lang.Exception
- Specified by:
open
in interfaceorg.apache.flink.api.common.functions.RichFunction
- Overrides:
open
in classorg.apache.flink.api.common.functions.AbstractRichFunction
- Throws:
java.lang.Exception
-
close
public void close() throws java.lang.Exception
- Specified by:
close
in interfaceorg.apache.flink.api.common.functions.RichFunction
- Overrides:
close
in classorg.apache.flink.api.common.functions.AbstractRichFunction
- Throws:
java.lang.Exception
-
createMasterTriggerRestoreHook
public org.apache.flink.runtime.checkpoint.MasterTriggerRestoreHook<io.pravega.client.stream.Checkpoint> createMasterTriggerRestoreHook()
- Specified by:
createMasterTriggerRestoreHook
in interfaceorg.apache.flink.streaming.api.checkpoint.WithMasterCheckpointHook<T>
-
setCheckpointTrigger
public void setCheckpointTrigger(org.apache.flink.streaming.api.checkpoint.ExternallyInducedSource.CheckpointTrigger checkpointTrigger)
- Specified by:
setCheckpointTrigger
in interfaceorg.apache.flink.streaming.api.checkpoint.ExternallyInducedSource<T,io.pravega.client.stream.Checkpoint>
-
createReaderGroupManager
protected io.pravega.client.admin.ReaderGroupManager createReaderGroupManager()
Create theReaderGroupManager
for the current configuration.
-
createEventStreamClientFactory
protected io.pravega.client.EventStreamClientFactory createEventStreamClientFactory()
Create theEventStreamClientFactory
for the current configuration.
-
createEventStreamReader
protected io.pravega.client.stream.EventStreamReader<T> createEventStreamReader(java.lang.String readerId)
Create theEventStreamReader
for the current configuration.- Parameters:
readerId
- the readerID to use.
-
builder
public static <T> FlinkPravegaReader.Builder<T> builder()
Gets a builder forFlinkPravegaReader
to read Pravega streams using the Flink streaming API.- Type Parameters:
T
- the element type.
-
-