do not merge leases on display, but do merge them on submit
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Sat, 24 Jul 2010 14:22:08 +0000 (16:22 +0200)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Sat, 24 Jul 2010 14:22:08 +0000 (16:22 +0200)
planetlab/slices/leases.js
planetlab/slices/slice.php

index a322f56..d34826d 100644 (file)
@@ -119,12 +119,21 @@ function Scheduler (slicename, axisx, axisy, data) {
        for (var i=0, len=this.leases.length; i<len; ++i) {
            var lease=this.leases[i];
            if (lease.current != lease.initial) {
+               var from_time=lease.from_time;
+               var until_time=lease.until_time;
+               /* scan the leases just after this one and merge if appropriate */
+               var j=i+1;
+               while (j<len && lease_methods.compare (lease, until_time, this.leases[j])) {
+                   window.console.log('merged index='+j);
+                   until_time=this.leases[j].until_time;
+                   ++j; ++i;
+               }
                var method=(lease.current=='free') ? 'DeleteLeases' : 'AddLeases';
                window.console.log(method + "(" + 
                                   "[" + lease.nodename + "]," + 
                                   this.slicename + "," +
-                                  lease.from_time + "," +
-                                  lease.until_time + ')');
+                                  from_time + "," +
+                                  until_time + ')');
            }
        }
     }
@@ -158,11 +167,19 @@ function Scheduler (slicename, axisx, axisy, data) {
     }
        
 
-} // Scheduler
+} // end Scheduler
 
 //////////////////////////////////////// couldn't find how to inhererit from the raphael objects...
 var lease_methods = {
     
+    /* in the process of merging leases before posting to the API */
+    compare: function (lease, until_time, next_lease) {
+       return (next_lease['nodename'] == lease['nodename'] &&
+               next_lease['from_time'] == until_time &&
+               next_lease['initial'] == lease['initial'] &&
+               next_lease['current'] == lease['current']);
+    },
+
     init_free: function (lease, unclick) {
        lease.current="free";
        // set color
index 778283d..fb0faa1 100644 (file)
@@ -569,11 +569,12 @@ if ($count && $privileges) {
     while ($counter<$steps) {
       if ($leases && ($leases[0]['nfrom']<=$counter)) {
        $lease=array_shift($leases);
-       /* nicer display, merge two consecutive leases for the same slice */
-       while ($leases && ($leases[0]['name']==$lease['name']) && ($leases[0]['nfrom']==$lease['nuntil'])) {
+       /* nicer display, merge two consecutive leases for the same slice 
+        -*- tmp -*- avoid doing that for now, as it might makes things confusing */
+       /* while ($leases && ($leases[0]['name']==$lease['name']) && ($leases[0]['nfrom']==$lease['nuntil'])) {
          $lease['nuntil']=$leases[0]['nuntil'];
          array_shift($leases);
-       }
+         }*/
        $duration=$lease['nuntil']-$counter;
        echo "<td colspan='$duration'>" . $lease['name'] . "</td>";
        $counter=$lease['nuntil'];