Search in sources :

Example 1 with RuntimePointer

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer in project legend-engine by finos.

the class ServiceTestGenerationHelper method buildRelationalTestRuntime.

private static Runtime buildRelationalTestRuntime(Runtime runtime, String mappingPath, String testDataCsv, List<String> sql) {
    if (runtime instanceof LegacyRuntime) {
        LegacyRuntime newRuntime = new LegacyRuntime();
        newRuntime.connections = ListIterate.collect(((LegacyRuntime) runtime).connections, c -> newRelationalConnection(c, testDataCsv, sql));
        return newRuntime;
    }
    if (runtime instanceof EngineRuntime) {
        EngineRuntime testRuntime = new EngineRuntime();
        PackageableElementPointer mappingPointer = new PackageableElementPointer();
        mappingPointer.type = PackageableElementType.MAPPING;
        mappingPointer.path = mappingPath;
        testRuntime.mappings.add(mappingPointer);
        testRuntime.connections = ListIterate.collect(((EngineRuntime) runtime).connections, c -> "ModelStore".equals(c.store.path) ? c : newRelationalStoreConnections(c, testDataCsv, sql));
        return testRuntime;
    }
    if (runtime instanceof RuntimePointer) {
        return runtime;
    }
    throw new UnsupportedOperationException("Unsupported runtime type: " + runtime.getClass().getName());
}
Also used : DatabaseType(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseType) Runtime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.Runtime) MutableList(org.eclipse.collections.api.list.MutableList) ProcessorSupport(org.finos.legend.pure.m3.navigation.ProcessorSupport) PackageableElementPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer) EngineRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime) MediaType(javax.ws.rs.core.MediaType) RichIterable(org.eclipse.collections.api.RichIterable) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) PackageableConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.PackageableConnection) Map(java.util.Map) Tuples(org.eclipse.collections.impl.tuple.Tuples) LegacyRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime) TypeReference(com.fasterxml.jackson.core.type.TypeReference) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) IdentifiedConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.IdentifiedConnection) StoreConnections(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.StoreConnections) ProcessingContext(org.finos.legend.engine.language.pure.compiler.toPureGraph.ProcessingContext) ServiceLoader(java.util.ServiceLoader) Iterate(org.eclipse.collections.impl.utility.Iterate) StandardCharsets(java.nio.charset.StandardCharsets) PackageableElementType(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementType) RelationalDatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection) Base64(java.util.Base64) List(java.util.List) DatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseConnection) Lists(org.eclipse.collections.impl.factory.Lists) SingleExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.SingleExecutionTest) 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) TestContainer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.TestContainer) Optional(java.util.Optional) XmlModelConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.XmlModelConnection) PackageableElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement) ModelChainConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.ModelChainConnection) ProcessorContext(org.finos.legend.pure.runtime.java.compiled.generation.ProcessorContext) ExternalFormatConnection(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatConnection) UrlStreamExternalSource(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.UrlStreamExternalSource) Function(java.util.function.Function) ConnectionFactoryExtension(org.finos.legend.engine.protocol.pure.v1.extension.ConnectionFactoryExtension) HelperRuntimeBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.HelperRuntimeBuilder) Pair(org.eclipse.collections.api.tuple.Pair) TestDatabaseAuthenticationStrategy(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.authentication.TestDatabaseAuthenticationStrategy) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) JsonModelConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.JsonModelConnection) ValueSpecificationBuilder(org.finos.legend.engine.language.pure.compiler.toPureGraph.ValueSpecificationBuilder) ListIterate(org.eclipse.collections.impl.utility.ListIterate) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) RuntimePointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer) InstanceValue(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.InstanceValue) Connection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.Connection) LazyIterate(org.eclipse.collections.impl.utility.LazyIterate) PureSingleExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureSingleExecution) ConnectionPointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.ConnectionPointer) LocalH2DatasourceSpecification(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.specification.LocalH2DatasourceSpecification) DataProtocolHandler(org.finos.legend.engine.shared.core.url.DataProtocolHandler) org.finos.legend.pure.generated.core_relational_relational_helperFunctions_helperFunctions(org.finos.legend.pure.generated.core_relational_relational_helperFunctions_helperFunctions) PackageableRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.PackageableRuntime) ValueSpecificationProcessor(org.finos.legend.pure.runtime.java.compiled.generation.processors.valuespecification.ValueSpecificationProcessor) RuntimePointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer) EngineRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime) PackageableElementPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer) LegacyRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime)

Example 2 with RuntimePointer

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer in project legend-engine by finos.

the class TestRuntimeGenerationForServiceTests method testRuntimeGenerationForServiceWithRuntimePointer.

@Test
public void testRuntimeGenerationForServiceWithRuntimePointer() {
    String pureGrammarWithModelChainConnection = "###Relational\n" + "Database test::relationalDB\n" + "(\n" + "  Table Person\n" + "  (\n" + "    fullname VARCHAR(1000) PRIMARY KEY\n" + "  )\n" + ")\n" + "\n" + "\n" + "###Service\n" + "Service test::serviceWithRuntimePointer\n" + "{\n" + "  pattern: '/garprat/test/fromStudio/';\n" + "  owners:\n" + "  [\n" + "    'garprat'\n" + "  ];\n" + "  documentation: '';\n" + "  autoActivateUpdates: false;\n" + "  execution: Single\n" + "  {\n" + "    query: |test::Person.all()->project([f|$f.fullName], ['fullName']);\n" + "    mapping: test::relationalMapping;\n" + "    runtime: test::runtimePointer;\n" + "  }\n" + "  test: Single\n" + "  {\n" + "    data: 'default\\nPerson\\nfullname\\nPierre DeBelen\\n';\n" + "    asserts:\n" + "    [\n" + "    ];\n" + "  }\n" + "}\n" + "\n" + "\n" + "###Pure\n" + "Class test::Person\n" + "{\n" + "  fullName: String[1];\n" + "}\n" + "\n" + "\n" + "###Mapping\n" + "Mapping test::relationalMapping\n" + "(\n" + "  test::Person: Relational\n" + "  {\n" + "    ~primaryKey\n" + "    (\n" + "      [test::relationalDB]Person.fullname\n" + "    )\n" + "    ~mainTable [test::relationalDB]Person\n" + "    fullName: [test::relationalDB]Person.fullname\n" + "  }\n" + ")\n" + "\n" + "###Connection\n" + "RelationalDatabaseConnection test::mySimpleConnection\n" + "{\n" + "  store: test::relationalDB;\n" + "  type: MemSQL;\n" + "  specification: Static\n" + "  {\n" + "    name: 'memsql_person_data';\n" + "    host: 'myserver_url';\n" + "    port: 80;\n" + "  };\n" + "  auth: DefaultH2;\n" + "}\n" + "\n" + "\n" + "###Runtime\n" + "Runtime test::runtimePointer\n" + "{\n" + "  mappings:\n" + "  [\n" + "     test::relationalMapping\n" + "  ];\n" + "  connections:\n" + "  [\n" + "    test::relationalDB:\n" + "    [\n" + "      connection_1: test::mySimpleConnection\n" + "    ]\n" + "  ];\n" + "}\n";
    PureModelContextData contextData = PureGrammarParser.newInstance().parseModel(pureGrammarWithModelChainConnection);
    PureModel pureModel = new PureModel(contextData, null, DeploymentMode.TEST);
    Service service = contextData.getElementsOfType(Service.class).get(0);
    EngineRuntime testRuntime = (EngineRuntime) ServiceTestGenerationHelper.buildSingleExecutionTestRuntime((PureSingleExecution) service.execution, (SingleExecutionTest) service.test, contextData, pureModel);
    Assert.assertEquals(testRuntime.connections.size(), 1);
}
Also used : PureSingleExecution(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureSingleExecution) SingleExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.SingleExecutionTest) EngineRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime) Service(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) SingleExecutionTest(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.SingleExecutionTest) Test(org.junit.Test)

Example 3 with RuntimePointer

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer in project legend-engine by finos.

the class ServiceTestGenerationHelper method resolveRuntime.

private static EngineRuntime resolveRuntime(Runtime runtime, PureModelContextData pureModelContextData) {
    if (runtime instanceof EngineRuntime) {
        return (EngineRuntime) runtime;
    }
    if (runtime instanceof LegacyRuntime) {
        return ((LegacyRuntime) runtime).toEngineRuntime();
    }
    if (runtime instanceof RuntimePointer) {
        String runtimeFullPath = ((RuntimePointer) runtime).runtime;
        PackageableElement found = Iterate.detect(pureModelContextData.getElements(), e -> runtimeFullPath.equals(e.getPath()));
        if (!(found instanceof PackageableRuntime)) {
            throw new RuntimeException("Can't find runtime '" + runtimeFullPath + "'");
        }
        return ((PackageableRuntime) found).runtimeValue;
    }
    throw new UnsupportedOperationException("Unsupported runtime type: " + runtime.getClass().getName());
}
Also used : PackageableElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement) RuntimePointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer) PackageableRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.PackageableRuntime) EngineRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime) LegacyRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime)

Example 4 with RuntimePointer

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer in project legend-engine by finos.

the class TestExecutionScope method buildTestRuntime.

public static Runtime buildTestRuntime(Runtime runtime, String testData, List<String> setupSqls) {
    if (runtime instanceof LegacyRuntime) {
        LegacyRuntime newRuntime = new LegacyRuntime();
        newRuntime.connections = ListIterate.collect(((LegacyRuntime) runtime).connections, connection -> {
            if (connection instanceof ModelChainConnection) {
                return connection;
            }
            return ConnectionManagerSelector.transformToTestConnectionSpecification(connection, testData, setupSqls);
        });
        return newRuntime;
    } else if (runtime instanceof EngineRuntime) {
        EngineRuntime newRuntime = new EngineRuntime();
        newRuntime.connections = ListIterate.collect(((EngineRuntime) runtime).connections, storeConnections -> {
            StoreConnections newStoreConnections = new StoreConnections();
            newStoreConnections.store = storeConnections.store;
            newStoreConnections.storeConnections = ListIterate.collect(storeConnections.storeConnections, identifiedConnection -> {
                if (identifiedConnection.connection instanceof ModelChainConnection) {
                    return identifiedConnection;
                }
                IdentifiedConnection newIdentifiedConnection = new IdentifiedConnection();
                newIdentifiedConnection.id = identifiedConnection.id;
                newIdentifiedConnection.connection = ConnectionManagerSelector.transformToTestConnectionSpecification(identifiedConnection.connection, testData, setupSqls);
                return newIdentifiedConnection;
            });
            return newStoreConnections;
        });
        return newRuntime;
    } else if (runtime instanceof RuntimePointer) {
        return runtime;
    }
    throw new UnsupportedOperationException();
}
Also used : IdentifiedConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.IdentifiedConnection) Server(org.h2.tools.Server) DynamicPortGenerator(org.finos.legend.engine.shared.core.port.DynamicPortGenerator) Connection(java.sql.Connection) ModelChainConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.ModelChainConnection) JdbcSQLNonTransientConnectionException(org.h2.jdbc.JdbcSQLNonTransientConnectionException) TemporaryTestDbConfiguration(org.finos.legend.engine.plan.execution.stores.relational.config.TemporaryTestDbConfiguration) StoreConnections(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.StoreConnections) CheckedProcedure(org.eclipse.collections.impl.block.procedure.checked.CheckedProcedure) IOException(java.io.IOException) ListIterate(org.eclipse.collections.impl.utility.ListIterate) Runtime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.Runtime) RelationalExecutionConfiguration(org.finos.legend.engine.plan.execution.stores.relational.config.RelationalExecutionConfiguration) ConnectionManagerSelector(org.finos.legend.engine.plan.execution.stores.relational.connection.manager.ConnectionManagerSelector) RuntimePointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer) EngineRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime) SQLException(java.sql.SQLException) List(java.util.List) RichIterable(org.eclipse.collections.api.RichIterable) Closeable(java.io.Closeable) Statement(java.sql.Statement) LegacyRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime) Scope(io.opentracing.Scope) StoreConnections(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.StoreConnections) RuntimePointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer) EngineRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime) ModelChainConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.ModelChainConnection) LegacyRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime) IdentifiedConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.IdentifiedConnection)

Example 5 with RuntimePointer

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer in project legend-engine by finos.

the class HelperRuntimeBuilder method buildPureRuntime.

public static org.finos.legend.pure.m3.coreinstance.meta.pure.runtime.Runtime buildPureRuntime(Runtime runtime, CompileContext context) {
    if (runtime == null) {
        return null;
    }
    if (runtime instanceof LegacyRuntime) {
        LegacyRuntime legacyRuntime = (LegacyRuntime) runtime;
        org.finos.legend.pure.m3.coreinstance.meta.pure.runtime.Runtime pureRuntime = new Root_meta_pure_runtime_Runtime_Impl("Root::meta::pure::runtime::Runtime");
        ListIterate.forEach(legacyRuntime.connections, connection -> pureRuntime._connectionsAdd(connection.accept(new ConnectionFirstPassBuilder(context))));
        return pureRuntime;
    }
    if (runtime instanceof EngineRuntime) {
        return buildEngineRuntime(((EngineRuntime) runtime), context);
    } else if (runtime instanceof RuntimePointer) {
        return context.resolveRuntime(((RuntimePointer) runtime).runtime, ((RuntimePointer) runtime).sourceInformation);
    }
    throw new UnsupportedOperationException();
}
Also used : RuntimePointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer) Root_meta_pure_runtime_Runtime_Impl(org.finos.legend.pure.generated.Root_meta_pure_runtime_Runtime_Impl) EngineRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime) LegacyRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime)

Aggregations

EngineRuntime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime)5 RuntimePointer (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer)5 LegacyRuntime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime)4 List (java.util.List)2 RichIterable (org.eclipse.collections.api.RichIterable)2 ListIterate (org.eclipse.collections.impl.utility.ListIterate)2 PureModel (org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel)2 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)2 PackageableElement (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement)2 IdentifiedConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.IdentifiedConnection)2 PackageableRuntime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.PackageableRuntime)2 Runtime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.Runtime)2 PureSingleExecution (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.PureSingleExecution)2 Service (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.Service)2 SingleExecutionTest (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.service.SingleExecutionTest)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 Scope (io.opentracing.Scope)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1