class ServiceRegistryService(BaseService): """ Service registry service interface @todo a service is a resource and should also be living in the resource registry """ # Declaration of service declare = BaseService.service_declare(name='service_registry', version='0.1.0', dependencies=[]) def slc_init(self): self.datastore = Store() @defer.inlineCallbacks def op_register_service(self, content, headers, msg): """ Service operation: register a service by name """ svcdesc = content['svc_desc'].copy() logging.info('op_register_service: '+str(svcdesc)) yield self.datastore.put(svcdesc['name'],svcdesc) yield self.reply_ok(msg) def op_get_service_desc(self, content, headers, msg): """ Service operation: Get service description. May include a service specification. """ @defer.inlineCallbacks def op_register_instance(self, content, headers, msg): """ Service operation: """ svcinstdesc = content['svcinst_desc'].copy() logging.info('op_register_instance: '+str(svcinstdesc)) yield self.datastore.put(svcinstdesc['svc_name'], svcinstdesc) yield self.reply_ok(msg) @defer.inlineCallbacks def op_get_instance(self, content, headers, msg): """ Service operation: Returns the exchange name of the service """ svcname = str(content['svc_name']) logging.info('op_get_instance: '+str(svcname)) svcid = yield self.datastore.get(svcname) yield self.reply_ok(msg, {'svcinst_desc':svcid})
class DataPubsubService(BaseService): """Data publish/subscribe service interface """ # Declaration of service declare = BaseService.service_declare(name='data_pubsub', version='0.1.0', dependencies=[]) def slc_init(self): self.topics = Store() @defer.inlineCallbacks def op_define_topic(self, content, headers, msg): """Service operation: Register a "topic" that can be published on and that can be subscribed to. Note: this has no direct connection to any AMQP topic notion. A topic is basically a data stream. """ topic_name = content['topic_name'] topic = {topic_name:{'name_type':'fanout', 'args':{'scope':'system'}}} yield bootstrap.declare_messaging(topic) qtopic_name = self.get_scoped_name('system',topic_name) yield self.topics.put(topic_name, topic[topic_name]) yield self.reply_ok(msg, {'topic_name':qtopic_name}, {}) def op_define_publisher(self, content, headers, msg): """Service operation: Register a publisher that subsequently is authorized to publish on a topic. """ def op_subscribe(self, content, headers, msg): """Service operation: Register a subscriber's intent to receive subscriptions on a topic, with additional filter and delivery method details. """ subscriber = None topic = None eventOnly = False def op_unsubscribe(self, content, headers, msg): """Service operation: Stop one's existing subscription to a topic. """ @defer.inlineCallbacks def op_publish(self, content, headers, msg): """Service operation: Publish data message on a topic """ topic_name = content['topic_name'] headers = content['msg_headers'] op = content['msg_op'] msg = content['msg'] qtopic = self.get_scoped_name('system',topic_name) # Todo: impersonate message as from sender yield self.send(qtopic, op, msg, headers) def find_topic(self, content, headers, msg): """Service operation: For a given resource, find the topic that contains
class AssociationService(BaseService): """Example service implementation """ # Declaration of service declare = BaseService.service_declare(name='associations', version='0.1.0', dependencies=[]) # def __init__(self, receiver, spawnArgs=None): # BaseService.__init__(self, receiver, spawnArgs) # logging.info('HelloService.__init__()') def slc_init(self): self.store = Store() @defer.inlineCallbacks def op_put_association(self, content, headers, msg): ''' content is a DataObject encoding - a Dictionary! For storing blobs, we really just want to store it encoded. Can we get the serialized value from the messaging layer? ''' logging.info('op_put_association: '+str(content)) association = ValueObject(content) yield self.store.put(association.identity, association.value) # @ TODO add References! # The following line shows how to reply to a message yield self.reply(msg, 'reply', {'Stored Key':association.identity}, {}) @defer.inlineCallbacks def op_get_association(self, content, headers, msg): ''' ''' association = yield self.store.get(content['key']) # The following line shows how to reply to a message yield self.reply(msg, 'reply', association, {}) @defer.inlineCallbacks def op_del_association(self, content, headers, msg): ''' ''' # @ TODO remove References! yield self.store.delete(content['key']) # The following line shows how to reply to a message yield self.reply(msg, 'reply', {'result':'success'}, {})
class ResourceRegistryService(BaseService): """ Resource registry service interface """ # Declaration of service declare = BaseService.service_declare(name='resource_registry', version='0.1.0', dependencies=[]) # For now, keep registration in local memory store. def slc_init(self): self.datastore = Store() @defer.inlineCallbacks def op_register_resource(self, content, headers, msg): """ Service operation: Register a resource instance with the registry. """ resdesc = content['res_desc'].copy() logging.info('op_register_resource: '+str(resdesc)) resdesc['lifecycle_state'] = ResourceLCState.RESLCS_NEW resid = pu.create_unique_id('R:') yield self.datastore.put(resid, resdesc) yield self.reply_ok(msg, {'res_id':str(resid)},) def op_define_resource_type(self, content, headers, msg): """ Service operation: Create or update a resource type with the registry. """ @defer.inlineCallbacks def op_get_resource_desc(self, content, headers, msg): """ Service operation: Get description for a resource instance. """ resid = content['res_id'] logging.info('op_get_resource_desc: '+str(resid)) res_desc = yield self.datastore.get(resid) yield self.reply_ok(msg, {'res_desc':res_desc}) def op_set_resource_lcstate(self, content, headers, msg): """ Service operation: set the life cycle state of resource """ def op_find_resources(self, content, headers, msg): """