Cole Walker a482d1ff96 Add v2 id to rabbitmq topics and add v1 container to daemonset
Update the notificationservice-base-v2 container image to use a v2
identifier on rabbitmq topics. This allows v1 and v2 messages to be
handled separately. Update the notificationclient image to use the v2
identifier as well.

The v1 notificationservice-base will continue to use the default
rabbitmq topics with no additional identifier. This is compatible with
the following notificationclient-base image:

starlingx/notificationclient-base:stx.5.0-v1.0.4

This change also updates the daemonset to deploy both v1 and v2
notificationservice-base images and provides a helm overrided to allow
either one to be disabled.

Finally, update the notificationclient-base Dockerfile to pin the
version of sqlalchemy to 1.4.12. This is the same version used for the v1
client, and the latest 2.x.x version of sqlalchemy has changes which
break notificationclient-base.

Test plan:
PASS: Build all container images
PASS: Build and deploy ptp-notification application
Pass: Test ptp-notification Pull, Subscribe, Delete functionality for v1
and v2

Story: 2010538
Task: 47285
Task: 47286

Change-Id: Ib033661f496439f62af785f8f37b1069ccb74ba1
2023-02-08 20:13:09 +00:00

102 lines
3.5 KiB
Python

#
# Copyright (c) 2021-2023 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import os
import json
import time
import oslo_messaging
from oslo_config import cfg
from notificationclientsdk.model.dto.rpc_endpoint import RpcEndpointInfo
from notificationclientsdk.client.base import BrokerClientBase
from notificationclientsdk.repository.subscription_repo import SubscriptionRepo
import logging
LOG = logging.getLogger(__name__)
from notificationclientsdk.common.helpers import log_helper
log_helper.config_logger(LOG)
class NotificationHandlerBase(object):
def __init__(self):
pass
def handle(self, notification_info):
return False
class NotificationServiceClient(BrokerClientBase):
class ListenerEndpoint(object):
target = oslo_messaging.Target(namespace='notification', version='1.0')
def __init__(self, handler):
self.handler = handler
def NotifyStatus(self, ctx, notification):
LOG.debug("NotificationServiceClient NotifyStatus called %s" % notification)
self.handler.handle(notification)
return time.time()
'''Init client to notification service'''
def __init__(self, target_node_name, notificationservice_transport_endpoint, broker_pod_ip):
self.Id = id(self)
self.target_node_name = target_node_name
self.broker_pod_ip = broker_pod_ip
super(NotificationServiceClient, self).__init__(
'{0}'.format(target_node_name),
notificationservice_transport_endpoint)
return
def __del__(self):
super(NotificationServiceClient, self).__del__()
return
def query_resource_status(self, resource_type,
timeout=None,
retry=None,
resource_qualifier_json=None,
resource_address=None,
optional=None):
topic = '{0}-Status-v2'.format(resource_type)
server = '{0}-Tracking-{1}'.format(resource_type, self.target_node_name)
return self.call(
topic, server, 'QueryStatus',
timeout=timeout, retry=retry,
QualifierJson=resource_qualifier_json,
ResourceAddress=resource_address,
optional=optional)
def add_resource_status_listener(self, resource_type, status_handler=None):
if not status_handler:
status_handler = NotificationHandlerBase()
topic='{0}-Event-v2-{1}'.format(resource_type, self.broker_name)
server="{0}-EventListener-{1}".format(resource_type, self.Id)
endpoints = [NotificationServiceClient.ListenerEndpoint(status_handler)]
super(NotificationServiceClient, self).add_listener(
topic, server, endpoints)
return True
def remove_resource_status_listener(self, resource_type):
topic='{0}-Event-v2-{1}'.format(resource_type, self.broker_name)
server="{0}-EventListener-{1}".format(resource_type, self.Id)
super(NotificationServiceClient, self).remove_listener(
topic, server)
pass
def is_listening_on_resource(self, resource_type):
topic='{0}-Event-v2-{1}'.format(resource_type, self.broker_name)
server="{0}-EventListener-{1}".format(resource_type, self.Id)
return super(NotificationServiceClient, self).is_listening(
topic, server)
def is_broker_ip(self, broker_pod_ip):
return self.broker_pod_ip == broker_pod_ip