Skip to content

Commit

Permalink
EOS-27256: IEM server integration with new event message changes (Sea…
Browse files Browse the repository at this point in the history
…gate#702)

* Iem server event message integrations changes

Signed-off-by: suryakumar.kumaravelan <[email protected]>

* code optimize

Signed-off-by: suryakumar.kumaravelan <[email protected]>

Co-authored-by: Sachin Punadikar <[email protected]>
Signed-off-by: suryakumar.kumaravelan <[email protected]>
  • Loading branch information
suryakumar1024 and Sachin Punadikar committed Mar 21, 2022
1 parent e40ae22 commit 171df19
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions py-utils/src/utils/iem_framework/iem_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,23 @@
from cortx.utils.iem_framework.error import EventMessageError
from cortx.utils.log import Log
from cortx.utils.common import CortxConf
from cortx.utils.conf_store import Conf

routes = web.RouteTableDef()


class IemRequestHandler(MessageServer):
""" Rest interface of Iem """

@staticmethod
def _get_cluster_data(config_path):
message_bus_backend = Conf.get('config',\
'cortx>utils>message_bus_backend')
message_server_endpoints = Conf.get('config',\
f'cortx>external>{message_bus_backend}>endpoints')
cluster_id = Conf.get('config','cluster>id')
return message_server_endpoints, cluster_id

@staticmethod
async def send(request):
try:
Expand All @@ -38,8 +48,10 @@ async def send(request):
component = payload['component']
source = payload['source']
cluster_conf = CortxConf.get_cluster_conf_path()
endpoint, cluster_id = IemRequestHandler._get_cluster_data(cluster_conf)

EventMessage.init(component=component, source=source,\
cluster_conf=cluster_conf)
cluster_id=cluster_id, message_server_endpoints=endpoint)

del payload['component']
del payload['source']
Expand Down Expand Up @@ -79,7 +91,9 @@ async def receive(request):
try:
cluster_conf = CortxConf.get_cluster_conf_path()
component = request.rel_url.query['component']
EventMessage.subscribe(component=component, cluster_conf=cluster_conf)
endpoint, _ = IemRequestHandler._get_cluster_data(cluster_conf)
EventMessage.subscribe(component=component,\
message_server_endpoints=endpoint)
alert = EventMessage.receive()
except EventMessageError as e:
status_code = e.rc
Expand Down

0 comments on commit 171df19

Please sign in to comment.