package custom
import (
"sync"
"clusterd/pkg/common/constant"
)
type faultCache struct {
deletedDevFaultCm map[string]*constant.AdvanceDeviceFaultCm
deletedSwitchFaultCm map[string]*constant.SwitchInfo
deletedJobFaultDeviceMap map[string][]constant.FaultDevice
rwMutex sync.RWMutex
}
var FaultCache *faultCache
func init() {
FaultCache = &faultCache{
deletedDevFaultCm: make(map[string]*constant.AdvanceDeviceFaultCm),
deletedSwitchFaultCm: make(map[string]*constant.SwitchInfo),
deletedJobFaultDeviceMap: make(map[string][]constant.FaultDevice),
rwMutex: sync.RWMutex{},
}
}
func (cache *faultCache) GetDeletedDevFaultCmForNodeMap() map[string]*constant.AdvanceDeviceFaultCm {
cache.rwMutex.RLock()
defer cache.rwMutex.RUnlock()
return cache.deletedDevFaultCm
}
func (cache *faultCache) GetDeletedSwitchFaultCmForNodeMap() map[string]*constant.SwitchInfo {
cache.rwMutex.RLock()
defer cache.rwMutex.RUnlock()
return cache.deletedSwitchFaultCm
}
func (cache *faultCache) GetDeletedJobFaultDeviceMap() map[string][]constant.FaultDevice {
cache.rwMutex.RLock()
defer cache.rwMutex.RUnlock()
return cache.deletedJobFaultDeviceMap
}
func (cache *faultCache) SetDeletedDevFaultCmForNodeMap(
deletedDeviceFaultCmMap map[string]*constant.AdvanceDeviceFaultCm) {
cache.rwMutex.Lock()
defer cache.rwMutex.Unlock()
cache.deletedDevFaultCm = deletedDeviceFaultCmMap
}
func (cache *faultCache) SetDeletedSwitchFaultCmForNodeMap(
deletedSwitchFaultCmMap map[string]*constant.SwitchInfo) {
cache.rwMutex.Lock()
defer cache.rwMutex.Unlock()
cache.deletedSwitchFaultCm = deletedSwitchFaultCmMap
}
func (cache *faultCache) SetDeletedJobFaultDeviceMap(deletedJobFaultDeviceMap map[string][]constant.FaultDevice) {
cache.rwMutex.Lock()
defer cache.rwMutex.Unlock()
cache.deletedJobFaultDeviceMap = deletedJobFaultDeviceMap
}