From c1020da6366d3e77306ed028d90bf87bee354884 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 4 Jun 2015 18:25:32 -0700 Subject: [PATCH] nits Signed-off-by: Victor Vieux --- api/handlers.go | 7 +++---- cluster/cluster.go | 8 +++++++- cluster/mesos/cluster.go | 16 ++++++++++++++-- cluster/swarm/cluster.go | 28 ++++++++++++++++++++++------ 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/api/handlers.go b/api/handlers.go index 97c6669f2b..e7468eefa4 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -24,18 +24,17 @@ const APIVERSION = "1.16" // GET /info func getInfo(c *context, w http.ResponseWriter, r *http.Request) { - clusterInfo, totalMemory, totalCpus := c.cluster.Info() info := dockerclient.Info{ Containers: int64(len(c.cluster.Containers())), Images: int64(len(c.cluster.Images())), - DriverStatus: clusterInfo, + DriverStatus: c.cluster.Info(), NEventsListener: int64(c.eventsHandler.Size()), Debug: c.debug, MemoryLimit: true, SwapLimit: true, IPv4Forwarding: true, - NCPU: totalCpus, - MemTotal: totalMemory, + NCPU: c.cluster.TotalCpus(), + MemTotal: c.cluster.TotalMemory(), } w.Header().Set("Content-Type", "application/json") diff --git a/cluster/cluster.go b/cluster/cluster.go index 598f4e08c4..f1c5fd4120 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -51,7 +51,13 @@ type Cluster interface { // Return some info about the cluster, like nb or containers / images // It is pretty open, so the implementation decides what to return. - Info() ([][]string, int64, int64) + Info() [][]string + + // Return the total memory of the cluster + TotalMemory() int64 + + // Return the number of CPUs in the cluster + TotalCpus() int64 // Register an event handler for cluster-wide events. RegisterEventHandler(h EventHandler) error diff --git a/cluster/mesos/cluster.go b/cluster/mesos/cluster.go index 01c401a9f2..31ab34c8cc 100644 --- a/cluster/mesos/cluster.go +++ b/cluster/mesos/cluster.go @@ -302,8 +302,20 @@ func (c *Cluster) listOffers() []*mesosproto.Offer { return list } +// TotalMemory return the total memory of the cluster +func (c *Cluster) TotalMemory() int64 { + // TODO: use current offers + return 0 +} + +// TotalCpus return the total memory of the cluster +func (c *Cluster) TotalCpus() int64 { + // TODO: use current offers + return 0 +} + // Info gives minimal information about containers and resources on the mesos cluster -func (c *Cluster) Info() ([][]string, int64, int64) { +func (c *Cluster) Info() [][]string { offers := c.listOffers() info := [][]string{ {"\bStrategy", c.scheduler.Strategy()}, @@ -320,7 +332,7 @@ func (c *Cluster) Info() ([][]string, int64, int64) { } } - return info, 0, 0 + return info } func (c *Cluster) addOffer(offer *mesosproto.Offer) { diff --git a/cluster/swarm/cluster.go b/cluster/swarm/cluster.go index ca32cf8f17..86e635c6bc 100644 --- a/cluster/swarm/cluster.go +++ b/cluster/swarm/cluster.go @@ -497,9 +497,27 @@ func (c *Cluster) listEngines() []*cluster.Engine { return out } -// Info is exported -func (c *Cluster) Info() (info [][]string, totalMemory int64, totalCpus int64) { - info = [][]string{ +// TotalMemory return the total memory of the cluster +func (c *Cluster) TotalMemory() int64 { + var totalMemory int64 + for _, engine := range c.engines { + totalMemory += engine.TotalMemory() + } + return totalMemory +} + +// TotalCpus return the total memory of the cluster +func (c *Cluster) TotalCpus() int64 { + var totalCpus int64 + for _, engine := range c.engines { + totalCpus += engine.TotalCpus() + } + return totalCpus +} + +// Info returns some info about the cluster, like nb or containers / images +func (c *Cluster) Info() [][]string { + info := [][]string{ {"\bStrategy", c.scheduler.Strategy()}, {"\bFilters", c.scheduler.Filters()}, {"\bNodes", fmt.Sprintf("%d", len(c.engines))}, @@ -519,11 +537,9 @@ func (c *Cluster) Info() (info [][]string, totalMemory int64, totalCpus int64) { } sort.Strings(labels) info = append(info, []string{" └ Labels", fmt.Sprintf("%s", strings.Join(labels, ", "))}) - totalMemory += engine.TotalMemory() - totalCpus += engine.TotalCpus() } - return info, totalMemory, totalCpus + return info } // RANDOMENGINE returns a random engine.