Skip to content

Commit 43e4d75

Browse files
committed
Add pytz and use utc time
1 parent 3276644 commit 43e4d75

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

Pipfile

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ coverage = "*"
1212
requests = "*"
1313
mesoshttp = "*"
1414
typing = "*"
15+
pytz = "*"
1516

1617
[requires]
1718
python_version = "2.7"

Pipfile.lock

+21-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hpc_cluster_manager.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import threading
22
from datetime import datetime, timedelta
33

4+
import pytz
45
from typing import Iterable, Callable, NamedTuple, Set, Dict, List, Tuple
56

67
import logging_aux
@@ -25,7 +26,7 @@ def _check_node_health_unapproved(node_status):
2526

2627
def _find_missing_nodes(rq_nodes, res_nodes):
2728
# type: (List[str], List[str]) -> List[str]
28-
return [name for name in rq_nodes if name not in res_nodes]
29+
return [name for name in _upper_strings(rq_nodes) if name not in _upper_strings(res_nodes)]
2930

3031

3132
def _check_node_state(node_status, target_state):
@@ -97,7 +98,7 @@ def subscribe_node_closed_callback(self, callback):
9798
# type: (Callable[[list[str]], ()]) -> ()
9899
self._node_closed_callbacks.append(callback)
99100

100-
def add_slaveinfo(self, fqdn, agent_id, task_id, cpus, last_heartbeat=datetime.utcnow()):
101+
def add_slaveinfo(self, fqdn, agent_id, task_id, cpus, last_heartbeat=datetime.now(pytz.utc)):
101102
# type: (str, str, str, float, datetime) -> ()
102103
u_fqdn = fqdn.upper()
103104
hostname = _get_hostname_from_fqdn(u_fqdn)
@@ -114,7 +115,7 @@ def add_slaveinfo(self, fqdn, agent_id, task_id, cpus, last_heartbeat=datetime.u
114115
self._heart_beat_table[hostname] = slaveinfo
115116
self.logger.info("Heart beat entry added: {}".format(str(slaveinfo)))
116117

117-
def on_slave_heartbeat(self, hostname, now=datetime.utcnow()):
118+
def on_slave_heartbeat(self, hostname, now=datetime.now(pytz.utc)):
118119
# type: (str, datetime) -> ()
119120
u_hostname = hostname.upper()
120121
if u_hostname in self._heart_beat_table:
@@ -123,7 +124,7 @@ def on_slave_heartbeat(self, hostname, now=datetime.utcnow()):
123124
if self._heart_beat_table[u_hostname].state == HpcState.Provisioning:
124125
with self._table_lock:
125126
if self._heart_beat_table[u_hostname].state == HpcState.Provisioning:
126-
self._set_nodes_configuring(u_hostname)
127+
self._set_nodes_configuring([u_hostname])
127128
else:
128129
self.logger.error("Host {} is not recognized. Heartbeat ignored.".format(u_hostname))
129130
self.logger.debug("_table {} ".format(self._heart_beat_table))
@@ -165,7 +166,7 @@ def check_fqdn_collision(self, fqdn):
165166
return True
166167
return False
167168

168-
def _check_timeout(self, now=datetime.utcnow()):
169+
def _check_timeout(self, now=datetime.now(pytz.utc)):
169170
# type: (datetime) -> ([SlaveInfo], [SlaveInfo], [SlaveInfo])
170171
# TODO: Check configuring timeout
171172
provision_timeout_list = []
@@ -276,8 +277,8 @@ def _configure_compute_nodes_state_machine(self):
276277
self.logger.info("Nodes configured: {}".format(configured_node_names))
277278
self._set_nodes_running(configured_node_names)
278279
if missing_nodes:
280+
# Missing is valid state of nodes in configuring.
279281
self.logger.info("Nodes missing when configuring: {}".format(missing_nodes))
280-
self._set_nodes_closed(missing_nodes)
281282

282283
def _check_runaway_and_idle_compute_nodes(self):
283284
# type: () -> ()
@@ -312,7 +313,7 @@ def _check_runaway_and_idle_compute_nodes(self):
312313
self.logger.info("Get idle_timeout_nodes:{}".format(str(idle_timeout_nodes)))
313314
self._set_nodes_draining(idle_timeout_nodes)
314315

315-
def _check_node_idle_timeout(self, node_names, now=datetime.utcnow()):
316+
def _check_node_idle_timeout(self, node_names, now=datetime.now(pytz.utc)):
316317
# type: (Iterable[str], datetime) -> [str]
317318
new_node_idle_check_table = {}
318319
for u_node_name in _upper_strings(node_names):
@@ -325,6 +326,7 @@ def _check_node_idle_timeout(self, node_names, now=datetime.utcnow()):
325326
else:
326327
new_node_idle_check_table[u_node_name] = now
327328
self._node_idle_check_table = new_node_idle_check_table
329+
self.logger.info("_check_node_idle_timeout: now - " + str(now))
328330
self.logger.info("_check_node_idle_timeout: " + str(self._node_idle_check_table))
329331
return [name for name, value in self._node_idle_check_table.iteritems() if
330332
(now - value) >= self._node_idle_timedelta]

0 commit comments

Comments
 (0)