def start_up(): """ This persona hosts resources from a few different APIs in order to facilitate the bootstrap buildout of a brand new meniscus grid. This persona effectively allows the new worker to pair with itself. """ #Datastore adapter/session manager datastore = datasource_handler(COORDINATOR_DB) # Resources versions = VersionResource() configuration = PairingConfigurationResource() worker_registration = WorkerRegistrationResource(datastore) worker_status = WorkerStatusResource(datastore) # Routing application = api = falcon.API() # Pairing Routing api.add_route('/', versions) api.add_route('/v1/pairing/configure', configuration) # Worker Registration Routing api.add_route('/v1/pairing', worker_registration) api.add_route('/v1/worker/{worker_id}/status', worker_status) return application
def start_up(): #Common Resource(s) versions = VersionResource() #Datastore adapter/session manager datastore = datasource_handler(COORDINATOR_DB) #Coordinator Resources worker_registration = WorkerRegistrationResource(datastore) workers_status = WorkersStatusResource(datastore) worker_status = WorkerStatusResource(datastore) #Tenant Resources tenant = TenantResource(datastore) user = UserResource(datastore) event_producers = EventProducersResource(datastore) event_producer = EventProducerResource(datastore) token = TokenResource(datastore) # Create API application = api = falcon.API() # Common Routing api.add_route('/', versions) # Coordinator Routing api.add_route('/v1/pairing', worker_registration) api.add_route('/v1/worker/{worker_id}/status', worker_status) api.add_route('/v1/status', workers_status) # Tenant Routing api.add_route('/v1/tenant', tenant) api.add_route('/v1/tenant/{tenant_id}', user) api.add_route('/v1/tenant/{tenant_id}/producers', event_producers) api.add_route('/v1/tenant/{tenant_id}/producers/{event_producer_id}', event_producer) api.add_route('/v1/tenant/{tenant_id}/token', token) return application
def start_up(): #Common Resource(s) versions = VersionResource() #Datastore adapter/session manager datastore = datasource_handler(COORDINATOR_DB) #Tenant Resources tenant = TenantResource(datastore) user = UserResource(datastore) event_producers = EventProducersResource(datastore) event_producer = EventProducerResource(datastore) token = TokenResource(datastore) # Create API application = api = falcon.API() # Version Routing api.add_route('/', versions) # Tenant Routing api.add_route('/v1/tenant', tenant) api.add_route('/v1/tenant/{tenant_id}', user) api.add_route('/v1/tenant/{tenant_id}/producers', event_producers) api.add_route('/v1/tenant/{tenant_id}/producers/{event_producer_id}', event_producer) api.add_route('/v1/tenant/{tenant_id}/token', token) celery.conf.CELERYBEAT_SCHEDULE = { 'worker_stats': { 'task': 'stats.publish', 'schedule': timedelta(seconds=publish_stats.WORKER_STATUS_INTERVAL) }, } #include blank argument to celery in order for beat to start correctly celery_proc = Process(target=celery.worker_main, args=[['', '--beat']]) celery_proc.start() _LOG.info('Celery started as process: {}'.format(celery_proc.pid)) return application
def start_up(): # Common Resource(s) versions = VersionResource() # Datastore adapter/session manager datastore = datasource_handler(COORDINATOR_DB) # Coordinator Resources worker_registration = WorkerRegistrationResource(datastore) workers_status = WorkersStatusResource(datastore) worker_status = WorkerStatusResource(datastore) # Tenant Resources tenant = TenantResource(datastore) user = UserResource(datastore) event_producers = EventProducersResource(datastore) event_producer = EventProducerResource(datastore) token = TokenResource(datastore) # Create API application = api = falcon.API() # Common Routing api.add_route("/", versions) # Coordinator Routing api.add_route("/v1/pairing", worker_registration) api.add_route("/v1/worker/{worker_id}/status", worker_status) api.add_route("/v1/status", workers_status) # Tenant Routing api.add_route("/v1/tenant", tenant) api.add_route("/v1/tenant/{tenant_id}", user) api.add_route("/v1/tenant/{tenant_id}/producers", event_producers) api.add_route("/v1/tenant/{tenant_id}/producers/{event_producer_id}", event_producer) api.add_route("/v1/tenant/{tenant_id}/token", token) return application
import time from meniscus.data.datastore import datasource_handler, SHORT_TERM_STORE from meniscus.queue import celery _db_handler = datasource_handler(SHORT_TERM_STORE) class Transaction(object): def _lock_records(self): raise NotImplementedError def _retrieve_locked_records(self): raise NotImplementedError def _process_locked_records(self): raise NotImplementedError def _release_lock(self): raise NotImplementedError def process_transaction(self): raise NotImplementedError class BatchMessageTransaction(Transaction): def __init__(self, sink_name, transaction_id, expire_seconds): self.db_handler = _db_handler self.transaction_field_base = "meniscus.correlation.destinations"
def setUp(self): init_config(['--config-file', 'meniscus.cfg']) conf = get_config() self.handler = datasource_handler(conf) self.handler.connect()
from meniscus.data.datastore import datasource_handler, DEFAULT_SINK from meniscus import env from meniscus.queue import celery _LOG = env.get_logger(__name__) _db_handler = datasource_handler(DEFAULT_SINK) @celery.task(acks_late=True, max_retries=None, ignore_result=True, serializer="json") def persist_message(message): """Takes a message and persists it to the default datastore.""" try: sink = _db_handler sink.put('tenant/{}'.format(message['meniscus']['tenant']), message) except Exception as ex: _LOG.exception(ex.message) persist_message.retry()
""" The tenant_util module provides an abstraction of database operations used with instances of the Tenant class and its member objects """ from meniscus.data.datastore import COORDINATOR_DB, datasource_handler from meniscus.data.model.tenant import EventProducer from meniscus.data.model.tenant import ( load_tenant_from_dict, Tenant, Token) from meniscus.data import ttl_tasks _db_handler = datasource_handler(COORDINATOR_DB) def find_tenant(tenant_id, create_on_missing=False): """ Retrieves a dictionary describing a tenant object and its EventProducers and maps them to a tenant object. If the "create_on_missing" param is set a new tenant will be created of the specified tenant is not found in the datastore """ # get the tenant dictionary from the data source tenant = retrieve_tenant(tenant_id) if tenant is None: #if the create_on_missing parameter us set, create the new tenant, # then retrieve it from the data store and return if create_on_missing: create_tenant(tenant_id) tenant = retrieve_tenant(tenant_id)
from meniscus.api.tenant.resources import TenantResource from meniscus.api.tenant.resources import TokenResource from meniscus.api.version.resources import VersionResource from meniscus.data.datastore import COORDINATOR_DB, datasource_handler from meniscus import env from meniscus.openstack.common import log log.setup('meniscus') _LOG = env.get_logger(__name__) #Common Resource(s) versions = VersionResource() #Coordinator Resources db_handler = datasource_handler(COORDINATOR_DB) worker_registration = WorkerRegistrationResource(db_handler) workers_status = WorkersStatusResource(db_handler) worker_status = WorkerStatusResource(db_handler) #Tenant Resources tenant = TenantResource(db_handler) user = UserResource(db_handler) event_producers = EventProducersResource(db_handler) event_producer = EventProducerResource(db_handler) token = TokenResource(db_handler) # Create API application = api = falcon.API() # Common Routing