From 841c7d5ee8e6cf3d626aaa9298f61080aee8a5ce Mon Sep 17 00:00:00 2001 From: Abhishek Jain Date: Fri, 24 Mar 2017 16:27:14 -0400 Subject: [PATCH] Added AddHostIfNew(..) utility function which is responsible to populate the constants.Hosts and constants.PowerClasses --- utilities/offerUtils/offerUtils.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/utilities/offerUtils/offerUtils.go b/utilities/offerUtils/offerUtils.go index 6f5dc81..9d0034a 100644 --- a/utilities/offerUtils/offerUtils.go +++ b/utilities/offerUtils/offerUtils.go @@ -1,8 +1,11 @@ package offerUtils import ( + "bitbucket.org/sunybingcloud/electron/constants" mesos "github.com/mesos/mesos-go/mesosproto" "strings" + "log" + "bitbucket.org/sunybingcloud/electron-archive/utilities/offerUtils" ) func OfferAgg(offer *mesos.Offer) (float64, float64, float64) { @@ -60,3 +63,26 @@ func HostMismatch(offerHost string, taskHost string) bool { } 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{}{} + } + } +} \ No newline at end of file