This repository has been archived by the owner on May 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathworkflow_fetcher.go
70 lines (63 loc) · 2.42 KB
/
workflow_fetcher.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
package ext
import (
"context"
"fmt"
"github.com/flyteorg/flytectl/pkg/filters"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
)
// FetchAllVerOfWorkflow fetches all the versions for give workflow name
func (a *AdminFetcherExtClient) FetchAllVerOfWorkflow(ctx context.Context, workflowName, project, domain string, filter filters.Filters) ([]*admin.Workflow, error) {
tranformFilters, err := filters.BuildResourceListRequestWithName(filter, project, domain, workflowName)
if err != nil {
return nil, err
}
wList, err := a.AdminServiceClient().ListWorkflows(ctx, tranformFilters)
if err != nil {
return nil, err
}
if len(wList.Workflows) == 0 {
return nil, fmt.Errorf("no workflow retrieved for %v", workflowName)
}
return wList.Workflows, nil
}
// FetchAllWorkflows fetches all workflows in project domain
func (a *AdminFetcherExtClient) FetchAllWorkflows(ctx context.Context, project, domain string, filter filters.Filters) ([]*admin.NamedEntity, error) {
tranformFilters, err := filters.BuildNamedEntityListRequest(filter, project, domain, core.ResourceType_WORKFLOW)
if err != nil {
return nil, err
}
wList, err := a.AdminServiceClient().ListNamedEntities(ctx, tranformFilters)
if err != nil {
return nil, err
}
if len(wList.Entities) == 0 {
return nil, fmt.Errorf("no workflow retrieved for %v project %v domain", project, domain)
}
return wList.Entities, nil
}
// FetchWorkflowLatestVersion fetches latest version for given workflow name
func (a *AdminFetcherExtClient) FetchWorkflowLatestVersion(ctx context.Context, name, project, domain string, filter filters.Filters) (*admin.Workflow, error) {
// Fetch the latest version of the workflow.
wVersions, err := a.FetchAllVerOfWorkflow(ctx, name, project, domain, filter)
if err != nil {
return nil, err
}
return a.FetchWorkflowVersion(ctx, name, wVersions[0].Id.Version, project, domain)
}
// FetchWorkflowVersion fetches particular version of workflow
func (a *AdminFetcherExtClient) FetchWorkflowVersion(ctx context.Context, name, version, project, domain string) (*admin.Workflow, error) {
lp, err := a.AdminServiceClient().GetWorkflow(ctx, &admin.ObjectGetRequest{
Id: &core.Identifier{
ResourceType: core.ResourceType_WORKFLOW,
Project: project,
Domain: domain,
Name: name,
Version: version,
},
})
if err != nil {
return nil, err
}
return lp, nil
}