-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmessages.go
More file actions
96 lines (85 loc) · 3.21 KB
/
messages.go
File metadata and controls
96 lines (85 loc) · 3.21 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
// Copyright SAP SE
// SPDX-License-Identifier: Apache-2.0
package api
import (
"log/slog"
"github.com/cobaltcore-dev/cortex/internal/scheduling/lib"
)
// Host object from the Cinder scheduler pipeline.
type ExternalSchedulerHost struct {
// Name of the Cinder share host.
VolumeHost string `json:"host"`
}
// Request generated by the Cinder scheduler when calling cortex.
// The request contains a spec of the share to be scheduled, a list of hosts and
// their status, and a map of weights that were calculated by the Cinder weigher
// pipeline. Some additional flags are also included.
type ExternalSchedulerRequest struct {
// TODO: Use a more specific type for the spec.
Spec any `json:"spec"`
// Request context from Cinder that contains additional meta information.
Context CinderRequestContext `json:"context"`
// The share hosts that are available for scheduling.
Hosts []ExternalSchedulerHost `json:"hosts"`
// Weights map of share hosts to their weights calculated by the Cinder weigher pipeline.
Weights map[string]float64 `json:"weights"`
// The name of the pipeline to execute.
Pipeline string `json:"pipeline"`
}
func (r ExternalSchedulerRequest) GetSubjects() []string {
hosts := make([]string, len(r.Hosts))
for i, host := range r.Hosts {
hosts[i] = host.VolumeHost
}
return hosts
}
func (r ExternalSchedulerRequest) GetWeights() map[string]float64 {
return r.Weights
}
func (r ExternalSchedulerRequest) GetTraceLogArgs() []slog.Attr {
return []slog.Attr{
slog.String("greq", r.Context.GlobalRequestID),
slog.String("req", r.Context.RequestID),
slog.String("user", r.Context.UserID),
slog.String("project", r.Context.ProjectID),
}
}
func (r ExternalSchedulerRequest) FilterSubjects(includedSubjects map[string]float64) lib.FilterWeigherPipelineRequest {
filteredHosts := make([]ExternalSchedulerHost, 0, len(includedSubjects))
for _, host := range r.Hosts {
if _, exists := includedSubjects[host.VolumeHost]; exists {
filteredHosts = append(filteredHosts, host)
}
}
r.Hosts = filteredHosts
return r
}
// Response generated by cortex for the Cinder scheduler.
// Cortex returns an ordered list of hosts that the share should be scheduled on.
type ExternalSchedulerResponse struct {
Hosts []string `json:"hosts"`
}
// TODO add specs
type CinderRequestContext struct {
// Fields added by oslo.context
UserID string `json:"user"`
ProjectID string `json:"project_id"`
SystemScope string `json:"system_scope"`
DomainID string `json:"domain"`
UserDomainID string `json:"user_domain"`
ProjectDomainID string `json:"project_domain"`
IsAdmin bool `json:"is_admin"`
ReadOnly bool `json:"read_only"`
ShowDeleted bool `json:"show_deleted"`
RequestID string `json:"request_id"`
GlobalRequestID string `json:"global_request_id"`
ResourceUUID string `json:"resource_uuid"`
Roles []string `json:"roles"`
UserIdentity string `json:"user_identity"`
IsAdminProject bool `json:"is_admin_project"`
// Fields added by the Cinder scheduler
RemoteAddress string `json:"remote_address"`
Timestamp string `json:"timestamp"`
QuotaClass *string `json:"quota_class"`
ProjectName string `json:"project_name"`
}