From 7ff07b2e5d36a9f314741c1f79a62656fe84198a Mon Sep 17 00:00:00 2001 From: ubaumann Date: Mon, 3 Oct 2022 22:19:04 +0200 Subject: [PATCH 1/7] Add publischer to ActionAlias --- .../st2common/persistence/actionalias.py | 15 ++++++- st2common/st2common/transport/actionalias.py | 42 +++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 st2common/st2common/transport/actionalias.py diff --git a/st2common/st2common/persistence/actionalias.py b/st2common/st2common/persistence/actionalias.py index 1782e4422c..facbe140a1 100644 --- a/st2common/st2common/persistence/actionalias.py +++ b/st2common/st2common/persistence/actionalias.py @@ -14,13 +14,24 @@ # limitations under the License. from __future__ import absolute_import +from st2common import transport from st2common.models.db.actionalias import actionalias_access -from st2common.persistence import base as persistence +from st2common.persistence.base import Access +__all__ = [ + "ActionAlias", +] -class ActionAlias(persistence.Access): + +class ActionAlias(Access): impl = actionalias_access @classmethod def _get_impl(cls): return cls.impl + + @classmethod + def _get_publisher(cls): + if not cls.publisher: + cls.publisher = transport.actionalias.ActionAliasPublisher() + return cls.publisher diff --git a/st2common/st2common/transport/actionalias.py b/st2common/st2common/transport/actionalias.py new file mode 100644 index 0000000000..9e53395c0e --- /dev/null +++ b/st2common/st2common/transport/actionalias.py @@ -0,0 +1,42 @@ +# Copyright 2020 The StackStorm Authors. +# 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. + +# All Exchanges and Queues related to liveaction. + +from __future__ import absolute_import +from kombu import Exchange, Queue +from st2common.transport import publishers + +__all__ = [ + "ActionAliasPublisher", + "get_queue", +] + +ACTIONALIAS_XCHG = Exchange("st2.actionalias", type="topic") + + +class ActionAliasPublisher(publishers.CUDPublisher): + def __init__(self): + super(ActionAliasPublisher, self).__init__(exchange=ACTIONALIAS_XCHG) + + +def get_queue(name=None, routing_key=None, exclusive=False, auto_delete=False): + return Queue( + name, + ACTIONALIAS_XCHG, + routing_key=routing_key, + exclusive=exclusive, + auto_delete=auto_delete, + ) From c06cdbe8424d36007a27713dc102e67d38c2065a Mon Sep 17 00:00:00 2001 From: ubaumann Date: Thu, 6 Oct 2022 22:36:41 +0200 Subject: [PATCH 2/7] Add ActionAlias Exchange to bootstrap_utils.py --- st2common/st2common/transport/bootstrap_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/st2common/st2common/transport/bootstrap_utils.py b/st2common/st2common/transport/bootstrap_utils.py index 2eea9ad64b..b2eb8c7c2d 100644 --- a/st2common/st2common/transport/bootstrap_utils.py +++ b/st2common/st2common/transport/bootstrap_utils.py @@ -27,6 +27,7 @@ from st2common import log as logging from st2common.transport import utils as transport_utils +from st2common.transport.actionalias import ACTIONALIAS_XCHG from st2common.transport.actionexecutionstate import ACTIONEXECUTIONSTATE_XCHG from st2common.transport.announcement import ANNOUNCEMENT_XCHG from st2common.transport.connection_retry_wrapper import ConnectionRetryWrapper @@ -62,6 +63,7 @@ # List of exchanges which are pre-declared on service set up. EXCHANGES = [ + ACTIONALIAS_XCHG, ACTIONEXECUTIONSTATE_XCHG, ANNOUNCEMENT_XCHG, EXECUTION_XCHG, From cd2ba8ab3d8d184489454fa2ad88a1642edf355b Mon Sep 17 00:00:00 2001 From: ubaumann Date: Thu, 6 Oct 2022 22:46:30 +0200 Subject: [PATCH 3/7] Update CHANGELOG.rst --- CHANGELOG.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 526c385bae..98175e8ef9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -56,6 +56,9 @@ Added to pants' use of PEX lockfiles. This is not a user-facing addition. #5713 #5724 #5726 #5725 #5732 #5733 #5737 #5738 Contributed by @cognifloyd +* Added publischer to ActionAlias + Contributed @ubaumann + Changed ~~~~~~~ From 2a928d9f3628d6e86357b781817977193f5cc3da Mon Sep 17 00:00:00 2001 From: ubaumann Date: Fri, 14 Oct 2022 20:52:23 +0200 Subject: [PATCH 4/7] Add ActionAlias queue to stream listener --- st2common/st2common/stream/listener.py | 8 +++++++- st2common/st2common/transport/queues.py | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/st2common/st2common/stream/listener.py b/st2common/st2common/stream/listener.py index 347c4cfc75..759133f96f 100644 --- a/st2common/st2common/stream/listener.py +++ b/st2common/st2common/stream/listener.py @@ -21,10 +21,11 @@ from kombu.mixins import ConsumerMixin from oslo_config import cfg -from st2common.models.api.action import LiveActionAPI +from st2common.models.api.action import LiveActionAPI, ActionAliasAPI from st2common.models.api.execution import ActionExecutionAPI from st2common.models.api.execution import ActionExecutionOutputAPI from st2common.transport import utils as transport_utils +from st2common.transport.queues import STREAM_ACTIONALIAS_QUEUE from st2common.transport.queues import STREAM_ANNOUNCEMENT_WORK_QUEUE from st2common.transport.queues import STREAM_EXECUTION_ALL_WORK_QUEUE from st2common.transport.queues import STREAM_EXECUTION_UPDATE_WORK_QUEUE @@ -201,6 +202,11 @@ class StreamListener(BaseListener): def get_consumers(self, consumer, channel): return [ + consumer( + queues=[STREAM_ACTIONALIAS_QUEUE], + accept=["pickle"], + callbacks=[self.processor(ActionAliasAPI)], + ), consumer( queues=[STREAM_ANNOUNCEMENT_WORK_QUEUE], accept=["pickle"], diff --git a/st2common/st2common/transport/queues.py b/st2common/st2common/transport/queues.py index 0b19c0ff1d..33a3f26d03 100644 --- a/st2common/st2common/transport/queues.py +++ b/st2common/st2common/transport/queues.py @@ -25,6 +25,7 @@ from kombu import Queue from st2common.constants import action as action_constants +from st2common.transport import actionalias from st2common.transport import actionexecutionstate from st2common.transport import announcement from st2common.transport import execution @@ -42,6 +43,7 @@ "NOTIFIER_ACTIONUPDATE_WORK_QUEUE", "RESULTSTRACKER_ACTIONSTATE_WORK_QUEUE", "RULESENGINE_WORK_QUEUE", + "STREAM_ACTIONALIAS_QUEUE", "STREAM_ANNOUNCEMENT_WORK_QUEUE", "STREAM_EXECUTION_ALL_WORK_QUEUE", "STREAM_EXECUTION_UPDATE_WORK_QUEUE", @@ -94,6 +96,10 @@ # Used by the stream service +STREAM_ACTIONALIAS_QUEUE = actionalias.get_queue( + routing_key=publishers.ANY_RK, exclusive=True, auto_delete=True +) + STREAM_ANNOUNCEMENT_WORK_QUEUE = announcement.get_queue( routing_key=publishers.ANY_RK, exclusive=True, auto_delete=True ) From abbbd65a019f2aed63975af4475eed1dc217e86d Mon Sep 17 00:00:00 2001 From: ubaumann Date: Fri, 14 Oct 2022 20:53:46 +0200 Subject: [PATCH 5/7] Fix Copyright year Co-authored-by: Jacob Floyd --- st2common/st2common/transport/actionalias.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/st2common/st2common/transport/actionalias.py b/st2common/st2common/transport/actionalias.py index 9e53395c0e..33fff1e92d 100644 --- a/st2common/st2common/transport/actionalias.py +++ b/st2common/st2common/transport/actionalias.py @@ -1,5 +1,4 @@ -# Copyright 2020 The StackStorm Authors. -# Copyright 2019 Extreme Networks, Inc. +# Copyright 2022 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. From b0ca413b5d1c104173da141baf0f4cf487a688aa Mon Sep 17 00:00:00 2001 From: ubaumann Date: Fri, 14 Oct 2022 20:54:00 +0200 Subject: [PATCH 6/7] Update CHANGELOG.rst Co-authored-by: Jacob Floyd --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 98175e8ef9..9950cba855 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -56,7 +56,7 @@ Added to pants' use of PEX lockfiles. This is not a user-facing addition. #5713 #5724 #5726 #5725 #5732 #5733 #5737 #5738 Contributed by @cognifloyd -* Added publischer to ActionAlias +* Added publisher to ActionAlias to enable streaming ActionAlias create/update/delete events. Contributed @ubaumann Changed From 6c81f4f91828cf493c75708edda89440200eb297 Mon Sep 17 00:00:00 2001 From: Jacob Floyd Date: Sat, 3 Dec 2022 16:48:38 -0600 Subject: [PATCH 7/7] Move changelog entry --- CHANGELOG.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6223de4175..e6df913647 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,9 @@ Added #5778 #5789 #5817 #5795 #5830 Contributed by @cognifloyd +* Added publisher to ActionAlias to enable streaming ActionAlias create/update/delete events. + Contributed @ubaumann + 3.8.0 - November 18, 2022 ------------------------- @@ -78,9 +81,6 @@ Added to pants' use of PEX lockfiles. This is not a user-facing addition. #5713 #5724 #5726 #5725 #5732 #5733 #5737 #5738 #5758 #5751 #5774 #5776 #5777 #5782 Contributed by @cognifloyd -* Added publisher to ActionAlias to enable streaming ActionAlias create/update/delete events. - Contributed @ubaumann - Changed ~~~~~~~