mdenet / educationplatform

Eclipse Public License 2.0
2 stars 3 forks source link

Activity Templates #142

Open arturboronat opened 8 months ago

arturboronat commented 8 months ago

Activity templates could help manage complexity in activity configuration files.

Problem

As we create more examples for the platform, activity configuration files are becoming increasingly difficult to maintain, mostly due to duplication of configuration parameters.

For example, a typical activity definition for model trafos like YAMTL looks something like this the yaml code snippet below, where only the annotated parameters need to be updated:

  - id: yamtl-cd2db-activity    # Activity id
    title: CD2DB                # Activity name 
    icon: yamtl                 
    tools:
      - https://yamtl.github.io/playground-interfaces/static.emf/emf-tool.yml
      - https://yamtl.github.io/playground-interfaces/static.yamtlgroovy/yamtl-m2m.yml
    layout:
      area:
        - - panel-yamtl
          - smm-panel-composite
          - tmm-panel-composite
        - - panel-console
          - smodel-panel-composite
          - tmodel-panel-composite
    actions:
      - source: panel-yamtl
        sourceButton: run-trafo-button
        parameters:
          trafoGroovy: panel-yamtl
          inModel: panel-smodel
          inMetamodel: panel-smm
          outMetamodel: panel-tmm
        output: panel-tmodel
        outputType: code
        outputConsole: panel-console
      - source: panel-smm
        sourceButton: emfatic2cd-button
        parameters:
          metamodel: panel-smm
        output: panel-smm-diagram
        outputType: puml
      - source: panel-tmm
        sourceButton: emfatic2cd-button
        parameters:
          metamodel: panel-tmm
        output: panel-tmm-diagram
        outputType: puml
      - source: panel-smodel
        sourceButton: xmi2od-button
        parameters:
          metamodel: panel-smm
          model: panel-smodel
        output: panel-smodel-diagram
        outputType: puml
      - source: panel-tmodel
        sourceButton: xmi2od-button
        parameters:
          metamodel: panel-tmm
          model: panel-tmodel
        output: panel-tmodel-diagram
        outputType: puml
    panels:
      - id: panel-yamtl
        name: Transformation(YAMTL)
        ref: yamtl
        file: CD2DB.groovy              # path to trafo definition
      - id: smm-panel-composite
        name: Source Metamodel
        ref: composite-panel
        childrenPanels:
          - id: panel-smm
            name: EMFatic
            ref: emfatic
            file: CD.emf                # path to source metamodel
          - id: panel-smm-diagram
            name: Diagram
            ref: plantuml
        buttons:
          - id: show-editor-button
            icon: editor
            internal: toggle
            targetPanel: panel-smm
            hint: Toggle editor
          - id: show-diagram-button
            icon: diagram
            internal: toggle
            targetPanel: panel-smm-diagram
            hint: Toggle diagram
      - id: tmm-panel-composite
        name: Target Metamodel
        ref: composite-panel
        childrenPanels:
          - id: panel-tmm
            name: EMFatic
            ref: emfatic
            file: Relational.emf        # path to target metamodel
          - id: panel-tmm-diagram
            name: Diagram
            ref: plantuml
        buttons:
          - id: show-editor-button
            icon: editor
            internal: toggle
            targetPanel: panel-tmm
            hint: Toggle editor
          - id: show-diagram-button
            icon: diagram
            internal: toggle
            targetPanel: panel-tmm-diagram
            hint: Toggle diagram
      - id: smodel-panel-composite
        name: Source Model
        ref: composite-panel
        icon: editor
        childrenPanels:
          - id: panel-smodel
            name: XMI
            ref: xmi
            file: sourceModel.xmi           # path to source model
          - id: panel-smodel-diagram
            name: Diagram
            ref: plantuml
        buttons:
          - id: show-editor-button
            icon: editor
            internal: toggle
            targetPanel: panel-smodel
            hint: Toggle editor
          - id: show-diagram-button
            icon: diagram
            internal: toggle
            targetPanel: panel-smodel-diagram
            hint: Toggle diagram
      - id: tmodel-panel-composite
        name: Target Model
        icon: editor
        ref: composite-panel
        childrenPanels:
          - id: panel-tmodel
            name: XMI
            ref: xmi
          - id: panel-tmodel-diagram
            name: Diagram
            ref: plantuml
        buttons:
          - id: show-editor-button
            icon: editor
            internal: toggle
            targetPanel: panel-tmodel
            hint: Toggle editor
          - id: show-diagram-button
            icon: diagram
            internal: toggle
            targetPanel: panel-tmodel-diagram
            hint: Toggle diagram
      - id: panel-console
        name: Console
        icon: console
        ref: console

Potential solution

A template is an activity abstraction that encapsulates the configuration of an activity type so that it can be parameterised, facilitating the reuse of the configuration logic across similar examples (template instances).

The idea is to define a template yamtl-m2m-activity-template with the configuration logic parameterised using parameter names where required as values of properties. Then, for each specific activity, the template can be instantiated using a specific value binding for each paramater. For example:

  - id: yamtl-cd2db-activity
    template: yamtl-m2m-activity-template
    binding:
      - ACTIVITY_NAME: CD2DB
      - TRAFO_PATH: CD2DB.groovy
      - SOURCE_MM: CD.emf
      - TARGET_MM: Relational.emf
      - SOURCE_MODEL: sourceModel.xmi

declares that yamtl-cd2db-activity is an instance of yamtl-m2m-activity-template with the specified bindings. The instantiation logic in the platform should replicate the activity template configuration replacing parameters with their corresponding argument. Once all activity instantiations have been unfolded in memory, the platform can carry on as usual.

A complete example of the configuration would look like this:

  - id: yamtl-cd2db-activity
    template: yamtl-m2m-activity-template
    binding:
      - ACTIVITY_NAME: CD2DB
      - TRAFO_PATH: CD2DB.groovy
      - SOURCE_MM: CD.emf
      - TARGET_MM: Relational.emf
      - SOURCE_MODEL: sourceModel.xmi
  - id: yamtl-m2m-activity-template # TEMPLATE NAME AND PARAMETER: activity id
    title: ACTIVITY_NAME            # PARAMETER: activity name 
    icon: yamtl
    tools:
      - https://yamtl.github.io/playground-interfaces/static.emf/emf-tool.yml
      - https://yamtl.github.io/playground-interfaces/static.yamtlgroovy/yamtl-m2m.yml
    layout:
      area:
        - - panel-yamtl
          - smm-panel-composite
          - tmm-panel-composite
        - - panel-console
          - smodel-panel-composite
          - tmodel-panel-composite
    actions:
      - source: panel-yamtl
        sourceButton: run-trafo-button
        parameters:
          trafoGroovy: panel-yamtl
          inModel: panel-smodel
          inMetamodel: panel-smm
          outMetamodel: panel-tmm
        output: panel-tmodel
        outputType: code
        outputConsole: panel-console
      - source: panel-smm
        sourceButton: emfatic2cd-button
        parameters:
          metamodel: panel-smm
        output: panel-smm-diagram
        outputType: puml
      - source: panel-tmm
        sourceButton: emfatic2cd-button
        parameters:
          metamodel: panel-tmm
        output: panel-tmm-diagram
        outputType: puml
      - source: panel-smodel
        sourceButton: xmi2od-button
        parameters:
          metamodel: panel-smm
          model: panel-smodel
        output: panel-smodel-diagram
        outputType: puml
      - source: panel-tmodel
        sourceButton: xmi2od-button
        parameters:
          metamodel: panel-tmm
          model: panel-tmodel
        output: panel-tmodel-diagram
        outputType: puml
    panels:
      - id: panel-yamtl
        name: Transformation(YAMTL)
        ref: yamtl
        file: TRAFO_PATH                # PARAMETER: path to trafo definition
      - id: smm-panel-composite
        name: Source Metamodel
        ref: composite-panel
        childrenPanels:
          - id: panel-smm
            name: EMFatic
            ref: emfatic
            file: SOURCE_MM               # PARAMETER: path to source metamodel
          - id: panel-smm-diagram
            name: Diagram
            ref: plantuml
        buttons:
          - id: show-editor-button
            icon: editor
            internal: toggle
            targetPanel: panel-smm
            hint: Toggle editor
          - id: show-diagram-button
            icon: diagram
            internal: toggle
            targetPanel: panel-smm-diagram
            hint: Toggle diagram
      - id: tmm-panel-composite
        name: Target Metamodel
        ref: composite-panel
        childrenPanels:
          - id: panel-tmm
            name: EMFatic
            ref: emfatic
            file: TARGET_MM             # PARAMETER: path to target metamodel
          - id: panel-tmm-diagram
            name: Diagram
            ref: plantuml
        buttons:
          - id: show-editor-button
            icon: editor
            internal: toggle
            targetPanel: panel-tmm
            hint: Toggle editor
          - id: show-diagram-button
            icon: diagram
            internal: toggle
            targetPanel: panel-tmm-diagram
            hint: Toggle diagram
      - id: smodel-panel-composite
        name: Source Model
        ref: composite-panel
        icon: editor
        childrenPanels:
          - id: panel-smodel
            name: XMI
            ref: xmi
            file: SOURCE_MODEL        # PARAMETER: path to source model
          - id: panel-smodel-diagram
            name: Diagram
            ref: plantuml
        buttons:
          - id: show-editor-button
            icon: editor
            internal: toggle
            targetPanel: panel-smodel
            hint: Toggle editor
          - id: show-diagram-button
            icon: diagram
            internal: toggle
            targetPanel: panel-smodel-diagram
            hint: Toggle diagram
      - id: tmodel-panel-composite
        name: Target Model
        icon: editor
        ref: composite-panel
        childrenPanels:
          - id: panel-tmodel
            name: XMI
            ref: xmi
          - id: panel-tmodel-diagram
            name: Diagram
            ref: plantuml
        buttons:
          - id: show-editor-button
            icon: editor
            internal: toggle
            targetPanel: panel-tmodel
            hint: Toggle editor
          - id: show-diagram-button
            icon: diagram
            internal: toggle
            targetPanel: panel-tmodel-diagram
            hint: Toggle diagram
      - id: panel-console
        name: Console
        icon: console
        ref: console

If this feature is added, the documentation should explain that:

Apart from adding one more level of reuse, activity templates reduce clutter significantly.

agarciadom commented 8 months ago

It may be worth drawing inspiration from known YAML configuration formats that also have to deal with duplication. For instance, this problem is common enough in Gitlab CI YAML files that they have come up with a number of mechanisms. See here:

https://docs.gitlab.com/ee/ci/yaml/yaml_optimization.html

It's worth keeping in mind that YAML already has functionality for some of this, e.g. anchors.