modelRT/model/measurement_group_model.go

64 lines
2.1 KiB
Go

// Package model define model struct of model runtime service
package model
import (
"context"
"fmt"
"modelRT/constants"
"modelRT/diagram"
"modelRT/logger"
"modelRT/orm"
)
// TraverseMeasurementGroupTables define func to traverse component measurement group tables
func TraverseMeasurementGroupTables(ctx context.Context, measSet orm.MeasurementSet) error {
rdb := diagram.GetRedisClientInstance()
pipe := rdb.Pipeline()
pipe.SAdd(ctx, constants.RedisAllGridSetKey, measSet.AllGridTags)
pipe.SAdd(ctx, constants.RedisAllZoneSetKey, measSet.AllZoneTags)
pipe.SAdd(ctx, constants.RedisAllStationSetKey, measSet.AllStationTags)
pipe.SAdd(ctx, constants.RedisAllGridSetKey, measSet.AllCompNSPaths)
pipe.SAdd(ctx, constants.RedisAllZoneSetKey, measSet.AllCompTags)
pipe.SAdd(ctx, constants.RedisAllConfigSetKey, "bay")
pipe.SAdd(ctx, constants.RedisAllStationSetKey, measSet.AllMeasTags)
// building the grid -> zones hierarchy
for gridTag, zoneTags := range measSet.GridToZoneTags {
key := fmt.Sprintf(constants.RedisSpecGridZoneSetKey, gridTag)
pipe.SAdd(ctx, key, zoneTags)
}
// building the zone -> stations hierarchy
for zoneTag, stationTags := range measSet.ZoneToStationTags {
key := fmt.Sprintf(constants.RedisSpecZoneStationSetKey, zoneTag)
pipe.SAdd(ctx, key, stationTags)
}
// building the station -> component nspaths hierarchy
for stationTag, compNSPaths := range measSet.StationToCompNSPaths {
key := fmt.Sprintf(constants.RedisSpecStationCompNSPATHSetKey, stationTag)
pipe.SAdd(ctx, key, compNSPaths)
}
// building the component nspath -> component tags hierarchy
for compNSPath, compTags := range measSet.CompNSPathToCompTags {
key := fmt.Sprintf(constants.RedisSpecCompNSPathCompTagSetKey, compNSPath)
pipe.SAdd(ctx, key, compTags)
}
// building the component tag -> measurement tags hierarchy
for compTag, measTags := range measSet.CompTagToMeasTags {
key := fmt.Sprintf(constants.RedisSpecCompTagMeasSetKey, compTag)
pipe.SAdd(ctx, key, measTags)
}
_, err := pipe.Exec(ctx)
if err != nil {
logger.Error(ctx, "init component measurement group recommend content failed", "error", err)
return err
}
return nil
}