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 63
/
db_admin_data_provider.go
73 lines (66 loc) · 2.64 KB
/
db_admin_data_provider.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
62
63
64
65
66
67
68
69
70
71
72
73
package impl
import (
"context"
"github.com/flyteorg/flyteadmin/pkg/clusterresource/interfaces"
"github.com/flyteorg/flyteadmin/pkg/common"
managerInterfaces "github.com/flyteorg/flyteadmin/pkg/manager/interfaces"
repositoryInterfaces "github.com/flyteorg/flyteadmin/pkg/repositories/interfaces"
"github.com/flyteorg/flyteadmin/pkg/repositories/transformers"
runtimeInterfaces "github.com/flyteorg/flyteadmin/pkg/runtime/interfaces"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
)
// Implementation of an interfaces.FlyteAdminDataProvider which fetches data directly from the provided database connection.
type dbAdminProvider struct {
db repositoryInterfaces.Repository
config runtimeInterfaces.Configuration
resourceManager managerInterfaces.ResourceInterface
}
func (p dbAdminProvider) GetClusterResourceAttributes(ctx context.Context, project, domain string) (*admin.ClusterResourceAttributes, error) {
resource, err := p.resourceManager.GetResource(ctx, managerInterfaces.ResourceRequest{
Project: project,
Domain: domain,
ResourceType: admin.MatchableResource_CLUSTER_RESOURCE,
})
if err != nil {
return nil, err
}
if resource != nil && resource.Attributes != nil && resource.Attributes.GetClusterResourceAttributes() != nil {
return resource.Attributes.GetClusterResourceAttributes(), nil
}
return nil, NewMissingEntityError("cluster resource attributes")
}
func (p dbAdminProvider) getDomains() []*admin.Domain {
configDomains := p.config.ApplicationConfiguration().GetDomainsConfig()
var domains = make([]*admin.Domain, len(*configDomains))
for index, configDomain := range *configDomains {
domains[index] = &admin.Domain{
Id: configDomain.ID,
Name: configDomain.Name,
}
}
return domains
}
func (p dbAdminProvider) GetProjects(ctx context.Context) (*admin.Projects, error) {
filter, err := common.NewSingleValueFilter(common.Project, common.NotEqual, "state", int32(admin.Project_ARCHIVED))
if err != nil {
return nil, err
}
projectModels, err := p.db.ProjectRepo().List(ctx, repositoryInterfaces.ListResourceInput{
SortParameter: descCreatedAtSortDBParam,
InlineFilters: []common.InlineFilter{filter},
})
if err != nil {
return nil, err
}
projects := transformers.FromProjectModels(projectModels, p.getDomains())
return &admin.Projects{
Projects: projects,
}, nil
}
func NewDatabaseAdminDataProvider(db repositoryInterfaces.Repository, config runtimeInterfaces.Configuration, resourceManager managerInterfaces.ResourceInterface) interfaces.FlyteAdminDataProvider {
return &dbAdminProvider{
db: db,
config: config,
resourceManager: resourceManager,
}
}