forked from AliceO2Group/Control
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.go
More file actions
1627 lines (1443 loc) · 53.7 KB
/
plugin.go
File metadata and controls
1627 lines (1443 loc) · 53.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* === This file is part of ALICE O² ===
*
* Copyright 2021-2024 CERN and copyright holders of ALICE O².
* Author: Teo Mrnjavac <teo.mrnjavac@cern.ch>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In applying this license CERN does not waive the privileges and
* immunities granted to it by virtue of its status as an
* Intergovernmental Organization or submit itself to any jurisdiction.
*/
//go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_opt=paths=source_relative --go-grpc_out=require_unimplemented_servers=false:. protos/odc.proto
package odc
import (
"context"
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"net/url"
"slices"
"strconv"
"strings"
"sync"
"time"
"github.com/AliceO2Group/Control/apricot"
common_event "github.com/AliceO2Group/Control/common/event"
"github.com/AliceO2Group/Control/common/event/topic"
"github.com/AliceO2Group/Control/common/logger/infologger"
pb "github.com/AliceO2Group/Control/common/protos"
"github.com/AliceO2Group/Control/common/utils"
"github.com/AliceO2Group/Control/common/utils/uid"
"github.com/AliceO2Group/Control/core/environment"
"github.com/AliceO2Group/Control/core/integration"
"github.com/AliceO2Group/Control/core/integration/odc/event"
"github.com/AliceO2Group/Control/core/integration/odc/fairmq"
odc "github.com/AliceO2Group/Control/core/integration/odc/protos"
"github.com/AliceO2Group/Control/core/task/sm"
"github.com/AliceO2Group/Control/core/the"
"github.com/AliceO2Group/Control/core/workflow/callable"
"github.com/spf13/viper"
"google.golang.org/grpc"
)
const (
ODC_DIAL_TIMEOUT = 2 * time.Second
ODC_GENERAL_OP_TIMEOUT = 5 * time.Second
ODC_CONFIGURE_TIMEOUT = 60 * time.Second
ODC_PARTITIONINITIALIZE_TIMEOUT = 60 * time.Second
ODC_START_TIMEOUT = 15 * time.Second
ODC_STOP_TIMEOUT = 15 * time.Second
ODC_RESET_TIMEOUT = 30 * time.Second
ODC_PARTITIONTERMINATE_TIMEOUT = 30 * time.Second
ODC_PADDING_TIMEOUT = 3 * time.Second
ODC_STATUS_TIMEOUT = 3 * time.Second
ODC_POLLING_INTERVAL = 3 * time.Second
ODC_MAX_INBOUND_MESSAGE_SIZE = 32 * 1024 * 1024 // 16 MiB
TOPIC = topic.IntegratedService + topic.Separator + "odc"
)
type Plugin struct {
odcHost string
odcPort int
odcClient *RpcClient
cachedStatus *OdcStatus
cachedStatusMu sync.RWMutex
cachedStatusCancelFunc context.CancelFunc
}
type OdcStatus struct {
Partitions map[uid.ID]*OdcPartitionInfo
Status odc.ReplyStatus
Message string
Error *odc.Error
}
type OdcDeviceId uint64
func (o OdcDeviceId) MarshalJSON() ([]byte, error) {
return json.Marshal(strconv.FormatUint(uint64(o), 10))
}
type OdcPartitionInfo struct {
PartitionId uid.ID `json:"-"`
RunNumber uint32 `json:"runNumber"`
State string `json:"state"`
EcsState sm.State `json:"ecsState"`
DdsSessionId string `json:"ddsSessionId"`
DdsSessionStatus string `json:"ddsSessionStatus"`
Devices map[OdcDeviceId]*OdcDevice `json:"devices"`
Hosts []string `json:"hosts"`
}
type OdcDevice struct {
TaskId string `json:"taskId"`
State string `json:"state"`
EcsState sm.State `json:"ecsState"`
Path string `json:"path"`
Ignored bool `json:"ignored"`
Host string `json:"host"`
Expendable bool `json:"expendable"`
Rmsjobid string `json:"rmsjobid"`
}
type partitionStateChangedEventPayload struct {
PartitionId uid.ID `json:"partitionId"`
DdsSessionId string `json:"ddsSessionId"`
DdsSessionStatus string `json:"ddsSessionStatus"`
State string `json:"state"`
EcsState sm.State `json:"ecsState"`
}
type deviceStateChangedEventPayload struct {
PartitionId uid.ID `json:"partitionId"`
DdsSessionId string `json:"ddsSessionId"`
DdsSessionStatus string `json:"ddsSessionStatus"`
State string `json:"state"`
EcsState sm.State `json:"ecsState"`
TaskId string `json:"taskId"`
Path string `json:"path"`
Ignored bool `json:"ignored"`
Host string `json:"host"`
Expendable bool `json:"expendable"`
Rmsjobid string `json:"rmsjobid"`
}
func NewPlugin(endpoint string) integration.Plugin {
u, err := url.Parse(endpoint)
if err != nil {
log.WithField("endpoint", endpoint).
WithError(err).
Error("bad service endpoint")
return nil
}
portNumber, _ := strconv.Atoi(u.Port())
return &Plugin{
odcHost: u.Hostname(),
odcPort: portNumber,
odcClient: nil,
}
}
func (p *Plugin) GetName() string {
return "odc"
}
func (p *Plugin) GetPrettyName() string {
return "ODC (EPN subcontrol)"
}
func (p *Plugin) GetEndpoint() string {
return viper.GetString("odcEndpoint")
}
func (p *Plugin) GetConnectionState() string {
if p == nil || p.odcClient == nil {
return "UNKNOWN"
}
return p.odcClient.conn.GetState().String()
}
func (p *Plugin) queryPartitionStatus() {
defer utils.TimeTrackFunction(time.Now(), log.WithPrefix("odcclient"))
ctx, cancel := context.WithTimeout(context.Background(), ODC_STATUS_TIMEOUT)
defer cancel()
statusRep := &odc.StatusReply{}
var err error
statusRep, err = p.odcClient.Status(ctx, &odc.StatusRequest{Running: true}, grpc.EmptyCallOption{})
if err != nil {
log.WithField("level", infologger.IL_Support).
WithField("call", "Status").
WithError(err).Error("ODC error")
}
if statusRep == nil {
log.WithField("level", infologger.IL_Support).
WithField("call", "Status").
WithError(fmt.Errorf("ODC Status response is nil")).Error("ODC error")
statusRep = &odc.StatusReply{}
}
response := &OdcStatus{
Status: statusRep.Status,
Message: statusRep.Msg,
Error: statusRep.Error,
Partitions: make(map[uid.ID]*OdcPartitionInfo),
}
odcPartInfoSlice := make([]*OdcPartitionInfo, len(statusRep.Partitions))
// concurrent request for the detailed state of each partition
var wg sync.WaitGroup
for idx, odcPartSt := range statusRep.Partitions {
if odcPartSt == nil {
continue
}
var id uid.ID
id, err = uid.FromString(odcPartSt.Partitionid)
if err != nil {
continue
}
wg.Add(1)
odcPartInfoSlice[idx] = &OdcPartitionInfo{
PartitionId: id,
RunNumber: uint32(odcPartSt.Runnr),
State: odcPartSt.State,
DdsSessionId: odcPartSt.Sessionid,
DdsSessionStatus: odcPartSt.Status.String(),
}
i := idx
go func(idx int, partId uid.ID) {
defer wg.Done()
ctx, cancel := context.WithTimeout(context.Background(), ODC_STATUS_TIMEOUT)
defer cancel()
odcPartStateRep, err := p.odcClient.GetState(ctx, &odc.StateRequest{
Partitionid: partId.String(),
Detailed: true,
}, grpc.EmptyCallOption{})
if err != nil {
log.WithField("level", infologger.IL_Support).
WithField("call", "GetState").
WithField("partition", partId.String()).
WithError(err).Error("ODC error")
return
}
if odcPartStateRep == nil || odcPartStateRep.Reply == nil {
log.WithField("level", infologger.IL_Support).
WithField("call", "GetState").
WithField("partition", partId.String()).
WithError(fmt.Errorf("ODC GetState response is nil")).Error("ODC error")
return
}
odcPartInfoSlice[idx].Hosts = odcPartStateRep.Reply.Hosts
odcPartInfoSlice[idx].Devices = make(map[OdcDeviceId]*OdcDevice, len(odcPartStateRep.Devices))
for _, device := range odcPartStateRep.Devices {
odcPartInfoSlice[idx].Devices[OdcDeviceId(device.Id)] = &OdcDevice{
TaskId: strconv.FormatUint(device.Id, 10),
State: device.State,
Path: device.Path,
Ignored: device.Ignored,
Host: device.Host,
Expendable: device.Expendable,
Rmsjobid: device.Rmsjobid,
}
}
}(i, id)
}
wg.Wait()
for _, odcPartSt := range odcPartInfoSlice {
if odcPartSt == nil || odcPartSt.PartitionId.IsNil() {
// The partition wasn't found in the ODC response
continue
}
response.Partitions[odcPartSt.PartitionId] = odcPartSt
}
p.cachedStatusMu.Lock()
// state change detection
if p.cachedStatus != nil && p.cachedStatus.Status == odc.ReplyStatus_SUCCESS {
for id, partitionInfo := range response.Partitions {
// do we have the given partition on record already? if not, no state change detection is possible
if existingPartition, ok := p.cachedStatus.Partitions[id]; ok {
// detection of device state change + event publication
for deviceId, device := range partitionInfo.Devices {
existingDevice, hasDevice := existingPartition.Devices[deviceId]
oldEcsState := sm.UNKNOWN // we presume the task didn't exist before
// if a device with this ID is already known to us from before
if hasDevice {
// if device state has changed
if existingDevice.State != device.State {
// if the state has changed, we take note of the previous state
oldEcsState = existingDevice.EcsState
} else {
// if the state hasn't changed, we set the old ECS state and bail
device.EcsState = existingDevice.EcsState
continue
}
}
device.EcsState = fairmq.ToEcsState(device.State, oldEcsState)
// since the odc-state of the task has changed, we must publish the event
payload := deviceStateChangedEventPayload{
PartitionId: partitionInfo.PartitionId,
DdsSessionId: partitionInfo.DdsSessionId,
DdsSessionStatus: partitionInfo.DdsSessionStatus,
State: device.State,
EcsState: device.EcsState,
TaskId: device.TaskId,
Path: device.Path,
Ignored: device.Ignored,
Host: device.Host,
Expendable: device.Expendable,
Rmsjobid: device.Rmsjobid,
}
payloadJson, _ := json.Marshal(payload)
the.EventWriterWithTopic(TOPIC).WriteEvent(&pb.Ev_IntegratedServiceEvent{
Name: "odc.deviceStateChanged",
EnvironmentId: id.String(),
Payload: string(payloadJson[:]),
})
}
// detection of env (ODC partition) state change + event publication
if existingPartition.State != partitionInfo.State {
partitionInfo.EcsState = fairmq.ToEcsState(partitionInfo.State, existingPartition.EcsState)
log.WithField("level", infologger.IL_Support).
WithField("partition", id.String()).
WithField("oldState", existingPartition.State).
WithField("oldEcsState", existingPartition.EcsState).
WithField("ecsState", partitionInfo.EcsState).
WithField("state", partitionInfo.State).
Info("ODC Partition state changed")
payload := partitionStateChangedEventPayload{
PartitionId: partitionInfo.PartitionId,
DdsSessionId: partitionInfo.DdsSessionId,
DdsSessionStatus: partitionInfo.DdsSessionStatus,
State: partitionInfo.State,
EcsState: partitionInfo.EcsState,
}
payloadJson, _ := json.Marshal(payload)
the.EventWriterWithTopic(TOPIC).WriteEvent(&pb.Ev_IntegratedServiceEvent{
Name: "odc.partitionStateChanged",
EnvironmentId: id.String(),
Payload: string(payloadJson[:]),
})
envMan := environment.ManagerInstance()
if envMan != nil {
go envMan.NotifyIntegratedServiceEvent(&event.OdcPartitionStateChangeEvent{
IntegratedServiceEventBase: common_event.IntegratedServiceEventBase{ServiceName: "ODC"},
EnvironmentId: id,
State: partitionInfo.State,
EcsState: partitionInfo.EcsState.String(),
})
} else {
log.WithField("level", infologger.IL_Support).
WithField("partition", id.String()).
WithField("oldState", existingPartition.State).
WithField("state", partitionInfo.State).
Warn("could not notify environment manager of ODC partition state change event")
}
} else {
partitionInfo.EcsState = existingPartition.EcsState
}
}
}
}
p.cachedStatus = response
p.cachedStatusMu.Unlock()
}
func (p *Plugin) GetData(_ []any) string {
if p == nil || p.odcClient == nil {
return ""
}
p.cachedStatusMu.RLock()
r := p.cachedStatus
if r == nil {
p.cachedStatusMu.RUnlock()
return ""
}
partitionStates := make(map[string]map[string]string)
if r.Status == odc.ReplyStatus_SUCCESS {
for id, partitionInfo := range r.Partitions {
partitionStates[id.String()] = map[string]string{
"state": partitionInfo.State,
"ecsState": partitionInfo.EcsState.String(),
}
}
}
p.cachedStatusMu.RUnlock()
out, err := json.Marshal(partitionStates)
if err != nil {
return ""
}
return string(out[:])
}
func (p *Plugin) GetEnvironmentsData(envIds []uid.ID) map[uid.ID]string {
if p == nil || p.odcClient == nil {
return nil
}
p.cachedStatusMu.RLock()
defer p.cachedStatusMu.RUnlock()
if p.cachedStatus == nil {
return nil
}
out := make(map[uid.ID]string)
for _, id := range envIds {
partitionInfo, ok := p.cachedStatus.Partitions[id]
if !ok {
continue
}
partitionInfoOut, err := json.Marshal(partitionInfo)
if err != nil {
continue
}
out[id] = string(partitionInfoOut[:])
}
return out
}
func (p *Plugin) GetEnvironmentsShortData(envIds []uid.ID) map[uid.ID]string {
if p == nil || p.odcClient == nil {
return nil
}
p.cachedStatusMu.RLock()
defer p.cachedStatusMu.RUnlock()
if p.cachedStatus == nil {
return nil
}
out := make(map[uid.ID]string)
for _, id := range envIds {
partitionInfo, ok := p.cachedStatus.Partitions[id]
if !ok {
continue
}
// return everything except the devices
partitionInfoPayload := &OdcPartitionInfo{
PartitionId: partitionInfo.PartitionId,
RunNumber: partitionInfo.RunNumber,
State: partitionInfo.State,
EcsState: partitionInfo.EcsState,
DdsSessionId: partitionInfo.DdsSessionId,
DdsSessionStatus: partitionInfo.DdsSessionStatus,
Hosts: partitionInfo.Hosts,
}
partitionInfoOut, err := json.Marshal(partitionInfoPayload)
if err != nil {
continue
}
out[id] = string(partitionInfoOut[:])
}
return out
}
func getFlpIdList(varStack map[string]string) (flps []string, err error) {
payload, ok := varStack["hosts"]
if !ok {
return []string{}, fmt.Errorf("could not retrieve FLP list (\"hosts\") from varStack")
}
flpHostnames := make([]string, 0)
err = json.Unmarshal([]byte(payload), &flpHostnames)
if err != nil {
return []string{}, err
}
const prodFlpPrefix = "alio2-cr1-flp"
const stagingFlpPrefix = "alio2-cr1-mvs"
// we take only prod and staging into account
// we add S to staging IDs as requested in OCTRL-753
flpIds := make([]string, 0)
for _, flp := range flpHostnames {
if strings.HasPrefix(flp, prodFlpPrefix) {
id := strings.TrimPrefix(flp, prodFlpPrefix)
if len(id) > 0 {
flpIds = append(flpIds, id)
}
} else if strings.HasPrefix(flp, stagingFlpPrefix) {
id := strings.TrimPrefix(flp, stagingFlpPrefix)
if len(id) > 0 {
flpIds = append(flpIds, "S"+id)
}
}
}
return flpIds, nil
}
func (p *Plugin) Init(_ string) error {
if p.odcClient == nil {
cxt, cancel := context.WithCancel(context.Background())
p.odcClient = NewClient(cxt, cancel, viper.GetString("odcEndpoint"))
if p.odcClient == nil {
return fmt.Errorf("failed to connect to ODC service on %s", viper.GetString("ddSchedulerEndpoint"))
}
log.Debug("ODC plugin initialized")
}
var ctx context.Context
ctx, p.cachedStatusCancelFunc = context.WithCancel(context.Background())
odcPollingIntervalStr := viper.GetString("odcPollingInterval")
odcPollingInterval, err := time.ParseDuration(odcPollingIntervalStr)
if err != nil {
odcPollingInterval = ODC_POLLING_INTERVAL
log.Debugf("ODC plugin cannot acquire polling interval, defaulting to %s", ODC_POLLING_INTERVAL.String())
}
// polling
go func() {
for {
select {
case <-ctx.Done():
return
case <-time.After(odcPollingInterval):
p.queryPartitionStatus()
}
}
}()
return nil
}
func (p *Plugin) ObjectStack(varStack map[string]string, baseConfigStack map[string]string) (stack map[string]interface{}) {
// baseConfigStack is this environment's defaults + vars from Consul but no user input
// It is passed around this way because it cannot be acquired from envMan.GetEnv(id).BaseConfigStack, since during
// this ObjectStack call the env isn't mapped in envMan yet (we're in the middle of creating + processing it with
// ProcessTemplates in loadWorkflow).
// The only reason we need the naked defaults + vars is for the non-standard processing of the "default" keyword in
// the ODC plugin, so this is a break from design.
envId, envIdOk := varStack["environment_id"]
if !envIdOk {
log.Error("ObjectStack cannot acquire environment ID")
return
}
if baseConfigStack == nil {
baseConfigStack = make(map[string]string)
}
stack = make(map[string]interface{})
stack["GenerateEPNWorkflowScript"] = func() (out string) {
/*
OCTRL-558 example:
GEN_TOPO_HASH=[0/1] GEN_TOPO_SOURCE=[...] DDMODE=[TfBuilder Mode] GEN_TOPO_LIBRARY_FILE=[...]
GEN_TOPO_WORKFLOW_NAME=[...] WORKFLOW_DETECTORS=[...] WORKFLOW_DETECTORS_QC=[...]
WORKFLOW_DETECTORS_CALIB=[...] WORKFLOW_PARAMETERS=[...] RECO_NUM_NODES_OVERRIDE=[...]
MULTIPLICITY_FACTOR_RAWDECODERS=[...] MULTIPLICITY_FACTOR_CTFENCODERS=[...]
MULTIPLICITY_FACTOR_REST=[...] GEN_TOPO_WIPE_CACHE=[0/1] BEAMTYPE=[PbPb/pp/pPb/cosmic/technical]
NHBPERTF=[...] GEN_TOPO_ONTHEFLY=1 [Extra environment variables]
/home/epn/pdp/gen_topo.sh
R3C-710:
`pdp_o2pdpsuite_version` is a new field. Its content should be sent in the string as `OVERRIDE_PDPSUITE_VERSION=[...]`.
In case it is set to `default`, instead of the string `default` the preconfigured default version in consul should be sent.
`pdp_qcjson_version`: similar to avove, new field. please send as `SET_QCJSON_VERSION`.
If set to the string `default`, please sent the default version configured in consul instead.
`pdp_o2_data_processing_hash`: if set to the string `default`, sent the default hash configured in consul instead.
`odc_n_epns_max_fail` : new field. Please send as `RECO_MAX_FAIL_NODES_OVERRIDE=[...]`.
`epn_store_raw_data_fraction` new field, please send as `DD_DISK_FRACTION=[...]`.
`pdp_nr_compute_nodes` removed this field since no longer needed.
Please send the value of `odc_n_epns` directly as `RECO_NUM_NODES_OVERRIDE=[...]`.
`pdp_epn_shmid`: new field, please send as `SHM_MANAGER_SHMID=[...]`
`pdp_epn_shm_recreate`: new field, please send as `SHM_MANAGER_SHM_RECREATE=[0|1]`
*/
var (
pdpConfigOption, o2DPSource, tfbDDMode string
pdpLibraryFile, pdpLibWorkflowName string
pdpDetectorList, pdpDetectorExcludeListQc, pdpDetectorExcludeListCalib string
pdpWorkflowParams string
pdpRawDecoderMultiFactor, pdpCtfEncoderMultiFactor, pdpRecoProcessMultiFactor string
pdpWipeWorkflowCache, pdpBeamType, pdpNHbfPerTf string
pdpExtraEnvVars, pdpEpnShmSizes, pdpGeneratorScriptPath string
odcNEpns string
ok bool
accumulator []string
pdpO2PdpSuiteVersion, pdpQcJsonVersion string
odcNEpnsMaxFail, epnStoreRawDataFraction string
pdpEpnShmId string
runType string
flpIds []string
deploymentType string
)
accumulator = make([]string, 0)
configStack := baseConfigStack
pdpConfigOption, ok = varStack["pdp_config_option"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire PDP workflow configuration mode")
return
}
switch pdpConfigOption {
case "Repository hash":
o2DPSource, ok = varStack["pdp_o2_data_processing_hash"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire PDP Repository hash")
return
}
if strings.TrimSpace(o2DPSource) == "default" { // if UI sends 'default', we look in Consul
o2DPSource, ok = configStack["pdp_o2_data_processing_hash"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire PDP Repository hash default")
return
}
}
accumulator = append(accumulator, "GEN_TOPO_HASH=1")
case "Repository path":
o2DPSource, ok = varStack["pdp_o2_data_processing_path"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire PDP Repository path")
return
}
accumulator = append(accumulator, "GEN_TOPO_HASH=0")
case "Manual XML":
fallthrough
default:
return
}
accumulator = append(accumulator, fmt.Sprintf("GEN_TOPO_SOURCE='%s'", strings.TrimSpace(o2DPSource)))
tfbDDMode, ok = varStack["tfb_dd_mode"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire TF Builder mode")
return
}
accumulator = append(accumulator, fmt.Sprintf("DDMODE='%s'", strings.TrimSpace(tfbDDMode)))
pdpLibraryFile, ok = varStack["pdp_topology_description_library_file"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire topology description library file")
return
}
accumulator = append(accumulator, fmt.Sprintf("GEN_TOPO_LIBRARY_FILE='%s'", strings.TrimSpace(pdpLibraryFile)))
pdpLibWorkflowName, ok = varStack["pdp_workflow_name"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire PDP workflow name in topology library file")
return
}
accumulator = append(accumulator, fmt.Sprintf("GEN_TOPO_WORKFLOW_NAME='%s'", strings.TrimSpace(pdpLibWorkflowName)))
pdpDetectorList, ok = varStack["pdp_detector_list_global"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire PDP workflow name in topology library file")
return
}
if strings.TrimSpace(pdpDetectorList) == "default" {
pdpDetectorList, ok = varStack["detectors"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire general detector list from varStack")
return
}
detectorsSlice, err := p.parseDetectors(pdpDetectorList)
if err != nil {
log.WithField("partition", envId).
WithField("detectorList", pdpDetectorList).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot parse general detector list")
return
}
// Special case: if the detector list is "default" and ctp_readout_enabled==true, we include TRG
ctpReadoutEnabled := "false"
ctpReadoutEnabled, ok = varStack["ctp_readout_enabled"]
if ok && strings.ToLower(strings.TrimSpace(ctpReadoutEnabled)) == "true" {
detectorsSlice = append(detectorsSlice, "TRG")
}
slices.Sort(detectorsSlice)
pdpDetectorList = strings.Join(detectorsSlice, ",")
}
accumulator = append(accumulator, fmt.Sprintf("WORKFLOW_DETECTORS='%s'", strings.TrimSpace(pdpDetectorList)))
pdpDetectorExcludeListQc, ok = varStack["pdp_detector_exclude_list_qc"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire QC detector exclude list in topology library file")
return
}
accumulator = append(accumulator, fmt.Sprintf("WORKFLOW_DETECTORS_EXCLUDE_QC='%s'", strings.TrimSpace(pdpDetectorExcludeListQc)))
pdpDetectorExcludeListCalib, ok = varStack["pdp_detector_exclude_list_calib"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire calibration detector exclude list in topology library file")
return
}
accumulator = append(accumulator, fmt.Sprintf("WORKFLOW_DETECTORS_EXCLUDE_CALIB='%s'", strings.TrimSpace(pdpDetectorExcludeListCalib)))
pdpWorkflowParams, ok = varStack["pdp_workflow_parameters"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire PDP workflow parameters")
return
}
accumulator = append(accumulator, fmt.Sprintf("WORKFLOW_PARAMETERS='%s'", strings.TrimSpace(pdpWorkflowParams)))
odcNEpns, ok = varStack["odc_n_epns"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire ODC number of EPNs")
return
}
odcNEpnsI, err := strconv.Atoi(odcNEpns)
if err != nil {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot parse ODC number of EPNs")
return
}
accumulator = append(accumulator, fmt.Sprintf("RECO_NUM_NODES_OVERRIDE=%d", odcNEpnsI))
odcNEpnsMaxFail, ok = varStack["odc_n_epns_max_fail"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire ODC number of EPNs max fail")
return
}
odcNEpnsMaxFailI, err := strconv.Atoi(odcNEpnsMaxFail)
if err != nil {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot parse ODC number of EPNs max fail")
return
}
accumulator = append(accumulator, fmt.Sprintf("RECO_MAX_FAIL_NODES_OVERRIDE=%d", odcNEpnsMaxFailI))
pdpRawDecoderMultiFactor, ok = varStack["pdp_raw_decoder_multi_factor"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire PDP number of raw decoder processing instances")
return
}
accumulator = append(accumulator, fmt.Sprintf("MULTIPLICITY_FACTOR_RAWDECODERS=%s", strings.TrimSpace(pdpRawDecoderMultiFactor)))
pdpCtfEncoderMultiFactor, ok = varStack["pdp_ctf_encoder_multi_factor"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire PDP number of CTF encoder processing instances")
return
}
accumulator = append(accumulator, fmt.Sprintf("MULTIPLICITY_FACTOR_CTFENCODERS=%s", strings.TrimSpace(pdpCtfEncoderMultiFactor)))
pdpRecoProcessMultiFactor, ok = varStack["pdp_reco_process_multi_factor"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire PDP number of other reconstruction processing instances")
return
}
accumulator = append(accumulator, fmt.Sprintf("MULTIPLICITY_FACTOR_REST=%s", strings.TrimSpace(pdpRecoProcessMultiFactor)))
pdpBeamType, ok = varStack["pdp_beam_type"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire beam type")
return
}
accumulator = append(accumulator, fmt.Sprintf("BEAMTYPE='%s'", strings.TrimSpace(pdpBeamType)))
pdpNHbfPerTf, ok = varStack["pdp_n_hbf_per_tf"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire number of HBFs per TF")
return
}
accumulator = append(accumulator, fmt.Sprintf("NHBPERTF=%s", strings.TrimSpace(pdpNHbfPerTf)))
accumulator = append(accumulator, "GEN_TOPO_ONTHEFLY=1")
pdpO2PdpSuiteVersion, ok = varStack["pdp_o2pdpsuite_version"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire PDP Suite version")
return
}
if strings.TrimSpace(pdpO2PdpSuiteVersion) == "default" { // if UI sends 'default', we look in Consul
pdpO2PdpSuiteVersion, ok = configStack["pdp_o2pdpsuite_version"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire PDP Suite version default")
return
}
}
accumulator = append(accumulator, fmt.Sprintf("OVERRIDE_PDPSUITE_VERSION='%s'", pdpO2PdpSuiteVersion))
// SET_QCJSON_VERSION does not come from user input or vars any more, it's instead a direct query to QC runtime
pdpQcJsonVersion, err = apricot.Instance().GetRuntimeEntry("qc", "config_hash")
if err != nil {
log.WithField("partition", envId).
WithError(err).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire PDP QCJson config_hash from QC runtime KV")
return
}
accumulator = append(accumulator, fmt.Sprintf("SET_QCJSON_VERSION='%s'", pdpQcJsonVersion))
epnStoreRawDataFraction, ok = varStack["epn_store_raw_data_fraction"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire EPN DD disk raw data fraction")
return
}
accumulator = append(accumulator, fmt.Sprintf("DD_DISK_FRACTION='%s'", epnStoreRawDataFraction))
pdpEpnShmId, ok = varStack["pdp_epn_shmid"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire PDP EPN SHMID")
return
}
accumulator = append(accumulator, fmt.Sprintf("SHM_MANAGER_SHMID='%s'", pdpEpnShmId))
runType, ok = varStack["run_type"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Warn("could not get variable run_type from environment context, using NONE")
runType = "NONE"
}
accumulator = append(accumulator, fmt.Sprintf("RUNTYPE=%s", strings.TrimSpace(runType)))
flpIds, err = getFlpIdList(varStack)
if err != nil {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
WithError(err).
Error("cannot acquire FLP ID list, it will be empty")
}
accumulator = append(accumulator, fmt.Sprintf("FLP_IDS='%s'", strings.Join(flpIds, ",")))
deploymentType, ok = varStack["setup_name"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire setup_name, needed for GEN_TOPO_DEPLOYMENT_TYPE, using UNKNOWN")
deploymentType = "UNKNOWN"
}
// we replace spaces with underscores, since David requested no spaces in OCTRL-751
deploymentType = strings.ReplaceAll(strings.TrimSpace(deploymentType), " ", "_")
accumulator = append(accumulator, fmt.Sprintf("GEN_TOPO_DEPLOYMENT_TYPE=%s", deploymentType))
pdpExtraEnvVars, ok = varStack["pdp_extra_env_vars"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire PDP extra environment variables")
return
}
accumulator = append(accumulator, strings.TrimSpace(pdpExtraEnvVars))
pdpEpnShmSizes, ok = varStack["pdp_epn_shm_sizes"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire PDP EPN SHM sizes")
return
}
accumulator = append(accumulator, strings.TrimSpace(pdpEpnShmSizes))
pdpGeneratorScriptPath, ok = varStack["pdp_generator_script_path"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot acquire PDP generator script path")
return
}
accumulator = append(accumulator, strings.TrimSpace(pdpGeneratorScriptPath))
out = strings.Join(accumulator, " ")
// before we ship out the payload, we take the hash of the full string and prepend a few last variables with the
// hash of everything else that follows, except ECS_ENVIRONMENT_ID and GEN_TOPO_WIPE_CACHE, the only
// variables that must stay unhashed
// see https://alice.its.cern.ch/jira/browse/OCTRL-736
hash := md5.Sum([]byte(out))
hashS := hex.EncodeToString(hash[:])
out = fmt.Sprintf("GEN_TOPO_CACHE_HASH=%s", hashS) + " " + out
pdpWipeWorkflowCache, ok = varStack["pdp_wipe_workflow_cache"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Warn("cannot acquire PDP workflow cache wipe option, assuming false")
pdpWipeWorkflowCache = "false"
}
pdpWipeWorkflowCacheB, err := strconv.ParseBool(pdpWipeWorkflowCache)
if err != nil {
log.WithField("partition", envId).
WithField("call", "GenerateEPNWorkflowScript").
Error("cannot parse PDP workflow cache wipe option")
pdpWipeWorkflowCacheB = false
}
pdpWipeWorkflowCacheI := 0
if pdpWipeWorkflowCacheB {
pdpWipeWorkflowCacheI = 1
}
out = fmt.Sprintf("GEN_TOPO_WIPE_CACHE=%d", pdpWipeWorkflowCacheI) + " " + out
// finally we prepend ECS_ENVIRONMENT_ID
out = fmt.Sprintf("ECS_ENVIRONMENT_ID=%s", envId) + " " + out
return
}
stack["GenerateEPNTopologyFullname"] = func() (out string) {
pdpConfigOption, ok := varStack["pdp_config_option"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNTopologyFullname").
Error("cannot acquire PDP workflow configuration mode")
return
}
pdpLibraryFile, ok := varStack["pdp_topology_description_library_file"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNTopologyFullname").
Error("cannot acquire topology description library file")
return
}
pdpLibWorkflowName, ok := varStack["pdp_workflow_name"]
if !ok {
log.WithField("partition", envId).
WithField("call", "GenerateEPNTopologyFullname").
Error("cannot acquire PDP workflow name in topology library file")
return
}