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'}, {})
示例#2
0
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})
示例#3
0
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):
        """