formatted code.
This commit is contained in:
parent
c31bf8db01
commit
9599588fb5
4 changed files with 22 additions and 22 deletions
|
@ -1,11 +1,11 @@
|
||||||
package def
|
package def
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/mash/gokmeans"
|
|
||||||
"log"
|
|
||||||
"sort"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/mdesenfants/gokmeans"
|
||||||
|
"log"
|
||||||
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Information about a cluster of tasks.
|
// Information about a cluster of tasks.
|
||||||
|
@ -140,10 +140,10 @@ 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, i)
|
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,
|
||||||
Watts: task.Watts,
|
Watts: task.Watts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,4 +158,4 @@ func GetResourceRequirement(taskID string) (TaskResources, error) {
|
||||||
// Shouldn't be here.
|
// Shouldn't be here.
|
||||||
return TaskResources{}, errors.New("Invalid TaskID: " + taskID)
|
return TaskResources{}, errors.New("Invalid TaskID: " + taskID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package schedulers
|
||||||
import (
|
import (
|
||||||
"bitbucket.org/sunybingcloud/elektron/def"
|
"bitbucket.org/sunybingcloud/elektron/def"
|
||||||
elecLogDef "bitbucket.org/sunybingcloud/elektron/logging/def"
|
elecLogDef "bitbucket.org/sunybingcloud/elektron/logging/def"
|
||||||
|
"bitbucket.org/sunybingcloud/elektron/utilities"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
@ -12,7 +13,6 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"bitbucket.org/sunybingcloud/elektron/utilities"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type baseScheduler struct {
|
type baseScheduler struct {
|
||||||
|
@ -21,13 +21,13 @@ type baseScheduler struct {
|
||||||
// Current scheduling policy used for resource offer consumption.
|
// Current scheduling policy used for resource offer consumption.
|
||||||
curSchedPolicy SchedPolicyState
|
curSchedPolicy SchedPolicyState
|
||||||
|
|
||||||
tasksCreated int
|
tasksCreated int
|
||||||
tasksRunning int
|
tasksRunning int
|
||||||
tasks []def.Task
|
tasks []def.Task
|
||||||
metrics map[string]def.Metric
|
metrics map[string]def.Metric
|
||||||
running map[string]map[string]bool
|
running map[string]map[string]bool
|
||||||
wattsAsAResource bool
|
wattsAsAResource bool
|
||||||
classMapWatts bool
|
classMapWatts bool
|
||||||
totalResourceAvailabilityRecorded bool
|
totalResourceAvailabilityRecorded bool
|
||||||
|
|
||||||
// First set of PCP values are garbage values, signal to logger to start recording when we're
|
// First set of PCP values are garbage values, signal to logger to start recording when we're
|
||||||
|
@ -164,7 +164,7 @@ func (s *baseScheduler) Disconnected(sched.SchedulerDriver) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *baseScheduler) ResourceOffers(driver sched.SchedulerDriver, offers []*mesos.Offer) {
|
func (s *baseScheduler) ResourceOffers(driver sched.SchedulerDriver, offers []*mesos.Offer) {
|
||||||
utilities.RecordTotalResourceAvailability(offers)
|
utilities.RecordTotalResourceAvailability(offers)
|
||||||
s.curSchedPolicy.ConsumeOffers(s, driver, offers)
|
s.curSchedPolicy.ConsumeOffers(s, driver, offers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,12 @@ package schedulers
|
||||||
import (
|
import (
|
||||||
"bitbucket.org/sunybingcloud/elektron/constants"
|
"bitbucket.org/sunybingcloud/elektron/constants"
|
||||||
"bitbucket.org/sunybingcloud/elektron/def"
|
"bitbucket.org/sunybingcloud/elektron/def"
|
||||||
"errors"
|
|
||||||
elecLogDef "bitbucket.org/sunybingcloud/elektron/logging/def"
|
elecLogDef "bitbucket.org/sunybingcloud/elektron/logging/def"
|
||||||
"bitbucket.org/sunybingcloud/elektron/utilities"
|
"bitbucket.org/sunybingcloud/elektron/utilities"
|
||||||
"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"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"log"
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ func LaunchTasks(offerIDs []*mesos.OfferID, tasksToLaunch []*mesos.TaskInfo, dri
|
||||||
driver.LaunchTasks(offerIDs, tasksToLaunch, mesosUtils.DefaultFilter)
|
driver.LaunchTasks(offerIDs, tasksToLaunch, mesosUtils.DefaultFilter)
|
||||||
// Update resource availability
|
// Update resource availability
|
||||||
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 {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
|
|
@ -17,9 +17,9 @@ 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
|
||||||
|
@ -106,7 +106,7 @@ var resourceAvailabilityUpdateScenario = map[string]func(mesos.TaskID, mesos.Sla
|
||||||
if taskResources, err := def.GetResourceRequirement(*taskID.Value); err != nil {
|
if taskResources, err := def.GetResourceRequirement(*taskID.Value); err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
} else {
|
||||||
// Checking if first resource offer already recorded for slaveID.
|
// Checking if first resource offer already recorded for slaveID.
|
||||||
if resCount, ok := tru.perHostResourceAvailability[*slaveID.Value]; ok {
|
if resCount, ok := tru.perHostResourceAvailability[*slaveID.Value]; ok {
|
||||||
resCount.DecrUnusedResources(taskResources)
|
resCount.DecrUnusedResources(taskResources)
|
||||||
} else {
|
} else {
|
||||||
|
|
Reference in a new issue