Search in sources :

Example 6 with SourceSessionParams

use of com.yahoo.messagebus.SourceSessionParams in project vespa by vespa-engine.

the class DocumentProcessingHandlerTestBase method createHandler.

@Before
public void createHandler() {
    documentTypeManager.register(getType());
    Protocol protocol = new DocumentProtocol(documentTypeManager);
    driver = ServerTestDriver.newInactiveInstanceWithProtocol(protocol);
    sessionCache = new SessionCache("raw:", driver.client().slobrokId(), "test", "raw:", null, "raw:", documentTypeManager);
    ContainerBuilder builder = driver.parent().newContainerBuilder();
    ComponentRegistry<DocprocService> registry = new ComponentRegistry<>();
    handler = new DocumentProcessingHandler(registry, new ComponentRegistry<>(), new ComponentRegistry<>(), new DocumentProcessingHandlerParameters().setDocumentTypeManager(documentTypeManager).setContainerDocumentConfig(new ContainerDocumentConfig(new ContainerDocumentConfig.Builder())));
    builder.serverBindings().bind("mbus://*/*", handler);
    ReferencedResource<SharedSourceSession> sessionRef = sessionCache.retainSource(new SourceSessionParams());
    MbusClient sourceClient = new MbusClient(sessionRef.getResource());
    builder.clientBindings().bind("mbus://*/source", sourceClient);
    builder.clientBindings().bind("mbus://*/" + MbusRequestContext.internalNoThrottledSource, sourceClient);
    sourceClient.start();
    List<Pair<String, CallStack>> callStacks = getCallStacks();
    List<AbstractResource> resources = new ArrayList<>();
    for (Pair<String, CallStack> callStackPair : callStacks) {
        DocprocService service = new DocprocService(callStackPair.getFirst());
        service.setCallStack(callStackPair.getSecond());
        service.setInService(true);
        ComponentId serviceId = new ComponentId(service.getName());
        registry.register(serviceId, service);
        ComponentId sessionName = ComponentId.fromString("chain." + serviceId);
        MbusServerProvider serviceProvider = new MbusServerProvider(sessionName, sessionCache, driver.parent());
        serviceProvider.get().start();
        serviceProviders.add(serviceProvider);
        MbusClient intermediateClient = new MbusClient(serviceProvider.getSession());
        builder.clientBindings().bind("mbus://*/" + sessionName.stringValue(), intermediateClient);
        intermediateClient.start();
        resources.add(intermediateClient);
    }
    driver.parent().activateContainer(builder);
    sessionRef.getReference().close();
    sourceClient.release();
    for (AbstractResource resource : resources) {
        resource.release();
    }
    remoteServer = RemoteServer.newInstance(driver.client().slobrokId(), "foobar", protocol);
}
Also used : CallStack(com.yahoo.docproc.CallStack) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) ArrayList(java.util.ArrayList) AbstractResource(com.yahoo.jdisc.AbstractResource) DocprocService(com.yahoo.docproc.DocprocService) ContainerBuilder(com.yahoo.jdisc.application.ContainerBuilder) DocumentProtocol(com.yahoo.documentapi.messagebus.protocol.DocumentProtocol) Protocol(com.yahoo.messagebus.Protocol) Pair(com.yahoo.collections.Pair) ContainerDocumentConfig(com.yahoo.container.core.document.ContainerDocumentConfig) MbusClient(com.yahoo.messagebus.jdisc.MbusClient) SourceSessionParams(com.yahoo.messagebus.SourceSessionParams) DocumentProtocol(com.yahoo.documentapi.messagebus.protocol.DocumentProtocol) SharedSourceSession(com.yahoo.messagebus.shared.SharedSourceSession) MbusServerProvider(com.yahoo.container.jdisc.messagebus.MbusServerProvider) ComponentRegistry(com.yahoo.component.provider.ComponentRegistry) SessionCache(com.yahoo.container.jdisc.messagebus.SessionCache) ComponentId(com.yahoo.component.ComponentId) Before(org.junit.Before)

Example 7 with SourceSessionParams

use of com.yahoo.messagebus.SourceSessionParams in project vespa by vespa-engine.

the class MbusSessionKeyTestCase method sourceSessionKey.

// TODO the session key tests are just smoke tests
@Test
public final void sourceSessionKey() {
    final SourceSessionParams base = new SourceSessionParams();
    final SourceSessionParams other = new SourceSessionParams();
    assertEquals(new SourceSessionKey(base), new SourceSessionKey(other));
    other.setTimeout(other.getTimeout() + 1);
    assertFalse(new SourceSessionKey(base).equals(new SourceSessionKey(other)));
}
Also used : SourceSessionKey(com.yahoo.container.jdisc.messagebus.SessionCache.SourceSessionKey) SourceSessionParams(com.yahoo.messagebus.SourceSessionParams) Test(org.junit.Test)

Example 8 with SourceSessionParams

use of com.yahoo.messagebus.SourceSessionParams in project vespa by vespa-engine.

the class FeedHandlerV3 method sourceSessionParams.

private SourceSessionParams sourceSessionParams(HttpRequest request) {
    SourceSessionParams params = new SourceSessionParams();
    String timeout = request.getHeader(Headers.TIMEOUT);
    if (timeout != null) {
        try {
            params.setTimeout(Double.parseDouble(timeout));
        } catch (NumberFormatException e) {
        // NOP
        }
    }
    return params;
}
Also used : SourceSessionParams(com.yahoo.messagebus.SourceSessionParams)

Example 9 with SourceSessionParams

use of com.yahoo.messagebus.SourceSessionParams in project vespa by vespa-engine.

the class FeedHandlerV3 method handle.

// TODO: If this is set up to run without first invoking the old FeedHandler code, we should
// verify the version header first. This is done in the old code.
@Override
public HttpResponse handle(HttpRequest request) {
    final String clientId = clientId(request);
    final ClientFeederV3 clientFeederV3;
    synchronized (monitor) {
        if (!clientFeederByClientId.containsKey(clientId)) {
            SourceSessionParams sourceSessionParams = sourceSessionParams(request);
            clientFeederByClientId.put(clientId, new ClientFeederV3(retainSource(sessionCache, sourceSessionParams), new FeedReaderFactory(), docTypeManager, clientId, metric, feedReplyHandler, threadsAvailableForFeeding));
        }
        clientFeederV3 = clientFeederByClientId.get(clientId);
    }
    try {
        return clientFeederV3.handleRequest(request);
    } catch (UnknownClientException uce) {
        String msg = Exceptions.toMessageString(uce);
        log.log(LogLevel.WARNING, msg);
        return new ErrorHttpResponse(com.yahoo.jdisc.http.HttpResponse.Status.BAD_REQUEST, msg);
    } catch (Exception e) {
        String msg = "Could not initialize document parsing: " + Exceptions.toMessageString(e);
        log.log(LogLevel.WARNING, msg);
        return new ErrorHttpResponse(com.yahoo.jdisc.http.HttpResponse.Status.INTERNAL_SERVER_ERROR, msg);
    }
}
Also used : SourceSessionParams(com.yahoo.messagebus.SourceSessionParams)

Example 10 with SourceSessionParams

use of com.yahoo.messagebus.SourceSessionParams in project vespa by vespa-engine.

the class FeedHandler method sourceSessionParams.

/**
 * Exposed for use when creating mocks.
 */
protected SourceSessionParams sourceSessionParams(HttpRequest request) {
    SourceSessionParams params = new SourceSessionParams();
    String timeout = request.getHeader(Headers.TIMEOUT);
    if (timeout != null) {
        try {
            params.setTimeout(Double.parseDouble(timeout));
        } catch (NumberFormatException e) {
        // NOP
        }
    }
    return params;
}
Also used : SourceSessionParams(com.yahoo.messagebus.SourceSessionParams)

Aggregations

SourceSessionParams (com.yahoo.messagebus.SourceSessionParams)13 Test (org.junit.Test)5 SharedSourceSession (com.yahoo.messagebus.shared.SharedSourceSession)3 SessionCache (com.yahoo.container.jdisc.messagebus.SessionCache)2 DocumentApiMetrics (com.yahoo.documentapi.metrics.DocumentApiMetrics)2 Slobrok (com.yahoo.jrt.slobrok.server.Slobrok)2 MessageBusParams (com.yahoo.messagebus.MessageBusParams)2 Before (org.junit.Before)2 Splitter (com.google.common.base.Splitter)1 Pair (com.yahoo.collections.Pair)1 ComponentId (com.yahoo.component.ComponentId)1 ComponentRegistry (com.yahoo.component.provider.ComponentRegistry)1 ContainerDocumentConfig (com.yahoo.container.core.document.ContainerDocumentConfig)1 HttpRequest (com.yahoo.container.jdisc.HttpRequest)1 HttpResponse (com.yahoo.container.jdisc.HttpResponse)1 MbusServerProvider (com.yahoo.container.jdisc.messagebus.MbusServerProvider)1 SourceSessionKey (com.yahoo.container.jdisc.messagebus.SessionCache.SourceSessionKey)1 AccessLog (com.yahoo.container.logging.AccessLog)1 CallStack (com.yahoo.docproc.CallStack)1 DocprocService (com.yahoo.docproc.DocprocService)1