Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
321a6bca
authored
Nov 22, 2018
by
Belákovics Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated logging for tests
parent
efdbf7ed
Pipeline
#681
passed with stage
in 0 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
17 deletions
+31
-17
circle/manager/scheduler.py
+31
-17
No files found.
circle/manager/scheduler.py
View file @
321a6bca
...
@@ -15,18 +15,18 @@
...
@@ -15,18 +15,18 @@
# You should have received a copy of the GNU General Public License along
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
import
random
import
datetime
import
datetime
import
json
import
random
from
logging
import
getLogger
from
django.conf
import
settings
from
django.core.cache
import
cache
from
django.core.cache
import
cache
from
django.utils.translation
import
ugettext_noop
from
django.utils
import
timezone
from
django.utils
import
timezone
from
django.
conf
import
settings
from
django.
utils.translation
import
ugettext_noop
from
common.models
import
HumanReadableException
from
logging
import
getLogger
from
circle.settings.base
import
SCHEDULER_METHOD
from
circle.settings.base
import
SCHEDULER_METHOD
from
common.models
import
HumanReadableException
logger
=
getLogger
(
__name__
)
logger
=
getLogger
(
__name__
)
...
@@ -93,7 +93,9 @@ def common_random(instance, nodes):
...
@@ -93,7 +93,9 @@ def common_random(instance, nodes):
def
advanced_with_time_stamp
(
instance
,
nodes
):
def
advanced_with_time_stamp
(
instance
,
nodes
):
nodes
=
common_select
(
instance
,
nodes
)
nodes
=
common_select
(
instance
,
nodes
)
nodes
.
sort
(
key
=
sorting_key
,
reverse
=
True
)
nodes
.
sort
(
key
=
sorting_key
,
reverse
=
True
)
logger
.
info
(
'SCHEDLOG:
%
s'
,
nodes
)
logger
.
info
(
"SCHEDLOG: {}"
.
format
(
json
.
dumps
({
"event"
:
"after_sort"
,
"list"
:
map
(
lambda
node
:
unicode
(
node
),
nodes
)})))
result
=
nodes
[
0
]
result
=
nodes
[
0
]
return
result
return
result
...
@@ -110,8 +112,10 @@ def select_node(instance, nodes):
...
@@ -110,8 +112,10 @@ def select_node(instance, nodes):
else
:
# Default method is the random
else
:
# Default method is the random
result
=
common_random
(
instance
,
nodes
)
result
=
common_random
(
instance
,
nodes
)
logger
.
info
(
'SCHEDLOG: Scheduler method:
%
s selected'
,
unicode
(
SCHEDULER_METHOD
))
logger
.
info
(
"SCHEDLOG: {}"
.
format
(
json
.
dumps
(
logger
.
info
(
'SCHEDLOG: select_node:
%
s for
%
s'
,
unicode
(
result
),
unicode
(
instance
))
{
"event"
:
"select"
,
"node"
:
unicode
(
result
),
"vm"
:
unicode
(
instance
)})))
set_time_stamp
(
result
)
set_time_stamp
(
result
)
...
@@ -127,17 +131,26 @@ def sorting_key(node):
...
@@ -127,17 +131,26 @@ def sorting_key(node):
key
=
free_cpu_time
(
node
)
*
corr
key
=
free_cpu_time
(
node
)
*
corr
else
:
else
:
key
=
free_ram
(
node
)
*
corr
key
=
free_ram
(
node
)
*
corr
logger
.
info
(
'SCHEDLOG: node:
%
s score:
%
s freecpu:
%
s freeram:
%
s'
,
unicode
(
node
),
unicode
(
key
),
unicode
(
free_cpu_time
(
node
)),
unicode
(
free_ram
(
node
)))
logger
.
info
(
"SCHEDLOG: {}"
.
format
(
json
.
dumps
({
"event"
:
"sort"
,
"node"
:
unicode
(
node
),
"sorting_key"
:
unicode
(
key
),
"free_cpu_time"
:
unicode
(
free_cpu_time
(
node
)),
"free_ram"
:
unicode
(
free_ram
(
node
)),
"last_scheduled_correction_factor"
:
unicode
(
last_scheduled_correction_factor
(
node
))})))
return
key
return
key
def
set_time_stamp
(
node
):
def
set_time_stamp
(
node
):
cache
.
set
(
'time_stamp{}'
.
format
(
node
.
id
),
timezone
.
now
())
cache
.
set
(
'time_stamp{}'
.
format
(
node
.
id
),
timezone
.
now
())
def
get_time_stamp
(
node
):
def
get_time_stamp
(
node
):
time_stamp
=
cache
.
get
(
'time_stamp{}'
.
format
(
node
.
id
))
time_stamp
=
cache
.
get
(
'time_stamp{}'
.
format
(
node
.
id
))
if
time_stamp
:
if
time_stamp
:
return
time_stamp
return
time_stamp
return
datetime
.
datetime
(
1970
,
1
,
1
,
tzinfo
=
timezone
.
get_current_timezone
())
return
datetime
.
datetime
(
1970
,
1
,
1
,
tzinfo
=
timezone
.
get_current_timezone
())
def
last_scheduled_correction_factor
(
node
):
def
last_scheduled_correction_factor
(
node
):
"""Returns the time correction factor for a node.
"""Returns the time correction factor for a node.
...
@@ -149,13 +162,14 @@ def last_scheduled_correction_factor(node):
...
@@ -149,13 +162,14 @@ def last_scheduled_correction_factor(node):
factor
=
0
factor
=
0
max_time_diff
=
settings
.
SCHEDULER_TIME_SENSITIVITY_IN_SECONDS
max_time_diff
=
settings
.
SCHEDULER_TIME_SENSITIVITY_IN_SECONDS
current_time
=
timezone
.
now
()
current_time
=
timezone
.
now
()
time_difference_in_seconds
=
(
current_time
-
get_time_stamp
(
node
))
.
total_seconds
()
time_difference_in_seconds
=
(
current_time
-
get_time_stamp
(
node
))
.
total_seconds
()
factor
=
time_difference_in_seconds
/
float
(
max_time_diff
)
factor
=
time_difference_in_seconds
/
float
(
max_time_diff
)
if
factor
>
1
:
if
factor
>
1
:
factor
=
1
factor
=
1
elif
factor
<
0
:
elif
factor
<
0
:
factor
=
1
factor
=
1
logger
.
info
(
'Scheduler set factor to
%
s'
,
unicode
(
factor
))
logger
.
info
(
'Scheduler set factor to
%
s'
,
unicode
(
factor
))
return
factor
return
factor
...
@@ -205,8 +219,8 @@ def free_cpu_time(node):
...
@@ -205,8 +219,8 @@ def free_cpu_time(node):
return
weighted_value
return
weighted_value
except
TypeError
as
e
:
except
TypeError
as
e
:
logger
.
exception
(
'Got incorrect monitoring data for node
%
s.
%
s'
,
logger
.
exception
(
'Got incorrect monitoring data for node
%
s.
%
s'
,
unicode
(
node
),
unicode
(
e
))
unicode
(
node
),
unicode
(
e
))
return
0
# will result lowest priority
return
0
# will result lowest priority
def
free_ram
(
node
):
def
free_ram
(
node
):
...
@@ -222,4 +236,4 @@ def free_ram(node):
...
@@ -222,4 +236,4 @@ def free_ram(node):
except
TypeError
as
e
:
except
TypeError
as
e
:
logger
.
exception
(
'Got incorrect monitoring data for node
%
s.
%
s'
,
logger
.
exception
(
'Got incorrect monitoring data for node
%
s.
%
s'
,
unicode
(
node
),
unicode
(
e
))
unicode
(
node
),
unicode
(
e
))
return
0
# will result lowest priority
return
0
# will result lowest priority
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