From aed78ef2aa329dbc3d15aa9dca4795e5cc4464ed Mon Sep 17 00:00:00 2001 From: =?utf8?q?Javier=20Garc=C3=ADa?= Date: Fri, 29 Aug 2014 14:01:24 +0200 Subject: [PATCH] Cleaned code and improved communication with SLA Collector --- myslice/settings.py | 1 + .../queryupdater/static/js/queryupdater.js | 290 +++++------------- plugins/sladialog/templates/sladialog.html | 21 +- sla/slaclient/restclient.py | 26 +- .../service/fed4fire/fed4fireservice.py | 24 +- .../templates/fed4fire/django/agreement.xml | 6 +- sla/slaclient/xmlconverter.py | 12 +- sla/slicetabsla.py | 94 ++++-- sla/templates/slice-tab-sla.html | 2 +- sla/urls.py | 1 + 10 files changed, 206 insertions(+), 271 deletions(-) diff --git a/myslice/settings.py b/myslice/settings.py index 5faef7f8..fe71e108 100644 --- a/myslice/settings.py +++ b/myslice/settings.py @@ -294,5 +294,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" diff --git a/plugins/queryupdater/static/js/queryupdater.js b/plugins/queryupdater/static/js/queryupdater.js index 5d017b9d..2e736293 100644 --- a/plugins/queryupdater/static/js/queryupdater.js +++ b/plugins/queryupdater/static/js/queryupdater.js @@ -75,228 +75,104 @@ do_checksla: function(e) { var username = e.data.options.username; var urn = data.value; - var arrayselectedresources = data.selected_resources; + var arraySelectedResources = data.selected_resources; - var accepted_sla = Array(); + var accepted_sla = []; var count = 0; var self = e.data; - // XXX check that the query is not disabled - - console.log("DATA VALUE: " + data.value); + // var testbedsWithSLA = ["iminds", "fuseco", "netmode"]; + var testbedsWithSLA; - //

SLA description

- //

Testbed guarantees 0.99 Uptime rate for 0.99 rate of the VirtualWall resources during the sliver lifetime

- //

SLA description

- //

Testbed guarantees 0.99 Uptime rate for 0.99 rate of the WiLab2 resources during the sliver lifetime

- var promt = $('#modal-body'); - - // id="myModalLabel" - var flagVW = false; - var flagWi = false; + var sliverPattern = /IDN\+(.+)\+(node|channel)\+/; + var list = []; - promt.append('

SLA description

'); + var promt = $('#sla-table-body'); - var wilabForm = ""; - wilabForm += ""; - - //var wallmessage = '

SLA description

Testbed guarantees 0.99 Uptime rate for 0.99 rate of the VirtualWall resources during the sliver lifetime

'; - - var wallForm = ""; - wallForm += ""; - - var flagDouble = false; - if(flagWi) - { - flagDouble = true; - promt.append('

Testbed guarantees 0.99 Uptime rate for 0.99 rate of the WiLab2 resources during the sliver lifetime

'); - //promt.append(wilabForm); - promt.append('
'); - } - if(flagVW) - { - //promt.append(wallmessage); - flagDouble = true; - promt.append('

Testbed guarantees 0.99 Uptime rate for 0.99 rate of the VirtualWall resources during the sliver lifetime

'); - //promt.append(wallForm); - promt.append('
'); - } - - - // var wimessage = '

SLA description

Testbed guarantees 0.99 Uptime rate for 0.99 rate of the VirtualWall resources during the sliver lifetime

' - - if(flagWi || flagVW){ - $('#sla_dialog').show(); - - $('#slamodal-wilab2').modal('show'); - } - else - { - - - var username = e.data.options.username; - var urn = data.value; - // XXX check that the query is not disabled - - self.spin(); - console.log("do_update"); - // XXX check that the query is not disabled - manifold.raise_event(self.options.query_uuid, RUN_UPDATE); - return; - } - - $("#accept_sla_wilab2").click(function(){ - console.log("SLA ACCEPTED"); - console.log("With username: " + username); - - // var promt = $('#modal-body'); - // var notchecked = true; - // for (var i=0;i<50;i++) - // { - // var wielement = $('#wi'+i); - // var wallElement = $('#wall'+i); - // if(wielement != null && !wielement.checked) - // { - // notchecked = false; - // } - // if(wallElement!= null && !wallElement.checked) - // { - // notchecked = false; - // } - // } - - if(flagDouble) - { - $.post("/sla/agreements/simplecreate", - { "template_id": "iMindsServiceWiLab2", - "user": username, - "expiration_time": new Date().toISOString() - }); - $.post("/sla/agreements/simplecreate", - { "template_id": "iMindsServiceVirtualwall", - "user": username, - "expiration_time": new Date().toISOString() - }); - - $('#slamodal-wilab2').modal('hide'); - accepted_sla["wilab2"] = true; - - //manifold.raise_event(self.options.query_uuid, RUN_UPDATE); - } - $('#modal-body').empty(); - }); + }); - $("#dismiss_sla_wilab2").click(function(){ - console.log("SLA NOT ACCEPTED"); - $('#slamodal-wilab2').modal('hide'); - $('#modal-body').empty(); - }); + $("#submit_sla").unbind().click(function(){ + console.log("With username: " + username); + + var notChecked = $("input[name='slaaccept']:not(:checked)"); - // } else { - // this.do_update(e); - // } + if (notChecked.length > 0) { + for (var i = 0; i < notChecked.length; i++) { + console.log("SLA not accepted: " + notChecked[i].value); + } - // for(var iter = 0; iter < arrayselectedresources.length; iter++){ - // var list = ''+arrayselectedresources[iter].toLowerCase()+'
'; - // promt.append(list); - // if (arrayselectedresources[iter].toLowerCase().indexOf("wall2") >= 0){ + alert("All SLAs have to be accepted to continue with the reservation"); + } else { + // $(list).each(function () { + // var date = new Date(); + // date.setYear(date.getFullYear() + 1); - - // accepted_sla.push({"wall2":false}); + // $.post("/sla/agreements/simplecreate", + // { "template_id": this.toString(), + // "user": username, + // "expiration_time": date.toISOString() + // }); - // $('#sla_dialog').show(); - // $('#slamodal-virtualwall').modal('show'); - - - // $("#accept_sla_vwall").click(function(){ - // console.log("SLA ACCEPTED"); - // console.log("With username: " + username); - - // $.post("/sla/agreements/simplecreate", - // { "template_id": "iMindsServiceVirtualwall", - // "user": username, - // "expiration_time": new Date() - // }); - // $('#slamodal-virtualwall').modal('hide'); - // accepted_sla["wall2"] = true; - // }); - - // $("#dismiss_sla_vwall").click(function(){ - // console.log("SLA NOT ACCEPTED"); - // $('#slamodal-vir').modal('hide'); - // }); - - // } - - // if (arrayselectedresources[iter].toLowerCase().indexOf("wilab2") >= 0){ - - // accepted_sla.push({"wilab2":false}); - - // $('#sla_dialog').show(); - // $('#slamodal-wilab2').modal('show'); - - - // $("#accept_sla_wilab2").click(function(){ - // console.log("SLA ACCEPTED"); - // console.log("With username: " + username); - - // $.post("/sla/agreements/simplecreate", - // { "template_id": "iMindsServiceWiLab2", - // "user": username, - // "expiration_time": new Date() - // }); - - // $('#slamodal-wilab2').modal('hide'); - // accepted_sla["wilab2"] = true; - // }); - - // $("#dismiss_sla_wilab2").click(function(){ - // console.log("SLA NOT ACCEPTED"); - // $('#slamodal-wilab2').modal('hide'); - // }); - - - // } - - // } - - // for(var sla in accepted_sla){ - // if(accepted_sla[sla] == true){ - // count += 1; - // } - // } - - // if(count == accepted_sla.length){ - // this.do_update(e); - // } + // }); + + $.ajax({ + url: "/sla/agreements/simplecreate", + data: { testbeds: list, + user: username, + resources: arraySelectedResources, + slice: main_query.filters.slice()[0][2] + }, + type: "post", + traditional: true + }); + + console.log(main_query.filters.slice()[0][2]); + + $('#slamodal').modal('hide'); + $('#sla-table-body').empty(); + //manifold.raise_event(self.options.query_uuid, RUN_UPDATE); + } + }); + + $("#cancel_sla").unbind().click(function(){ + $('#slamodal').modal('hide'); + $('#sla-table-body').empty(); + }); }, diff --git a/plugins/sladialog/templates/sladialog.html b/plugins/sladialog/templates/sladialog.html index ce27c2e4..cb50c29b 100644 --- a/plugins/sladialog/templates/sladialog.html +++ b/plugins/sladialog/templates/sladialog.html @@ -1,18 +1,27 @@
-