Add StatusCids() to Restapi client
This commit is contained in:
parent
a046af811c
commit
a1b6dabbb0
|
@ -84,6 +84,8 @@ type Client interface {
|
|||
// the information affects only the current peer, otherwise the information
|
||||
// is fetched from all cluster peers.
|
||||
Status(ctx context.Context, ci cid.Cid, local bool) (*api.GlobalPinInfo, error)
|
||||
// StatusCids status information for the requested CIDs.
|
||||
StatusCids(ctx context.Context, cids []cid.Cid, local bool) ([]*api.GlobalPinInfo, error)
|
||||
// StatusAll gathers Status() for all tracked items.
|
||||
StatusAll(ctx context.Context, filter api.TrackerStatus, local bool) ([]*api.GlobalPinInfo, error)
|
||||
|
||||
|
|
|
@ -253,6 +253,21 @@ func (lc *loadBalancingClient) Status(ctx context.Context, ci cid.Cid, local boo
|
|||
return pinInfo, err
|
||||
}
|
||||
|
||||
// StatusCids returns Status() information for the given Cids. If local is
|
||||
// true, the information affects only the current peer, otherwise the
|
||||
// information is fetched from all cluster peers.
|
||||
func (lc *loadBalancingClient) StatusCids(ctx context.Context, cids []cid.Cid, local bool) ([]*api.GlobalPinInfo, error) {
|
||||
var pinInfos []*api.GlobalPinInfo
|
||||
call := func(c Client) error {
|
||||
var err error
|
||||
pinInfos, err = c.StatusCids(ctx, cids, local)
|
||||
return err
|
||||
}
|
||||
|
||||
err := lc.retry(0, call)
|
||||
return pinInfos, err
|
||||
}
|
||||
|
||||
// StatusAll gathers Status() for all tracked items. If a filter is
|
||||
// provided, only entries matching the given filter statuses
|
||||
// will be returned. A filter can be built by merging TrackerStatuses with
|
||||
|
|
|
@ -220,12 +220,23 @@ func (c *defaultClient) Status(ctx context.Context, ci cid.Cid, local bool) (*ap
|
|||
return &gpi, err
|
||||
}
|
||||
|
||||
// StatusCids returns Status() information for the given Cids. If local is
|
||||
// true, the information affects only the current peer, otherwise the
|
||||
// information is fetched from all cluster peers.
|
||||
func (c *defaultClient) StatusCids(ctx context.Context, cids []cid.Cid, local bool) ([]*api.GlobalPinInfo, error) {
|
||||
return c.statusAllWithCids(ctx, api.TrackerStatusUndefined, cids, local)
|
||||
}
|
||||
|
||||
// StatusAll gathers Status() for all tracked items. If a filter is
|
||||
// provided, only entries matching the given filter statuses
|
||||
// will be returned. A filter can be built by merging TrackerStatuses with
|
||||
// a bitwise OR operation (st1 | st2 | ...). A "0" filter value (or
|
||||
// api.TrackerStatusUndefined), means all.
|
||||
func (c *defaultClient) StatusAll(ctx context.Context, filter api.TrackerStatus, local bool) ([]*api.GlobalPinInfo, error) {
|
||||
return c.statusAllWithCids(ctx, filter, nil, local)
|
||||
}
|
||||
|
||||
func (c *defaultClient) statusAllWithCids(ctx context.Context, filter api.TrackerStatus, cids []cid.Cid, local bool) ([]*api.GlobalPinInfo, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "client/StatusAll")
|
||||
defer span.End()
|
||||
|
||||
|
@ -239,10 +250,16 @@ func (c *defaultClient) StatusAll(ctx context.Context, filter api.TrackerStatus,
|
|||
}
|
||||
}
|
||||
|
||||
var cidsStr []string
|
||||
for _, c := range cids {
|
||||
cidsStr = append(cidsStr, c.String())
|
||||
}
|
||||
|
||||
err := c.do(
|
||||
ctx,
|
||||
"GET",
|
||||
fmt.Sprintf("/pins?local=%t&filter=%s", local, url.QueryEscape(filterStr)),
|
||||
fmt.Sprintf("/pins?local=%t&filter=%s&cids=%s",
|
||||
local, url.QueryEscape(filterStr), strings.Join(cidsStr, ",")),
|
||||
nil,
|
||||
nil,
|
||||
&gpis,
|
||||
|
|
|
@ -327,6 +327,27 @@ func TestStatus(t *testing.T) {
|
|||
testClients(t, api, testF)
|
||||
}
|
||||
|
||||
func TestStatusCids(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
api := testAPI(t)
|
||||
defer shutdown(api)
|
||||
|
||||
testF := func(t *testing.T, c Client) {
|
||||
pins, err := c.StatusCids(ctx, []cid.Cid{test.Cid1}, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(pins) != 1 {
|
||||
t.Fatal("wrong number of pins returned")
|
||||
}
|
||||
if !pins[0].Cid.Equals(test.Cid1) {
|
||||
t.Error("should be same pin")
|
||||
}
|
||||
}
|
||||
|
||||
testClients(t, api, testF)
|
||||
}
|
||||
|
||||
func TestStatusAll(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
api := testAPI(t)
|
||||
|
|
Loading…
Reference in New Issue
Block a user