- RefreshPeer & AddSliceToNodes had bugs
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 10 Nov 2006 17:00:21 +0000 (17:00 +0000)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Fri, 10 Nov 2006 17:00:21 +0000 (17:00 +0000)
- foreign nodes have timestamps

PLC/ForeignNodes.py
PLC/Peers.py
TestPeers.py
planetlab4.sql

index 61e892b..b609006 100644 (file)
@@ -1,6 +1,7 @@
 #
 # Thierry Parmentelat - INRIA
 # 
+import time
 
 from types import StringTypes
 
@@ -24,14 +25,21 @@ class ForeignNode (Row) :
        'boot_state' : Parameter (str, "Boot state, see Node"),
         'model' : Parameter (str,"Model, see Node"),
         'version' : Parameter (str,"Version, see Node"),
-#        'date_created': Parameter(int, "Creation time, see Node"),
-#        'last_updated': Parameter(int, "Update time, see Node"),
+        'date_created': Parameter(int, "Creation time, see Node"),
+        'last_updated': Parameter(int, "Update time, see Node"),
+        'slice_ids': Parameter([int], "List of slices on this node"),
        }
 
     def __init__(self,api,fields={},uptodate=True):
        Row.__init__(self,api,fields)
        self.uptodate=uptodate
 
+    def validate_date_created(self,timestamp):
+        return time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(timestamp))
+
+    def validate_last_updated(self,timestamp):
+        return time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(timestamp))
+
     def purge_peer_node (self,commit=True):
         sql = "DELETE FROM peer_node WHERE node_id=%d"%self['node_id']
         self.api.db.do(sql)
@@ -67,3 +75,18 @@ class ForeignNodes (Table):
                 sql += " AND (%s)" % foreign_node_filter.sql(api, "AND")
 
        self.selectall(sql)
+
+    # managing an index by hostname
+    def hostname_index(self):
+        if 'hostname' not in self.columns:
+            raise PLCFault,"ForeignNodes::index_hostname, hostname not selected"
+        self.index={}
+        for foreign_node in self:
+            self.index[foreign_node['hostname']]=foreign_node
+            
+    def hostname_add_by(self,foreign_node):
+        self.index[foreign_node['hostname']]=foreign_node
+
+    def hostname_locate(self,hostname):
+        return self.index[hostname]
+            
index 5499994..872a867 100644 (file)
@@ -78,6 +78,8 @@ class Peer (Row):
        # we get the whole table just in case 
        # a host would have switched from one plc to the other
        local_foreign_nodes = ForeignNodes (self.api)
+        # new to index it by hostname for searching later
+        local_foreign_nodes.hostname_index()
        
        ### mark entries for this peer outofdate
         old_count=0;
@@ -88,14 +90,14 @@ class Peer (Row):
 
         ### these fields get copied through
         ### xxx need to figure how to revert unix timestamp to db timestamp format
-#        remote_fields = ['boot_state','model','version','date_created','last_updated']
-        remote_fields = ['boot_state','model','version']
+        remote_fields = ['boot_state','model','version','date_created','last_updated']
+
         
        ### scan the new entries, and mark them uptodate
        for node in current_peer_nodes:
            hostname = node['hostname']
             try:
-                foreign_node = ForeignNodes(self.api,{'hostname':hostname})[0]
+                foreign_node = local_foreign_nodes.hostname_locate(hostname)
                 if foreign_node['peer_id'] != peer_id:
                     ### the node has changed its plc, needs to update peer_node
                     old_peer_id = foreign_node['peer_id']
@@ -118,6 +120,7 @@ class Peer (Row):
                 new_foreign_node.sync()
                 new_foreign_node.uptodate = True
                 self.manage_node(new_foreign_node,True)
+                local_foreign_nodes.hostname_add_by(new_foreign_node)
 
 
        ### delete entries that are not uptodate
index 5581fb6..2ec9472 100755 (executable)
@@ -195,4 +195,5 @@ def catch_up (args=[1,2]):
         plc[i]['peer_admin_id']=3
         plc[i]['peer_person_id']=4
         plc[i]['peer_id']=1
+        plc[i]['slice_id']=1
 
index 7cb748b..9d24dc0 100644 (file)
@@ -9,7 +9,7 @@
 --
 -- Copyright (C) 2006 The Trustees of Princeton University
 --
--- $Id: planetlab4.sql,v 1.29 2006/11/08 22:07:29 mlhuang Exp $
+-- $Id: planetlab4.sql,v 1.30 2006/11/10 15:05:52 thierry Exp $
 --
 
 --------------------------------------------------------------------------------
@@ -835,7 +835,7 @@ nodes.model,
 nodes.version,
 CAST(date_part('epoch', nodes.date_created) AS bigint) AS date_created,
 CAST(date_part('epoch', nodes.last_updated) AS bigint) AS last_updated,
-node_slices.slice_ids,
+COALESCE(node_slices.slice_ids, '{}') AS slice_ids,
 nodes.deleted
 FROM nodes
 LEFT JOIN peer_node USING (node_id)