| @@ -4,6 +4,5 @@ import ( | |||||
| // !!! 需要导入所有存储服务的包 !!! | // !!! 需要导入所有存储服务的包 !!! | ||||
| _ "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/efile" | _ "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/efile" | ||||
| _ "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/local" | _ "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/local" | ||||
| _ "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/mashup" | |||||
| _ "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/obs" | _ "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/obs" | ||||
| ) | ) | ||||
| @@ -91,10 +91,6 @@ func (b *builder) getToken() (string, error) { | |||||
| } | } | ||||
| func (b *builder) CreateECMultiplier(typeOnly bool) (types.ECMultiplier, error) { | func (b *builder) CreateECMultiplier(typeOnly bool) (types.ECMultiplier, error) { | ||||
| if typeOnly { | |||||
| return (*ECMultiplier)(nil), nil | |||||
| } | |||||
| feat := types.FindFeature[*cortypes.ECMultiplierFeature](b.detail) | feat := types.FindFeature[*cortypes.ECMultiplierFeature](b.detail) | ||||
| if feat == nil { | if feat == nil { | ||||
| return nil, fmt.Errorf("feature ECMultiplier not found") | return nil, fmt.Errorf("feature ECMultiplier not found") | ||||
| @@ -105,6 +101,10 @@ func (b *builder) CreateECMultiplier(typeOnly bool) (types.ECMultiplier, error) | |||||
| return nil, fmt.Errorf("invalid storage credential type %T for efile storage", b.detail.UserSpace.Credential) | return nil, fmt.Errorf("invalid storage credential type %T for efile storage", b.detail.UserSpace.Credential) | ||||
| } | } | ||||
| if typeOnly { | |||||
| return (*ECMultiplier)(nil), nil | |||||
| } | |||||
| return &ECMultiplier{ | return &ECMultiplier{ | ||||
| blder: b, | blder: b, | ||||
| url: cred.APIURL, | url: cred.APIURL, | ||||
| @@ -27,56 +27,56 @@ func (b *builder) FeatureDesc() types.FeatureDesc { | |||||
| } | } | ||||
| func (b *builder) CreateShardStore(typeOnly bool) (types.ShardStore, error) { | func (b *builder) CreateShardStore(typeOnly bool) (types.ShardStore, error) { | ||||
| if typeOnly { | |||||
| return (*ShardStore)(nil), nil | |||||
| } | |||||
| cred, ok := b.detail.UserSpace.Credential.(*cortypes.LocalCred) | cred, ok := b.detail.UserSpace.Credential.(*cortypes.LocalCred) | ||||
| if !ok { | if !ok { | ||||
| return nil, fmt.Errorf("invalid storage credential type %T for local storage", b.detail.UserSpace.Credential) | return nil, fmt.Errorf("invalid storage credential type %T for local storage", b.detail.UserSpace.Credential) | ||||
| } | } | ||||
| if typeOnly { | |||||
| return (*ShardStore)(nil), nil | |||||
| } | |||||
| return NewShardStore(cred.RootDir, b.detail) | return NewShardStore(cred.RootDir, b.detail) | ||||
| } | } | ||||
| func (b *builder) CreateBaseStore(typeOnly bool) (types.BaseStore, error) { | func (b *builder) CreateBaseStore(typeOnly bool) (types.BaseStore, error) { | ||||
| if typeOnly { | |||||
| return (*BaseStore)(nil), nil | |||||
| } | |||||
| cred, ok := b.detail.UserSpace.Credential.(*cortypes.LocalCred) | cred, ok := b.detail.UserSpace.Credential.(*cortypes.LocalCred) | ||||
| if !ok { | if !ok { | ||||
| return nil, fmt.Errorf("invalid storage credential type %T for local storage", b.detail.UserSpace.Credential) | return nil, fmt.Errorf("invalid storage credential type %T for local storage", b.detail.UserSpace.Credential) | ||||
| } | } | ||||
| if typeOnly { | |||||
| return (*BaseStore)(nil), nil | |||||
| } | |||||
| return NewBaseStore(cred.RootDir, b.detail) | return NewBaseStore(cred.RootDir, b.detail) | ||||
| } | } | ||||
| func (b *builder) CreateMultiparter(typeOnly bool) (types.Multiparter, error) { | func (b *builder) CreateMultiparter(typeOnly bool) (types.Multiparter, error) { | ||||
| if typeOnly { | |||||
| return (*Multiparter)(nil), nil | |||||
| } | |||||
| feat := types.FindFeature[*cortypes.MultipartUploadFeature](b.detail) | feat := types.FindFeature[*cortypes.MultipartUploadFeature](b.detail) | ||||
| if feat == nil { | if feat == nil { | ||||
| return nil, fmt.Errorf("feature %T not found", cortypes.MultipartUploadFeature{}) | return nil, fmt.Errorf("feature %T not found", cortypes.MultipartUploadFeature{}) | ||||
| } | } | ||||
| if typeOnly { | |||||
| return (*Multiparter)(nil), nil | |||||
| } | |||||
| return &Multiparter{ | return &Multiparter{ | ||||
| feat: feat, | feat: feat, | ||||
| }, nil | }, nil | ||||
| } | } | ||||
| func (b *builder) CreateS2STransfer(typeOnly bool) (types.S2STransfer, error) { | func (b *builder) CreateS2STransfer(typeOnly bool) (types.S2STransfer, error) { | ||||
| if typeOnly { | |||||
| return (*S2STransfer)(nil), nil | |||||
| } | |||||
| feat := types.FindFeature[*cortypes.S2STransferFeature](b.detail) | feat := types.FindFeature[*cortypes.S2STransferFeature](b.detail) | ||||
| if feat == nil { | if feat == nil { | ||||
| return nil, fmt.Errorf("feature %T not found", cortypes.S2STransferFeature{}) | return nil, fmt.Errorf("feature %T not found", cortypes.S2STransferFeature{}) | ||||
| } | } | ||||
| if typeOnly { | |||||
| return (*S2STransfer)(nil), nil | |||||
| } | |||||
| return &S2STransfer{ | return &S2STransfer{ | ||||
| detail: b.detail, | detail: b.detail, | ||||
| }, nil | }, nil | ||||
| @@ -1,114 +0,0 @@ | |||||
| package mashup | |||||
| /* | |||||
| import ( | |||||
| "fmt" | |||||
| clitypes "gitlink.org.cn/cloudream/jcs-pub/client/types" | |||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/factory/reg" | |||||
| "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/storage/types" | |||||
| cortypes "gitlink.org.cn/cloudream/jcs-pub/coordinator/types" | |||||
| ) | |||||
| func init() { | |||||
| reg.RegisterBuilder[*cortypes.MashupStorageType](func(detail *clitypes.UserSpaceDetail) types.StorageBuilder { | |||||
| return &builder{ | |||||
| detail: detail, | |||||
| } | |||||
| }) | |||||
| } | |||||
| type builder struct { | |||||
| detail *clitypes.UserSpaceDetail | |||||
| } | |||||
| func (b *builder) FeatureDesc() types.FeatureDesc { | |||||
| stgType := b.detail.UserSpace.Storage.(*cortypes.MashupStorageType) | |||||
| cred, ok := b.detail.UserSpace.Credential.(*cortypes.MashupCred) | |||||
| if !ok { | |||||
| return types.FeatureDesc{} | |||||
| } | |||||
| newDetail := *b.detail | |||||
| newDetail.UserSpace.Storage = stgType.Store | |||||
| newDetail.UserSpace.Credential = cred.Store | |||||
| blder := reg.GetBuilderInternal(&newDetail) | |||||
| return blder.FeatureDesc() | |||||
| } | |||||
| func (b *builder) CreateShardStore() (types.ShardStore, error) { | |||||
| stgType := b.detail.UserSpace.Storage.(*cortypes.MashupStorageType) | |||||
| cred, ok := b.detail.UserSpace.Credential.(*cortypes.MashupCred) | |||||
| if !ok { | |||||
| return nil, fmt.Errorf("invalid storage credential type %T for mashup storage", b.detail.UserSpace.Credential) | |||||
| } | |||||
| newDetail := *b.detail | |||||
| newDetail.UserSpace.Storage = stgType.Store | |||||
| newDetail.UserSpace.Credential = cred.Store | |||||
| blder := reg.GetBuilderInternal(&newDetail) | |||||
| return blder.CreateShardStore() | |||||
| } | |||||
| func (b *builder) CreateBaseStore() (types.BaseStore, error) { | |||||
| stgType := b.detail.UserSpace.Storage.(*cortypes.MashupStorageType) | |||||
| cred, ok := b.detail.UserSpace.Credential.(*cortypes.MashupCred) | |||||
| if !ok { | |||||
| return nil, fmt.Errorf("invalid storage credential type %T for mashup storage", b.detail.UserSpace.Credential) | |||||
| } | |||||
| newDetail := *b.detail | |||||
| newDetail.UserSpace.Storage = stgType.Store | |||||
| newDetail.UserSpace.Credential = cred.Store | |||||
| blder := reg.GetBuilderInternal(&newDetail) | |||||
| return blder.CreateBaseStore() | |||||
| } | |||||
| func (b *builder) CreateMultiparter() (types.Multiparter, error) { | |||||
| stgType := b.detail.UserSpace.Storage.(*cortypes.MashupStorageType) | |||||
| cred, ok := b.detail.UserSpace.Credential.(*cortypes.MashupCred) | |||||
| if !ok { | |||||
| return nil, fmt.Errorf("invalid storage credential type %T for mashup storage", b.detail.UserSpace.Credential) | |||||
| } | |||||
| newDetail := *b.detail | |||||
| newDetail.UserSpace.Storage = stgType.Feature | |||||
| newDetail.UserSpace.Credential = cred.Feature | |||||
| blder := reg.GetBuilderInternal(&newDetail) | |||||
| return blder.CreateMultiparter() | |||||
| } | |||||
| func (b *builder) CreateS2STransfer() (types.S2STransfer, error) { | |||||
| stgType := b.detail.UserSpace.Storage.(*cortypes.MashupStorageType) | |||||
| cred, ok := b.detail.UserSpace.Credential.(*cortypes.MashupCred) | |||||
| if !ok { | |||||
| return nil, fmt.Errorf("invalid storage credential type %T for mashup storage", b.detail.UserSpace.Credential) | |||||
| } | |||||
| newDetail := *b.detail | |||||
| newDetail.UserSpace.Storage = stgType.Feature | |||||
| newDetail.UserSpace.Credential = cred.Feature | |||||
| blder := reg.GetBuilderInternal(&newDetail) | |||||
| return blder.CreateS2STransfer() | |||||
| } | |||||
| func (b *builder) CreateECMultiplier() (types.ECMultiplier, error) { | |||||
| stgType := b.detail.UserSpace.Storage.(*cortypes.MashupStorageType) | |||||
| cred, ok := b.detail.UserSpace.Credential.(*cortypes.MashupCred) | |||||
| if !ok { | |||||
| return nil, fmt.Errorf("invalid storage credential type %T for mashup storage", b.detail.UserSpace.Credential) | |||||
| } | |||||
| newDetail := *b.detail | |||||
| newDetail.UserSpace.Storage = stgType.Feature | |||||
| newDetail.UserSpace.Credential = cred.Feature | |||||
| blder := reg.GetBuilderInternal(&newDetail) | |||||
| return blder.CreateECMultiplier() | |||||
| } | |||||
| */ | |||||
| @@ -33,16 +33,16 @@ func (b *builder) FeatureDesc() types.FeatureDesc { | |||||
| } | } | ||||
| func (b *builder) CreateShardStore(typeOnly bool) (types.ShardStore, error) { | func (b *builder) CreateShardStore(typeOnly bool) (types.ShardStore, error) { | ||||
| if typeOnly { | |||||
| return (*ShardStore)(nil), nil | |||||
| } | |||||
| stgType := b.detail.UserSpace.Storage.(*cortypes.OBSType) | stgType := b.detail.UserSpace.Storage.(*cortypes.OBSType) | ||||
| cred, ok := b.detail.UserSpace.Credential.(*cortypes.OBSCred) | cred, ok := b.detail.UserSpace.Credential.(*cortypes.OBSCred) | ||||
| if !ok { | if !ok { | ||||
| return nil, fmt.Errorf("invalid storage credential type %T for obs storage", b.detail.UserSpace.Credential) | return nil, fmt.Errorf("invalid storage credential type %T for obs storage", b.detail.UserSpace.Credential) | ||||
| } | } | ||||
| if typeOnly { | |||||
| return (*ShardStore)(nil), nil | |||||
| } | |||||
| cli, bucket, err := createClient(stgType, cred) | cli, bucket, err := createClient(stgType, cred) | ||||
| if err != nil { | if err != nil { | ||||
| return nil, err | return nil, err | ||||
| @@ -52,16 +52,16 @@ func (b *builder) CreateShardStore(typeOnly bool) (types.ShardStore, error) { | |||||
| } | } | ||||
| func (b *builder) CreateBaseStore(typeOnly bool) (types.BaseStore, error) { | func (b *builder) CreateBaseStore(typeOnly bool) (types.BaseStore, error) { | ||||
| if typeOnly { | |||||
| return (*s3stg.BaseStore)(nil), nil | |||||
| } | |||||
| stgType := b.detail.UserSpace.Storage.(*cortypes.OBSType) | stgType := b.detail.UserSpace.Storage.(*cortypes.OBSType) | ||||
| cred, ok := b.detail.UserSpace.Credential.(*cortypes.OBSCred) | cred, ok := b.detail.UserSpace.Credential.(*cortypes.OBSCred) | ||||
| if !ok { | if !ok { | ||||
| return nil, fmt.Errorf("invalid storage credential type %T for obs storage", b.detail.UserSpace.Credential) | return nil, fmt.Errorf("invalid storage credential type %T for obs storage", b.detail.UserSpace.Credential) | ||||
| } | } | ||||
| if typeOnly { | |||||
| return (*s3stg.BaseStore)(nil), nil | |||||
| } | |||||
| cli, bucket, err := createClient(stgType, cred) | cli, bucket, err := createClient(stgType, cred) | ||||
| if err != nil { | if err != nil { | ||||
| return nil, err | return nil, err | ||||
| @@ -91,16 +91,16 @@ func createClient(stgType *cortypes.OBSType, cred *cortypes.OBSCred) (*s3.Client | |||||
| } | } | ||||
| func (b *builder) CreateMultiparter(typeOnly bool) (types.Multiparter, error) { | func (b *builder) CreateMultiparter(typeOnly bool) (types.Multiparter, error) { | ||||
| if typeOnly { | |||||
| return (*s3stg.Multiparter)(nil), nil | |||||
| } | |||||
| stgType := b.detail.UserSpace.Storage.(*cortypes.OBSType) | stgType := b.detail.UserSpace.Storage.(*cortypes.OBSType) | ||||
| feat := types.FindFeature[*cortypes.MultipartUploadFeature](b.detail) | feat := types.FindFeature[*cortypes.MultipartUploadFeature](b.detail) | ||||
| if feat == nil { | if feat == nil { | ||||
| return nil, fmt.Errorf("feature %T not found", cortypes.MultipartUploadFeature{}) | return nil, fmt.Errorf("feature %T not found", cortypes.MultipartUploadFeature{}) | ||||
| } | } | ||||
| if typeOnly { | |||||
| return (*s3stg.Multiparter)(nil), nil | |||||
| } | |||||
| cred, ok := b.detail.UserSpace.Credential.(*cortypes.OBSCred) | cred, ok := b.detail.UserSpace.Credential.(*cortypes.OBSCred) | ||||
| if !ok { | if !ok { | ||||
| return nil, fmt.Errorf("invalid storage credential type %T for obs storage", b.detail.UserSpace.Credential) | return nil, fmt.Errorf("invalid storage credential type %T for obs storage", b.detail.UserSpace.Credential) | ||||
| @@ -120,16 +120,16 @@ func (b *builder) CreateMultiparter(typeOnly bool) (types.Multiparter, error) { | |||||
| } | } | ||||
| func (b *builder) CreateS2STransfer(typeOnly bool) (types.S2STransfer, error) { | func (b *builder) CreateS2STransfer(typeOnly bool) (types.S2STransfer, error) { | ||||
| if typeOnly { | |||||
| return (*S2STransfer)(nil), nil | |||||
| } | |||||
| stgType := b.detail.UserSpace.Storage.(*cortypes.OBSType) | stgType := b.detail.UserSpace.Storage.(*cortypes.OBSType) | ||||
| feat := types.FindFeature[*cortypes.S2STransferFeature](b.detail) | feat := types.FindFeature[*cortypes.S2STransferFeature](b.detail) | ||||
| if feat == nil { | if feat == nil { | ||||
| return nil, fmt.Errorf("feature %T not found", cortypes.S2STransferFeature{}) | return nil, fmt.Errorf("feature %T not found", cortypes.S2STransferFeature{}) | ||||
| } | } | ||||
| if typeOnly { | |||||
| return (*S2STransfer)(nil), nil | |||||
| } | |||||
| cred, ok := b.detail.UserSpace.Credential.(*cortypes.OBSCred) | cred, ok := b.detail.UserSpace.Credential.(*cortypes.OBSCred) | ||||
| if !ok { | if !ok { | ||||
| return nil, fmt.Errorf("invalid storage credential type %T for obs storage", b.detail.UserSpace.Credential) | return nil, fmt.Errorf("invalid storage credential type %T for obs storage", b.detail.UserSpace.Credential) | ||||
| @@ -32,16 +32,16 @@ func (b *builder) FeatureDesc() types.FeatureDesc { | |||||
| } | } | ||||
| func (b *builder) CreateShardStore(typeOnly bool) (types.ShardStore, error) { | func (b *builder) CreateShardStore(typeOnly bool) (types.ShardStore, error) { | ||||
| if typeOnly { | |||||
| return (*ShardStore)(nil), nil | |||||
| } | |||||
| stgType := b.detail.UserSpace.Storage.(*cortypes.S3Type) | stgType := b.detail.UserSpace.Storage.(*cortypes.S3Type) | ||||
| s3Cred, ok := b.detail.UserSpace.Credential.(*cortypes.S3Cred) | s3Cred, ok := b.detail.UserSpace.Credential.(*cortypes.S3Cred) | ||||
| if !ok { | if !ok { | ||||
| return nil, fmt.Errorf("invalid storage credential type %T for s3 storage", b.detail.UserSpace.Credential) | return nil, fmt.Errorf("invalid storage credential type %T for s3 storage", b.detail.UserSpace.Credential) | ||||
| } | } | ||||
| if typeOnly { | |||||
| return (*ShardStore)(nil), nil | |||||
| } | |||||
| cli, bkt, err := createClient(stgType, s3Cred) | cli, bkt, err := createClient(stgType, s3Cred) | ||||
| if err != nil { | if err != nil { | ||||
| return nil, err | return nil, err | ||||
| @@ -51,15 +51,16 @@ func (b *builder) CreateShardStore(typeOnly bool) (types.ShardStore, error) { | |||||
| } | } | ||||
| func (b *builder) CreateBaseStore(typeOnly bool) (types.BaseStore, error) { | func (b *builder) CreateBaseStore(typeOnly bool) (types.BaseStore, error) { | ||||
| if typeOnly { | |||||
| return (*BaseStore)(nil), nil | |||||
| } | |||||
| stgType := b.detail.UserSpace.Storage.(*cortypes.S3Type) | stgType := b.detail.UserSpace.Storage.(*cortypes.S3Type) | ||||
| s3Cred, ok := b.detail.UserSpace.Credential.(*cortypes.S3Cred) | s3Cred, ok := b.detail.UserSpace.Credential.(*cortypes.S3Cred) | ||||
| if !ok { | if !ok { | ||||
| return nil, fmt.Errorf("invalid storage credential type %T for s3 storage", b.detail.UserSpace.Credential) | return nil, fmt.Errorf("invalid storage credential type %T for s3 storage", b.detail.UserSpace.Credential) | ||||
| } | } | ||||
| if typeOnly { | |||||
| return (*BaseStore)(nil), nil | |||||
| } | |||||
| cli, bkt, err := createClient(stgType, s3Cred) | cli, bkt, err := createClient(stgType, s3Cred) | ||||
| if err != nil { | if err != nil { | ||||
| return nil, err | return nil, err | ||||
| @@ -91,10 +92,6 @@ func createClient(stgType *cortypes.S3Type, cred *cortypes.S3Cred) (*s3.Client, | |||||
| } | } | ||||
| func (b *builder) CreateMultiparter(typeOnly bool) (types.Multiparter, error) { | func (b *builder) CreateMultiparter(typeOnly bool) (types.Multiparter, error) { | ||||
| if typeOnly { | |||||
| return (*Multiparter)(nil), nil | |||||
| } | |||||
| stgType := b.detail.UserSpace.Storage.(*cortypes.S3Type) | stgType := b.detail.UserSpace.Storage.(*cortypes.S3Type) | ||||
| feat := types.FindFeature[*cortypes.MultipartUploadFeature](b.detail) | feat := types.FindFeature[*cortypes.MultipartUploadFeature](b.detail) | ||||
| if feat == nil { | if feat == nil { | ||||
| @@ -106,6 +103,10 @@ func (b *builder) CreateMultiparter(typeOnly bool) (types.Multiparter, error) { | |||||
| return nil, fmt.Errorf("invalid storage credential type %T for s3 base store", b.detail.UserSpace.Credential) | return nil, fmt.Errorf("invalid storage credential type %T for s3 base store", b.detail.UserSpace.Credential) | ||||
| } | } | ||||
| if typeOnly { | |||||
| return (*Multiparter)(nil), nil | |||||
| } | |||||
| cli, bucket, err := createClient(stgType, s3Cred) | cli, bucket, err := createClient(stgType, s3Cred) | ||||
| if err != nil { | if err != nil { | ||||
| return nil, err | return nil, err | ||||