BUG Fix1: taskID creation in taskUtils#initTaskResourceRequirements. BUG Fix2: Converted value in utilities/trackResourceUsage#TrackResourceUsage#perHostResourceAvailability to be a pointer to ResourceCount.

This commit is contained in:
Pradyumna Kaushik 2018-01-29 18:03:46 -05:00
parent 657dc8df93
commit c31bf8db01
3 changed files with 33 additions and 29 deletions

View file

@ -140,7 +140,7 @@ func initTaskResourceRequirements(tasks []Task) {
baseTaskID := "electron-" baseTaskID := "electron-"
for _, task := range tasks { for _, task := range tasks {
for i := *task.Instances; i > 0; i-- { for i := *task.Instances; i > 0; i-- {
taskID := fmt.Sprintf("%s-%d", baseTaskID + task.Name, *task.Instances) taskID := fmt.Sprintf("%s-%d", baseTaskID + task.Name, i)
taskResourceRequirement[taskID] = &TaskResources{ taskResourceRequirement[taskID] = &TaskResources{
CPU: task.CPU, CPU: task.CPU,
Ram: task.RAM, Ram: task.RAM,

View file

@ -9,6 +9,7 @@ import (
"bitbucket.org/sunybingcloud/elektron/utilities/mesosUtils" "bitbucket.org/sunybingcloud/elektron/utilities/mesosUtils"
mesos "github.com/mesos/mesos-go/api/v0/mesosproto" mesos "github.com/mesos/mesos-go/api/v0/mesosproto"
sched "github.com/mesos/mesos-go/api/v0/scheduler" sched "github.com/mesos/mesos-go/api/v0/scheduler"
"log"
) )
func coLocated(tasks map[string]bool, s baseScheduler) { func coLocated(tasks map[string]bool, s baseScheduler) {
@ -131,6 +132,9 @@ func LaunchTasks(offerIDs []*mesos.OfferID, tasksToLaunch []*mesos.TaskInfo, dri
var err error var err error
for _, task := range tasksToLaunch { for _, task := range tasksToLaunch {
err = utilities.ResourceAvailabilityUpdate("ON_TASK_ACTIVE_STATE", *task.TaskId, *task.SlaveId) err = utilities.ResourceAvailabilityUpdate("ON_TASK_ACTIVE_STATE", *task.TaskId, *task.SlaveId)
if err != nil {
log.Println(err)
}
} }
return err return err
} }

View file

@ -9,7 +9,7 @@ import (
) )
type TrackResourceUsage struct { type TrackResourceUsage struct {
perHostResourceAvailability map[string]ResourceCount perHostResourceAvailability map[string]*ResourceCount
sync.Mutex sync.Mutex
} }
@ -17,28 +17,28 @@ type TrackResourceUsage struct {
// This information is maintained for each node in the cluster. // This information is maintained for each node in the cluster.
type ResourceCount struct { type ResourceCount struct {
// Total resources available. // Total resources available.
totalCPU float64 TotalCPU float64
totalRAM float64 TotalRAM float64
totalWatts float64 TotalWatts float64
// Resources currently unused. // Resources currently unused.
unusedCPU float64 UnusedCPU float64
unusedRAM float64 UnusedRAM float64
unusedWatts float64 UnusedWatts float64
} }
// Increment unused resources. // Increment unused resources.
func (rc *ResourceCount) IncrUnusedResources(tr def.TaskResources) { func (rc *ResourceCount) IncrUnusedResources(tr def.TaskResources) {
rc.unusedCPU += tr.CPU rc.UnusedCPU += tr.CPU
rc.unusedRAM += tr.Ram rc.UnusedRAM += tr.Ram
rc.unusedWatts += tr.Watts rc.UnusedWatts += tr.Watts
} }
// Decrement unused resources. // Decrement unused resources.
func (rc *ResourceCount) DecrUnusedResources(tr def.TaskResources) { func (rc *ResourceCount) DecrUnusedResources(tr def.TaskResources) {
rc.unusedCPU -= tr.CPU rc.UnusedCPU -= tr.CPU
rc.unusedRAM -= tr.Ram rc.UnusedRAM -= tr.Ram
rc.unusedWatts -= tr.Watts rc.UnusedWatts -= tr.Watts
} }
var truInstance *TrackResourceUsage var truInstance *TrackResourceUsage
@ -52,7 +52,7 @@ func getTRUInstance() *TrackResourceUsage {
func newResourceUsageTracker() *TrackResourceUsage { func newResourceUsageTracker() *TrackResourceUsage {
return &TrackResourceUsage{ return &TrackResourceUsage{
perHostResourceAvailability: make(map[string]ResourceCount), perHostResourceAvailability: make(map[string]*ResourceCount),
} }
} }
@ -65,15 +65,15 @@ func RecordTotalResourceAvailability(offers []*mesos.Offer) {
// If first offer received from Mesos Agent. // If first offer received from Mesos Agent.
if _, ok := tru.perHostResourceAvailability[*offer.SlaveId.Value]; !ok { if _, ok := tru.perHostResourceAvailability[*offer.SlaveId.Value]; !ok {
cpu, mem, watts := offerUtils.OfferAgg(offer) cpu, mem, watts := offerUtils.OfferAgg(offer)
tru.perHostResourceAvailability[*offer.SlaveId.Value] = ResourceCount{ tru.perHostResourceAvailability[*offer.SlaveId.Value] = &ResourceCount{
totalCPU: cpu, TotalCPU: cpu,
totalRAM: mem, TotalRAM: mem,
totalWatts: watts, TotalWatts: watts,
// Initially, all resources are used. // Initially, all resources are used.
unusedCPU: cpu, UnusedCPU: cpu,
unusedRAM: mem, UnusedRAM: mem,
unusedWatts: watts, UnusedWatts: watts,
} }
} }
} }
@ -139,21 +139,21 @@ func GetClusterwideResourceAvailability() ResourceCount {
clusterwideResourceCount := ResourceCount{} clusterwideResourceCount := ResourceCount{}
for _, resCount := range tru.perHostResourceAvailability { for _, resCount := range tru.perHostResourceAvailability {
// Aggregating the total CPU, RAM and Watts. // Aggregating the total CPU, RAM and Watts.
clusterwideResourceCount.totalCPU += resCount.totalCPU clusterwideResourceCount.TotalCPU += resCount.TotalCPU
clusterwideResourceCount.totalRAM += resCount.totalRAM clusterwideResourceCount.TotalRAM += resCount.TotalRAM
clusterwideResourceCount.totalWatts += resCount.totalWatts clusterwideResourceCount.TotalWatts += resCount.TotalWatts
// Aggregating the total unused CPU, RAM and Watts. // Aggregating the total unused CPU, RAM and Watts.
clusterwideResourceCount.unusedCPU += resCount.unusedCPU clusterwideResourceCount.UnusedCPU += resCount.UnusedCPU
clusterwideResourceCount.unusedRAM += resCount.unusedRAM clusterwideResourceCount.UnusedRAM += resCount.UnusedRAM
clusterwideResourceCount.unusedWatts += resCount.unusedWatts clusterwideResourceCount.UnusedWatts += resCount.UnusedWatts
} }
return clusterwideResourceCount return clusterwideResourceCount
} }
// Retrieve resource availability for each host in the cluster. // Retrieve resource availability for each host in the cluster.
func GetPerHostResourceAvailability() map[string]ResourceCount { func GetPerHostResourceAvailability() map[string]*ResourceCount {
tru := getTRUInstance() tru := getTRUInstance()
tru.Lock() tru.Lock()
defer tru.Unlock() defer tru.Unlock()