Skip to main content

Service Execution Jar

This tutorial demonstrates the use of "Service Execution Jars"

Requirements

  • A Legend Studio project with a Service model
  • Familiarity with the following Legend concepts :
    • Data modeling with classes, associations
    • Data modeling with stores, mappings, connections and runtimes
    • Data modeling with Legend services

Example

Legend Studio Project - https://gitlab.com/finosfoundation/legend/showcase/legend-showcase-project2

Setup

N/A

Tutorial

1. Service Execution Primer

A "service execution" jar is a Java library generated from a Legend model.

Consider the service model below. It is a grouping of a data access query, a mapping to a physical (relational) store and a specific database connection.

Service service::persons
{
pattern: '/api/persons';
documentation: '';
autoActivateUpdates: true;
execution: Single
{
query: |domain::Person.all()->project([x|$x.name, x|$x.firmId], ['Name', 'FirmId']);
mapping: mapping::firmperson;
runtime: runtime::firmperson;
}
}

2. Service Execution Class

Once modeled in Legend, the Legend project's SDLC infrastucture consumes this model and generates a Java class.

personsService service = new personsService();

When executed, this class connects to the database specified in the model, queries and returns the data.

3. Building a Service Execution Jar

In the simplest case, a service execution jar is autogenerated by the Legend project's SDLC.

To generate a service execution jar using Legend SDLC

  • Create a Legend Studio project
  • Use Legend Studio to create a Legend model. This model should include a service definition as shown above
  • Use Legend Studio SDLC controls or native Gitlab controls to merge your model to the master branch
  • Once merged, the Gitlab pipeline configured by Legend SDLC runs a code generation plugin which generate a service execution jar
  • The Gitlab pipeline also publishes the generated jar to a Gitlab Maven registry.

As a concrete example

4. Using a Service Execution Jar

Just as with other stores in Legend, the logical model is mapped to the logical definition of the store.

Once a jar has been created it can be consumed like any other jar in a Java application.

See https://github.com/finos/legend/blob/service-exec-jar-example/examples/service-execution-jar/legend-application/src/main/java/org/finos/legend/demo/app/LegendApplication.java

See https://github.com/finos/legend/blob/service-exec-jar-example/examples/service-execution-jar/legend-application/src/test/java/org/finos/legend/demo/app/LegendApplicationTest.java

See https://github.com/finos/legend/blob/service-exec-jar-example/examples/service-execution-jar/legend-application/src/test/java/org/finos/legend/demo/app/LegendExecutionPlanTest.java

Reference

N/A

Code

N/A