X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=manifoldapi%2Fstatic%2Fjs%2Fmanifold.js;h=d0d314ea4b09afffb5da0a0535db0446e6b75d9d;hb=75b26254fbc898b1adb7aab4eb654b2ef5dcb375;hp=e0454a51dca6d37e084b85dd9ff5366809a111f8;hpb=a01625f2f3b73344306eced21c2d6605a2c6a3d9;p=myslice.git diff --git a/manifoldapi/static/js/manifold.js b/manifoldapi/static/js/manifold.js index e0454a51..d0d314ea 100644 --- a/manifoldapi/static/js/manifold.js +++ b/manifoldapi/static/js/manifold.js @@ -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; @@ -177,6 +177,10 @@ var CONSTRAINT_RESERVABLE_LEASE = 0; var CONSTRAINT_RESERVABLE_LEASE_MSG = "Configuration required: this resource needs to be scheduled"; +var CONSTRAINT_SLA = 1; + +var CONSTRAINT_SLA_MSG = "SLA acceptance required: testbed offers SLA for its resources" + // A structure for storing queries function QueryExt(query, parent_query_ext, main_query_ext, update_query_ext, disabled, domain_query_ext) { @@ -243,6 +247,7 @@ function QueryStore() { // XXX query.change_action() should become deprecated update_query = query.clone(); update_query.action = 'update'; + update_query.fields = []; update_query.analyzed_query.action = 'update'; update_query.params = {}; update_query_ext = new QueryExt(update_query); @@ -344,12 +349,20 @@ function QueryStore() { default_set = (default_set === undefined) ? STATE_SET_OUT : default_set; var self = this; - var query_ext = this.find_analyzed_query_ext(query_uuid); - var record_key = manifold.metadata.get_key(query_ext.query.object); + var key, object, query_ext, record_key; + + query_ext = this.find_analyzed_query_ext(query_uuid); + object = query_ext.query.object; + if (object.indexOf(':') != -1) { + object = object.split(':')[1]; + } + record_key = manifold.metadata.get_key(object); + + // ["start_time", "resource", "end_time"] + // ["urn"] + $.each(records, function(i, record) { - var key = manifold.metadata.get_key(query_ext.query.object); - // ["start_time", "resource", "end_time"] - // ["urn"] + //var key = manifold.metadata.get_key(query_ext.query.object); var record_key_value = manifold.record_get_value(record, record_key); query_ext.records.put(record_key_value, record); @@ -503,7 +516,7 @@ function QueryStore() { this.recount = function(query_uuid) { var query_ext; - var is_reserved, is_pending, in_set, is_unconfigured; + var is_reserved, is_pending, in_set, is_unconfigured, is_unavailable, is_available; query_ext = manifold.query_store.find_analyzed_query_ext(query_uuid); query_ext.num_pending = 0; @@ -512,6 +525,8 @@ function QueryStore() { this.iter_records(query_uuid, function(record_key, record) { var record_state = manifold.query_store.get_record_state(query_uuid, record_key, STATE_SET); var record_warnings = manifold.query_store.get_record_state(query_uuid, record_key, STATE_WARNINGS); + is_unavailable = (record.available == 'false'); + is_available = (record.available == 'true'); is_reserved = (record_state == STATE_SET_IN) || (record_state == STATE_SET_OUT_PENDING) @@ -551,12 +566,17 @@ function QueryStore() { // Adapted from querytable._querytable_filter() this.iter_records(query_uuid, function(record_key, record) { - var is_reserved, is_pending, in_set, is_unconfigured; + var is_reserved, is_pending, in_set, is_unconfigured, is_unavailable, is_available; + + /* By default, a record is visible unless a filter says the opposite */ var visible = true; var record_state = manifold.query_store.get_record_state(query_uuid, record_key, STATE_SET); var record_warnings = manifold.query_store.get_record_state(query_uuid, record_key, STATE_WARNINGS); + is_unavailable = (record.available == 'false'); + is_available = (record.available == 'true'); + is_reserved = (record_state == STATE_SET_IN) || (record_state == STATE_SET_OUT_PENDING) || (record_state == STATE_SET_IN_SUCCESS) @@ -595,6 +615,12 @@ function QueryStore() { // false => ~ break visible = is_reserved; return visible; + case 'available': + visible = is_available; + return visible; + case 'unavailable': + visible = is_unavailable; + return visible; case 'unconfigured': visible = is_unconfigured; return visible; @@ -621,13 +647,16 @@ function QueryStore() { if (op == '=' || op == '==') { if ( col_value != value || col_value==null || col_value=="" || col_value=="n/a") visible = false; + }else if (op == 'included') { + /* By default, the filter returns false unless the record + * field match at least one value of the included statement + */ + visible = false; $.each(value, function(i,x) { if(x == col_value){ visible = true; return false; // ~ break - }else{ - visible = false; } }); }else if (op == '!=') { @@ -658,7 +687,7 @@ function QueryStore() { }); var end = new Date().getTime(); - console.log("APPLY FILTERS took", end - start, "ms"); + console.log("APPLY FILTERS [", filters, "] took", end - start, "ms"); } @@ -723,6 +752,12 @@ var manifold = { } else { console.log('Unknown field'); } + // FIX if the record contains a string instead of a key:value + // example: select resource, slice_hrn from slice where slice_hrn=='xxx' + // Result will be {slice_hrn:'xxx', resource:'urn+zzz'} + // We don't have this resource:{urn:'urn+zzz'} + } else if(typeof(record) === 'string'){ + return record; } else { return record[fields]; } @@ -757,6 +792,9 @@ var manifold = { _record_equals: function(self, other, key_fields) { + if ((typeof self === "string") && (typeof other === "string")) { + return self == other; + } for (var i=0; i < key_fields.length; i++) { var this_value = self[key_fields[i]]; var other_value = other[key_fields[i]]; @@ -769,6 +807,7 @@ var manifold = { switch (this_type) { case TYPE_VALUE: case TYPE_LIST_OF_VALUES: + case TYPE_LIST_OF_RECORDS: if (this_value != other_value) return false; break; @@ -776,6 +815,9 @@ var manifold = { if (!(_record_equals(this_value, other_value, key_fields))) return false; break; + /* + XXX WARNING = disabled for OpenFlow plugin !!! + case TYPE_LIST_OF_RECORDS: if (this_value.length != other_value.length) return false; @@ -783,6 +825,7 @@ var manifold = { if (!(_record_equals(this_value[j], other_value[j], key_fields))) return false; break; + */ } } return true; @@ -952,18 +995,44 @@ var manifold = { var query_ext = manifold.query_store.find_query_ext(query.query_uuid); query_ext.query_state = QUERY_STATE_INPROGRESS; - var query_json = JSON.stringify(query); + /* + If the Query object concerns SFA AM objects, iterate on each AM platform + Loop per platform, allows a progressive loading per AM platform + Update is run on all platforms at the same time to get a final answer, we don't manage partial answers yet... + */ + // Removed slice from the per platform query - it's quick enough... + if((query.object == 'resource' || query.object == 'lease') && query.action != "update"){ + var obj = query.object; + $.post("/rest/platform/", function( data ) { + $.each(data, function(index, p) { + query.object = p.platform+":"+obj; + var query_json = JSON.stringify(query); + + // Inform plugins about the progress + query.iter_subqueries(function (sq) { + var sq_query_ext = manifold.query_store.find_analyzed_query_ext(sq.query_uuid); + sq_query_ext.query_state = QUERY_STATE_INPROGRESS; + manifold.raise_record_event(sq.query_uuid, IN_PROGRESS); + }); - // Inform plugins about the progress - query.iter_subqueries(function (sq) { - var sq_query_ext = manifold.query_store.find_analyzed_query_ext(sq.query_uuid); - sq_query_ext.query_state = QUERY_STATE_INPROGRESS; + $.post(manifold.proxy_url, {'json': query_json} , manifold.success_closure(query, null, callback)); - manifold.raise_record_event(sq.query_uuid, IN_PROGRESS); - }); + }); + }); + + }else{ + var query_json = JSON.stringify(query); + + // Inform plugins about the progress + query.iter_subqueries(function (sq) { + var sq_query_ext = manifold.query_store.find_analyzed_query_ext(sq.query_uuid); + sq_query_ext.query_state = QUERY_STATE_INPROGRESS; + manifold.raise_record_event(sq.query_uuid, IN_PROGRESS); + }); + $.post(manifold.proxy_url, {'json': query_json} , manifold.success_closure(query, null, callback)); - $.post(manifold.proxy_url, {'json': query_json} , manifold.success_closure(query, null, callback)); + } }, // XXX DEPRECATED @@ -1027,7 +1096,7 @@ var manifold = { * \param array results results corresponding to query */ publish_result: function(query, result) { - if (typeof result === 'undefined') + if (result == null || typeof result === 'undefined') result = []; // NEW PLUGIN API @@ -1058,25 +1127,31 @@ var manifold = { }, store_records: function(query, records) { - // Store records - var query_ext = manifold.query_store.find_analyzed_query_ext(query.query_uuid); - if (query_ext.set_query_ext) { - // We have a domain query - // The results are stored in the corresponding set_query - manifold.query_store.set_records(query_ext.set_query_ext.query.query_uuid, records); - - } else if (query_ext.domain_query_ext) { - // We have a set query, it is only used to determine which objects are in the set, we should only retrieve the key - // Has it a domain query, and has it completed ? - $.each(records, function(i, record) { - var key = manifold.metadata.get_key(query.object); - var record_key = manifold.record_get_value(record, key); - manifold.query_store.set_record_state(query.query_uuid, record_key, STATE_SET, STATE_SET_IN); - }); + if(records != null && records.length != 0){ + // Store records + var query_ext = manifold.query_store.find_analyzed_query_ext(query.query_uuid); + if (query_ext.set_query_ext) { + // We have a domain query + // The results are stored in the corresponding set_query + manifold.query_store.set_records(query_ext.set_query_ext.query.query_uuid, records); + + } else if (query_ext.domain_query_ext) { + // We have a set query, it is only used to determine which objects are in the set, we should only retrieve the key + // Has it a domain query, and has it completed ? + $.each(records, function(i, record) { + var key = manifold.metadata.get_key(query.object); + if ( typeof record === "string" ){ + var record_key = record; + }else{ + var record_key = manifold.record_get_value(record, key); + } + manifold.query_store.set_record_state(query.query_uuid, record_key, STATE_SET, STATE_SET_IN); + }); - } else { - // We have a normal query - manifold.query_store.set_records(query.query_uuid, records, STATE_SET_IN); + } else { + // We have a normal query + manifold.query_store.set_records(query.query_uuid, records, STATE_SET_IN); + } } }, @@ -1198,7 +1273,20 @@ var manifold = { make_record: function(object, record) { // To make an object a record, we just add the hash function - var key = manifold.metadata.get_key(object); + var key, new_object; + + if (object.indexOf(':') != -1) { + new_object = object.split(':')[1]; + } else { + new_object = object; + } + + key = manifold.metadata.get_key(new_object); + if (!key){ + console.log("object type: " + new_object + " has no key"); + console.log(record); + return; + } record.hashCode = manifold.record_hashcode(key.sort()); record.equals = manifold.record_equals(key); @@ -1329,8 +1417,9 @@ case TYPE_LIST_OF_VALUES: case TYPE_LIST_OF_VALUES: // XXX Until fixed case TYPE_LIST_OF_RECORDS: var key, new_state, cur_query_uuid; - - cur_query_uuid = query.analyzed_query.subqueries[field].query_uuid; + if($.inArray(field,Object.keys(query.analyzed_query.subqueries)) > -1){ + cur_query_uuid = query.analyzed_query.subqueries[field].query_uuid; + } // example: slice.resource // - update_query_orig.params.resource = resources in slice before update @@ -1415,6 +1504,8 @@ case TYPE_LIST_OF_VALUES: var query_ext = manifold.query_store.find_query_ext(query.query_uuid); query_ext.query_state = QUERY_STATE_DONE; + var tmp_query = manifold.query_store.find_analyzed_query(query.query_uuid); + manifold.publish_result_rec(tmp_query, records); // Send DONE message to plugins query.iter_subqueries(function(sq, data, parent_query) { @@ -1611,17 +1702,22 @@ case TYPE_LIST_OF_VALUES: var query, data; query = query_ext.query; - + var testbeds_with_sla = Array(); + if(localStorage.getItem("sla_testbeds")!=null){ + testbeds_with_sla = localStorage.getItem("sla_testbeds").split(","); + } switch(query.object) { case 'resource': + + var warnings = manifold.query_store.get_record_state(query.query_uuid, record_key, STATE_WARNINGS); // 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); + var is_reservable = (record.exclusive == 'true'); if (is_reservable) { - var warnings = manifold.query_store.get_record_state(query.query_uuid, record_key, STATE_WARNINGS); + // 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 @@ -1634,6 +1730,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]; @@ -1642,13 +1749,24 @@ 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); + var urn_regexp = /\+(.*?)\+/; + var testbed_urn = urn_regexp.exec(record.urn)[1]; + var has_sla = $.inArray(testbed_urn, testbeds_with_sla) != -1; + + if (has_sla) { + // var warnings = manifold.query_store.get_record_state(query.query_uuid, record_key, STATE_WARNINGS); + if (event_type == STATE_SET_ADD) { + var warn = CONSTRAINT_SLA_MSG; + warnings[CONSTRAINT_SLA] = warn; + } else { + delete warnings[CONSTRAINT_SLA]; + } + } + + 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, @@ -1657,6 +1775,46 @@ case TYPE_LIST_OF_VALUES: value : warnings } manifold.raise_record_event(query.query_uuid, FIELD_STATE_CHANGED, data); + + // JGLL: SLA code + /*get_testbeds_with_sla() + .done( function(testbeds) { + var urn_regexp = /\+(.*?)\+/; + var testbed_urn = urn_regexp.exec(record.urn)[1]; + + var warnings = manifold.query_store.get_record_state(query.query_uuid, record_key, STATE_WARNINGS); + + if ($.inArray(testbed_urn, testbeds) != -1) { + // JGLL: Set a warning on resources covered by testbeds offering SLAs + // CONSTRAINT_SLA + + if (event_type == STATE_SET_ADD) { + var warn = CONSTRAINT_SLA_MSG; + warnings[CONSTRAINT_SLA] = warn; + } else { + delete warnings[CONSTRAINT_SLA] + } + } + + 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); + }) + .fail( function(err) { + console.log("SLA - Error retrieving testbeds that support SLAs"); + });*/ + + /* This was redundant */ + // manifold.query_store.recount(query.query_uuid); + break; case 'lease': @@ -1664,7 +1822,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 { @@ -1675,23 +1833,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; } @@ -1732,6 +1889,10 @@ 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_REMOVE); + break; // XXX At some point, should be renamed to RECORD_STATE_CHANGED case FIELD_STATE_CHANGED: @@ -1850,6 +2011,7 @@ case TYPE_LIST_OF_VALUES: break; case RUN_UPDATE: + query_ext.main_query_ext.update_query_ext.query.fields = []; manifold.run_query(query_ext.main_query_ext.update_query_ext.query); break;