-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Yee Hing Tong <[email protected]>
- Loading branch information
1 parent
5c659aa
commit 729b300
Showing
23 changed files
with
767 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
artifactsServer: | ||
myTestValue: "test from file" | ||
database: | ||
postgres: | ||
dbname: artifacts | ||
logger: | ||
level: 5 | ||
show-source: true | ||
# This is an (incomplete) configure file for the artifact service, here just as an example. | ||
#artifactsServer: | ||
# database: | ||
# postgres: | ||
# dbname: your pg db | ||
#logger: | ||
# level: 5 | ||
# show-source: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package blob | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/flyteorg/flyte/flyteartifacts/pkg/configuration" | ||
"github.com/flyteorg/flyte/flytestdlib/logger" | ||
"github.com/flyteorg/flyte/flytestdlib/promutils" | ||
"github.com/flyteorg/flyte/flytestdlib/storage" | ||
"github.com/golang/protobuf/ptypes/any" | ||
) | ||
|
||
type ArtifactBlobStore struct { | ||
store *storage.DataStore | ||
} | ||
|
||
// OffloadArtifactCard stores the artifact card in the blob store | ||
func (a *ArtifactBlobStore) OffloadArtifactCard(ctx context.Context, name, version string, card *any.Any) (storage.DataReference, error) { | ||
uri, err := a.store.ConstructReference(ctx, a.store.GetBaseContainerFQN(ctx), name, version) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to construct data reference for [%s/%s] with err: %v", name, version, err) | ||
} | ||
err = a.store.WriteProtobuf(ctx, uri, storage.Options{}, card) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to write protobuf to %s with err: %v", uri, err) | ||
} | ||
return uri, nil | ||
} | ||
|
||
func (a *ArtifactBlobStore) RetrieveArtifactCard(ctx context.Context, uri storage.DataReference) (*any.Any, error) { | ||
card := &any.Any{} | ||
err := a.store.ReadProtobuf(ctx, uri, card) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read protobuf from %s with err: %v", uri, err) | ||
} | ||
return nil, nil | ||
} | ||
|
||
func NewArtifactBlobStore(ctx context.Context, scope promutils.Scope) ArtifactBlobStore { | ||
storageCfg := configuration.ApplicationConfig.GetConfig().(*configuration.ApplicationConfiguration).ArtifactBlobStoreConfig | ||
logger.Infof(ctx, "Initializing storage client with config [%+v]", storageCfg) | ||
|
||
dataStorageClient, err := storage.NewDataStore(&storageCfg, scope) | ||
if err != nil { | ||
logger.Error(ctx, "Failed to initialize storage config") | ||
panic(err) | ||
} | ||
return ArtifactBlobStore{ | ||
store: dataStorageClient, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package db | ||
|
||
import ( | ||
"context" | ||
"github.com/flyteorg/flyte/flyteartifacts/pkg/models" | ||
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/artifact" | ||
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/core" | ||
"github.com/flyteorg/flyte/flytestdlib/logger" | ||
"github.com/golang/protobuf/proto" | ||
"github.com/jackc/pgx/v5/pgtype" | ||
) | ||
|
||
func PartitionsIdlToHstore(idlPartitions *core.Partitions) pgtype.Hstore { | ||
ctx := context.Background() | ||
if idlPartitions == nil || idlPartitions.GetValue() == nil { | ||
return nil | ||
} | ||
var hstore = make(pgtype.Hstore) | ||
|
||
for k, v := range idlPartitions.GetValue() { | ||
if len(v.GetStaticValue()) == 0 { | ||
logger.Warningf(ctx, "Partition key [%s] missing static value, [%+v]", k, v.GetValue()) | ||
continue | ||
} | ||
sv := v.GetStaticValue() | ||
hstore[k] = &sv | ||
} | ||
return hstore | ||
} | ||
|
||
func HstoreToIdlPartitions(hs pgtype.Hstore) *core.Partitions { | ||
if hs == nil || len(hs) == 0 { | ||
return nil | ||
} | ||
m := make(map[string]*core.LabelValue, len(hs)) | ||
for k, v := range hs { | ||
m[k] = &core.LabelValue{ | ||
Value: &core.LabelValue_StaticValue{ | ||
StaticValue: *v, | ||
}, | ||
} | ||
} | ||
return &core.Partitions{ | ||
Value: m, | ||
} | ||
} | ||
|
||
func ServiceToGormModel(serviceModel models.Artifact) (Artifact, error) { | ||
partitions := PartitionsIdlToHstore(serviceModel.Artifact.GetArtifactId().GetPartitions()) | ||
|
||
ga := Artifact{ | ||
ArtifactKey: ArtifactKey{ | ||
Project: serviceModel.Artifact.ArtifactId.ArtifactKey.Project, | ||
Domain: serviceModel.Artifact.ArtifactId.ArtifactKey.Domain, | ||
Name: serviceModel.Artifact.ArtifactId.ArtifactKey.Name, | ||
}, | ||
Version: serviceModel.Artifact.ArtifactId.Version, | ||
Partitions: partitions, | ||
|
||
LiteralType: serviceModel.LiteralTypeBytes, | ||
LiteralValue: serviceModel.LiteralValueBytes, | ||
Description: serviceModel.Artifact.Spec.ShortDescription, | ||
MetadataType: serviceModel.Artifact.Spec.MetadataType, | ||
OffloadedUserMetadata: serviceModel.OffloadedMetadata, | ||
|
||
ExecutionName: serviceModel.Artifact.Spec.Execution.Name, | ||
} | ||
|
||
if serviceModel.Artifact.Spec.TaskExecution != nil { | ||
ga.TaskProject = serviceModel.Artifact.Spec.TaskExecution.TaskId.Project | ||
ga.TaskDomain = serviceModel.Artifact.Spec.TaskExecution.TaskId.Domain | ||
ga.TaskName = serviceModel.Artifact.Spec.TaskExecution.TaskId.Name | ||
ga.TaskVersion = serviceModel.Artifact.Spec.TaskExecution.TaskId.Version | ||
ga.RetryAttempt = &serviceModel.Artifact.Spec.TaskExecution.RetryAttempt | ||
} | ||
|
||
return ga, nil | ||
} | ||
|
||
func GormToServiceModel(ga Artifact) (models.Artifact, error) { | ||
lt := &core.LiteralType{} | ||
lit := &core.Literal{} | ||
if err := proto.Unmarshal(ga.LiteralType, lt); err != nil { | ||
return models.Artifact{}, err | ||
} | ||
if err := proto.Unmarshal(ga.LiteralValue, lit); err != nil { | ||
return models.Artifact{}, err | ||
} | ||
|
||
// gatepr: principal is missing still - can be added following discussion on source object. | ||
// taskexecution and additional source information to be added when resolved. | ||
// gatepr: implement tags | ||
a := artifact.Artifact{ | ||
ArtifactId: &core.ArtifactID{ | ||
ArtifactKey: &core.ArtifactKey{ | ||
Project: ga.ArtifactKey.Project, | ||
Domain: ga.ArtifactKey.Domain, | ||
Name: ga.ArtifactKey.Name, | ||
}, | ||
Version: ga.Version, | ||
}, | ||
Spec: &artifact.ArtifactSpec{ | ||
Value: lit, | ||
Type: lt, | ||
TaskExecution: nil, | ||
Execution: &core.WorkflowExecutionIdentifier{ | ||
Project: ga.ArtifactKey.Project, | ||
Domain: ga.ArtifactKey.Domain, | ||
Name: ga.ExecutionName, | ||
}, | ||
Principal: "", | ||
ShortDescription: ga.Description, | ||
UserMetadata: nil, | ||
MetadataType: ga.MetadataType, | ||
}, | ||
Tags: nil, | ||
} | ||
p := HstoreToIdlPartitions(ga.Partitions) | ||
if p != nil { | ||
a.ArtifactId.Dimensions = &core.ArtifactID_Partitions{Partitions: p} | ||
} | ||
|
||
return models.Artifact{ | ||
Artifact: a, | ||
OffloadedMetadata: "", | ||
LiteralTypeBytes: nil, | ||
LiteralValueBytes: nil, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.