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());
}
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());
}
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);
}
Aggregations