Added AddHostIfNew(..) utility function which is responsible to populate the constants.Hosts and constants.PowerClasses
This commit is contained in:
parent
ed8799566b
commit
841c7d5ee8
1 changed files with 26 additions and 0 deletions
|
@ -1,8 +1,11 @@
|
||||||
package offerUtils
|
package offerUtils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bitbucket.org/sunybingcloud/electron/constants"
|
||||||
mesos "github.com/mesos/mesos-go/mesosproto"
|
mesos "github.com/mesos/mesos-go/mesosproto"
|
||||||
"strings"
|
"strings"
|
||||||
|
"log"
|
||||||
|
"bitbucket.org/sunybingcloud/electron-archive/utilities/offerUtils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func OfferAgg(offer *mesos.Offer) (float64, float64, float64) {
|
func OfferAgg(offer *mesos.Offer) (float64, float64, float64) {
|
||||||
|
@ -60,3 +63,26 @@ func HostMismatch(offerHost string, taskHost string) bool {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the host in the offer is a new host, add the host to the set of Hosts and
|
||||||
|
// register the powerclass of this host.
|
||||||
|
func AddHostIfNew(offer *mesos.Offer) {
|
||||||
|
var host = offer.GetHostname()
|
||||||
|
// If this host is not present in the set of hosts.
|
||||||
|
if _, ok := constants.Hosts[host]; !ok {
|
||||||
|
log.Printf("New host found. Adding host [%s]", host)
|
||||||
|
// Add this host.
|
||||||
|
constants.Hosts[host] = struct{}{}
|
||||||
|
// Get the power class of this host.
|
||||||
|
var class = offerUtils.PowerClass(offer)
|
||||||
|
log.Printf("Registering the power class of this host [%s] --> [%s]", host, class)
|
||||||
|
// If this class is a new power class, create a map for this class.
|
||||||
|
if _, ok := constants.PowerClasses[class]; !ok {
|
||||||
|
constants.PowerClasses[class] = make(map[string]struct{})
|
||||||
|
}
|
||||||
|
// If the host of this class is not yet present in PowerClasses[class], add it.
|
||||||
|
if _, ok:= constants.PowerClasses[class][host]; !ok{
|
||||||
|
constants.PowerClasses[class][host] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue