From 6f6374f374c82d146766a656788f3b34a20cf343 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Javier=20Garc=C3=ADa?= Date: Fri, 24 Apr 2015 10:59:29 +0200 Subject: [PATCH] Fixed sla creation calls and cleaned debug messages --- myslice/settings.py | 1 + plugins/sladialog/static/js/sladialog.js | 13 +++++----- sla/slaclient/restclient.py | 3 +-- sla/slaclient/xmlconverter.py | 5 ++-- sla/slicetabsla.py | 32 ++++++++++++++++-------- sla/templates/slice-tab-sla.html | 4 +-- sla/wsag_helper.py | 2 -- 7 files changed, 34 insertions(+), 26 deletions(-) diff --git a/myslice/settings.py b/myslice/settings.py index 5fe21697..1581d396 100644 --- a/myslice/settings.py +++ b/myslice/settings.py @@ -360,5 +360,6 @@ 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" 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 c1187435..b76a23d8 100644 --- a/plugins/sladialog/static/js/sladialog.js +++ b/plugins/sladialog/static/js/sladialog.js @@ -98,13 +98,14 @@ 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] === "object") { + + 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 diff --git a/sla/slaclient/restclient.py b/sla/slaclient/restclient.py index e6c516d2..a3445548 100755 --- a/sla/slaclient/restclient.py +++ b/sla/slaclient/restclient.py @@ -126,7 +126,6 @@ class Client(object): # for key, values in kwargs.iteritems(): # print key, values - logger.debug('SLA GET {}'.format(url)) result = requests.get(url, **kwargs) logger.debug('SLA GET {} - result: {}'.format(result.url, result.status_code)) # print "GET {} {} {}".format( @@ -170,7 +169,7 @@ class Client(object): result = requests.post(url, data, **kwargs) location = result.headers["location"] \ if "location" in result.headers else "" - print "POST {} {} Location: {}".format( + print "POST {} {} - Location: {}".format( result.url, result.status_code, location) return result diff --git a/sla/slaclient/xmlconverter.py b/sla/slaclient/xmlconverter.py index 1d3e22ef..35dc58c3 100755 --- a/sla/slaclient/xmlconverter.py +++ b/sla/slaclient/xmlconverter.py @@ -201,9 +201,8 @@ class AgreementConverter(Converter): :param Element xmlroot: root element of xml to convert. :rtype: wsag_model.Agreement """ - for name, value in xmlroot.attrib.items(): - logger.debug('SLA xmlconverter: {} = {}'.format(name, value)) - # print '{0}="{1}"'.format(name, value) + # for name, value in xmlroot.attrib.items(): + # logger.debug('SLA xmlconverter: {} = {}'.format(name, value)) if xmlroot.tag in self.agreement_tags: result = Agreement() diff --git a/sla/slicetabsla.py b/sla/slicetabsla.py index 5fcdc04f..c9043f67 100755 --- a/sla/slicetabsla.py +++ b/sla/slicetabsla.py @@ -3,6 +3,7 @@ from __future__ import print_function # this somehow is not used anymore - should it not be ? import ast from datetime import datetime +import json import pytz from django.template import RequestContext from django.shortcuts import render_to_response @@ -117,7 +118,8 @@ class SLAView(FreeAccessView, ThemeView): row.append(agreement.context.time_formatted()) # Date enf = _get_enforcement(agreement.agreement_id, provider) - logger.debug("SLA AAAAA: {}".format(agreement.guaranteestatus)) + # logger.debug("SLA guarantee status {}: {}".format(agreement.agreement_id, + # agreement.guaranteestatus)) if enf.enabled == 'true': row.append('Evaluating') # Status @@ -402,22 +404,30 @@ class CreateAgreement(LoginRequiredView, ThemeView): pattern = re.compile(testbed_urn_regex) testbed_urn = pattern.search(data["SLIVER_INFO_AGGREGATE_URN"]).group(1) - tstmp = data["SLIVER_INFO_EXPIRATION"] + # Fix for django QueryDict list parameters + slivers = data.getlist("SLIVER_INFO_URN[]") + data["SLIVER_INFO_URN"] = slivers + del data["SLIVER_INFO_URN[]"] + # Timestamp to ISO date + timezone + tstmp = data["SLIVER_INFO_EXPIRATION"] dt = datetime.fromtimestamp(float(tstmp)) - gmt_2 = pytz.timezone("Etc/GMT-2") # FIXME: hardcoded for demo purposes - dlocal = gmt_2.localize(dt).isoformat() - + # gmt_2 = pytz.timezone("Etc/GMT-2") + # dlocal = gmt_2.localize(dt).isoformat() + dlocal = dt.isoformat() + "CET" # FIXME: hardcoded for demo purposes data["SLIVER_INFO_EXPIRATION"] = dlocal - logger.debug("SLA Agreement parameters: {}".format(data)) + # logger.debug("SLA Agreement parameters: {}".format(data.dict())) + # import pdb; pdb.set_trace() try: - response = c.post("agreementslist/", data=data, testbed=testbed_urn) + response = c.post("agreementslist/", data=json.dumps(data), + headers={"accept": "application/json", + "content-type": "application/json"}) except Exception as e: - import traceback, sys - - traceback.print_exc(file=sys.stdout) - logger.debug("SLA ERROR {}".format(e.message)) + # import traceback, sys + # + # traceback.print_exc(file=sys.stdout) + logger.debug("SLA Error: CreateAgreement {}".format(e.message)) return HttpResponse(response.text, status=response.status_code) diff --git a/sla/templates/slice-tab-sla.html b/sla/templates/slice-tab-sla.html index 91953b04..a737577e 100755 --- a/sla/templates/slice-tab-sla.html +++ b/sla/templates/slice-tab-sla.html @@ -32,13 +32,13 @@
Experimenter
{{ row.agreement.context.consumer|default:" " }}
Service
-
Testbed guarantees 0.99 Uptime rate for 0.99 rate of the resources during the sliver lifetime
+
Testbed guarantees 0.99 Uptime rate for 0.99 rate of the selected resources
Testbed
{{ row.agreement.context.testbed_formatted }}
Expiration date:
{{ row.date|default:" " }}
-
Covered slivers:
+
Covered resources:
{% for sliver in row.slivers %}
{{ sliver|default:" " }}
{% endfor %} diff --git a/sla/wsag_helper.py b/sla/wsag_helper.py index 6c7887a1..162e8288 100755 --- a/sla/wsag_helper.py +++ b/sla/wsag_helper.py @@ -105,8 +105,6 @@ class AgreementAnnotator(object): """ a = agreement - logger.debug("SLA STATUS: {}".format(status)) - if status is not None: a.guaranteestatus = status.guaranteestatus a.statusclass = self._get_statusclass(status.guaranteestatus) -- 2.43.0