mirror of
https://github.com/harness/drone.git
synced 2025-05-07 05:41:36 +08:00
feat:[AH-945]: API to fetch storage details per account (#3373)
* feat:[AH-945]: API to fetch storage details per account * feat:[AH-945]: API to fetch storage details per account
This commit is contained in:
parent
f9432e92dc
commit
e93f30a6a5
@ -30,6 +30,8 @@ import (
|
|||||||
type APIController struct {
|
type APIController struct {
|
||||||
ImageStore store.ImageRepository
|
ImageStore store.ImageRepository
|
||||||
fileManager filemanager.FileManager
|
fileManager filemanager.FileManager
|
||||||
|
BlobStore store.BlobRepository
|
||||||
|
GenericBlobStore store.GenericBlobRepository
|
||||||
RegistryRepository store.RegistryRepository
|
RegistryRepository store.RegistryRepository
|
||||||
UpstreamProxyStore store.UpstreamProxyConfigRepository
|
UpstreamProxyStore store.UpstreamProxyConfigRepository
|
||||||
TagStore store.TagRepository
|
TagStore store.TagRepository
|
||||||
@ -49,6 +51,8 @@ type APIController struct {
|
|||||||
func NewAPIController(
|
func NewAPIController(
|
||||||
repositoryStore store.RegistryRepository,
|
repositoryStore store.RegistryRepository,
|
||||||
fileManager filemanager.FileManager,
|
fileManager filemanager.FileManager,
|
||||||
|
blobStore store.BlobRepository,
|
||||||
|
genericBlobStore store.GenericBlobRepository,
|
||||||
upstreamProxyStore store.UpstreamProxyConfigRepository,
|
upstreamProxyStore store.UpstreamProxyConfigRepository,
|
||||||
tagStore store.TagRepository,
|
tagStore store.TagRepository,
|
||||||
manifestStore store.ManifestRepository,
|
manifestStore store.ManifestRepository,
|
||||||
@ -66,6 +70,8 @@ func NewAPIController(
|
|||||||
) *APIController {
|
) *APIController {
|
||||||
return &APIController{
|
return &APIController{
|
||||||
fileManager: fileManager,
|
fileManager: fileManager,
|
||||||
|
GenericBlobStore: genericBlobStore,
|
||||||
|
BlobStore: blobStore,
|
||||||
RegistryRepository: repositoryStore,
|
RegistryRepository: repositoryStore,
|
||||||
UpstreamProxyStore: upstreamProxyStore,
|
UpstreamProxyStore: upstreamProxyStore,
|
||||||
TagStore: tagStore,
|
TagStore: tagStore,
|
||||||
|
@ -79,6 +79,8 @@ func NewAPIHandler(
|
|||||||
apiController := metadata.NewAPIController(
|
apiController := metadata.NewAPIController(
|
||||||
repoDao,
|
repoDao,
|
||||||
fileManager,
|
fileManager,
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
upstreamproxyDao,
|
upstreamproxyDao,
|
||||||
tagDao,
|
tagDao,
|
||||||
manifestDao,
|
manifestDao,
|
||||||
|
@ -46,6 +46,7 @@ type BlobRepository interface {
|
|||||||
ctx context.Context, repoID int64, d digest.Digest,
|
ctx context.Context, repoID int64, d digest.Digest,
|
||||||
image string,
|
image string,
|
||||||
) (bool, error)
|
) (bool, error)
|
||||||
|
TotalSizeByRootParentID(ctx context.Context, id int64) (int64, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type CleanupPolicyRepository interface {
|
type CleanupPolicyRepository interface {
|
||||||
@ -556,6 +557,7 @@ type GenericBlobRepository interface {
|
|||||||
) (*types.GenericBlob, error)
|
) (*types.GenericBlob, error)
|
||||||
Create(ctx context.Context, gb *types.GenericBlob) error
|
Create(ctx context.Context, gb *types.GenericBlob) error
|
||||||
DeleteByID(ctx context.Context, id string) error
|
DeleteByID(ctx context.Context, id string) error
|
||||||
|
TotalSizeByRootParentID(ctx context.Context, id int64) (int64, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebhooksRepository interface {
|
type WebhooksRepository interface {
|
||||||
|
@ -16,6 +16,7 @@ package database
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -99,6 +100,27 @@ func (bd blobDao) FindByDigestAndRootParentID(ctx context.Context, d digest.Dige
|
|||||||
return bd.mapToBlob(dst)
|
return bd.mapToBlob(dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bd blobDao) TotalSizeByRootParentID(ctx context.Context, rootID int64) (int64, error) {
|
||||||
|
q := database.Builder.Select("SUM(blob_size) AS size").
|
||||||
|
From("blobs").
|
||||||
|
Where("blob_root_parent_id = ?", rootID)
|
||||||
|
|
||||||
|
db := dbtx.GetAccessor(ctx, bd.db)
|
||||||
|
|
||||||
|
var size int64
|
||||||
|
sqlQuery, args, err := q.ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return 0, errors2.Wrap(err, "Failed to convert query to sql")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = db.QueryRowContext(ctx, sqlQuery, args...).Scan(&size); err != nil &&
|
||||||
|
!errors2.Is(err, sql.ErrNoRows) {
|
||||||
|
return 0,
|
||||||
|
database.ProcessSQLErrorf(ctx, err, "Failed to find total blob size for root parent with id %d", rootID)
|
||||||
|
}
|
||||||
|
return size, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (bd blobDao) FindByID(ctx context.Context, id int64) (*types.Blob, error) {
|
func (bd blobDao) FindByID(ctx context.Context, id int64) (*types.Blob, error) {
|
||||||
stmt := PrimaryQuery.
|
stmt := PrimaryQuery.
|
||||||
Where("blob_id = ?", id)
|
Where("blob_id = ?", id)
|
||||||
|
@ -57,6 +57,28 @@ func (g GenericBlobDao) FindByID(ctx context.Context, id string) (*types.Generic
|
|||||||
return g.mapToGenericBlob(ctx, dst)
|
return g.mapToGenericBlob(ctx, dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g GenericBlobDao) TotalSizeByRootParentID(ctx context.Context, rootID int64) (int64, error) {
|
||||||
|
q := databaseg.Builder.
|
||||||
|
Select("SUM(generic_blob_size) AS size").
|
||||||
|
From("generic_blobs").
|
||||||
|
Where("generic_blob_root_parent_id = ?", rootID)
|
||||||
|
|
||||||
|
db := dbtx.GetAccessor(ctx, g.sqlDB)
|
||||||
|
|
||||||
|
var size int64
|
||||||
|
sqlQuery, args, err := q.ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return 0, errors.Wrap(err, "Failed to convert query to sql")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = db.QueryRowContext(ctx, sqlQuery, args...).Scan(&size); err != nil &&
|
||||||
|
!errors.Is(err, sql.ErrNoRows) {
|
||||||
|
return 0,
|
||||||
|
databaseg.ProcessSQLErrorf(ctx, err, "Failed to find total blob size for root parent with id %d", rootID)
|
||||||
|
}
|
||||||
|
return size, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (g GenericBlobDao) FindBySha256AndRootParentID(ctx context.Context,
|
func (g GenericBlobDao) FindBySha256AndRootParentID(ctx context.Context,
|
||||||
sha256 string, rootParentID int64) (
|
sha256 string, rootParentID int64) (
|
||||||
*types.GenericBlob, error) {
|
*types.GenericBlob, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user