From 01988daf1b166ee0d483fc0c235f1820f801ad98 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Javier=20Garc=C3=ADa?= Date: Mon, 27 Apr 2015 11:22:07 +0200 Subject: [PATCH] added alert on accepted sla --- manifoldapi/static/js/manifold.js | 45 +++++++++++++++------- myslice/settings.py | 1 - plugins/sladialog/static/js/sladialog.js | 25 ++++++++++++ plugins/sladialog/templates/sladialog.html | 14 +++++-- 4 files changed, 67 insertions(+), 18 deletions(-) diff --git a/manifoldapi/static/js/manifold.js b/manifoldapi/static/js/manifold.js index 4ca5e007..d6f09320 100644 --- a/manifoldapi/static/js/manifold.js +++ b/manifoldapi/static/js/manifold.js @@ -1688,27 +1688,20 @@ case TYPE_LIST_OF_VALUES: { var query, data; - // JGLL: TODO These lines should be moved to a different part of the code - // to avoid a call every time a resource is selected or deselected -> where? - function get_testbeds_with_sla() { - return $.ajax({ - url: '/sla/testbeds/', - async: true - }); - } - query = query_ext.query; 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 @@ -1722,7 +1715,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, @@ -1730,7 +1723,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 @@ -1742,6 +1735,31 @@ 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) { @@ -1857,7 +1875,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: diff --git a/myslice/settings.py b/myslice/settings.py index d3228482..5fe21697 100644 --- a/myslice/settings.py +++ b/myslice/settings.py @@ -360,6 +360,5 @@ CSRF_FAILURE_VIEW = 'manifoldapi.manifoldproxy.csrf_failure' ####SLA##### SLA_COLLECTOR_URL = "http://157.193.215.125:4001/sla-collector/sla" -#SLA_COLLECTOR_URL = "http://172.24.76.19:8000/sla" // TODO: Remove line SLA_COLLECTOR_USER = "portal" SLA_COLLECTOR_PASSWORD = "password" diff --git a/plugins/sladialog/static/js/sladialog.js b/plugins/sladialog/static/js/sladialog.js index b76a23d8..2773df09 100644 --- a/plugins/sladialog/static/js/sladialog.js +++ b/plugins/sladialog/static/js/sladialog.js @@ -16,6 +16,7 @@ var SlaDialog = Plugin.extend({ accepted_slas: {}, + queries: [], /** XXX to check * @brief Plugin constructor @@ -45,6 +46,20 @@ // call function this.button_binding(); + // Get testbeds with sla and store them in localStorage + //this.get_testbeds_with_sla(); + + }, + + get_testbeds_with_sla: function () { + return $.get('/sla/testbeds/', function(data) { + if (typeof(Storage) !== "undefined") { + if (!localStorage.getItem("sla_testbeds")) { + var testbeds = data; + localStorage.setItem("sla_testbeds", testbeds); + } + } + }); }, find_row: function(key) @@ -86,11 +101,19 @@ self.accepted_slas[id] = true; var is_ok = self.check_template_status(); + $(".sla-alert").show(); + $(this).button("complete"); + $(this).prop("disabled", true); + if (is_ok) { // remove warnings // var warnings = manifold.query_store.get_record_state(resource_query.query_uuid, resource_key, STATE_WARNINGS); } }); + + $(".sla-alert-close").click(function() { + $(this).closest(".sla-alert").hide(); + }); }, create_sla: function(record) { @@ -219,6 +242,8 @@ if ($("#" + id_ref).data("urns").length == 0) { $("#" + id_ref).hide(); delete self.accepted_slas[id_ref]; + $(".sla-accept-button").button("reset"); + $(".sla-accept-button").prop("disabled", false); } //$( "#sla_offers_list" ).append( // $("
  • ").text("Testbed " + testbeds[pos] + " offers SLA for its resources") diff --git a/plugins/sladialog/templates/sladialog.html b/plugins/sladialog/templates/sladialog.html index 9e3ba903..b1a9ab25 100644 --- a/plugins/sladialog/templates/sladialog.html +++ b/plugins/sladialog/templates/sladialog.html @@ -16,6 +16,12 @@ +