Search in sources :

Example 1 with PureExecutionStreamingException

use of org.finos.legend.pure.m3.exception.PureExecutionStreamingException in project legend-pure by finos.

the class ExecutionManager method execute.

private void execute(CoreInstance function, ListIterable<CoreInstance> parameters, HttpResponseWriter response, HttpInformation httpInformation, boolean canStreamOutput, OutputFormat format) {
    long start = System.currentTimeMillis();
    try {
        CanStreamState.setCanStream(canStreamOutput);
        response.setIsStreamingResponse(canStreamOutput);
        this.addContentTypeAndDispositionHeaders(response, httpInformation);
        response.setHeader("Trailer", "X-Streaming-Error");
        // Do not open outputStream in try-with-resources
        OutputStream outputStream = response.getOutputStream();
        try {
            OutputWriter writer = this.functionExecution.newOutputWriter();
            if (format == OutputFormat.XLSX) {
                writer = new XLSXOutputWriter(writer);
            }
            this.functionExecution.start(function, parameters, outputStream, writer);
        } catch (PureExecutionStreamingException ex) {
        }
        // outputStream must NOT be closed in case of an uncaught exception
        // so the call to close must not be in a finally block or implicit in a try-with-resources
        outputStream.close();
    } catch (Throwable t) {
        if (t instanceof RuntimeException) {
            throw (RuntimeException) t;
        }
        if (t instanceof Error) {
            throw (Error) t;
        }
        throw new RuntimeException(t);
    } finally {
        // Reset
        CanStreamState.resetCanStream();
    }
}
Also used : OutputStream(java.io.OutputStream) PureExecutionStreamingException(org.finos.legend.pure.m3.exception.PureExecutionStreamingException) OutputWriter(org.finos.legend.pure.m3.execution.OutputWriter) XLSXOutputWriter(org.finos.legend.pure.m3.execution.XLSXOutputWriter) XLSXOutputWriter(org.finos.legend.pure.m3.execution.XLSXOutputWriter)

Example 2 with PureExecutionStreamingException

use of org.finos.legend.pure.m3.exception.PureExecutionStreamingException in project legend-pure by finos.

the class FunctionExecutionCompiled method start.

@Override
public void start(CoreInstance func, ListIterable<? extends CoreInstance> arguments, OutputStream outputStream, OutputWriter writer) {
    CompiledExecutionSupport executionSupport = new CompiledExecutionSupport(this.javaCompilerEventHandler.getJavaCompileState(), (CompiledProcessorSupport) this.getProcessorSupport(), this.sourceRegistry, this.runtime.getCodeStorage(), this.runtime.getIncrementalCompiler(), this.executionActivityListener, this.consoleCompiled, this.javaCompilerEventHandler.getFunctionCache(), this.javaCompilerEventHandler.getClassCache(), this.metadataCompilerEventHandler, this.extraSupportedTypes, this.runtime.getOptions());
    Exception exception = null;
    try {
        Object result = this.executeFunction(func, arguments, executionSupport);
        try {
            writer.write(result, outputStream);
        } catch (PureExecutionException ex) {
            exception = ex;
            throw new PureExecutionStreamingException(ex);
        } catch (IOException e) {
            exception = e;
            throw new RuntimeException("Failed to write results to OutputStream", e);
        }
    } finally {
        executionSupport.executionEnd(exception);
    }
}
Also used : PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) PureExecutionStreamingException(org.finos.legend.pure.m3.exception.PureExecutionStreamingException) IOException(java.io.IOException) PureExecutionStreamingException(org.finos.legend.pure.m3.exception.PureExecutionStreamingException) PureExecutionException(org.finos.legend.pure.m3.exception.PureExecutionException) IOException(java.io.IOException) PureException(org.finos.legend.pure.m4.exception.PureException)

Aggregations

PureExecutionStreamingException (org.finos.legend.pure.m3.exception.PureExecutionStreamingException)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 PureExecutionException (org.finos.legend.pure.m3.exception.PureExecutionException)1 OutputWriter (org.finos.legend.pure.m3.execution.OutputWriter)1 XLSXOutputWriter (org.finos.legend.pure.m3.execution.XLSXOutputWriter)1 PureException (org.finos.legend.pure.m4.exception.PureException)1