listenerlib

package module
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2023 License: Apache-2.0 Imports: 20 Imported by: 1

README

ptp-events-listener

Overview

The ptp-event-listener enables to directly stream events from the ptp-operator linux-ptp-daemon pods. This project does the following:

  • get the outbound IP of the local host. This is achieved by pinging the k8s api of the cluster running the ptp-operator.
  • create a port forwarding tunnel between the local host and the linux-ptp-daemon pod running the cloud-event-proxy container. The tunnel creates a localhost:4093 endpoint to enable direct access between the local host and the linux-ptp-daemon pod.
  • create a http server to receive any http request/responses in the local host. The server listen to 0.0.0.0:8989. This is used to complete registration steps and receive events
  • send a registration request to the tunnel endpoint at localhost:4093 to register a new subscriber to the cloud-event-proxy. The registration message contains:
    • the address and port of the http server that is registering the events. This is the :8989.
    • the events it is interested in
  • After successful registration, ptp events are streamed via POST messages to the registered :8989 endpoint
  • the local host HTTP server receives the POST messages and dispatches them to internal subscribers

ptp-events-listener-overview

Dispatch of events to internal subscribers

Internal dispatch of ptp events is done via the channel-pubsub project, using native Golang channels:

  • the webserver publishes all events received via POST messages to the channel-pubsub object. Currently only event.sync.sync-status.os-clock-sync-state-change are supported.
  • any internal process can register to receive a certain event (today only event.sync.sync-status.os-clock-sync-state-change is available)
  • any time a event is received by the HTTP server all internal processes that have registered it are notified.

ptp-events-listener-pubsub

Example

An example project is at https://github.com/redhat-cne/ptp-listener-example

Documentation

Index

Constants

View Source
const (
	SubscriptionPath  = "/api/ocloudNotifications/v1/subscriptions"
	EventsPath        = "/api/ocloudNotifications/v1"
	LocalEventPath    = "/event"
	LocalHealthPath   = "/health"
	LocalAckEventPath = "/ack/event"
	HTTP200           = 200
)

Variables

View Source
var (
	Ps                           *chanpubsub.Pubsub
	CurrentSubscriptionIDPerType = map[string]string{}
)
View Source
var HTTPClient = &http.Client{
	Transport: &http.Transport{
		MaxIdleConnsPerHost: 20,
	},
	Timeout: 10 * time.Second,
}

Functions

func GetEvent added in v0.1.4

func GetEvent(nodeName, apiAddr, resource string) (aEvent exports.StoredEvent, aType string, err error)

func GetOutboundIP

func GetOutboundIP(aURL string) net.IP

Get preferred outbound ip of this machine

func InitPubSub

func InitPubSub()

func IsEventValid added in v0.1.4

func IsEventValid(aEvent *event.Event) bool

func PushInitialEvent added in v0.1.4

func PushInitialEvent(resource string)

sends a fake events to indicate the initial state at the time of registering events via channel-pubsub

func StartListening

func StartListening(ptpEventServiceLocalhostPort,
	ptpEventServiceRemotePort,
	localHTTPServerPort int,
	ptpPodName,
	nodeName,
	ptpNs,
	kubeconfigPath,
	kubernetesHost string,
	timeoutPost time.Duration,
) (err error)

func SubscribeAllEvents

func SubscribeAllEvents(supportedResource, apiAddr, localAPIAddr string, timeoutPost time.Duration) (err error)

func SubscribeAnWaitForAllEvents

func SubscribeAnWaitForAllEvents(kubernetesHost, nodeName, apiAddr string, localHTTPServerPort int, timeoutPost time.Duration) (err error)

func UnsubscribeAllEvents

func UnsubscribeAllEvents(nodeName string)

Types

type ListenerConfig added in v0.1.4

type ListenerConfig struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL