Commit Graph

298 Commits

Author SHA1 Message Date
Vadim Zelenevsky cadfe9dca2 Fix maintence mode
Added MaintenceHook to app configuration
Refactored maintence service
Fixed sql queries
Fix maintence controller

Closes-Bug: #2058009
Signed-off-by: Vadim Zelenevsky <wortellen@gmail.com>
Change-Id: Ica41e8208b29aeba6e781801540843d46375c3d1
2024-04-08 07:24:41 +00:00
Zuul 4446f9ced8 Merge "Python 3.12: cast random delays as int" 2024-03-20 09:29:16 +00:00
Thomas Goirand 2b2c8759d4 Python 3.12: cast random delays as int
This patch fixes 128 unit test failures under Python 3.12 when
building the Debian package under Unstable. Without this patch,
I'm getting:

Traceback (most recent call last):
  File "/usr/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/<<PKGBUILDDIR>>/mistral/services/legacy_scheduler.py", line 152, in _loop
    random.Random().randint(0, self._random_delay * 1000) * 0.001
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/random.py", line 336, in randint
    return self.randrange(a, b+1)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/random.py", line 312, in randrange
    istop = _index(stop)
            ^^^^^^^^^^^^
TypeError: 'float' object cannot be interpreted as an integer

Change-Id: Ia85ea13923216d090ef1e4deee7840e70f9185b4
2024-03-19 09:04:43 +01:00
Takashi Kajinami 44cd95684b Bump hacking
hacking 3.0.x is too old.

Also remove the note about pip's behavior which was already fixed in
recent versions.

Change-Id: I65d350943649c3346ed5741631c01724ddd256ef
2024-02-19 02:23:53 +09:00
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
Vasudeo Nimbekar 51574ef6ef Added maintenance mode
Change-Id: Ie42fcfa96044da1793f1afbff5fb2ae5534d5c2e
2023-05-31 17:31:42 +05:30
Vasudeo Nimbekar 88e7e7ceee Adding root_execution_id parameter to mistral loggers
After this patch, user can update logging format to include root_execution_id in logs, which will be helpful to find and debug logs related to specific workflow execution.

  - Logs about creation and status changes of Mistral entities(execution,
    task, action execution, etc) are changed to INFO log level.
  - User can update logging_context_format_string to include root_execution_id in logs.

Implements: Implements: blueprint improve-mistral-loggers

Change-Id: I54fe058e5451abba6ea7f69d03d498d78a90993e
2023-02-13 05:01:39 +00:00
Arnaud Morin 5e069e1c98 Remove extra description on cron trigger executions
When creating a periodic workflow execution from a cron trigger, the
description field was filled with info like cron trigger ID, name, etc.

The cron trigger name can be set by user and is then injected in the
description field.
Beside the fact that this is not useful, it may also be dangerous.

The purpose of this patch is to remove the name from the description so
that the lenght of description field is not user dependant anymore.

Signed-off-by: Arnaud Morin <arnaud.morin@ovhcloud.com>
Change-Id: I326400a4a04fba71ccc90545909212a41d6b3b13
2022-09-29 10:42:03 +02:00
Takashi Kajinami e82c4ca08b Replace deprecated arguments of RequestContext
The following arguments of the RequestContext class are deprecated
since oslo.context 2.18[1].
 user          : renamed to user_id
 tenant        : renamed to project_id
 domain        : renamed to domain_id
 user_domain   : renamed to user_domain_id
 project_domain: renamed to project_domain_id

This change updates arguments used accordingly.

[1] d78cf592e1e3e7aa0fc99bfdd655e82f5c44dfe3

Change-Id: I24a8963d112a24674ad5699685118d019ef1ed56
2022-03-02 09:29:24 +00:00
songwenping 22e822dde2 Remove references to sys.version_info
We support Python 3.6 as a minimum now, making these checks no-ops.

Change-Id: Ia4b1eec7a788cb1ede3dc338f7be7e5d8a84069d
2021-07-10 06:20:08 +00:00
Renat Akhmerov a73fe5b8a3 Fix dynamic actions further
* Reworked /code_sources and /dynamic_actions API endpoints to
  simplify them. For now they don't work with multiple objects and
  they are consistent with other endpoints. If needed, we'll add
  support for multiple objects (i.e. adding multiple dynamic actions
  with a single request) later in a backwards compatible manner.
* Simplified unit tests.
* Got rid of services/*.py modules since they didn't do anything
  useful. They were just wrappers around DB API calls.

Change-Id: Ib5a53f1f1a185f0395ffae1ab0c401633fcdd0fc
2020-12-03 16:51:25 +07:00
Renat Akhmerov f78f33507e Code improvements after the dynamic actions patch
* Style improvements to make sure the code is compliant with the
  coding guidelines
* Fixing small but important things like the mismatch between the
  sinatures of the methods find_all() in the DynamicActionProvider
  class and the base ActionProvider interface.
* Improved the tests.
* Simplified the implementation of DynamicActionProvider.

Change-Id: Idbfb15b4c3bb415e7fa9c7ece27eabfe674b6059
2020-11-23 15:33:54 +07:00
ali 9be4f8e119 created a new Api endpoints and added dynamic actions
* added dynamic actions:
     these actions are created and modified in runtime,
     each action needs a code source to be imported from and a
     class name.

 - there are 2 new endpoints:
    - /v2/code_sources/:
       used to add new code sources to mistral.
    - /v2/dynamic_actions/:
      used to add dynamic actions to mistral in runtime

 - a new Action provider (DynamicActionProvider) was added:
    it provides the actions created from the dynamic actions api.

Change-Id: I9fe8c28ffdef71016d9dc13aea60a288c8ebaa0a
Signed-off-by: ali <ali.abdelal@nokia.com>
2020-11-18 10:15:26 +00:00
Renat Akhmerov 06a0f33476 Refactor Mistral with Action Providers
* This patch refactors Mistral with the action provider concept
  that is responsible for delivering actions to the system. So
  it takes all the burden of managing action definitions w/o
  having to spread that across multiple subsystems like Engine
  and API and w/o having to assume that action definitions are
  always stored in DB.
* Added LegacyActionProvider  that represents the old way of
  delivering action definitions to the system. It pretty much just
  analyses what entries are configured in the entry point
  "mistral.actions" in setup.cfg and build a collection of
  corresponding Python action classes in memory accessible by names.
* The module mistral/services/actions.py is now renamed to
  adhoc_actions.py because it's effectively responsible only for
  ad-hoc actions (those defined in YAML).
* Added the new entry point in setup.cfg "mistral.action.providers"
  to register action provider classes
* Added the module mistral/services/actions.py that will be a facade
  for action providers. Engine and other subsystems will need to
  work with it.
* Other small code changes.

Depends-On: I13033253d5098655a001135c8702d1b1d13e76d4
Depends-On: Ic9108c9293731b3576081c75f2786e1156ba0ccd
Change-Id: I8e826657acb12bbd705668180f7a3305e1e597e2
2020-09-24 11:10:33 +00:00
Q.hongtao 4bc6162515 Remove six library
Remove six-library Replace the following items with Python 3 style code.
- six.interger_types
- six.itervalues
- six.text_type
- six.string_types
- six.StringIO
- six.next
- six.b
- six.PY3

Change-Id: I299c90d5cbeb41be0132691265b8dcbeae65520e
2020-09-23 10:27:12 +08: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
Eyal 8bdf341af7 Remove OpenStack actions from mistral
Depends-on: https://review.opendev.org/#/c/703296/
Depends-On: https://review.opendev.org/#/c/704280/
Change-Id: Id62fdabe7699e7c3b2977166e253cfc77779e467
2020-02-26 10:12:01 +02:00
Renat Akhmerov 6dc0c05f04 Fix adhoc actions
* Method _create_action_execution() for AdHocActin didn't have
  the right signature. It was missing the argument "namespace" and
  failed under some conditions. This patch does some refactoring
  to preserve the target namespace during action init time. For
  regular python actions it's just taken from it's action definition
  object. For ad-hoc actions it is taken from its definition also
  but it has to do it separately because it extends the class
  PythonAction passing a base action definition into it as a parameter
  of the initializer (so that extracts the namespace of the base action).
  The benefit of preserving a namespace value during init time is that
  it becomes available for the entire instance life-span, not only for
  the method _create_action_execution().
* Style changes (blank lines, indentation, formatting).

Change-Id: I84d1cd0fb4a746197ad890276f654cd12455603e
2020-02-19 14:48:35 +07:00
Renat Akhmerov 5b5576dd04 Set the delayed call "key" field to the right value
* The field "key" of the DelayedCall class must be set to the right
  value. It allows to significantly optimize performance of workflows
  with "join" tasks. However, it was broken during the refactoring
  in the summer of 2019. This patch fixes it.
* Added another profiler trace decorator.

Closes-Bug: #1861988
Change-Id: I247b674d8a358795871cfa87bcdf29f4857ca2d8
2020-02-05 09:09:50 +00:00
Renat Akhmerov 511be4f98f Initialize profiler for scheduler threads
* It turns out that osprofiler wasn't initialized properly for
  threads in which scheduler runs its jobs. So profiling simply
  didn't work for this threads and lots of important info didn't
  get to the profiler log. This patch fixes it.
* When evaluating a YAQL expression, sometimes we get a huge result
  value that we always put into the debug log. In practice, it doesn't
  make much sense and, moreover, it utilizes lots of CPU and disk
  space. It's better shrink it to some reasonable size that would
  allow to make necessary analysis, if needed.
* Other minor style fixes according to the Mistral coding guidelines.

Change-Id: I3df3ab96342c456429e20a905615b90bcb94818d
2020-01-30 16:23:56 +07: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
ali 20c3408692 Add namespaces to Ad-Hoc actions
added namespace for the actions, actions can have the same name if they
 are not in the same namespace, when executing an action, if an action
 with that name is not found in the workflow namespace or given
 namespace mistral will look for that action in the default namespace.

  * action base can only be in the same namespace,or in the
    default namespace.
  * Namespaces are not part of the mistral DSL.
  * The default namespace is an empty string ''.
  * all actions will be in a namespace, if not specified, they will be
    under default namespace

Depends-On: I61acaed1658d291798e10229e81136259fcdb627
Change-Id: I07862e30adf28404ec70a473571a9213e53d8a08
Partially-Implements: blueprint create-and-run-workflows-within-a-namespace
Signed-off-by: ali <ali.abdelal@nokia.com>
2020-01-07 08:10:53 +00: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 7b58b9c267 Fix log messages in the action heartbeats mechanism
Change-Id: Ic1293db03d020f321d4e009ab7906da7622c5daf
2019-11-22 14:46:32 +07:00
Zuul a9a7a99237 Merge "Make action heartbeats work for all executor types" 2019-11-18 04:49:28 +00:00
Zuul 6701883a03 Merge "Refactor action execution reporter" 2019-11-18 04:49:27 +00:00
Renat Akhmerov 7ec4f26744 Make action heartbeats work for all executor types
* Previously action hearbeats didn't work in case of using local
  executors because the component responsible for sending heartbeats
  was started by the executor RPC server which doesn't make sense to
  initialize for a local executor. This patch refactors the code
  so that now heartbeats get sent for any type of executors. For
  local executors it is also useful because a cluster node that
  runs an engine and a local executor may also crash. With this
  change, remaining cluster nodes will be able to understand that
  the action will never complete and one of them will time it out.
  If all is fine with the node where the local executor is running
  then heartbeats will be sent normally and the action won't time
  out. Before this change, in case of local executors a long running
  action would always time out after a configured amount of time
  (by default, 60 mins) just because local executors never sent
  heartbeats.
* Made a lot of renamings to clearly see what component is
  responsible for.
* Wrote the tests that check the heartbeat sender, both positive
  and negative scenarios for local and remote executor types.

Closes-Bug: #1852722

Change-Id: I4d0fdff54de9bee70aeaf10a4ef483ad7000840b
2019-11-15 16:44:40 +07:00
Renat Akhmerov 0e758e16e1 Refactor action execution reporter
* Moved away from using Oslo periodic tasks in the action execution
  reporter since in this case they don't make the code more readable.
  Also, now it is symmetric with other similar components like action
  execution checker.
* Refactored action execution checker w/o using classes since having
  many instances of it doesn't make sense.
* Small style changes

Change-Id: I9a97c40222e8dc4870c9b6a7c5f5e3c14f37bdd6
2019-11-12 17:42:59 +07:00
ali 6b862e625e Extend capabilities to clean up old executions
* Added a configuration option to the expiration policy
  to filter out workflow states.

Closes-Bug: #1796627
Change-Id: Ife49e6da1d7d52a3f50f1628d808d4c65a22cad9
2019-11-12 07:12:45 +00: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
Renat Akhmerov 0f6bc1897f Improve new scheduler
* Changed method get_scheduled_jobs_count() in the Scheduler
  interface to has_scheduled_jobs(). In fact, the callers
  always need to compare the number of jobs with 0, i.e.
  to see if there are any jobs or not. But more importantly,
  this semantics (returning just boolean) allows to make a
  good optimisation for DefaultScheduler and avoid DB calls
  in a number of cases. Practically, for example, it saves
  several seconds (5-6) if we run a workflow with 500 parallel
  no-op tasks that are all merged with one "join" task. Tested
  on 1 and 2 engines.
* Added test assertions for has_scheduled_jobs()
* Other minor chagnes

Change-Id: Ife48d9e464114fd60a08707d8f32f847a6f623c9
2019-08-16 13:39:39 +07:00
Mike Fedosin 6914823380 Bulk delete of stored delayed calls
Instead of making a lot of single requests for deleting stored delayed
calls, we can use bulk requests.

Change-Id: Ia2a6462d72f31df18a9811329672eae7f60d160f
2019-07-22 13:37:35 +02:00
Renat Akhmerov 43d23c0e25 Create needed infrastructure to switch scheduler implementations
* After this patch we can switch scheduler implementations in the
  configuration. All functionality related to scheduling jobs is
  now expressed vi the internal API classes Scheduler and
  SchedulerJob. Patch also adds another entry point into setup.cfg
  where we can register a new scheduler implementation.
* The new scheduler (which is now called DefaultScheduler) still
  should be considered experimental and requires a lot of testing
  and optimisations.
* Fixed and refactored "with-items" tests. Before the patch they
  were breaking the "black box" testing principle and relied on
  on some either purely implementation or volatile data (e.g.
  checks of the internal 'capacity' property)
* Fixed all other relevant tests.

Change-Id: I340f886615d416a1db08e4516f825d200f76860d
2019-06-24 11:25:57 +03: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
Zuul 0eb1611327 Merge "[Event-engine] Allow event_engine to work in HA" 2018-12-09 11:31:19 +00:00
Zuul d9e9391b4e Merge "Eliminating datetime.now()" 2018-12-04 21:03:09 +00:00
Renat Akhmerov 3153f1ca58 Set admin security context in the action execution checker thread
Change-Id: I4c7abff04b8797618294d9e13fbec4b5876bcdb6
Closes-Bug: #1805080
2018-11-26 14:09:59 +00:00
Kupai József 38cc50bc1e Eliminating datetime.now()
Using utc everywhere to eliminite timezone difference related lurky issues.

Change-Id: If90f1404d5a3c26dc2608ba3977199d69879fab7
2018-11-21 10:51:44 +01:00
Zuul 4b83cef3af Merge "Divide yaml input to save it into definitions separately." 2018-11-12 10:45:05 +00: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 2d74e6ebac Refactor action execution checker without using scheduler
* Removed using scheduler from action execution heartbeat checker
  in favor of regular threads.
* Added the new config options "batch_size" under [action_heartbeat]
  group to limit a number of action executions being processed during
  one iteration the checker.
* Added a test checking that an action execution is automatically
  failed by the heartbeat checker.

Closes-Bug: #1802065
Change-Id: I18c0c2c3159b9294c8af96c93c65a6edfc1de1a1
2018-11-09 14:17:28 +07:00
Renat Akhmerov 80a1bed67b Simplify workflow and join completion logic
* action_queue module is replaced with the more generic
  post_tx_queue module that allows to register operations that must
  run after the main DB transaction associated with processing a
  workflow event such as completing action.
* Instead of calling workflow completion check from all places
  where task may possibly complete, Mistral now registers a post
  transactional operation that runs after the main DB transaction
  (to make sure at least one needed consistent DB read) right
  inside the task completion logic. It reduces clutter significantly.
* Workflow completion check is now registered only if the just
  completed task may lead to workflow completion, i.e. if it's the
  last one in a workflow branch.
* Join now checks delayed calls to reduce a number of join
  completion checks created with scheduler and also uses post
  transactional queue for that.

Closes-Bug: #1801872
Change-Id: I90741d4121c48c42606dfa850cfe824557b095d0
2018-11-09 14:17:20 +07:00
Jose Castro Leon defff08773 [Event-engine] Allow event_engine to work in HA
A previous patch allows to make multiple event_engines to listen
to a single queue, but the RPC calls on CRUD are still synchronous

This patch modifies the calls and broadcasts them on all the event
engines allow them to modify each independent listeners.

Closes-Bug: #1715848
Change-Id: Ia37831a03993f5a1bf980d62344d25377062788d
2018-10-17 16:30:17 +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
Renat Akhmerov 8f40b01cb6 Performance: remove unnecessary workflow execution update
* This fix drastically improves performance since it eliminates
  an unnecessary update of the workflow execution object when
  processing "on_action_complete" operation. W/o this fix
  all such transactions would have to compete for the workflow
  executions table that causes lots of DB deadlocks (on MySQL)
  and transaction retries. In some cases the number of retries
  even exceeds the limit (currently hardcoded 50) and such tasks
  can be fixed only with the integrity checker over time.
  See the code comment in the "dispatcher.py" module that explains
  why this specific change eliminates the update of the workflow
  execution object.
* Style changes in api.py and aciton_execution_checker.py

Closes-Bug: #1790079

Change-Id: I08cb561e252d31e35fcfb61984d87a7bfc387a4d
2018-09-03 11:47:11 +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
Zuul 846222cf2f Merge "Make cron-triggers not play catchup" 2018-06-18 16:03:03 +00:00
Adriano Petrich 07c26e50dc Make cron-triggers not play catchup
Currently if the API is stopped for a length and restarted the crontrigger
jobs will have their next execution in the past and will do a catchup
running a lot of times. That happens because the next execution is
calculated based on the first time it was executed. This change makes it be
the next execution time be the max of the calculated time and utcnow so
that if the server is lagging we keep uptodate with the calculated next
execution times.

Change-Id: I05b35261b1adbe17a1b0316eee95da12634c3978
Closes-bug: 1719882
2018-06-14 09:49:24 +01:00