2021-02-09 15:03:43 +00:00
|
|
|
package innerring
|
|
|
|
|
|
|
|
import (
|
2024-07-22 08:12:41 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-locode-db/pkg/locode"
|
|
|
|
locodedb "git.frostfs.info/TrueCloudLab/frostfs-locode-db/pkg/locode/db"
|
|
|
|
locodebolt "git.frostfs.info/TrueCloudLab/frostfs-locode-db/pkg/locode/db/boltdb"
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/netmap"
|
|
|
|
irlocode "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/innerring/processors/netmap/nodevalidation/locode"
|
2021-02-09 15:03:43 +00:00
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Server) newLocodeValidator(cfg *viper.Viper) (netmap.NodeValidator, error) {
|
|
|
|
locodeDB := locodebolt.New(locodebolt.Prm{
|
|
|
|
Path: cfg.GetString("locode.db.path"),
|
2021-02-09 15:21:36 +00:00
|
|
|
},
|
|
|
|
locodebolt.ReadOnly(),
|
|
|
|
)
|
2021-02-09 15:03:43 +00:00
|
|
|
|
|
|
|
s.registerStarter(locodeDB.Open)
|
|
|
|
s.registerIOCloser(locodeDB)
|
|
|
|
|
|
|
|
return irlocode.New(irlocode.Prm{
|
|
|
|
DB: (*locodeBoltDBWrapper)(locodeDB),
|
|
|
|
}), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type locodeBoltEntryWrapper struct {
|
|
|
|
*locodedb.Key
|
|
|
|
*locodedb.Record
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *locodeBoltEntryWrapper) LocationName() string {
|
2021-02-10 10:20:39 +00:00
|
|
|
return l.Record.LocationName()
|
2021-02-09 15:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type locodeBoltDBWrapper locodebolt.DB
|
|
|
|
|
|
|
|
func (l *locodeBoltDBWrapper) Get(lc *locode.LOCODE) (irlocode.Record, error) {
|
|
|
|
key, err := locodedb.NewKey(*lc)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
rec, err := (*locodebolt.DB)(l).Get(*key)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &locodeBoltEntryWrapper{
|
|
|
|
Key: key,
|
|
|
|
Record: rec,
|
|
|
|
}, nil
|
|
|
|
}
|