Commit e8684154 by Czémán Arnold

Merge branch 'configurable_scheduler' into 'master'

Configurable scheduler method

See merge request !401
parents 14750235 2c2a1c71
...@@ -576,6 +576,8 @@ SESSION_COOKIE_NAME = "csessid%x" % (((getnode() // 139) ^ ...@@ -576,6 +576,8 @@ SESSION_COOKIE_NAME = "csessid%x" % (((getnode() // 139) ^
MAX_NODE_RAM = get_env_variable("MAX_NODE_RAM", 1024) MAX_NODE_RAM = get_env_variable("MAX_NODE_RAM", 1024)
MAX_NODE_CPU_CORE = get_env_variable("MAX_NODE_CPU_CORE", 10) MAX_NODE_CPU_CORE = get_env_variable("MAX_NODE_CPU_CORE", 10)
SCHEDULER_METHOD = get_env_variable("SCHEDULER_METHOD", 'random')
# Url to download the client: (e.g. http://circlecloud.org/client/download/) # Url to download the client: (e.g. http://circlecloud.org/client/download/)
CLIENT_DOWNLOAD_URL = get_env_variable('CLIENT_DOWNLOAD_URL', 'http://circlecloud.org/client/download/') CLIENT_DOWNLOAD_URL = get_env_variable('CLIENT_DOWNLOAD_URL', 'http://circlecloud.org/client/download/')
......
...@@ -21,6 +21,10 @@ from django.utils.translation import ugettext_noop ...@@ -21,6 +21,10 @@ from django.utils.translation import ugettext_noop
from common.models import HumanReadableException from common.models import HumanReadableException
from circle.settings.base import SCHEDULER_METHOD
import random
logger = getLogger(__name__) logger = getLogger(__name__)
...@@ -50,9 +54,7 @@ class TraitsUnsatisfiableException(SchedulerError): ...@@ -50,9 +54,7 @@ class TraitsUnsatisfiableException(SchedulerError):
"new virtual machine currently.") "new virtual machine currently.")
def select_node(instance, nodes): def common_select(instance, nodes):
''' Select a node for hosting an instance based on its requirements.
'''
# check required traits # check required traits
nodes = [n for n in nodes nodes = [n for n in nodes
if n.schedule_enabled and n.online and if n.schedule_enabled and n.online and
...@@ -70,8 +72,32 @@ def select_node(instance, nodes): ...@@ -70,8 +72,32 @@ def select_node(instance, nodes):
# sort nodes first by processor usage, then priority # sort nodes first by processor usage, then priority
nodes.sort(key=lambda n: n.priority, reverse=True) nodes.sort(key=lambda n: n.priority, reverse=True)
nodes.sort(key=free_cpu_time, reverse=True) nodes.sort(key=free_cpu_time, reverse=True)
return nodes
def common_evenly(instance, nodes):
nodes = common_select(instance, nodes)
result = nodes[0] result = nodes[0]
return result
def common_random(instance, nodes):
nodes = common_select(instance, nodes)
result = random.choice(nodes)
return result
def select_node(instance, nodes):
''' Select a node for hosting an instance based on its requirements.
'''
if SCHEDULER_METHOD == 'evenly':
result = common_evenly(instance, nodes)
elif SCHEDULER_METHOD == 'random':
result = common_random(instance, nodes)
else: # Default method is the random
result = common_random(instance, nodes)
logger.info('Scheduler method: %s selected', unicode(SCHEDULER_METHOD))
logger.info('select_node: %s for %s', unicode(result), unicode(instance)) logger.info('select_node: %s for %s', unicode(result), unicode(instance))
return result return result
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment