use of org.finos.legend.pure.generated.Root_meta_pure_router_extension_RouterExtension in project legend-sdlc by finos.
the class MappingTestCase method collectTestCases.
@LegendSDLCTestCaseCollector(collectorClass = Mapping.class)
public static void collectTestCases(PureModel pureModel, PureModelContextData pureModelContextData, MutableList<PlanTransformer> planTransformers, RichIterable<? extends Root_meta_pure_router_extension_RouterExtension> extensions, String pureVersion, Entity entity, Consumer<? super LegendSDLCTestCase> testCaseConsumer) {
Mapping mapping = findPackageableElement(pureModelContextData.getElementsOfType(Mapping.class), entity.getPath());
Optional.ofNullable(mapping.tests).orElse(Collections.emptyList()).stream().map(test -> new MappingTestCase(pureModel, pureModelContextData, mapping, test, planTransformers, extensions, pureVersion)).forEach(testCaseConsumer);
}
use of org.finos.legend.pure.generated.Root_meta_pure_router_extension_RouterExtension 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.pure.generated.Root_meta_pure_router_extension_RouterExtension in project legend-sdlc by finos.
the class ServicesGenerationMojo method execute.
@Override
public void execute() throws MojoExecutionException {
if (this.inclusions != null) {
getLog().info("include service paths: " + this.inclusions.servicePaths);
getLog().info("include service packages: " + this.inclusions.packages);
getLog().info("include service directories: " + Arrays.toString(this.inclusions.directories));
}
if (this.exclusions != null) {
getLog().info("exclude service paths: " + this.exclusions.servicePaths);
getLog().info("exclude service packages: " + this.exclusions.packages);
getLog().info("exclude service directories: " + Arrays.toString(this.exclusions.directories));
}
getLog().info("package prefix: " + ((this.packagePrefix == null) ? null : ('"' + this.packagePrefix + '"')));
getLog().info("Java source output directory: " + this.javaSourceOutputDirectory);
getLog().info("resource output directory: " + this.resourceOutputDirectory);
if ((this.packagePrefix != null) && !SourceVersion.isName(this.packagePrefix)) {
throw new MojoExecutionException("Invalid package prefix: " + this.packagePrefix);
}
getLog().info("Loading model");
long modelStart = System.nanoTime();
PureModelBuilder pureModelBuilder = PureModelBuilder.newBuilder();
try (EntityLoader allEntities = EntityLoader.newEntityLoader(Thread.currentThread().getContextClassLoader())) {
pureModelBuilder.addEntitiesIfPossible(allEntities.getAllEntities());
} catch (Exception e) {
throw new MojoExecutionException("Error loading entities from model", e);
}
int elementCount = pureModelBuilder.getElementCount();
getLog().info("Found " + elementCount + " elements in the model");
if (elementCount == 0) {
long modelEnd = System.nanoTime();
getLog().info(String.format("Finished loading model (%.9fs)", (modelEnd - modelStart) / 1_000_000_000.0));
getLog().info("No execution artifacts to generate");
return;
}
PureModelBuilder.PureModelWithContextData pureModelWithContextData;
try {
pureModelWithContextData = pureModelBuilder.build();
} catch (Exception e) {
throw new MojoExecutionException("Error building Pure model", e);
}
PureModelContextData pureModelContextData = pureModelWithContextData.getPureModelContextData();
PureModel pureModel = pureModelWithContextData.getPureModel();
long modelEnd = System.nanoTime();
getLog().info(String.format("Finished loading model (%.9fs)", (modelEnd - modelStart) / 1_000_000_000.0));
JsonMapper jsonMapper = PureProtocolObjectMapperFactory.withPureProtocolExtensions(JsonMapper.builder().enable(SerializationFeature.INDENT_OUTPUT).enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS).enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY).disable(StreamWriteFeature.AUTO_CLOSE_TARGET).disable(StreamReadFeature.AUTO_CLOSE_SOURCE).serializationInclusion(JsonInclude.Include.NON_NULL).build());
long start = System.nanoTime();
Map<String, Service> servicesByPath = pureModelContextData.getElementsOfType(Service.class).stream().collect(Collectors.toMap(PackageableElement::getPath, el -> el));
filterServicesByIncludes(servicesByPath);
filterServicesByExcludes(servicesByPath);
if (servicesByPath.isEmpty()) {
getLog().info("Found 0 services for generation");
} else if (getLog().isInfoEnabled()) {
getLog().info(servicesByPath.keySet().stream().sorted().collect(Collectors.joining(", ", "Found " + servicesByPath.size() + " services for generation: ", "")));
}
for (Service service : servicesByPath.values()) {
getLog().info("Generating execution artifacts for " + service.getPath());
long serviceStart = System.nanoTime();
try {
MutableList<PlanGeneratorExtension> extensions = Lists.mutable.withAll(ServiceLoader.load(PlanGeneratorExtension.class));
RichIterable<? extends Root_meta_pure_router_extension_RouterExtension> routerExtensions = extensions.flatCollect(e -> e.getExtraRouterExtensions(pureModel));
MutableList<PlanTransformer> planTransformers = extensions.flatCollect(PlanGeneratorExtension::getExtraPlanTransformers);
ServiceExecutionGenerator.newGenerator(service, pureModel, this.packagePrefix, this.javaSourceOutputDirectory.toPath(), this.resourceOutputDirectory.toPath(), jsonMapper, routerExtensions, planTransformers, null).generate();
} catch (Exception e) {
throw new MojoExecutionException("Error generating execution artifacts for " + service.getPath(), e);
}
long serviceEnd = System.nanoTime();
getLog().info(String.format("Finished generating execution artifacts for %s (%.9fs)", service.getPath(), (serviceEnd - serviceStart) / 1_000_000_000.0));
}
long end = System.nanoTime();
getLog().info(String.format("Finished generating execution artifacts for %d services (%.9fs)", servicesByPath.size(), (end - start) / 1_000_000_000.0));
}
Aggregations