Search in sources :

Example 1 with InProcessServerFactory

use of org.apache.beam.sdk.fn.server.InProcessServerFactory in project beam by apache.

the class EmbeddedSdkHarness method before.

@Override
protected void before() throws Exception {
    InProcessServerFactory serverFactory = InProcessServerFactory.create();
    executor = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).build());
    ControlClientPool clientPool = MapControlClientPool.create();
    FnApiControlClientPoolService clientPoolService = FnApiControlClientPoolService.offeringClientsToPool(clientPool.getSink(), GrpcContextHeaderAccessorProvider.getHeaderAccessor());
    loggingServer = GrpcFnServer.allocatePortAndCreateFor(GrpcLoggingService.forWriter(Slf4jLogWriter.getDefault()), serverFactory);
    dataServer = GrpcFnServer.allocatePortAndCreateFor(GrpcDataService.create(PipelineOptionsFactory.create(), executor, OutboundObserverFactory.serverDirect()), serverFactory);
    controlServer = GrpcFnServer.allocatePortAndCreateFor(clientPoolService, serverFactory);
    InstructionRequestHandler requestHandler = EmbeddedEnvironmentFactory.create(PipelineOptionsFactory.create(), loggingServer, controlServer, clientPool.getSource()).createEnvironment(Environment.getDefaultInstance(), "embedded_worker").getInstructionRequestHandler();
    client = SdkHarnessClient.usingFnApiClient(requestHandler, dataServer.getService());
}
Also used : FnApiControlClientPoolService(org.apache.beam.runners.fnexecution.control.FnApiControlClientPoolService) InProcessServerFactory(org.apache.beam.sdk.fn.server.InProcessServerFactory) MapControlClientPool(org.apache.beam.runners.fnexecution.control.MapControlClientPool) ControlClientPool(org.apache.beam.runners.fnexecution.control.ControlClientPool) ThreadFactoryBuilder(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ThreadFactoryBuilder) InstructionRequestHandler(org.apache.beam.runners.fnexecution.control.InstructionRequestHandler)

Example 2 with InProcessServerFactory

use of org.apache.beam.sdk.fn.server.InProcessServerFactory in project beam by apache.

the class RemoteExecutionTest method launchSdkHarness.

public void launchSdkHarness(PipelineOptions options) throws Exception {
    // Setup execution-time servers
    ThreadFactory threadFactory = new ThreadFactoryBuilder().setDaemon(true).build();
    serverExecutor = Executors.newCachedThreadPool(threadFactory);
    InProcessServerFactory serverFactory = InProcessServerFactory.create();
    dataServer = GrpcFnServer.allocatePortAndCreateFor(GrpcDataService.create(PipelineOptionsFactory.create(), serverExecutor, OutboundObserverFactory.serverDirect()), serverFactory);
    loggingServer = GrpcFnServer.allocatePortAndCreateFor(GrpcLoggingService.forWriter(Slf4jLogWriter.getDefault()), serverFactory);
    stateDelegator = GrpcStateService.create();
    stateServer = GrpcFnServer.allocatePortAndCreateFor(stateDelegator, serverFactory);
    ControlClientPool clientPool = MapControlClientPool.create();
    controlServer = GrpcFnServer.allocatePortAndCreateFor(FnApiControlClientPoolService.offeringClientsToPool(clientPool.getSink(), GrpcContextHeaderAccessorProvider.getHeaderAccessor()), serverFactory);
    // Create the SDK harness, and wait until it connects
    sdkHarnessExecutor = Executors.newSingleThreadExecutor(threadFactory);
    sdkHarnessExecutorFuture = sdkHarnessExecutor.submit(() -> {
        try {
            FnHarness.main(WORKER_ID, options, // Runner capabilities.
            Collections.emptySet(), loggingServer.getApiServiceDescriptor(), controlServer.getApiServiceDescriptor(), null, ManagedChannelFactory.createInProcess(), OutboundObserverFactory.clientDirect(), Caches.eternal());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
    InstructionRequestHandler controlClient = clientPool.getSource().take(WORKER_ID, java.time.Duration.ofSeconds(2));
    this.controlClient = SdkHarnessClient.usingFnApiClient(controlClient, dataServer.getService());
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) InProcessServerFactory(org.apache.beam.sdk.fn.server.InProcessServerFactory) ThreadFactoryBuilder(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ThreadFactoryBuilder) CoderException(org.apache.beam.sdk.coders.CoderException) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with InProcessServerFactory

use of org.apache.beam.sdk.fn.server.InProcessServerFactory in project beam by apache.

the class SingleEnvironmentInstanceJobBundleFactoryTest method setup.

@Before
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    when(instructionRequestHandler.handle(any(InstructionRequest.class))).thenReturn(CompletableFuture.completedFuture(InstructionResponse.getDefaultInstance()));
    InProcessServerFactory serverFactory = InProcessServerFactory.create();
    dataServer = GrpcFnServer.allocatePortAndCreateFor(GrpcDataService.create(PipelineOptionsFactory.create(), executor, OutboundObserverFactory.serverDirect()), serverFactory);
    stateServer = GrpcFnServer.allocatePortAndCreateFor(GrpcStateService.create(), serverFactory);
    factory = SingleEnvironmentInstanceJobBundleFactory.create(environmentFactory, dataServer, stateServer, () -> GENERATED_ID);
}
Also used : InstructionRequest(org.apache.beam.model.fnexecution.v1.BeamFnApi.InstructionRequest) InProcessServerFactory(org.apache.beam.sdk.fn.server.InProcessServerFactory) Before(org.junit.Before)

Aggregations

InProcessServerFactory (org.apache.beam.sdk.fn.server.InProcessServerFactory)3 ThreadFactoryBuilder (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.util.concurrent.ThreadFactoryBuilder)2 ExecutionException (java.util.concurrent.ExecutionException)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 InstructionRequest (org.apache.beam.model.fnexecution.v1.BeamFnApi.InstructionRequest)1 ControlClientPool (org.apache.beam.runners.fnexecution.control.ControlClientPool)1 FnApiControlClientPoolService (org.apache.beam.runners.fnexecution.control.FnApiControlClientPoolService)1 InstructionRequestHandler (org.apache.beam.runners.fnexecution.control.InstructionRequestHandler)1 MapControlClientPool (org.apache.beam.runners.fnexecution.control.MapControlClientPool)1 CoderException (org.apache.beam.sdk.coders.CoderException)1 Before (org.junit.Before)1