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'}, {})
Esempio n. 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})
Esempio n. 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):
        """
Esempio n. 4
0
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
Esempio n. 5
0
def reset_container():
    """
    Resets the container for warm restart. Simple implementation
    currently. Used for testing only.
    """
    # The following is extremely hacky. Reset static module and classvariables
    # to their defaults. Even further, reset imported names in other modules
    # to the new objects.
    base_process.procRegistry = Store()
    base_process.processes = {}
    base_process.receivers = []
    spawnable.store = Container.store
    spawnable.Spawnable.progeny = {}
Esempio n. 6
0
 def _stop_container(self):
     """
     Taking down the container's connection to the broker an preparing for
     reinitialization.
     """
     logging.info("Closing ION container")
     self.test_sup = None
     dcs = reactor.getDelayedCalls()
     logging.info("Cancelling %s delayed reactor calls!" % len(dcs))
     for dc in dcs:
         dc.cancel()
     self.cont_conn.transport.loseConnection()
     container.Container._started = False
     container.Container.store = Store()
     bootstrap.reset_container()
     logging.info("============ION container closed============")
Esempio n. 7
0
def currenttime():
    """
    @retval current UTC time as float with seconds in epoch and fraction
    """
    return time.time()


def currenttime_ms():
    """
    @retval current UTC time as int with milliseconds in epoch
    """
    return int(currenttime() * 1000)


# Stuff for testing: Stubs, mock objects
fakeStore = Store()


class FakeMessage(object):
    """Instances of this object are given to receive functions and handlers
    by test cases, in lieu of carrot BaseMessage instances. Production code
    detects these and no send is done.
    """
    def __init__(self, payload=None):
        self.payload = payload

    @defer.inlineCallbacks
    def send(self, to, msg):
        self.sendto = to
        self.sendmsg = msg
        # Need to be a generator
Esempio n. 8
0
 def slc_init(self):
     self.datastore = Store()
Esempio n. 9
0
 def slc_init(self):
     self.store = Store()
Esempio n. 10
0
 def _setup_backend(self):
     """return a deferred which returns a initiated instance of a
     backend
     """
     d = Store.create_store()
     return d
Esempio n. 11
0
 def slc_init(self):
     self.topics = Store()