Cole Walker 4178a86975 Integration work for ORAN notification
Several improvements and fixes to enable the end-to-end functionality of
all of the components in support of the O-RAN Spec Compliant Timing API
Notification work.

1. Add time stamps to logging for notificationservice and
notificationclient
2. Add support for the "optional" hierarchy in the resource address
which allows the client to query the status of a specific ptp instances.
ie. get the status of instance ptp1 rather than all ptp instances
3. Add a parent key to the returned notification data so that multiple
statuses can be returned to the client with a single notification'
4. Reworked the notificationservice daemonset to start its process
directly rather than using an intermediary script. This allows the
container logs to show properly via kubectl logs and will also allow the
container to crash properly if the program errors out.
5. Reworked the helm values for ptp4l and ts2phc instances to allow
users to supply overrides with multiple instances

Test plan:
PASS: PTP notification v1 compatibility
PASS: GET all v2 resources
PASS: SUBSCRIBE/LIST/DELETE v2 resources
PASS: Build and deploy containers/fluxcd app

Story: 2010056
Task: 46226

Change-Id: Id471fdc0815afdcc5639e81c6457616e268e6cd7
Signed-off-by: Cole Walker <cole.walker@windriver.com>
2022-09-14 11:02:43 -04:00

102 lines
3.5 KiB
Python

#
# Copyright (c) 2021-2022 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'.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-{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-{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-{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