Search in sources :

Example 6 with ExecuteResponse

use of org.apache.zeppelin.interpreter.jupyter.proto.ExecuteResponse in project zeppelin by apache.

the class JupyterKernelClient method block_execute.

// blocking execute the code
public ExecuteResponse block_execute(ExecuteRequest request) {
    ExecuteResponse.Builder responseBuilder = ExecuteResponse.newBuilder();
    responseBuilder.setStatus(ExecuteStatus.SUCCESS);
    Iterator<ExecuteResponse> iter = blockingStub.execute(request);
    StringBuilder outputBuilder = new StringBuilder();
    try {
        // iter.hasNext may throw exception, so use try catch outside.
        while (iter.hasNext()) {
            ExecuteResponse nextResponse = iter.next();
            if (nextResponse.getStatus() == ExecuteStatus.ERROR) {
                responseBuilder.setStatus(ExecuteStatus.ERROR);
            }
            outputBuilder.append(nextResponse.getOutput());
        }
        responseBuilder.setOutput(outputBuilder.toString());
    } catch (Exception e) {
        responseBuilder.setStatus(ExecuteStatus.ERROR);
        responseBuilder.setOutput(outputBuilder.toString());
    }
    return responseBuilder.build();
}
Also used : ExecuteResponse(org.apache.zeppelin.interpreter.jupyter.proto.ExecuteResponse) IOException(java.io.IOException)

Aggregations

ExecuteResponse (org.apache.zeppelin.interpreter.jupyter.proto.ExecuteResponse)6 IOException (java.io.IOException)5 InputStream (java.io.InputStream)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 InterpreterException (org.apache.zeppelin.interpreter.InterpreterException)1 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)1 InterpreterResultMessageOutput (org.apache.zeppelin.interpreter.InterpreterResultMessageOutput)1 OutputType (org.apache.zeppelin.interpreter.jupyter.proto.OutputType)1