Skip to content

Commit

Permalink
feat: Add AutoEvent Retention Model and DTO
Browse files Browse the repository at this point in the history
Add AutoEvent Retention Model and DTO for event retention enhancement

Signed-off-by: bruce <[email protected]>
  • Loading branch information
weichou1229 committed Feb 10, 2025
1 parent c739c72 commit c293476
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
26 changes: 22 additions & 4 deletions dtos/autoevent.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//
// Copyright (C) 2020-2023 IOTech Ltd
// Copyright (C) 2025 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -10,10 +11,17 @@ import (
)

type AutoEvent struct {
Interval string `json:"interval" yaml:"interval" validate:"required,edgex-dto-duration=1ms"` // min/max can be defined as params, ex. edgex-dto-duration=10ms0x2C24h
OnChange bool `json:"onChange" yaml:"onChange"`
OnChangeThreshold float64 `json:"onChangeThreshold" yaml:"onChangeThreshold" validate:"gte=0"`
SourceName string `json:"sourceName" yaml:"sourceName" validate:"required"`
Interval string `json:"interval" yaml:"interval" validate:"required,edgex-dto-duration=1ms"` // min/max can be defined as params, ex. edgex-dto-duration=10ms0x2C24h
OnChange bool `json:"onChange" yaml:"onChange"`
OnChangeThreshold float64 `json:"onChangeThreshold" yaml:"onChangeThreshold" validate:"gte=0"`
SourceName string `json:"sourceName" yaml:"sourceName" validate:"required"`
Retention Retention `json:"retention" yaml:"retention" validate:"omitempty"`
}

type Retention struct {
MaxCap int64 `json:"maxCap" yaml:"maxCap"`
MinCap int64 `json:"minCap" yaml:"minCap"`
Duration string `json:"duration" yaml:"duration" validate:"edgex-dto-duration=0s"`
}

// ToAutoEventModel transforms the AutoEvent DTO to the AutoEvent model
Expand All @@ -23,6 +31,11 @@ func ToAutoEventModel(a AutoEvent) models.AutoEvent {
OnChange: a.OnChange,
OnChangeThreshold: a.OnChangeThreshold,
SourceName: a.SourceName,
Retention: models.Retention{
MaxCap: a.Retention.MaxCap,
MinCap: a.Retention.MinCap,
Duration: a.Retention.Duration,
},
}
}

Expand All @@ -42,6 +55,11 @@ func FromAutoEventModelToDTO(a models.AutoEvent) AutoEvent {
OnChange: a.OnChange,
OnChangeThreshold: a.OnChangeThreshold,
SourceName: a.SourceName,
Retention: Retention{
MaxCap: a.Retention.MaxCap,
MinCap: a.Retention.MinCap,
Duration: a.Retention.Duration,
},
}
}

Expand Down
8 changes: 8 additions & 0 deletions models/autoevent.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//
// Copyright (C) 2020-2021 IOTech Ltd
// Copyright (C) 2025 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -10,4 +11,11 @@ type AutoEvent struct {
OnChange bool
OnChangeThreshold float64
SourceName string
Retention Retention
}

type Retention struct {
MaxCap int64
MinCap int64
Duration string
}

0 comments on commit c293476

Please sign in to comment.