Search in sources :

Example 1 with ModelManager

use of org.finos.legend.engine.language.pure.modelManager.ModelManager in project legend-engine by finos.

the class TestM2MGrammarCompileAndExecute method runTest.

private Response runTest(ExecuteInput input) {
    ModelManager modelManager = new ModelManager(DeploymentMode.TEST);
    PlanExecutor executor = PlanExecutor.newPlanExecutor(InMemory.build());
    HttpServletRequest request = (HttpServletRequest) Proxy.newProxyInstance(getClass().getClassLoader(), new java.lang.Class<?>[] { HttpServletRequest.class }, new ReflectiveInvocationHandler(new Request()));
    // Should use: core_pure_extensions_extension.Root_meta_pure_router_extension_defaultExtensions__RouterExtension_MANY_(modelManager.)
    Response result = new Execute(modelManager, executor, (PureModel pureModel) -> Lists.mutable.empty(), LegendPlanTransformers.transformers).execute(request, input, SerializationFormat.defaultFormat, null, null);
    Assert.assertEquals(200, result.getStatus());
    return result;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Response(javax.ws.rs.core.Response) Execute(org.finos.legend.engine.query.pure.api.Execute) PlanExecutor(org.finos.legend.engine.plan.execution.PlanExecutor) HttpServletRequest(javax.servlet.http.HttpServletRequest) BeforeClass(org.junit.BeforeClass) Class(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Class) ModelManager(org.finos.legend.engine.language.pure.modelManager.ModelManager) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel)

Example 2 with ModelManager

use of org.finos.legend.engine.language.pure.modelManager.ModelManager in project legend-engine by finos.

the class Server method run.

@Override
public void run(ServerConfiguration serverConfiguration, Environment environment) {
    loadVaults(serverConfiguration.vaults);
    this.environment = environment;
    DeploymentStateAndVersions.DEPLOYMENT_MODE = serverConfiguration.deployment.mode;
    SDLCLoader sdlcLoader = new SDLCLoader(serverConfiguration.metadataserver, null);
    ModelManager modelManager = new ModelManager(serverConfiguration.deployment.mode, sdlcLoader);
    ChainFixingFilterHandler.apply(environment.getApplicationContext(), serverConfiguration.filterPriorities);
    RelationalStoreExecutor relationalStoreExecutor = (RelationalStoreExecutor) Relational.build(serverConfiguration.relationalexecution);
    PlanExecutor planExecutor = PlanExecutor.newPlanExecutor(relationalStoreExecutor, ServiceStore.build(), InMemory.build());
    // Session Management
    SessionTracker sessionTracker = new SessionTracker();
    environment.servlets().setSessionHandler(new SessionHandler());
    environment.servlets().addServletListeners(sessionTracker);
    environment.jersey().register(new SessionInfo(sessionTracker));
    // API & Swagger
    environment.jersey().setUrlPattern("/api/*");
    ServerShared.registerSwagger(environment, serverConfiguration.swagger);
    // Server
    environment.jersey().register(new Info(serverConfiguration.deployment, serverConfiguration.opentracing));
    environment.jersey().register(new CurrentUser());
    environment.jersey().register(new Memory());
    environment.jersey().register(new RelationalExecutorInformation());
    // Grammar
    environment.jersey().register(new GrammarToJson());
    environment.jersey().register(new JsonToGrammar());
    environment.jersey().register(new RelationalOperationElementGrammarToJson());
    environment.jersey().register(new RelationalOperationElementJsonToGrammar());
    environment.jersey().register(new TransformGrammarToJson());
    environment.jersey().register(new TransformJsonToGrammar());
    environment.jersey().register(new TransformRelationalOperationElementGrammarToJson());
    environment.jersey().register(new TransformRelationalOperationElementJsonToGrammar());
    // Relational
    environment.jersey().register(new SchemaExplorationApi(modelManager, relationalStoreExecutor));
    // Compilation
    environment.jersey().register((DynamicFeature) (resourceInfo, context) -> context.register(new InflateInterceptor()));
    environment.jersey().register(new Compile(modelManager));
    // Generation and Import
    MutableList<GenerationExtension> genExtensions = Iterate.addAllTo(ServiceLoader.load(GenerationExtension.class), Lists.mutable.empty());
    environment.jersey().register(new CodeGenerators(modelManager, genExtensions.select(p -> p.getMode() == GenerationMode.Code).collect(GenerationExtension::getGenerationDescription).select(Objects::nonNull)));
    environment.jersey().register(new CodeImports(modelManager, genExtensions.select(p -> p.getMode() == GenerationMode.Code).collect(GenerationExtension::getImportDescription).select(Objects::nonNull)));
    environment.jersey().register(new SchemaGenerators(modelManager, genExtensions.select(p -> p.getMode() == GenerationMode.Schema).collect(GenerationExtension::getGenerationDescription).select(Objects::nonNull)));
    environment.jersey().register(new SchemaImports(modelManager, genExtensions.select(p -> p.getMode() == GenerationMode.Schema).collect(GenerationExtension::getImportDescription).select(Objects::nonNull)));
    genExtensions.forEach(p -> environment.jersey().register(p.getService(modelManager)));
    // Execution
    MutableList<PlanGeneratorExtension> generatorExtensions = Lists.mutable.withAll(ServiceLoader.load(PlanGeneratorExtension.class));
    Function<PureModel, RichIterable<? extends Root_meta_pure_router_extension_RouterExtension>> routerExtensions = (PureModel pureModel) -> generatorExtensions.flatCollect(e -> e.getExtraRouterExtensions(pureModel));
    environment.jersey().register(new Execute(modelManager, planExecutor, routerExtensions, generatorExtensions.flatCollect(PlanGeneratorExtension::getExtraPlanTransformers)));
    environment.jersey().register(new ExecutePlanStrategic(planExecutor));
    environment.jersey().register(new ExecutePlanLegacy(planExecutor));
    // GraphQL
    environment.jersey().register(new GraphQLGrammar());
    environment.jersey().register(new GraphQLExecute(modelManager, planExecutor, serverConfiguration.metadataserver, generatorExtensions.flatCollect(PlanGeneratorExtension::getExtraPlanTransformers)));
    environment.jersey().register(new GraphQLDebug(modelManager, serverConfiguration.metadataserver));
    // Service
    environment.jersey().register(new ServiceModelingApi(modelManager, serverConfiguration.deployment.mode));
    // Query
    environment.jersey().register(new ApplicationQuery(ApplicationQueryConfiguration.getMongoClient()));
    // Global
    environment.jersey().register(new JsonInformationExceptionMapper());
    environment.jersey().register(new CatchAllExceptionMapper());
    // External Format
    environment.jersey().register(new ExternalFormats(modelManager));
    enableCors(environment);
}
Also used : SessionHandler(org.eclipse.jetty.server.session.SessionHandler) CurrentUser(org.finos.legend.engine.server.core.api.CurrentUser) ExecutePlanStrategic(org.finos.legend.engine.plan.execution.api.ExecutePlanStrategic) Memory(org.finos.legend.engine.server.core.api.Memory) SchemaExplorationApi(org.finos.legend.engine.plan.execution.stores.relational.connection.api.schema.SchemaExplorationApi) LegendPac4jBundle(org.finos.legend.server.pac4j.LegendPac4jBundle) MutableList(org.eclipse.collections.api.list.MutableList) SwaggerBundleConfiguration(io.federecio.dropwizard.swagger.SwaggerBundleConfiguration) RelationalOperationElementGrammarToJson(org.finos.legend.engine.language.pure.grammar.api.relationalOperationElement.RelationalOperationElementGrammarToJson) ExecutePlanLegacy(org.finos.legend.engine.plan.execution.api.ExecutePlanLegacy) RichIterable(org.eclipse.collections.api.RichIterable) PlanExecutor(org.finos.legend.engine.plan.execution.PlanExecutor) GenerationMode(org.finos.legend.engine.external.shared.format.extension.GenerationMode) Info(org.finos.legend.engine.server.core.api.Info) GraphQLGrammar(org.finos.legend.engine.query.graphQL.api.grammar.GraphQLGrammar) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) SchemaGenerators(org.finos.legend.engine.external.shared.format.generations.loaders.SchemaGenerators) RelationalExecutorInformation(org.finos.legend.engine.plan.execution.stores.relational.api.RelationalExecutorInformation) EnumSet(java.util.EnumSet) Application(io.dropwizard.Application) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) GraphQLDebug(org.finos.legend.engine.query.graphQL.api.debug.GraphQLDebug) CollectorRegistry(io.prometheus.client.CollectorRegistry) Execute(org.finos.legend.engine.query.pure.api.Execute) ServiceLoader(java.util.ServiceLoader) FilterRegistration(javax.servlet.FilterRegistration) SwaggerBundle(io.federecio.dropwizard.swagger.SwaggerBundle) Iterate(org.eclipse.collections.impl.utility.Iterate) Root_meta_pure_router_extension_RouterExtension(org.finos.legend.pure.generated.Root_meta_pure_router_extension_RouterExtension) ApplicationQuery(org.finos.legend.engine.application.query.api.ApplicationQuery) Objects(java.util.Objects) AssetsBundle(io.dropwizard.assets.AssetsBundle) DynamicFeature(javax.ws.rs.container.DynamicFeature) ExternalFormats(org.finos.legend.engine.external.shared.format.model.api.ExternalFormats) List(java.util.List) RelationalStoreExecutor(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutor) CodeGenerators(org.finos.legend.engine.external.shared.format.generations.loaders.CodeGenerators) TransformRelationalOperationElementGrammarToJson(org.finos.legend.engine.language.pure.grammar.api.relationalOperationElement.TransformRelationalOperationElementGrammarToJson) SDLCLoader(org.finos.legend.engine.language.pure.modelManager.sdlc.SDLCLoader) TransformRelationalOperationElementJsonToGrammar(org.finos.legend.engine.language.pure.grammar.api.relationalOperationElement.TransformRelationalOperationElementJsonToGrammar) ObjectMapperFactory(org.finos.legend.engine.shared.core.ObjectMapperFactory) GraphQLExecute(org.finos.legend.engine.query.graphQL.api.execute.GraphQLExecute) InflateInterceptor(org.finos.legend.engine.shared.core.operational.http.InflateInterceptor) TransformGrammarToJson(org.finos.legend.engine.language.pure.grammar.api.grammarToJson.TransformGrammarToJson) PlanGeneratorExtension(org.finos.legend.engine.plan.generation.extension.PlanGeneratorExtension) SchemaImports(org.finos.legend.engine.external.shared.format.imports.loaders.SchemaImports) ServiceStore(org.finos.legend.engine.plan.execution.stores.service.plugin.ServiceStore) LegendDefaultDatabaseAuthenticationFlowProviderConfiguration(org.finos.legend.engine.authentication.LegendDefaultDatabaseAuthenticationFlowProviderConfiguration) CatchAllExceptionMapper(org.finos.legend.engine.server.core.exceptionMappers.CatchAllExceptionMapper) Bootstrap(io.dropwizard.setup.Bootstrap) Function(org.eclipse.collections.api.block.function.Function) GrammarToJson(org.finos.legend.engine.language.pure.grammar.api.grammarToJson.GrammarToJson) Lists(org.eclipse.collections.api.factory.Lists) Vault(org.finos.legend.engine.shared.core.vault.Vault) SessionAttributeBundle(org.finos.legend.engine.server.core.session.SessionAttributeBundle) ServiceModelingApi(org.finos.legend.engine.plan.execution.service.api.ServiceModelingApi) RelationalOperationElementJsonToGrammar(org.finos.legend.engine.language.pure.grammar.api.relationalOperationElement.RelationalOperationElementJsonToGrammar) JsonToGrammar(org.finos.legend.engine.language.pure.grammar.api.jsonToGrammar.JsonToGrammar) CrossOriginFilter(org.eclipse.jetty.servlets.CrossOriginFilter) Environment(io.dropwizard.setup.Environment) CodeImports(org.finos.legend.engine.external.shared.format.imports.loaders.CodeImports) Logger(org.slf4j.Logger) Relational(org.finos.legend.engine.plan.execution.stores.relational.plugin.Relational) GenerationExtension(org.finos.legend.engine.external.shared.format.extension.GenerationExtension) ServerShared(org.finos.legend.engine.server.core.ServerShared) JsonInformationExceptionMapper(org.finos.legend.engine.server.core.exceptionMappers.JsonInformationExceptionMapper) VaultConfiguration(org.finos.legend.engine.shared.core.vault.VaultConfiguration) ListIterate(org.eclipse.collections.impl.utility.ListIterate) SessionInfo(org.finos.legend.engine.server.core.session.api.SessionInfo) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) InMemory(org.finos.legend.engine.plan.execution.stores.inMemory.plugin.InMemory) MultiPartBundle(io.dropwizard.forms.MultiPartBundle) ApplicationQueryConfiguration(org.finos.legend.engine.application.query.configuration.ApplicationQueryConfiguration) TransformJsonToGrammar(org.finos.legend.engine.language.pure.grammar.api.jsonToGrammar.TransformJsonToGrammar) ModelManager(org.finos.legend.engine.language.pure.modelManager.ModelManager) DeploymentStateAndVersions(org.finos.legend.engine.shared.core.deployment.DeploymentStateAndVersions) VaultFactory(org.finos.legend.engine.shared.core.vault.VaultFactory) LegendPlanTransformers(org.finos.legend.engine.plan.generation.transformers.LegendPlanTransformers) HostnameHeaderBundle(org.finos.legend.server.shared.bundles.HostnameHeaderBundle) PureProtocolObjectMapperFactory(org.finos.legend.engine.protocol.pure.v1.PureProtocolObjectMapperFactory) DispatcherType(javax.servlet.DispatcherType) ChainFixingFilterHandler(org.finos.legend.server.shared.bundles.ChainFixingFilterHandler) SessionTracker(org.finos.legend.engine.server.core.session.SessionTracker) EngineUrlStreamHandlerFactory(org.finos.legend.engine.shared.core.url.EngineUrlStreamHandlerFactory) Compile(org.finos.legend.engine.language.pure.compiler.api.Compile) CurrentUser(org.finos.legend.engine.server.core.api.CurrentUser) Execute(org.finos.legend.engine.query.pure.api.Execute) GraphQLExecute(org.finos.legend.engine.query.graphQL.api.execute.GraphQLExecute) Memory(org.finos.legend.engine.server.core.api.Memory) InMemory(org.finos.legend.engine.plan.execution.stores.inMemory.plugin.InMemory) RelationalStoreExecutor(org.finos.legend.engine.plan.execution.stores.relational.plugin.RelationalStoreExecutor) SessionInfo(org.finos.legend.engine.server.core.session.api.SessionInfo) ExternalFormats(org.finos.legend.engine.external.shared.format.model.api.ExternalFormats) TransformRelationalOperationElementJsonToGrammar(org.finos.legend.engine.language.pure.grammar.api.relationalOperationElement.TransformRelationalOperationElementJsonToGrammar) RelationalOperationElementJsonToGrammar(org.finos.legend.engine.language.pure.grammar.api.relationalOperationElement.RelationalOperationElementJsonToGrammar) TransformGrammarToJson(org.finos.legend.engine.language.pure.grammar.api.grammarToJson.TransformGrammarToJson) Compile(org.finos.legend.engine.language.pure.compiler.api.Compile) JsonInformationExceptionMapper(org.finos.legend.engine.server.core.exceptionMappers.JsonInformationExceptionMapper) GraphQLExecute(org.finos.legend.engine.query.graphQL.api.execute.GraphQLExecute) ServiceModelingApi(org.finos.legend.engine.plan.execution.service.api.ServiceModelingApi) CatchAllExceptionMapper(org.finos.legend.engine.server.core.exceptionMappers.CatchAllExceptionMapper) RelationalExecutorInformation(org.finos.legend.engine.plan.execution.stores.relational.api.RelationalExecutorInformation) PlanGeneratorExtension(org.finos.legend.engine.plan.generation.extension.PlanGeneratorExtension) RelationalOperationElementGrammarToJson(org.finos.legend.engine.language.pure.grammar.api.relationalOperationElement.RelationalOperationElementGrammarToJson) TransformRelationalOperationElementGrammarToJson(org.finos.legend.engine.language.pure.grammar.api.relationalOperationElement.TransformRelationalOperationElementGrammarToJson) TransformGrammarToJson(org.finos.legend.engine.language.pure.grammar.api.grammarToJson.TransformGrammarToJson) GrammarToJson(org.finos.legend.engine.language.pure.grammar.api.grammarToJson.GrammarToJson) GraphQLDebug(org.finos.legend.engine.query.graphQL.api.debug.GraphQLDebug) GenerationExtension(org.finos.legend.engine.external.shared.format.extension.GenerationExtension) ExecutePlanLegacy(org.finos.legend.engine.plan.execution.api.ExecutePlanLegacy) ExecutePlanStrategic(org.finos.legend.engine.plan.execution.api.ExecutePlanStrategic) RelationalOperationElementGrammarToJson(org.finos.legend.engine.language.pure.grammar.api.relationalOperationElement.RelationalOperationElementGrammarToJson) TransformRelationalOperationElementGrammarToJson(org.finos.legend.engine.language.pure.grammar.api.relationalOperationElement.TransformRelationalOperationElementGrammarToJson) InflateInterceptor(org.finos.legend.engine.shared.core.operational.http.InflateInterceptor) GraphQLGrammar(org.finos.legend.engine.query.graphQL.api.grammar.GraphQLGrammar) SchemaExplorationApi(org.finos.legend.engine.plan.execution.stores.relational.connection.api.schema.SchemaExplorationApi) SchemaImports(org.finos.legend.engine.external.shared.format.imports.loaders.SchemaImports) PlanExecutor(org.finos.legend.engine.plan.execution.PlanExecutor) SchemaGenerators(org.finos.legend.engine.external.shared.format.generations.loaders.SchemaGenerators) CodeGenerators(org.finos.legend.engine.external.shared.format.generations.loaders.CodeGenerators) SDLCLoader(org.finos.legend.engine.language.pure.modelManager.sdlc.SDLCLoader) SessionTracker(org.finos.legend.engine.server.core.session.SessionTracker) TransformRelationalOperationElementGrammarToJson(org.finos.legend.engine.language.pure.grammar.api.relationalOperationElement.TransformRelationalOperationElementGrammarToJson) CodeImports(org.finos.legend.engine.external.shared.format.imports.loaders.CodeImports) ModelManager(org.finos.legend.engine.language.pure.modelManager.ModelManager) Info(org.finos.legend.engine.server.core.api.Info) SessionInfo(org.finos.legend.engine.server.core.session.api.SessionInfo) PureModel(org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel) Root_meta_pure_router_extension_RouterExtension(org.finos.legend.pure.generated.Root_meta_pure_router_extension_RouterExtension) TransformRelationalOperationElementJsonToGrammar(org.finos.legend.engine.language.pure.grammar.api.relationalOperationElement.TransformRelationalOperationElementJsonToGrammar) RelationalOperationElementJsonToGrammar(org.finos.legend.engine.language.pure.grammar.api.relationalOperationElement.RelationalOperationElementJsonToGrammar) JsonToGrammar(org.finos.legend.engine.language.pure.grammar.api.jsonToGrammar.JsonToGrammar) TransformJsonToGrammar(org.finos.legend.engine.language.pure.grammar.api.jsonToGrammar.TransformJsonToGrammar) RichIterable(org.eclipse.collections.api.RichIterable) TransformJsonToGrammar(org.finos.legend.engine.language.pure.grammar.api.jsonToGrammar.TransformJsonToGrammar) ApplicationQuery(org.finos.legend.engine.application.query.api.ApplicationQuery) Objects(java.util.Objects) TransformRelationalOperationElementJsonToGrammar(org.finos.legend.engine.language.pure.grammar.api.relationalOperationElement.TransformRelationalOperationElementJsonToGrammar)

Example 3 with ModelManager

use of org.finos.legend.engine.language.pure.modelManager.ModelManager in project legend-engine by finos.

the class TestModelManagerPureModelCaching method testPureModelCaching.

@Test
public void testPureModelCaching() {
    ModelManager manager = new ModelManager(DeploymentMode.TEST, new MockModelLoader());
    Protocol protocol = new Protocol("pure", "v1_17_0");
    PackageableElementPointer element0 = new PackageableElementPointer(PackageableElementType.MAPPING, "meta::relational::tests::milestoning::milestoningmap");
    PackageableElementPointer element1 = new PackageableElementPointer(PackageableElementType.STORE, "meta::relational::tests::dbInc");
    PackageableElementPointer element2 = new PackageableElementPointer(PackageableElementType.STORE, "meta::relational::tests::db");
    List<PackageableElementPointer> list = new ArrayList<>();
    list.add(element0);
    list.add(element1);
    list.add(element2);
    PureSDLC pureSDLC = new PureSDLC();
    pureSDLC.packageableElementPointers = list;
    PureModelContextPointer pointer = new PureModelContextPointer();
    pointer.serializer = protocol;
    pointer.sdlcInfo = pureSDLC;
    PureModelContext context = pointer;
    manager.loadModel(context, null, null, null);
    Assert.assertEquals(1, manager.pureModelCache.size());
}
Also used : PureModelContextPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextPointer) PureSDLC(org.finos.legend.engine.protocol.pure.v1.model.context.PureSDLC) PureModelContext(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext) ArrayList(java.util.ArrayList) PackageableElementPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer) ModelManager(org.finos.legend.engine.language.pure.modelManager.ModelManager) Protocol(org.finos.legend.engine.protocol.Protocol) Test(org.junit.Test)

Example 4 with ModelManager

use of org.finos.legend.engine.language.pure.modelManager.ModelManager in project legend-engine by finos.

the class TestAvroGeneration method test.

public void test(String directoryInput, String expected) throws Exception {
    InputStream stream;
    stream = Objects.requireNonNull(TestAvroGeneration.class.getResourceAsStream(directoryInput));
    String jsonInput = new java.util.Scanner(stream).useDelimiter("\\A").next();
    AvroGenerationInput request = objectMapper.readValue(jsonInput, AvroGenerationInput.class);
    ModelManager modelManager = new ModelManager(DeploymentMode.TEST);
    AvroGenerationService executor = new AvroGenerationService(modelManager);
    Response response = executor.generateAvro(request, null);
    String returnedContext = response.getEntity().toString();
    Assert.assertEquals(expected, returnedContext);
    stream.close();
}
Also used : Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream) AvroGenerationService(org.finos.legend.engine.external.format.avro.schema.generations.AvroGenerationService) ModelManager(org.finos.legend.engine.language.pure.modelManager.ModelManager) AvroGenerationInput(org.finos.legend.engine.external.format.avro.schema.generations.AvroGenerationInput)

Aggregations

ModelManager (org.finos.legend.engine.language.pure.modelManager.ModelManager)4 Response (javax.ws.rs.core.Response)2 PureModel (org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel)2 PlanExecutor (org.finos.legend.engine.plan.execution.PlanExecutor)2 Execute (org.finos.legend.engine.query.pure.api.Execute)2 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)1 Application (io.dropwizard.Application)1 AssetsBundle (io.dropwizard.assets.AssetsBundle)1 MultiPartBundle (io.dropwizard.forms.MultiPartBundle)1 Bootstrap (io.dropwizard.setup.Bootstrap)1 Environment (io.dropwizard.setup.Environment)1 SwaggerBundle (io.federecio.dropwizard.swagger.SwaggerBundle)1 SwaggerBundleConfiguration (io.federecio.dropwizard.swagger.SwaggerBundleConfiguration)1 CollectorRegistry (io.prometheus.client.CollectorRegistry)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 Objects (java.util.Objects)1 ServiceLoader (java.util.ServiceLoader)1