Search in sources :

Example 1 with ThrowingFunction

use of org.apache.beam.fn.harness.fn.ThrowingFunction in project beam by apache.

the class FnHarness method main.

public static void main(PipelineOptions options, BeamFnApi.ApiServiceDescriptor loggingApiServiceDescriptor, BeamFnApi.ApiServiceDescriptor controlApiServiceDescriptor) throws Exception {
    ManagedChannelFactory channelFactory = ManagedChannelFactory.from(options);
    StreamObserverFactory streamObserverFactory = StreamObserverFactory.fromOptions(options);
    PrintStream originalErrStream = System.err;
    try (BeamFnLoggingClient logging = new BeamFnLoggingClient(options, loggingApiServiceDescriptor, channelFactory::forDescriptor, streamObserverFactory::from)) {
        LOG.info("Fn Harness started");
        EnumMap<BeamFnApi.InstructionRequest.RequestCase, ThrowingFunction<BeamFnApi.InstructionRequest, BeamFnApi.InstructionResponse.Builder>> handlers = new EnumMap<>(BeamFnApi.InstructionRequest.RequestCase.class);
        RegisterHandler fnApiRegistry = new RegisterHandler();
        BeamFnDataGrpcClient beamFnDataMultiplexer = new BeamFnDataGrpcClient(options, channelFactory::forDescriptor, streamObserverFactory::from);
        ProcessBundleHandler processBundleHandler = new ProcessBundleHandler(options, fnApiRegistry::getById, beamFnDataMultiplexer);
        handlers.put(BeamFnApi.InstructionRequest.RequestCase.REGISTER, fnApiRegistry::register);
        handlers.put(BeamFnApi.InstructionRequest.RequestCase.PROCESS_BUNDLE, processBundleHandler::processBundle);
        BeamFnControlClient control = new BeamFnControlClient(controlApiServiceDescriptor, channelFactory::forDescriptor, streamObserverFactory::from, handlers);
        LOG.info("Entering instruction processing loop");
        control.processInstructionRequests(options.as(GcsOptions.class).getExecutorService());
    } catch (Throwable t) {
        t.printStackTrace(originalErrStream);
    } finally {
        originalErrStream.println("Shutting SDK harness down.");
    }
}
Also used : BeamFnControlClient(org.apache.beam.fn.harness.control.BeamFnControlClient) PrintStream(java.io.PrintStream) ThrowingFunction(org.apache.beam.fn.harness.fn.ThrowingFunction) BeamFnDataGrpcClient(org.apache.beam.fn.harness.data.BeamFnDataGrpcClient) BeamFnApi(org.apache.beam.fn.v1.BeamFnApi) StreamObserverFactory(org.apache.beam.fn.harness.stream.StreamObserverFactory) RegisterHandler(org.apache.beam.fn.harness.control.RegisterHandler) ProcessBundleHandler(org.apache.beam.fn.harness.control.ProcessBundleHandler) ManagedChannelFactory(org.apache.beam.fn.harness.channel.ManagedChannelFactory) BeamFnLoggingClient(org.apache.beam.fn.harness.logging.BeamFnLoggingClient) EnumMap(java.util.EnumMap)

Aggregations

PrintStream (java.io.PrintStream)1 EnumMap (java.util.EnumMap)1 ManagedChannelFactory (org.apache.beam.fn.harness.channel.ManagedChannelFactory)1 BeamFnControlClient (org.apache.beam.fn.harness.control.BeamFnControlClient)1 ProcessBundleHandler (org.apache.beam.fn.harness.control.ProcessBundleHandler)1 RegisterHandler (org.apache.beam.fn.harness.control.RegisterHandler)1 BeamFnDataGrpcClient (org.apache.beam.fn.harness.data.BeamFnDataGrpcClient)1 ThrowingFunction (org.apache.beam.fn.harness.fn.ThrowingFunction)1 BeamFnLoggingClient (org.apache.beam.fn.harness.logging.BeamFnLoggingClient)1 StreamObserverFactory (org.apache.beam.fn.harness.stream.StreamObserverFactory)1 BeamFnApi (org.apache.beam.fn.v1.BeamFnApi)1