-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdependencies.go
More file actions
130 lines (114 loc) · 3.77 KB
/
dependencies.go
File metadata and controls
130 lines (114 loc) · 3.77 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
/*___INFO__MARK_BEGIN__*/
/*************************************************************************
* Copyright 2025 HPC-Gridware GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************/
/*___INFO__MARK_END__*/
package main
import (
"fmt"
qconf "github.com/hpc-gridware/go-clusterscheduler/pkg/qconf/v9.0"
)
// cleanupInvalidPEReferences removes references to parallel environments
// from queues when those PEs are not defined in the configuration.
// This prevents errors when comparing configurations.
func cleanupInvalidPEReferences(config *qconf.ClusterConfig) {
// Build a set of valid PE names
validPEs := make(map[string]bool)
for peName := range config.ParallelEnvironments {
validPEs[peName] = true
}
// Check each queue and remove invalid PE references
for queueName, queue := range config.ClusterQueues {
if len(queue.PeList) == 0 {
continue
}
// Filter out invalid PE names
validPEList := make([]string, 0)
for _, peRef := range queue.PeList {
// PE references can be in format "pename" or "[host=pename]"
// Extract the PE name
peName := peRef
if len(peRef) > 0 && peRef[0] == '[' {
// Skip host-specific PE references as they're harder to parse
// and we're being conservative here
continue
}
// Only keep if PE is defined
if validPEs[peName] {
validPEList = append(validPEList, peRef)
} else {
fmt.Printf("Warning: Removing reference to undefined PE '%s' from queue '%s'\n",
peName, queueName)
}
}
// Update the queue's PE list
if len(validPEList) == 0 {
queue.PeList = nil
} else {
queue.PeList = validPEList
}
config.ClusterQueues[queueName] = queue
}
}
// removeQueuePEReferences modifies queues in the cluster to remove references
// to parallel environments that are about to be deleted.
func removeQueuePEReferences(cs *qconf.CommandLineQConf, currentConfig qconf.ClusterConfig,
pesToDelete map[string]qconf.ParallelEnvironmentConfig) error {
// Build a set of PE names to delete
peNamesToDelete := make(map[string]bool)
for peName := range pesToDelete {
peNamesToDelete[peName] = true
}
// Check each queue in the current configuration
for queueName, queue := range currentConfig.ClusterQueues {
if len(queue.PeList) == 0 {
continue
}
modified := false
newPEList := make([]string, 0)
for _, peRef := range queue.PeList {
// PE references can be in format "pename" or "[host=pename]"
peName := peRef
if len(peRef) > 0 && peRef[0] == '[' {
// For host-specific references, skip for simplicity
// Most configs won't use this
newPEList = append(newPEList, peRef)
continue
}
// Keep PE reference only if it's not being deleted
if !peNamesToDelete[peName] {
newPEList = append(newPEList, peRef)
} else {
fmt.Printf("Removing PE reference '%s' from queue '%s' before deletion\n",
peName, queueName)
modified = true
}
}
// If we modified the queue, update it in the cluster
if modified {
queue.PeList = newPEList
if len(newPEList) == 0 {
queue.PeList = nil
}
err := cs.ModifyClusterQueue(queueName, queue)
if err != nil {
return fmt.Errorf("failed to modify queue %s to remove PE references: %w",
queueName, err)
}
}
}
return nil
}