frostfs-node/pkg/services/audit/task.go
Dmitrii Stepanov e8d340287f [#222] auditsvc: Refactor audit task
Resolve containedctx linter. Cancel task by listen cancel.

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2023-04-07 17:29:13 +03:00

120 lines
2.5 KiB
Go

package audit
import (
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/storagegroup"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
)
// Task groups groups the container audit parameters.
type Task struct {
cancelCh <-chan struct{}
reporter Reporter
idCnr cid.ID
cnr container.Container
nm *netmap.NetMap
cnrNodes [][]netmap.NodeInfo
sgList []storagegroup.StorageGroup
}
// WithReporter sets audit report writer.
func (t *Task) WithReporter(r Reporter) *Task {
if t != nil {
t.reporter = r
}
return t
}
// Reporter returns audit report writer.
func (t *Task) Reporter() Reporter {
return t.reporter
}
func (t *Task) WithCancelChannel(ch <-chan struct{}) *Task {
if ch != nil {
t.cancelCh = ch
}
return t
}
func (t *Task) CancelChannel() <-chan struct{} {
return t.cancelCh
}
// WithContainerID sets identifier of the container under audit.
func (t *Task) WithContainerID(cnr cid.ID) *Task {
if t != nil {
t.idCnr = cnr
}
return t
}
// ContainerID returns identifier of the container under audit.
func (t *Task) ContainerID() cid.ID {
return t.idCnr
}
// WithContainerStructure sets structure of the container under audit.
func (t *Task) WithContainerStructure(cnr container.Container) *Task {
if t != nil {
t.cnr = cnr
}
return t
}
// ContainerStructure returns structure of the container under audit.
func (t *Task) ContainerStructure() container.Container {
return t.cnr
}
// WithContainerNodes sets nodes in the container under audit.
func (t *Task) WithContainerNodes(cnrNodes [][]netmap.NodeInfo) *Task {
if t != nil {
t.cnrNodes = cnrNodes
}
return t
}
// NetworkMap returns network map of audit epoch.
func (t *Task) NetworkMap() *netmap.NetMap {
return t.nm
}
// WithNetworkMap sets network map of audit epoch.
func (t *Task) WithNetworkMap(nm *netmap.NetMap) *Task {
if t != nil {
t.nm = nm
}
return t
}
// ContainerNodes returns nodes in the container under audit.
func (t *Task) ContainerNodes() [][]netmap.NodeInfo {
return t.cnrNodes
}
// WithStorageGroupList sets a list of storage groups from container under audit.
func (t *Task) WithStorageGroupList(sgList []storagegroup.StorageGroup) *Task {
if t != nil {
t.sgList = sgList
}
return t
}
// StorageGroupList returns list of storage groups from container under audit.
func (t *Task) StorageGroupList() []storagegroup.StorageGroup {
return t.sgList
}