Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repurpose CidInfo #689

Merged
merged 2 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions api/client/ffs.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ func (f *FFS) SetDefaultStorageConfig(ctx context.Context, config *rpc.StorageCo
return f.client.SetDefaultStorageConfig(ctx, req)
}

// CidData returns information about cids managed by the FFS instance.
func (f *FFS) CidData(ctx context.Context, cids ...string) (*rpc.CidDataResponse, error) {
return f.client.CidData(ctx, &rpc.CidDataRequest{Cids: cids})
// CidInfo returns information about cids managed by the FFS instance.
func (f *FFS) CidInfo(ctx context.Context, cids ...string) (*rpc.CidInfoResponse, error) {
return f.client.CidInfo(ctx, &rpc.CidInfoRequest{Cids: cids})
}

// CancelJob signals that the executing Job with JobID jid should be
Expand Down
8 changes: 4 additions & 4 deletions cmd/pow/cmd/ffs_data.go → cmd/pow/cmd/ffs_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
)

func init() {
ffsCmd.AddCommand(ffsDataCmd)
ffsCmd.AddCommand(ffsInfoCmd)
}

var ffsDataCmd = &cobra.Command{
Use: "data [optional cid1,cid2,...]",
var ffsInfoCmd = &cobra.Command{
Use: "info [optional cid1,cid2,...]",
Short: "Get information about the current state of cid storage",
Long: `Get information about the current state of cid storage`,
Args: cobra.MaximumNArgs(1),
Expand All @@ -32,7 +32,7 @@ var ffsDataCmd = &cobra.Command{
cids = strings.Split(args[0], ",")
}

res, err := fcClient.FFS.CidData(mustAuthCtx(ctx), cids...)
res, err := fcClient.FFS.CidInfo(mustAuthCtx(ctx), cids...)
checkErr(err)

json, err := protojson.MarshalOptions{Multiline: true, Indent: " ", EmitUnpopulated: true}.Marshal(res)
Expand Down
4 changes: 2 additions & 2 deletions ffs/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ func (i *API) GetStorageConfigs(cids ...cid.Cid) (map[cid.Cid]ffs.StorageConfig,

// Show returns the information about a stored Cid. If no information is available,
// since the Cid was never stored, it returns ErrNotFound.
func (i *API) Show(cid cid.Cid) (ffs.CidInfo, error) {
inf, err := i.sched.GetCidInfo(cid)
func (i *API) Show(cid cid.Cid) (ffs.StorageInfo, error) {
inf, err := i.sched.GetStorageInfo(cid)
if err == scheduler.ErrNotFound {
return inf, ErrNotFound
}
Expand Down
4 changes: 2 additions & 2 deletions ffs/api/api_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (i *API) ImportStorage(payloadCid cid.Cid, pieceCid cid.Cid, deals []Import
}
}

cinfo := ffs.CidInfo{
cinfo := ffs.StorageInfo{
JobID: ffs.EmptyJobID,
Cid: payloadCid,
Created: time.Now(),
Expand All @@ -57,7 +57,7 @@ func (i *API) ImportStorage(payloadCid cid.Cid, pieceCid cid.Cid, deals []Import
},
}

if err := i.sched.ImportCidInfo(cinfo); err != nil {
if err := i.sched.ImportStorageInfo(cinfo); err != nil {
return fmt.Errorf("importing cid info in scheduler: %s", err)
}

Expand Down
30 changes: 15 additions & 15 deletions ffs/rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ func (s *RPC) SetDefaultStorageConfig(ctx context.Context, req *SetDefaultStorag
return &SetDefaultStorageConfigResponse{}, nil
}

// CidData returns information about cids managed by the FFS instance.
func (s *RPC) CidData(ctx context.Context, req *CidDataRequest) (*CidDataResponse, error) {
// CidInfo returns information about cids managed by the FFS instance.
func (s *RPC) CidInfo(ctx context.Context, req *CidInfoRequest) (*CidInfoResponse, error) {
i, err := s.getInstanceByToken(ctx)
if err != nil {
return nil, err
Expand All @@ -176,18 +176,18 @@ func (s *RPC) CidData(ctx context.Context, req *CidDataRequest) (*CidDataRespons
}
return nil, status.Errorf(code, "getting storage configs: %v", err)
}
res := make([]*CidData, 0, len(storageConfigs))
res := make([]*CidInfo, 0, len(storageConfigs))
for cid, config := range storageConfigs {
rpcConfig := ToRPCStorageConfig(config)
cidData := &CidData{
cidInfo := &CidInfo{
Cid: cid.String(),
LatestPushedStorageConfig: rpcConfig,
}
info, err := i.Show(cid)
if err != nil && err != api.ErrNotFound {
return nil, status.Errorf(codes.Internal, "getting storage info: %v", err)
} else if err == nil {
cidData.CurrentCidInfo = toRPCCidInfo(info)
cidInfo.CurrentStorageInfo = toRPCStorageInfo(info)
}
queuedJobs := i.QueuedStorageJobs(cid)
rpcQueudJobs := make([]*Job, len(queuedJobs))
Expand All @@ -198,34 +198,34 @@ func (s *RPC) CidData(ctx context.Context, req *CidDataRequest) (*CidDataRespons
}
rpcQueudJobs[i] = rpcJob
}
cidData.QueuedStorageJobs = rpcQueudJobs
cidInfo.QueuedStorageJobs = rpcQueudJobs
executingJobs := i.ExecutingStorageJobs()
if len(executingJobs) > 0 {
rpcJob, err := toRPCJob(executingJobs[0])
if err != nil {
return nil, status.Errorf(codes.Internal, "converting job to rpc job: %v", err)
}
cidData.ExecutingStorageJob = rpcJob
cidInfo.ExecutingStorageJob = rpcJob
}
finalJobs := i.LatestFinalStorageJobs(cid)
if len(finalJobs) > 0 {
rpcJob, err := toRPCJob(finalJobs[0])
if err != nil {
return nil, status.Errorf(codes.Internal, "converting job to rpc job: %v", err)
}
cidData.LatestFinalStorageJob = rpcJob
cidInfo.LatestFinalStorageJob = rpcJob
}
successfulJobs := i.LatestSuccessfulStorageJobs(cid)
if len(successfulJobs) > 0 {
rpcJob, err := toRPCJob(successfulJobs[0])
if err != nil {
return nil, status.Errorf(codes.Internal, "converting job to rpc job: %v", err)
}
cidData.LatestSuccessfulStorageJob = rpcJob
cidInfo.LatestSuccessfulStorageJob = rpcJob
}
res = append(res, cidData)
res = append(res, cidInfo)
}
return &CidDataResponse{CidDatas: res}, nil
return &CidInfoResponse{CidInfos: res}, nil
}

// CancelJob calls API.CancelJob.
Expand Down Expand Up @@ -821,8 +821,8 @@ func fromRPCColdConfig(config *ColdConfig) ffs.ColdConfig {
return res
}

func toRPCCidInfo(info ffs.CidInfo) *CidInfo {
cidInfo := &CidInfo{
func toRPCStorageInfo(info ffs.StorageInfo) *StorageInfo {
storageInfo := &StorageInfo{
JobId: info.JobID.String(),
Cid: util.CidToString(info.Cid),
Created: info.Created.UnixNano(),
Expand Down Expand Up @@ -851,7 +851,7 @@ func toRPCCidInfo(info ffs.CidInfo) *CidInfo {
if p.PieceCid.Defined() {
strPieceCid = util.CidToString(p.PieceCid)
}
cidInfo.Cold.Filecoin.Proposals[i] = &FilStorage{
storageInfo.Cold.Filecoin.Proposals[i] = &FilStorage{
ProposalCid: strProposalCid,
PieceCid: strPieceCid,
Renewed: p.Renewed,
Expand All @@ -862,7 +862,7 @@ func toRPCCidInfo(info ffs.CidInfo) *CidInfo {
EpochPrice: p.EpochPrice,
}
}
return cidInfo
return storageInfo
}

func toRPCPaychInfo(info ffs.PaychInfo) *PaychInfo {
Expand Down
Loading