Skip to content

Commit

Permalink
middle of debugging create db
Browse files Browse the repository at this point in the history
Signed-off-by: Yee Hing Tong <[email protected]>
  • Loading branch information
wild-endeavor committed Oct 13, 2023
1 parent c69cc81 commit 72d9c47
Show file tree
Hide file tree
Showing 19 changed files with 374 additions and 181 deletions.
5 changes: 4 additions & 1 deletion flyteartifacts/artifact_config.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
artifactsServer:
myTestValue: "test from file"
myTestValue: "test from file"
database:
postgres:
dbname: artifacts
4 changes: 2 additions & 2 deletions flyteartifacts/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ func main() {
ctx := context.Background()
logger.Infof(ctx, "Beginning Flyte Artifacts Service")
rootCmd := sharedCmd.NewRootCmd("artifacts", server.GrpcRegistrationHook, server.HttpRegistrationHook)

rootCmd.AddCommand(sharedCmd.NewMigrateCmd(migrations))
migs := server.GetMigrations(ctx)
rootCmd.AddCommand(sharedCmd.NewMigrateCmd(migs))
err := rootCmd.ExecuteContext(ctx)
if err != nil {
panic(err)
Expand Down
8 changes: 4 additions & 4 deletions flyteartifacts/cmd/shared/migrate.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package shared

import (
stdlibLogger "github.com/flyteorg/flyte/flytestdlib/logger"
"context"
"github.com/flyteorg/flyte/flytestdlib/database"
"github.com/go-gormigrate/gormigrate/v2"
"github.com/flyteorg/flyte/flytestdlib/promutils"
"github.com/spf13/cobra"
)
\

// NewMigrateCmd represents the migrate command
func NewMigrateCmd(migs []*gormigrate.Migration) *cobra.Command {
return &cobra.Command{
Use: "migrate",
Short: "This command will run all the migrations for the database",
RunE: func(cmd *cobra.Command, args []string) error {
return migrions.Migrate(confi.GetDBConfig(), stdlibLogger.GetConfig(), promutils.NewScope("dbmigrate"), migrs)
return database.Migrate(context.Background(), migs)
},
}
}
22 changes: 17 additions & 5 deletions flyteartifacts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/jinzhu/gorm v1.9.16
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.1
github.com/spf13/cobra v1.4.0
github.com/spf13/pflag v1.0.5
google.golang.org/grpc v1.56.1
gorm.io/gorm v1.25.4
gorm.io/gorm v1.25.5
)

require (
Expand Down Expand Up @@ -52,18 +54,26 @@ require (
github.com/googleapis/gax-go/v2 v2.7.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.14.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.2 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.4.3 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/lib/pq v1.2.0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-sqlite3 v1.14.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/ncw/swift v1.0.53 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pelletier/go-toml/v2 v2.0.0-beta.8 // indirect
github.com/prometheus/client_golang v1.12.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
Expand All @@ -74,10 +84,10 @@ require (
github.com/spf13/viper v1.11.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/crypto v0.0.0-20221005025214-4161e89ecf1b // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/time v0.1.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
Expand All @@ -88,6 +98,8 @@ require (
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/postgres v1.5.3 // indirect
gorm.io/driver/sqlite v1.5.4 // indirect
k8s.io/apimachinery v0.20.2 // indirect
k8s.io/client-go v0.0.0-20210217172142-7279fc64d847 // indirect
k8s.io/klog/v2 v2.5.0 // indirect
Expand Down
134 changes: 124 additions & 10 deletions flyteartifacts/go.sum

Large diffs are not rendered by default.

31 changes: 2 additions & 29 deletions flyteartifacts/pkg/configuration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,10 @@ import (

const artifactsServer = "artifactsServer"

type PostgresConfig struct {
Host string `json:"host" pflag:",The host name of the database server"`
Port int `json:"port" pflag:",The port name of the database server"`
DbName string `json:"dbname" pflag:",The database name"`
User string `json:"username" pflag:",The database user who is connecting to the server."`
// Either Password or PasswordPath must be set.
Password string `json:"password" pflag:",The database password."`
PasswordPath string `json:"passwordPath" pflag:",Points to the file containing the database password."`
ExtraOptions string `json:"options" pflag:",See http://gorm.io/docs/connecting_to_the_database.html for available options passed, in addition to the above."`
Debug bool `json:"debug" pflag:" Whether or not to start the database connection with debug mode enabled."`
}

type DbConfig struct {
Postgres PostgresConfig `json:"postgres" pflag:",Postgres database configuration"`
}

type ApplicationConfiguration struct {
Database DbConfig `json:"database" pflag:",Database configuration"`
MyTestVal string `json:"myTestValue" pflag:",Database configuration"`
}

var defaultApplicationConfiguration = ApplicationConfiguration{
Database: DbConfig{
Postgres: PostgresConfig{
// These values are suitable for local sandbox development
Host: "localhost",
Port: 30001,
DbName: "artifacts",
User: "postgres",
Password: "postgres",
},
},
}
var defaultApplicationConfiguration = ApplicationConfiguration{}

var ApplicationConfig = config.MustRegisterSection(artifactsServer, &defaultApplicationConfiguration)
28 changes: 0 additions & 28 deletions flyteartifacts/pkg/db/migrator.go

This file was deleted.

24 changes: 0 additions & 24 deletions flyteartifacts/pkg/migrations.go

This file was deleted.

27 changes: 1 addition & 26 deletions flyteartifacts/pkg/server/interfaces.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,4 @@
package server

import (
"context"
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/artifact"
)

type ArtifactHandler interface {
CreateArtifact(ctx context.Context, request *artifact.CreateArtifactRequest) (*artifact.CreateArtifactResponse, error)
GetArtifact(ctx context.Context, request *artifact.GetArtifactRequest) (*artifact.GetArtifactResponse, error)
}

type TriggerHandler interface {
CreateTrigger(ctx context.Context, request *artifact.CreateTriggerRequest) (*artifact.CreateTriggerResponse, error)
DeleteTrigger(ctx context.Context, request *artifact.DeleteTriggerRequest) (*artifact.DeleteTriggerResponse, error)
}

type TagHandler interface {
AddTag(ctx context.Context, request *artifact.AddTagRequest) (*artifact.AddTagResponse, error)
}

type LineageHandler interface {
RegisterProducer(ctx context.Context, request *artifact.RegisterProducerRequest) (*artifact.RegisterResponse, error)
RegisterConsumer(ctx context.Context, request *artifact.RegisterConsumerRequest) (*artifact.RegisterResponse, error)
}

type SearchHandler interface {
SearchArtifacts(ctx context.Context, request *artifact.SearchArtifactsRequest) (*artifact.SearchArtifactsResponse, error)
type StorageInterface interface {
}
59 changes: 59 additions & 0 deletions flyteartifacts/pkg/server/migrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package server

import (
"github.com/go-gormigrate/gormigrate/v2"
"github.com/jinzhu/gorm/dialects/postgres"

"gorm.io/gorm"
)

var Migrations = []*gormigrate.Migration{
{
ID: "2023-10-12-inits",
Migrate: func(tx *gorm.DB) error {
type ArtifactsKey struct {
gorm.Model
Project string `gorm:"primary_key;type:varchar(64)"`
Domain string `gorm:"primary_key;type:varchar(64)"`
Name string `gorm:"primary_key;type:varchar(255)"`
}
type Artifact struct {
gorm.Model
ArtifactsKey
Version string `gorm:"type:varchar(255);index:idx_artifact_version"`
Partitions postgres.Hstore `gorm:"index:idx_artifact_partitions"`

LiteralType []byte `gorm:"not null"`
LiteralValue []byte `gorm:"not null"`

Description string `gorm:"type:varchar(255)"`
OffloadedLongDescription string `gorm:"type:varchar(255)"`
MetadataType string `gorm:"type:varchar(64)"`
OffloadedUserMetadata string `gorm:"type:varchar(255)"`

// Project/Domain assumed to always be the same as the Artifact
ExecutionName string `gorm:"type:varchar(255)"`
WorkflowProject string `gorm:"type:varchar(64)"`
WorkflowDomain string `gorm:"type:varchar(64)"`
WorkflowName string `gorm:"type:varchar(255)"`
WorkflowVersion string `gorm:"type:varchar(255)"`
TaskProject string `gorm:"type:varchar(64)"`
TaskDomain string `gorm:"type:varchar(64)"`
TaskName string `gorm:"type:varchar(255)"`
TaskVersion string `gorm:"type:varchar(255)"`
NodeID string `gorm:"type:varchar(64)"`
// See Admin migration for note.
// Here nullable in the case of workflow output.
RetryAttempt *uint32
}
return tx.AutoMigrate(
&ArtifactsKey{}, &Artifact{},
)
},
Rollback: func(tx *gorm.DB) error {
return tx.Migrator().DropTable(
"markers",
)
},
},
}
43 changes: 8 additions & 35 deletions flyteartifacts/pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/flyteorg/flyte/flyteartifacts/pkg/configuration"
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/artifact"
"github.com/flyteorg/flyte/flytestdlib/promutils"
"github.com/go-gormigrate/gormigrate/v2"
"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/pkg/errors"
"google.golang.org/grpc"
Expand All @@ -15,11 +16,9 @@ import (

type ArtifactService struct {
artifact.UnimplementedArtifactRegistryServer
ArtifactProvider ArtifactHandler
TriggerProvider TriggerHandler
TagProvider TagHandler
LineageProvider LineageHandler
Metrics ServiceMetrics
StorageProvider StorageInterface
Metrics ServiceMetrics
Service CoreService
}

func NewArtifactService(scope promutils.Scope) *ArtifactService {
Expand All @@ -28,6 +27,7 @@ func NewArtifactService(scope promutils.Scope) *ArtifactService {

return &ArtifactService{
Metrics: InitMetrics(scope),
Service: CoreService{},
}
}

Expand All @@ -46,34 +46,7 @@ func GrpcRegistrationHook(ctx context.Context, server *grpc.Server, scope promut
return nil
}

func (a *ArtifactService) CreateArtifact(ctx context.Context, request *artifact.CreateArtifactRequest) (*artifact.CreateArtifactResponse, error) {
return &artifact.CreateArtifactResponse{}, nil
}

func (a *ArtifactService) GetArtifact(ctx context.Context, request *artifact.GetArtifactRequest) (*artifact.GetArtifactResponse, error) {
return &artifact.GetArtifactResponse{}, nil
}

func (a *ArtifactService) CreateTrigger(ctx context.Context, request *artifact.CreateTriggerRequest) (*artifact.CreateTriggerResponse, error) {
return &artifact.CreateTriggerResponse{}, nil
}

func (a *ArtifactService) DeleteTrigger(ctx context.Context, request *artifact.DeleteTriggerRequest) (*artifact.DeleteTriggerResponse, error) {
return &artifact.DeleteTriggerResponse{}, nil
}

func (a *ArtifactService) AddTag(ctx context.Context, request *artifact.AddTagRequest) (*artifact.AddTagResponse, error) {
return &artifact.AddTagResponse{}, nil
}

func (a *ArtifactService) RegisterProducer(ctx context.Context, request *artifact.RegisterProducerRequest) (*artifact.RegisterResponse, error) {
return &artifact.RegisterResponse{}, nil
}

func (a *ArtifactService) RegisterConsumer(ctx context.Context, request *artifact.RegisterConsumerRequest) (*artifact.RegisterResponse, error) {
return &artifact.RegisterResponse{}, nil
}

func (a *ArtifactService) SearchArtifacts(ctx context.Context, request *artifact.SearchArtifactsRequest) (*artifact.SearchArtifactsResponse, error) {
return &artifact.SearchArtifactsResponse{}, nil
// GetMigrations should be hidden behind the storage interface in the future.
func GetMigrations(ctx context.Context) []*gormigrate.Migration {
return Migrations
}
Loading

0 comments on commit 72d9c47

Please sign in to comment.