Browse Source

拆分cdssdk的storage相关定义

gitlink
Sydonian 1 year ago
parent
commit
7dc1aa871c
4 changed files with 139 additions and 44 deletions
  1. +3
    -44
      sdks/storage/models.go
  2. +43
    -0
      sdks/storage/shard_storage.go
  3. +47
    -0
      sdks/storage/storage.go
  4. +46
    -0
      sdks/storage/storage_feature.go

+ 3
- 44
sdks/storage/models.go View File

@@ -227,9 +227,9 @@ func (n Node) String() string {
}

type PinnedObject struct {
ObjectID ObjectID `db:"ObjectID" json:"objectID"`
NodeID NodeID `db:"NodeID" json:"nodeID"`
CreateTime time.Time `db:"CreateTime" json:"createTime"`
ObjectID ObjectID `gorm:"column:ObjectID; primaryKey" json:"objectID"`
StorageID StorageID `gorm:"column:StorageID; primaryKey" json:"storageID"`
CreateTime time.Time `gorm:"column:CreateTime" json:"createTime"`
}

type Bucket struct {
@@ -271,44 +271,3 @@ type CodeError struct {
func (e *CodeError) Error() string {
return fmt.Sprintf("code: %s, message: %s", e.Code, e.Message)
}

type StorageAddress interface {
GetType() string
// 输出调试用的字符串,不要包含敏感信息
String() string
}

type Feature interface {
GetType() string
}

type Storage struct {
StorageID StorageID `json:"storageID" gorm:"column:StorageID; primaryKey; autoIncrement;"`
Name string `json:"name" gorm:"column:Name; not null"`
// 存储服务的地址,包含鉴权所需数据
Address StorageAddress `json:"address" gorm:"column:Address; type:json; not null; serializer:union"`
// 存储服务拥有的特别功能
Features []Feature `json:"features" gorm:"column:Features; type:json; serializer:union"`
}

type ShardStoreConfig interface {
GetType() string
}

type ShardStorage struct {
StorageID StorageID `json:"storageID" gorm:"column:StorageID; primaryKey"`
// 完全管理此存储服务的Hub的ID
MasterHub NodeID `json:"masterHub" gorm:"column:MasterHub; not null"`
// Shard存储空间在存储服务的目录
Root string `json:"root" gorm:"column:Root; not null"`
// ShardStore配置数据
Config ShardStoreConfig `json:"config" gorm:"column:Config; type:json; not null; serializer:union"`
}

type SharedStorage struct {
StorageID StorageID `json:"storageID" gorm:"column:StorageID; primaryKey"`
// 调度文件时保存文件的根路径
LoadBase string `json:"loadBase" gorm:"column:LoadBase; not null"`
// 回源数据时数据存放位置的根路径
DataReturnBase string `json:"dataReturnBase" gorm:"column:DataReturnBase; not null"`
}

+ 43
- 0
sdks/storage/shard_storage.go View File

@@ -0,0 +1,43 @@
package cdssdk

import (
"fmt"

"gitlink.org.cn/cloudream/common/pkgs/types"
"gitlink.org.cn/cloudream/common/utils/serder"
)

// 分片存储服务的配置数据
type ShardStoreConfig interface {
GetType() string
// 输出调试用的字符串,不要包含敏感信息
String() string
}

var _ = serder.UseTypeUnionInternallyTagged(types.Ref(types.NewTypeUnion[ShardStoreConfig](
(*LocalShardStorage)(nil),
)), "type")

type ShardStorage struct {
StorageID StorageID `json:"storageID" gorm:"column:StorageID; primaryKey"`
// 完全管理此存储服务的Hub的ID
MasterHub NodeID `json:"masterHub" gorm:"column:MasterHub; not null"`
// Shard存储空间在存储服务的目录
Root string `json:"root" gorm:"column:Root; not null"`
// ShardStore配置数据
Config ShardStoreConfig `json:"config" gorm:"column:Config; type:json; not null; serializer:union"`
}

type LocalShardStorage struct {
serder.Metadata `union:"Local"`
Root string `json:"root"`
MaxSize int64 `json:"maxSize"`
}

func (s *LocalShardStorage) GetType() string {
return "Local"
}

func (s *LocalShardStorage) String() string {
return fmt.Sprintf("Local[root=%s, maxSize=%d]", s.Root, s.MaxSize)
}

+ 47
- 0
sdks/storage/storage.go View File

@@ -0,0 +1,47 @@
package cdssdk

import (
"gitlink.org.cn/cloudream/common/pkgs/types"
"gitlink.org.cn/cloudream/common/utils/serder"
)

// 存储服务地址
type StorageAddress interface {
GetType() string
// 输出调试用的字符串,不要包含敏感信息
String() string
}

var _ = serder.UseTypeUnionInternallyTagged(types.Ref(types.NewTypeUnion[StorageAddress](
(*LocalStorageAddress)(nil),
)), "type")

type LocalStorageAddress struct {
serder.Metadata `union:"Local"`
}

func (a *LocalStorageAddress) GetType() string {
return "Local"
}

func (a *LocalStorageAddress) String() string {
return "Local"
}

type Storage struct {
StorageID StorageID `json:"storageID" gorm:"column:StorageID; primaryKey; autoIncrement;"`
Name string `json:"name" gorm:"column:Name; not null"`
// 存储服务的地址,包含鉴权所需数据
Address StorageAddress `json:"address" gorm:"column:Address; type:json; not null; serializer:union"`
// 存储服务拥有的特别功能
Features []StorageFeature `json:"features" gorm:"column:Features; type:json; serializer:union"`
}

// 共享存储服务的配置数据
type SharedStorage struct {
StorageID StorageID `json:"storageID" gorm:"column:StorageID; primaryKey"`
// 调度文件时保存文件的根路径
LoadBase string `json:"loadBase" gorm:"column:LoadBase; not null"`
// 回源数据时数据存放位置的根路径
DataReturnBase string `json:"dataReturnBase" gorm:"column:DataReturnBase; not null"`
}

+ 46
- 0
sdks/storage/storage_feature.go View File

@@ -0,0 +1,46 @@
package cdssdk

import (
"gitlink.org.cn/cloudream/common/pkgs/types"
"gitlink.org.cn/cloudream/common/utils/serder"
)

// 存储服务特性
type StorageFeature interface {
GetType() string
// 输出调试用的字符串,不要包含敏感信息
String() string
}

var _ = serder.UseTypeUnionInternallyTagged(types.Ref(types.NewTypeUnion[StorageFeature](
(*BypassUploadFeature)(nil),
(*MultipartUploadFeature)(nil),
)), "type")

// 存储服务支持被非MasterHub直接上传文件
type BypassUploadFeature struct {
serder.Metadata `union:"BypassUpload"`
// 存放上传文件的临时目录
TempRoot string `json:"tempRoot"`
}

func (f *BypassUploadFeature) GetType() string {
return "BypassUpload"
}

func (f *BypassUploadFeature) String() string {
return "BypassUpload"
}

// 存储服务支持分段上传
type MultipartUploadFeature struct {
serder.Metadata `union:"MultipartUpload"`
}

func (f *MultipartUploadFeature) GetType() string {
return "MultipartUpload"
}

func (f *MultipartUploadFeature) String() string {
return "MultipartUpload"
}

Loading…
Cancel
Save