Search in sources :

Example 1 with Execution

use of com.yahoo.processing.execution.Execution in project vespa by vespa-engine.

the class Processing method doProcessAndRender.

@Override
protected ListenableFuture<Boolean> doProcessAndRender(ComponentSpecification chainSpec, Request request, Renderer<Response> renderer, ByteArrayOutputStream stream) throws IOException {
    Execution execution = handler.createExecution(getChain(chainSpec), request);
    Response response = execution.process(request);
    return renderer.render(stream, response, execution, request);
}
Also used : Response(com.yahoo.processing.Response) Execution(com.yahoo.processing.execution.Execution)

Example 2 with Execution

use of com.yahoo.processing.execution.Execution in project vespa by vespa-engine.

the class ExecutionContextTestCase method testtrace.

/**
 * Tests combined use of trace messages, context values and access log entries
 */
public void testtrace() {
    Execution execution1 = Execution.createRoot(chain, 2, Execution.Environment.createEmpty());
    execution1.trace().setProperty("a", "a1");
    execution1.trace().logValue("a", "a1");
    execution1.trace().trace("root 1", 2);
    execution1.trace().setProperty("a", "a2");
    execution1.trace().setProperty("b", "b1");
    execution1.trace().logValue("a", "a2");
    execution1.trace().logValue("b", "b1");
    Execution execution2 = new Execution(chain, execution1);
    execution2.trace().setProperty("b", "b2");
    execution2.trace().logValue("b", "b2");
    execution2.trace().trace("  child-1 1", 2);
    execution2.trace().setProperty("b", "b3");
    execution2.trace().logValue("b", "b3");
    execution1.trace().setProperty("b", "b4");
    execution1.trace().logValue("b", "b4");
    Execution execution3 = new Execution(chain, execution1);
    execution3.trace().setProperty("b", "b5");
    execution3.trace().setProperty("c", "c1");
    execution3.trace().logValue("b", "b5");
    execution3.trace().logValue("c", "c1");
    execution3.trace().trace("  child-2 1", 2);
    execution2.trace().setProperty("c", "c2");
    execution2.trace().logValue("c", "c2");
    execution1.trace().trace("root 2", 2);
    execution3.trace().setProperty("d", "d1");
    execution1.trace().logValue("d", "d1");
    execution2.trace().trace("  child-1 2", 2);
    execution2.trace().setProperty("c", "c3");
    execution2.trace().logValue("c", "c3");
    execution1.trace().setProperty("c", "c4");
    execution1.trace().logValue("c", "c4");
    Iterator<String> traceIterator = execution1.trace().traceNode().root().descendants(String.class).iterator();
    assertEquals("root 1", traceIterator.next());
    assertEquals("  child-1 1", traceIterator.next());
    assertEquals("  child-1 2", traceIterator.next());
    assertEquals("  child-2 1", traceIterator.next());
    assertEquals("root 2", traceIterator.next());
    assertFalse(traceIterator.hasNext());
    // Verify context variables
    assertEquals("a2", execution1.trace().getProperty("a"));
    assertEquals("b5", execution1.trace().getProperty("b"));
    assertEquals("c4", execution1.trace().getProperty("c"));
    assertEquals("d1", execution1.trace().getProperty("d"));
    assertNull(execution1.trace().getProperty("e"));
    // Verify access log
    Set<String> logValues = new HashSet<>();
    for (Iterator<Execution.Trace.LogValue> logValueIterator = execution1.trace().logValueIterator(); logValueIterator.hasNext(); ) logValues.add(logValueIterator.next().toString());
    assertEquals(12, logValues.size());
    assertTrue(logValues.contains("a=a1"));
    assertTrue(logValues.contains("a=a2"));
    assertTrue(logValues.contains("b=b1"));
    assertTrue(logValues.contains("b=b2"));
    assertTrue(logValues.contains("b=b3"));
    assertTrue(logValues.contains("b=b4"));
    assertTrue(logValues.contains("b=b5"));
    assertTrue(logValues.contains("c=c1"));
    assertTrue(logValues.contains("c=c2"));
    assertTrue(logValues.contains("d=d1"));
    assertTrue(logValues.contains("c=c3"));
    assertTrue(logValues.contains("c=c4"));
}
Also used : Execution(com.yahoo.processing.execution.Execution) HashSet(java.util.HashSet)

Example 3 with Execution

use of com.yahoo.processing.execution.Execution in project vespa by vespa-engine.

the class DocumentationTestCase method test.

@SuppressWarnings("unchecked")
@Test
public final void test() {
    Processor p = new ExampleProcessor();
    Chain<Processor> basic = new Chain<>(p);
    Processor initiator = new AsyncDataProcessingInitiator(basic);
    Chain<Processor> postProcessing = new Chain<>(initiator);
    Execution e = Execution.createRoot(postProcessing, 0, Execution.Environment.createEmpty());
    Response r = e.process(new Request());
    // just adds a listener to the result returned from basic
    assertEquals(0, r.data().asList().size());
    Processor producer = new AsyncDataProducer();
    Chain<Processor> asyncChain = new Chain<>(producer);
    Processor federator = new Federator(basic, asyncChain);
    e = Execution.createRoot(federator, 0, Execution.Environment.createEmpty());
    r = e.process(new Request());
    assertEquals(2, r.data().asList().size());
}
Also used : Response(com.yahoo.processing.Response) AsyncDataProducer(com.yahoo.processing.test.documentation.AsyncDataProducer) Chain(com.yahoo.component.chain.Chain) AsyncDataProcessingInitiator(com.yahoo.processing.test.documentation.AsyncDataProcessingInitiator) Federator(com.yahoo.processing.test.documentation.Federator) ExampleProcessor(com.yahoo.processing.test.documentation.ExampleProcessor) Processor(com.yahoo.processing.Processor) Execution(com.yahoo.processing.execution.Execution) ExampleProcessor(com.yahoo.processing.test.documentation.ExampleProcessor) Request(com.yahoo.processing.Request) Test(org.junit.Test)

Example 4 with Execution

use of com.yahoo.processing.execution.Execution in project vespa by vespa-engine.

the class AsynchronousSectionedRendererTest method render.

@SuppressWarnings("unchecked")
public String render(Renderer renderer, DataList data) throws InterruptedException, IOException {
    TestContentChannel contentChannel = new TestContentChannel();
    Execution execution = Execution.createRoot(new NoopProcessor(), 0, null);
    final ContentChannelOutputStream stream = new ContentChannelOutputStream(contentChannel);
    ListenableFuture result = renderer.render(stream, new Response(data), execution, null);
    int waitCounter = 1000;
    while (!result.isDone()) {
        Thread.sleep(60);
        --waitCounter;
        if (waitCounter < 0) {
            throw new IllegalStateException();
        }
    }
    stream.close();
    contentChannel.close(null);
    String str = "";
    for (ByteBuffer buf : contentChannel.getBuffers()) {
        str += Utf8.toString(buf);
    }
    return str;
}
Also used : Response(com.yahoo.processing.Response) Execution(com.yahoo.processing.execution.Execution) ContentChannelOutputStream(com.yahoo.container.jdisc.ContentChannelOutputStream) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ByteBuffer(java.nio.ByteBuffer)

Example 5 with Execution

use of com.yahoo.processing.execution.Execution in project vespa by vespa-engine.

the class AbstractProcessingHandler method handle.

@Override
@SuppressWarnings("unchecked")
public HttpResponse handle(HttpRequest request, ContentChannel channel) {
    com.yahoo.processing.Request processingRequest = new com.yahoo.processing.Request();
    populate("", request.propertyMap(), processingRequest.properties());
    populate("context", request.getJDiscRequest().context(), processingRequest.properties());
    processingRequest.properties().set(Request.JDISC_REQUEST, request);
    FreezeListener freezeListener = new FreezeListener(processingRequest, renderers, defaultRenderer, channel, renderingExecutor);
    processingRequest.properties().set(freezeListenerKey, freezeListener);
    Chain<COMPONENT> chain = chainRegistry.getComponent(resolveChainId(processingRequest.properties()));
    if (chain == null)
        throw new IllegalArgumentException("Chain '" + processingRequest.properties().get("chain") + "' not found");
    Execution execution = createExecution(chain, processingRequest);
    freezeListener.setExecution(execution);
    Response processingResponse = execution.process(processingRequest);
    return freezeListener.getHttpResponse(processingResponse);
}
Also used : Response(com.yahoo.processing.Response) HttpResponse(com.yahoo.container.jdisc.HttpResponse) Execution(com.yahoo.processing.execution.Execution) Request(com.yahoo.processing.Request) HttpRequest(com.yahoo.container.jdisc.HttpRequest) Request(com.yahoo.processing.Request)

Aggregations

Execution (com.yahoo.processing.execution.Execution)5 Response (com.yahoo.processing.Response)4 Request (com.yahoo.processing.Request)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 Chain (com.yahoo.component.chain.Chain)1 ContentChannelOutputStream (com.yahoo.container.jdisc.ContentChannelOutputStream)1 HttpRequest (com.yahoo.container.jdisc.HttpRequest)1 HttpResponse (com.yahoo.container.jdisc.HttpResponse)1 Processor (com.yahoo.processing.Processor)1 AsyncDataProcessingInitiator (com.yahoo.processing.test.documentation.AsyncDataProcessingInitiator)1 AsyncDataProducer (com.yahoo.processing.test.documentation.AsyncDataProducer)1 ExampleProcessor (com.yahoo.processing.test.documentation.ExampleProcessor)1 Federator (com.yahoo.processing.test.documentation.Federator)1 ByteBuffer (java.nio.ByteBuffer)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1