Search in sources :

Example 1 with LegacyRuntime

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime 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 LegacyRuntime

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

the class TestM2MGrammarCompileAndExecute method runtimeValue.

private Runtime runtimeValue(Connection connection) {
    LegacyRuntime runtime = new LegacyRuntime();
    runtime.connections = Collections.singletonList(connection);
    return runtime;
}
Also used : LegacyRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime)

Example 3 with LegacyRuntime

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime 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 LegacyRuntime

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime 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 LegacyRuntime

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime 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

LegacyRuntime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime)5 EngineRuntime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime)4 RuntimePointer (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer)4 List (java.util.List)2 RichIterable (org.eclipse.collections.api.RichIterable)2 ListIterate (org.eclipse.collections.impl.utility.ListIterate)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 StoreConnections (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.StoreConnections)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 StandardCharsets (java.nio.charset.StandardCharsets)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1