This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
/
resourcemanager.go
61 lines (48 loc) · 1.95 KB
/
resourcemanager.go
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
package resourcemanager
import (
"context"
"sync"
pluginCore "github.com/lyft/flyteplugins/go/tasks/pluginmachinery/core"
"github.com/lyft/flytestdlib/promutils"
)
//go:generate mockery -name ResourceManager -case=underscore
// This struct is designed to serve as the identifier of an user of resource manager
type Resource struct {
quota int
metrics Metrics
rejectedTokens sync.Map
}
type Metrics interface {
GetScope() promutils.Scope
}
type Builder interface {
ResourceRegistrar(namespacePrefix pluginCore.ResourceNamespace) pluginCore.ResourceRegistrar
BuildResourceManager(ctx context.Context) (pluginCore.ResourceManager, error)
}
type Proxy struct {
pluginCore.ResourceManager
NamespacePrefix pluginCore.ResourceNamespace
}
func (p Proxy) getPrefixedNamespace(namespace pluginCore.ResourceNamespace) pluginCore.ResourceNamespace {
return p.NamespacePrefix.CreateSubNamespace(namespace)
}
func (p Proxy) AllocateResource(ctx context.Context, namespace pluginCore.ResourceNamespace,
allocationToken string) (pluginCore.AllocationStatus, error) {
status, err := p.ResourceManager.AllocateResource(ctx, p.getPrefixedNamespace(namespace), allocationToken)
return status, err
}
func (p Proxy) ReleaseResource(ctx context.Context, namespace pluginCore.ResourceNamespace,
allocationToken string) error {
err := p.ResourceManager.ReleaseResource(ctx, p.getPrefixedNamespace(namespace), allocationToken)
return err
}
type ResourceRegistrarProxy struct {
pluginCore.ResourceRegistrar
NamespacePrefix pluginCore.ResourceNamespace
}
func (p ResourceRegistrarProxy) getPrefixedNamespace(namespace pluginCore.ResourceNamespace) pluginCore.ResourceNamespace {
return p.NamespacePrefix.CreateSubNamespace(namespace)
}
func (p ResourceRegistrarProxy) RegisterResourceQuota(ctx context.Context, namespace pluginCore.ResourceNamespace, quota int) error {
return p.ResourceRegistrar.RegisterResourceQuota(ctx, p.getPrefixedNamespace(namespace), quota)
}