ptp-notification-armada-app/locationservice-base/docker/locationservice/locationservicesdk/client/locationproducer.py
Cole Walker 37c15ea4fb Add support for httpGet liveness probes
Updates the locationservice, notificationservice and notificationclient
containers to support ipv6 httpGet liveness probes.

notificationservice-base and notificationservice-basev2:
- Adds health.py which starts a simple http server that runs within the
  daemon. The k8s httpGet liveness probe can query this endpoint to
  verify that the service is running
- Update the daemonset template and values to provide the required info
  for initalizing the new endpoint

locationservice-base:
- Remove unused portions of the locationservice_start.sh config map.
  The location-query-server.py and location-announce.py were never
  active and are not required
- Add locationservice_start.py in order to start the locationservice
  pecan WSGI application with either an ipv4 or ipv6 socket
- Use existing pecan endpoint to respond to liveness probes

notificationclient-base:
- Add notificationclient_start.py to start the notificationclient
  pecan WSGI application with either an ipv4 or ipv6 socket
- Use existing pecan endpoint to respond to liveness probes

Daemonset:
- Add required ip and port environment variables to support liveness
  probes on each container
- Add a conditional section for enabling liveness probes. Disabled by
  default but can be enabled via helm overrides by setting "liveness:
  True"

Misc:
- Re-organized python imports in affected files
- Incremented helm chart version to 2.0.1

Test-plan:
Pass: Verify application build and install
Pass: Verify containers build correctly
Pass: Deploy ptp-notification and verify basic sanity (v1 and v2 get,
subscribe, delete, list)
Pass: Enable httpGet liveness probes for each container and verify
operation
Pass: Verify application removal

Story: 2011090
Task: 49851

Signed-off-by: Cole Walker <cole.walker@windriver.com>
Change-Id: I4671c7f8c67c4869a6d5e3b384eae66d8c57a284
2024-04-16 11:07:15 -04:00

92 lines
3.0 KiB
Python

#
# Copyright (c) 2021-2024 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
import json
import logging
import os
import time
import oslo_messaging
from locationservicesdk.client.base import BrokerClientBase
from locationservicesdk.common.helpers import log_helper
from oslo_config import cfg
LOG = logging.getLogger(__name__)
log_helper.config_logger(LOG)
class LocationProducer(BrokerClientBase):
class ListenerEndpoint(object):
target = oslo_messaging.Target(namespace='notification', version='1.0')
def __init__(self, location_info, handler=None):
self.location_info = location_info
self.handler = handler
pass
def QueryLocation(self, ctx, **rpc_kwargs):
LOG.debug("LocationProducer QueryLocation called %s" % rpc_kwargs)
return self.location_info
def TriggerAnnouncement(self, ctx, **rpc_kwargs):
LOG.debug("LocationProducer TriggerAnnouncement called %s" %
rpc_kwargs)
if self.handler:
return self.handler.handle(**rpc_kwargs)
else:
return False
def __init__(self, node_name, registrationservice_transport_endpoint):
self.Id = id(self)
self.node_name = node_name
super(LocationProducer, self).__init__(
'locationproducer', registrationservice_transport_endpoint)
return
def __del__(self):
super(LocationProducer, self).__del__()
return
def announce_location(self, LocationInfo):
location_topic_all = 'LocationListener-*'
location_topic = 'LocationListener-{0}'.format(self.node_name)
server = None
while True:
try:
self.cast(location_topic_all, 'NotifyLocation',
location_info=LocationInfo)
LOG.debug(
"Broadcast location info:{0}@Topic:{1}".format(LocationInfo, location_topic))
except Exception as ex:
LOG.debug(
"Failed to publish location due to: {0}".format(str(ex)))
continue
else:
break
def start_location_listener(self, location_info, handler=None):
topic = 'LocationQuery'
server = "LocationService-{0}".format(self.node_name)
endpoints = [LocationProducer.ListenerEndpoint(location_info, handler)]
super(LocationProducer, self).add_listener(
topic, server, endpoints)
return True
def stop_location_listener(self):
topic = 'LocationQuery'
server = "LocationService-{0}".format(self.node_name)
super(LocationProducer, self).remove_listener(
topic, server)
def is_listening(self):
topic = 'LocationQuery'
server = "LocationService-{0}".format(self.node_name)
return super(LocationProducer, self).is_listening(
topic, server)