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
/
digests.go
51 lines (43 loc) · 1.85 KB
/
digests.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
package util
import (
"context"
"github.com/flyteorg/flyteadmin/pkg/errors"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core"
"github.com/flyteorg/flytestdlib/logger"
"github.com/flyteorg/flytestdlib/pbhash"
"google.golang.org/grpc/codes"
)
// Returns a unique digest for functionally equivalent launch plans
func GetLaunchPlanDigest(ctx context.Context, launchPlan *admin.LaunchPlan) ([]byte, error) {
launchPlanDigest, err := pbhash.ComputeHash(ctx, launchPlan)
if err != nil {
logger.Warningf(ctx, "failed to hash launch plan [%+v] to digest with err %v",
launchPlan.Id, err)
return nil, errors.NewFlyteAdminErrorf(codes.Internal,
"failed to hash launch plan [%+v] to digest with err %v", launchPlan.Id, err)
}
return launchPlanDigest, nil
}
// Returns a unique digest for functionally equivalent compiled tasks
func GetTaskDigest(ctx context.Context, task *core.CompiledTask) ([]byte, error) {
taskDigest, err := pbhash.ComputeHash(ctx, task)
if err != nil {
logger.Warningf(ctx, "failed to hash task [%+v] to digest with err %v",
task.Template.Id, err)
return nil, errors.NewFlyteAdminErrorf(codes.Internal,
"failed to hash task [%+v] to digest with err %v", task.Template.Id, err)
}
return taskDigest, nil
}
// Returns a unique digest for functionally equivalent compiled workflows
func GetWorkflowDigest(ctx context.Context, workflowClosure *core.CompiledWorkflowClosure) ([]byte, error) {
workflowDigest, err := pbhash.ComputeHash(ctx, workflowClosure)
if err != nil {
logger.Warningf(ctx, "failed to hash workflow [%+v] to digest with err %v",
workflowClosure.Primary.Template.Id, err)
return nil, errors.NewFlyteAdminErrorf(codes.Internal,
"failed to hash workflow [%+v] to digest with err %v", workflowClosure.Primary.Template.Id, err)
}
return workflowDigest, nil
}