Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2013-02-20 14:22:11 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2013-02-20 14:22:11 (GMT)
commit50d31c0552ea32cf0978018b480dc1ed4c30fb4e (patch)
tree8fe9d2506d8cda1b513192c1ac8a8123c95fee8a
parent9c8f1cd801eafc8c380a589f803d7e0dd9ee95ae (diff)
Do not expose node stats object from NodeCommands
-rwxr-xr-xsugar-network-node16
-rw-r--r--sugar_network/node/commands.py24
-rwxr-xr-xtests/units/node/node.py3
3 files changed, 21 insertions, 22 deletions
diff --git a/sugar-network-node b/sugar-network-node
index 7d71739..916f2fe 100755
--- a/sugar-network-node
+++ b/sugar-network-node
@@ -54,29 +54,24 @@ class Application(application.Daemon):
volume = Volume(node.data_root.value)
self.jobs.spawn(volume.populate)
- node_stats = None
- if stats.stats_node_step.value:
- node_stats = stats.NodeStats(volume)
- self.jobs.spawn(self._commit_stats, node_stats)
-
node_path = join(node.data_root.value, 'node')
master_path = join(node.data_root.value, 'master')
if exists(node_path):
with file(node_path) as f:
guid = f.read().strip()
logging.info('Start %s node in slave mode', guid)
- cp = SlaveCommands(guid, volume, node_stats)
+ cp = SlaveCommands(guid, volume)
elif exists(master_path):
with file(master_path) as f:
guid = f.read().strip()
logging.info('Start %s node in master mode', guid)
- cp = MasterCommands(guid, volume, node_stats)
+ cp = MasterCommands(guid, volume)
else:
guid = db.uuid()
with file(node_path, 'w') as f:
f.write(guid)
logging.info('Start new %s node in slave mode', guid)
- cp = SlaveCommands(guid, volume, node_stats)
+ cp = SlaveCommands(guid, volume)
logging.info('Listening for requests on %s:%s',
node.host.value, node.port.value)
@@ -109,11 +104,6 @@ class Application(application.Daemon):
def shutdown(self):
self.jobs.kill()
- def _commit_stats(self, node_stats):
- while True:
- coroutine.sleep(stats.stats_node_step.value)
- node_stats.commit()
-
# Let toolkit.http work in concurrence
# XXX No DNS because `toolkit.network.res_init()` doesn't work otherwise
diff --git a/sugar_network/node/commands.py b/sugar_network/node/commands.py
index 9c6ea5c..01a351d 100644
--- a/sugar_network/node/commands.py
+++ b/sugar_network/node/commands.py
@@ -19,9 +19,9 @@ import hashlib
from os.path import exists, join
from sugar_network import db, node
-from sugar_network.node import auth, obs
+from sugar_network.node import auth, obs, stats
from sugar_network.resources.volume import Commands, VolumeCommands
-from sugar_network.toolkit import router, util, exception, enforce
+from sugar_network.toolkit import router, util, coroutine, exception, enforce
_MAX_STATS_LENGTH = 100
@@ -31,12 +31,17 @@ _logger = logging.getLogger('node.commands')
class NodeCommands(VolumeCommands, Commands):
- def __init__(self, is_master, guid, volume, stats=None):
+ def __init__(self, is_master, guid, volume):
VolumeCommands.__init__(self, volume)
Commands.__init__(self)
+
self._is_master = is_master
self._guid = guid
- self._stats = stats
+ self._stats = None
+
+ if stats.stats_node_step.value:
+ self._stats = stats.NodeStats(volume)
+ coroutine.spawn(self._commit_stats)
@property
def guid(self):
@@ -105,7 +110,7 @@ class NodeCommands(VolumeCommands, Commands):
dbs = {}
for i in source:
- enforce('.' in i, 'Misnamed source name')
+ enforce('.' in i, 'Misnamed source')
db_name, ds_name = i.split('.', 1)
dbs.setdefault(db_name, []).append(ds_name)
result = {}
@@ -113,12 +118,12 @@ class NodeCommands(VolumeCommands, Commands):
for rdb in self._stats.rrd:
if rdb.name not in dbs:
continue
- stats = result[rdb.name] = []
+ info = result[rdb.name] = []
for ts, ds_values in rdb.get(start, end, resolution):
values = {}
for name in dbs[rdb.name]:
values[name] = ds_values.get(name)
- stats.append((ts, values))
+ info.append((ts, values))
return result
@@ -246,6 +251,11 @@ class NodeCommands(VolumeCommands, Commands):
'Document deleted')
return result
+ def _commit_stats(self):
+ while True:
+ coroutine.sleep(stats.stats_node_step.value)
+ self._stats.commit()
+
def _load_pubkey(pubkey):
pubkey = pubkey.strip()
diff --git a/tests/units/node/node.py b/tests/units/node/node.py
index 0e3b9bd..5c23545 100755
--- a/tests/units/node/node.py
+++ b/tests/units/node/node.py
@@ -107,8 +107,7 @@ class NodeTest(tests.Test):
rrd['user'].put({'total': i}, ts + i)
volume = Volume('db', [User, Context, Review, Feedback, Solution, Artifact])
- stats = NodeStats(volume)
- cp = NodeCommands(False, 'guid', volume, stats)
+ cp = NodeCommands(False, 'guid', volume)
self.assertEqual({
'user': [