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

Improvements #2

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ClusterAPI interface {
List(ctx context.Context, opts ...ListOption) ([]Cluster, error)

// Remove destroys clusters permanently.
Remove(ctx context.Context, names ...string) error
Remove(ctx context.Context, force bool, names ...string) error
}

// Cluster is a group of instances connected in a p2p network. They can be
Expand Down
8 changes: 7 additions & 1 deletion cmd/labctl/command/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ var clusterCommand = cli.Command{
Aliases: []string{"rm"},
Usage: "Remove clusters.",
Action: removeClustersAction,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "force",
Usage: "force removal to ignore possible staleness and other misc issues",
},
},
},
},
}
Expand Down Expand Up @@ -251,7 +257,7 @@ func removeClustersAction(c *cli.Context) error {
}

ctx := cliutil.CommandContext(c)
err = control.Cluster().Remove(ctx, names...)
err = control.Cluster().Remove(ctx, c.Bool("force"), names...)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion labapp/labapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ func New(ctx context.Context, root, addr string, port int, logger *zerolog.Logge
pctx, cancel := context.WithCancel(ctx)
p, err := peer.New(pctx, root, port, pdef)
if err != nil {
cancel()
return nil, err
}
closers = append(closers, &daemon.CancelCloser{cancel})
closers = append(closers, &daemon.CancelCloser{Cancel: cancel})

daemon, err := daemon.New("labapp", addr, logger,
approuter.New(p),
Expand Down
5 changes: 3 additions & 2 deletions labd/controlapi/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ func (a *clusterAPI) List(ctx context.Context, opts ...p2plab.ListOption) ([]p2p
type Event struct {
}

func (a *clusterAPI) Remove(ctx context.Context, names ...string) error {
func (a *clusterAPI) Remove(ctx context.Context, force bool, names ...string) error {
req := a.client.NewRequest("DELETE", a.url("/clusters/delete")).
Option("names", strings.Join(names, ","))
Option("names", strings.Join(names, ",")).
Option("force", force)

resp, err := req.Send(ctx)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion labd/labd.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ func New(root, addr string, logger *zerolog.Logger, opts ...LabdOption) (*Labd,
Routing: "nil",
})
if err != nil {
cancel()
return nil, errors.Wrap(err, "failed to create seeder peer")
}
closers = append(closers, &daemon.CancelCloser{cancel})
closers = append(closers, &daemon.CancelCloser{Cancel: cancel})

ts := transformers.New(filepath.Join(root, "transformers"), client.HTTPClient)
closers = append(closers, ts)
Expand Down
7 changes: 5 additions & 2 deletions labd/routers/clusterrouter/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ func (s *router) putClustersLabel(ctx context.Context, w http.ResponseWriter, r

func (s *router) deleteClusters(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
names := strings.Split(r.FormValue("names"), ",")

var force bool
if r.FormValue("force") != "" {
force = true
}
ctx, logger := logutil.WithResponseLogger(ctx, w)

// TODO: parallelize with different color loggers?
Expand All @@ -185,7 +188,7 @@ func (s *router) deleteClusters(ctx context.Context, w http.ResponseWriter, r *h
return errors.Wrapf(err, "failed to get cluster %q", name)
}

if cluster.Status != metadata.ClusterDestroying {
if cluster.Status != metadata.ClusterDestroying || force {
cluster.Status = metadata.ClusterDestroying
cluster, err = s.db.UpdateCluster(ctx, cluster)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions peer/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (p *Peer) Report(ctx context.Context) (metadata.ReportNode, error) {
}

return metadata.ReportNode{
metadata.ReportBitswap{
Bitswap: metadata.ReportBitswap{
BlocksReceived: stat.BlocksReceived,
DataReceived: stat.DataReceived,
BlocksSent: stat.BlocksSent,
Expand All @@ -302,7 +302,7 @@ func (p *Peer) Report(ctx context.Context) (metadata.ReportNode, error) {
DupDataReceived: stat.DupDataReceived,
MessagesReceived: stat.MessagesReceived,
},
metadata.ReportBandwidth{
Bandwidth: metadata.ReportBandwidth{
Totals: p.reporter.GetBandwidthTotals(),
Peers: peers,
Protocols: p.reporter.GetBandwidthByProtocol(),
Expand Down