Search in sources :

Example 1 with StoppableStreamSource

use of org.apache.flink.streaming.api.operators.StoppableStreamSource in project flink by apache.

the class StreamGraph method addOperator.

public <IN, OUT> void addOperator(Integer vertexID, String slotSharingGroup, StreamOperator<OUT> operatorObject, TypeInformation<IN> inTypeInfo, TypeInformation<OUT> outTypeInfo, String operatorName) {
    if (operatorObject instanceof StoppableStreamSource) {
        addNode(vertexID, slotSharingGroup, StoppableSourceStreamTask.class, operatorObject, operatorName);
    } else if (operatorObject instanceof StreamSource) {
        addNode(vertexID, slotSharingGroup, SourceStreamTask.class, operatorObject, operatorName);
    } else {
        addNode(vertexID, slotSharingGroup, OneInputStreamTask.class, operatorObject, operatorName);
    }
    TypeSerializer<IN> inSerializer = inTypeInfo != null && !(inTypeInfo instanceof MissingTypeInfo) ? inTypeInfo.createSerializer(executionConfig) : null;
    TypeSerializer<OUT> outSerializer = outTypeInfo != null && !(outTypeInfo instanceof MissingTypeInfo) ? outTypeInfo.createSerializer(executionConfig) : null;
    setSerializers(vertexID, inSerializer, null, outSerializer);
    if (operatorObject instanceof OutputTypeConfigurable && outTypeInfo != null) {
        @SuppressWarnings("unchecked") OutputTypeConfigurable<OUT> outputTypeConfigurable = (OutputTypeConfigurable<OUT>) operatorObject;
        // sets the output type which must be know at StreamGraph creation time
        outputTypeConfigurable.setOutputType(outTypeInfo, executionConfig);
    }
    if (operatorObject instanceof InputTypeConfigurable) {
        InputTypeConfigurable inputTypeConfigurable = (InputTypeConfigurable) operatorObject;
        inputTypeConfigurable.setInputType(inTypeInfo, executionConfig);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Vertex: {}", vertexID);
    }
}
Also used : MissingTypeInfo(org.apache.flink.api.java.typeutils.MissingTypeInfo) OutputTypeConfigurable(org.apache.flink.streaming.api.operators.OutputTypeConfigurable) OneInputStreamTask(org.apache.flink.streaming.runtime.tasks.OneInputStreamTask) StoppableStreamSource(org.apache.flink.streaming.api.operators.StoppableStreamSource) StreamSource(org.apache.flink.streaming.api.operators.StreamSource) InputTypeConfigurable(org.apache.flink.api.java.typeutils.InputTypeConfigurable) StoppableSourceStreamTask(org.apache.flink.streaming.runtime.tasks.StoppableSourceStreamTask) SourceStreamTask(org.apache.flink.streaming.runtime.tasks.SourceStreamTask) StoppableStreamSource(org.apache.flink.streaming.api.operators.StoppableStreamSource)

Example 2 with StoppableStreamSource

use of org.apache.flink.streaming.api.operators.StoppableStreamSource in project flink by apache.

the class StreamSourceOperatorTest method testAutomaticWatermarkContext.

@Test
public void testAutomaticWatermarkContext() throws Exception {
    // regular stream source operator
    final StoppableStreamSource<String, InfiniteSource<String>> operator = new StoppableStreamSource<>(new InfiniteSource<String>());
    long watermarkInterval = 10;
    TestProcessingTimeService processingTimeService = new TestProcessingTimeService();
    processingTimeService.setCurrentTime(0);
    setupSourceOperator(operator, TimeCharacteristic.IngestionTime, watermarkInterval, 0, processingTimeService);
    final List<StreamElement> output = new ArrayList<>();
    StreamSourceContexts.getSourceContext(TimeCharacteristic.IngestionTime, operator.getContainingTask().getProcessingTimeService(), operator.getContainingTask().getCheckpointLock(), operator.getContainingTask().getStreamStatusMaintainer(), new CollectorOutput<String>(output), operator.getExecutionConfig().getAutoWatermarkInterval(), -1);
    for (long i = 1; i < 100; i += watermarkInterval) {
        processingTimeService.setCurrentTime(i);
    }
    assertTrue(output.size() == 9);
    long nextWatermark = 0;
    for (StreamElement el : output) {
        nextWatermark += watermarkInterval;
        Watermark wm = (Watermark) el;
        assertTrue(wm.getTimestamp() == nextWatermark);
    }
}
Also used : StoppableStreamSource(org.apache.flink.streaming.api.operators.StoppableStreamSource) ArrayList(java.util.ArrayList) TestProcessingTimeService(org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService) StreamElement(org.apache.flink.streaming.runtime.streamrecord.StreamElement) Watermark(org.apache.flink.streaming.api.watermark.Watermark) Test(org.junit.Test)

Aggregations

StoppableStreamSource (org.apache.flink.streaming.api.operators.StoppableStreamSource)2 ArrayList (java.util.ArrayList)1 InputTypeConfigurable (org.apache.flink.api.java.typeutils.InputTypeConfigurable)1 MissingTypeInfo (org.apache.flink.api.java.typeutils.MissingTypeInfo)1 OutputTypeConfigurable (org.apache.flink.streaming.api.operators.OutputTypeConfigurable)1 StreamSource (org.apache.flink.streaming.api.operators.StreamSource)1 Watermark (org.apache.flink.streaming.api.watermark.Watermark)1 StreamElement (org.apache.flink.streaming.runtime.streamrecord.StreamElement)1 OneInputStreamTask (org.apache.flink.streaming.runtime.tasks.OneInputStreamTask)1 SourceStreamTask (org.apache.flink.streaming.runtime.tasks.SourceStreamTask)1 StoppableSourceStreamTask (org.apache.flink.streaming.runtime.tasks.StoppableSourceStreamTask)1 TestProcessingTimeService (org.apache.flink.streaming.runtime.tasks.TestProcessingTimeService)1 Test (org.junit.Test)1