Search in sources :

Example 1 with IdentifiedConnection

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

the class ServiceTestGenerationHelper method newRelationalIdentifiedConnection.

private static IdentifiedConnection newRelationalIdentifiedConnection(IdentifiedConnection identifiedConnection, String testDataCsv, List<String> sql) {
    Connection newConnection = newRelationalConnection(identifiedConnection.connection, testDataCsv, sql);
    if (newConnection == identifiedConnection.connection) {
        return identifiedConnection;
    }
    IdentifiedConnection newIdentifiedConnection = new IdentifiedConnection();
    newIdentifiedConnection.id = identifiedConnection.id;
    newIdentifiedConnection.connection = newConnection;
    return newIdentifiedConnection;
}
Also used : PackageableConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.PackageableConnection) IdentifiedConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.IdentifiedConnection) RelationalDatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection) DatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseConnection) XmlModelConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.XmlModelConnection) ModelChainConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.ModelChainConnection) ExternalFormatConnection(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatConnection) JsonModelConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.JsonModelConnection) Connection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.Connection) IdentifiedConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.IdentifiedConnection)

Example 2 with IdentifiedConnection

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

the class ServiceTestGenerationHelper method hasModelChainConnection.

private static boolean hasModelChainConnection(Runtime runtime, PureModelContextData pureModelContextData) {
    EngineRuntime engineRuntime = resolveRuntime(runtime, pureModelContextData);
    List<StoreConnections> storeConnections = engineRuntime.connections;
    for (StoreConnections s : storeConnections) {
        List<IdentifiedConnection> identifiedConnection = s.storeConnections;
        for (IdentifiedConnection ic : identifiedConnection) {
            if (ic.connection instanceof ModelChainConnection || (("ModelStore").equals(s.store.path) && ic.connection instanceof ConnectionPointer)) {
                return true;
            }
        }
    }
    return false;
}
Also used : StoreConnections(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.StoreConnections) 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) IdentifiedConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.IdentifiedConnection) ConnectionPointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.ConnectionPointer)

Example 3 with IdentifiedConnection

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

the class LegacyRuntime method toEngineRuntime.

@JsonIgnore
public EngineRuntime toEngineRuntime() {
    EngineRuntime engineRuntime = new EngineRuntime();
    AtomicInteger counter = new AtomicInteger(1);
    engineRuntime.mappings = this.mappings;
    ListIterate.forEach(this.connections, connection -> {
        IdentifiedConnection identifiedConnection = new IdentifiedConnection();
        // adhoc connection id creation
        identifiedConnection.id = "connection_" + counter;
        identifiedConnection.connection = connection;
        counter.getAndIncrement();
        // find the current connections by store and update
        if (engineRuntime.getStoreConnections(connection.element) != null) {
            engineRuntime.getStoreConnections(connection.element).storeConnections.add(identifiedConnection);
        } else {
            StoreConnections storeConnections = new StoreConnections();
            storeConnections.storeConnections.add(identifiedConnection);
            PackageableElementPointer storePointer = new PackageableElementPointer();
            storePointer.type = PackageableElementType.STORE;
            storePointer.path = connection.element;
            storeConnections.store = storePointer;
            engineRuntime.connections.add(storeConnections);
        }
    });
    return engineRuntime;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PackageableElementPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Example 4 with IdentifiedConnection

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

the class HelperRuntimeBuilder method buildEngineRuntime.

public static org.finos.legend.pure.m3.coreinstance.meta.pure.runtime.Runtime buildEngineRuntime(EngineRuntime engineRuntime, CompileContext context) {
    if (engineRuntime.mappings.isEmpty()) {
        throw new EngineException("Runtime must cover at least one mapping", engineRuntime.sourceInformation, EngineErrorType.COMPILATION);
    }
    // verify if each mapping associated with the PackageableRuntime exists
    List<Mapping> mappings = engineRuntime.mappings.stream().map(mappingPointer -> context.resolveMapping(mappingPointer.path, mappingPointer.sourceInformation)).collect(Collectors.toList());
    // build connections
    List<Connection> connections = new ArrayList<>();
    Set<String> ids = new HashSet<>();
    ListIterate.forEach(engineRuntime.connections, storeConnections -> {
        if (!storeConnections.store.path.equals("ModelStore")) {
            // verify stores used for indexing exist
            context.resolveStore(storeConnections.store.path, storeConnections.store.sourceInformation);
        }
        ListIterate.forEach(storeConnections.storeConnections, identifiedConnection -> {
            // ID must be unique across all connections of the runtime
            if (ids.contains(identifiedConnection.id)) {
                throw new EngineException("Runtime connection with ID '" + identifiedConnection.id + "' has already been specified", identifiedConnection.sourceInformation, EngineErrorType.COMPILATION);
            } else {
                ids.add(identifiedConnection.id);
            }
            if (identifiedConnection.connection instanceof ConnectionPointer) {
                ConnectionPointer pointer = (ConnectionPointer) identifiedConnection.connection;
                Store connectionStore = HelperRuntimeBuilder.getConnectionStore(context.resolveConnection(pointer.connection, pointer.sourceInformation));
                String connectionStorePath = HelperModelBuilder.getElementFullPath(connectionStore, context.pureModel.getExecutionSupport());
                if (!storeConnections.store.path.equals(connectionStorePath)) {
                    throw new EngineException("Connection pointer for store '" + connectionStorePath + "' should not be indexed to store '" + storeConnections.store.path + "'", pointer.sourceInformation, EngineErrorType.COMPILATION);
                }
                connections.add(identifiedConnection.connection);
            } else if (storeConnections.store.path.equals(identifiedConnection.connection.element)) {
                connections.add(identifiedConnection.connection);
            } else if (identifiedConnection.connection.element == null) {
                identifiedConnection.connection.element = storeConnections.store.path;
                identifiedConnection.connection.elementSourceInformation = identifiedConnection.connection.sourceInformation;
                connections.add(identifiedConnection.connection);
            } else {
                throw new EngineException("Connection for store '" + identifiedConnection.connection.element + "' should not be indexed to store '" + storeConnections.store.path + "'", identifiedConnection.connection.sourceInformation, EngineErrorType.COMPILATION);
            }
        });
    });
    // convert EngineRuntime with connection as a map indexes by store to Pure runtime which only contains an array of connections
    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(connections, connection -> {
        final org.finos.legend.pure.m3.coreinstance.meta.pure.runtime.Connection pureConnection = connection.accept(new ConnectionFirstPassBuilder(context));
        connection.accept(new ConnectionSecondPassBuilder(context, pureConnection));
        pureRuntime._connectionsAdd(pureConnection);
    });
    // verify runtime mapping coverage
    checkRuntimeMappingCoverage(pureRuntime, mappings, context, engineRuntime.sourceInformation);
    return pureRuntime;
}
Also used : EngineErrorType(org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType) Set(java.util.Set) ListIterate(org.eclipse.collections.impl.utility.ListIterate) SourceInformation(org.finos.legend.engine.protocol.pure.v1.model.SourceInformation) Runtime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.Runtime) StringUtils(org.apache.commons.lang3.StringUtils) Root_meta_external_shared_format_binding_Binding(org.finos.legend.pure.generated.Root_meta_external_shared_format_binding_Binding) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RuntimePointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer) EngineRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime) List(java.util.List) Connection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.Connection) Mapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping) Store(org.finos.legend.pure.m3.coreinstance.meta.pure.store.Store) ConnectionPointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.ConnectionPointer) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) LegacyRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime) PureInstanceSetImplementation(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.modelToModel.PureInstanceSetImplementation) Root_meta_pure_runtime_Runtime_Impl(org.finos.legend.pure.generated.Root_meta_pure_runtime_Runtime_Impl) Root_meta_pure_runtime_Runtime_Impl(org.finos.legend.pure.generated.Root_meta_pure_runtime_Runtime_Impl) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) Connection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.Connection) ArrayList(java.util.ArrayList) Store(org.finos.legend.pure.m3.coreinstance.meta.pure.store.Store) Mapping(org.finos.legend.pure.m3.coreinstance.meta.pure.mapping.Mapping) ConnectionPointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.ConnectionPointer) HashSet(java.util.HashSet)

Example 5 with IdentifiedConnection

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

the class ServiceTestGenerationHelper method newTestIdentifiedConnection.

private static IdentifiedConnection newTestIdentifiedConnection(IdentifiedConnection identifiedConnection, StoreConnections storeConnections, Function<String, String> testDataAccessor, PureModelContextData pureModelContextData, EngineRuntime runtime, String mappingPath, PureModel pureModel, String testData) {
    Connection connection = identifiedConnection.connection;
    IdentifiedConnection newIdentifiedConnection = new IdentifiedConnection();
    newIdentifiedConnection.id = identifiedConnection.id;
    String idTestDataAccessorResult = testDataAccessor.apply(identifiedConnection.id);
    identifiedConnection.connection = getTestConnection(connection, runtime, mappingPath, Tuples.pair(pureModelContextData, pureModel), storeConnections, testDataAccessor, testData, idTestDataAccessorResult);
    return identifiedConnection;
}
Also used : PackageableConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.PackageableConnection) IdentifiedConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.IdentifiedConnection) RelationalDatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection) DatabaseConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseConnection) XmlModelConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.XmlModelConnection) ModelChainConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.ModelChainConnection) ExternalFormatConnection(org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatConnection) JsonModelConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.JsonModelConnection) Connection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.Connection) IdentifiedConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.IdentifiedConnection)

Aggregations

IdentifiedConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.IdentifiedConnection)5 ModelChainConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.ModelChainConnection)4 Connection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.Connection)3 ConnectionPointer (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.ConnectionPointer)3 EngineRuntime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime)3 StoreConnections (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.StoreConnections)3 List (java.util.List)2 ListIterate (org.eclipse.collections.impl.utility.ListIterate)2 SourceInformation (org.finos.legend.engine.protocol.pure.v1.model.SourceInformation)2 PackageableElementPointer (org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer)2 PackageableConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.PackageableConnection)2 LegacyRuntime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime)2 Runtime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.Runtime)2 RuntimePointer (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer)2 JsonModelConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.JsonModelConnection)2 XmlModelConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.modelToModel.connection.XmlModelConnection)2 DatabaseConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.DatabaseConnection)2 RelationalDatabaseConnection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.store.relational.connection.RelationalDatabaseConnection)2 ExternalFormatConnection (org.finos.legend.engine.protocol.pure.v1.packageableElement.external.shared.ExternalFormatConnection)2 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)2