+ switch(query.object) {
+
+ case 'resource':
+ // CONSTRAINT_RESERVABLE_LEASE
+ //
+ // +) If a reservable node is added to the slice, then it should have a corresponding lease
+ // XXX Not always a resource
+ var is_reservable = (record.exclusive == true);
+ if (is_reservable) {
+ var warnings = manifold.query_store.get_record_state(query.query_uuid, record_key, STATE_WARNINGS);
+
+ if (event_type == STATE_SET_ADD) {
+ // We should have a lease_query associated
+ var lease_query = query_ext.parent_query_ext.query.subqueries['lease']; // in options
+ var lease_query_ext = manifold.query_store.find_analyzed_query_ext(lease_query.query_uuid);
+ // Do we have lease records (in) with this resource
+ var lease_records = $.grep(lease_query_ext.records.entries(), this._grep_active_lease_callback(lease_query, record_key));
+ if (lease_records.length == 0) {
+ // Sets a warning
+ // XXX Need for a better function to manage warnings
+ var warn = CONSTRAINT_RESERVABLE_LEASE_MSG;
+ warnings[CONSTRAINT_RESERVABLE_LEASE] = warn;
+ } else {
+ // Lease are defined, delete the warning in case it was set previously
+ delete warnings[CONSTRAINT_RESERVABLE_LEASE];
+ }
+ } else {
+ // 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':
+ var resource_key = record_key.resource;
+ 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) {
+ // A lease is added, it removes the constraint
+ delete warnings[CONSTRAINT_RESERVABLE_LEASE];
+ } else {
+ // A lease is removed, it might trigger the warning
+ var lease_records = $.grep(query_ext.records.entries(), this._grep_active_lease_callback(query, resource_key));
+ if (lease_records.length == 0) { // XXX redundant cases
+ // Sets a warning
+ // XXX Need for a better function to manage warnings
+ var warn = CONSTRAINT_RESERVABLE_LEASE_MSG;
+ warnings[CONSTRAINT_RESERVABLE_LEASE] = warn;
+ } else {
+ // Lease are defined, delete the warning in case it was set previously
+ delete warnings[CONSTRAINT_RESERVABLE_LEASE];
+ }
+
+ }
+
+ 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;
+ }
+
+ // -) When a lease is added, it might remove the warning associated to a reservable node
+
+ // If a NITOS node is reserved, then at least a NITOS channel should be reserved
+ // - When a NITOS channel is added, it might remove a warning associated to all NITOS nodes
+
+ // If a NITOS channel is reserved, then at least a NITOS node should be reserved
+ // - When a NITOS node is added, it might remove a warning associated to all NITOS channels
+
+ // A lease is present while the resource has been removed => Require warnings on nodes not in set !
+
+ },
+
+ _get_query_path: function(query_ext) {
+ var path = "";
+ var sq = query_ext;
+ while (sq.parent_query_ext) {
+ if (path != "")
+ path = '.' + path;
+ path = sq.query.object + path;
+ sq = sq.parent_query_ext;
+ }
+ return path;
+ },
+
+
+ /**
+ * Handling events raised by plugins
+ */
+ raise_event: function(query_uuid, event_type, data)
+ {