Ejemplo n.º 1
0
    def test_message_during_init(self):
        child2 = ProcessDesc(name='echo',
                             module='ion.core.test.test_baseprocess')
        pid2 = yield self.test_sup.spawn_child(child2, init=False)
        proc2 = self._get_procinstance(pid2)
        proc2.plc_init = proc2.plc_noinit
        self.assertEquals(proc2.proc_state, 'NEW')

        msgName = self.test_sup.get_scoped_name('global', pu.create_guid())
        messaging = {'name_type': 'worker', 'args': {'scope': 'global'}}
        yield Container.configure_messaging(msgName, messaging)
        extraRec = Receiver(proc2.proc_name, msgName)
        extraRec.handle(proc2.receive)
        extraid = yield spawn(extraRec)
        logging.info('Created new receiver %s with pid %s' %
                     (msgName, extraid))

        yield self.test_sup.send(pid2, 'init', {}, {'quiet': True})
        logging.info('Sent init to process 1')

        yield pu.asleep(0.5)
        self.assertEquals(proc2.proc_state, 'INIT')

        (cont, hdrs,
         msg) = yield self.test_sup.rpc_send(msgName, 'echo', 'content123')
        self.assertEquals(cont['value'], 'content123')
        logging.info('Process 1 responsive correctly after init')

        yield pu.asleep(2)
        self.assertEquals(proc2.proc_state, 'ACTIVE')

        (cont, hdrs,
         msg) = yield self.test_sup.rpc_send(msgName, 'echo', 'content123')
        self.assertEquals(cont['value'], 'content123')
        logging.info('Process 1 responsive correctly after init')
Ejemplo n.º 2
0
def create_producers(proc, n=1):

    dpsc = pubsub_service.DataPubsubClient(proc=proc)

    for i in range(n):

        tname = 'topic name ' + str(i)
        ka = 'keyword a'
        kb = 'keyword b'

        if (i / 2) * 2 == i:
            keyword = ka
        else:
            keyword = kb
        topic = PubSubTopicResource.create(tname, keyword)
        topic = yield dpsc.define_topic(topic)

        dspname = 'data_stream_producer_' + str(i)
        interval = random.randint(1, 10)
        dsp = {
            'name': dspname,
            'module': 'ion.services.dm.util.data_stream_producer',
            'procclass': 'DataStreamProducer',
            'spawnargs': {
                'delivery queue': topic.queue.name,
                'delivery interval': interval
            }
        }

        child = ProcessDesc(**dsp)
        child_id = yield proc.spawn_child(child)
Ejemplo n.º 3
0
    def test_spawn_child(self):
        child1 = ProcessDesc(name='echo',
                             module='ion.core.test.test_baseprocess')
        self.assertEquals(child1.proc_state, 'DEFINED')

        pid1 = yield self.test_sup.spawn_child(child1)
        self.assertEquals(child1.proc_state, 'INIT_OK')
        proc = self._get_procinstance(pid1)
        self.assertEquals(
            str(proc.__class__),
            "<class 'ion.core.test.test_baseprocess.EchoProcess'>")
        self.assertEquals(pid1, proc.receiver.spawned.id)
        logging.info('Process 1 spawned and initd correctly')

        (cont, hdrs,
         msg) = yield self.test_sup.rpc_send(pid1, 'echo', 'content123')
        self.assertEquals(cont['value'], 'content123')
        logging.info('Process 1 responsive correctly')

        # The following tests the process attaching a second receiver
        msgName = self.test_sup.get_scoped_name('global', pu.create_guid())
        messaging = {'name_type': 'worker', 'args': {'scope': 'global'}}
        yield Container.configure_messaging(msgName, messaging)
        extraRec = Receiver(proc.proc_name, msgName)
        extraRec.handle(proc.receive)
        extraid = yield spawn(extraRec)
        logging.info('Created new receiver %s with pid %s' %
                     (msgName, extraid))

        (cont, hdrs,
         msg) = yield self.test_sup.rpc_send(msgName, 'echo', 'content456')
        self.assertEquals(cont['value'], 'content456')
        logging.info('Process 1 responsive correctly on second receiver')
Ejemplo n.º 4
0
    def test_hello(self):

        pd1 = {
            'name': 'hello1',
            'module': 'ion.play.hello_process',
            'class': 'HelloService'
        }

        proc1 = ProcessDesc(**pd1)

        sup1 = yield bootstrap.create_supervisor()

        proc1_id = yield self.test_sup.spawn_child(proc1)

        sup2 = yield bootstrap.create_supervisor()

        logging.info('Calling hello there with hc(sup1)')
        hc1 = HelloProcessClient(proc=sup1, target=proc1_id)
        yield hc1.hello("Hi there, hello1")

        logging.info('Calling hello there with hc(sup2)')
        hc2 = HelloProcessClient(proc=sup2, target=proc1_id)
        yield hc2.hello("Hi there, hello1")

        logging.info('Tada!')
Ejemplo n.º 5
0
 def spawn(name, node=None, args=None):
     (mod, name) = _get_target(name)
     if node != None:
         node = _get_node(node)
         self.send(node, 'spawn', {'module': mod})
     else:
         d = self.spawn_child(ProcessDesc(name=name, module=mod))
Ejemplo n.º 6
0
 def op_spawn(self, content, headers, msg):
     """
     Service operation: spawns a local module
     """
     procMod = str(content['module'])
     child = ProcessDesc(name=procMod.rpartition('.')[2], module=procMod)
     pid = yield self.spawn_child(child)
     yield self.reply_ok(msg, {'process-id': str(pid)})
Ejemplo n.º 7
0
    def test_message_before_init(self):
        child2 = ProcessDesc(name='echo', module='ion.core.test.test_baseprocess')
        pid2 = yield self.test_sup.spawn_child(child2, init=False)
        self.assertEquals(child2.proc_state, 'SPAWNED')
        proc2 = self._get_procinstance(pid2)

        (cont,hdrs,msg) = yield self.test_sup.rpc_send(pid2,'echo','content123')
        self.assertEquals(cont['status'], 'ERROR')
        logging.info('Process 1 rejected first message correctly')

        yield child2.init()
        self.assertEquals(child2.proc_state, 'INIT_OK')
        logging.info('Process 1 rejected initialized OK')

        (cont,hdrs,msg) = yield self.test_sup.rpc_send(pid2,'echo','content123')
        self.assertEquals(cont['value'], 'content123')
        logging.info('Process 1 responsive correctly after init')
Ejemplo n.º 8
0
    def test_error_in_op(self):
        child1 = ProcessDesc(name='echo',
                             module='ion.core.test.test_baseprocess')
        pid1 = yield self.test_sup.spawn_child(child1)

        (cont, hdrs,
         msg) = yield self.test_sup.rpc_send(pid1, 'echofail2', 'content123')
        self.assertEquals(cont['status'], 'ERROR')
        logging.info('Process 1 responded to error correctly')
Ejemplo n.º 9
0
    def test_message_before_init(self):
        child2 = ProcessDesc(name='echo',
                             module='ion.core.test.test_baseprocess')
        pid2 = yield self.test_sup.spawn_child(child2, init=False)
        self.assertEquals(child2.proc_state, 'SPAWNED')
        proc2 = self._get_procinstance(pid2)

        (cont, hdrs,
         msg) = yield self.test_sup.rpc_send(pid2, 'echo', 'content123')
        self.assertEquals(cont['status'], 'ERROR')
        logging.info('Process 1 rejected first message correctly')

        yield child2.init()
        self.assertEquals(child2.proc_state, 'INIT_OK')
        logging.info('Process 1 rejected initialized OK')

        (cont, hdrs,
         msg) = yield self.test_sup.rpc_send(pid2, 'echo', 'content123')
        self.assertEquals(cont['value'], 'content123')
        logging.info('Process 1 responsive correctly after init')
Ejemplo n.º 10
0
    def test_child_processes(self):
        p1 = BaseProcess()
        pid1 = yield p1.spawn()

        child = ProcessDesc(name='echo',
                            module='ion.core.test.test_baseprocess')
        pid2 = yield p1.spawn_child(child)

        (cont, hdrs, msg) = yield p1.rpc_send(pid2, 'echo', 'content123')
        self.assertEquals(cont['value'], 'content123')

        yield p1.shutdown()
Ejemplo n.º 11
0
    def op_start_instrument_agent(self, content, headers, msg):
        """
        Service operation: Starts an instrument agent for a type of
        instrument.
        """
        if 'instrumentID' in content:
            inst_id = str(content['instrumentID'])
        else:
            raise ValueError("Input for instrumentID not present")

        if 'model' in content:
            model = str(content['model'])
        else:
            raise ValueError("Input for model not present")

        if model != 'SBE49':
            raise ValueError("Only SBE49 supported!")

        agent_pid = yield self.get_agent_pid_for_instrument(inst_id)
        if agent_pid:
            raise StandardError("Agent already started for instrument " +
                                str(inst_id))

        simulator = Simulator(inst_id)
        simulator.start()

        topicname = "Inst/RAW/" + inst_id
        topic = PubSubTopicResource.create(topicname, "")

        # Use the service to create a queue and register the topic
        topic = yield self.dpsc.define_topic(topic)

        iagent_args = {}
        iagent_args['instrument-id'] = inst_id
        driver_args = {}
        driver_args['port'] = simulator.port
        driver_args['publish-to'] = topic.RegistryIdentity
        iagent_args['driver-args'] = driver_args

        iapd = ProcessDesc(
            **{
                'name': 'SBE49IA',
                'module': 'ion.agents.instrumentagents.SBE49_IA',
                'class': 'SBE49InstrumentAgent',
                'spawnargs': iagent_args
            })

        iagent_id = yield self.spawn_child(iapd)
        iaclient = InstrumentAgentClient(proc=self, target=iagent_id)
        yield iaclient.register_resource(inst_id)

        yield self.reply_ok(msg, "OK")
Ejemplo n.º 12
0
    def plc_init(self):
        """
        Initialize instrument driver when this process is started.
        """
        InstrumentAgent.plc_init(self)

        self.instrument_id = self.spawn_args.get('instrument-id', '123')
        self.driver_args = self.spawn_args.get('driver-args', {})
        logging.info("INIT agent for instrument ID: %s" % (self.instrument_id))

        self.driver_args['instrument-id'] = self.instrument_id
        self.pd = ProcessDesc(**{'name':'SBE49Driver',
                          'module':'ion.agents.instrumentagents.SBE49_driver',
                          'class':'SBE49InstrumentDriver',
                          'spawnargs':self.driver_args})

        driver_id = yield self.spawn_child(self.pd)
        self.driver_client = SBE49InstrumentDriverClient(proc=self,
                                                         target=driver_id)
Ejemplo n.º 13
0
    def test_stream(self):

        #Set up a logging consumer as a listenr
        pd1 = {
            'name': 'consumer_number_1',
            'module':
            'ion.services.dm.distribution.consumers.logging_consumer',
            'procclass': 'LoggingConsumer',
            'spawnargs': {
                'attach': [self.queue1]
            }
        }
        child1 = base_consumer.ConsumerDesc(**pd1)

        child1_id = yield self.test_sup.spawn_child(child1)

        dc1 = self._get_procinstance(child1_id)

        dsp1 = {
            'name': 'data_stream_1',
            'module': 'ion.services.dm.util.data_stream_producer',
            'procclass': 'DataStreamProducer',
            'spawnargs': {
                'delivery queue': self.queue1,
                'delivery interval': 5
            }
        }

        child2 = ProcessDesc(**dsp1)

        child2_id = yield self.test_sup.spawn_child(child2)

        yield pu.asleep(2)

        rec = dc1.receive_cnt[self.queue1]
        self.assertEqual(rec, 1)

        yield pu.asleep(5)

        rec = dc1.receive_cnt[self.queue1]
        self.assertEqual(rec, 2)
Ejemplo n.º 14
0
def create_producer(proc):

    dpsc = pubsub_service.DataPubsubClient(proc=proc)

    topic = PubSubTopicResource.create('time series',
                                       'dap grid, timeseries, data')
    topic = yield dpsc.define_topic(topic)

    dspname = 'data_timeseries_stream_producer'
    dsp = {
        'name': dspname,
        'module': 'ion.services.dm.util.dap_grid_timeseries_producer',
        'procclass': 'DapGridDataStreamProducer',
        'spawnargs': {
            'delivery queue': topic.queue.name,
            'delivery interval': 5
        }
    }

    child = ProcessDesc(**dsp)
    child_id = yield proc.spawn_child(child)
Ejemplo n.º 15
0
def spawn_processes(procs, sup=None):
    """
    Spawns a set of processes.
    @param procs  list of processes (as description dict) to start up
    @param sup  spawned BaseProcess instance acting as supervisor
    @retval Deferred, for supervisor BaseProcess instance
    """
    children = []
    for procDef in procs:
        child = ProcessDesc(**procDef)
        children.append(child)

    if sup == None:
        sup = yield create_supervisor()

    logging.info("Spawning child processes")
    for child in children:
        child_id = yield sup.spawn_child(child)

    logging.debug("process_ids: "+ str(base_process.procRegistry.kvs))

    defer.returnValue(sup)
Ejemplo n.º 16
0
 def __init__(self, **kwargs):
     
     ProcessDesc.__init__(self,**kwargs)