From ddc2293d4bb517b16d4bdf887238e7474d2dd365 Mon Sep 17 00:00:00 2001 From: Andrew Melton Date: Tue, 12 Feb 2013 16:07:46 -0500 Subject: [PATCH 1/4] Updating pip-requires --- etc/pip-requires.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/etc/pip-requires.txt b/etc/pip-requires.txt index 3dcf02d..46c7581 100644 --- a/etc/pip-requires.txt +++ b/etc/pip-requires.txt @@ -1,3 +1,6 @@ Django>=1.4.2 MySQL-python>=1.2.3 eventlet>=0.9.17 +kombu==2.5.4 +Pympler==0.3.0 +librabbitmq==1.0.1 From fda6d67b85331ea9ee1f206500e68b604e8a6f0c Mon Sep 17 00:00:00 2001 From: Andrew Melton Date: Thu, 14 Feb 2013 14:45:00 -0500 Subject: [PATCH 2/4] Revert "Updating pip-requires" This reverts commit ddc2293d4bb517b16d4bdf887238e7474d2dd365. --- etc/pip-requires.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/etc/pip-requires.txt b/etc/pip-requires.txt index 46c7581..3dcf02d 100644 --- a/etc/pip-requires.txt +++ b/etc/pip-requires.txt @@ -1,6 +1,3 @@ Django>=1.4.2 MySQL-python>=1.2.3 eventlet>=0.9.17 -kombu==2.5.4 -Pympler==0.3.0 -librabbitmq==1.0.1 From e54a95be6bbd70f2fcfa13c9b10bda0686e9f63a Mon Sep 17 00:00:00 2001 From: Andrew Melton Date: Thu, 14 Feb 2013 15:27:02 -0500 Subject: [PATCH 3/4] Improving str_time_to_unix() --- stacktach/views.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/stacktach/views.py b/stacktach/views.py index d770645..10e6a6d 100644 --- a/stacktach/views.py +++ b/stacktach/views.py @@ -321,17 +321,25 @@ def aggregate_usage(raw): def str_time_to_unix(when): - try: - when = datetime.datetime.strptime(when, "%Y-%m-%d %H:%M:%S") - except ValueError: + if 'T' in when: + try: + # Old way of doing it + when = datetime.datetime.strptime(when, "%Y-%m-%dT%H:%M:%S.%f") + except ValueError: + try: + # Old way of doing it, no millis + when = datetime.datetime.strptime(when, "%Y-%m-%dT%H:%M:%S") + except Exception, e: + print "BAD DATE: ", e + else: try: when = datetime.datetime.strptime(when, "%Y-%m-%d %H:%M:%S.%f") except ValueError: try: - # Old way of doing it - when = datetime.datetime.strptime(when, "%Y-%m-%dT%H:%M:%S.%f") + when = datetime.datetime.strptime(when, "%Y-%m-%d %H:%M:%S") except Exception, e: print "BAD DATE: ", e + return dt.dt_to_decimal(when) From e8131625d0e7760e833b22a4436bbb64c3b74c2d Mon Sep 17 00:00:00 2001 From: Andrew Melton Date: Thu, 14 Feb 2013 15:29:39 -0500 Subject: [PATCH 4/4] Adding gets for individual dbapi resources --- stacktach/dbapi.py | 40 ++++++++++++++++++++++++++++++++-------- stacktach/urls.py | 6 ++++++ worker/worker.py | 3 ++- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/stacktach/dbapi.py b/stacktach/dbapi.py index 6f01a1a..9566011 100644 --- a/stacktach/dbapi.py +++ b/stacktach/dbapi.py @@ -3,8 +3,9 @@ import json from django.forms.models import model_to_dict from django.http import HttpResponse +from django.shortcuts import get_object_or_404 -import datetime_to_decimal +import datetime_to_decimal as dt import models @@ -12,6 +13,12 @@ def rsp(data): return HttpResponse(json.dumps(data), content_type="application/json") +def _get_model_by_id(klass, model_id): + model = get_object_or_404(klass, id=model_id) + model_dict = _convert_model(model) + return model_dict + + def list_usage_launches(request): filter_args = {} if 'instance' in request.GET: @@ -26,6 +33,10 @@ def list_usage_launches(request): return rsp({'launches': dicts}) +def get_usage_launch(request, launch_id): + return rsp({'launch': _get_model_by_id(models.InstanceUsage, launch_id)}) + + def list_usage_deletes(request): filter_args = {} if 'instance' in request.GET: @@ -40,6 +51,10 @@ def list_usage_deletes(request): return rsp({'deletes': dicts}) +def get_usage_delete(request, delete_id): + return rsp({'delete': _get_model_by_id(models.InstanceDeletes, delete_id)}) + + def list_usage_exists(request): filter_args = {} if 'instance' in request.GET: @@ -54,12 +69,21 @@ def list_usage_exists(request): return rsp({'exists': dicts}) -def _convert_model_list(list): +def get_usage_exist(request, exist_id): + return rsp({'exist': _get_model_by_id(models.InstanceExists, exist_id)}) + + +def _convert_model(model): + model_dict = model_to_dict(model) + for key in model_dict: + if isinstance(model_dict[key], decimal.Decimal): + model_dict[key] = str(dt.dt_from_decimal(model_dict[key])) + return model_dict + + +def _convert_model_list(model_list): converted = [] - for item in list: - dict = model_to_dict(item) - for key in dict: - if isinstance(dict[key], decimal.Decimal): - dict[key] = str(datetime_to_decimal.dt_from_decimal(dict[key])) - converted.append(dict) + for item in model_list: + converted.append(_convert_model(item)) + return converted diff --git a/stacktach/urls.py b/stacktach/urls.py index 59c6098..675a557 100644 --- a/stacktach/urls.py +++ b/stacktach/urls.py @@ -27,9 +27,15 @@ urlpatterns = patterns('', url(r'db/usage/launches/$', 'stacktach.dbapi.list_usage_launches'), + url(r'db/usage/launches/(?P\d+)/$', + 'stacktach.dbapi.get_usage_launch'), url(r'db/usage/deletes/$', 'stacktach.dbapi.list_usage_deletes'), + url(r'db/usage/deletes/(?P\d+)/$', + 'stacktach.dbapi.get_usage_delete'), url(r'db/usage/exists/$', 'stacktach.dbapi.list_usage_exists'), + url(r'db/usage/exists/(?P\d+)/$', + 'stacktach.dbapi.get_usage_exist'), url(r'^(?P\d+)/$', 'stacktach.views.home', name='home'), url(r'^(?P\d+)/details/(?P\w+)/(?P\d+)/$', diff --git a/worker/worker.py b/worker/worker.py index 7e10f4e..a651c10 100644 --- a/worker/worker.py +++ b/worker/worker.py @@ -147,7 +147,8 @@ def run(deployment_config): transport="librabbitmq", virtual_host=virtual_host) - while True: + # continue_running() is used for testing + while continue_running(): try: LOG.debug("Processing on '%s'" % name) with kombu.connection.BrokerConnection(**params) as conn: