X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=manifoldapi%2Fstatic%2Fjs%2Fmanifold.js;h=f8d299a189bdaec6dc3ae822203b9d3f997f7bc1;hb=d035a1f93e4acbeee79b7c8200264687d940ccc2;hp=d7e568833020a424e6f701d9202f41d51999d709;hpb=a8104de58940697d33f0f38cb3c866b7ecf6f4f4;p=myslice.git diff --git a/manifoldapi/static/js/manifold.js b/manifoldapi/static/js/manifold.js index d7e56883..f8d299a1 100644 --- a/manifoldapi/static/js/manifold.js +++ b/manifoldapi/static/js/manifold.js @@ -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) { @@ -512,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; @@ -521,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) @@ -560,7 +566,7 @@ 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; @@ -568,6 +574,9 @@ function QueryStore() { 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) @@ -606,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; @@ -1081,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 @@ -1112,29 +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); - 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); - }); + 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); + } } }, @@ -1689,13 +1706,15 @@ case TYPE_LIST_OF_VALUES: 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); 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 @@ -1709,7 +1728,7 @@ case TYPE_LIST_OF_VALUES: 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); + /*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, @@ -1717,7 +1736,7 @@ case TYPE_LIST_OF_VALUES: op : null, value : warnings } - manifold.raise_record_event(query.query_uuid, FIELD_STATE_CHANGED, data); + manifold.raise_record_event(query.query_uuid, FIELD_STATE_CHANGED, data);*/ } else { // Lease are defined, delete the warning in case it was set previously @@ -1729,8 +1748,69 @@ case TYPE_LIST_OF_VALUES: } } + /*var urn_regexp = /\+(.*?)\+/; + var testbed_urn = urn_regexp.exec(record.urn)[1]; + var has_sla = $.inArray(testbed_urn, localStorage.getItem("sla_testbeds").split(",")) != -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, + key : record_key, + op : null, + 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); + // manifold.query_store.recount(query.query_uuid); break; @@ -1808,7 +1888,8 @@ case TYPE_LIST_OF_VALUES: 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); + 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: