Breadcrumbs

Server Job Translation

Job Translation is a made up of a list of small, discrete Translation Operations. When a job is processed for translation, the server job is processed in order by each Translation Operation in the list. The resulting job can be a partially or fully translated parallel job depending on which Translation Operations were used.

Unknown Attachment

The operations involved in Job Translation and the order in which they execute is completely configurable through a simple YAML configuration files:

debug: false
script: my/script/directory
steps:
 - type: SplitTransformerLookups
 - type: ReplaceLookups
 - type: ReplaceTransformers

This design allows new translation operations to be created and incorporated into the system with very little work. Users can also customize the translation process by swapping out translation operations and changing their order to affect precedence.

For debugging purposes, it is possible to set debug: true to generate a DSX file and HTML report which reflect the state of the Job at each point in the translation process:

Unknown Attachment

Implementation

A Translation Operation is just a class which implements the TranslationOperation. This interface accepts a Job model as parameter and returns true/false based on whether the Translation Operation changed the Job model.

There are two methods of implementation available:

  1. Java class

  2. Groovy Script (to be extended as a DSL in future)

Java

To create a new TranslationOperation implementation and ensure it can be added to the YAML configuration, the following steps need to be performed:

  • Create an implementation of TranslationOperation

  • Add @Translation annotation to the implementation, the name property is the identifier used as type in the YAML configuration

  • Add @Inject annotation to the constructor, all dependencies are injected as part of the Inversion of Control pattern implemented by Dagger2

  • Add an entry to the JobTranslationsModule, this step will eventually be replaced with code generated by an annotation processor.

Implementations of TranslationOperation can also use @JsonProperty on class members and/or getters and setters to define additional configuration items which are set via the YAML configuration file. Java bean validation has also been enabled, so the @JsonProperty fields can have validation annotation applied.

For example:

Java
@Translation(name="MySillyOperation", description ="A very silly example")
public class MyTranslation extends TranslationOperation {
   @NotBlank
   @JsonProperty
   String myString;
   
   @Min(5)
   @Max(10)
   @JsonProperty
   int myNumber;
   
   @Inject
   public MyTranslation() {
   }
   
   boolean translate(Job job) {
      // perform translation here
      System.out.println(job.name() + ": " + myString)
      return true;
   }
}

This new translation operation can be added to the configuration using the following YAML snippet

steps:
  - type: MySillyOperation
    myString: Silly Text
    myNumber: 8

This will automatically instantiate a MyTranslation operation as the one and only operation used during Job Translation. The myString and myNumber fields will be automatically set as “Silly Text” and 8 respectively. Error messages during startup will be displayed if myString and myNumber do not meet the non blank string and number between 5 and 10 validation requirements.

Groovy Script

The directory specified by the scripts property in the config YAML is searched (not recursively) for all .groovy files and automatically loaded into the system. A groovy script is similar to the Java implementation but has far less boilerplate. It will also be extended in the future to provide a DSL for simple translation patterns.

A groovy script is executed top to bottom just like a shell script. All scripts require a @Translation annotation at the top to describe the translation operation implemented by the script. The job variable contains the Job model that is to be manipulated during translation. @Property annotation are used to identify variables who’s values are set from the YAML configuration file.

Below is a Groovy implementation of the MySillyOperation defined in the preview Java section:

Groovy
@Translation(name="MySillyOperation", description ="A very silly example")

@NotBlank
@Property
String myString
   
@Min(5)
@Max(10)
@Property
int myNumber

// perform translation here
println "${job.name}: ${myString}"