From: Javier GarcĂ­a Date: Tue, 21 Apr 2015 15:39:07 +0000 (+0200) Subject: SLA plugin code updated & SLA app folder cleaned X-Git-Tag: myslice-1.3~36 X-Git-Url: http://git.onelab.eu/?p=unfold.git;a=commitdiff_plain;h=6ff6f343105cd2ef19a99126b07e8dabf57d65f4 SLA plugin code updated & SLA app folder cleaned --- diff --git a/manifoldapi/static/js/manifold.js b/manifoldapi/static/js/manifold.js index d7e56883..4ca5e007 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) { @@ -1684,6 +1688,15 @@ 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) { @@ -1729,8 +1742,44 @@ case TYPE_LIST_OF_VALUES: } } + // 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; diff --git a/myslice/settings.py b/myslice/settings.py index f4d0835b..bcd8df50 100644 --- a/myslice/settings.py +++ b/myslice/settings.py @@ -256,6 +256,8 @@ INSTALLED_APPS = [ # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', 'portal', + #SLA + #'sla', ] # with django-1.7 we leave south and use native migrations # managing database migrations @@ -357,7 +359,6 @@ CSRF_FAILURE_VIEW = 'manifoldapi.manifoldproxy.csrf_failure' ####SLA##### -SLA_MANAGER_URL = "http://157.193.215.125:4001/sla-collector/sla" -#SLA_MANAGER_URL = "http://172.24.76.28:8000/sla" -SLA_MANAGER_USER = "portal" -SLA_MANAGER_PASSWORD = "password" +SLA_COLLECTOR_URL = "http://157.193.215.125:4001/sla-collector/sla" +SLA_COLLECTOR_USER = "portal" +SLA_COLLECTOR_PASSWORD = "password" diff --git a/myslice/urls.py b/myslice/urls.py index 631c15ef..e2b85cce 100644 --- a/myslice/urls.py +++ b/myslice/urls.py @@ -126,7 +126,7 @@ urls = [ url(r'^portal/', include('portal.urls')), # SLA -# url(r'^sla/', include('sla.urls')), + #url(r'^sla/', include('sla.urls')), ] urls.extend( components.urls() ) diff --git a/plugins/columns_editor/__init__.py b/plugins/columns_editor/__init__.py index a58d4120..b651da33 100644 --- a/plugins/columns_editor/__init__.py +++ b/plugins/columns_editor/__init__.py @@ -41,6 +41,18 @@ class ColumnsEditor(Plugin): metadata = self.page.get_metadata() md_fields = metadata.details_by_object('resource') + sla_column_info = { + 'name': 'sla_supported', + 'default': '', + 'is_array': False, + 'description': '', + 'type': 'bool', + 'qualifier': None + } + + if sla_column_info not in md_fields['column']: + md_fields['column'].append(sla_column_info) + # XXX use django templating system here for md_field in sorted(md_fields['column']): if md_field['type'] == 'string': diff --git a/plugins/scheduler2/templates/scheduler.html b/plugins/scheduler2/templates/scheduler.html index 259723b1..89f34195 100755 --- a/plugins/scheduler2/templates/scheduler.html +++ b/plugins/scheduler2/templates/scheduler.html @@ -137,3 +137,4 @@ //alert("1"); + \ No newline at end of file diff --git a/plugins/sladialog/static/css/sladialog.css b/plugins/sladialog/static/css/sladialog.css index e69de29b..ae147405 100644 --- a/plugins/sladialog/static/css/sladialog.css +++ b/plugins/sladialog/static/css/sladialog.css @@ -0,0 +1,12 @@ +#sla_dialog { + //margin-top: 2em; + margin-left: 1em; +} + +#sla_offers div.row p { + line-height: 40px; +} + +span.provider { + font-weight: bold; +} \ No newline at end of file diff --git a/plugins/sladialog/static/js/sladialog.js b/plugins/sladialog/static/js/sladialog.js index 1098e2ef..c1187435 100644 --- a/plugins/sladialog/static/js/sladialog.js +++ b/plugins/sladialog/static/js/sladialog.js @@ -15,6 +15,8 @@ var SlaDialog = Plugin.extend({ + accepted_slas: {}, + /** XXX to check * @brief Plugin constructor * @param options : an associative array of setting values @@ -41,6 +43,7 @@ /* GUI setup and event binding */ // call function + this.button_binding(); }, @@ -61,18 +64,71 @@ return cols[0]; }, + check_template_status: function() { + for (var testbed in this.accepted_slas) { + if (!this.accepted_slas[testbed]) { return false; } + } + + return true; + }, + /* PLUGIN EVENTS */ // on_show like in querytable /* GUI EVENTS */ + button_binding: function() { + var self = this; + $(".sla-accept-button").click(function() { + // set SLA as accepted and remove warnings + var id = $(this).closest(".row").attr("id"); + self.accepted_slas[id] = true; + var is_ok = self.check_template_status(); + + if (is_ok) { + // remove warnings + // var warnings = manifold.query_store.get_record_state(resource_query.query_uuid, resource_key, STATE_WARNINGS); + } + }); + }, + + create_sla: function(record) { + var self = this; + + var urns = []; + + record.resource.forEach(function(r) { + if ($.inArray(r.component_id, record.resource) == -1) { // if not already selected + urns.push(r.component_id); + } + }); + + if (record.resource.length != 0 && typeof record.resource[0] !== "undefined") { + var data = { + "SLIVER_INFO_AGGREGATE_URN": record.resource[0].component_manager_id, + "SLIVER_INFO_EXPIRATION": record.lease[0].end_time, // FIXME: only working with leases + "SLIVER_INFO_SLICE_URN": record.slice_urn, + "SLIVER_INFO_CREATOR_URN": record.users[0], + "SLIVER_INFO_URN": urns, + "SLIVER_INFO_SLA_ID": self._getUUID() + }; + + console.log(data); + + $.post("/sla/agreements/create/", data) + .done(function (response) { + console.log("SLA created"); + }); + } + }, + uncheck: function(urn) { - $('#slamodal').on('hidden.bs.modal', function(e){ - $('#' + (urn).replace(/"/g,'')).click(); - console.log('#' + (data.value).replace(/"/g,'')); - }); +// $('#slamodal').on('hidden.bs.modal', function(e){ +// $('#' + (urn).replace(/"/g,'')).click(); +// console.log('#' + (data.value).replace(/"/g,'')); +// }); }, // a function to bind events here: click change @@ -117,10 +173,69 @@ }, - on_field_state_changed: function(result) + on_field_state_changed: function(data) { - console.log("triggered state_changed: "+result); + var self = this; // this.set_state(result, this.options.username); + + switch(data.state) { + case STATE_SET: + switch(data.op) { + case STATE_SET_IN_PENDING: + if (typeof(data.value) == 'string') { + // data.value = urn + this._supports_sla(data.value) + .done( function(testbeds) { + var urn_regexp = /\+(.*?)\+/; + var urn = urn_regexp.exec(data.value)[1]; + var pos = $.inArray(urn, testbeds); + if ( pos != -1) { + var id_ref = testbeds[pos].replace(/\.|:/g, "-"); + $("#" + id_ref).data("urns").push(data.value); + $("#" + id_ref).show(); + self.accepted_slas[id_ref] = false; + //$( "#sla_offers_list" ).append( + // $("
  • ").text("Testbed " + testbeds[pos] + " offers SLA for its resources") + //); + } + }); + } + break; + case STATE_SET_OUT: + // data.value = urn + if (typeof(data.value) == 'string') { + // data.value = urn + this._supports_sla(data.value) + .done( function(testbeds) { + var urn_regexp = /\+(.*?)\+/; + var urn = urn_regexp.exec(data.value)[1]; + var pos = $.inArray(urn, testbeds); + if ( pos != -1) { + var id_ref = testbeds[pos].replace(/\.|:/g, "-"); + var array = $("#" + id_ref).data("urns"); + array.splice(array.indexOf(data.value), 1); + + if ($("#" + id_ref).data("urns").length == 0) { + $("#" + id_ref).hide(); + delete self.accepted_slas[id_ref]; + } + //$( "#sla_offers_list" ).append( + // $("
  • ").text("Testbed " + testbeds[pos] + " offers SLA for its resources") + //); + } + }); + } + break; + } + break; + + case STATE_WARNINGS: + // Add resource to SLA + // data.key = urn + // data.value = {1: "SLA acceptance required..."} + // this.change_status(data.key, data.value); + break; + } }, // ... be sure to list all events here @@ -133,7 +248,7 @@ on_new_record: function(record) { - + this.create_sla(record); }, /* INTERNAL FUNCTIONS */ @@ -141,6 +256,19 @@ // only convention, not strictly enforced at the moment }, + _supports_sla: function(resource_urn) { + return $.ajax("/sla/testbeds/"); + }, + + + + _getUUID: function() { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { + var r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8); + return v.toString(16); + }); + }, + }); /* Plugin registration */ diff --git a/plugins/sladialog/templates/sladialog.html b/plugins/sladialog/templates/sladialog.html index cb50c29b..e569a429 100644 --- a/plugins/sladialog/templates/sladialog.html +++ b/plugins/sladialog/templates/sladialog.html @@ -1,47 +1,72 @@
    - +
    \ No newline at end of file diff --git a/portal/sliceresourceview.py b/portal/sliceresourceview.py index 2451600a..0968b5db 100644 --- a/portal/sliceresourceview.py +++ b/portal/sliceresourceview.py @@ -398,21 +398,21 @@ class SliceResourceView (LoginRequiredView, ThemeView): # }, # ) - # # -------------------------------------------------------------------------- - # # SLA View and accept dialog - # - # sla_dialog = SlaDialog( - # page = page, - # title = 'sla dialog', - # query = main_query, - # togglable = False, - # # start turned off, it will open up itself when stuff comes in - # toggled = True, - # domid = 'sla_dialog', - # outline_complete = True, - # username = request.user, - # ) - # + # -------------------------------------------------------------------------- + # SLA View and accept dialog + + sla_dialog = SlaDialog( + page = page, + title = 'sla dialog', + query = main_query, + #togglable = False, + # start turned off, it will open up itself when stuff comes in + #toggled = True, + domid = 'sla_dialog', + #outline_complete = True, + username = request.user, + ) + ## check user is pi or not platform_query = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled') account_query = Query().get('local:account').select('user_id','platform_id','auth_type','config') @@ -458,7 +458,7 @@ class SliceResourceView (LoginRequiredView, ThemeView): # template_env['vm_form'] = univbrisvtamform.render(self.request) # template_env['pending_resources'] = pending_resources.render(self.request) - # template_env['sla_dialog'] = '' # sla_dialog.render(self.request) + template_env['sla_dialog'] = sla_dialog.render(self.request) template_env["theme"] = self.theme template_env["username"] = request.user template_env["pi"] = pi diff --git a/portal/templates/fed4fire/fed4fire_slice-resource-view.html b/portal/templates/fed4fire/fed4fire_slice-resource-view.html index 3fefedf7..650092f5 100644 --- a/portal/templates/fed4fire/fed4fire_slice-resource-view.html +++ b/portal/templates/fed4fire/fed4fire_slice-resource-view.html @@ -55,6 +55,7 @@ $(document).ready(function() {
  • Table
  • Map
  • Scheduler
  • +
  • SLA offers
  • @@ -90,6 +91,9 @@ $(document).ready(function() {
    {{map_resources}}
    +
    + {{sla_dialog}} +
    {{scheduler}}
    diff --git a/portal/templates/fed4fire/fed4fire_slice-view.html b/portal/templates/fed4fire/fed4fire_slice-view.html index c2d52c35..05a43a61 100644 --- a/portal/templates/fed4fire/fed4fire_slice-view.html +++ b/portal/templates/fed4fire/fed4fire_slice-view.html @@ -14,5 +14,6 @@
    ...
    +
    ...
    {% endblock %} diff --git a/portal/templates/fed4fire/fed4fire_widget-slice-sections.html b/portal/templates/fed4fire/fed4fire_widget-slice-sections.html index 40761b55..d4fa7cde 100644 --- a/portal/templates/fed4fire/fed4fire_widget-slice-sections.html +++ b/portal/templates/fed4fire/fed4fire_widget-slice-sections.html @@ -20,6 +20,7 @@
  • Tools
  • +
  • SLA status
  • {% else %}