Search in sources :

Example 1 with JavaCompileException

use of org.finos.legend.engine.shared.javaCompiler.JavaCompileException in project legend-engine by finos.

the class JavaHelper method compilePlanFast.

private static EngineJavaCompiler compilePlanFast(SingleExecutionPlan singleExecutionPlan) throws JavaCompileException, IOException, CompileException {
    Map<JavaPlatformImplementation, List<JavaClass>> javaClassesMap = Maps.mutable.empty();
    if (singleExecutionPlan.globalImplementationSupport != null) {
        JavaPlatformImplementation platformImplementation = (JavaPlatformImplementation) singleExecutionPlan.globalImplementationSupport;
        List<JavaClass> globalImplementationSupportClasses = collectJavaClasses(platformImplementation);
        if (!globalImplementationSupportClasses.isEmpty()) {
            javaClassesMap.put(platformImplementation, globalImplementationSupportClasses);
        }
    }
    collectJavaClasses(singleExecutionPlan.rootExecutionNode, javaClassesMap);
    if (javaClassesMap.isEmpty()) {
        return null;
    }
    EngineJavaCompiler javaCompiler = createNewJavaCompiler();
    Map<JavaClass, JavaPlatformImplementation> reverseClassMap = Maps.mutable.empty();
    List<JavaClass> executeClasses = new ArrayList<>();
    List<JavaClass> nonExecuteClasses = new ArrayList<>();
    javaClassesMap.forEach((jimpl, jclasses) -> jclasses.forEach(jclass -> {
        reverseClassMap.put(jclass, jimpl);
        (javaClassHasFullName(jclass, jimpl.executionClassFullName) ? executeClasses : nonExecuteClasses).add(jclass);
    }));
    Map<String, JavaClass> classMap = nonExecuteClasses.stream().collect(Collectors.toMap(JavaHelper::getJavaClassFullName, x -> x, (x, y) -> {
        throw new RuntimeException("Conflicting classes compilation in fast mode not supported!");
    }));
    Map<String, String> classToBytecodeMap = compileJavaClasses(nonExecuteClasses, javaCompiler);
    classToBytecodeMap.forEach((name, bytecode) -> {
        JavaClass _class = classMap.get(name);
        if (_class == null) {
            // Handling Inner Classes only
            int firstDollar = name.indexOf('$');
            if (firstDollar == -1) {
                throw new RuntimeException("Non Inner classes are not supported yet!");
            }
            JavaClass topClass = classMap.get(name.substring(0, firstDollar));
            JavaPlatformImplementation impl = reverseClassMap.get(topClass);
            _class = createGeneratedJavaClass(name);
            if (impl.classes == null) {
                impl.classes = FastList.newListWith(_class);
            } else {
                impl.classes.add(_class);
            }
        }
        _class.byteCode = bytecode;
    });
    ClassLoader globalClassLoader = javaCompiler.getClassLoader();
    for (JavaClass executeClass : executeClasses) {
        if (executeClass.byteCode == null) {
            Map<String, byte[]> classes = SingleFileCompiler.compileFile(buildStringJavaSource(executeClass), globalClassLoader);
            executeClass.byteCode = Base64.getEncoder().encodeToString(classes.get(getJavaClassFullName(executeClass)));
        }
    }
    return javaCompiler;
}
Also used : JavaClass(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.JavaClass) LoggingEventType(org.finos.legend.engine.shared.core.operational.logs.LoggingEventType) SingleFileCompiler(org.finos.legend.engine.shared.javaCompiler.SingleFileCompiler) CommonProfile(org.pac4j.core.profile.CommonProfile) ExecutionPlanDependenciesFilter(org.finos.legend.engine.plan.compilation.ExecutionPlanDependenciesFilter) ClassPathFilter(org.finos.legend.engine.shared.javaCompiler.ClassPathFilter) CompositeClassPathFilter(org.finos.legend.engine.shared.javaCompiler.CompositeClassPathFilter) MutableList(org.eclipse.collections.api.list.MutableList) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) Maps(org.eclipse.collections.api.factory.Maps) CompileException(org.codehaus.commons.compiler.CompileException) Map(java.util.Map) ExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ExecutionNode) JavaPlatformImplementation(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.JavaPlatformImplementation) ErrorResult(org.finos.legend.engine.plan.execution.result.ErrorResult) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) Logger(org.slf4j.Logger) EngineJavaCompiler(org.finos.legend.engine.shared.javaCompiler.EngineJavaCompiler) SingleExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) LogInfo(org.finos.legend.engine.shared.core.operational.logs.LogInfo) JavaVersion(org.finos.legend.engine.shared.javaCompiler.JavaVersion) Base64(java.util.Base64) List(java.util.List) JavaCompileException(org.finos.legend.engine.shared.javaCompiler.JavaCompileException) Lists(org.eclipse.collections.impl.factory.Lists) StringJavaSource(org.finos.legend.engine.shared.javaCompiler.StringJavaSource) CompiledClass(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.CompiledClass) Collections(java.util.Collections) EngineJavaCompiler(org.finos.legend.engine.shared.javaCompiler.EngineJavaCompiler) ArrayList(java.util.ArrayList) JavaClass(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.JavaClass) JavaPlatformImplementation(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.JavaPlatformImplementation) MutableList(org.eclipse.collections.api.list.MutableList) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with JavaCompileException

use of org.finos.legend.engine.shared.javaCompiler.JavaCompileException 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 JavaCompileException

use of org.finos.legend.engine.shared.javaCompiler.JavaCompileException in project legend-engine by finos.

the class ServiceTestRunner method executeTestAsserts.

@Prometheus(name = "service test execute", doc = "Execution duration summary within service test execution")
private RichServiceTestResult executeTestAsserts(SingleExecutionPlan executionPlan, List<TestContainer> asserts, RichIterable<? extends String> sqlStatements, Scope scope) throws IOException {
    long start = System.currentTimeMillis();
    if (ExecutionNodeTDSResultHelper.isResultTDS(executionPlan.rootExecutionNode) || (executionPlan.rootExecutionNode.isResultPrimitiveType() && "String".equals(executionPlan.rootExecutionNode.getDataTypeResultType()))) {
        // Java
        String packageName = "org.finos.legend.tests.generated";
        String className = "TestSuite";
        String javaCode = ServiceTestGenerationHelper.generateJavaForAsserts(asserts, this.service, this.pureModel, packageName, className);
        Class<?> assertsClass;
        RichServiceTestResult testRun;
        try {
            assertsClass = compileJavaForAsserts(packageName, className, javaCode);
        } catch (JavaCompileException e) {
            MetricsHandler.incrementErrorCount("test_execute", 0);
            throw new RuntimeException("Error compiling test asserts for " + this.service.getPath(), e);
        }
        scope.span().log("Java asserts generated and compiled");
        TestExecutionScope execScope = null;
        try {
            // Setup test database if needed
            if (sqlStatements != null) {
                execScope = TestExecutionScope.setupTestServer(sqlStatements, scope);
            }
            // Run tests
            Map<String, TestResult> results = Maps.mutable.empty();
            Map<String, Exception> assertExceptions = Maps.mutable.empty();
            for (Pair<TestContainer, Integer> tc : LazyIterate.zipWithIndex(asserts)) {
                // Build Param Map
                Map<String, Result> parameters = Maps.mutable.empty();
                if (this.service.execution instanceof PureExecution) {
                    parameters = ListIterate.zip(((PureExecution) this.service.execution).func.parameters, tc.getOne().parametersValues).toMap(p -> p.getOne().name, p -> // Condition evoked in case of studio-flow
                    p.getTwo() instanceof Collection ? new ConstantResult(ListIterate.collect(((Collection) p.getTwo()).values, v -> v.accept(new ValueSpecificationToResultVisitor()).getValue())) : // Condition evoked in case of pureIDE-flow
                    p.getTwo() instanceof PureList ? new ConstantResult(ListIterate.collect(((PureList) p.getTwo()).values, v -> v.accept(new ValueSpecificationToResultVisitor()).getValue())) : p.getTwo().accept(new ValueSpecificationToResultVisitor()));
                }
                // Execute Plan
                ExecutionState testExecutionState = new ExecutionState(parameters, Lists.mutable.withAll(executionPlan.templateFunctions), Lists.mutable.with(new RelationalStoreExecutionState(new RelationalStoreState(execScope == null ? -1 : execScope.getPort())), new InMemoryStoreExecutionState(new InMemoryStoreState()), new ServiceStoreExecutionState(new ServiceStoreState())));
                Result result = this.executor.execute(executionPlan, testExecutionState, null, null);
                org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Result<Object> pureResult = result.accept(new ResultToPureResultVisitor());
                // Execute Assert
                String testName = ServiceTestGenerationHelper.getAssertMethodName(tc.getTwo());
                scope.span().setTag(testName, resultToString(pureResult, this.pureModel.getExecutionSupport()));
                TestResult testResult;
                try {
                    Boolean assertResult = (Boolean) assertsClass.getMethod(testName, org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Result.class, ExecutionSupport.class).invoke(null, pureResult, pureModel.getExecutionSupport());
                    testResult = assertResult ? TestResult.SUCCESS : TestResult.FAILURE;
                    scope.span().setTag(testName + "_assert", assertResult);
                } catch (Exception e) {
                    StringWriter out = new StringWriter();
                    PrintWriter writer = new PrintWriter(out);
                    e.printStackTrace(writer);
                    e.printStackTrace();
                    testResult = TestResult.ERROR;
                    assertExceptions.put(testName, e);
                    scope.span().setTag(testName + "_assert", out.toString());
                }
                results.put(testName, testResult);
            }
            testRun = new RichServiceTestResult(service.getPath(), results, assertExceptions, null, executionPlan, javaCode);
            scope.span().log("Finished running tests " + results);
            MetricsHandler.observeServerOperation("test_execute", metricsContext, start, System.currentTimeMillis());
        } catch (Exception e) {
            LOGGER.error("Error running tests", e);
            MetricsHandler.incrementErrorCount("test_execute", 0);
            throw (e instanceof RuntimeException) ? (RuntimeException) e : new RuntimeException(e);
        } finally {
            if (execScope != null) {
                execScope.close();
            }
            MetricsHandler.observe("service test execute", start, System.currentTimeMillis());
        }
        return testRun;
    } else {
        return new RichServiceTestResult(this.service.getPath(), Collections.emptyMap(), Collections.emptyMap(), null, executionPlan, "");
    }
}
Also used : ServiceStoreState(org.finos.legend.engine.plan.execution.stores.service.plugin.ServiceStoreState) KeyedSingleExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.KeyedSingleExecutionTest) MultiExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.MultiExecutionTest) ExecutionNodeTDSResultHelper(org.finos.legend.engine.plan.execution.nodes.helpers.ExecutionNodeTDSResultHelper) LoggerFactory(org.slf4j.LoggerFactory) TestResult(org.finos.legend.engine.test.runner.shared.TestResult) Runtime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.Runtime) Root_meta_legend_service_metamodel_Service(org.finos.legend.pure.generated.Root_meta_legend_service_metamodel_Service) MutableList(org.eclipse.collections.api.list.MutableList) Maps(org.eclipse.collections.api.factory.Maps) EngineRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime) RichIterable(org.eclipse.collections.api.RichIterable) PlanExecutor(org.finos.legend.engine.plan.execution.PlanExecutor) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Map(java.util.Map) ConstantResult(org.finos.legend.engine.plan.execution.result.ConstantResult) LegacyRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime) Root_meta_legend_service_metamodel_SingleExecutionTest(org.finos.legend.pure.generated.Root_meta_legend_service_metamodel_SingleExecutionTest) ServiceStoreExecutionState(org.finos.legend.engine.plan.execution.stores.service.plugin.ServiceStoreExecutionState) PlanTransformer(org.finos.legend.engine.plan.generation.transformers.PlanTransformer) PrintWriter(java.io.PrintWriter) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) ServiceExecutionExtension(org.finos.legend.engine.language.pure.dsl.service.generation.extension.ServiceExecutionExtension) Prometheus(org.finos.legend.engine.shared.core.operational.prometheus.Prometheus) SingleExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan) ServiceLoader(java.util.ServiceLoader) Iterate(org.eclipse.collections.impl.utility.Iterate) InMemoryStoreExecutionState(org.finos.legend.engine.plan.execution.stores.inMemory.plugin.InMemoryStoreExecutionState) Root_meta_pure_router_extension_RouterExtension(org.finos.legend.pure.generated.Root_meta_pure_router_extension_RouterExtension) Objects(java.util.Objects) ServiceTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.ServiceTest) RelationalDatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection) List(java.util.List) JavaCompileException(org.finos.legend.engine.shared.javaCompiler.JavaCompileException) PackageableElement(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.PackageableElement) SingleExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.SingleExecutionTest) Service(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service) ObjectMapperFactory(org.finos.legend.engine.shared.core.ObjectMapperFactory) TestContainer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.TestContainer) Optional(java.util.Optional) Scope(io.opentracing.Scope) PureList(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.PureList) InMemoryStoreState(org.finos.legend.engine.plan.execution.stores.inMemory.plugin.InMemoryStoreState) Assert(org.finos.legend.engine.shared.core.operational.Assert) ExecutionState(org.finos.legend.engine.plan.execution.nodes.state.ExecutionState) KeyedExecutionParameter(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.KeyedExecutionParameter) Lists(org.eclipse.collections.api.factory.Lists) TestExecutionScope(org.finos.legend.engine.plan.execution.stores.relational.TestExecutionScope) PlanPlatform(org.finos.legend.engine.plan.platform.PlanPlatform) MutableMap(org.eclipse.collections.api.map.MutableMap) ServicePlanGenerator(org.finos.legend.engine.language.pure.dsl.service.generation.ServicePlanGenerator) JavaHelper(org.finos.legend.engine.plan.execution.nodes.helpers.platform.JavaHelper) Pair(org.eclipse.collections.api.tuple.Pair) MetricsHandler(org.finos.legend.engine.shared.core.operational.prometheus.MetricsHandler) Execution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Execution) Result(org.finos.legend.engine.plan.execution.result.Result) RelationalStoreExecutionState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState) Logger(org.slf4j.Logger) StringWriter(java.io.StringWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EngineJavaCompiler(org.finos.legend.engine.shared.javaCompiler.EngineJavaCompiler) GlobalTracer(io.opentracing.util.GlobalTracer) IOException(java.io.IOException) RelationalStoreState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreState) ListIterate(org.eclipse.collections.impl.utility.ListIterate) Collection(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Collection) PureMultiExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureMultiExecution) ExecutionSupport(org.finos.legend.pure.m3.execution.ExecutionSupport) LazyIterate(org.eclipse.collections.impl.utility.LazyIterate) PureSingleExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureSingleExecution) ExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.ExecutionPlan) LocalH2DatasourceSpecification(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.specification.LocalH2DatasourceSpecification) PureExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureExecution) Class(java.lang.Class) StringJavaSource(org.finos.legend.engine.shared.javaCompiler.StringJavaSource) Collections(java.util.Collections) org.finos.legend.pure.generated.core_relational_relational_helperFunctions_helperFunctions(org.finos.legend.pure.generated.core_relational_relational_helperFunctions_helperFunctions) ServiceStoreExecutionState(org.finos.legend.engine.plan.execution.stores.service.plugin.ServiceStoreExecutionState) InMemoryStoreExecutionState(org.finos.legend.engine.plan.execution.stores.inMemory.plugin.InMemoryStoreExecutionState) ExecutionState(org.finos.legend.engine.plan.execution.nodes.state.ExecutionState) RelationalStoreExecutionState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState) RelationalStoreExecutionState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutionState) InMemoryStoreExecutionState(org.finos.legend.engine.plan.execution.stores.inMemory.plugin.InMemoryStoreExecutionState) PureList(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.PureList) TestResult(org.finos.legend.engine.test.runner.shared.TestResult) ConstantResult(org.finos.legend.engine.plan.execution.result.ConstantResult) Result(org.finos.legend.engine.plan.execution.result.Result) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) InMemoryStoreState(org.finos.legend.engine.plan.execution.stores.inMemory.plugin.InMemoryStoreState) TestContainer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.TestContainer) TestExecutionScope(org.finos.legend.engine.plan.execution.stores.relational.TestExecutionScope) ConstantResult(org.finos.legend.engine.plan.execution.result.ConstantResult) JavaCompileException(org.finos.legend.engine.shared.javaCompiler.JavaCompileException) TestResult(org.finos.legend.engine.test.runner.shared.TestResult) JavaCompileException(org.finos.legend.engine.shared.javaCompiler.JavaCompileException) IOException(java.io.IOException) ServiceStoreExecutionState(org.finos.legend.engine.plan.execution.stores.service.plugin.ServiceStoreExecutionState) ServiceStoreState(org.finos.legend.engine.plan.execution.stores.service.plugin.ServiceStoreState) Collection(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Collection) RelationalStoreState(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreState) PureExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureExecution) Prometheus(org.finos.legend.engine.shared.core.operational.prometheus.Prometheus)

Example 4 with JavaCompileException

use of org.finos.legend.engine.shared.javaCompiler.JavaCompileException in project legend-engine by finos.

the class JavaHelper method compileImplementation.

private static void compileImplementation(JavaPlatformImplementation javaPlatformImplementation, EngineJavaCompiler javaCompiler) throws JavaCompileException {
    List<JavaClass> allJavaClasses = collectJavaClasses(javaPlatformImplementation);
    if (!allJavaClasses.isEmpty()) {
        Map<String, String> classToBytecodeMap = compileJavaClasses(allJavaClasses, javaCompiler);
        Map<String, JavaClass> classMap = allJavaClasses.stream().collect(Collectors.toMap(JavaHelper::getJavaClassFullName, x -> x));
        classToBytecodeMap.forEach((name, bytecode) -> {
            JavaClass _class = classMap.get(name);
            if (_class == null) {
                _class = createGeneratedJavaClass(name);
                if (javaPlatformImplementation.classes == null) {
                    javaPlatformImplementation.classes = FastList.newListWith(_class);
                } else {
                    javaPlatformImplementation.classes.add(_class);
                }
            }
            _class.byteCode = bytecode;
        });
    }
}
Also used : JavaClass(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.JavaClass) LoggingEventType(org.finos.legend.engine.shared.core.operational.logs.LoggingEventType) SingleFileCompiler(org.finos.legend.engine.shared.javaCompiler.SingleFileCompiler) CommonProfile(org.pac4j.core.profile.CommonProfile) ExecutionPlanDependenciesFilter(org.finos.legend.engine.plan.compilation.ExecutionPlanDependenciesFilter) ClassPathFilter(org.finos.legend.engine.shared.javaCompiler.ClassPathFilter) CompositeClassPathFilter(org.finos.legend.engine.shared.javaCompiler.CompositeClassPathFilter) MutableList(org.eclipse.collections.api.list.MutableList) FastList(org.eclipse.collections.impl.list.mutable.FastList) ArrayList(java.util.ArrayList) Maps(org.eclipse.collections.api.factory.Maps) CompileException(org.codehaus.commons.compiler.CompileException) Map(java.util.Map) ExecutionNode(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.ExecutionNode) JavaPlatformImplementation(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.JavaPlatformImplementation) ErrorResult(org.finos.legend.engine.plan.execution.result.ErrorResult) UnifiedMap(org.eclipse.collections.impl.map.mutable.UnifiedMap) Logger(org.slf4j.Logger) EngineJavaCompiler(org.finos.legend.engine.shared.javaCompiler.EngineJavaCompiler) SingleExecutionPlan(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) LogInfo(org.finos.legend.engine.shared.core.operational.logs.LogInfo) JavaVersion(org.finos.legend.engine.shared.javaCompiler.JavaVersion) Base64(java.util.Base64) List(java.util.List) JavaCompileException(org.finos.legend.engine.shared.javaCompiler.JavaCompileException) Lists(org.eclipse.collections.impl.factory.Lists) StringJavaSource(org.finos.legend.engine.shared.javaCompiler.StringJavaSource) CompiledClass(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.CompiledClass) Collections(java.util.Collections) JavaClass(org.finos.legend.engine.protocol.pure.v1.model.executionPlan.nodes.JavaClass)

Example 5 with JavaCompileException

use of org.finos.legend.engine.shared.javaCompiler.JavaCompileException in project legend-engine by finos.

the class ServiceModeling method testService.

@Prometheus(name = "service test model resolve", doc = "Model resolution duration summary within service test execution")
public List<TestResult> testService(MutableList<CommonProfile> profiles, PureModelContext context, String metricsContext) {
    try {
        long start = System.currentTimeMillis();
        PureModelContextData data = ((PureModelContextData) context).shallowCopy();
        Service service = (Service) Iterate.detect(data.getElements(), e -> e instanceof Service);
        PureModelContextData dataWithoutService = PureModelContextData.newBuilder().withOrigin(data.getOrigin()).withSerializer(data.getSerializer()).withElements(LazyIterate.select(data.getElements(), e -> e != service)).build();
        PureModel pureModel = new PureModel(dataWithoutService, profiles, deploymentMode);
        Pair<PureModelContextData, PureModel> pureModelAndData = Tuples.pair(dataWithoutService, pureModel);
        long end = System.currentTimeMillis();
        MetricsHandler.observe("service test model resolve", start, end);
        MetricsHandler.observeServerOperation("model_resolve", metricsContext, start, end);
        if (service.execution instanceof PureMultiExecution) {
            throw new UnsupportedOperationException("MultiExecutions not yet supported");
        }
        Root_meta_legend_service_metamodel_Service pureService = compileService(service, pureModel.getContext(service));
        TestRun testRun = executeTests(service, pureService, pureModelAndData, PureClientVersions.production, metricsContext);
        if (!(testRun instanceof SingleTestRun)) {
            throw new UnsupportedOperationException("Expected a single test run result");
        }
        return ((SingleTestRun) testRun).results.entrySet().stream().map(x -> new TestResult(x.getKey(), x.getValue())).collect(Collectors.toList());
    } catch (IOException | JavaCompileException e) {
        MetricsHandler.incrementErrorCount("model_resolve", 0);
        throw new RuntimeException(e);
    }
}
Also used : Maps(org.eclipse.collections.impl.factory.Maps) RichServiceTestResult(org.finos.legend.engine.test.runner.service.RichServiceTestResult) CommonProfile(org.pac4j.core.profile.CommonProfile) TestRun(org.finos.legend.engine.plan.execution.service.test.TestRun) Lists(org.eclipse.collections.api.factory.Lists) Root_meta_legend_service_metamodel_Service(org.finos.legend.pure.generated.Root_meta_legend_service_metamodel_Service) MutableList(org.eclipse.collections.api.list.MutableList) PackageableElementSecondPassBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.PackageableElementSecondPassBuilder) RichIterable(org.eclipse.collections.api.RichIterable) PlanExecutor(org.finos.legend.engine.plan.execution.PlanExecutor) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Map(java.util.Map) Tuples(org.eclipse.collections.impl.tuple.Tuples) Package(org.finos.legend.pure.m3.coreinstance.Package) Pair(org.eclipse.collections.api.tuple.Pair) MetricsHandler(org.finos.legend.engine.shared.core.operational.prometheus.MetricsHandler) PlanTransformer(org.finos.legend.engine.plan.generation.transformers.PlanTransformer) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) PureModelContext(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext) Relational(org.finos.legend.engine.plan.execution.stores.relational.plugin.Relational) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Prometheus(org.finos.legend.engine.shared.core.operational.prometheus.Prometheus) PackageableElementFirstPassBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.PackageableElementFirstPassBuilder) IOException(java.io.IOException) ServiceLoader(java.util.ServiceLoader) PureClientVersions(org.finos.legend.engine.protocol.pure.PureClientVersions) Iterate(org.eclipse.collections.impl.utility.Iterate) Collectors(java.util.stream.Collectors) JavaCode(org.finos.legend.engine.plan.execution.service.test.JavaCode) Root_meta_pure_router_extension_RouterExtension(org.finos.legend.pure.generated.Root_meta_pure_router_extension_RouterExtension) InMemory(org.finos.legend.engine.plan.execution.stores.inMemory.plugin.InMemory) SingleTestRun(org.finos.legend.engine.plan.execution.service.test.SingleTestRun) ModelManager(org.finos.legend.engine.language.pure.modelManager.ModelManager) List(java.util.List) PureMultiExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureMultiExecution) JavaCompileException(org.finos.legend.engine.shared.javaCompiler.JavaCompileException) LazyIterate(org.eclipse.collections.impl.utility.LazyIterate) TestResult(org.finos.legend.engine.plan.execution.service.test.TestResult) ServiceTestRunner(org.finos.legend.engine.test.runner.service.ServiceTestRunner) CompileContext(org.finos.legend.engine.language.pure.compiler.toPureGraph.CompileContext) Service(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service) ObjectMapperFactory(org.finos.legend.engine.shared.core.ObjectMapperFactory) DeploymentMode(org.finos.legend.engine.shared.core.deployment.DeploymentMode) PlanGeneratorExtension(org.finos.legend.engine.plan.generation.extension.PlanGeneratorExtension) ServiceStore(org.finos.legend.engine.plan.execution.stores.service.plugin.ServiceStore) PureMultiExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureMultiExecution) Root_meta_legend_service_metamodel_Service(org.finos.legend.pure.generated.Root_meta_legend_service_metamodel_Service) Service(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service) JavaCompileException(org.finos.legend.engine.shared.javaCompiler.JavaCompileException) RichServiceTestResult(org.finos.legend.engine.test.runner.service.RichServiceTestResult) TestResult(org.finos.legend.engine.plan.execution.service.test.TestResult) Root_meta_legend_service_metamodel_Service(org.finos.legend.pure.generated.Root_meta_legend_service_metamodel_Service) IOException(java.io.IOException) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) TestRun(org.finos.legend.engine.plan.execution.service.test.TestRun) SingleTestRun(org.finos.legend.engine.plan.execution.service.test.SingleTestRun) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) SingleTestRun(org.finos.legend.engine.plan.execution.service.test.SingleTestRun) Prometheus(org.finos.legend.engine.shared.core.operational.prometheus.Prometheus)

Aggregations

IOException (java.io.IOException)5 JavaCompileException (org.finos.legend.engine.shared.javaCompiler.JavaCompileException)5 List (java.util.List)4 Map (java.util.Map)4 MutableList (org.eclipse.collections.api.list.MutableList)4 Collections (java.util.Collections)3 Collectors (java.util.stream.Collectors)3 CompileException (org.codehaus.commons.compiler.CompileException)3 Maps (org.eclipse.collections.api.factory.Maps)3 ErrorResult (org.finos.legend.engine.plan.execution.result.ErrorResult)3 EngineJavaCompiler (org.finos.legend.engine.shared.javaCompiler.EngineJavaCompiler)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayList (java.util.ArrayList)2 Base64 (java.util.Base64)2 ServiceLoader (java.util.ServiceLoader)2 RichIterable (org.eclipse.collections.api.RichIterable)2 Lists (org.eclipse.collections.api.factory.Lists)2 Pair (org.eclipse.collections.api.tuple.Pair)2 Lists (org.eclipse.collections.impl.factory.Lists)2 FastList (org.eclipse.collections.impl.list.mutable.FastList)2