Search in sources :

Example 1 with JsonTraceCodec

use of com.linkedin.parseq.trace.codec.json.JsonTraceCodec in project rest.li by linkedin.

the class ParseqTraceDebugRequestHandler method sendTraceRawAsResponse.

private void sendTraceRawAsResponse(final RequestExecutionCallback<RestResponse> callback, final RequestExecutionReport executionReport) {
    String mediaType = HEADER_VALUE_APPLICATION_JSON;
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {
        Trace trace = executionReport.getParseqTrace();
        if (trace != null) {
            //Serialize the Parseq trace into JSON.
            JsonTraceCodec traceCodec = new JsonTraceCodec();
            traceCodec.encode(trace, outputStream);
        }
    } catch (IOException exception) {
        callback.onError(new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, exception), null, null, null);
    }
    sendByteArrayAsResponse(callback, outputStream.toByteArray(), mediaType);
}
Also used : Trace(com.linkedin.parseq.trace.Trace) JsonTraceCodec(com.linkedin.parseq.trace.codec.json.JsonTraceCodec) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 2 with JsonTraceCodec

use of com.linkedin.parseq.trace.codec.json.JsonTraceCodec in project rest.li by linkedin.

the class TestParseqTraceDebugRequestHandler method executeRequestThroughParseqDebugHandler.

private void executeRequestThroughParseqDebugHandler(URI uri, RequestExecutionCallback<RestResponse> callback) {
    ParseqTraceDebugRequestHandler requestHandler = new ParseqTraceDebugRequestHandler();
    RestRequestBuilder requestBuilder = new RestRequestBuilder(uri);
    RestRequest request = requestBuilder.build();
    RequestContext requestContext = new RequestContext();
    requestHandler.handleRequest(request, requestContext, new RestLiDebugRequestHandler.ResourceDebugRequestHandler() {

        @Override
        public void handleRequest(RestRequest request, RequestContext requestContext, RequestExecutionCallback<RestResponse> callback) {
            RestResponse response = EasyMock.createMock(RestResponse.class);
            RequestExecutionReportBuilder executionReportBuilder = new RequestExecutionReportBuilder();
            JsonTraceCodec jsonTraceCodec = new JsonTraceCodec();
            Trace t = null;
            try {
                t = jsonTraceCodec.decode(TEST_TRACE);
                executionReportBuilder.setParseqTrace(t);
            } catch (IOException exc) {
            //test will fail later
            }
            callback.onSuccess(response, executionReportBuilder.build(), null);
        }
    }, null, callback);
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) IOException(java.io.IOException) Trace(com.linkedin.parseq.trace.Trace) RestRequest(com.linkedin.r2.message.rest.RestRequest) JsonTraceCodec(com.linkedin.parseq.trace.codec.json.JsonTraceCodec) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) RequestContext(com.linkedin.r2.message.RequestContext)

Example 3 with JsonTraceCodec

use of com.linkedin.parseq.trace.codec.json.JsonTraceCodec in project rest.li by linkedin.

the class ParseqTraceDebugRequestHandler method sendTracevisEntryPageAsResponse.

private void sendTracevisEntryPageAsResponse(final Callback<RestResponse> callback, final Trace trace) {
    String mediaType = HEADER_VALUE_TEXT_HTML;
    ClassLoader currentClassLoader = getClass().getClassLoader();
    InputStream resourceStream = currentClassLoader.getResourceAsStream(ENTRY_PATH_SEGMENT_TRACEVIS + PATH_SEP + ENTRY_PAGE);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {
        IOUtils.copy(resourceStream, outputStream);
        if (trace != null) {
            // Serialize the Parseq trace into JSON and then inject a javascript into the response
            // which will call the corresponding render function on the entry page html with the JSON
            // string.
            JsonTraceCodec traceCodec = new JsonTraceCodec();
            IOUtils.write(createTraceRenderScript(traceCodec.encode(trace)), outputStream);
        }
    } catch (IOException exception) {
        callback.onError(new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, exception));
    }
    sendByteArrayAsResponse(callback, outputStream.toByteArray(), mediaType);
}
Also used : InputStream(java.io.InputStream) JsonTraceCodec(com.linkedin.parseq.trace.codec.json.JsonTraceCodec) ByteString(com.linkedin.data.ByteString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 4 with JsonTraceCodec

use of com.linkedin.parseq.trace.codec.json.JsonTraceCodec in project parseq by linkedin.

the class ExampleUtil method printTracingResults.

public static void printTracingResults(final Task<?> task) {
    final Trace trace = task.getTrace();
    System.out.println();
    System.out.println();
    System.out.println("JSON Trace:");
    try {
        System.out.println(new JsonTraceCodec().encode(trace));
    } catch (IOException e) {
        System.err.println("Failed to encode JSON");
        e.printStackTrace();
    }
    System.out.println();
}
Also used : Trace(com.linkedin.parseq.trace.Trace) JsonTraceCodec(com.linkedin.parseq.trace.codec.json.JsonTraceCodec) IOException(java.io.IOException)

Example 5 with JsonTraceCodec

use of com.linkedin.parseq.trace.codec.json.JsonTraceCodec in project rest.li by linkedin.

the class ParseqTraceDebugRequestHandler method sendTracevisEntryPageAsResponse.

private void sendTracevisEntryPageAsResponse(final RequestExecutionCallback<RestResponse> callback, final RequestExecutionReport executionReport) {
    String mediaType = HEADER_VALUE_TEXT_HTML;
    ClassLoader currentClassLoader = getClass().getClassLoader();
    InputStream resourceStream = currentClassLoader.getResourceAsStream(ENTRY_PATH_SEGMENT_TRACEVIS + PATH_SEP + ENTRY_PAGE);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {
        IOUtils.copy(resourceStream, outputStream);
        Trace trace = executionReport.getParseqTrace();
        if (trace != null) {
            //Serialize the Parseq trace into JSON and then inject a javascript into the response
            //which will call the corresponding render function on the entry page html with the JSON
            //string.
            JsonTraceCodec traceCodec = new JsonTraceCodec();
            IOUtils.write(createTraceRenderScript(traceCodec.encode(trace)), outputStream);
        }
    } catch (IOException exception) {
        callback.onError(new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, exception), null, null, null);
    }
    sendByteArrayAsResponse(callback, outputStream.toByteArray(), mediaType);
}
Also used : Trace(com.linkedin.parseq.trace.Trace) InputStream(java.io.InputStream) JsonTraceCodec(com.linkedin.parseq.trace.codec.json.JsonTraceCodec) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

JsonTraceCodec (com.linkedin.parseq.trace.codec.json.JsonTraceCodec)8 IOException (java.io.IOException)8 Trace (com.linkedin.parseq.trace.Trace)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 RestResponse (com.linkedin.r2.message.rest.RestResponse)3 InputStream (java.io.InputStream)3 ByteString (com.linkedin.data.ByteString)2 RequestContext (com.linkedin.r2.message.RequestContext)2 RestRequest (com.linkedin.r2.message.rest.RestRequest)2 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)2 Task (com.linkedin.parseq.Task)1 PromiseListener (com.linkedin.parseq.promise.PromiseListener)1