Add remainding services and split pg code to collector

This commit is contained in:
Endre Karlson 2013-04-25 12:23:06 -07:00
parent 076963a681
commit 44a247eeb5
12 changed files with 161 additions and 7 deletions

View File

@ -20,7 +20,7 @@ from flask import Response
from billingstack.api.base import Rest, Query
from billingstack.api.v1 import models
from billingstack.central.rpcapi import central_api
from billingstack.rating.rpcapi import rating_api
from billingstack.rater.rpcapi import rater_api
from wsmeext.flask import signature
@ -683,7 +683,7 @@ def create_usage(merchant_id, body):
values = body.to_db()
values['merchant_id'] = merchant_id
row = rating_api.create_usage(request.environ['context'], values)
row = rater_api.create_usage(request.environ['context'], values)
return models.Usage.from_db(row)
@ -693,7 +693,7 @@ def create_usage(merchant_id, body):
def list_usages(merchant_id, q=[]):
criterion = _query_to_criterion(q, merchant_id=merchant_id)
rows = rating_api.list_usages(
rows = rater_api.list_usages(
request.environ['context'], criterion=criterion)
return map(models.Usage.from_db, rows)
@ -702,7 +702,7 @@ def list_usages(merchant_id, q=[]):
@bp.get('/merchants/<merchant_id>/usage/<usage_id>')
@signature([models.Usage], str, str)
def get_usage(merchant_id, usage_id):
row = rating_api.get_usage(request.environ['context'],
row = rater_api.get_usage(request.environ['context'],
usage_id)
return models.Usage.from_db(row)
@ -711,7 +711,7 @@ def get_usage(merchant_id, usage_id):
@bp.put('/merchants/<merchant_id>/usage/<usage_id>')
@signature(models.Usage, str, str, body=models.Usage)
def update_usage(merchant_id, usage_id, body):
row = rating_api.update_usage(
row = rater_api.update_usage(
request.environ['context'],
usage_id,
body.to_db())
@ -721,7 +721,7 @@ def update_usage(merchant_id, usage_id, body):
@bp.delete('/merchants/<merchant_id>/usage/<usage_id>')
def delete_usage(merchant_id, usage_id):
rating_api.delete_usage(
rater_api.delete_usage(
request.environ['context'],
usage_id)
return Response(status=204)

View File

@ -0,0 +1,12 @@
from oslo.config import cfg
cfg.CONF.register_group(cfg.OptGroup(
name='service:biller', title="Configuration for Biller Service"
))
cfg.CONF.register_opts([
cfg.IntOpt('workers', default=None,
help='Number of worker processes to spawn'),
cfg.StrOpt('storage-driver', default='sqlalchemy',
help='The storage driver to use'),
], group='service:biller')

View File

@ -0,0 +1,22 @@
from oslo.config import cfg
from billingstack.openstack.common.rpc import proxy
rpcapi_opts = [
cfg.StrOpt('biller_topic', default='biller',
help='the topic biller nodes listen on')
]
cfg.CONF.register_opts(rpcapi_opts)
class BillerAPI(proxy.RpcProxy):
BASE_RPC_VERSION = '1.0'
def __init__(self):
super(BillerAPI, self).__init__(
topic=cfg.CONF.rater_topic,
default_version=self.BASE_RPC_VERSION)
biller_api = BillerAPI()

View File

@ -0,0 +1,28 @@
from oslo.config import cfg
from billingstack.openstack.common import log as logging
from billingstack.openstack.common.rpc import service as rpc_service
from billingstack.biller import storage
cfg.CONF.import_opt('biller_topic', 'billingstack.biller.rpcapi')
cfg.CONF.import_opt('host', 'billingstack.netconf')
cfg.CONF.import_opt('state_path', 'billingstack.paths')
LOG = logging.getLogger(__name__)
class Service(rpc_service.Service):
"""
Biller service
"""
def __init__(self, *args, **kwargs):
kwargs.update(
host=cfg.CONF.host,
topic=cfg.CONF.biller_topic,
)
super(Service, self).__init__(*args, **kwargs)
def start(self):
self.storage_conn = storage.get_connection()
super(Service, self).start()

View File

@ -0,0 +1,17 @@
from oslo.config import cfg
from billingstack.storage import base
class StorageEngine(base.StorageEngine):
"""Base class for the biller storage"""
__plugin_ns__ = 'billingstack.biller.storage'
class Connection(base.Connection):
"""Define the base API for biller storage"""
def get_connection():
name = cfg.CONF['service:biller'].storage_driver
plugin = StorageEngine.get_plugin(name, invoke_on_load=True)
return plugin.get_connection()

View File

@ -0,0 +1,51 @@
# Author: Endre Karlson <endre.karlson@gmail.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
A Usage plugin using sqlalchemy...
"""
from oslo.config import cfg
from sqlalchemy import Column
from sqlalchemy import Unicode, Float, DateTime
from sqlalchemy.ext.declarative import declarative_base
from billingstack.openstack.common import log as logging
from billingstack.biller.storage import Connection, StorageEngine
from billingstack.sqlalchemy.types import UUID
from billingstack.sqlalchemy import api, model_base, session
# DB SCHEMA
BASE = declarative_base(cls=model_base.ModelBase)
LOG = logging.getLogger(__name__)
cfg.CONF.register_group(cfg.OptGroup(
name='biller:sqlalchemy', title='Config for biller sqlalchemy plugin'))
cfg.CONF.register_opts(session.SQLOPTS, group='biller:sqlalchemy')
class SQLAlchemyEngine(StorageEngine):
def get_connection(self):
return Connection()
class Connection(Connection, api.HelpersMixin):
def __init__(self):
self.setup('biller:sqlalchemy')
def base(self):
return BASE

View File

View File

@ -0,0 +1,22 @@
from oslo.config import cfg
from billingstack.openstack.common.rpc import proxy
rpcapi_opts = [
cfg.StrOpt('collector_topic', default='collector',
help='the topic collector nodes listen on')
]
cfg.CONF.register_opts(rpcapi_opts)
class CollectorAPI(proxy.RpcProxy):
BASE_RPC_VERSION = '1.0'
def __init__(self):
super(CollectorAPI, self).__init__(
topic=cfg.CONF.collector_topic,
default_version=self.BASE_RPC_VERSION)
collector_api = CollectorAPI()

View File

@ -10,7 +10,7 @@ from billingstack.central.rpcapi import CentralAPI
cfg.CONF.import_opt('host', 'billingstack.netconf')
cfg.CONF.import_opt('pg_topic', 'billingstack.payment_gateway.rpcapi')
cfg.CONF.import_opt('collector_topic', 'billingstack.collector.rpcapi')
cfg.CONF.import_opt('state_path', 'billingstack.paths')

View File

View File

View File

@ -51,6 +51,8 @@ setup(
'bin/billingstack-db-manage',
'bin/billingstack-manage',
'bin/billingstack-central',
'bin/billingstack-biller',
'bin/billingstack-collector',
'bin/billingstack-rater'
],
cmdclass=common_setup.get_cmdclass(),