Search in sources :

Example 1 with ErrorResult

use of org.finos.legend.engine.plan.execution.result.ErrorResult in project legend-sdlc by finos.

the class LegendPureV1TestCase method getResultValuesAsJson.

private List<JsonNode> getResultValuesAsJson(Result result) {
    if (result instanceof ErrorResult) {
        throw new RuntimeException(((ErrorResult) result).getMessage());
    }
    JsonNode jsonResult = getResultAsJson(result);
    JsonNode values = jsonResult.get("values");
    return nodeToList(values);
}
Also used : ErrorResult(org.finos.legend.engine.plan.execution.result.ErrorResult) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 2 with ErrorResult

use of org.finos.legend.engine.plan.execution.result.ErrorResult in project legend-engine by finos.

the class ExecutionNodeExecutor method visit.

@Override
public Result visit(MultiResultSequenceExecutionNode multiResultSequenceExecutionNode) {
    Map<String, Result> subResults = Maps.mutable.empty();
    Result last = null;
    for (ExecutionNode n : multiResultSequenceExecutionNode.executionNodes()) {
        last = n.accept(new ExecutionNodeExecutor(this.profiles, this.executionState));
        if (n instanceof AllocationExecutionNode) {
            subResults.put(((AllocationExecutionNode) n).varName, last);
        }
        if (last instanceof ErrorResult) {
            return last;
        }
    }
    if (last != null) {
        subResults.put("@LAST", last);
    }
    return new MultiResult(subResults);
}
Also used : MultiResult(org.finos.legend.engine.plan.execution.result.MultiResult) AllocationExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.AllocationExecutionNode) InMemoryCrossStoreGraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.store.inMemory.InMemoryCrossStoreGraphFetchExecutionNode) ErrorExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ErrorExecutionNode) StoreStreamReadingExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.store.inMemory.StoreStreamReadingExecutionNode) ExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ExecutionNode) AllocationExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.AllocationExecutionNode) ConstantExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ConstantExecutionNode) InMemoryRootGraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.store.inMemory.InMemoryRootGraphFetchExecutionNode) FreeMarkerConditionalExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.FreeMarkerConditionalExecutionNode) MultiResultSequenceExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.MultiResultSequenceExecutionNode) AggregationAwareExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.AggregationAwareExecutionNode) GraphFetchM2MExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.GraphFetchM2MExecutionNode) PureExpressionPlatformExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.PureExpressionPlatformExecutionNode) GraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.GraphFetchExecutionNode) SequenceExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.SequenceExecutionNode) InMemoryPropertyGraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.store.inMemory.InMemoryPropertyGraphFetchExecutionNode) GlobalGraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.GlobalGraphFetchExecutionNode) LocalGraphFetchExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.graphFetch.LocalGraphFetchExecutionNode) ErrorResult(org.finos.legend.engine.plan.execution.result.ErrorResult) ConstantResult(org.finos.legend.engine.plan.execution.result.ConstantResult) GraphFetchResult(org.finos.legend.engine.plan.execution.result.graphFetch.GraphFetchResult) StreamingObjectResult(org.finos.legend.engine.plan.execution.result.object.StreamingObjectResult) ErrorResult(org.finos.legend.engine.plan.execution.result.ErrorResult) Result(org.finos.legend.engine.plan.execution.result.Result) MultiResult(org.finos.legend.engine.plan.execution.result.MultiResult)

Example 3 with ErrorResult

use of org.finos.legend.engine.plan.execution.result.ErrorResult in project legend-engine by finos.

the class ExecutionNodeJavaPlatformHelper method getClassToExecute.

public static Class<?> getClassToExecute(ExecutionNode node, String _class, ExecutionState executionState, MutableList<CommonProfile> pm) {
    if (executionState.isJavaCompilationForbidden()) {
        try {
            return Thread.currentThread().getContextClassLoader().loadClass(_class);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
    JavaPlatformImplementation j = (JavaPlatformImplementation) node.implementation;
    List<JavaClass> javaClasses = FastList.newList();
    if (j.code != null) {
        JavaClass executeClass = JavaHelper.newJavaClass(JavaHelper.getExecutionClassFullName(j));
        executeClass.source = j.code;
        javaClasses.add(executeClass);
    }
    javaClasses.addAll(getLocalImplementationSupportClasses(node));
    if (javaClasses.isEmpty()) {
        ClassLoader classLoader = executionState.hasJavaCompiler() ? executionState.getJavaCompiler().getClassLoader() : Thread.currentThread().getContextClassLoader();
        try {
            return classLoader.loadClass(_class);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
    try {
        // TODO Confirm we can delete this
        MutableMap<String, String> compiledClassesWithByteCode = getCompiledClasses(node);
        List<StringJavaSource> classesToCompile = javaClasses.stream().filter(c -> !compiledClassesWithByteCode.containsKey(JavaHelper.getJavaClassFullName(c))).map(JavaHelper::buildStringJavaSource).collect(Collectors.toList());
        EngineJavaCompiler compiler = new EngineJavaCompiler(executionState.getJavaCompiler());
        long start = System.currentTimeMillis();
        try {
            if (!compiledClassesWithByteCode.isEmpty()) {
                compiler.load(compiledClassesWithByteCode);
            }
            if (!classesToCompile.isEmpty()) {
                LOGGER.info(new LogInfo(pm, LoggingEventType.JAVA_COMPILATION_START, "Node: " + node.getClass().getName()).toString());
                compiler.compile(classesToCompile);
                LOGGER.info(new LogInfo(pm, LoggingEventType.JAVA_COMPILATION_STOP, (double) System.currentTimeMillis() - start).toString());
            }
        } catch (Exception jce) {
            LOGGER.info(new LogInfo(pm, LoggingEventType.JAVA_COMPILATION_ERROR, new ErrorResult(1, jce).getMessage()).toString());
            throw jce;
        }
        return compiler.getClassLoader().loadClass(_class);
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : LogInfo(org.finos.legend.engine.shared.core.operational.logs.LogInfo) EngineJavaCompiler(org.finos.legend.engine.shared.javaCompiler.EngineJavaCompiler) ErrorResult(org.finos.legend.engine.plan.execution.result.ErrorResult) InvocationTargetException(java.lang.reflect.InvocationTargetException) JavaClass(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.JavaClass) JavaPlatformImplementation(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.JavaPlatformImplementation) StringJavaSource(org.finos.legend.engine.shared.javaCompiler.StringJavaSource)

Example 4 with ErrorResult

use of org.finos.legend.engine.plan.execution.result.ErrorResult in project legend-engine by finos.

the class JavaHelper method compilePlan.

public static EngineJavaCompiler compilePlan(SingleExecutionPlan singleExecutionPlan, MutableList<CommonProfile> pm) throws JavaCompileException {
    try {
        long start = System.currentTimeMillis();
        LOGGER.info(new LogInfo(pm, LoggingEventType.JAVA_COMPILATION_START, "Compile Plan").toString());
        EngineJavaCompiler compiler;
        try {
            compiler = compilePlanFast(singleExecutionPlan);
        } catch (Exception ignored) {
            // TODO Confirm we can delete this
            compiler = compilePlanSlow(singleExecutionPlan);
        }
        LOGGER.info(new LogInfo(pm, LoggingEventType.JAVA_COMPILATION_STOP, (double) System.currentTimeMillis() - start).toString());
        return compiler;
    } catch (Exception e) {
        LOGGER.info(new LogInfo(pm, LoggingEventType.JAVA_COMPILATION_ERROR, new ErrorResult(1, e).getMessage()).toString());
        throw e;
    }
}
Also used : LogInfo(org.finos.legend.engine.shared.core.operational.logs.LogInfo) EngineJavaCompiler(org.finos.legend.engine.shared.javaCompiler.EngineJavaCompiler) ErrorResult(org.finos.legend.engine.plan.execution.result.ErrorResult) CompileException(org.codehaus.commons.compiler.CompileException) IOException(java.io.IOException) JavaCompileException(org.finos.legend.engine.shared.javaCompiler.JavaCompileException)

Example 5 with ErrorResult

use of org.finos.legend.engine.plan.execution.result.ErrorResult in project legend-engine by finos.

the class MappingTestRunner method getResultValuesAsJson.

private List<JsonNode> getResultValuesAsJson(Result result) {
    if (result instanceof ErrorResult) {
        throw new RuntimeException(((ErrorResult) result).getMessage());
    }
    JsonNode jsonResult = getResultAsJson(result);
    JsonNode values = jsonResult.get("values");
    if (values != null) {
        return nodeToList(values);
    }
    values = jsonResult.get("result");
    if (values != null) {
        return nodeToList(values.get("rows"));
    }
    throw new RuntimeException("The system was not extract values from the Result");
}
Also used : ErrorResult(org.finos.legend.engine.plan.execution.result.ErrorResult) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

ErrorResult (org.finos.legend.engine.plan.execution.result.ErrorResult)6 LogInfo (org.finos.legend.engine.shared.core.operational.logs.LogInfo)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 EngineJavaCompiler (org.finos.legend.engine.shared.javaCompiler.EngineJavaCompiler)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 CompileException (org.codehaus.commons.compiler.CompileException)1 ConstantResult (org.finos.legend.engine.plan.execution.result.ConstantResult)1 MultiResult (org.finos.legend.engine.plan.execution.result.MultiResult)1 Result (org.finos.legend.engine.plan.execution.result.Result)1 GraphFetchResult (org.finos.legend.engine.plan.execution.result.graphFetch.GraphFetchResult)1 StreamingObjectResult (org.finos.legend.engine.plan.execution.result.object.StreamingObjectResult)1 AggregationAwareExecutionNode (org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.AggregationAwareExecutionNode)1 AllocationExecutionNode (org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.AllocationExecutionNode)1 ConstantExecutionNode (org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ConstantExecutionNode)1 ErrorExecutionNode (org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ErrorExecutionNode)1 ExecutionNode (org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ExecutionNode)1 FreeMarkerConditionalExecutionNode (org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.FreeMarkerConditionalExecutionNode)1 GraphFetchM2MExecutionNode (org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.GraphFetchM2MExecutionNode)1 JavaClass (org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.JavaClass)1