Search in sources :

Example 1 with PackageableRuntime

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

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

the class RuntimeParseTreeWalker method visitRuntime.

public PackageableRuntime visitRuntime(RuntimeParserGrammar.RuntimeContext ctx) {
    PackageableRuntime runtime = new PackageableRuntime();
    runtime.name = PureGrammarParserUtility.fromIdentifier(ctx.qualifiedName().identifier());
    runtime._package = ctx.qualifiedName().packagePath() == null ? "" : PureGrammarParserUtility.fromPath(ctx.qualifiedName().packagePath().identifier());
    runtime.sourceInformation = walkerSourceInformation.getSourceInformation(ctx);
    runtime.runtimeValue = new EngineRuntime();
    runtime.runtimeValue.sourceInformation = runtime.sourceInformation;
    RuntimeParserGrammar.MappingsContext mappingsContext = PureGrammarParserUtility.validateAndExtractRequiredField(ctx.mappings(), "mappings", runtime.sourceInformation);
    // mappings
    runtime.runtimeValue.mappings = ListIterate.collect(mappingsContext.qualifiedName(), pathCtx -> {
        PackageableElementPointer pointer = new PackageableElementPointer();
        pointer.type = PackageableElementType.MAPPING;
        pointer.path = PureGrammarParserUtility.fromQualifiedName(pathCtx.packagePath() == null ? Collections.emptyList() : pathCtx.packagePath().identifier(), pathCtx.identifier());
        pointer.sourceInformation = walkerSourceInformation.getSourceInformation(pathCtx);
        return pointer;
    });
    // connections (optional)
    RuntimeParserGrammar.ConnectionsContext connectionsContext = PureGrammarParserUtility.validateAndExtractOptionalField(ctx.connections(), "connections", runtime.sourceInformation);
    this.addConnectionsByStore(connectionsContext, runtime.runtimeValue);
    return runtime;
}
Also used : IdentifiedConnection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.IdentifiedConnection) RuntimeParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.runtime.RuntimeParserGrammar) PackageableElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement) ConnectionParser(org.finos.legend.engine.language.pure.grammar.from.connection.ConnectionParser) EngineErrorType(org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType) ParseTreeWalkerSourceInformation(org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation) StoreConnections(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.StoreConnections) ListIterate(org.eclipse.collections.impl.utility.ListIterate) SourceInformation(org.finos.legend.engine.protocol.pure.v1.model.SourceInformation) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) PackageableElementPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer) PackageableElementType(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementType) EngineRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime) ConnectionPointer(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.ConnectionPointer) ImportAwareCodeSection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.ImportAwareCodeSection) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) PureGrammarParserUtility(org.finos.legend.engine.language.pure.grammar.from.PureGrammarParserUtility) Collections(java.util.Collections) PackageableRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.PackageableRuntime) PackageableRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.PackageableRuntime) EngineRuntime(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime) RuntimeParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.runtime.RuntimeParserGrammar) PackageableElementPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer)

Example 3 with PackageableRuntime

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

Aggregations

EngineRuntime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.EngineRuntime)3 ArrayList (java.util.ArrayList)2 ListIterate (org.eclipse.collections.impl.utility.ListIterate)2 SourceInformation (org.finos.legend.engine.protocol.pure.v1.model.SourceInformation)2 EngineErrorType (org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType)2 PackageableElement (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement)2 ConnectionPointer (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.connection.ConnectionPointer)2 LegacyRuntime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.LegacyRuntime)2 PackageableRuntime (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.PackageableRuntime)2 RuntimePointer (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.runtime.RuntimePointer)2 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)2 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 ParseTreeWalkerSourceInformation (org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation)1 PureGrammarParserUtility (org.finos.legend.engine.language.pure.grammar.from.PureGrammarParserUtility)1