You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

67 rivejä
1.5 KiB

  1. package appcontext
  2. import (
  3. "encoding/json"
  4. "time"
  5. "github.com/AFASystems/presence/internal/pkg/kafkaclient"
  6. )
  7. type BaseHealth struct {
  8. Uptime time.Duration `json:"uptime"`
  9. ActiveReaders []string `json:"activeReaders" gorm:"type:jsonb"`
  10. ActiveWriters []string `json:"activeWriters" gorm:"type:jsonb"`
  11. ActiveBeacons []string `json:"activeBeacons" gorm:"type:jsonb"`
  12. }
  13. type DecoderHealth struct {
  14. BaseHealth
  15. // current active configs ? dont know yet how
  16. }
  17. type LocationHealth struct {
  18. BaseHealth
  19. ActiveSettings []Settings `json:"activeSettings" gorm:"type:jsonb"`
  20. }
  21. type BridgeHealth struct {
  22. BaseHealth
  23. }
  24. type Health struct {
  25. Location LocationHealth `gorm:"embedded;embeddedPrefix:loc_"`
  26. Decoder DecoderHealth `gorm:"embedded;embeddedPrefix:dec_"`
  27. Bridge BridgeHealth `gorm:"embedded;embeddedPrefix:brg_"`
  28. }
  29. func (b *BaseHealth) GetUptime(startTime time.Time) {
  30. b.Uptime = time.Since(startTime)
  31. }
  32. func (b *BaseHealth) GetActiveReaders(m *kafkaclient.KafkaManager) {
  33. b.ActiveReaders = m.GetReaders()
  34. }
  35. func (b *BaseHealth) GetActiveWriters(m *kafkaclient.KafkaManager) {
  36. b.ActiveWriters = m.GetWriters()
  37. }
  38. func (b *BaseHealth) GetActiveBeacons(m *AppState) {
  39. beacons := m.GetAllBeacons()
  40. for beacon := range beacons {
  41. b.ActiveBeacons = append(b.ActiveBeacons, beacon)
  42. }
  43. }
  44. func (d *DecoderHealth) Marshal() ([]byte, error) {
  45. return json.Marshal(d)
  46. }
  47. func (l *LocationHealth) Marshal() ([]byte, error) {
  48. return json.Marshal(l)
  49. }
  50. func (b *BridgeHealth) Marshal() ([]byte, error) {
  51. return json.Marshal(b)
  52. }