Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Rewrite BucketConfigRepository, talk to Stagecraft
Browse files Browse the repository at this point in the history
We don't store the metadata in Backdrop any more. We're modifying
BucketConfigRepository to call the Stagecraft /data-sets endpoint to get
the metadata.
  • Loading branch information
nick-gravgaard authored and Paul M Furley committed Feb 20, 2014
1 parent a4c855e commit 8b3ab56
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 14 deletions.
65 changes: 52 additions & 13 deletions backdrop/core/repository.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

import json

import requests

from backdrop.core.bucket import BucketConfig
from backdrop.core.user import UserConfig

Expand Down Expand Up @@ -42,27 +47,61 @@ def _create_model(self, doc):

class BucketConfigRepository(object):

def __init__(self, db):
self._db = db
self._repository = _Repository(db, BucketConfig, "buckets", "name")
def __init__(self, stagecraft_url, stagecraft_token):
self._stagecraft_url = stagecraft_url
self._stagecraft_token = stagecraft_token

def save(self, bucket_config, create_bucket=True):
self._repository.save(bucket_config)

This comment has been minimized.

Copy link
@roc

roc Mar 10, 2014

Contributor

Dumb question: isn't this how we save config in backdrop at the moment? What happens when I want to change some bucket metadata?

If not, can this method be completely removed for clarity?

This comment has been minimized.

Copy link
@fawkesley

fawkesley Mar 10, 2014

Contributor

"isn't this how we save config in backdrop at the moment?" - not after you hit merge :)
"What happens when I want to change some bucket metadata?" - you go to Stagecraft

My feeling is that we previously advertised save() it as a public interface, so it's weird to get rid of it (and someone might think we removed it accidentally). On the other hand this repo is the only user of that method, so if you think it's clearer to remove it, I'll support that :)

This comment has been minimized.

Copy link
@roc

roc via email Mar 10, 2014

Contributor

if bucket_config.realtime and create_bucket:
self._db.create_capped_collection(bucket_config.name,
bucket_config.capped_size)
raise NotImplementedError("You can't create/update data-sets through "
"backdrop any more - this is read-only.")

def get_all(self):
return self._repository.get_all()
data_set_url = '{url}/data-sets/'.format(url=self._stagecraft_url)

data_sets = _decode_json(_get_url(data_set_url))
return [_make_bucket_config(data_set) for data_set in data_sets]

def retrieve(self, name):

This comment has been minimized.

Copy link
@roc

roc Mar 10, 2014

Contributor

What happens if there isn't a name? Return all? Fail? I guess regardless it should be handled.

This comment has been minimized.

Copy link
@robyoung

robyoung Mar 11, 2014

Contributor

It's quite common in python to return None if a thing isn't found. Are you talking about if the name is None? If so, I agree, we should do some validation that the name is a non empty string.

return self._repository.retrieve(name)
data_set_url = ('{url}/data-sets/{data_set_name}'.format(
url=self._stagecraft_url,
data_set_name=name))

data_set = _decode_json(_get_url(data_set_url))
return _make_bucket_config(data_set)

def get_bucket_for_query(self, data_group, data_type):
return self._repository.find_first_instance_of(

This comment has been minimized.

Copy link
@roc

roc Mar 10, 2014

Contributor

Same issue as above... maybe there's room for a requests validation decorator. Otherwise, just some validation in these methods.

{"data_group": data_group,
"data_type": data_type})
data_set_url = ('{url}/data-sets?data-group={data_group_name}'
'&data-type={data_type_name}'.format(
url=self._stagecraft_url,
data_group_name=data_group,
data_type_name=data_type))

data_sets = _decode_json(_get_url(data_set_url))
if len(data_sets) > 0:
return _make_bucket_config(data_sets[0])
return None


def _make_bucket_config(stagecraft_dict):
if stagecraft_dict is None:
return None
return BucketConfig(**stagecraft_dict)


def _decode_json(string):
return json.loads(string) if string is not None else None


def _get_url(url):
response = requests.get(url)
try:
response.raise_for_status()
except requests.HTTPError as e:
if e.code == 404:
return None
raise

return response.content


class UserConfigRepository(object):
Expand Down
2 changes: 2 additions & 0 deletions backdrop/read/config/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@
# LPA / Lasting Power of Attorney
"lpa_journey": True,
}

STAGECRAFT_URL = 'stagecraft.perfplat.dev:3204'
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pymongo==2.6.3
python-dateutil==2.1
pytz==2013b
rauth==0.5.5
requests==1.2.3
statsd==2.0.3
xlrd==0.9.2
logstash_formatter==0.5.7
1 change: 0 additions & 1 deletion requirements_for_tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ mock==1.0.1
nose==1.3.0
pep8==1.4.5
PyHamcrest==1.7.1
requests==1.2.3
selenium==2.37.2
splinter==0.5.4
freezegun==0.1.11

0 comments on commit 8b3ab56

Please sign in to comment.