store

package
v0.0.0-...-123cd0f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DeleteRecordTableNameEnvKey = "DELETE_RECORD_DYNAMODB_TABLE_NAME"
)

Variables

This section is empty.

Functions

func GetTestAWSConfig

func GetTestAWSConfig(t *testing.T, mockSqsUrl string) aws.Config

func NewTestPackageNodeId

func NewTestPackageNodeId(pt packageType.Type) string

func RandPackageState

func RandPackageState() packageState.State

func RandPackageType

func RandPackageType() packageType.Type

func RandString

func RandString(n int) string

Types

type AWSError

type AWSError struct {
	Code      string
	Message   string
	Bucket    string
	Key       string
	VersionId string
}

func NewAWSError

func NewAWSError(bucket string, e types.Error) AWSError

func (*AWSError) Error

func (e *AWSError) Error() string

type DeleteObjectsVersionResponse

type DeleteObjectsVersionResponse struct {
	Deleted   []DeletedPackage
	AWSErrors []AWSError
}

type DeletedPackage

type DeletedPackage struct {
	NodeId       string
	DeleteMarker bool
}

type DynamoDBFixture

type DynamoDBFixture struct {
	Fixture
	Client *dynamodb.Client
	// Tables is a set of table names
	Tables map[string]bool
}

func NewDynamoDBFixture

func NewDynamoDBFixture(t *testing.T, client *dynamodb.Client, inputs ...*dynamodb.CreateTableInput) *DynamoDBFixture

func (*DynamoDBFixture) Teardown

func (f *DynamoDBFixture) Teardown()

func (*DynamoDBFixture) WithItems

func (f *DynamoDBFixture) WithItems(inputs ...*dynamodb.PutItemInput) *DynamoDBFixture

type DynamoDBStore

type DynamoDBStore struct {
	Client *dynamodb.Client
}

func NewDynamoDBStore

func NewDynamoDBStore(client *dynamodb.Client) *DynamoDBStore

func (*DynamoDBStore) WithLogging

func (d *DynamoDBStore) WithLogging(log *logging.Log) NoSQLStore

type Fixture

type Fixture struct {
	T *testing.T
}

type GetDeleteMarkerVersionsResponse

type GetDeleteMarkerVersionsResponse map[string]*S3ObjectInfo

type ModelScanner

type ModelScanner struct {
	ColumnNames       []string
	ColumnNamesString string
}

func NewModelScanner

func NewModelScanner(columnNames []string) *ModelScanner

func (*ModelScanner) QualifiedColumnNamesString

func (ms *ModelScanner) QualifiedColumnNamesString(qualifier string) string

type NoLogger

type NoLogger struct{}

func (NoLogger) LogDebug

func (n NoLogger) LogDebug(_ ...any)

func (NoLogger) LogDebugWithFields

func (n NoLogger) LogDebugWithFields(_ log.Fields, _ ...any)

func (NoLogger) LogError

func (n NoLogger) LogError(_ ...any)

func (NoLogger) LogErrorWithFields

func (n NoLogger) LogErrorWithFields(_ log.Fields, _ ...any)

func (NoLogger) LogInfo

func (n NoLogger) LogInfo(_ ...any)

func (NoLogger) LogInfoWithFields

func (n NoLogger) LogInfoWithFields(_ log.Fields, _ ...any)

func (NoLogger) LogWarn

func (n NoLogger) LogWarn(_ ...any)

func (NoLogger) LogWarnWithFields

func (n NoLogger) LogWarnWithFields(_ log.Fields, _ ...any)

type NoSQLStore

type NoSQLStore interface {
	GetDeleteMarkerVersions(ctx context.Context, restoring ...*models.RestorePackageInfo) (GetDeleteMarkerVersionsResponse, error)
	RemoveDeleteRecords(ctx context.Context, restoring []*models.RestorePackageInfo) error
	logging.Logger
}

type ObjectStore

type ObjectStore interface {
	DeleteObjectsVersion(ctx context.Context, objInfos ...S3ObjectInfo) (DeleteObjectsVersionResponse, error)
	logging.Logger
}

type PackageScanner

type PackageScanner struct {
	*ModelScanner
	QualifiedColumnNamesString string
}

func NewPackageScanner

func NewPackageScanner(columnNames []string) *PackageScanner

func (PackageScanner) Scan

func (s PackageScanner) Scan(scanner RowScanner, pkg *pgdb.Package) error

type PackageStateTransition

type PackageStateTransition struct {
	// NodeId: package node id
	NodeId string
	// Expected: expected current state of package
	Expected packageState.State
	// Target: desired state of package
	Target packageState.State
}

type PostgresConfig

type PostgresConfig struct {
	Host     string
	Port     string
	User     string
	Password string
	DBName   string
	SSLMode  string
}

func PostgresConfigFromEnv

func PostgresConfigFromEnv() *PostgresConfig

func (*PostgresConfig) LogString

func (c *PostgresConfig) LogString() string

func (*PostgresConfig) Open

func (c *PostgresConfig) Open(additionalOptions ...PostgresOption) (*sql.DB, error)

func (*PostgresConfig) OpenAtSchema

func (c *PostgresConfig) OpenAtSchema(schema string) (*sql.DB, error)

func (*PostgresConfig) String

func (c *PostgresConfig) String() string

type PostgresOption

type PostgresOption struct {
	Name  string
	Value string
}

func (*PostgresOption) String

func (o *PostgresOption) String() string

type PostgresStoreFactory

type PostgresStoreFactory struct {
	DB *sql.DB
}

func NewPostgresStoreFactory

func NewPostgresStoreFactory(db *sql.DB) *PostgresStoreFactory

func (*PostgresStoreFactory) WithLogging

func (s *PostgresStoreFactory) WithLogging(log logging.Logger) SQLStoreFactory

type Queries

type Queries struct {
	OrgId int
	logging.Logger
	// contains filtered or unexported fields
}

func NewQueries

func NewQueries(db pg.DBTX, orgId int, logger logging.Logger) *Queries

func (*Queries) GetDatasetByNodeId

func (q *Queries) GetDatasetByNodeId(ctx context.Context, dsNodeId string) (*pgdb.Dataset, error)

func (*Queries) GetPackageByNodeId

func (q *Queries) GetPackageByNodeId(ctx context.Context, packageId string) (*pgdb.Package, error)

func (*Queries) IncrementDatasetStorage

func (q *Queries) IncrementDatasetStorage(ctx context.Context, datasetId int64, sizeIncrement int64) error

func (*Queries) IncrementOrganizationStorage

func (q *Queries) IncrementOrganizationStorage(ctx context.Context, organizationId int64, sizeIncrement int64) error

func (*Queries) IncrementPackageStorage

func (q *Queries) IncrementPackageStorage(ctx context.Context, packageId int64, sizeIncrement int64) error

func (*Queries) IncrementPackageStorageAncestors

func (q *Queries) IncrementPackageStorageAncestors(ctx context.Context, parentId int64, size int64) error

IncrementPackageStorageAncestors increases the storage associated with the parents of the provided package.

func (*Queries) NewSavepoint

func (q *Queries) NewSavepoint(ctx context.Context, name string) error

func (*Queries) ReleaseSavepoint

func (q *Queries) ReleaseSavepoint(ctx context.Context, name string) error

func (*Queries) RollbackToSavepoint

func (q *Queries) RollbackToSavepoint(ctx context.Context, name string) error

func (*Queries) TransitionAncestorPackageState

func (q *Queries) TransitionAncestorPackageState(ctx context.Context, parentId int64, expectedState, targetState packageState.State) ([]*pgdb.Package, error)

func (*Queries) TransitionDescendantPackageState

func (q *Queries) TransitionDescendantPackageState(ctx context.Context, datasetId, packageId int64, expectedState, targetState packageState.State) ([]*pgdb.Package, error)

func (*Queries) TransitionPackageState

func (q *Queries) TransitionPackageState(ctx context.Context, datasetId int64, packageId string, expectedState, targetState packageState.State) (*pgdb.Package, error)

func (*Queries) TransitionPackageStateBulk

func (q *Queries) TransitionPackageStateBulk(ctx context.Context, datasetId int64, transitions []PackageStateTransition) ([]*pgdb.Package, error)

func (*Queries) UpdatePackageName

func (q *Queries) UpdatePackageName(ctx context.Context, packageId int64, newName string) error

type QueueStore

type QueueStore interface {
	SendRestorePackage(ctx context.Context, restoreMessage models.RestorePackageMessage) error
}

func NewQueueStore

func NewQueueStore(sqsClient *sqs.Client) QueueStore

type RowScanner

type RowScanner interface {
	Scan(dest ...any) error
}

type S3Fixture

type S3Fixture struct {
	Fixture
	Client *s3.Client
	// Buckets is a set of bucket names
	Buckets map[string]bool
}

func NewS3Fixture

func NewS3Fixture(t *testing.T, client *s3.Client, inputs ...*s3.CreateBucketInput) *S3Fixture

func (*S3Fixture) Teardown

func (f *S3Fixture) Teardown()

func (*S3Fixture) WithObjects

func (f *S3Fixture) WithObjects(objectInputs ...*s3.PutObjectInput) *S3Fixture

type S3ObjectInfo

type S3ObjectInfo struct {
	NodeId    string `dynamodbav:"NodeId"`
	Bucket    string `dynamodbav:"S3Bucket"`
	Key       string `dynamodbav:"S3Key"`
	VersionId string `dynamodbav:"S3ObjectVersion"`
	Size      string `dynamodbav:"ObjectSize"`
}

func (*S3ObjectInfo) GetSize

func (o *S3ObjectInfo) GetSize() (int64, error)

type S3Store

type S3Store struct {
	Client *s3.Client
}

func NewS3Store

func NewS3Store(s3Client *s3.Client) *S3Store

func (*S3Store) WithLogging

func (s *S3Store) WithLogging(log *logging.Log) ObjectStore

type SQLStore

type SQLStore interface {
	UpdatePackageName(ctx context.Context, packageId int64, newName string) error
	GetDatasetByNodeId(ctx context.Context, dsNodeId string) (*pgdb.Dataset, error)
	// TransitionPackageState updates the state of the given package from expectedState to targetState and returns the resulting package.
	// If the package is not already in expectedState, then models.PackageNotFoundError is returned.
	TransitionPackageState(ctx context.Context, datasetId int64, packageId string, expectedState, targetState packageState.State) (*pgdb.Package, error)
	// TransitionPackageStateBulk updates the state of the given packages from expectedStates to targetStates and returns the resulting packages.
	TransitionPackageStateBulk(ctx context.Context, datasetId int64, transitions []PackageStateTransition) ([]*pgdb.Package, error)
	// TransitionDescendantPackageState updates the state of any descendants of the given package which have state == expectedState to targetState and returns the updated packages.
	// It does not update the state of the package with id packageId, only its descendants if any.
	TransitionDescendantPackageState(ctx context.Context, datasetId, packageId int64, expectedState, targetState packageState.State) ([]*pgdb.Package, error)
	// TransitionAncestorPackageState updates the state of any ancestors of the package with the given parentId which have state == expectedState to targetState and returns the updated packages.
	TransitionAncestorPackageState(ctx context.Context, parentId int64, expectedState, targetState packageState.State) ([]*pgdb.Package, error)
	NewSavepoint(ctx context.Context, name string) error
	RollbackToSavepoint(ctx context.Context, name string) error
	ReleaseSavepoint(ctx context.Context, name string) error
	IncrementOrganizationStorage(ctx context.Context, organizationId int64, sizeIncrement int64) error
	IncrementDatasetStorage(ctx context.Context, datasetId int64, sizeIncrement int64) error
	IncrementPackageStorage(ctx context.Context, packageId int64, sizeIncrement int64) error
	IncrementPackageStorageAncestors(ctx context.Context, parentId int64, size int64) error
	GetPackageByNodeId(ctx context.Context, packageId string) (*pgdb.Package, error)
	logging.Logger
}

type SQLStoreFactory

type SQLStoreFactory interface {
	NewSimpleStore(orgId int) SQLStore
	ExecStoreTx(ctx context.Context, orgId int, fn func(store SQLStore) error) error
}

type TestDB

type TestDB struct {
	*sql.DB
	// contains filtered or unexported fields
}

func OpenDB

func OpenDB(t *testing.T, additionalOptions ...PostgresOption) TestDB

func (*TestDB) Close

func (tdb *TestDB) Close()

func (*TestDB) CloseRows

func (tdb *TestDB) CloseRows(rows *sql.Rows)

func (*TestDB) ExecSQLFile

func (tdb *TestDB) ExecSQLFile(sqlFile string)

func (*TestDB) PingUntilReady

func (tdb *TestDB) PingUntilReady() error

PingUntilReady pings the db up to 10 times, stopping when a ping is successful. Used because there have been problems on Jenkins with the test DB not being fully started and ready to make connections. But there must be a better way.

func (*TestDB) Queries

func (tdb *TestDB) Queries(orgId int) *Queries

func (*TestDB) Truncate

func (tdb *TestDB) Truncate(orgID int, table string)

func (*TestDB) TruncatePennsieve

func (tdb *TestDB) TruncatePennsieve(table string)

type TestPackage

type TestPackage struct {
	pgdb.Package
}

func NewTestPackage

func NewTestPackage(id int64, datasetId int, ownerId int) *TestPackage

func (*TestPackage) AsPackage

func (p *TestPackage) AsPackage() pgdb.Package

func (*TestPackage) Deleted

func (p *TestPackage) Deleted() *TestPackage

func (*TestPackage) Insert

func (p *TestPackage) Insert(ctx context.Context, db TestDB, orgId int) *pgdb.Package

func (*TestPackage) Restoring

func (p *TestPackage) Restoring() *TestPackage

func (*TestPackage) WithDeletedName

func (p *TestPackage) WithDeletedName() *TestPackage

func (*TestPackage) WithName

func (p *TestPackage) WithName(name string) *TestPackage

func (*TestPackage) WithParentId

func (p *TestPackage) WithParentId(parentId int64) *TestPackage

func (*TestPackage) WithState

func (p *TestPackage) WithState(ps packageState.State) *TestPackage

func (*TestPackage) WithType

func (p *TestPackage) WithType(pt packageType.Type) *TestPackage

type TestPackageAttribute

type TestPackageAttribute struct {
	packageInfo.PackageAttribute
}

func NewTestPackageAttribute

func NewTestPackageAttribute() *TestPackageAttribute

func (*TestPackageAttribute) AsPackageAttribute

func (a *TestPackageAttribute) AsPackageAttribute() packageInfo.PackageAttribute

type TestPackageAttributes

type TestPackageAttributes []TestPackageAttribute

func NewTestPackageAttributes

func NewTestPackageAttributes(len int) TestPackageAttributes

func (TestPackageAttributes) AsPackageAttributes

func (as TestPackageAttributes) AsPackageAttributes() packageInfo.PackageAttributes

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL