Commit Graph

41 Commits

Author SHA1 Message Date
Vadim Zelenevskii ac8b2d0488 Add checksum field to wf definition
We have no way to determine whether the workflow definition has
changed or not.
This complicates the work with Mistral for external services.
A 'checksum' field has been added to workflow_definitions_v2
to solve this issue.

Implements: blueprint mistral-add-checksum-field-to-wf-definition

Change-Id: I99d095c6c74c62f134aedfa3a63308a0712db38d
2023-11-29 07:55:28 +00:00
Eyal b705666f9f Move preinstalled workflows to mistral-extra
* These workflows are openstack workflows and should be in mistral-extra
* Rename the function name to register_preinstalled_workflows
* Rename then function name to register_preinstalled_actions

Change-Id: I80fc1dfe4ec5e81b1b5163c9771eea5a49432f88
Depends-On: https://review.opendev.org/#/c/709970/
Depends-On: https://review.opendev.org/#/c/710024/
2020-02-26 14:33:36 +02:00
Oleg Ovcharuk c1c21d7cdd Disable key sorting in workflow definition
Update to PyYAML 5.1 to be able to turn off key sorting
in workflow definitions. We should not change user's data
until user asks to.

Change-Id: I888008ac8f9c12bd92a9bd72bd7c276a11827847
Closes-Bug: #1815515
Signed-off-by: Oleg Ovcharuk <vgvoleg@gmail.com>
2020-01-21 00:40:26 +03:00
Eyal eac23d9e77 Disable the use of anchors when parsing yaml
This can be used as a DDoS attack

Closes-Bug: 1785657
Change-Id: Icf460fea113e9279715cae87df3ef88a77575e04
2019-12-17 12:08:10 +02:00
Renat Akhmerov ac41f94d11 Add an ability to disable workflow text validation
* For the sake of the service performance, it may make sense to
  disable validation of the workflow language syntax if it is
  affordable for a particular use case. For example, if all
  workflows are auto-generated by a 3rd party system and tested
  thoroughly (either by running them with Mistral or at least
  validating them via the special Mistral endpoint) then we can
  safely disable validation of the language syntax when uploading
  workflow definitions. For production systems it makes a big
  difference if workflow texts are large (thousands of tasks).
  This patch adds the boolean parameter "skip_validation" for API
  requests like "POST /v2/workflows" to disable validation, if
  needed, and the new configuration property "validation_mode"
  to set a desired validation mode.
  The option is an enumeration and has the following valid values:
    1) "enabled" - enabled for all API requests unless it's
       explicitly disabled in the request itself
    2) "mandatory" - enabled for all API requests regardless
       of the flag in the request
    3) "disabled" - disabled for all API requrests regardless
       of the flag in the request
  "mandatory" is choosen as the default value for this new
  property to keep compatibility with the previous versions.
* Minor style changes.

Closes-Bug: #1844242

Change-Id: Ib509653d38254954f8449be3031457e5f636ccf2
2019-09-27 04:33:04 +00:00
ali 7e7f1cb92b moved generic util functions from mistral to mistral-lib
Depends-On: I780c270e4b1a184d7d4dcc580d23697ba75edab1
Closes-bug: #1815183
Change-Id: I5a1d402baa3f69c37f9347c8b3d02a83b8f60423
2019-09-13 04:06:27 +00:00
Oleg Ovcharuk 9a2f3b5715 Simple optimization of creating/updating workflows
In case we load definition of one workflow, there is no need to convert
it to yaml and back.

Change-Id: Ia7fb914843e56650c8f6ff5e8c16d1b57001c0fc
Signed-off-by: Oleg Ovcharuk <vgvoleg@gmail.com>
2019-06-10 11:50:43 +03:00
Oleg Ovcharuk c712e369ed Divide yaml input to save it into definitions separately.
In case of creating/updating multiple workflows from one yaml,
we should not save the whole input to each workflow.

Closes-Bug: #1792975
Change-Id: I724c041ab3441805fcfa2cfc4a50afd774998cc7
Signed-off-by: Oleg Ovcharuk <vgvoleg@gmail.com>
2018-11-09 07:27:44 +00:00
Renat Akhmerov c802ad2851 Make task execution logging more readable and informative
* Changed a debug log statement more readable for tasks
* Minor style changes

Change-Id: I841c15230fe2bc1e605a985bb1b9cd6131ac795c
2018-10-01 11:37:48 +07:00
Vitalii Solodilov 4bf03d8e7d Remove extra a specification validation
Currently when we get a specification using the instantiate_spec function,
we always validate their schema and semantics over and over again.
To prevent it we add new validate parameter to a Spec class.
The validate parameter must be True when we create a workflow, workbook
or action using a mistral-api. In all other cases, it must be False.

Change-Id: Ia450ea9635bc75c204fe031cfeeab154f1d03862
Closes-Bug: #1738769
Signed-off-by: Vitalii Solodilov <mcdkr@yandex.ru>
2018-07-30 11:55:35 +04:00
hardikj 834747b5d9 Add namespace support for workbooks
This patch brings namespace support to workbooks.
Namespace of the workbook is inherited by workflows.

Implements: blueprint mistral-namespace-for-actions-workbooks
Change-Id: I2c66b3961915f0f35a9c468eb6dd0c0c70995234
2018-07-26 17:13:58 +05:30
Renat Akhmerov b77769cf44 Get rid of a extra copy of workflow environment
* Previously, we had two copies of the workflow environment
  passed by a user: one was in the 'params' fields under ke 'env'
  key and another one was copied into the 'context' field under
  the '__env' key so that we can evaluate expressions involving
  the env() function (YAQL or Jinja).
  This patch removes the copy from the 'context' field in favor
  of using an ad-hoc ContextView structure where we now also
  weave in the environment dictionary under the same key '__env'.

Related-Bug: #1757966
Change-Id: I1204b082794b376787d126136a79dd204ec3af07
2018-04-27 19:47:32 +07:00
Renat Akhmerov 4936d778e5 Optimizing big 'on-XXX' clauses
* Fixed the implementation of data_flow.evaluate_task_outbound_context
  method so that it doesn't use copy.deepcopy() because it may be
  very expensive (both CPU and RAM) on big dictionaries.

Change-Id: I6cc77c6ded1e8f00ff164156be9312e1ccb86efb
2018-04-17 14:30:41 +07:00
byhan 068aa53623 Modify log infomation to achieve the same format
Some log information starts with capital letter
Some log information starts with lowercase letter
Change them to starting with capital letter

Closes-Bug:#1732375

Change-Id: Ib40a327d299292ba3a417f3f0384f466fcefaa80
2017-11-20 09:04:54 +00:00
Michal Gershenzon cbee740de5 Create and run a workflow within a namespace
Allow adding many workflows with the same name.
The way this works is by adding the new workflows under another
namespace.

Notice that:
  1. Namespaces are not part of the mistral DSL.
  2. When executing a workflow, the namespace passes down to the
     subworkflow.
  3. When searching for the sub-workflow definition -
     If no workflow was found in the given namespace, than the defualt
     namespace will be used.
  4. The default namespace is an empty string.
  5. The namespace property or the workflow execution will be under
     params

Partially-Implements: blueprint create-and-run-workflows-within-a-namespace

Change-Id: Id248ec5906a0899d188675d002b45f6249d36d90
2017-08-01 13:51:05 +00:00
Adriano Petrich 4c53234e27 Adding log to db_sync
if called by mistral-db-manage it will log info level
    to /var/log/mistral/mistral-db-manage

Included some debug level logging also for main actions.

Change-Id: I0574b38efcc0dd7485953bf3089ff0a5a3ef6394
Closes-Bug: #1689821
2017-05-16 05:17:08 +00:00
Renat Akhmerov 5c140a2fce Rename package 'workbook' to 'lang'
* The previous name of the package is not relevant anymore, it was
  chosen for reasons that don't make sense anymore. A name of the
  package should reflect that it's about the workflow language.

Change-Id: I7e05ba97abf0aa5db4e19d9d72b4ea0d52e328fb
2017-03-06 15:41:37 +07:00
Renat Akhmerov bdf49b7193 Remove environment data from task inbound context
* It's redundant to keep environment data in task inbound context,
  it is immutable and we can always take it from workflow execution
  object which is more efficient from DB space consumption
  standpoint. The only case when it's allowed to modify data
  in a workflow environment is when we either resume or re-run
  a workflow and in this case we can change it for the whole
  workflow execution.

Change-Id: I244c1768aaa306f8ad41084325107a40005d874c
2016-09-26 14:50:10 +03:00
Renat Akhmerov f2445acb28 Fix specification caching mechanism
* The problem was that cache instance was instantiated on different
  Mistral instances and invalidation didn't work properly (known
  problem for local cache implementations). The solution, first of
  all, is to cache specifications by workflow execution ids so that
  we get a consistent spec value during workflow execution lifetime.
  And secondly, if we need to build a specification based on
  workflow definition id we also need to use 'updated_at' as part of
  cache key so that if workflow definition has changed the cache is
  updated properly. Old cache entities would be kicked out of cache
  by LRU algorithm as the cache runs out of space.

Change-Id: If97b2e47d8adcbd7b5d5844b56e24eac1b1ae6c1
2016-08-09 20:16:09 +07:00
Jenkins 3a7e91df4a Merge "Fixed trivial issue in exception message" 2016-08-04 13:07:59 +00:00
Renat Akhmerov 09c08864dc Invalidate workflow spec cache on workflow definition updates
* Workflow spec cache is updated on update of workbook and workflow
* Fixed scheduler docstring

Change-Id: I64042db4aa902166d2e80ea30adb7cbca1515c39
2016-08-02 11:47:28 +07:00
hardik b2aabd221a Fixed trivial issue in exception message
Change-Id: I2837875f82a87394be502016a21642b1dffde1f0
2016-07-29 16:44:52 +05:30
Renat Akhmerov e2c89f777d Refactoring workflow handler
* Introduced new class Workflow that manages life-cycle of running
  workflows and is responsible for managing workflow persistent state
* Moved all workflow level logic to workflow handler and Workflow class
* Changed semantics if how workflows start errors are handled.
  Previously, in case of invalid user input Mistral engine would store
  information about error in "state_info" field of workflow execution
  and bubble up an exception to the user. This approach was incorrect
  for a number of reasons including broken semantics: if an exception
  was raised due to invalid input it's normal to expect that system
  state has not changed. After this refactoring, engine only raises
  an exception in case of bad user input. That way behavior is
  consistent with the idea of exceptional situations.
* Fixed unit tests in according to the previous point
* Fixed a number of logical issues in tests. For example, in
  test_default_engine.py we expected one type of errors (e.g. env not
  found) but effectively received another one (invalid input).

Partially implements: blueprint mistral-engine-error-handling

Change-Id: I09070411fd833df8284cb80db69b8401a40eb6fe
2016-06-07 18:38:38 +07:00
Winson Chan 0e7be02a48 Allow env update on resume and rerun workflows
Add optional env kwarg to resume_workflow and rerun_workflow in default
engine. Add database API to update env in the params and context of the
existing workflow execution. The updated env will be merged into existing
__env of workflow context. For existing task, the env will be merged into
__env of in_context.

Partially implements: blueprint mistral-rerun-update-env

Change-Id: Id378762d90ca5fc62d14e22134f18f9bce71a123
2016-01-11 20:52:48 +00:00
Lingxian Kong b468b9f524 Support UUID when updating a workflow definition
* When updating a workflow with UUID provided, only one workflow
  definition could be contained in request body.
* Workflow name can also be updated when using UUID.
* Tenant can not update workflows of other tenants.

Partially implements: blueprint use-workflow-id-in-rest-api
Change-Id: I87f9122b8ad9727a3eeb429ce19835c57c76b32d
2015-12-18 13:21:32 +08:00
Nikolay Mahotkin 3b3695efca Wrap sync_db operations in transactions
Fix for fail on failed to find system actions

Change-Id: Ief7cf96eedd201990ca3c169fb0c1509ee55665e
Closes-Bug: 1508379
2015-11-16 15:33:02 +00:00
Nikolay Mahotkin 1c702e2555 Adding 'is_system' to definition model
* Fixed work of mistral-db-manage populate
 * Fixed modifying of standard workflows

Closes-Bug: #1478448
Closes-Bug: #1396121

Change-Id: Ia2825408ee43a6dfc80e33fa9614e11f3ff6d97b
2015-09-17 13:31:27 +03:00
Limor Stotland 856d1d7154 Make update behavior consistent
Keep behavior of updating workflow consistent with that of workbook and
environment. The update command will fail if the workflow doesn't exist.

Change-Id: I7a871c2ac378ac0b7f6360f03f395816b9d0f4b0
Closes-Bug: #1418545
2015-07-15 07:00:31 +00:00
Nikolay Mahotkin 4e699ce21b Fixing mistral resources path
* Fixed standard actions and workflows paths.
   If mistral is installed in system, 'resources'
   are not copied to dist-packages/mistral, so
   mistral-db-manage populate command won't work.
   Now resources are included in mistral.

Closes-Bug: #1457842

Change-Id: I3149867e615acd188691b299a051e7458e2eb386
2015-05-22 14:11:33 +03:00
Renat Akhmerov bdefdc6a6f Refactoring task output: full redesign of DB models
* Created a Execution hierarcy mapped on a single table:
  - ActionExecution
  - WorkflowExecution
  - TaskExecution
* Created necessary associations within Execution hierarchy
* Created necessary methods for Execution objects on DB API
* Created Definition hierarchy mapped on separate tables:
  - Workbook
  - WorkflowDefinition
  - ActionDefinition
* Renamed attributes
  - 'wf_name' -> 'workflow_name'
  - 'wf_spec' -> 'spec'
* Fixed all unit tests

TODO:
* Complete renaming throughout the code
* Further refactoring of workflow engine

Change-Id: I0032bea573d9200025f9f7dd951e93cb6f1661bb
2015-03-03 16:50:55 +06:00
Nikolay Mahotkin fdfee071c9 Fixing problem with trust creation
Closes-Bug: #1413124

Change-Id: I5de648fdcf56afcd74e15b3652ac8a13a2a7d37c
2015-01-23 09:50:31 +00:00
Renat Akhmerov 9fcbfbe2f9 Working on secure DB access (part 3)
* Moving method get_project_id() to services/security.py

Change-Id: Id4a166a754c1eda24280e7454530339b43243cb3
2015-01-22 16:37:30 +00:00
Renat Akhmerov 693227ffcf Working on secure DB access (part 1)
* Refactored DB models with new mixin class MistralSecureModelMixin
* Refactored services working with workflows, worbooks, actions
* Other minor changes

Change-Id: I9f2cb5c02670aa8c4c3dd06c4301f2e613f5c013
2015-01-22 16:35:26 +00:00
Renat Akhmerov b5140060a0 Renaming trusts.py to security.py and adding method add_security_info
Change-Id: Ia25afa6c24cbdba8eabfbd2adc0e7ca40a04b8b6
2014-11-27 15:53:32 +06:00
Renat Akhmerov 836c66996d Fixing condition in workflow service
Change-Id: I50d335ef071852a42a7e0fc43c277692cf5e9337
2014-10-14 09:54:24 +07:00
Renat Akhmerov c8f84f6724 Refactoring workflow and action services
Change-Id: I153b5a09a21be58cb0d2645e9d1d62eb30fb3617
2014-10-14 09:54:21 +07:00
Renat Akhmerov 7515f3be34 Implementing cron cron trigger v2
* Refactored triggers v1
* Implemented triggers v2
* Refactored tests for triggers v1
* Added simple unit tests for v2
* Refactored workflow service

Change-Id: I950d858f9f90e6f1c16580667512bc134c07be57
2014-10-14 09:54:17 +07:00
Nikolay Mahotkin bb5d09b0e3 Create standard workflows and actions
* Standard workflows are creating during sync_db.sh
 * Standard workflows include:
     - std.create_instance
     - std.delete_instance
     (list will be extended in future)
 * Standard actions:
     - std.wait_ssh (needed for std.create_instance)
 * Make it possible to see these workflows from any project (global scope)
 * Small changes in sqlalchemy api and workflows_service

Partially implements blueprint mistral-multitenancy

Change-Id: I8a8ace40949b2b711a292aac94d7e6354d1dff9c
2014-10-10 12:46:40 +04:00
Renat Akhmerov 914bbcd8c7 Modifying workflow and action services to save 'tags'
Closes-Bug: #1373295

Change-Id: I6812675d47cfc1d9f5108d2fe4466abaa7e2e40f
2014-09-25 15:02:19 -07:00
Renat Akhmerov 9f0ea2519b Making workflow endpoint able to upload multiple workflows
* Added WorkflowListSpec that represents a top level specification
  for uploading workflows (shouldn't be confused with WorkflowSpecList)
* Added workflow service that takes care of parsing, validating and
  creating multiple workflows from definition
* Added unit tests for workflow service
* Fixed workflow controller to work with multiple workflows on post/put
* Fixed workflow controller tests

Change-Id: I70a46a16e1970673fec0352091e4b610f320fbb8
2014-09-22 14:52:04 -07:00
Nikolay Mahotkin 3170fb4aab Add workflow service module
* According to adding 'name' in DSL

Change-Id: I3c1e0bde023d081335f21c5c3bc30ca7467d06d0
2014-09-22 11:52:50 +00:00