Search in sources :

Example 1 with LogInfo

use of org.finos.legend.engine.shared.core.operational.logs.LogInfo 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 2 with LogInfo

use of org.finos.legend.engine.shared.core.operational.logs.LogInfo 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 3 with LogInfo

use of org.finos.legend.engine.shared.core.operational.logs.LogInfo in project legend-engine by finos.

the class MorphirGenerationService method exec.

private Response exec(MorphirGenerationConfig morphirGenerationConfig, Function0<PureModel> pureModelFunc, boolean interactive, MutableList<CommonProfile> pm) {
    try {
        LOGGER.info(new LogInfo(pm, interactive ? LoggingEventType.GENERATE_MORPHIR_INTERACTIVE_START : LoggingEventType.GENERATE_MORPHIR_START).toString());
        PureModel pureModel = pureModelFunc.value();
        RichIterable<? extends Root_meta_pure_generation_metamodel_GenerationOutput> output = core_external_language_morphir_integration.Root_meta_external_language_morphir_generation_generateMorphirIRFromPureWithScope_MorphirConfig_1__GenerationOutput_MANY_(morphirGenerationConfig.process(pureModel), pureModel.getExecutionSupport());
        LOGGER.info(new LogInfo(pm, interactive ? LoggingEventType.GENERATE_MORPHIR_INTERACTIVE_STOP : LoggingEventType.GENERATE_MORPHIR_STOP).toString());
        return ManageConstantResult.manageResult(pm, output.collect(v -> new GenerationOutput(v._content(), v._fileName(), v._format())).toList());
    } catch (Exception ex) {
        return ExceptionTool.exceptionManager(ex, interactive ? LoggingEventType.GENERATE_MORPHIR_INTERACTIVE_ERROR : LoggingEventType.GENERATE_MORPHIR_ERROR, pm);
    }
}
Also used : LogInfo(org.finos.legend.engine.shared.core.operational.logs.LogInfo) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) GenerationOutput(org.finos.legend.engine.external.shared.format.generations.GenerationOutput) Root_meta_pure_generation_metamodel_GenerationOutput(org.finos.legend.pure.generated.Root_meta_pure_generation_metamodel_GenerationOutput)

Example 4 with LogInfo

use of org.finos.legend.engine.shared.core.operational.logs.LogInfo in project legend-engine by finos.

the class TestRelationalOperationElementGrammarRoundtrip method test.

protected static void test(String val, String expectedErrorMsg) {
    RelationalOperationElement operation = null;
    try {
        RelationalOperationElement op = RelationalGrammarParserExtension.parseRelationalOperationElement(val, true);
        String json = objectMapper.writeValueAsString(op);
        operation = objectMapper.readValue(json, RelationalOperationElement.class);
        if (expectedErrorMsg != null) {
            Assert.fail("Test did not fail with error '" + expectedErrorMsg + "' as expected");
        }
    } catch (Exception e) {
        LogInfo errorResponse = new LogInfo(null, LoggingEventType.PARSE_ERROR, e);
        Assert.assertNotNull("No source information provided in error", errorResponse.sourceInformation);
        Assert.assertEquals(expectedErrorMsg, EngineException.buildPrettyErrorMessage(errorResponse.message, errorResponse.sourceInformation, EngineErrorType.PARSER));
    }
    String renderedOperation = RelationalGrammarComposerExtension.renderRelationalOperationElement(operation);
    Assert.assertEquals(null, val, renderedOperation);
}
Also used : LogInfo(org.finos.legend.engine.shared.core.operational.logs.LogInfo) RelationalOperationElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.model.operation.RelationalOperationElement) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)

Example 5 with LogInfo

use of org.finos.legend.engine.shared.core.operational.logs.LogInfo in project legend-engine by finos.

the class AvroGenerationService method exec.

private Response exec(AvroGenerationConfig avroConfig, Function0<PureModel> pureModelFunc, boolean interactive, MutableList<CommonProfile> pm) {
    try {
        long start = System.currentTimeMillis();
        LOGGER.info(new LogInfo(pm, interactive ? LoggingEventType.GENERATE_AVRO_CODE_INTERACTIVE_START : LoggingEventType.GENERATE_AVRO_CODE_START).toString());
        PureModel pureModel = pureModelFunc.value();
        RichIterable<? extends Root_meta_pure_generation_metamodel_GenerationOutput> output = core_external_format_avro_tramsformation_avroSchemaGenerator.Root_meta_external_format_avro_generation_generateAvroFromPureWithScope_AvroConfig_1__AvroOutput_MANY_(avroConfig.process(pureModel), pureModel.getExecutionSupport());
        LOGGER.info(new LogInfo(pm, interactive ? LoggingEventType.GENERATE_AVRO_CODE_INTERACTIVE_STOP : LoggingEventType.GENERATE_AVRO_CODE_STOP, (double) System.currentTimeMillis() - start).toString());
        return ManageConstantResult.manageResult(pm, output.collect(v -> new GenerationOutput(v._content(), v._fileName(), v._format())).toList());
    } catch (Exception ex) {
        return ExceptionTool.exceptionManager(ex, interactive ? LoggingEventType.GENERATE_AVRO_CODE_INTERACTIVE_ERROR : LoggingEventType.GENERATE_AVRO_CODE_ERROR, pm);
    }
}
Also used : LogInfo(org.finos.legend.engine.shared.core.operational.logs.LogInfo) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) GenerationOutput(org.finos.legend.engine.external.shared.format.generations.GenerationOutput) Root_meta_pure_generation_metamodel_GenerationOutput(org.finos.legend.pure.generated.Root_meta_pure_generation_metamodel_GenerationOutput)

Aggregations

LogInfo (org.finos.legend.engine.shared.core.operational.logs.LogInfo)29 PureModel (org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel)8 Scope (io.opentracing.Scope)7 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)7 CommonProfile (org.pac4j.core.profile.CommonProfile)6 GenerationOutput (org.finos.legend.engine.external.shared.format.generations.GenerationOutput)5 Response (javax.ws.rs.core.Response)4 LoggingEventType (org.finos.legend.engine.shared.core.operational.logs.LoggingEventType)4 Logger (org.slf4j.Logger)4 ApiOperation (io.swagger.annotations.ApiOperation)3 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 RichIterable (org.eclipse.collections.api.RichIterable)3 MutableList (org.eclipse.collections.api.list.MutableList)3 Lists (org.eclipse.collections.impl.factory.Lists)3 ErrorResult (org.finos.legend.engine.plan.execution.result.ErrorResult)3 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)3 SingleExecutionPlan (org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan)3 Span (io.opentracing.Span)2