
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>
169 lines
6.2 KiB
Python
169 lines
6.2 KiB
Python
#
|
|
# Copyright (c) 2021-2022 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
from pecan import conf
|
|
from pecan import expose, rest, response, abort
|
|
from webob.exc import HTTPException, HTTPNotFound, HTTPBadRequest, HTTPClientError, HTTPServerError
|
|
|
|
import os
|
|
import logging
|
|
|
|
from wsme import types as wtypes
|
|
from wsmeext.pecan import wsexpose
|
|
|
|
from notificationclientsdk.model.dto.subscription import SubscriptionInfoV2
|
|
|
|
from notificationclientsdk.repository.subscription_repo import SubscriptionRepo
|
|
from notificationclientsdk.services.ptp import PtpService
|
|
from notificationclientsdk.exception import client_exception
|
|
from notificationclientsdk.common.helpers import log_helper
|
|
|
|
from sidecar.repository.notification_control import notification_control
|
|
from sidecar.repository.dbcontext_default import defaults
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
log_helper.config_logger(LOG)
|
|
|
|
THIS_NODE_NAME = os.environ.get("THIS_NODE_NAME", 'controller-0')
|
|
|
|
|
|
class SubscriptionsControllerV2(rest.RestController):
|
|
|
|
@wsexpose(SubscriptionInfoV2, body=SubscriptionInfoV2, status_code=201)
|
|
def post(self, subscription):
|
|
# decode the request body
|
|
try:
|
|
if subscription.ResourceAddress:
|
|
LOG.info(' subscribe: ResourceAddress {0} with callback uri {1}'.format(
|
|
subscription.ResourceAddress,
|
|
subscription.EndpointUri))
|
|
|
|
if not self._validateV2(subscription):
|
|
LOG.warning(' Invalid Request data:{0}'.format(subscription.to_dict()))
|
|
abort(400)
|
|
|
|
subscription.UriLocation = "{0}://{1}:{2}/ocloudNotifications/v2/subscriptions".format(
|
|
conf.server.get('protocol', 'http'),
|
|
conf.server.get('host', '127.0.0.1'),
|
|
conf.server.get('port', '8080')
|
|
)
|
|
if subscription.ResourceAddress:
|
|
ptpservice = PtpService(notification_control)
|
|
entry = ptpservice.add_subscription(subscription)
|
|
del ptpservice
|
|
if not entry:
|
|
abort(404)
|
|
subscription.SubscriptionId = entry.SubscriptionId
|
|
subscription.UriLocation = entry.UriLocation
|
|
LOG.info('created subscription: {0}'.format(subscription.to_dict()))
|
|
|
|
return subscription
|
|
except client_exception.InvalidSubscription as ex:
|
|
abort(400)
|
|
except client_exception.InvalidEndpoint as ex:
|
|
abort(400)
|
|
except client_exception.NodeNotAvailable as ex:
|
|
abort(404)
|
|
except client_exception.ResourceNotAvailable as ex:
|
|
abort(404)
|
|
except HTTPException as ex:
|
|
LOG.warning("Client side error:{0},{1}".format(type(ex), str(ex)))
|
|
abort(400)
|
|
except HTTPServerError as ex:
|
|
LOG.error("Server side error:{0},{1}".format(type(ex), str(ex)))
|
|
abort(500)
|
|
except Exception as ex:
|
|
LOG.error("Exception:{0}@{1}".format(type(ex), str(ex)))
|
|
abort(500)
|
|
|
|
@expose('json')
|
|
def get(self):
|
|
try:
|
|
repo = SubscriptionRepo(defaults['dbcontext'].get_session(), autocommit=False)
|
|
entries = repo.get(Status=1)
|
|
response.status = 200
|
|
subs = []
|
|
for x in entries:
|
|
if x.Status == 1:
|
|
if getattr(x, 'ResourceAddress', None) is not None:
|
|
subs.append(SubscriptionInfoV2(x).to_dict())
|
|
return subs
|
|
except HTTPException as ex:
|
|
LOG.warning("Client side error:{0},{1}".format(type(ex), str(ex)))
|
|
raise ex
|
|
except HTTPServerError as ex:
|
|
LOG.error("Server side error:{0},{1}".format(type(ex), str(ex)))
|
|
raise ex
|
|
except Exception as ex:
|
|
LOG.error("Exception:{0}@{1}".format(type(ex), str(ex)))
|
|
abort(500)
|
|
|
|
@expose()
|
|
def _lookup(self, subscription_id, *remainder):
|
|
return SubscriptionController(subscription_id), remainder
|
|
|
|
def _validateV2(self, subscription_request):
|
|
try:
|
|
assert subscription_request.ResourceAddress
|
|
assert subscription_request.EndpointUri
|
|
|
|
return True
|
|
except:
|
|
return False
|
|
|
|
|
|
class SubscriptionController(rest.RestController):
|
|
def __init__(self, subscription_id):
|
|
self.subscription_id = subscription_id
|
|
|
|
@expose('json')
|
|
def get(self):
|
|
try:
|
|
repo = SubscriptionRepo(defaults['dbcontext'].get_session(), autocommit=False)
|
|
entry = repo.get_one(SubscriptionId=self.subscription_id, Status=1)
|
|
|
|
if not entry:
|
|
abort(404)
|
|
else:
|
|
response.status = 200
|
|
if getattr(entry, 'ResourceAddress', None):
|
|
return SubscriptionInfoV2(entry).to_dict()
|
|
|
|
except HTTPException as ex:
|
|
LOG.warning("Client side error:{0},{1}".format(type(ex), str(ex)))
|
|
raise ex
|
|
except HTTPServerError as ex:
|
|
LOG.error("Server side error:{0},{1}".format(type(ex), str(ex)))
|
|
raise ex
|
|
except Exception as ex:
|
|
LOG.error("Exception:{0}@{1}".format(type(ex), str(ex)))
|
|
abort(500)
|
|
|
|
@wsexpose(status_code=204)
|
|
def delete(self):
|
|
try:
|
|
repo = SubscriptionRepo(defaults['dbcontext'].get_session(), autocommit=False)
|
|
entry = repo.get_one(SubscriptionId=self.subscription_id)
|
|
if entry:
|
|
if entry.SubscriptionId:
|
|
ptpservice = PtpService(notification_control)
|
|
ptpservice.remove_subscription(entry.SubscriptionId)
|
|
del ptpservice
|
|
return
|
|
else:
|
|
repo.delete_one(SubscriptionId=self.subscription_id)
|
|
return
|
|
abort(404)
|
|
except HTTPException as ex:
|
|
LOG.warning("Client side error:{0},{1}".format(type(ex), str(ex)))
|
|
raise ex
|
|
except HTTPServerError as ex:
|
|
LOG.error("Server side error:{0},{1}".format(type(ex), str(ex)))
|
|
raise ex
|
|
except Exception as ex:
|
|
LOG.error("Exception:{0}@{1}".format(type(ex), str(ex)))
|
|
abort(500)
|