-
-
Notifications
You must be signed in to change notification settings - Fork 782
[WIP] [Issue#4939] Changes to support new purge task executions and purge workflows #4924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
66a06e9
changes to support new purge task executions and st2 purge workflow
srimandaleeka01 4ee1b5d
Merge branch 'master' into sri/pxpse_8278
srimandaleeka01 5f1dab8
Support new purge task executions and st2 purge workflow
srimandaleeka01 249eebd
Merge branch 'sri/pxpse_8278' of https://github.com/Plexxi/st2 into s…
srimandaleeka01 62dd9ac
Merge branch 'master' into sri/pxpse_8278
srimandaleeka01 cb28924
Merge branch 'master' into sri/pxpse_8278
srimandaleeka01 95d0cf3
Merge branch 'master' into sri/pxpse_8278
srimandaleeka01 36c7fdf
Call the purge workflow and task execution methods in the garbage col…
srimandaleeka01 e9d9cbb
Fix unit tests
srimandaleeka01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #!/usr/bin/env python | ||
| # Licensed to the StackStorm, Inc ('StackStorm') under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import sys | ||
|
|
||
| from st2common.cmd.purge_task_executions import main | ||
|
|
||
| if __name__ == '__main__': | ||
| sys.exit(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #!/usr/bin/env python | ||
| # Licensed to the StackStorm, Inc ('StackStorm') under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import sys | ||
|
|
||
| from st2common.cmd.purge_workflows import main | ||
|
|
||
| if __name__ == '__main__': | ||
| sys.exit(main()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| # Copyright 2019 Extreme Networks, Inc. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| """ | ||
| A utility script that purges st2 executions older than certain | ||
| timestamp. | ||
|
|
||
| *** RISK RISK RISK. You will lose data. Run at your own risk. *** | ||
| """ | ||
|
|
||
| from __future__ import absolute_import | ||
|
|
||
| from datetime import datetime | ||
|
|
||
| import six | ||
| import pytz | ||
| from oslo_config import cfg | ||
|
|
||
| from st2common import config | ||
| from st2common import log as logging | ||
| from st2common.config import do_register_cli_opts | ||
| from st2common.script_setup import setup as common_setup | ||
| from st2common.script_setup import teardown as common_teardown | ||
| from st2common.constants.exit_codes import SUCCESS_EXIT_CODE | ||
| from st2common.constants.exit_codes import FAILURE_EXIT_CODE | ||
| from st2common.garbage_collection.workflows import purge_task_execution | ||
|
|
||
| __all__ = [ | ||
| 'main' | ||
| ] | ||
|
|
||
| LOG = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def _register_cli_opts(): | ||
| cli_opts = [ | ||
| cfg.StrOpt('timestamp', default=None, | ||
| help='Will delete execution and liveaction models older than ' + | ||
| 'this UTC timestamp. ' + | ||
| 'Example value: 2015-03-13T19:01:27.255542Z.'), | ||
| cfg.StrOpt('action-ref', default='', | ||
| help='action-ref to delete executions for.'), | ||
| cfg.BoolOpt('purge-incomplete', default=False, | ||
| help='Purge all models irrespective of their ``status``.' + | ||
| 'By default, only executions in completed states such as "succeeeded" ' + | ||
| ', "failed", "canceled" and "timed_out" are deleted.'), | ||
| ] | ||
| do_register_cli_opts(cli_opts) | ||
|
|
||
|
|
||
| def main(): | ||
| _register_cli_opts() | ||
| common_setup(config=config, setup_db=True, register_mq_exchanges=False) | ||
|
|
||
| # Get config values | ||
| timestamp = cfg.CONF.timestamp | ||
| action_ref = cfg.CONF.action_ref | ||
| purge_incomplete = cfg.CONF.purge_incomplete | ||
|
|
||
| if not timestamp: | ||
| LOG.error('Please supply a timestamp for purging models. Aborting.') | ||
| return 1 | ||
| else: | ||
| timestamp = datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%fZ') | ||
| timestamp = timestamp.replace(tzinfo=pytz.UTC) | ||
|
|
||
| try: | ||
| purge_task_execution(logger=LOG, timestamp=timestamp, action_ref=action_ref, | ||
| purge_incomplete=purge_incomplete) | ||
| except Exception as e: | ||
| LOG.exception(six.text_type(e)) | ||
| return FAILURE_EXIT_CODE | ||
| finally: | ||
| common_teardown() | ||
|
|
||
| return SUCCESS_EXIT_CODE | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| # Copyright 2019 Extreme Networks, Inc. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copyright 2021, The StackStorm Authors. |
||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| """ | ||
| A utility script that purges st2 executions older than certain | ||
| timestamp. | ||
|
|
||
| *** RISK RISK RISK. You will lose data. Run at your own risk. *** | ||
| """ | ||
|
|
||
| from __future__ import absolute_import | ||
|
|
||
| from datetime import datetime | ||
|
|
||
| import six | ||
| import pytz | ||
| from oslo_config import cfg | ||
|
|
||
| from st2common import config | ||
| from st2common import log as logging | ||
| from st2common.config import do_register_cli_opts | ||
| from st2common.script_setup import setup as common_setup | ||
| from st2common.script_setup import teardown as common_teardown | ||
| from st2common.constants.exit_codes import SUCCESS_EXIT_CODE | ||
| from st2common.constants.exit_codes import FAILURE_EXIT_CODE | ||
| from st2common.garbage_collection.workflows import purge_workflow_execution | ||
|
|
||
| __all__ = [ | ||
| 'main' | ||
| ] | ||
|
|
||
| LOG = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def _register_cli_opts(): | ||
| cli_opts = [ | ||
| cfg.StrOpt('timestamp', default=None, | ||
| help='Will delete execution and liveaction models older than ' + | ||
| 'this UTC timestamp. ' + | ||
| 'Example value: 2015-03-13T19:01:27.255542Z.'), | ||
| cfg.StrOpt('action-ref', default='', | ||
| help='action-ref to delete executions for.'), | ||
| cfg.BoolOpt('purge-incomplete', default=False, | ||
| help='Purge all models irrespective of their ``status``.' + | ||
| 'By default, only executions in completed states such as "succeeeded" ' + | ||
| ', "failed", "canceled" and "timed_out" are deleted.'), | ||
| ] | ||
| do_register_cli_opts(cli_opts) | ||
|
|
||
|
|
||
| def main(): | ||
| _register_cli_opts() | ||
| common_setup(config=config, setup_db=True, register_mq_exchanges=False) | ||
|
|
||
| # Get config values | ||
| timestamp = cfg.CONF.timestamp | ||
| action_ref = cfg.CONF.action_ref | ||
| purge_incomplete = cfg.CONF.purge_incomplete | ||
|
|
||
| if not timestamp: | ||
| LOG.error('Please supply a timestamp for purging models. Aborting.') | ||
| return 1 | ||
| else: | ||
| timestamp = datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%fZ') | ||
| timestamp = timestamp.replace(tzinfo=pytz.UTC) | ||
|
|
||
| try: | ||
| purge_workflow_execution(logger=LOG, timestamp=timestamp, action_ref=action_ref, | ||
| purge_incomplete=purge_incomplete) | ||
| except Exception as e: | ||
| LOG.exception(six.text_type(e)) | ||
| return FAILURE_EXIT_CODE | ||
| finally: | ||
| common_teardown() | ||
|
|
||
| return SUCCESS_EXIT_CODE | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copyright is now StackStorm Authors, and year file first introduced, e.g. could you change to:
Copyright 2021, The StackStorm Authors.