Jump to: navigation, search

Difference between revisions of "Mistral/DSL"

(Mistral DSL specification)
Line 109: Line 109:
 
=== Full YAML example: ===
 
=== Full YAML example: ===
  
   Services:
+
   Workflow:
  MyRest:
+
  tasks:
    type: REST_API
+
    runJob:
    parameters:
+
      requires:
        baseUrl: http://some_host
+
        createVM: $.vm_ip != null
    actions:
+
      action: DemoApp:runJob
        create-vm:
+
      on-success: deleteVM
          parameters:
+
      on-error: sendJobError
              url: /service/action/execute
+
 
              method: GET
+
    deleteVM:
          task-parameters:
+
      action: Nova:deleteVM
              flavor_id:
+
      on-finish: end
              image_id:
+
 
 +
    sendJobError:
 +
      action: std:email
 +
      parameters:
 +
        address: admin@mycompany.com
 +
        subject: Workflow error
 +
        body: Error occurred while running a VM job in execution {$.execution.id}
 +
      on-finish: deleteVM
 +
 
 +
  # Creating a VM and waiting till it is up (an IP address has been assigned).
 +
 
 +
    createVM:
 +
      action: Nova:createVM
 +
      on-success: waitForIP
 +
      on-error: sendCreateVMError
 +
 
 +
    waitForIP:
 +
      action: std:repeat
 +
      parameters:
 +
        task: getIP
 +
        retries: 5
 +
        delay: 3000
 +
        break-on: $.vm_ip != null
 +
      on-finish:
 +
        sendCreateVMError: $.vm_ip = null
 +
      on-error:
 +
        sendCreateVMError
 
    
 
    
        backup-vm:
+
    getIP:
          parameters:
+
      action: Nova:getIP
              url: url_for_backup
 
              method: GET
 
          task-parameters:
 
              server_id:
 
 
    
 
    
        attach-volume:
+
    sendCreateVMError:
          parameters:
+
      action: std:email
              url: url_for_attach
+
      parameters:
              method: GET
+
        address: admin@mycompany.com
          task-parameters:
+
        subject: Workflow error
              size:
+
        body: Failed to create a VM in execution {$.execution.id}
              mnt_path:
+
      on-finish: end
 
    
 
    
        format-volume:
+
  # Terminal no-op task.
          parameters:
 
              url: url_for_format
 
              method: GET
 
          task-parameters:
 
              volume_id:
 
              server_id:
 
 
    
 
    
  Workflow:
+
    end:
    tasks:
+
      action: Util:no-op
      create-vms:
 
          action: MyRest:create-vm
 
          parameters:
 
            image_id: 1234
 
            flavor_id: 42
 
 
    
 
    
      attach-volumes:
+
  events:
          dependsOn: [create-vms]
+
    runJob:
          action: MyRest:attach-volume
+
      type: periodic
          parameters:
+
      tasks: runJob
            size:
+
      parameters:
            mnt_path:
+
        cron-pattern: "*/1 * * * *"
 
    
 
    
      format-volumes:
+
  Services:
           dependsOn: [attach-volumes]
+
    Nova:
           action: MyRest:format-volume
+
      type: REST_API
 +
      parameters:
 +
        baseUrl: {$.novaURL}
 +
      actions:
 +
        createVM:
 +
           parameters:
 +
            url: /servers/{$.vm_id}
 +
            method: POST
 +
           response:
 +
            select: $.server.id
 +
            store-as: vm_id
 +
        getIP:
 
           parameters:
 
           parameters:
            server_id:
+
            url: /servers/{$.vm_id}
 
+
            method: GET
      backup-vms:
+
          response:
          dependsOn: [create-vms]
+
            select: $.server.accessIPv4
          action: MyRest:backup-vm
+
            store-as: vm_ip
 +
        deleteVM:
 
           parameters:
 
           parameters:
            server_id:
+
            url: /servers/{$.vm_id}
 +
            method: DELETE
 
    
 
    
    events:
+
  DemoAPP:
      create-vms:
+
    type: MISTRAL_REST_API
           type: periodic
+
    parameters:
           tasks: create-vms
+
      baseUrl: http://{$.vm_ip}:8080/
          parameters:
+
    actions:
              cron-pattern: "*/5 * * * *"
+
      runJob:
 +
        parameters:
 +
           url: /runJob
 +
           method: GET
 +
 
 +
==== Initial execution context ====
 +
  {
 +
    "novaURL": TBD,
 +
    "imageID": TBD
 +
  }
 +
 
 +
'''When a workflow starts Mistral also adds execution information into the context so the context looks like the following:'''
 +
 
 +
  {
 +
    "novaURL": TBD,
 +
    "imageID": TBD,
 +
    "execution": {
 +
      "id": "234234",
 +
      "workbook_name" : "my_workbook",
 +
      "project_id": "ghfgsdfasdfasdf"
 +
      "auth_token": "sdfljsdfsdf-234234234",
 +
      "trust_id": "oiretoilkjsdfglkjsdfglkjsdfg"
 +
    }
 +
  }

Revision as of 13:58, 28 January 2014

Mistral DSL specification

Version 0.1

Main objects

  • Service
  • Action
  • Workflow
  • Task
  • Event

Service

Provides some specific functionality. For example, Nova service provides functionality for VMs management in OpenStack.

Attributes

  • name - string without space, mandatory attribute
  • type - currently we support the following types: RESTAPI, OPENSTACKSERVICE, OSLO_RPC, this is a mandatory attribute
  • parameters - dictionary depending on type of the service, this parameter can be optional. For example for REST API it should contain url of the service, method of authentication etc.
  • actions - list of actions provided by this service

YAML example:

 Service:
    name: Nova
    type: REST_API
    parameters:
        key:value
    actions:
        create-vm:
          ......
        delete-vm:  
          .....

Action

A function provided by services. For example Nova service provides the following actions: create-vm, shutdown-vm

Attributes

  • name - string without space, mandatory attribute
  • parameters - dictionary, which structured is defined by service type. For REST service it contains url and method.
  • task-parameters - dictionary containing parameters which should or could be specified in task

YAML example:

 create-vm:
     parameters:
         url: servers
     task-parameters:
         name:
           optional: False

Workflow

Attributes

  • name - string without space, mandatory attribute
  • tasks - list of task in this workflow, each task represent some step in worflow
  • events - list of events in workflow, e.g. timer or periodic events

YAML example:

 Workflow:
    tasks:
       create-vms:
         .....
       attache-volumes: 
         .....

Task

Represents a step in workflow, for example attaching volume

Attributes

  • name - string without space, mandatory attribute
  • action - name of action to perform
  • dependsOn - list of tasks which should be execute before this tasks, this is optional parameter
  • parameters - list of parameters

YAML example:

 create-vms:
    action: Nova:create-vm
    parameters:
       image_id: 1234
       flavor_id: 42

Events

By event it is possible to invoke specific task.

Attributes

  • name - string without space, mandatory attribute
  • type - can be PERIODIC, TIMER, CEILOMETER_ALARM
  • tasks - list of tasks which should be execute on event
  • parameters - list of parameters, defined by task

YAML example:

 backup-vm:
    type: periodic
    tasks: [create_backup, delete_old_backup] 
    parameters:
       time: 1 0 * * *

Full YAML example:

 Workflow:
 tasks:
   runJob:
     requires:
       createVM: $.vm_ip != null
     action: DemoApp:runJob
     on-success: deleteVM
     on-error: sendJobError
 
   deleteVM:
     action: Nova:deleteVM
     on-finish: end
 
   sendJobError:
     action: std:email
     parameters:
       address: admin@mycompany.com
       subject: Workflow error
       body: Error occurred while running a VM job in execution {$.execution.id}
     on-finish: deleteVM
 
 # Creating a VM and waiting till it is up (an IP address has been assigned).
 
   createVM:
     action: Nova:createVM
     on-success: waitForIP
     on-error: sendCreateVMError
 
   waitForIP:
     action: std:repeat
     parameters:
       task: getIP
       retries: 5
       delay: 3000
       break-on: $.vm_ip != null
     on-finish:
       sendCreateVMError: $.vm_ip = null
     on-error:
       sendCreateVMError 
 
   getIP:
     action: Nova:getIP
 
   sendCreateVMError:
     action: std:email
     parameters:
       address: admin@mycompany.com
       subject: Workflow error
       body: Failed to create a VM in execution {$.execution.id}
     on-finish: end
 
 # Terminal no-op task.
 
   end:
     action: Util:no-op
 
 events:
   runJob:
     type: periodic
     tasks: runJob
     parameters:
       cron-pattern: "*/1 * * * *"
 
 Services:
   Nova:
     type: REST_API
     parameters:
       baseUrl: {$.novaURL}
     actions:
       createVM:
         parameters:
           url: /servers/{$.vm_id}
           method: POST
         response:
           select: $.server.id
           store-as: vm_id
       getIP:
         parameters:
           url: /servers/{$.vm_id}
           method: GET
         response:
           select: $.server.accessIPv4
           store-as: vm_ip 
       deleteVM:
         parameters:
           url: /servers/{$.vm_id}
           method: DELETE
 
 DemoAPP:
   type: MISTRAL_REST_API
   parameters:
     baseUrl: http://{$.vm_ip}:8080/
   actions:
     runJob:
       parameters:
         url: /runJob
         method: GET

Initial execution context

 {
   "novaURL": TBD,
   "imageID": TBD
 }

When a workflow starts Mistral also adds execution information into the context so the context looks like the following:

 {
   "novaURL": TBD,
   "imageID": TBD,
   "execution": {
     "id": "234234",
     "workbook_name" : "my_workbook",
     "project_id": "ghfgsdfasdfasdf"
     "auth_token": "sdfljsdfsdf-234234234",
     "trust_id": "oiretoilkjsdfglkjsdfglkjsdfg"
   }
 }