Search in sources :

Example 1 with OperatorEvent

use of org.apache.flink.runtime.operators.coordination.OperatorEvent in project flink by apache.

the class SourceOperatorTest method testOpen.

@Test
public void testOpen() throws Exception {
    // Initialize the operator.
    operator.initializeState(context.createStateContext());
    // Open the operator.
    operator.open();
    // The source reader should have been assigned a split.
    assertEquals(Collections.singletonList(SourceOperatorTestContext.MOCK_SPLIT), mockSourceReader.getAssignedSplits());
    // The source reader should have started.
    assertTrue(mockSourceReader.isStarted());
    // A ReaderRegistrationRequest should have been sent.
    assertEquals(1, mockGateway.getEventsSent().size());
    OperatorEvent operatorEvent = mockGateway.getEventsSent().get(0);
    assertTrue(operatorEvent instanceof ReaderRegistrationEvent);
    assertEquals(SourceOperatorTestContext.SUBTASK_INDEX, ((ReaderRegistrationEvent) operatorEvent).subtaskId());
}
Also used : ReaderRegistrationEvent(org.apache.flink.runtime.source.event.ReaderRegistrationEvent) OperatorEvent(org.apache.flink.runtime.operators.coordination.OperatorEvent) Test(org.junit.Test)

Example 2 with OperatorEvent

use of org.apache.flink.runtime.operators.coordination.OperatorEvent in project flink by apache.

the class OperatorEventDispatcherImpl method dispatchEventToHandlers.

void dispatchEventToHandlers(OperatorID operatorID, SerializedValue<OperatorEvent> serializedEvent) throws FlinkException {
    final OperatorEvent evt;
    try {
        evt = serializedEvent.deserializeValue(classLoader);
    } catch (IOException | ClassNotFoundException e) {
        throw new FlinkException("Could not deserialize operator event", e);
    }
    final OperatorEventHandler handler = handlers.get(operatorID);
    if (handler != null) {
        handler.handleOperatorEvent(evt);
    } else {
        throw new FlinkException("Operator not registered for operator events");
    }
}
Also used : OperatorEventHandler(org.apache.flink.runtime.operators.coordination.OperatorEventHandler) OperatorEvent(org.apache.flink.runtime.operators.coordination.OperatorEvent) IOException(java.io.IOException) FlinkException(org.apache.flink.util.FlinkException)

Example 3 with OperatorEvent

use of org.apache.flink.runtime.operators.coordination.OperatorEvent in project flink by apache.

the class JobMaster method sendOperatorEventToCoordinator.

@Override
public CompletableFuture<Acknowledge> sendOperatorEventToCoordinator(final ExecutionAttemptID task, final OperatorID operatorID, final SerializedValue<OperatorEvent> serializedEvent) {
    try {
        final OperatorEvent evt = serializedEvent.deserializeValue(userCodeLoader);
        schedulerNG.deliverOperatorEventToCoordinator(task, operatorID, evt);
        return CompletableFuture.completedFuture(Acknowledge.get());
    } catch (Exception e) {
        return FutureUtils.completedExceptionally(e);
    }
}
Also used : OperatorEvent(org.apache.flink.runtime.operators.coordination.OperatorEvent) TimeoutException(java.util.concurrent.TimeoutException) CompletionException(java.util.concurrent.CompletionException) FlinkJobNotFoundException(org.apache.flink.runtime.messages.FlinkJobNotFoundException) FlinkException(org.apache.flink.util.FlinkException) PartitionProducerDisposedException(org.apache.flink.runtime.jobmanager.PartitionProducerDisposedException) IOException(java.io.IOException)

Example 4 with OperatorEvent

use of org.apache.flink.runtime.operators.coordination.OperatorEvent in project flink by apache.

the class SourceCoordinatorContextTest method testAssignSplits.

@SuppressWarnings("unchecked")
private void testAssignSplits(boolean fromCoordinatorExecutor) throws Exception {
    sourceReady();
    registerReaders();
    // Assign splits to the readers.
    SplitsAssignment<MockSourceSplit> splitsAssignment = getSplitsAssignment(2, 0);
    if (fromCoordinatorExecutor) {
        coordinatorExecutor.submit(() -> context.assignSplits(splitsAssignment)).get();
    } else {
        context.assignSplits(splitsAssignment);
    }
    // The tracker should have recorded the assignments.
    verifyAssignment(Collections.singletonList("0"), splitSplitAssignmentTracker.uncheckpointedAssignments().get(0));
    verifyAssignment(Arrays.asList("1", "2"), splitSplitAssignmentTracker.uncheckpointedAssignments().get(1));
    // The OperatorCoordinatorContext should have received the event sending call.
    assertEquals("There should be two events sent to the subtasks.", 2, receivingTasks.getNumberOfSentEvents());
    // Assert the events to subtask0.
    List<OperatorEvent> eventsToSubtask0 = receivingTasks.getSentEventsForSubtask(0);
    assertEquals(1, eventsToSubtask0.size());
    OperatorEvent event = eventsToSubtask0.get(0);
    assertTrue(event instanceof AddSplitEvent);
    verifyAssignment(Collections.singletonList("0"), ((AddSplitEvent<MockSourceSplit>) event).splits(new MockSourceSplitSerializer()));
}
Also used : AddSplitEvent(org.apache.flink.runtime.source.event.AddSplitEvent) OperatorEvent(org.apache.flink.runtime.operators.coordination.OperatorEvent) MockSourceSplitSerializer(org.apache.flink.api.connector.source.mocks.MockSourceSplitSerializer) MockSourceSplit(org.apache.flink.api.connector.source.mocks.MockSourceSplit)

Example 5 with OperatorEvent

use of org.apache.flink.runtime.operators.coordination.OperatorEvent in project flink by apache.

the class SourceCoordinatorAlignmentTest method assertLatestWatermarkAlignmentEvent.

private void assertLatestWatermarkAlignmentEvent(int subtask, long expectedWatermark) {
    List<OperatorEvent> events = receivingTasks.getSentEventsForSubtask(subtask);
    assertFalse(events.isEmpty());
    assertEquals(new WatermarkAlignmentEvent(expectedWatermark), events.get(events.size() - 1));
}
Also used : OperatorEvent(org.apache.flink.runtime.operators.coordination.OperatorEvent) WatermarkAlignmentEvent(org.apache.flink.runtime.source.event.WatermarkAlignmentEvent)

Aggregations

OperatorEvent (org.apache.flink.runtime.operators.coordination.OperatorEvent)6 IOException (java.io.IOException)2 MockSourceSplit (org.apache.flink.api.connector.source.mocks.MockSourceSplit)2 MockSourceSplitSerializer (org.apache.flink.api.connector.source.mocks.MockSourceSplitSerializer)2 AddSplitEvent (org.apache.flink.runtime.source.event.AddSplitEvent)2 WatermarkAlignmentEvent (org.apache.flink.runtime.source.event.WatermarkAlignmentEvent)2 FlinkException (org.apache.flink.util.FlinkException)2 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionException (java.util.concurrent.CompletionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 Watermark (org.apache.flink.api.common.eventtime.Watermark)1 WatermarkGenerator (org.apache.flink.api.common.eventtime.WatermarkGenerator)1 WatermarkOutput (org.apache.flink.api.common.eventtime.WatermarkOutput)1 WatermarkStrategy (org.apache.flink.api.common.eventtime.WatermarkStrategy)1