Scheduler: adding/removing resources enforce warnings and recount number of unconfigu... f4f-review
authorLoic Baron <loic.baron@lip6.fr>
Wed, 15 Apr 2015 22:24:54 +0000 (00:24 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Thu, 16 Apr 2015 09:42:24 +0000 (11:42 +0200)
manifoldapi/static/js/manifold.js
plugins/filter_status/__init__.py
plugins/filter_status/static/js/filter_status.js
plugins/scheduler2/static/js/scheduler2.js
portal/sliceresourceview.py

index 517ab69..d7e5688 100644 (file)
@@ -141,10 +141,10 @@ var QUERY_STATE_DONE        = 2;
  * RECORD STATES (for query_store)
  ******************************************************************************/
 
-var STATE_SET       = 0;
-var STATE_VALUE     = 1;
-var STATE_WARNINGS  = 2;
-var STATE_VISIBLE   = 3;
+var STATE_SET       = 20;
+var STATE_VALUE     = 21;
+var STATE_WARNINGS  = 22;
+var STATE_VISIBLE   = 23;
 
 // ACTIONS
 var STATE_SET_CHANGE = 0;
@@ -1708,6 +1708,17 @@ case TYPE_LIST_OF_VALUES:
                             // XXX Need for a better function to manage warnings
                             var warn = CONSTRAINT_RESERVABLE_LEASE_MSG;
                             warnings[CONSTRAINT_RESERVABLE_LEASE] = warn;
+
+                            manifold.query_store.set_record_state(query.query_uuid, record_key, STATE_WARNINGS, warnings);
+                            // Signal the change to plugins (even if the constraint does not apply, so that the plugin can display a checkmark)
+                            data = {
+                                state:  STATE_WARNINGS,
+                                key   : record_key,
+                                op    : null,
+                                value : warnings
+                            }
+                            manifold.raise_record_event(query.query_uuid, FIELD_STATE_CHANGED, data);
+
                         } else {
                             // Lease are defined, delete the warning in case it was set previously
                             delete warnings[CONSTRAINT_RESERVABLE_LEASE];
@@ -1716,21 +1727,11 @@ case TYPE_LIST_OF_VALUES:
                         // Remove warnings attached to this resource
                         delete warnings[CONSTRAINT_RESERVABLE_LEASE];
                     }
-
-                    manifold.query_store.set_record_state(query.query_uuid, record_key, STATE_WARNINGS, warnings);
                 }
 
                 /* This was redundant */
                 // manifold.query_store.recount(query.query_uuid); 
 
-                // Signal the change to plugins (even if the constraint does not apply, so that the plugin can display a checkmark)
-                data = {
-                    state:  STATE_WARNINGS,
-                    key   : record_key,
-                    op    : null,
-                    value : warnings
-                }
-                manifold.raise_record_event(query.query_uuid, FIELD_STATE_CHANGED, data);
                 break;
 
             case 'lease':
@@ -1738,7 +1739,7 @@ case TYPE_LIST_OF_VALUES:
                 var resource_query = query_ext.parent_query_ext.query.subqueries['resource'];
                 var warnings = manifold.query_store.get_record_state(resource_query.query_uuid, resource_key, STATE_WARNINGS);
 
-                if (event_type == STATE_SET_ADD) {
+                if (event_type == STATE_SET_ADD || event_type == STATE_SET_IN_PENDING) {
                      // A lease is added, it removes the constraint
                     delete warnings[CONSTRAINT_RESERVABLE_LEASE];
                 } else {
@@ -1749,23 +1750,22 @@ case TYPE_LIST_OF_VALUES:
                         // XXX Need for a better function to manage warnings
                         var warn = CONSTRAINT_RESERVABLE_LEASE_MSG;
                         warnings[CONSTRAINT_RESERVABLE_LEASE] = warn;
+
+                        // Signal the change to plugins (even if the constraint does not apply, so that the plugin can display a checkmark)
+                        data = {
+                            state:  STATE_WARNINGS,
+                            key   : resource_key,
+                            op    : null,
+                            value : warnings
+                        }
+                        manifold.raise_record_event(resource_query.query_uuid, FIELD_STATE_CHANGED, data);
                     } else {
                         // Lease are defined, delete the warning in case it was set previously
                         delete warnings[CONSTRAINT_RESERVABLE_LEASE];
                     }
-                    
                 }
-
+                /* Adding a lease can remove a warning and reduce the unconfigured resources  */
                 manifold.query_store.recount(resource_query.query_uuid); 
-
-                // Signal the change to plugins (even if the constraint does not apply, so that the plugin can display a checkmark)
-                data = {
-                    state:  STATE_WARNINGS,
-                    key   : resource_key,
-                    op    : null,
-                    value : warnings
-                }
-                manifold.raise_record_event(resource_query.query_uuid, FIELD_STATE_CHANGED, data);
                 break;
         }
 
@@ -1806,6 +1806,9 @@ case TYPE_LIST_OF_VALUES:
         query = query_ext.query;
 
         switch(event_type) {
+            case STATUS_REMOVE_WARNING:
+                record = manifold.query_store.get_record(query_uuid, data.value);
+                this._enforce_constraints(query_ext, record, data.value, STATE_SET_ADD);
 
             // XXX At some point, should be renamed to RECORD_STATE_CHANGED
             case FIELD_STATE_CHANGED:
index a0d269b..38a5ffc 100644 (file)
@@ -2,10 +2,13 @@ from unfold.plugin import Plugin
 
 class FilterStatusPlugin(Plugin):
     
-    def __init__ (self, query=None, **settings):
+    def __init__ (self, query=None, query_lease=None, **settings):
         Plugin.__init__ (self, **settings)
         self.query              = query
 
+        self.query_lease = query_lease
+        self.query_lease_uuid = query_lease.query_uuid
+
     def template_file (self):
         return "filter_status.html"
 
@@ -24,7 +27,7 @@ class FilterStatusPlugin(Plugin):
         # query_uuid will pass self.query results to the javascript
         # and will be available as "record" in :
         # on_new_record: function(record)
-        return ['plugin_uuid', 'domid', 'query_uuid']
+        return ['plugin_uuid', 'domid', 'query_uuid', 'query_lease_uuid']
 
     def export_json_settings (self):
         return True
index 9c1c244..324634c 100644 (file)
@@ -28,6 +28,7 @@
 
             /* Setup query and record handlers */
             this.listen_query(options.query_uuid);
+            this.listen_query(options.query_lease_uuid, 'leases');
 
             /* Setup click handlers */
             this.elts('list-group-item').click({'instance': this}, this._on_click);
         // XXX
     },
 
+    on_leases_field_state_changed: function(data) 
+    {
+        console.log('leases_field_state_changed');
+        this.on_field_state_changed(data);
+    },
     on_field_state_changed: function(data) 
     {
         var query_ext;
index 6ef2549..933f32f 100755 (executable)
@@ -196,6 +196,7 @@ var SCHEDULER_COLWIDTH = 50;
                 op   : STATE_SET_ADD,
                 value: new_lease
             }
+            prev_state = manifold.query_store.get_record_state($scope.instance.options.query_uuid, resource_urn, STATE_SET);
             manifold.raise_event($scope.instance.options.query_lease_uuid, FIELD_STATE_CHANGED, data);
 
             /* Add to local cache also, unless we listen to events from outside */
@@ -208,7 +209,13 @@ var SCHEDULER_COLWIDTH = 50;
                     op   : STATE_SET_ADD,
                     value: resource_urn
                 };
-                manifold.raise_event($scope.instance.options.query_uuid, FIELD_STATE_CHANGED, data_resource);
+                /* Send the message to the list of resources, depending on the previous state */
+                prev_state = manifold.query_store.get_record_state($scope.instance.options.query_uuid, data_resource.value, STATE_SET);
+                if(jQuery.inArray(prev_state,[STATE_SET_OUT,STATE_SET_OUT_SUCCESS,STATE_SET_OUT_PENDING,STATE_SET_IN_FAILURE])>-1){
+                    manifold.raise_event($scope.instance.options.query_uuid, FIELD_STATE_CHANGED, data_resource);
+                }
+                /* Remove the warning on resource as we have added Leases to it */
+                //manifold.raise_event($scope.instance.options.query_uuid, STATUS_REMOVE_WARNING, data_resource);
             }
             $scope._leases_by_resource[resource_urn].push(new_lease);
 
@@ -235,8 +242,9 @@ var SCHEDULER_COLWIDTH = 50;
                 op   : STATE_SET_REMOVE,
                 value: other_key
             }
+            prev_state = manifold.query_store.get_record_state($scope.instance.options.query_uuid, other.resource, STATE_SET);
             manifold.raise_event($scope.instance.options.query_lease_uuid, FIELD_STATE_CHANGED, data);
-            /* Remove from local cache also, unless we listen to events from outside */
+            /* Remove Lease from local cache also, unless we listen to events from outside */
             $scope._leases_by_resource[other.resource] = $.grep($scope._leases_by_resource[other.resource], function(x) { return x != other; });
             /* Last lease removed for this resource -> remove the resource from the list */
             if($scope._leases_by_resource.hasOwnProperty(other.resource) && $scope._leases_by_resource[other.resource].length == 0){
@@ -247,7 +255,15 @@ var SCHEDULER_COLWIDTH = 50;
                     op   : STATE_SET_REMOVE,
                     value: other.resource
                 };
-                manifold.raise_event($scope.instance.options.query_uuid, FIELD_STATE_CHANGED, data_resource);
+
+                prev_state = manifold.query_store.get_record_state($scope.instance.options.query_uuid, data_resource.value, STATE_SET);
+                /* Remove Resource from local cache */
+                delete $scope._leases_by_resource[data_resource.value]
+                /* Send the message to the list of resources, depending on the previous state */
+                if(jQuery.inArray(prev_state,[STATE_SET_IN,STATE_SET_IN_SUCCESS,STATE_SET_IN_PENDING,STATE_SET_OUT_FAILURE])>-1){
+                    manifold.raise_event($scope.instance.options.query_uuid, FIELD_STATE_CHANGED, data_resource);
+                    //manifold.raise_event($scope.instance.options.query_uuid, STATUS_REMOVE_WARNING, data_resource);
+                }
                
             }
         }
@@ -698,26 +714,42 @@ var SCHEDULER_COLWIDTH = 50;
             on_leases_filter_removed:    function(filter) { this._get_scope().$apply(); },
             on_leases_filter_clear:      function()       { this._get_scope().$apply(); },
 
-            on_field_state_changed: function(data)
+            on_resources_field_state_changed: function(data)
             {
-                /*
-                this._set_lease_slots(lease_key, lease);
-
+                console.log('on_resources_field_state_changed');
+                console.log(data);
                 switch(data.state) {
                     case STATE_SET:
                         switch(data.op) {
+                            /*
                             case STATE_SET_IN:
                             case STATE_SET_IN_SUCCESS:
                             case STATE_SET_OUT_FAILURE:
-                                this.set_checkbox_from_data(data.value, true);
-                                this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_RESET);
+                                //this.set_checkbox_from_data(data.value, true);
+                                //this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_RESET);
                                 break;  
+                            */
                             case STATE_SET_OUT:
                             case STATE_SET_OUT_SUCCESS:
                             case STATE_SET_IN_FAILURE:
-                                this.set_checkbox_from_data(data.value, false);
-                                this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_RESET);
+                                // A resource has been removed
+                                console.log(this._get_scope()._leases_by_resource);
+                                s = this._get_scope();
+                                // loop over the list of leases by resource cached
+                                $.each(this._get_scope()._leases_by_resource, function(k,v){
+                                    // if the resource removed is in the list
+                                    // we need to remove all the leases corresponding to that resoruce
+                                    if(k == data.value){
+                                        console.log(k,v);
+                                        // loop each lease should be removed
+                                        $.each(v, function(i,lease){
+                                            console.log(i,lease);
+                                            s._remove_lease(lease);
+                                        });
+                                    }
+                                });
                                 break;
+                            /*
                             case STATE_SET_IN_PENDING:
                                 this.set_checkbox_from_data(data.key, true);
                                 this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_ADDED);
@@ -726,14 +758,15 @@ var SCHEDULER_COLWIDTH = 50;
                                 this.set_checkbox_from_data(data.key, false);
                                 this.set_bgcolor(data.value, QUERYTABLE_BGCOLOR_REMOVED);
                                 break;
+                            */
                         }
                         break;
-
+                    /*
                     case STATE_WARNINGS:
                         this.change_status(data.key, data.value);
                         break;
+                    */
                 }
-                */
             },
 
 
index c394345..4829aef 100644 (file)
@@ -282,6 +282,7 @@ class SliceResourceView (LoginRequiredView, ThemeView):
             page            = page,
             domid           = "filter-status",
             query           = sq_resource,
+            query_lease     = sq_lease,
         )
         apply = ApplyPlugin(
             page            = page,