From 9340607aca8e44fb0afb825420a87c9acb2d6acf Mon Sep 17 00:00:00 2001 From: Piotr Konopka Date: Tue, 4 Nov 2025 12:05:30 +0100 Subject: [PATCH] Set special users before automatic run stops A minimal, but not comprehensive addition for OCTRL-1065. --- common/protos/common.pb.go | 138 ++++++++++++++++++++++---------- common/protos/common.proto | 9 +++ common/protos/protoutils.go | 14 ++++ core/environment/environment.go | 1 + core/environment/manager.go | 1 + 5 files changed, 122 insertions(+), 41 deletions(-) diff --git a/common/protos/common.pb.go b/common/protos/common.pb.go index 5ea0cc482..ce7796310 100644 --- a/common/protos/common.pb.go +++ b/common/protos/common.pb.go @@ -43,6 +43,58 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +// Production and staging BKP recognizes these special user IDs. +// They are used to associate certain actions (e.g. EOR) with certain subsystem +// or AliECS component rather than a human user. +type SpecialUserId int32 + +const ( + SpecialUserId_INVALID SpecialUserId = 0 + SpecialUserId_LHC SpecialUserId = 60 + SpecialUserId_TIMER SpecialUserId = 65 +) + +// Enum value maps for SpecialUserId. +var ( + SpecialUserId_name = map[int32]string{ + 0: "INVALID", + 60: "LHC", + 65: "TIMER", + } + SpecialUserId_value = map[string]int32{ + "INVALID": 0, + "LHC": 60, + "TIMER": 65, + } +) + +func (x SpecialUserId) Enum() *SpecialUserId { + p := new(SpecialUserId) + *p = x + return p +} + +func (x SpecialUserId) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (SpecialUserId) Descriptor() protoreflect.EnumDescriptor { + return file_protos_common_proto_enumTypes[0].Descriptor() +} + +func (SpecialUserId) Type() protoreflect.EnumType { + return &file_protos_common_proto_enumTypes[0] +} + +func (x SpecialUserId) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use SpecialUserId.Descriptor instead. +func (SpecialUserId) EnumDescriptor() ([]byte, []int) { + return file_protos_common_proto_rawDescGZIP(), []int{0} +} + // * // Beam modes as defined and sent by LHC DIP client plus: // * virtual type LOST_BEAMS - that is generated when beam 1 and beam 2 energy values are not equal anymore as per LHC DIP track: dip/acc/LHC/RunControl/SafeBeam @@ -138,11 +190,11 @@ func (x BeamMode) String() string { } func (BeamMode) Descriptor() protoreflect.EnumDescriptor { - return file_protos_common_proto_enumTypes[0].Descriptor() + return file_protos_common_proto_enumTypes[1].Descriptor() } func (BeamMode) Type() protoreflect.EnumType { - return &file_protos_common_proto_enumTypes[0] + return &file_protos_common_proto_enumTypes[1] } func (x BeamMode) Number() protoreflect.EnumNumber { @@ -151,7 +203,7 @@ func (x BeamMode) Number() protoreflect.EnumNumber { // Deprecated: Use BeamMode.Descriptor instead. func (BeamMode) EnumDescriptor() ([]byte, []int) { - return file_protos_common_proto_rawDescGZIP(), []int{0} + return file_protos_common_proto_rawDescGZIP(), []int{1} } type User struct { @@ -414,37 +466,40 @@ var file_protos_common_proto_rawDesc = []byte{ 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x62, 0x65, 0x61, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x12, 0x2c, 0x0a, 0x08, 0x62, 0x65, 0x61, 0x6d, 0x4d, 0x6f, 0x64, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x10, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x42, 0x65, 0x61, 0x6d, 0x4d, 0x6f, - 0x64, 0x65, 0x52, 0x08, 0x62, 0x65, 0x61, 0x6d, 0x4d, 0x6f, 0x64, 0x65, 0x2a, 0x80, 0x03, 0x0a, - 0x08, 0x42, 0x65, 0x61, 0x6d, 0x4d, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x55, 0x4e, 0x4b, - 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x53, 0x45, 0x54, 0x55, 0x50, 0x10, - 0x01, 0x12, 0x09, 0x0a, 0x05, 0x41, 0x42, 0x4f, 0x52, 0x54, 0x10, 0x02, 0x12, 0x18, 0x0a, 0x14, - 0x49, 0x4e, 0x4a, 0x45, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x50, 0x52, 0x4f, 0x42, 0x45, 0x5f, - 0x42, 0x45, 0x41, 0x4d, 0x10, 0x03, 0x12, 0x18, 0x0a, 0x14, 0x49, 0x4e, 0x4a, 0x45, 0x43, 0x54, - 0x49, 0x4f, 0x4e, 0x5f, 0x53, 0x45, 0x54, 0x55, 0x50, 0x5f, 0x42, 0x45, 0x41, 0x4d, 0x10, 0x04, - 0x12, 0x1a, 0x0a, 0x16, 0x49, 0x4e, 0x4a, 0x45, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x50, 0x48, - 0x59, 0x53, 0x49, 0x43, 0x53, 0x5f, 0x42, 0x45, 0x41, 0x4d, 0x10, 0x05, 0x12, 0x10, 0x0a, 0x0c, - 0x50, 0x52, 0x45, 0x50, 0x41, 0x52, 0x45, 0x5f, 0x52, 0x41, 0x4d, 0x50, 0x10, 0x06, 0x12, 0x08, - 0x0a, 0x04, 0x52, 0x41, 0x4d, 0x50, 0x10, 0x07, 0x12, 0x0c, 0x0a, 0x08, 0x46, 0x4c, 0x41, 0x54, - 0x5f, 0x54, 0x4f, 0x50, 0x10, 0x08, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x51, 0x55, 0x45, 0x45, 0x5a, - 0x45, 0x10, 0x09, 0x12, 0x0a, 0x0a, 0x06, 0x41, 0x44, 0x4a, 0x55, 0x53, 0x54, 0x10, 0x0a, 0x12, - 0x10, 0x0a, 0x0c, 0x53, 0x54, 0x41, 0x42, 0x4c, 0x45, 0x5f, 0x42, 0x45, 0x41, 0x4d, 0x53, 0x10, - 0x0b, 0x12, 0x0e, 0x0a, 0x0a, 0x4c, 0x4f, 0x53, 0x54, 0x5f, 0x42, 0x45, 0x41, 0x4d, 0x53, 0x10, - 0x0c, 0x12, 0x12, 0x0a, 0x0e, 0x55, 0x4e, 0x53, 0x54, 0x41, 0x42, 0x4c, 0x45, 0x5f, 0x42, 0x45, - 0x41, 0x4d, 0x53, 0x10, 0x0d, 0x12, 0x15, 0x0a, 0x11, 0x42, 0x45, 0x41, 0x4d, 0x5f, 0x44, 0x55, - 0x4d, 0x50, 0x5f, 0x57, 0x41, 0x52, 0x4e, 0x49, 0x4e, 0x47, 0x10, 0x0e, 0x12, 0x0d, 0x0a, 0x09, - 0x42, 0x45, 0x41, 0x4d, 0x5f, 0x44, 0x55, 0x4d, 0x50, 0x10, 0x0f, 0x12, 0x0d, 0x0a, 0x09, 0x52, - 0x41, 0x4d, 0x50, 0x5f, 0x44, 0x4f, 0x57, 0x4e, 0x10, 0x10, 0x12, 0x0b, 0x0a, 0x07, 0x43, 0x59, - 0x43, 0x4c, 0x49, 0x4e, 0x47, 0x10, 0x11, 0x12, 0x0c, 0x0a, 0x08, 0x52, 0x45, 0x43, 0x4f, 0x56, - 0x45, 0x52, 0x59, 0x10, 0x12, 0x12, 0x13, 0x0a, 0x0f, 0x49, 0x4e, 0x4a, 0x45, 0x43, 0x54, 0x5f, - 0x41, 0x4e, 0x44, 0x5f, 0x44, 0x55, 0x4d, 0x50, 0x10, 0x13, 0x12, 0x16, 0x0a, 0x12, 0x43, 0x49, - 0x52, 0x43, 0x55, 0x4c, 0x41, 0x54, 0x45, 0x5f, 0x41, 0x4e, 0x44, 0x5f, 0x44, 0x55, 0x4d, 0x50, - 0x10, 0x14, 0x12, 0x0b, 0x0a, 0x07, 0x4e, 0x4f, 0x5f, 0x42, 0x45, 0x41, 0x4d, 0x10, 0x15, 0x42, - 0x53, 0x0a, 0x1f, 0x63, 0x68, 0x2e, 0x63, 0x65, 0x72, 0x6e, 0x2e, 0x61, 0x6c, 0x69, 0x63, 0x65, - 0x2e, 0x6f, 0x32, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, - 0x6f, 0x6e, 0x5a, 0x30, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x41, - 0x6c, 0x69, 0x63, 0x65, 0x4f, 0x32, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x2f, 0x43, 0x6f, 0x6e, 0x74, - 0x72, 0x6f, 0x6c, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x73, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x64, 0x65, 0x52, 0x08, 0x62, 0x65, 0x61, 0x6d, 0x4d, 0x6f, 0x64, 0x65, 0x2a, 0x30, 0x0a, 0x0d, + 0x53, 0x70, 0x65, 0x63, 0x69, 0x61, 0x6c, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x0b, 0x0a, + 0x07, 0x49, 0x4e, 0x56, 0x41, 0x4c, 0x49, 0x44, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x4c, 0x48, + 0x43, 0x10, 0x3c, 0x12, 0x09, 0x0a, 0x05, 0x54, 0x49, 0x4d, 0x45, 0x52, 0x10, 0x41, 0x2a, 0x80, + 0x03, 0x0a, 0x08, 0x42, 0x65, 0x61, 0x6d, 0x4d, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x55, + 0x4e, 0x4b, 0x4e, 0x4f, 0x57, 0x4e, 0x10, 0x00, 0x12, 0x09, 0x0a, 0x05, 0x53, 0x45, 0x54, 0x55, + 0x50, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x41, 0x42, 0x4f, 0x52, 0x54, 0x10, 0x02, 0x12, 0x18, + 0x0a, 0x14, 0x49, 0x4e, 0x4a, 0x45, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x50, 0x52, 0x4f, 0x42, + 0x45, 0x5f, 0x42, 0x45, 0x41, 0x4d, 0x10, 0x03, 0x12, 0x18, 0x0a, 0x14, 0x49, 0x4e, 0x4a, 0x45, + 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x53, 0x45, 0x54, 0x55, 0x50, 0x5f, 0x42, 0x45, 0x41, 0x4d, + 0x10, 0x04, 0x12, 0x1a, 0x0a, 0x16, 0x49, 0x4e, 0x4a, 0x45, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, + 0x50, 0x48, 0x59, 0x53, 0x49, 0x43, 0x53, 0x5f, 0x42, 0x45, 0x41, 0x4d, 0x10, 0x05, 0x12, 0x10, + 0x0a, 0x0c, 0x50, 0x52, 0x45, 0x50, 0x41, 0x52, 0x45, 0x5f, 0x52, 0x41, 0x4d, 0x50, 0x10, 0x06, + 0x12, 0x08, 0x0a, 0x04, 0x52, 0x41, 0x4d, 0x50, 0x10, 0x07, 0x12, 0x0c, 0x0a, 0x08, 0x46, 0x4c, + 0x41, 0x54, 0x5f, 0x54, 0x4f, 0x50, 0x10, 0x08, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x51, 0x55, 0x45, + 0x45, 0x5a, 0x45, 0x10, 0x09, 0x12, 0x0a, 0x0a, 0x06, 0x41, 0x44, 0x4a, 0x55, 0x53, 0x54, 0x10, + 0x0a, 0x12, 0x10, 0x0a, 0x0c, 0x53, 0x54, 0x41, 0x42, 0x4c, 0x45, 0x5f, 0x42, 0x45, 0x41, 0x4d, + 0x53, 0x10, 0x0b, 0x12, 0x0e, 0x0a, 0x0a, 0x4c, 0x4f, 0x53, 0x54, 0x5f, 0x42, 0x45, 0x41, 0x4d, + 0x53, 0x10, 0x0c, 0x12, 0x12, 0x0a, 0x0e, 0x55, 0x4e, 0x53, 0x54, 0x41, 0x42, 0x4c, 0x45, 0x5f, + 0x42, 0x45, 0x41, 0x4d, 0x53, 0x10, 0x0d, 0x12, 0x15, 0x0a, 0x11, 0x42, 0x45, 0x41, 0x4d, 0x5f, + 0x44, 0x55, 0x4d, 0x50, 0x5f, 0x57, 0x41, 0x52, 0x4e, 0x49, 0x4e, 0x47, 0x10, 0x0e, 0x12, 0x0d, + 0x0a, 0x09, 0x42, 0x45, 0x41, 0x4d, 0x5f, 0x44, 0x55, 0x4d, 0x50, 0x10, 0x0f, 0x12, 0x0d, 0x0a, + 0x09, 0x52, 0x41, 0x4d, 0x50, 0x5f, 0x44, 0x4f, 0x57, 0x4e, 0x10, 0x10, 0x12, 0x0b, 0x0a, 0x07, + 0x43, 0x59, 0x43, 0x4c, 0x49, 0x4e, 0x47, 0x10, 0x11, 0x12, 0x0c, 0x0a, 0x08, 0x52, 0x45, 0x43, + 0x4f, 0x56, 0x45, 0x52, 0x59, 0x10, 0x12, 0x12, 0x13, 0x0a, 0x0f, 0x49, 0x4e, 0x4a, 0x45, 0x43, + 0x54, 0x5f, 0x41, 0x4e, 0x44, 0x5f, 0x44, 0x55, 0x4d, 0x50, 0x10, 0x13, 0x12, 0x16, 0x0a, 0x12, + 0x43, 0x49, 0x52, 0x43, 0x55, 0x4c, 0x41, 0x54, 0x45, 0x5f, 0x41, 0x4e, 0x44, 0x5f, 0x44, 0x55, + 0x4d, 0x50, 0x10, 0x14, 0x12, 0x0b, 0x0a, 0x07, 0x4e, 0x4f, 0x5f, 0x42, 0x45, 0x41, 0x4d, 0x10, + 0x15, 0x42, 0x53, 0x0a, 0x1f, 0x63, 0x68, 0x2e, 0x63, 0x65, 0x72, 0x6e, 0x2e, 0x61, 0x6c, 0x69, + 0x63, 0x65, 0x2e, 0x6f, 0x32, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x63, 0x6f, + 0x6d, 0x6d, 0x6f, 0x6e, 0x5a, 0x30, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x41, 0x6c, 0x69, 0x63, 0x65, 0x4f, 0x32, 0x47, 0x72, 0x6f, 0x75, 0x70, 0x2f, 0x43, 0x6f, + 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x73, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -459,16 +514,17 @@ func file_protos_common_proto_rawDescGZIP() []byte { return file_protos_common_proto_rawDescData } -var file_protos_common_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_protos_common_proto_enumTypes = make([]protoimpl.EnumInfo, 2) var file_protos_common_proto_msgTypes = make([]protoimpl.MessageInfo, 3) var file_protos_common_proto_goTypes = []interface{}{ - (BeamMode)(0), // 0: common.BeamMode - (*User)(nil), // 1: common.User - (*WorkflowTemplateInfo)(nil), // 2: common.WorkflowTemplateInfo - (*BeamInfo)(nil), // 3: common.BeamInfo + (SpecialUserId)(0), // 0: common.SpecialUserId + (BeamMode)(0), // 1: common.BeamMode + (*User)(nil), // 2: common.User + (*WorkflowTemplateInfo)(nil), // 3: common.WorkflowTemplateInfo + (*BeamInfo)(nil), // 4: common.BeamInfo } var file_protos_common_proto_depIdxs = []int32{ - 0, // 0: common.BeamInfo.beamMode:type_name -> common.BeamMode + 1, // 0: common.BeamInfo.beamMode:type_name -> common.BeamMode 1, // [1:1] is the sub-list for method output_type 1, // [1:1] is the sub-list for method input_type 1, // [1:1] is the sub-list for extension type_name @@ -525,7 +581,7 @@ func file_protos_common_proto_init() { File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_protos_common_proto_rawDesc, - NumEnums: 1, + NumEnums: 2, NumMessages: 3, NumExtensions: 0, NumServices: 0, diff --git a/common/protos/common.proto b/common/protos/common.proto index f367be9e4..1942c36e2 100644 --- a/common/protos/common.proto +++ b/common/protos/common.proto @@ -40,6 +40,15 @@ message User { string name = 3; } +// Production and staging BKP recognizes these special user IDs. +// They are used to associate certain actions (e.g. EOR) with certain subsystem +// or AliECS component rather than a human user. +enum SpecialUserId { + INVALID = 0; + LHC = 60; + TIMER = 65; +} + message WorkflowTemplateInfo { string name = 1; string description = 2; diff --git a/common/protos/protoutils.go b/common/protos/protoutils.go index e0a009de5..5d3a43d82 100644 --- a/common/protos/protoutils.go +++ b/common/protos/protoutils.go @@ -34,3 +34,17 @@ func WrapEvent(ce isEvent_Payload) *Event { Payload: ce, } } + +// SpecialUser returns a User populated from a SpecialUserId enum: +// - externalId = enum numeric value +// - id = enum numeric value +// - name = enum string name +func SpecialUser(enumId SpecialUserId) *User { + externalId := int32(enumId) + name := enumId.String() + return &User{ + ExternalId: &externalId, + Id: nil, + Name: name, + } +} diff --git a/core/environment/environment.go b/core/environment/environment.go index f75367461..352a3e05f 100644 --- a/core/environment/environment.go +++ b/core/environment/environment.go @@ -1449,6 +1449,7 @@ func (env *Environment) scheduleAutoStopTransition() (scheduled bool, expected t log.WithField("partition", env.id). WithField("run", env.currentRunNumber). Infof("Executing scheduled auto stop transition following expiration of %s", autoStopDuration) + env.SetLastRequestUser(pb.SpecialUser(pb.SpecialUserId_TIMER)) err = env.TryTransition(NewStopActivityTransition(ManagerInstance().taskman)) if err != nil { log.WithField("partition", env.id). diff --git a/core/environment/manager.go b/core/environment/manager.go index 5c732607e..571db94c6 100644 --- a/core/environment/manager.go +++ b/core/environment/manager.go @@ -1103,6 +1103,7 @@ func (envs *Manager) handleLhcEvents(evt event.IntegratedServiceEvent) { WithField("run", env.currentRunNumber). Info("stopping the run due to beam dump") + env.SetLastRequestUser(evpb.SpecialUser(evpb.SpecialUserId_LHC)) err := env.TryTransition(NewStopActivityTransition(envs.taskman)) if err != nil { log.WithPrefix("scheduler").