Skip to content

Commit a4aa3a4

Browse files
committed
[core] Reformat DCS client data output
1 parent 7d484d7 commit a4aa3a4

File tree

2 files changed

+91
-11
lines changed

2 files changed

+91
-11
lines changed

core/integration/dcs/plugin.go

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import (
5454
const (
5555
DCS_DIAL_TIMEOUT = 2 * time.Hour
5656
DCS_GENERAL_OP_TIMEOUT = 45 * time.Second
57+
DCS_TIME_FORMAT = "2006-01-02 15:04:05.000"
5758
)
5859

5960
type Plugin struct {
@@ -73,6 +74,8 @@ type DCSDetectorOpAvailabilityMap map[dcspb.Detector]dcspb.DetectorState
7374

7475
type DCSDetectorInfoMap map[dcspb.Detector]*dcspb.DetectorInfo
7576

77+
type ECSDetectorInfoMap map[string]ECSDetectorInfo
78+
7679
func NewPlugin(endpoint string) integration.Plugin {
7780
u, err := url.Parse(endpoint)
7881
if err != nil {
@@ -121,7 +124,7 @@ func (p *Plugin) GetData(_ []any) string {
121124
environmentIds := environment.ManagerInstance().Ids()
122125

123126
outMap := make(map[string]interface{})
124-
outMap["partitions"] = p.partitionStatesForEnvs(environmentIds)
127+
outMap["partitions"] = p.pendingEorsForEnvs(environmentIds)
125128

126129
p.detectorMapMu.RLock()
127130
outMap["detectors"] = p.detectorMap.ToEcsDetectors()
@@ -139,20 +142,50 @@ func (p *Plugin) GetEnvironmentsData(environmentIds []uid.ID) map[uid.ID]string
139142
return nil
140143
}
141144

142-
out := p.partitionStatesForEnvs(environmentIds)
145+
envMan := environment.ManagerInstance()
146+
pendingEors := p.pendingEorsForEnvs(environmentIds)
147+
148+
out := make(map[uid.ID]string)
149+
150+
detectorMap := p.detectorMap.ToEcsDetectors()
151+
for _, envId := range environmentIds {
152+
env, err := envMan.Environment(envId)
153+
if err != nil {
154+
log.WithField("partition", envId).
155+
WithError(err).
156+
Error("DCS client cannot acquire environment")
157+
continue
158+
}
159+
160+
includedDetectors := env.GetActiveDetectors().StringList()
161+
includedDetectorsMap := detectorMap.Filtered(includedDetectors)
162+
163+
pi := PartitionInfo{
164+
Detectors: includedDetectorsMap,
165+
}
166+
if pendingEorStatus, pendingEorExists := pendingEors[envId]; pendingEorExists {
167+
pi.SorSuccessful = pendingEorStatus
168+
}
169+
170+
marshalled, err := json.Marshal(pi)
171+
if err != nil {
172+
continue
173+
}
174+
out[envId] = string(marshalled[:])
175+
}
176+
143177
return out
144178
}
145179

146180
func (p *Plugin) GetEnvironmentsShortData(environmentIds []uid.ID) map[uid.ID]string {
147-
return p.GetEnvironmentsData(environmentIds)
181+
return nil
148182
}
149183

150-
func (p *Plugin) partitionStatesForEnvs(envIds []uid.ID) map[uid.ID]string {
151-
out := make(map[uid.ID]string)
184+
func (p *Plugin) pendingEorsForEnvs(envIds []uid.ID) map[uid.ID]bool {
185+
out := make(map[uid.ID]bool)
152186
for _, envId := range envIds {
153-
if _, ok := p.pendingEORs[envId.String()]; ok {
154-
out[envId] = "SOR SUCCESSFUL"
155-
}
187+
_, pendingEorExists := p.pendingEORs[envId.String()]
188+
out[envId] = pendingEorExists
156189
}
157190
return out
158191
}
@@ -168,6 +201,10 @@ func (p *Plugin) updateLastKnownDetectorStates(detectorMatrix []*dcspb.DetectorI
168201
} else {
169202
if detInfo.State != dcspb.DetectorState_NULL_STATE {
170203
p.detectorMap[dcsDet].State = detInfo.State
204+
timestamp, err := time.Parse(DCS_TIME_FORMAT, detInfo.Timestamp)
205+
if err == nil {
206+
p.detectorMap[dcsDet].Timestamp = fmt.Sprintf("%d", timestamp.UnixMilli())
207+
}
171208
}
172209
}
173210
}
@@ -184,6 +221,10 @@ func (p *Plugin) updateDetectorOpAvailabilities(detectorMatrix []*dcspb.Detector
184221
} else {
185222
p.detectorMap[dcsDet].PfrAvailability = detInfo.PfrAvailability
186223
p.detectorMap[dcsDet].SorAvailability = detInfo.SorAvailability
224+
timestamp, err := time.Parse(DCS_TIME_FORMAT, detInfo.Timestamp)
225+
if err == nil {
226+
p.detectorMap[dcsDet].Timestamp = fmt.Sprintf("%d", timestamp.UnixMilli())
227+
}
187228
}
188229
}
189230
}

core/integration/dcs/structs.go

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ import (
3131
dcspb "github.com/AliceO2Group/Control/core/integration/dcs/protos"
3232
)
3333

34+
type PartitionInfo struct {
35+
SorSuccessful bool
36+
Detectors ECSDetectorInfoMap
37+
}
38+
39+
type ECSDetectorInfo struct {
40+
State string
41+
Timestamp string
42+
AllowedRunTypes []string
43+
PfrAvailability string
44+
SorAvailability string
45+
}
46+
3447
func (d DCSDetectors) ToStringSlice() (sslice []string) {
3548
if d == nil {
3649
return
@@ -102,10 +115,36 @@ func (dsm DCSDetectorOpAvailabilityMap) compatibleWithDCSOperation(conditionStat
102115
}
103116
}
104117

105-
func (m DCSDetectorInfoMap) ToEcsDetectors() map[string]*dcspb.DetectorInfo {
106-
out := make(map[string]*dcspb.DetectorInfo)
118+
func fromDcsDetectorInfo(d *dcspb.DetectorInfo) ECSDetectorInfo {
119+
return ECSDetectorInfo{
120+
State: d.GetState().String(),
121+
Timestamp: d.GetTimestamp(),
122+
AllowedRunTypes: func(rts []dcspb.RunType) []string {
123+
out := make([]string, len(rts))
124+
for i, rt := range rts {
125+
out[i] = rt.String()
126+
}
127+
return out
128+
}(d.GetAllowedRunTypes()),
129+
PfrAvailability: d.GetPfrAvailability().String(),
130+
SorAvailability: d.GetSorAvailability().String(),
131+
}
132+
}
133+
134+
func (m DCSDetectorInfoMap) ToEcsDetectors() ECSDetectorInfoMap {
135+
out := make(map[string]ECSDetectorInfo)
107136
for k, v := range m {
108-
out[dcsToEcsDetector(k)] = v
137+
out[dcsToEcsDetector(k)] = fromDcsDetectorInfo(v)
138+
}
139+
return out
140+
}
141+
142+
func (m ECSDetectorInfoMap) Filtered(detectorList []string) ECSDetectorInfoMap {
143+
out := make(ECSDetectorInfoMap)
144+
for _, det := range detectorList {
145+
if _, ok := m[det]; ok {
146+
out[det] = m[det]
147+
}
109148
}
110149
return out
111150
}

0 commit comments

Comments
 (0)