Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
20a12af1
authored
Mar 15, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
manager: add logging and exception handling to scheduler
parent
fb475b8b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
2 deletions
+21
-2
circle/manager/scheduler.py
+21
-2
No files found.
circle/manager/scheduler.py
View file @
20a12af1
from
logging
import
getLogger
from
django.db.models
import
Sum
from
django.db.models
import
Sum
logger
=
getLogger
(
__name__
)
class
NotEnoughMemoryException
(
Exception
):
class
NotEnoughMemoryException
(
Exception
):
...
@@ -24,20 +28,25 @@ def select_node(instance, nodes):
...
@@ -24,20 +28,25 @@ def select_node(instance, nodes):
'''
'''
# check required traits
# check required traits
nodes
=
[
n
for
n
in
nodes
nodes
=
[
n
for
n
in
nodes
if
n
.
enabled
and
has_traits
(
instance
.
req_traits
.
all
(),
n
)]
if
n
.
enabled
and
n
.
online
and
has_traits
(
instance
.
req_traits
.
all
(),
n
)]
if
not
nodes
:
if
not
nodes
:
logger
.
warning
(
'select_node: no usable node for
%
s'
,
unicode
(
instance
))
raise
TraitsUnsatisfiableException
()
raise
TraitsUnsatisfiableException
()
# check required RAM
# check required RAM
nodes
=
[
n
for
n
in
nodes
if
has_enough_ram
(
instance
.
ram_size
,
n
)]
nodes
=
[
n
for
n
in
nodes
if
has_enough_ram
(
instance
.
ram_size
,
n
)]
if
not
nodes
:
if
not
nodes
:
logger
.
warning
(
'select_node: no enough RAM for
%
s'
,
unicode
(
instance
))
raise
NotEnoughMemoryException
()
raise
NotEnoughMemoryException
()
# 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
)
result
=
nodes
[
0
]
return
nodes
[
0
]
logger
.
info
(
'select_node:
%
s for
%
s'
,
unicode
(
result
),
unicode
(
instance
))
return
result
def
has_traits
(
traits
,
node
):
def
has_traits
(
traits
,
node
):
...
@@ -51,6 +60,7 @@ def has_enough_ram(ram_size, node):
...
@@ -51,6 +60,7 @@ def has_enough_ram(ram_size, node):
"""True, if the node has enough memory to accomodate a guest requiring
"""True, if the node has enough memory to accomodate a guest requiring
ram_size mebibytes of memory; otherwise, false.
ram_size mebibytes of memory; otherwise, false.
"""
"""
try
:
total
=
node
.
ram_size
total
=
node
.
ram_size
used
=
(
node
.
ram_usage
/
100
)
*
total
used
=
(
node
.
ram_usage
/
100
)
*
total
unused
=
total
-
used
unused
=
total
-
used
...
@@ -60,6 +70,10 @@ def has_enough_ram(ram_size, node):
...
@@ -60,6 +70,10 @@ def has_enough_ram(ram_size, node):
free
=
overcommit
-
reserved
free
=
overcommit
-
reserved
return
ram_size
<
unused
and
ram_size
<
free
return
ram_size
<
unused
and
ram_size
<
free
except
TypeError
as
e
:
logger
.
warning
(
'Got incorrect monitoring data for node
%
s.
%
s'
,
unicode
(
node
),
unicode
(
e
))
return
False
def
free_cpu_time
(
node
):
def
free_cpu_time
(
node
):
...
@@ -67,7 +81,12 @@ def free_cpu_time(node):
...
@@ -67,7 +81,12 @@ def free_cpu_time(node):
Higher values indicate more idle time.
Higher values indicate more idle time.
"""
"""
try
:
activity
=
node
.
cpu_usage
/
100
activity
=
node
.
cpu_usage
/
100
inactivity
=
1
-
activity
inactivity
=
1
-
activity
cores
=
node
.
num_cores
cores
=
node
.
num_cores
return
cores
*
inactivity
return
cores
*
inactivity
except
TypeError
as
e
:
logger
.
warning
(
'Got incorrect monitoring data for node
%
s.
%
s'
,
unicode
(
node
),
unicode
(
e
))
return
False
# monitoring data is incorrect
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment