Search in sources :

Example 6 with BeamFnDataOutboundAggregator

use of org.apache.beam.sdk.fn.data.BeamFnDataOutboundAggregator in project beam by apache.

the class PTransformRunnerFactoryTestContext method addOutgoingDataEndpoint.

@Override
public <T> FnDataReceiver<T> addOutgoingDataEndpoint(ApiServiceDescriptor apiServiceDescriptor, Coder<T> coder) {
    BeamFnDataOutboundAggregator aggregator = getOutboundAggregators().get(apiServiceDescriptor);
    FnDataReceiver<T> receiver = aggregator.registerOutputDataLocation(getPTransformId(), coder);
    getOutgoingDataEndpoints().computeIfAbsent(apiServiceDescriptor, (unused) -> new ArrayList<>()).add(DataEndpoint.create(getPTransformId(), coder, receiver));
    return receiver;
}
Also used : BeamFnDataOutboundAggregator(org.apache.beam.sdk.fn.data.BeamFnDataOutboundAggregator) BeamFnDataOutboundAggregator(org.apache.beam.sdk.fn.data.BeamFnDataOutboundAggregator) Elements(org.apache.beam.model.fnexecution.v1.BeamFnApi.Elements) WindowedValue(org.apache.beam.sdk.util.WindowedValue) BeamFnStateClient(org.apache.beam.fn.harness.state.BeamFnStateClient) BundleFinalizer(org.apache.beam.sdk.transforms.DoFn.BundleFinalizer) Coder(org.apache.beam.sdk.coders.Coder) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) PipelineOptionsFactory(org.apache.beam.sdk.options.PipelineOptionsFactory) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Map(java.util.Map) DelayedBundleApplication(org.apache.beam.model.fnexecution.v1.BeamFnApi.DelayedBundleApplication) BeamFnDataClient(org.apache.beam.fn.harness.data.BeamFnDataClient) BundleApplication(org.apache.beam.model.fnexecution.v1.BeamFnApi.BundleApplication) NoSuchElementException(java.util.NoSuchElementException) MetricsApi(org.apache.beam.model.pipeline.v1.MetricsApi) ApiServiceDescriptor(org.apache.beam.model.pipeline.v1.Endpoints.ApiServiceDescriptor) PipelineOptions(org.apache.beam.sdk.options.PipelineOptions) RunnerApi(org.apache.beam.model.pipeline.v1.RunnerApi) DoFn(org.apache.beam.sdk.transforms.DoFn) CloseableFnDataReceiver(org.apache.beam.sdk.fn.data.CloseableFnDataReceiver) TimerEndpoint(org.apache.beam.sdk.fn.data.TimerEndpoint) FnDataReceiver(org.apache.beam.sdk.fn.data.FnDataReceiver) Set(java.util.Set) BundleSplitListener(org.apache.beam.fn.harness.control.BundleSplitListener) BeamFnApi(org.apache.beam.model.fnexecution.v1.BeamFnApi) ProgressRequestCallback(org.apache.beam.fn.harness.PTransformRunnerFactory.ProgressRequestCallback) DataEndpoint(org.apache.beam.sdk.fn.data.DataEndpoint) List(java.util.List) StateRequest(org.apache.beam.model.fnexecution.v1.BeamFnApi.StateRequest) Timer(org.apache.beam.runners.core.construction.Timer) Instant(org.joda.time.Instant) AutoValue(com.google.auto.value.AutoValue) Collections(java.util.Collections) StateResponse(org.apache.beam.model.fnexecution.v1.BeamFnApi.StateResponse) ThrowingRunnable(org.apache.beam.sdk.function.ThrowingRunnable) ArrayList(java.util.ArrayList)

Example 7 with BeamFnDataOutboundAggregator

use of org.apache.beam.sdk.fn.data.BeamFnDataOutboundAggregator in project beam by apache.

the class BeamFnDataGrpcClientTest method testForOutboundConsumer.

@Test
public void testForOutboundConsumer() throws Exception {
    CountDownLatch waitForInboundServerValuesCompletion = new CountDownLatch(2);
    Collection<BeamFnApi.Elements> inboundServerValues = new ConcurrentLinkedQueue<>();
    CallStreamObserver<BeamFnApi.Elements> inboundServerObserver = TestStreams.withOnNext((BeamFnApi.Elements t) -> {
        inboundServerValues.add(t);
        waitForInboundServerValuesCompletion.countDown();
    }).build();
    Endpoints.ApiServiceDescriptor apiServiceDescriptor = Endpoints.ApiServiceDescriptor.newBuilder().setUrl(this.getClass().getName() + "-" + UUID.randomUUID()).build();
    Server server = InProcessServerBuilder.forName(apiServiceDescriptor.getUrl()).addService(new BeamFnDataGrpc.BeamFnDataImplBase() {

        @Override
        public StreamObserver<BeamFnApi.Elements> data(StreamObserver<BeamFnApi.Elements> outboundObserver) {
            return inboundServerObserver;
        }
    }).build();
    server.start();
    try {
        ManagedChannel channel = InProcessChannelBuilder.forName(apiServiceDescriptor.getUrl()).build();
        BeamFnDataGrpcClient clientFactory = new BeamFnDataGrpcClient(PipelineOptionsFactory.fromArgs(new String[] { "--experiments=data_buffer_size_limit=20" }).create(), (Endpoints.ApiServiceDescriptor descriptor) -> channel, OutboundObserverFactory.trivial());
        BeamFnDataOutboundAggregator aggregator = clientFactory.createOutboundAggregator(apiServiceDescriptor, () -> INSTRUCTION_ID_A, false);
        FnDataReceiver<WindowedValue<String>> fnDataReceiver = aggregator.registerOutputDataLocation(TRANSFORM_ID_A, CODER);
        fnDataReceiver.accept(valueInGlobalWindow("ABC"));
        fnDataReceiver.accept(valueInGlobalWindow("DEF"));
        fnDataReceiver.accept(valueInGlobalWindow("GHI"));
        aggregator.sendOrCollectBufferedDataAndFinishOutboundStreams();
        waitForInboundServerValuesCompletion.await();
        assertThat(inboundServerValues, contains(ELEMENTS_A_1, ELEMENTS_A_2));
    } finally {
        server.shutdownNow();
    }
}
Also used : CallStreamObserver(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.CallStreamObserver) StreamObserver(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver) BeamFnDataOutboundAggregator(org.apache.beam.sdk.fn.data.BeamFnDataOutboundAggregator) Server(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server) BeamFnApi(org.apache.beam.model.fnexecution.v1.BeamFnApi) CountDownLatch(java.util.concurrent.CountDownLatch) Endpoints(org.apache.beam.model.pipeline.v1.Endpoints) WindowedValue(org.apache.beam.sdk.util.WindowedValue) ManagedChannel(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Test(org.junit.Test)

Aggregations

BeamFnDataOutboundAggregator (org.apache.beam.sdk.fn.data.BeamFnDataOutboundAggregator)7 ArrayList (java.util.ArrayList)4 Elements (org.apache.beam.model.fnexecution.v1.BeamFnApi.Elements)4 BeamFnApi (org.apache.beam.model.fnexecution.v1.BeamFnApi)3 ApiServiceDescriptor (org.apache.beam.model.pipeline.v1.Endpoints.ApiServiceDescriptor)3 RunnerApi (org.apache.beam.model.pipeline.v1.RunnerApi)3 Timer (org.apache.beam.runners.core.construction.Timer)3 DataEndpoint (org.apache.beam.sdk.fn.data.DataEndpoint)3 TimerEndpoint (org.apache.beam.sdk.fn.data.TimerEndpoint)3 WindowedValue (org.apache.beam.sdk.util.WindowedValue)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Supplier (java.util.function.Supplier)2