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;
}
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);
}
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());
}
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();
}
Aggregations