Search in sources :

Example 1 with ProcessBundleResponse

use of org.apache.beam.model.fnexecution.v1.BeamFnApi.ProcessBundleResponse in project beam by apache.

the class SdkHarnessClientTest method handleCleanupWhenAwaitingOnClosingOutputReceivers.

@Test
public void handleCleanupWhenAwaitingOnClosingOutputReceivers() throws Exception {
    Exception testException = new Exception();
    InboundDataClient mockOutputReceiver = mock(InboundDataClient.class);
    CloseableFnDataReceiver mockInputSender = mock(CloseableFnDataReceiver.class);
    CompletableFuture<InstructionResponse> processBundleResponseFuture = new CompletableFuture<>();
    when(fnApiControlClient.handle(any(BeamFnApi.InstructionRequest.class))).thenReturn(processBundleResponseFuture);
    FullWindowedValueCoder<String> coder = FullWindowedValueCoder.of(StringUtf8Coder.of(), Coder.INSTANCE);
    BundleProcessor processor = sdkHarnessClient.getProcessor(descriptor, Collections.singletonList(RemoteInputDestination.of((FullWindowedValueCoder) coder, SDK_GRPC_READ_TRANSFORM)));
    when(dataService.receive(any(), any(), any())).thenReturn(mockOutputReceiver);
    when(dataService.send(any(), eq(coder))).thenReturn(mockInputSender);
    doThrow(testException).when(mockOutputReceiver).awaitCompletion();
    RemoteOutputReceiver mockRemoteOutputReceiver = mock(RemoteOutputReceiver.class);
    BundleProgressHandler mockProgressHandler = mock(BundleProgressHandler.class);
    try {
        try (RemoteBundle activeBundle = processor.newBundle(ImmutableMap.of(SDK_GRPC_WRITE_TRANSFORM, mockRemoteOutputReceiver), mockProgressHandler)) {
            // Correlating the ProcessBundleRequest and ProcessBundleResponse is owned by the underlying
            // FnApiControlClient. The SdkHarnessClient owns just wrapping the request and unwrapping
            // the response.
            // 
            // Currently there are no fields so there's nothing to check. This test is formulated
            // to match the pattern it should have if/when the response is meaningful.
            BeamFnApi.ProcessBundleResponse response = BeamFnApi.ProcessBundleResponse.getDefaultInstance();
            processBundleResponseFuture.complete(BeamFnApi.InstructionResponse.newBuilder().setProcessBundle(response).build());
        }
        fail("Exception expected");
    } catch (Exception e) {
        assertEquals(testException, e);
    }
}
Also used : CloseableFnDataReceiver(org.apache.beam.sdk.fn.data.CloseableFnDataReceiver) BeamFnApi(org.apache.beam.model.fnexecution.v1.BeamFnApi) InstructionResponse(org.apache.beam.model.fnexecution.v1.BeamFnApi.InstructionResponse) ByteString(org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString) ExpectedException(org.junit.rules.ExpectedException) ExecutionException(java.util.concurrent.ExecutionException) InboundDataClient(org.apache.beam.sdk.fn.data.InboundDataClient) CompletableFuture(java.util.concurrent.CompletableFuture) ProcessBundleResponse(org.apache.beam.model.fnexecution.v1.BeamFnApi.ProcessBundleResponse) BundleProcessor(org.apache.beam.runners.fnexecution.control.SdkHarnessClient.BundleProcessor) Test(org.junit.Test)

Example 2 with ProcessBundleResponse

use of org.apache.beam.model.fnexecution.v1.BeamFnApi.ProcessBundleResponse in project beam by apache.

the class SdkHarnessClientTest method testBundleCheckpointCallback.

@Test
public void testBundleCheckpointCallback() throws Exception {
    InboundDataClient mockOutputReceiver = mock(InboundDataClient.class);
    CloseableFnDataReceiver mockInputSender = mock(CloseableFnDataReceiver.class);
    CompletableFuture<InstructionResponse> processBundleResponseFuture = new CompletableFuture<>();
    when(fnApiControlClient.handle(any(BeamFnApi.InstructionRequest.class))).thenReturn(processBundleResponseFuture);
    FullWindowedValueCoder<String> coder = FullWindowedValueCoder.of(StringUtf8Coder.of(), Coder.INSTANCE);
    BundleProcessor processor = sdkHarnessClient.getProcessor(descriptor, Collections.singletonList(RemoteInputDestination.of((FullWindowedValueCoder) coder, SDK_GRPC_READ_TRANSFORM)));
    when(dataService.receive(any(), any(), any())).thenReturn(mockOutputReceiver);
    when(dataService.send(any(), eq(coder))).thenReturn(mockInputSender);
    RemoteOutputReceiver mockRemoteOutputReceiver = mock(RemoteOutputReceiver.class);
    BundleProgressHandler mockProgressHandler = mock(BundleProgressHandler.class);
    BundleSplitHandler mockSplitHandler = mock(BundleSplitHandler.class);
    BundleCheckpointHandler mockCheckpointHandler = mock(BundleCheckpointHandler.class);
    BundleFinalizationHandler mockFinalizationHandler = mock(BundleFinalizationHandler.class);
    ProcessBundleResponse response = ProcessBundleResponse.newBuilder().addResidualRoots(DelayedBundleApplication.getDefaultInstance()).build();
    try (ActiveBundle activeBundle = processor.newBundle(ImmutableMap.of(SDK_GRPC_WRITE_TRANSFORM, mockRemoteOutputReceiver), Collections.emptyMap(), (request) -> {
        throw new UnsupportedOperationException();
    }, mockProgressHandler, mockSplitHandler, mockCheckpointHandler, mockFinalizationHandler)) {
        processBundleResponseFuture.complete(InstructionResponse.newBuilder().setProcessBundle(response).build());
    }
    verify(mockProgressHandler).onCompleted(response);
    verify(mockCheckpointHandler).onCheckpoint(response);
    verifyZeroInteractions(mockFinalizationHandler, mockSplitHandler);
}
Also used : ActiveBundle(org.apache.beam.runners.fnexecution.control.SdkHarnessClient.BundleProcessor.ActiveBundle) CloseableFnDataReceiver(org.apache.beam.sdk.fn.data.CloseableFnDataReceiver) InstructionResponse(org.apache.beam.model.fnexecution.v1.BeamFnApi.InstructionResponse) ByteString(org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString) InboundDataClient(org.apache.beam.sdk.fn.data.InboundDataClient) CompletableFuture(java.util.concurrent.CompletableFuture) BundleProcessor(org.apache.beam.runners.fnexecution.control.SdkHarnessClient.BundleProcessor) ProcessBundleResponse(org.apache.beam.model.fnexecution.v1.BeamFnApi.ProcessBundleResponse) Test(org.junit.Test)

Example 3 with ProcessBundleResponse

use of org.apache.beam.model.fnexecution.v1.BeamFnApi.ProcessBundleResponse in project beam by apache.

the class ProcessBundleHandler method embedOutboundElementsIfApplicable.

private void embedOutboundElementsIfApplicable(ProcessBundleResponse.Builder response, BundleProcessor bundleProcessor) {
    if (bundleProcessor.getOutboundAggregators().isEmpty()) {
        return;
    }
    List<Elements> collectedElements = new ArrayList<>(bundleProcessor.getOutboundAggregators().size());
    boolean hasFlushedAggregator = false;
    for (BeamFnDataOutboundAggregator aggregator : bundleProcessor.getOutboundAggregators().values()) {
        Elements elements = aggregator.sendOrCollectBufferedDataAndFinishOutboundStreams();
        if (elements == null) {
            hasFlushedAggregator = true;
        }
        collectedElements.add(elements);
    }
    if (!hasFlushedAggregator) {
        Elements.Builder elementsToEmbed = Elements.newBuilder();
        for (Elements collectedElement : collectedElements) {
            elementsToEmbed.mergeFrom(collectedElement);
        }
        response.setElements(elementsToEmbed.build());
    } else {
        // Since there was at least one flushed aggregator, we have to use the aggregators that were
        // able to successfully collect their elements to emit them and can not send them as part of
        // the ProcessBundleResponse.
        int i = 0;
        for (BeamFnDataOutboundAggregator aggregator : bundleProcessor.getOutboundAggregators().values()) {
            Elements elements = collectedElements.get(i++);
            if (elements != null) {
                aggregator.sendElements(elements);
            }
        }
    }
}
Also used : BeamFnDataOutboundAggregator(org.apache.beam.sdk.fn.data.BeamFnDataOutboundAggregator) ArrayList(java.util.ArrayList) Elements(org.apache.beam.model.fnexecution.v1.BeamFnApi.Elements) TimerEndpoint(org.apache.beam.sdk.fn.data.TimerEndpoint) DataEndpoint(org.apache.beam.sdk.fn.data.DataEndpoint)

Example 4 with ProcessBundleResponse

use of org.apache.beam.model.fnexecution.v1.BeamFnApi.ProcessBundleResponse in project beam by apache.

the class ExecutableStageDoFnOperator method open.

@Override
public void open() throws Exception {
    executableStage = ExecutableStage.fromPayload(payload);
    hasSdfProcessFn = hasSDF(executableStage);
    initializeUserState(executableStage, getKeyedStateBackend(), pipelineOptions);
    // TODO: Wire this into the distributed cache and make it pluggable.
    // TODO: Do we really want this layer of indirection when accessing the stage bundle factory?
    // It's a little strange because this operator is responsible for the lifetime of the stage
    // bundle "factory" (manager?) but not the job or Flink bundle factories. How do we make
    // ownership of the higher level "factories" explicit? Do we care?
    stageContext = contextFactory.get(jobInfo);
    stageBundleFactory = stageContext.getStageBundleFactory(executableStage);
    stateRequestHandler = getStateRequestHandler(executableStage);
    progressHandler = new BundleProgressHandler() {

        @Override
        public void onProgress(ProcessBundleProgressResponse progress) {
            if (flinkMetricContainer != null) {
                flinkMetricContainer.updateMetrics(stepName, progress.getMonitoringInfosList());
            }
        }

        @Override
        public void onCompleted(ProcessBundleResponse response) {
            if (flinkMetricContainer != null) {
                flinkMetricContainer.updateMetrics(stepName, response.getMonitoringInfosList());
            }
        }
    };
    finalizationHandler = BundleFinalizationHandlers.inMemoryFinalizer(stageBundleFactory.getInstructionRequestHandler());
    checkpointHandler = getBundleCheckpointHandler(hasSdfProcessFn);
    minEventTimeTimerTimestampInCurrentBundle = Long.MAX_VALUE;
    minEventTimeTimerTimestampInLastBundle = Long.MAX_VALUE;
    super.setPreBundleCallback(this::preBundleStartCallback);
    super.setBundleFinishedCallback(this::finishBundleCallback);
    // This will call {@code createWrappingDoFnRunner} which needs the above dependencies.
    super.open();
}
Also used : BundleProgressHandler(org.apache.beam.runners.fnexecution.control.BundleProgressHandler) ProcessBundleProgressResponse(org.apache.beam.model.fnexecution.v1.BeamFnApi.ProcessBundleProgressResponse) ProcessBundleResponse(org.apache.beam.model.fnexecution.v1.BeamFnApi.ProcessBundleResponse)

Example 5 with ProcessBundleResponse

use of org.apache.beam.model.fnexecution.v1.BeamFnApi.ProcessBundleResponse in project beam by apache.

the class RegisterAndProcessBundleOperation method start.

@Override
public void start() throws Exception {
    try (Closeable scope = context.enterStart()) {
        super.start();
        // Only register once by using the presence of the future as a signal.
        if (registerFuture == null) {
            InstructionRequest request = InstructionRequest.newBuilder().setInstructionId(idGenerator.getId()).setRegister(registerRequest).build();
            registerFuture = instructionRequestHandler.handle(request);
        }
        checkState(registerRequest.getProcessBundleDescriptorCount() == 1, "Only one bundle registration at a time currently supported.");
        InstructionRequest processBundleRequest = InstructionRequest.newBuilder().setInstructionId(getProcessBundleInstructionId()).setProcessBundle(ProcessBundleRequest.newBuilder().setProcessBundleDescriptorId(registerRequest.getProcessBundleDescriptor(0).getId())).build();
        deregisterStateHandler = beamFnStateDelegator.registerForProcessBundleInstructionId(getProcessBundleInstructionId(), this::delegateByStateKeyType);
        processBundleResponse = getRegisterResponse(registerFuture).thenCompose(registerResponse -> instructionRequestHandler.handle(processBundleRequest));
    }
}
Also used : MoreObjects(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.MoreObjects) LoggerFactory(org.slf4j.LoggerFactory) StateAppendResponse(org.apache.beam.model.fnexecution.v1.BeamFnApi.StateAppendResponse) ImmutableMap(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap) Map(java.util.Map) Iterables(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Iterables) NameContext(org.apache.beam.runners.dataflow.worker.counters.NameContext) GlobalWindow(org.apache.beam.sdk.transforms.windowing.GlobalWindow) StateClearResponse(org.apache.beam.model.fnexecution.v1.BeamFnApi.StateClearResponse) StateDelegator(org.apache.beam.runners.fnexecution.state.StateDelegator) Materializations(org.apache.beam.sdk.transforms.Materializations) IdGenerator(org.apache.beam.sdk.fn.IdGenerator) KvCoder(org.apache.beam.sdk.coders.KvCoder) OperationContext(org.apache.beam.runners.dataflow.worker.util.common.worker.OperationContext) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) BeamFnApi(org.apache.beam.model.fnexecution.v1.BeamFnApi) List(java.util.List) InstructionRequest(org.apache.beam.model.fnexecution.v1.BeamFnApi.InstructionRequest) ProcessBundleDescriptor(org.apache.beam.model.fnexecution.v1.BeamFnApi.ProcessBundleDescriptor) CompletionStage(java.util.concurrent.CompletionStage) RequestCase(org.apache.beam.model.fnexecution.v1.BeamFnApi.StateRequest.RequestCase) StateRequest(org.apache.beam.model.fnexecution.v1.BeamFnApi.StateRequest) InstructionRequestHandler(org.apache.beam.runners.fnexecution.control.InstructionRequestHandler) Entry(java.util.Map.Entry) DataflowStepContext(org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowStepContext) RegisterRequest(org.apache.beam.model.fnexecution.v1.BeamFnApi.RegisterRequest) StateKey(org.apache.beam.model.fnexecution.v1.BeamFnApi.StateKey) StateGetResponse(org.apache.beam.model.fnexecution.v1.BeamFnApi.StateGetResponse) PTransform(org.apache.beam.model.pipeline.v1.RunnerApi.PTransform) MonitoringInfoEncodings.decodeInt64Counter(org.apache.beam.runners.core.metrics.MonitoringInfoEncodings.decodeInt64Counter) ByteStringCoder(org.apache.beam.runners.dataflow.worker.ByteStringCoder) Coder(org.apache.beam.sdk.coders.Coder) CompletableFuture(java.util.concurrent.CompletableFuture) StateNamespaces(org.apache.beam.runners.core.StateNamespaces) StateTags(org.apache.beam.runners.core.StateTags) TextFormat(org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.TextFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DataflowOperationContext(org.apache.beam.runners.dataflow.worker.DataflowOperationContext) InstructionResponse(org.apache.beam.model.fnexecution.v1.BeamFnApi.InstructionResponse) Maps(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Maps) MonitoringInfoConstants(org.apache.beam.runners.core.metrics.MonitoringInfoConstants) ByteString(org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString) OutputReceiver(org.apache.beam.runners.dataflow.worker.util.common.worker.OutputReceiver) ProcessBundleProgressRequest(org.apache.beam.model.fnexecution.v1.BeamFnApi.ProcessBundleProgressRequest) RemoteGrpcPortWrite(org.apache.beam.sdk.fn.data.RemoteGrpcPortWrite) Nullable(org.checkerframework.checker.nullness.qual.Nullable) MonitoringInfo(org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo) SideInputReader(org.apache.beam.runners.core.SideInputReader) RunnerApi(org.apache.beam.model.pipeline.v1.RunnerApi) ProcessBundleRequest(org.apache.beam.model.fnexecution.v1.BeamFnApi.ProcessBundleRequest) Logger(org.slf4j.Logger) Table(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Table) IOException(java.io.IOException) RemoteGrpcPortRead(org.apache.beam.sdk.fn.data.RemoteGrpcPortRead) ExecutionException(java.util.concurrent.ExecutionException) Operation(org.apache.beam.runners.dataflow.worker.util.common.worker.Operation) BagState(org.apache.beam.sdk.state.BagState) Preconditions.checkState(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkState) PCollectionView(org.apache.beam.sdk.values.PCollectionView) Closeable(java.io.Closeable) BoundedWindow(org.apache.beam.sdk.transforms.windowing.BoundedWindow) MoreFutures(org.apache.beam.sdk.util.MoreFutures) StateResponse(org.apache.beam.model.fnexecution.v1.BeamFnApi.StateResponse) InstructionRequest(org.apache.beam.model.fnexecution.v1.BeamFnApi.InstructionRequest) Closeable(java.io.Closeable)

Aggregations

ProcessBundleResponse (org.apache.beam.model.fnexecution.v1.BeamFnApi.ProcessBundleResponse)10 ByteString (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString)8 BundleProcessor (org.apache.beam.runners.fnexecution.control.SdkHarnessClient.BundleProcessor)7 Test (org.junit.Test)7 CompletableFuture (java.util.concurrent.CompletableFuture)6 InstructionResponse (org.apache.beam.model.fnexecution.v1.BeamFnApi.InstructionResponse)6 BeamFnApi (org.apache.beam.model.fnexecution.v1.BeamFnApi)5 CloseableFnDataReceiver (org.apache.beam.sdk.fn.data.CloseableFnDataReceiver)5 ArrayList (java.util.ArrayList)4 ProcessBundleProgressResponse (org.apache.beam.model.fnexecution.v1.BeamFnApi.ProcessBundleProgressResponse)4 InboundDataClient (org.apache.beam.sdk.fn.data.InboundDataClient)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ExecutionException (java.util.concurrent.ExecutionException)3 RunnerApi (org.apache.beam.model.pipeline.v1.RunnerApi)3 Closeable (java.io.Closeable)2 HashMap (java.util.HashMap)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 ExecutableStage (org.apache.beam.runners.core.construction.graph.ExecutableStage)2 FusedPipeline (org.apache.beam.runners.core.construction.graph.FusedPipeline)2 BundleProgressHandler (org.apache.beam.runners.fnexecution.control.BundleProgressHandler)2