Changed the Hosts from list to a set of hosts using a map with key as hostname and value as an empty struct
This commit is contained in:
parent
8b7a57519b
commit
9365c2e51d
2 changed files with 1 additions and 66 deletions
|
@ -7,10 +7,7 @@ TODO: Clean this up and use Mesos Attributes instead.
|
|||
*/
|
||||
package constants
|
||||
|
||||
var Hosts = []string{"stratos-001.cs.binghamton.edu", "stratos-002.cs.binghamton.edu",
|
||||
"stratos-003.cs.binghamton.edu", "stratos-004.cs.binghamton.edu",
|
||||
"stratos-005.cs.binghamton.edu", "stratos-006.cs.binghamton.edu",
|
||||
"stratos-007.cs.binghamton.edu", "stratos-008.cs.binghamton.edu"}
|
||||
var Hosts = make(map[string]struct{})
|
||||
|
||||
/*
|
||||
Classification of the nodes in the cluster based on their Thermal Design Power (TDP).
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
package offerUtils
|
||||
|
||||
import (
|
||||
mesos "github.com/mesos/mesos-go/mesosproto"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func OfferAgg(offer *mesos.Offer) (float64, float64, float64) {
|
||||
var cpus, mem, watts float64
|
||||
|
||||
for _, resource := range offer.Resources {
|
||||
switch resource.GetName() {
|
||||
case "cpus":
|
||||
cpus += *resource.GetScalar().Value
|
||||
case "mem":
|
||||
mem += *resource.GetScalar().Value
|
||||
case "watts":
|
||||
watts += *resource.GetScalar().Value
|
||||
}
|
||||
}
|
||||
|
||||
return cpus, mem, watts
|
||||
}
|
||||
|
||||
// Determine the power class of the host in the offer
|
||||
func PowerClass(offer *mesos.Offer) string {
|
||||
var powerClass string
|
||||
for _, attr := range offer.GetAttributes() {
|
||||
if attr.GetName() == "class" {
|
||||
powerClass = attr.GetText().GetValue()
|
||||
}
|
||||
}
|
||||
return powerClass
|
||||
}
|
||||
|
||||
// Implements the sort.Sort interface to sort Offers based on CPU.
|
||||
// TODO: Have a generic sorter that sorts based on a defined requirement (CPU, RAM, DISK or Watts)
|
||||
type OffersSorter []*mesos.Offer
|
||||
|
||||
func (offersSorter OffersSorter) Len() int {
|
||||
return len(offersSorter)
|
||||
}
|
||||
|
||||
func (offersSorter OffersSorter) Swap(i, j int) {
|
||||
offersSorter[i], offersSorter[j] = offersSorter[j], offersSorter[i]
|
||||
}
|
||||
|
||||
func (offersSorter OffersSorter) Less(i, j int) bool {
|
||||
// getting CPU resource availability of offersSorter[i]
|
||||
cpu1, _, _ := OfferAgg(offersSorter[i])
|
||||
// getting CPU resource availability of offersSorter[j]
|
||||
cpu2, _, _ := OfferAgg(offersSorter[j])
|
||||
return cpu1 <= cpu2
|
||||
}
|
||||
|
||||
// Is there a mismatch between the task's host requirement and the host corresponding to the offer.
|
||||
func HostMismatch(offerHost string, taskHost string) bool {
|
||||
if taskHost != "" && !strings.HasPrefix(offerHost, taskHost) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
Reference in a new issue