Skip to content

Commit

Permalink
add clock class event source to support v1 (#373)
Browse files Browse the repository at this point in the history
Signed-off-by: Aneesh Puttur <[email protected]>
  • Loading branch information
aneeshkp authored Dec 10, 2024
1 parent 289f4cf commit 8c77327
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 12 deletions.
7 changes: 5 additions & 2 deletions examples/consumer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func main() {
log.Infof("apiVersion=%s, updated apiAddr=%s, apiPath=%s", apiVersion, apiAddr, apiPath)
}

subscribeTo := initSubscribers(consumerType)
subscribeTo := initSubscribers(consumerType, isV1Api)
var wg sync.WaitGroup
wg.Add(1)
go server() // spin local api
Expand Down Expand Up @@ -327,12 +327,15 @@ func processEventV2(data []byte) error {
return nil
}

func initSubscribers(cType ConsumerTypeEnum) map[string]string {
func initSubscribers(cType ConsumerTypeEnum, v1Api bool) map[string]string {
subscribeTo := make(map[string]string)
switch cType {
case PTP:
subscribeTo[string(ptpEvent.OsClockSyncStateChange)] = string(ptpEvent.OsClockSyncState)
subscribeTo[string(ptpEvent.PtpClockClassChange)] = string(ptpEvent.PtpClockClass)
if v1Api {
subscribeTo[string(ptpEvent.PtpClockClassChange)] = string(ptpEvent.PtpClockClassV1)
}
subscribeTo[string(ptpEvent.PtpStateChange)] = string(ptpEvent.PtpLockState)
subscribeTo[string(ptpEvent.GnssStateChange)] = string(ptpEvent.GnssSyncStatus)
subscribeTo[string(ptpEvent.SyncStateChange)] = string(ptpEvent.SyncStatusState)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/onsi/gomega v1.23.0
github.com/prometheus/client_golang v1.14.0
github.com/redhat-cne/rest-api v1.21.0
github.com/redhat-cne/sdk-go v1.21.0
github.com/redhat-cne/sdk-go v1.21.1
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.1
golang.org/x/net v0.23.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0ua
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/redhat-cne/rest-api v1.21.0 h1:Nh/0K2q6Aov5WvnRcevWOIOR6Jzh9YDrDXIM2Gfp80o=
github.com/redhat-cne/rest-api v1.21.0/go.mod h1:P4+xDa4l9NjBMLeslRXqaWm+iLA/wWJaScEPcfcHcKM=
github.com/redhat-cne/sdk-go v1.21.0 h1:hDcZ2ySW3w3+CFRtfgIbjCa1MowZQP4wqtQDSJs3+zQ=
github.com/redhat-cne/sdk-go v1.21.0/go.mod h1:1fq4KGbPiUgj65/rZCD217uV04Qz3mVjODUNrP02FkQ=
github.com/redhat-cne/sdk-go v1.21.1 h1:ifyH8Ci3hezxTBNFSAONFxI0HqeTBMpKT8YItrrYrqk=
github.com/redhat-cne/sdk-go v1.21.1/go.mod h1:1fq4KGbPiUgj65/rZCD217uV04Qz3mVjODUNrP02FkQ=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down
20 changes: 15 additions & 5 deletions plugins/ptp_operator/ptp_operator_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func Start(wg *sync.WaitGroup, configuration *common.SCConfiguration, _ func(e i
config = configuration
// register metrics type
ptpMetrics.RegisterMetrics(nodeName)
publishers = InitPubSubTypes()
publishers = InitPubSubTypes(config)

// 1. Create event Publication
var err error
Expand Down Expand Up @@ -200,6 +200,9 @@ func getCurrentStatOverrideFn() func(e v2.Event, d *channel.DataChan) error {
} else if strings.Contains(e.Source(), string(ptp.PtpClockClass)) {
eventType = ptp.PtpClockClassChange
eventSource = ptp.PtpClockClass
} else if strings.Contains(e.Source(), string(ptp.PtpClockClassV1)) {
eventType = ptp.PtpClockClassChange
eventSource = ptp.PtpClockClassV1
} else if strings.Contains(e.Source(), string(ptp.GnssSyncStatus)) {
eventType = ptp.GnssStateChange
eventSource = ptp.GnssSyncStatus
Expand Down Expand Up @@ -576,7 +579,7 @@ func HasEqualInterface(a []*string, b []*ptp4lconf.PTPInterface) bool {
}

// InitPubSubTypes ... initialize types of publishers for ptp operator
func InitPubSubTypes() map[ptp.EventType]*ptpTypes.EventPublisherType {
func InitPubSubTypes(scConfig *common.SCConfiguration) map[ptp.EventType]*ptpTypes.EventPublisherType {
InitPubs := make(map[ptp.EventType]*ptpTypes.EventPublisherType)
InitPubs[ptp.SyncStateChange] = &ptpTypes.EventPublisherType{
EventType: ptp.SyncStateChange,
Expand All @@ -586,9 +589,16 @@ func InitPubSubTypes() map[ptp.EventType]*ptpTypes.EventPublisherType {
EventType: ptp.OsClockSyncStateChange,
Resource: ptp.OsClockSyncState,
}
InitPubs[ptp.PtpClockClassChange] = &ptpTypes.EventPublisherType{
EventType: ptp.PtpClockClassChange,
Resource: ptp.PtpClockClass,
if !common.IsV1Api(scConfig.APIVersion) {
InitPubs[ptp.PtpClockClassChange] = &ptpTypes.EventPublisherType{
EventType: ptp.PtpClockClassChange,
Resource: ptp.PtpClockClass,
}
} else {
InitPubs[ptp.PtpClockClassChange] = &ptpTypes.EventPublisherType{
EventType: ptp.PtpClockClassChange,
Resource: ptp.PtpClockClassV1,
}
}
InitPubs[ptp.PtpStateChange] = &ptpTypes.EventPublisherType{
EventType: ptp.PtpStateChange,
Expand Down
2 changes: 1 addition & 1 deletion plugins/ptp_operator/ptp_operator_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestMain(m *testing.M) {

c = make(chan os.Signal)
common.StartPubSubService(scConfig)
pubsubTypes = InitPubSubTypes()
pubsubTypes = InitPubSubTypes(scConfig)
cleanUP()
os.Exit(m.Run())
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ github.com/redhat-cne/rest-api
github.com/redhat-cne/rest-api/pkg/localmetrics
github.com/redhat-cne/rest-api/pkg/restclient
github.com/redhat-cne/rest-api/v2
# github.com/redhat-cne/sdk-go v1.21.0
# github.com/redhat-cne/sdk-go v1.21.1
## explicit; go 1.21
github.com/redhat-cne/sdk-go/pkg/channel
github.com/redhat-cne/sdk-go/pkg/common
Expand Down

0 comments on commit 8c77327

Please sign in to comment.